VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_point.c@ 55043

Last change on this file since 55043 was 50041, checked in by vboxsync, 11 years ago

crOpenGL: crOpenGL: 1. workaround point sprite driver bugs; 2. workaround multi-string shader source driver bug; 3. proper GLhandle for OSX; 4. extended dumping; 5. misc fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.0 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "state.h"
8#include "state/cr_statetypes.h"
9#include "state_internals.h"
10
11void crStatePointInit (CRContext *ctx)
12{
13 CRPointState *p = &ctx->point;
14 CRStateBits *sb = GetCurrentBits();
15 CRPointBits *pb = &(sb->point);
16 int i;
17
18 p->pointSmooth = GL_FALSE;
19 RESET(pb->enableSmooth, ctx->bitid);
20 p->pointSize = 1.0f;
21 RESET(pb->size, ctx->bitid);
22#ifdef CR_ARB_point_parameters
23 p->minSize = 0.0f;
24 RESET(pb->minSize, ctx->bitid);
25 p->maxSize = CR_ALIASED_POINT_SIZE_MAX;
26 RESET(pb->maxSize, ctx->bitid);
27 p->fadeThresholdSize = 1.0f;
28 RESET(pb->fadeThresholdSize, ctx->bitid);
29 p->distanceAttenuation[0] = 1.0f;
30 p->distanceAttenuation[1] = 0.0f;
31 p->distanceAttenuation[2] = 0.0f;
32 RESET(pb->distanceAttenuation, ctx->bitid);
33#endif
34#ifdef CR_ARB_point_sprite
35 p->pointSprite = GL_FALSE;
36 RESET(pb->enableSprite, ctx->bitid);
37 for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++) {
38 p->coordReplacement[i] = GL_FALSE;
39 RESET(pb->coordReplacement[i], ctx->bitid);
40 }
41#endif
42
43 p->spriteCoordOrigin = (GLfloat)GL_UPPER_LEFT;
44 RESET(pb->spriteCoordOrigin, ctx->bitid);
45
46 RESET(pb->dirty, ctx->bitid);
47
48 /*
49 *p->aliasedpointsizerange_min = c->aliasedpointsizerange_min;
50 *p->aliasedpointsizerange_max = c->aliasedpointsizerange_max;
51 *p->aliasedpointsizegranularity = c->aliasedpointsizegranularity;
52 *p->smoothpointsizerange_min = c->smoothpointsizerange_min;
53 *p->smoothpointsizerange_max = c->smoothpointsizerange_max;
54 *p->smoothpointgranularity = c->smoothpointgranularity;
55 */
56}
57
58void STATE_APIENTRY crStatePointSize(GLfloat size)
59{
60 CRContext *g = GetCurrentContext();
61 CRPointState *p = &(g->point);
62 CRStateBits *sb = GetCurrentBits();
63 CRPointBits *pb = &(sb->point);
64
65 if (g->current.inBeginEnd)
66 {
67 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPointSize called in begin/end");
68 return;
69 }
70
71 FLUSH();
72
73 if (size <= 0.0f)
74 {
75 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointSize called with size <= 0.0: %f", size);
76 return;
77 }
78
79 p->pointSize = size;
80 DIRTY(pb->size, g->neg_bitid);
81 DIRTY(pb->dirty, g->neg_bitid);
82}
83
84void STATE_APIENTRY crStatePointParameterfARB(GLenum pname, GLfloat param)
85{
86 CRContext *g = GetCurrentContext();
87
88 if (g->current.inBeginEnd)
89 {
90 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfARB called in begin/end");
91 return;
92 }
93
94 FLUSH();
95
96 crStatePointParameterfvARB(pname, &param);
97}
98
99void STATE_APIENTRY crStatePointParameterfvARB(GLenum pname, const GLfloat *params)
100{
101 CRContext *g = GetCurrentContext();
102 CRPointState *p = &(g->point);
103 CRStateBits *sb = GetCurrentBits();
104 CRPointBits *pb = &(sb->point);
105
106 if (g->current.inBeginEnd)
107 {
108 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfvARB called in begin/end");
109 return;
110 }
111
112 FLUSH();
113
114 switch (pname) {
115 case GL_DISTANCE_ATTENUATION_EXT:
116 if (g->extensions.ARB_point_parameters) {
117 p->distanceAttenuation[0] = params[0];
118 p->distanceAttenuation[1] = params[1];
119 p->distanceAttenuation[2] = params[2];
120 DIRTY(pb->distanceAttenuation, g->neg_bitid);
121 }
122 else
123 {
124 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
125 return;
126 }
127 break;
128 case GL_POINT_SIZE_MIN_EXT:
129 if (g->extensions.ARB_point_parameters) {
130 if (params[0] < 0.0F) {
131 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
132 return;
133 }
134 p->minSize = params[0];
135 DIRTY(pb->minSize, g->neg_bitid);
136 }
137 else
138 {
139 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
140 return;
141 }
142 break;
143 case GL_POINT_SIZE_MAX_EXT:
144 if (g->extensions.ARB_point_parameters) {
145 if (params[0] < 0.0F) {
146 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
147 return;
148 }
149 p->maxSize = params[0];
150 DIRTY(pb->maxSize, g->neg_bitid);
151 }
152 else
153 {
154 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
155 return;
156 }
157 break;
158 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
159 if (g->extensions.ARB_point_parameters) {
160 if (params[0] < 0.0F) {
161 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid value: %f", params[0]);
162 return;
163 }
164 p->fadeThresholdSize = params[0];
165 DIRTY(pb->fadeThresholdSize, g->neg_bitid);
166 }
167 else
168 {
169 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
170 return;
171 }
172 break;
173 case GL_POINT_SPRITE_COORD_ORIGIN:
174 {
175 GLenum enmVal = (GLenum)params[0];
176 if (enmVal != GL_LOWER_LEFT && enmVal != GL_UPPER_LEFT) {
177 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glPointParameterfvARB invalid GL_POINT_SPRITE_COORD_ORIGIN value: %f", params[0]);
178 return;
179 }
180 p->spriteCoordOrigin = params[0];
181 DIRTY(pb->spriteCoordOrigin, g->neg_bitid);
182 break;
183 }
184 default:
185 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glPointParameterfvARB invalid enum: %f", pname);
186 return;
187 }
188
189 DIRTY(pb->dirty, g->neg_bitid);
190}
191
192void STATE_APIENTRY crStatePointParameteri(GLenum pname, GLint param)
193{
194 GLfloat f_param = (GLfloat) param;
195 crStatePointParameterfvARB( pname, &f_param );
196}
197
198void STATE_APIENTRY crStatePointParameteriv(GLenum pname, const GLint *params)
199{
200 GLfloat f_param = (GLfloat) (*params);
201 crStatePointParameterfvARB( pname, &f_param );
202}
203
204void crStatePointDiff(CRPointBits *b, CRbitvalue *bitID,
205 CRContext *fromCtx, CRContext *toCtx)
206{
207 CRPointState *from = &(fromCtx->point);
208 CRPointState *to = &(toCtx->point);
209 unsigned int j, i;
210 CRbitvalue nbitID[CR_MAX_BITARRAY];
211 Assert(0);
212 for (j=0;j<CR_MAX_BITARRAY;j++)
213 nbitID[j] = ~bitID[j];
214 i = 0; /* silence compiler */
215 if (CHECKDIRTY(b->enableSmooth, bitID))
216 {
217 glAble able[2];
218 able[0] = diff_api.Disable;
219 able[1] = diff_api.Enable;
220 if (from->pointSmooth != to->pointSmooth)
221 {
222 able[to->pointSmooth](GL_POINT_SMOOTH);
223 from->pointSmooth = to->pointSmooth;
224 }
225 CLEARDIRTY(b->enableSmooth, nbitID);
226 }
227 if (CHECKDIRTY(b->size, bitID))
228 {
229 if (from->pointSize != to->pointSize)
230 {
231 diff_api.PointSize (to->pointSize);
232 from->pointSize = to->pointSize;
233 }
234 CLEARDIRTY(b->size, nbitID);
235 }
236 if (CHECKDIRTY(b->minSize, bitID))
237 {
238 if (from->minSize != to->minSize)
239 {
240 diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
241 from->minSize = to->minSize;
242 }
243 CLEARDIRTY(b->minSize, nbitID);
244 }
245 if (CHECKDIRTY(b->maxSize, bitID))
246 {
247 if (from->maxSize != to->maxSize)
248 {
249 diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
250 from->maxSize = to->maxSize;
251 }
252 CLEARDIRTY(b->maxSize, nbitID);
253 }
254 if (CHECKDIRTY(b->fadeThresholdSize, bitID))
255 {
256 if (from->fadeThresholdSize != to->fadeThresholdSize)
257 {
258 diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
259 from->fadeThresholdSize = to->fadeThresholdSize;
260 }
261 CLEARDIRTY(b->fadeThresholdSize, nbitID);
262 }
263 if (CHECKDIRTY(b->spriteCoordOrigin, bitID))
264 {
265 if (from->spriteCoordOrigin != to->spriteCoordOrigin)
266 {
267 diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
268 from->spriteCoordOrigin = to->spriteCoordOrigin;
269 }
270 CLEARDIRTY(b->spriteCoordOrigin, nbitID);
271 }
272 if (CHECKDIRTY(b->distanceAttenuation, bitID))
273 {
274 if (from->distanceAttenuation[0] != to->distanceAttenuation[0] || from->distanceAttenuation[1] != to->distanceAttenuation[1] || from->distanceAttenuation[2] != to->distanceAttenuation[2]) {
275 diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
276 from->distanceAttenuation[0] = to->distanceAttenuation[0];
277 from->distanceAttenuation[1] = to->distanceAttenuation[1];
278 from->distanceAttenuation[2] = to->distanceAttenuation[2];
279 }
280 CLEARDIRTY(b->distanceAttenuation, nbitID);
281 }
282 if (CHECKDIRTY(b->enableSprite, bitID))
283 {
284 glAble able[2];
285 able[0] = diff_api.Disable;
286 able[1] = diff_api.Enable;
287 if (from->pointSprite != to->pointSprite)
288 {
289 able[to->pointSprite](GL_POINT_SPRITE_ARB);
290 from->pointSprite = to->pointSprite;
291 }
292 CLEARDIRTY(b->enableSprite, nbitID);
293 }
294 {
295 unsigned int activeUnit = (unsigned int) -1;
296 for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++) {
297 if (CHECKDIRTY(b->coordReplacement[i], bitID))
298 {
299 GLint replacement = to->coordReplacement[i];
300 if (activeUnit != i) {
301 diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB );
302 activeUnit = i;
303 }
304 diff_api.TexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &replacement);
305 from->coordReplacement[i] = to->coordReplacement[i];
306 CLEARDIRTY(b->coordReplacement[i], nbitID);
307 }
308 }
309 if (activeUnit != toCtx->texture.curTextureUnit)
310 diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
311 }
312 CLEARDIRTY(b->dirty, nbitID);
313}
314
315void crStatePointSwitch(CRPointBits *b, CRbitvalue *bitID,
316 CRContext *fromCtx, CRContext *toCtx)
317{
318 CRPointState *from = &(fromCtx->point);
319 CRPointState *to = &(toCtx->point);
320 unsigned int j, i;
321 GLboolean fEnabled;
322 CRbitvalue nbitID[CR_MAX_BITARRAY];
323 for (j=0;j<CR_MAX_BITARRAY;j++)
324 nbitID[j] = ~bitID[j];
325 i = 0; /* silence compiler */
326 if (CHECKDIRTY(b->enableSmooth, bitID))
327 {
328 glAble able[2];
329 able[0] = diff_api.Disable;
330 able[1] = diff_api.Enable;
331 if (from->pointSmooth != to->pointSmooth)
332 {
333 able[to->pointSmooth](GL_POINT_SMOOTH);
334 FILLDIRTY(b->enableSmooth);
335 FILLDIRTY(b->dirty);
336 }
337 CLEARDIRTY(b->enableSmooth, nbitID);
338 }
339 if (CHECKDIRTY(b->size, bitID))
340 {
341 if (from->pointSize != to->pointSize)
342 {
343 diff_api.PointSize (to->pointSize);
344 FILLDIRTY(b->size);
345 FILLDIRTY(b->dirty);
346 }
347 CLEARDIRTY(b->size, nbitID);
348 }
349 if (CHECKDIRTY(b->minSize, bitID))
350 {
351 if (from->minSize != to->minSize)
352 {
353 diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
354 FILLDIRTY(b->minSize);
355 FILLDIRTY(b->dirty);
356 }
357 CLEARDIRTY(b->minSize, nbitID);
358 }
359 if (CHECKDIRTY(b->maxSize, bitID))
360 {
361 if (from->maxSize != to->maxSize)
362 {
363 diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
364 FILLDIRTY(b->maxSize);
365 FILLDIRTY(b->dirty);
366 }
367 CLEARDIRTY(b->maxSize, nbitID);
368 }
369 if (CHECKDIRTY(b->fadeThresholdSize, bitID))
370 {
371 if (from->fadeThresholdSize != to->fadeThresholdSize)
372 {
373 diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
374 FILLDIRTY(b->fadeThresholdSize);
375 FILLDIRTY(b->dirty);
376 }
377 CLEARDIRTY(b->fadeThresholdSize, nbitID);
378 }
379 if (CHECKDIRTY(b->spriteCoordOrigin, bitID))
380 {
381 if (from->spriteCoordOrigin != to->spriteCoordOrigin)
382 {
383 diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
384 FILLDIRTY(b->spriteCoordOrigin);
385 FILLDIRTY(b->dirty);
386 }
387 CLEARDIRTY(b->spriteCoordOrigin, nbitID);
388 }
389 if (CHECKDIRTY(b->distanceAttenuation, bitID))
390 {
391 if (from->distanceAttenuation[0] != to->distanceAttenuation[0] || from->distanceAttenuation[1] != to->distanceAttenuation[1] || from->distanceAttenuation[2] != to->distanceAttenuation[2]) {
392 diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
393 FILLDIRTY(b->distanceAttenuation);
394 FILLDIRTY(b->dirty);
395 }
396 CLEARDIRTY(b->distanceAttenuation, nbitID);
397 }
398 fEnabled = from->pointSprite;
399 {
400 unsigned int activeUnit = (unsigned int) -1;
401 for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++) {
402 if (CHECKDIRTY(b->coordReplacement[i], bitID))
403 {
404 if (!fEnabled)
405 {
406 diff_api.Enable(GL_POINT_SPRITE_ARB);
407 fEnabled = GL_TRUE;
408 }
409#if 0
410 /*don't set coord replacement, it will be set just before drawing points when necessary,
411 * to work around gpu driver bugs
412 * See crServerDispatch[Begin|End|Draw*] */
413 GLint replacement = to->coordReplacement[i];
414 if (activeUnit != i) {
415 diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB );
416 activeUnit = i;
417 }
418 diff_api.TexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &replacement);
419#endif
420 CLEARDIRTY(b->coordReplacement[i], nbitID);
421 }
422 }
423 if (activeUnit != toCtx->texture.curTextureUnit)
424 diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
425 }
426 if (CHECKDIRTY(b->enableSprite, bitID))
427 {
428 glAble able[2];
429 able[0] = diff_api.Disable;
430 able[1] = diff_api.Enable;
431 if (fEnabled != to->pointSprite)
432 {
433 able[to->pointSprite](GL_POINT_SPRITE_ARB);
434 FILLDIRTY(b->enableSprite);
435 FILLDIRTY(b->dirty);
436 }
437 CLEARDIRTY(b->enableSprite, nbitID);
438 }
439 else if (fEnabled != to->pointSprite)
440 {
441 glAble able[2];
442 able[0] = diff_api.Disable;
443 able[1] = diff_api.Enable;
444 able[to->pointSprite](GL_POINT_SPRITE_ARB);
445 }
446 CLEARDIRTY(b->dirty, nbitID);
447}
Note: See TracBrowser for help on using the repository browser.

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