wip - import hostgl from abi v0 and adapt to abi v1/GL.library ABI
[AROS.git] / arch / all-hosted / libs / hostgl / hostgl_support.c
blobb53fd64340782b2ce4bddc4ea6c0f6cab11104b2
1 /*
2 Copyright 2009-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
7 #include <aros/debug.h>
9 #include <proto/utility.h>
10 #include <proto/exec.h>
11 #include <proto/graphics.h>
12 #include <proto/cybergraphics.h>
14 #include <cybergraphx/cybergraphics.h>
15 #include <graphics/rpattr.h>
17 #include "hostgl_support.h"
20 VOID HostGLSelectRastPort(struct hostgl_context * ctx, struct TagItem * tagList)
22 ctx->Screen = (struct Screen *)GetTagData(GLA_Screen, 0, tagList);
23 ctx->window = (struct Window *)GetTagData(GLA_Window, 0, tagList);
24 ctx->visible_rp = (struct RastPort *)GetTagData(GLA_RastPort, 0, tagList);
26 if (ctx->Screen)
28 D(bug("[HOSTGL] HostGLSelectRastPort: Screen @ %x\n", ctx->Screen));
29 if (ctx->window)
31 D(bug("[HOSTGL] HostGLSelectRastPort: Window @ %x\n", ctx->window));
32 if (!(ctx->visible_rp))
34 /* Use the windows rastport */
35 ctx->visible_rp = ctx->window->RPort;
36 D(bug("[HOSTGL] HostGLSelectRastPort: Windows RastPort @ %x\n", ctx->visible_rp));
39 else
41 if (!(ctx->visible_rp))
43 /* Use the screens rastport */
44 ctx->visible_rp = &ctx->Screen->RastPort;
45 D(bug("[HOSTGL] HostGLSelectRastPort: Screens RastPort @ %x\n", ctx->visible_rp));
49 else
51 /* Not passed a screen */
52 if (ctx->window)
54 D(bug("[HOSTGL] HostGLSelectRastPort: Window @ %x\n", ctx->window));
55 /* Use the windows Screen */
56 ctx->Screen = ctx->window->WScreen;
57 D(bug("[HOSTGL] HostGLSelectRastPort: Windows Screen @ %x\n", ctx->Screen));
59 if (!(ctx->visible_rp))
61 /* Use the windows rastport */
62 ctx->visible_rp = ctx->window->RPort;
63 D(bug("[HOSTGL] HostGLSelectRastPort: Windows RastPort @ %x\n", ctx->visible_rp));
66 else
68 /* Only Passed A Rastport */
69 D(bug("[HOSTGL] HostGLSelectRastPort: Using RastPort only!\n"));
73 D(bug("[HOSTGL] HostGLSelectRastPort: Using RastPort @ %x\n", ctx->visible_rp));
76 BOOL HostGLStandardInit(struct hostgl_context * ctx, struct TagItem *tagList)
78 LONG requestedwidth = 0, requestedheight = 0;
79 LONG requestedright = 0, requestedbottom = 0;
80 LONG defaultleft = 0, defaulttop = 0;
81 LONG defaultright = 0, defaultbottom = 0;
83 /* Set the defaults based on window information */
84 if (ctx->window)
86 if(!(ctx->window->Flags & WFLG_GIMMEZEROZERO))
88 defaultleft = ctx->window->BorderLeft;
89 defaulttop = ctx->window->BorderTop;
90 defaultright = ctx->window->BorderRight;
91 defaultbottom = ctx->window->BorderBottom;
95 D(bug("[HOSTGL] HostGLStandardInit(ctx @ %x, taglist @ %x)\n", ctx, tagList));
96 D(bug("[HOSTGL] HostGLStandardInit: Using RastPort @ %x\n", ctx->visible_rp));
98 ctx->visible_rp = CloneRastPort(ctx->visible_rp);
100 D(bug("[HOSTGL] HostGLStandardInit: Cloned RastPort @ %x\n", ctx->visible_rp));
102 /* We assume left and top are given or if there is a window, set to border left/top
103 or if there is no window set to 0 */
104 ctx->left = GetTagData(GLA_Left, defaultleft, tagList);
105 ctx->top = GetTagData(GLA_Top, defaulttop, tagList);
107 requestedright = GetTagData(GLA_Right, -1, tagList);
108 requestedbottom = GetTagData(GLA_Bottom, -1, tagList);
109 requestedwidth = GetTagData(GLA_Width, -1 , tagList);
110 requestedheight = GetTagData(GLA_Height, -1 , tagList);
112 /* Calculate rastport dimensions */
113 ctx->visible_rp_width =
114 ctx->visible_rp->Layer->bounds.MaxX - ctx->visible_rp->Layer->bounds.MinX + 1;
116 ctx->visible_rp_height =
117 ctx->visible_rp->Layer->bounds.MaxY - ctx->visible_rp->Layer->bounds.MinY + 1;
119 /* right will be either passed or calculated from width or 0 */
120 ctx->right = 0;
121 if (requestedright < 0)
123 if (requestedwidth >= 0)
125 requestedright = ctx->visible_rp_width - ctx->left - requestedwidth;
126 if (requestedright < 0) requestedright = 0;
128 else
129 requestedright = defaultright; /* Set the default here, not in GetDataData */
131 ctx->right = requestedright;
133 /* bottom will be either passed or calculated from height or 0 */
134 ctx->bottom = 0;
135 if (requestedbottom < 0)
137 if (requestedheight >= 0)
139 requestedbottom = ctx->visible_rp_height - ctx->top - requestedheight;
140 if (requestedbottom < 0) requestedbottom = 0;
142 else
143 requestedbottom = defaultbottom; /* Set the default here, not in GetDataData */
145 ctx->bottom = requestedbottom;
147 /* Init screen information */
148 if (ctx->Screen)
149 ctx->BitsPerPixel = GetCyberMapAttr(ctx->Screen->RastPort.BitMap, CYBRMATTR_BPPIX) * 8;
151 D(bug("[HOSTGL] HostGLStandardInit: Context Base dimensions set -:\n"));
152 D(bug("[HOSTGL] HostGLStandardInit: ctx->visible_rp_width = %d\n", ctx->visible_rp_width));
153 D(bug("[HOSTGL] HostGLStandardInit: ctx->visible_rp_height = %d\n", ctx->visible_rp_height));
154 D(bug("[HOSTGL] HostGLStandardInit: ctx->left = %d\n", ctx->left));
155 D(bug("[HOSTGL] HostGLStandardInit: ctx->right = %d\n", ctx->right));
156 D(bug("[HOSTGL] HostGLStandardInit: ctx->top = %d\n", ctx->top));
157 D(bug("[HOSTGL] HostGLStandardInit: ctx->bottom = %d\n", ctx->bottom));
159 return TRUE;
162 VOID HostGLRecalculateBufferWidthHeight(struct hostgl_context * ctx)
164 ULONG newwidth = 0;
165 ULONG newheight = 0;
167 D(bug("[HOSTGL] HostGLRecalculateBufferWidthHeight\n"));
170 ctx->visible_rp_width =
171 ctx->visible_rp->Layer->bounds.MaxX - ctx->visible_rp->Layer->bounds.MinX + 1;
173 ctx->visible_rp_height =
174 ctx->visible_rp->Layer->bounds.MaxY - ctx->visible_rp->Layer->bounds.MinY + 1;
177 newwidth = ctx->visible_rp_width - ctx->left - ctx->right;
178 newheight = ctx->visible_rp_height - ctx->top - ctx->bottom;
180 if (newwidth < 0) newwidth = 0;
181 if (newheight < 0) newheight = 0;
184 if ((newwidth != ctx->framebuffer->width) || (newheight != ctx->framebuffer->height))
186 /* The drawing area size has changed. Buffer must change */
187 D(bug("[HOSTGL] HostGLRecalculateBufferWidthHeight: current height = %d\n", ctx->framebuffer->height));
188 D(bug("[HOSTGL] HostGLRecalculateBufferWidthHeight: current width = %d\n", ctx->framebuffer->width));
189 D(bug("[HOSTGL] HostGLRecalculateBufferWidthHeight: new height = %d\n", newheight));
190 D(bug("[HOSTGL] HostGLRecalculateBufferWidthHeight: new width = %d\n", newwidth));
192 ctx->framebuffer->width = newwidth;
193 ctx->framebuffer->height = newheight;
194 ctx->framebuffer->resized = TRUE;
196 if (ctx->window)
198 struct Rectangle rastcliprect;
199 struct TagItem crptags[] =
201 { RPTAG_ClipRectangle , (IPTR)&rastcliprect },
202 { RPTAG_ClipRectangleFlags , (RPCRF_RELRIGHT | RPCRF_RELBOTTOM) },
203 { TAG_DONE }
206 D(bug("[HOSTGL] HostGLRecalculateBufferWidthHeight: Clipping Rastport to Window's dimensions\n"));
208 /* Clip the rastport to the visible area */
209 rastcliprect.MinX = ctx->left;
210 rastcliprect.MinY = ctx->top;
211 rastcliprect.MaxX = ctx->left + ctx->framebuffer->width;
212 rastcliprect.MaxY = ctx->top + ctx->framebuffer->height;
213 SetRPAttrsA(ctx->visible_rp, crptags);
218 VOID HostGLFreeContext(struct hostgl_context * ctx)
220 if (ctx)
222 FreeVec(ctx);