finish migrating from arosmesa to mesa3dgl
[AROS.git] / workbench / libs / mesa / src / aros / mesa3dgl / mesa3dgl_support.c
blob4b095e0e7235ff211fc8cc9d6fc2ffc6db762838
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 * amesa, struct TagItem * tagList)
20 amesa->Screen = (struct Screen *)GetTagData(GLA_Screen, 0, tagList);
21 amesa->window = (struct Window *)GetTagData(GLA_Window, 0, tagList);
22 amesa->visible_rp = (struct RastPort *)GetTagData(GLA_RastPort, 0, tagList);
24 if (amesa->Screen)
26 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Screen @ %x\n", amesa->Screen));
27 if (amesa->window)
29 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Window @ %x\n", amesa->window));
30 if (!(amesa->visible_rp))
32 /* Use the windows rastport */
33 amesa->visible_rp = amesa->window->RPort;
34 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Windows RastPort @ %x\n", amesa->visible_rp));
37 else
39 if (!(amesa->visible_rp))
41 /* Use the screens rastport */
42 amesa->visible_rp = &amesa->Screen->RastPort;
43 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Screens RastPort @ %x\n", amesa->visible_rp));
47 else
49 /* Not passed a screen */
50 if (amesa->window)
52 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Window @ %x\n", amesa->window));
53 /* Use the windows Screen */
54 amesa->Screen = amesa->window->WScreen;
55 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Windows Screen @ %x\n", amesa->Screen));
57 if (!(amesa->visible_rp))
59 /* Use the windows rastport */
60 amesa->visible_rp = amesa->window->RPort;
61 D(bug("[MESA3DGL] MESA3DGLSelectRastPort: Windows RastPort @ %x\n", amesa->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", amesa->visible_rp));
74 BOOL MESA3DGLStandardInit(struct mesa3dgl_context * amesa, 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 (amesa->window)
84 if(!(amesa->window->Flags & WFLG_GIMMEZEROZERO))
86 defaultleft = amesa->window->BorderLeft;
87 defaulttop = amesa->window->BorderTop;
88 defaultright = amesa->window->BorderRight;
89 defaultbottom = amesa->window->BorderBottom;
93 D(bug("[MESA3DGL] MESA3DGLStandardInit(amesa @ %x, taglist @ %x)\n", amesa, tagList));
94 D(bug("[MESA3DGL] MESA3DGLStandardInit: Using RastPort @ %x\n", amesa->visible_rp));
96 amesa->visible_rp = CloneRastPort(amesa->visible_rp);
98 D(bug("[MESA3DGL] MESA3DGLStandardInit: Cloned RastPort @ %x\n", amesa->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 amesa->left = GetTagData(GLA_Left, defaultleft, tagList);
103 amesa->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 amesa->visible_rp_width =
112 amesa->visible_rp->Layer->bounds.MaxX - amesa->visible_rp->Layer->bounds.MinX + 1;
114 amesa->visible_rp_height =
115 amesa->visible_rp->Layer->bounds.MaxY - amesa->visible_rp->Layer->bounds.MinY + 1;
117 /* right will be either passed or calculated from width or 0 */
118 amesa->right = 0;
119 if (requestedright < 0)
121 if (requestedwidth >= 0)
123 requestedright = amesa->visible_rp_width - amesa->left - requestedwidth;
124 if (requestedright < 0) requestedright = 0;
126 else
127 requestedright = defaultright; /* Set the default here, not in GetDataData */
129 amesa->right = requestedright;
131 /* bottom will be either passed or calculated from height or 0 */
132 amesa->bottom = 0;
133 if (requestedbottom < 0)
135 if (requestedheight >= 0)
137 requestedbottom = amesa->visible_rp_height - amesa->top - requestedheight;
138 if (requestedbottom < 0) requestedbottom = 0;
140 else
141 requestedbottom = defaultbottom; /* Set the default here, not in GetDataData */
143 amesa->bottom = requestedbottom;
145 /* Init screen information */
146 if (amesa->Screen)
147 amesa->BitsPerPixel = GetCyberMapAttr(amesa->Screen->RastPort.BitMap, CYBRMATTR_BPPIX) * 8;
149 D(bug("[MESA3DGL] MESA3DGLStandardInit: Context Base dimensions set -:\n"));
150 D(bug("[MESA3DGL] MESA3DGLStandardInit: amesa->visible_rp_width = %d\n", amesa->visible_rp_width));
151 D(bug("[MESA3DGL] MESA3DGLStandardInit: amesa->visible_rp_height = %d\n", amesa->visible_rp_height));
152 D(bug("[MESA3DGL] MESA3DGLStandardInit: amesa->left = %d\n", amesa->left));
153 D(bug("[MESA3DGL] MESA3DGLStandardInit: amesa->right = %d\n", amesa->right));
154 D(bug("[MESA3DGL] MESA3DGLStandardInit: amesa->top = %d\n", amesa->top));
155 D(bug("[MESA3DGL] MESA3DGLStandardInit: amesa->bottom = %d\n", amesa->bottom));
157 return TRUE;
160 VOID MESA3DGLRecalculateBufferWidthHeight(struct mesa3dgl_context * amesa)
162 ULONG newwidth = 0;
163 ULONG newheight = 0;
165 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight\n"));
168 amesa->visible_rp_width =
169 amesa->visible_rp->Layer->bounds.MaxX - amesa->visible_rp->Layer->bounds.MinX + 1;
171 amesa->visible_rp_height =
172 amesa->visible_rp->Layer->bounds.MaxY - amesa->visible_rp->Layer->bounds.MinY + 1;
175 newwidth = amesa->visible_rp_width - amesa->left - amesa->right;
176 newheight = amesa->visible_rp_height - amesa->top - amesa->bottom;
178 if (newwidth < 0) newwidth = 0;
179 if (newheight < 0) newheight = 0;
182 if ((newwidth != amesa->framebuffer->width) || (newheight != amesa->framebuffer->height))
184 /* The drawing area size has changed. Buffer must change */
185 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: current height = %d\n", amesa->framebuffer->height));
186 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: current width = %d\n", amesa->framebuffer->width));
187 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: new height = %d\n", newheight));
188 D(bug("[MESA3DGL] MESA3DGLRecalculateBufferWidthHeight: new width = %d\n", newwidth));
190 amesa->framebuffer->width = newwidth;
191 amesa->framebuffer->height = newheight;
192 amesa->framebuffer->resized = TRUE;
194 if (amesa->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 = amesa->left;
208 rastcliprect.MinY = amesa->top;
209 rastcliprect.MaxX = amesa->left + amesa->framebuffer->width;
210 rastcliprect.MaxY = amesa->top + amesa->framebuffer->height;
211 SetRPAttrsA(amesa->visible_rp, crptags);
216 VOID MESA3DGLFreeContext(struct mesa3dgl_context * amesa)
218 if (amesa)
220 FreeVec(amesa);