disable debug
[AROS.git] / workbench / libs / mesa / src / aros / mesa3dgl / mesa3dgl_support.c
blob7fe2f83fea4764eb822c86ad559d1dc724fe2cb5
1 /*
2 Copyright 2009-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <proto/utility.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/cybergraphics.h>
13 #include <cybergraphx/cybergraphics.h>
14 #include <graphics/rpattr.h>
16 #include "mesa3dgl_support.h"
18 VOID MESA3DGLSelectRastPort(struct mesa3dgl_context * ctx, struct TagItem * tagList)
20 ctx->Screen = (struct Screen *)GetTagData(GLA_Screen, 0, tagList);
21 ctx->window = (struct Window *)GetTagData(GLA_Window, 0, tagList);
22 ctx->visible_rp = (struct RastPort *)GetTagData(GLA_RastPort, 0, tagList);
24 if (ctx->Screen)
26 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Screen @ %x\n", ctx->Screen));
27 if (ctx->window)
29 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Window @ %x\n", ctx->window));
30 if (!(ctx->visible_rp))
32 /* Use the windows rastport */
33 ctx->visible_rp = ctx->window->RPort;
34 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Windows RastPort @ %x\n", ctx->visible_rp));
37 else
39 if (!(ctx->visible_rp))
41 /* Use the screens rastport */
42 ctx->visible_rp = &ctx->Screen->RastPort;
43 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Screens RastPort @ %x\n", ctx->visible_rp));
47 else
49 /* Not passed a screen */
50 if (ctx->window)
52 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Window @ %x\n", ctx->window));
53 /* Use the windows Screen */
54 ctx->Screen = ctx->window->WScreen;
55 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Windows Screen @ %x\n", ctx->Screen));
57 if (!(ctx->visible_rp))
59 /* Use the windows rastport */
60 ctx->visible_rp = ctx->window->RPort;
61 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Windows RastPort @ %x\n", ctx->visible_rp));
64 else
66 /* Only Passed A Rastport */
67 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Using RastPort only!\n"));
71 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Using RastPort @ %x\n", ctx->visible_rp));
74 BOOL MESA3DGLStandardInit(struct mesa3dgl_context * ctx, struct TagItem *tagList)
76 LONG requestedwidth = 0, requestedheight = 0;
77 LONG requestedright = 0, requestedbottom = 0;
78 LONG defaultleft = 0, defaulttop = 0;
79 LONG defaultright = 0, defaultbottom = 0;
81 /* Set the defaults based on window information */
82 if (ctx->window)
84 if(!(ctx->window->Flags & WFLG_GIMMEZEROZERO))
86 defaultleft = ctx->window->BorderLeft;
87 defaulttop = ctx->window->BorderTop;
88 defaultright = ctx->window->BorderRight;
89 defaultbottom = ctx->window->BorderBottom;
93 D(bug("[MESA3DGL] MESA3DGLStandardInit(ctx @ %x, taglist @ %x)\n", ctx, tagList));
94 D(bug("[MESA3DGL] MESA3DGLStandardInit: Using RastPort @ %x\n", ctx->visible_rp));
96 ctx->visible_rp = CloneRastPort(ctx->visible_rp);
98 D(bug("[MESA3DGL] MESA3DGLStandardInit: Cloned RastPort @ %x\n", ctx->visible_rp));
100 /* We assume left and top are given or if there is a window, set to border left/top
101 or if there is no window set to 0 */
102 ctx->left = GetTagData(GLA_Left, defaultleft, tagList);
103 ctx->top = GetTagData(GLA_Top, defaulttop, tagList);
105 requestedright = GetTagData(GLA_Right, -1, tagList);
106 requestedbottom = GetTagData(GLA_Bottom, -1, tagList);
107 requestedwidth = GetTagData(GLA_Width, -1 , tagList);
108 requestedheight = GetTagData(GLA_Height, -1 , tagList);
110 /* Calculate rastport dimensions */
111 ctx->visible_rp_width =
112 ctx->visible_rp->Layer->bounds.MaxX - ctx->visible_rp->Layer->bounds.MinX + 1;
114 ctx->visible_rp_height =
115 ctx->visible_rp->Layer->bounds.MaxY - ctx->visible_rp->Layer->bounds.MinY + 1;
117 /* right will be either passed or calculated from width or 0 */
118 ctx->right = 0;
119 if (requestedright < 0)
121 if (requestedwidth >= 0)
123 requestedright = ctx->visible_rp_width - ctx->left - requestedwidth;
124 if (requestedright < 0) requestedright = 0;
126 else
127 requestedright = defaultright; /* Set the default here, not in GetDataData */
129 ctx->right = requestedright;
131 /* bottom will be either passed or calculated from height or 0 */
132 ctx->bottom = 0;
133 if (requestedbottom < 0)
135 if (requestedheight >= 0)
137 requestedbottom = ctx->visible_rp_height - ctx->top - requestedheight;
138 if (requestedbottom < 0) requestedbottom = 0;
140 else
141 requestedbottom = defaultbottom; /* Set the default here, not in GetDataData */
143 ctx->bottom = requestedbottom;
145 /* Init screen information */
146 if (ctx->Screen)
147 ctx->BitsPerPixel = GetCyberMapAttr(ctx->Screen->RastPort.BitMap, CYBRMATTR_BPPIX) * 8;
149 D(bug("[MESA3DGL] MESA3DGLStandardInit: Context Base dimensions set -:\n"));
150 D(bug("[MESA3DGL] MESA3DGLStandardInit: ctx->visible_rp_width = %d\n", ctx->visible_rp_width));
151 D(bug("[MESA3DGL] MESA3DGLStandardInit: ctx->visible_rp_height = %d\n", ctx->visible_rp_height));
152 D(bug("[MESA3DGL] MESA3DGLStandardInit: ctx->left = %d\n", ctx->left));
153 D(bug("[MESA3DGL] MESA3DGLStandardInit: ctx->right = %d\n", ctx->right));
154 D(bug("[MESA3DGL] MESA3DGLStandardInit: ctx->top = %d\n", ctx->top));
155 D(bug("[MESA3DGL] MESA3DGLStandardInit: ctx->bottom = %d\n", ctx->bottom));
157 return TRUE;
160 VOID MESA3DGLRecalculateBufferWidthHeight(struct mesa3dgl_context * ctx)
162 ULONG newwidth = 0;
163 ULONG newheight = 0;
165 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight\n"));
168 ctx->visible_rp_width =
169 ctx->visible_rp->Layer->bounds.MaxX - ctx->visible_rp->Layer->bounds.MinX + 1;
171 ctx->visible_rp_height =
172 ctx->visible_rp->Layer->bounds.MaxY - ctx->visible_rp->Layer->bounds.MinY + 1;
175 newwidth = ctx->visible_rp_width - ctx->left - ctx->right;
176 newheight = ctx->visible_rp_height - ctx->top - ctx->bottom;
178 if (newwidth < 0) newwidth = 0;
179 if (newheight < 0) newheight = 0;
182 if ((newwidth != ctx->framebuffer->width) || (newheight != ctx->framebuffer->height))
184 /* The drawing area size has changed. Buffer must change */
185 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: current height = %d\n", ctx->framebuffer->height));
186 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: current width = %d\n", ctx->framebuffer->width));
187 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: new height = %d\n", newheight));
188 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: new width = %d\n", newwidth));
190 ctx->framebuffer->width = newwidth;
191 ctx->framebuffer->height = newheight;
192 ctx->framebuffer->resized = TRUE;
194 if (ctx->window)
196 struct Rectangle rastcliprect;
197 struct TagItem crptags[] =
199 { RPTAG_ClipRectangle , (IPTR)&rastcliprect },
200 { RPTAG_ClipRectangleFlags , (RPCRF_RELRIGHT | RPCRF_RELBOTTOM) },
201 { TAG_DONE }
204 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: Clipping Rastport to Window's dimensions\n"));
206 /* Clip the rastport to the visible area */
207 rastcliprect.MinX = ctx->left;
208 rastcliprect.MinY = ctx->top;
209 rastcliprect.MaxX = ctx->left + ctx->framebuffer->width;
210 rastcliprect.MaxY = ctx->top + ctx->framebuffer->height;
211 SetRPAttrsA(ctx->visible_rp, crptags);
216 VOID MESA3DGLFreeContext(struct mesa3dgl_context * ctx)
218 if (ctx)
220 FreeVec(ctx);