VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/dlm/dlm_bbox.c@ 56473

Last change on this file since 56473 was 54905, checked in by vboxsync, 10 years ago

Host 3D: Chromium server: add Expando SPU and DLM module in order to record and save OpenGL Display Lists (currently disabled).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/* $Id: dlm_bbox.c 54905 2015-03-23 11:20:58Z vboxsync $ */
2/**
3 * Code to compute the bounding box of a DLM display list.
4 * Matrix commands in the display list are observed to properly
5 * transform the vertices we find.
6 */
7
8#include <float.h>
9#include "cr_dlm.h"
10#include "cr_mem.h"
11#include "cr_spu.h"
12#include "cr_glstate.h"
13#include "dlm.h"
14
15
16static CRMatrixStack ModelViewStack;
17static CRMatrixStack DummyStack;
18static CRMatrixStack *CurrentStack;
19
20
21static GLfloat Xmin, Xmax, Ymin, Ymax, Zmin, Zmax;
22
23
24static void
25MatrixMode(GLenum matrix)
26{
27 switch (matrix) {
28 case GL_MODELVIEW:
29 CurrentStack = &ModelViewStack;
30 break;
31 default:
32 CurrentStack = &DummyStack;
33 }
34}
35
36
37static void
38LoadMatrixf(const GLfloat m[16])
39{
40 crMatrixInitFromFloats(CurrentStack->top, m);
41}
42
43
44static void
45LoadMatrixd(const GLdouble m[16])
46{
47 crMatrixInitFromDoubles(CurrentStack->top, m);
48}
49
50
51static void
52LoadIdentity(void)
53{
54 crMatrixInit(CurrentStack->top);
55}
56
57
58static void
59PushMatrix(void)
60{
61 if (CurrentStack->depth < CurrentStack->maxDepth) {
62 /* copy matrix */
63 *(CurrentStack->top + 1) = *(CurrentStack->top);
64 /* Move the stack pointer */
65 CurrentStack->depth++;
66 CurrentStack->top = CurrentStack->stack + CurrentStack->depth;
67 }
68 else {
69 crWarning("Stack overflow in dlm_bbox.c");
70 }
71}
72
73
74static void
75PopMatrix(void)
76{
77 if (CurrentStack->depth > 0) {
78 CurrentStack->depth--;
79 CurrentStack->top = CurrentStack->stack + CurrentStack->depth;
80 }
81 else {
82 crWarning("Stack underflow in dlm_bbox.c");
83 }
84}
85
86
87static void
88MultMatrixf(const GLfloat m1[16])
89{
90 CRmatrix *m = CurrentStack->top;
91 const GLdefault lm00 = m->m00;
92 const GLdefault lm01 = m->m01;
93 const GLdefault lm02 = m->m02;
94 const GLdefault lm03 = m->m03;
95 const GLdefault lm10 = m->m10;
96 const GLdefault lm11 = m->m11;
97 const GLdefault lm12 = m->m12;
98 const GLdefault lm13 = m->m13;
99 const GLdefault lm20 = m->m20;
100 const GLdefault lm21 = m->m21;
101 const GLdefault lm22 = m->m22;
102 const GLdefault lm23 = m->m23;
103 const GLdefault lm30 = m->m30;
104 const GLdefault lm31 = m->m31;
105 const GLdefault lm32 = m->m32;
106 const GLdefault lm33 = m->m33;
107 const GLdefault rm00 = (GLdefault) m1[0];
108 const GLdefault rm01 = (GLdefault) m1[1];
109 const GLdefault rm02 = (GLdefault) m1[2];
110 const GLdefault rm03 = (GLdefault) m1[3];
111 const GLdefault rm10 = (GLdefault) m1[4];
112 const GLdefault rm11 = (GLdefault) m1[5];
113 const GLdefault rm12 = (GLdefault) m1[6];
114 const GLdefault rm13 = (GLdefault) m1[7];
115 const GLdefault rm20 = (GLdefault) m1[8];
116 const GLdefault rm21 = (GLdefault) m1[9];
117 const GLdefault rm22 = (GLdefault) m1[10];
118 const GLdefault rm23 = (GLdefault) m1[11];
119 const GLdefault rm30 = (GLdefault) m1[12];
120 const GLdefault rm31 = (GLdefault) m1[13];
121 const GLdefault rm32 = (GLdefault) m1[14];
122 const GLdefault rm33 = (GLdefault) m1[15];
123
124 m->m00 = lm00*rm00 + lm10*rm01 + lm20*rm02 + lm30*rm03;
125 m->m01 = lm01*rm00 + lm11*rm01 + lm21*rm02 + lm31*rm03;
126 m->m02 = lm02*rm00 + lm12*rm01 + lm22*rm02 + lm32*rm03;
127 m->m03 = lm03*rm00 + lm13*rm01 + lm23*rm02 + lm33*rm03;
128 m->m10 = lm00*rm10 + lm10*rm11 + lm20*rm12 + lm30*rm13;
129 m->m11 = lm01*rm10 + lm11*rm11 + lm21*rm12 + lm31*rm13;
130 m->m12 = lm02*rm10 + lm12*rm11 + lm22*rm12 + lm32*rm13;
131 m->m13 = lm03*rm10 + lm13*rm11 + lm23*rm12 + lm33*rm13;
132 m->m20 = lm00*rm20 + lm10*rm21 + lm20*rm22 + lm30*rm23;
133 m->m21 = lm01*rm20 + lm11*rm21 + lm21*rm22 + lm31*rm23;
134 m->m22 = lm02*rm20 + lm12*rm21 + lm22*rm22 + lm32*rm23;
135 m->m23 = lm03*rm20 + lm13*rm21 + lm23*rm22 + lm33*rm23;
136 m->m30 = lm00*rm30 + lm10*rm31 + lm20*rm32 + lm30*rm33;
137 m->m31 = lm01*rm30 + lm11*rm31 + lm21*rm32 + lm31*rm33;
138 m->m32 = lm02*rm30 + lm12*rm31 + lm22*rm32 + lm32*rm33;
139 m->m33 = lm03*rm30 + lm13*rm31 + lm23*rm32 + lm33*rm33;
140}
141
142
143static void
144MultMatrixd(const GLdouble m1[16])
145{
146 GLfloat m2[16];
147 int i;
148 for (i = 0; i < 16; i++)
149 m2[i] = (GLfloat) m1[i];
150 MultMatrixf(m2);
151}
152
153
154static void
155Rotatef(GLfloat ang, GLfloat x, GLfloat y, GLfloat z)
156{
157 crMatrixRotate(CurrentStack->top, ang, x, y, z);
158}
159
160
161static void
162Rotated(GLdouble ang, GLdouble x, GLdouble y, GLdouble z)
163{
164 crMatrixRotate(CurrentStack->top, (GLfloat) ang,
165 (GLfloat) x, (GLfloat) y, (GLfloat) z);
166}
167
168
169static void
170Translatef(GLfloat x, GLfloat y, GLfloat z)
171{
172 crMatrixTranslate(CurrentStack->top, x, y, z);
173}
174
175
176static void
177Translated(GLdouble x, GLdouble y, GLdouble z)
178{
179 crMatrixTranslate(CurrentStack->top, (GLfloat) x, (GLfloat) y, (GLfloat) z);
180}
181
182
183static void
184Scalef(GLfloat x, GLfloat y, GLfloat z)
185{
186 crMatrixScale(CurrentStack->top, x, y, z);
187}
188
189
190static void
191Scaled(GLdouble x, GLdouble y, GLdouble z)
192{
193 crMatrixScale(CurrentStack->top, (GLfloat) x, (GLfloat) y, (GLfloat) z);
194}
195
196
197/**
198 * Transform given (x,y,z,w) by current matrix and update the bounding box.
199 */
200static void
201DoVertex(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
202{
203 const CRmatrix *m = CurrentStack->top;
204 const GLfloat x2 = m->m00 * x + m->m10 * y + m->m20 * z + m->m30 * w;
205 const GLfloat y2 = m->m01 * x + m->m11 * y + m->m21 * z + m->m31 * w;
206 const GLfloat z2 = m->m02 * x + m->m12 * y + m->m22 * z + m->m32 * w;
207 /*const GLfloat w2 = m->m03 * x + m->m13 * y + m->m23 * z + m->m33 * w;*/
208
209 if (x2 < Xmin) Xmin = x2;
210 if (x2 > Xmax) Xmax = x2;
211 if (y2 < Ymin) Ymin = y2;
212 if (y2 > Ymax) Ymax = y2;
213 if (z2 < Zmin) Zmin = z2;
214 if (z2 > Zmax) Zmax = z2;
215}
216
217
218static void
219Vertex2f(GLfloat x, GLfloat y)
220{
221 DoVertex(x, y, 0.0f, 1.0f);
222}
223
224static void
225Vertex2fv(const GLfloat *v)
226{
227 DoVertex(v[0], v[1], 0.0f, 1.0f);
228}
229
230static void
231Vertex3f(GLfloat x, GLfloat y, GLfloat z)
232{
233 DoVertex(x, y, z, 1.0f);
234}
235
236static void
237Vertex3fv(const GLfloat *v)
238{
239 DoVertex(v[0], v[1], v[2], 1.0f);
240}
241
242static void
243Vertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
244{
245 DoVertex(x, y, z, w);
246}
247
248static void
249Vertex4fv(const GLfloat *v)
250{
251 DoVertex(v[0], v[1], v[2], v[3]);
252}
253
254
255/**
256 ** XXX TO DO:
257 **
258glVertex2d( GLdouble x, GLdouble y );
259glVertex2f( GLfloat x, GLfloat y );
260glVertex2i( GLint x, GLint y );
261glVertex2s( GLshort x, GLshort y );
262glVertex3d( GLdouble x, GLdouble y, GLdouble z );
263glVertex3f( GLfloat x, GLfloat y, GLfloat z );
264glVertex3i( GLint x, GLint y, GLint z );
265glVertex3s( GLshort x, GLshort y, GLshort z );
266glVertex4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w );
267glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w );
268glVertex4i( GLint x, GLint y, GLint z, GLint w );
269glVertex4s( GLshort x, GLshort y, GLshort z, GLshort w );
270glVertex2dv( const GLdouble *v );
271glVertex2fv( const GLfloat *v );
272glVertex2iv( const GLint *v );
273glVertex2sv( const GLshort *v );
274glVertex3dv( const GLdouble *v );
275glVertex3fv( const GLfloat *v );
276glVertex3iv( const GLint *v );
277glVertex3sv( const GLshort *v );
278glVertex4dv( const GLdouble *v );
279glVertex4fv( const GLfloat *v );
280glVertex4iv( const GLint *v );
281glVertex4sv( const GLshort *v );
282
283glVertexAttrib1dARB(GLuint, GLdouble);
284glVertexAttrib1dvARB(GLuint, const GLdouble *);
285glVertexAttrib1fARB(GLuint, GLfloat);
286glVertexAttrib1fvARB(GLuint, const GLfloat *);
287glVertexAttrib1sARB(GLuint, GLshort);
288glVertexAttrib1svARB(GLuint, const GLshort *);
289glVertexAttrib2dARB(GLuint, GLdouble, GLdouble);
290glVertexAttrib2dvARB(GLuint, const GLdouble *);
291glVertexAttrib2fARB(GLuint, GLfloat, GLfloat);
292glVertexAttrib2fvARB(GLuint, const GLfloat *);
293glVertexAttrib2sARB(GLuint, GLshort, GLshort);
294glVertexAttrib2svARB(GLuint, const GLshort *);
295glVertexAttrib3dARB(GLuint, GLdouble, GLdouble, GLdouble);
296glVertexAttrib3dvARB(GLuint, const GLdouble *);
297**/
298
299static void
300VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z)
301{
302 if (index == 0)
303 DoVertex(x, y, z, 1.0f);
304}
305
306/**
307glVertexAttrib3fvARB(GLuint, const GLfloat *);
308glVertexAttrib3sARB(GLuint, GLshort, GLshort, GLshort);
309glVertexAttrib3svARB(GLuint, const GLshort *);
310glVertexAttrib4NbvARB(GLuint, const GLbyte *);
311glVertexAttrib4NivARB(GLuint, const GLint *);
312glVertexAttrib4NsvARB(GLuint, const GLshort *);
313glVertexAttrib4NubARB(GLuint, GLubyte, GLubyte, GLubyte, GLubyte);
314glVertexAttrib4NubvARB(GLuint, const GLubyte *);
315glVertexAttrib4NuivARB(GLuint, const GLuint *);
316glVertexAttrib4NusvARB(GLuint, const GLushort *);
317glVertexAttrib4bvARB(GLuint, const GLbyte *);
318glVertexAttrib4dARB(GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
319glVertexAttrib4dvARB(GLuint, const GLdouble *);
320glVertexAttrib4fARB(GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
321glVertexAttrib4fvARB(GLuint, const GLfloat *);
322glVertexAttrib4ivARB(GLuint, const GLint *);
323glVertexAttrib4sARB(GLuint, GLshort, GLshort, GLshort, GLshort);
324glVertexAttrib4svARB(GLuint, const GLshort *);
325glVertexAttrib4ubvARB(GLuint, const GLubyte *);
326glVertexAttrib4uivARB(GLuint, const GLuint *);
327glVertexAttrib4usvARB(GLuint, const GLushort *);
328
329glVertexAttrib1dNV(GLuint, GLdouble);
330glVertexAttrib1dvNV(GLuint, const GLdouble *);
331glVertexAttrib1fNV(GLuint, GLfloat);
332glVertexAttrib1fvNV(GLuint, const GLfloat *);
333glVertexAttrib1sNV(GLuint, GLshort);
334glVertexAttrib1svNV(GLuint, const GLshort *);
335glVertexAttrib2dNV(GLuint, GLdouble, GLdouble);
336glVertexAttrib2dvNV(GLuint, const GLdouble *);
337glVertexAttrib2fNV(GLuint, GLfloat, GLfloat);
338glVertexAttrib2fvNV(GLuint, const GLfloat *);
339glVertexAttrib2sNV(GLuint, GLshort, GLshort);
340glVertexAttrib2svNV(GLuint, const GLshort *);
341glVertexAttrib3dNV(GLuint, GLdouble, GLdouble, GLdouble);
342glVertexAttrib3dvNV(GLuint, const GLdouble *);
343glVertexAttrib3fNV(GLuint, GLfloat, GLfloat, GLfloat);
344glVertexAttrib3fvNV(GLuint, const GLfloat *);
345glVertexAttrib3sNV(GLuint, GLshort, GLshort, GLshort);
346glVertexAttrib3svNV(GLuint, const GLshort *);
347glVertexAttrib4dNV(GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
348glVertexAttrib4dvNV(GLuint, const GLdouble *);
349glVertexAttrib4fNV(GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
350glVertexAttrib4fvNV(GLuint, const GLfloat *);
351glVertexAttrib4sNV(GLuint, GLshort, GLshort, GLshort, GLshort);
352glVertexAttrib4svNV(GLuint, const GLshort *);
353glVertexAttrib4ubNV(GLuint, GLubyte, GLubyte, GLubyte, GLubyte);
354glVertexAttrib4ubvNV(GLuint, const GLubyte *);
355
356glVertexAttribs1dvNV(GLuint, GLsizei, const GLdouble *);
357glVertexAttribs1fvNV(GLuint, GLsizei, const GLfloat *);
358glVertexAttribs1svNV(GLuint, GLsizei, const GLshort *);
359glVertexAttribs2dvNV(GLuint, GLsizei, const GLdouble *);
360glVertexAttribs2fvNV(GLuint, GLsizei, const GLfloat *);
361glVertexAttribs2svNV(GLuint, GLsizei, const GLshort *);
362glVertexAttribs3dvNV(GLuint, GLsizei, const GLdouble *);
363glVertexAttribs3fvNV(GLuint, GLsizei, const GLfloat *);
364glVertexAttribs3svNV(GLuint, GLsizei, const GLshort *);
365glVertexAttribs4dvNV(GLuint, GLsizei, const GLdouble *);
366glVertexAttribs4fvNV(GLuint, GLsizei, const GLfloat *);
367glVertexAttribs4svNV(GLuint, GLsizei, const GLshort *);
368glVertexAttribs4ubvNV(GLuint, GLsizei, const GLubyte *);
369**/
370
371
372/**
373 ** XXX also need to track evaluator coordinates (glutTeapot)
374 **/
375
376
377static void
378InitDispatchTable(SPUDispatchTable *t)
379{
380 crMemZero(t, sizeof(*t));
381 crSPUInitDispatchNops(t);
382 /* drm1 */
383 t->MatrixMode = (MatrixModeFunc_t)MatrixMode;
384 t->LoadIdentity = (LoadIdentityFunc_t)LoadIdentity;
385 t->LoadMatrixf = (LoadMatrixfFunc_t)LoadMatrixf;
386 t->LoadMatrixd = (LoadMatrixdFunc_t)LoadMatrixd;
387 t->PushMatrix = (PushMatrixFunc_t)PushMatrix;
388 t->PopMatrix = (PopMatrixFunc_t)PopMatrix;
389 t->MultMatrixf = (MultMatrixfFunc_t)MultMatrixf;
390 t->MultMatrixd = (MultMatrixdFunc_t)MultMatrixd;
391 t->Rotatef = (RotatefFunc_t)Rotatef;
392 t->Rotated = (RotatedFunc_t)Rotated;
393 t->Translatef = (TranslatefFunc_t)Translatef;
394 t->Translated = (TranslatedFunc_t)Translated;
395 t->Scalef = (ScalefFunc_t)Scalef;
396 t->Scaled = (ScaledFunc_t)Scaled;
397 t->Vertex2f = (Vertex2fFunc_t)Vertex2f;
398 t->Vertex2fv = (Vertex2fvFunc_t)Vertex2fv;
399 t->Vertex3f = (Vertex3fFunc_t)Vertex3f;
400 t->Vertex3fv = (Vertex3fvFunc_t)Vertex3fv;
401 t->Vertex4f = (Vertex4fFunc_t)Vertex4f;
402 t->Vertex4fv = (Vertex4fvFunc_t)Vertex4fv;
403 t->VertexAttrib3fARB = (VertexAttrib3fARBFunc_t)VertexAttrib3fARB;
404}
405
406
407void
408crDLMComputeBoundingBox(unsigned long listId)
409{
410 static GLboolean tableInitialized = GL_FALSE;
411 static SPUDispatchTable t;
412 CRDLMContextState *listState = CURRENT_STATE();
413 CRDLM *dlm = listState->dlm;
414 DLMListInfo *listInfo
415 = (DLMListInfo *) crHashtableSearch(dlm->displayLists, listId);
416
417 if (!tableInitialized) {
418 InitDispatchTable(&t);
419 crStateInitMatrixStack(&ModelViewStack, CR_MAX_MODELVIEW_STACK_DEPTH);
420 crStateInitMatrixStack(&DummyStack, CR_MAX_MODELVIEW_STACK_DEPTH);
421 tableInitialized = GL_TRUE;
422 }
423
424 CurrentStack = &ModelViewStack;
425
426 Xmin = Ymin = Zmin = FLT_MAX;
427 Xmax = Ymax = Zmax = -FLT_MAX;
428
429 crDLMReplayDLMList(listState->dlm, listId, &t);
430
431 if (Xmin == FLT_MAX) {
432 /* XXX review this choice of default bounds */
433 /*
434 crDebug("Warning: no bounding box!");
435 */
436 Xmin = -100;
437 Xmax = 100;
438 Ymin = -100;
439 Ymax = 100;
440 Zmin = -100;
441 Zmax = 100;
442 }
443 /*
444 crDebug("List %d bbox: %f, %f, %f .. %f, %f, %f", (int) listId,
445 Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
446 */
447
448 listInfo->bbox.xmin = Xmin;
449 listInfo->bbox.ymin = Ymin;
450 listInfo->bbox.zmin = Zmin;
451 listInfo->bbox.xmax = Xmax;
452 listInfo->bbox.ymax = Ymax;
453 listInfo->bbox.zmax = Zmax;
454}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette