VirtualBox

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

Last change on this file since 78375 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 14.8 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(ctx->pStateTracker);
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(PCRStateTracker pState, GLfloat size)
59{
60 CRContext *g = GetCurrentContext(pState);
61 CRPointState *p = &(g->point);
62 CRStateBits *sb = GetCurrentBits(pState);
63 CRPointBits *pb = &(sb->point);
64
65 if (g->current.inBeginEnd)
66 {
67 crStateError(pState, __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(pState, __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(PCRStateTracker pState, GLenum pname, GLfloat param)
85{
86 CRContext *g = GetCurrentContext(pState);
87
88 if (g->current.inBeginEnd)
89 {
90 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glPointParameterfARB called in begin/end");
91 return;
92 }
93
94 FLUSH();
95
96 crStatePointParameterfvARB(pState, pname, &param);
97}
98
99void STATE_APIENTRY crStatePointParameterfvARB(PCRStateTracker pState, GLenum pname, const GLfloat *params)
100{
101 CRContext *g = GetCurrentContext(pState);
102 CRPointState *p = &(g->point);
103 CRStateBits *sb = GetCurrentBits(pState);
104 CRPointBits *pb = &(sb->point);
105
106 if (g->current.inBeginEnd)
107 {
108 crStateError(pState, __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(pState, __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(pState, __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(pState, __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(pState, __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(pState, __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(pState, __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(pState, __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(pState, __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(pState, __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(PCRStateTracker pState, GLenum pname, GLint param)
193{
194 GLfloat f_param = (GLfloat) param;
195 crStatePointParameterfvARB(pState, pname, &f_param );
196}
197
198void STATE_APIENTRY crStatePointParameteriv(PCRStateTracker pState, GLenum pname, const GLint *params)
199{
200 GLfloat f_param = (GLfloat) (*params);
201 crStatePointParameterfvARB(pState, pname, &f_param );
202}
203
204void crStatePointDiff(CRPointBits *b, CRbitvalue *bitID,
205 CRContext *fromCtx, CRContext *toCtx)
206{
207 PCRStateTracker pState = fromCtx->pStateTracker;
208 CRPointState *from = &(fromCtx->point);
209 CRPointState *to = &(toCtx->point);
210 unsigned int j, i;
211 CRbitvalue nbitID[CR_MAX_BITARRAY];
212 Assert(0); /** @todo Is this never called? */
213
214 CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
215
216 for (j=0;j<CR_MAX_BITARRAY;j++)
217 nbitID[j] = ~bitID[j];
218 i = 0; /* silence compiler */
219 if (CHECKDIRTY(b->enableSmooth, bitID))
220 {
221 glAble able[2];
222 able[0] = pState->diff_api.Disable;
223 able[1] = pState->diff_api.Enable;
224 if (from->pointSmooth != to->pointSmooth)
225 {
226 able[to->pointSmooth](GL_POINT_SMOOTH);
227 from->pointSmooth = to->pointSmooth;
228 }
229 CLEARDIRTY(b->enableSmooth, nbitID);
230 }
231 if (CHECKDIRTY(b->size, bitID))
232 {
233 if (from->pointSize != to->pointSize)
234 {
235 pState->diff_api.PointSize (to->pointSize);
236 from->pointSize = to->pointSize;
237 }
238 CLEARDIRTY(b->size, nbitID);
239 }
240 if (CHECKDIRTY(b->minSize, bitID))
241 {
242 if (from->minSize != to->minSize)
243 {
244 pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
245 from->minSize = to->minSize;
246 }
247 CLEARDIRTY(b->minSize, nbitID);
248 }
249 if (CHECKDIRTY(b->maxSize, bitID))
250 {
251 if (from->maxSize != to->maxSize)
252 {
253 pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
254 from->maxSize = to->maxSize;
255 }
256 CLEARDIRTY(b->maxSize, nbitID);
257 }
258 if (CHECKDIRTY(b->fadeThresholdSize, bitID))
259 {
260 if (from->fadeThresholdSize != to->fadeThresholdSize)
261 {
262 pState->diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
263 from->fadeThresholdSize = to->fadeThresholdSize;
264 }
265 CLEARDIRTY(b->fadeThresholdSize, nbitID);
266 }
267 if (CHECKDIRTY(b->spriteCoordOrigin, bitID))
268 {
269 if (from->spriteCoordOrigin != to->spriteCoordOrigin)
270 {
271 pState->diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
272 from->spriteCoordOrigin = to->spriteCoordOrigin;
273 }
274 CLEARDIRTY(b->spriteCoordOrigin, nbitID);
275 }
276 if (CHECKDIRTY(b->distanceAttenuation, bitID))
277 {
278 if (from->distanceAttenuation[0] != to->distanceAttenuation[0] || from->distanceAttenuation[1] != to->distanceAttenuation[1] || from->distanceAttenuation[2] != to->distanceAttenuation[2]) {
279 pState->diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
280 from->distanceAttenuation[0] = to->distanceAttenuation[0];
281 from->distanceAttenuation[1] = to->distanceAttenuation[1];
282 from->distanceAttenuation[2] = to->distanceAttenuation[2];
283 }
284 CLEARDIRTY(b->distanceAttenuation, nbitID);
285 }
286 if (CHECKDIRTY(b->enableSprite, bitID))
287 {
288 glAble able[2];
289 able[0] = pState->diff_api.Disable;
290 able[1] = pState->diff_api.Enable;
291 if (from->pointSprite != to->pointSprite)
292 {
293 able[to->pointSprite](GL_POINT_SPRITE_ARB);
294 from->pointSprite = to->pointSprite;
295 }
296 CLEARDIRTY(b->enableSprite, nbitID);
297 }
298 {
299 unsigned int activeUnit = (unsigned int) -1;
300 for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++) {
301 if (CHECKDIRTY(b->coordReplacement[i], bitID))
302 {
303 GLint replacement = to->coordReplacement[i];
304 if (activeUnit != i) {
305 pState->diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB );
306 activeUnit = i;
307 }
308 pState->diff_api.TexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &replacement);
309 from->coordReplacement[i] = to->coordReplacement[i];
310 CLEARDIRTY(b->coordReplacement[i], nbitID);
311 }
312 }
313 if (activeUnit != toCtx->texture.curTextureUnit)
314 pState->diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
315 }
316 CLEARDIRTY(b->dirty, nbitID);
317}
318
319void crStatePointSwitch(CRPointBits *b, CRbitvalue *bitID,
320 CRContext *fromCtx, CRContext *toCtx)
321{
322 PCRStateTracker pState = fromCtx->pStateTracker;
323 CRPointState *from = &(fromCtx->point);
324 CRPointState *to = &(toCtx->point);
325 unsigned int j, i;
326 GLboolean fEnabled;
327 CRbitvalue nbitID[CR_MAX_BITARRAY];
328
329 CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
330
331 for (j=0;j<CR_MAX_BITARRAY;j++)
332 nbitID[j] = ~bitID[j];
333 i = 0; /* silence compiler */
334 if (CHECKDIRTY(b->enableSmooth, bitID))
335 {
336 glAble able[2];
337 able[0] = pState->diff_api.Disable;
338 able[1] = pState->diff_api.Enable;
339 if (from->pointSmooth != to->pointSmooth)
340 {
341 able[to->pointSmooth](GL_POINT_SMOOTH);
342 FILLDIRTY(b->enableSmooth);
343 FILLDIRTY(b->dirty);
344 }
345 CLEARDIRTY(b->enableSmooth, nbitID);
346 }
347 if (CHECKDIRTY(b->size, bitID))
348 {
349 if (from->pointSize != to->pointSize)
350 {
351 pState->diff_api.PointSize (to->pointSize);
352 FILLDIRTY(b->size);
353 FILLDIRTY(b->dirty);
354 }
355 CLEARDIRTY(b->size, nbitID);
356 }
357 if (CHECKDIRTY(b->minSize, bitID))
358 {
359 if (from->minSize != to->minSize)
360 {
361 pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MIN_ARB, to->minSize);
362 FILLDIRTY(b->minSize);
363 FILLDIRTY(b->dirty);
364 }
365 CLEARDIRTY(b->minSize, nbitID);
366 }
367 if (CHECKDIRTY(b->maxSize, bitID))
368 {
369 if (from->maxSize != to->maxSize)
370 {
371 pState->diff_api.PointParameterfARB (GL_POINT_SIZE_MAX_ARB, to->maxSize);
372 FILLDIRTY(b->maxSize);
373 FILLDIRTY(b->dirty);
374 }
375 CLEARDIRTY(b->maxSize, nbitID);
376 }
377 if (CHECKDIRTY(b->fadeThresholdSize, bitID))
378 {
379 if (from->fadeThresholdSize != to->fadeThresholdSize)
380 {
381 pState->diff_api.PointParameterfARB (GL_POINT_FADE_THRESHOLD_SIZE_ARB, to->fadeThresholdSize);
382 FILLDIRTY(b->fadeThresholdSize);
383 FILLDIRTY(b->dirty);
384 }
385 CLEARDIRTY(b->fadeThresholdSize, nbitID);
386 }
387 if (CHECKDIRTY(b->spriteCoordOrigin, bitID))
388 {
389 if (from->spriteCoordOrigin != to->spriteCoordOrigin)
390 {
391 pState->diff_api.PointParameterfARB (GL_POINT_SPRITE_COORD_ORIGIN, to->spriteCoordOrigin);
392 FILLDIRTY(b->spriteCoordOrigin);
393 FILLDIRTY(b->dirty);
394 }
395 CLEARDIRTY(b->spriteCoordOrigin, nbitID);
396 }
397 if (CHECKDIRTY(b->distanceAttenuation, bitID))
398 {
399 if (from->distanceAttenuation[0] != to->distanceAttenuation[0] || from->distanceAttenuation[1] != to->distanceAttenuation[1] || from->distanceAttenuation[2] != to->distanceAttenuation[2]) {
400 pState->diff_api.PointParameterfvARB (GL_POINT_DISTANCE_ATTENUATION_ARB, to->distanceAttenuation);
401 FILLDIRTY(b->distanceAttenuation);
402 FILLDIRTY(b->dirty);
403 }
404 CLEARDIRTY(b->distanceAttenuation, nbitID);
405 }
406 fEnabled = from->pointSprite;
407 {
408 unsigned int activeUnit = (unsigned int) -1;
409 for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++) {
410 if (CHECKDIRTY(b->coordReplacement[i], bitID))
411 {
412 if (!fEnabled)
413 {
414 pState->diff_api.Enable(GL_POINT_SPRITE_ARB);
415 fEnabled = GL_TRUE;
416 }
417#if 0
418 /*don't set coord replacement, it will be set just before drawing points when necessary,
419 * to work around gpu driver bugs
420 * See crServerDispatch[Begin|End|Draw*] */
421 GLint replacement = to->coordReplacement[i];
422 if (activeUnit != i) {
423 diff_api.ActiveTextureARB(i + GL_TEXTURE0_ARB );
424 activeUnit = i;
425 }
426 diff_api.TexEnviv(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, &replacement);
427#endif
428 CLEARDIRTY(b->coordReplacement[i], nbitID);
429 }
430 }
431 if (activeUnit != toCtx->texture.curTextureUnit)
432 pState->diff_api.ActiveTextureARB(GL_TEXTURE0 + toCtx->texture.curTextureUnit);
433 }
434 if (CHECKDIRTY(b->enableSprite, bitID))
435 {
436 glAble able[2];
437 able[0] = pState->diff_api.Disable;
438 able[1] = pState->diff_api.Enable;
439 if (fEnabled != to->pointSprite)
440 {
441 able[to->pointSprite](GL_POINT_SPRITE_ARB);
442 FILLDIRTY(b->enableSprite);
443 FILLDIRTY(b->dirty);
444 }
445 CLEARDIRTY(b->enableSprite, nbitID);
446 }
447 else if (fEnabled != to->pointSprite)
448 {
449 glAble able[2];
450 able[0] = pState->diff_api.Disable;
451 able[1] = pState->diff_api.Enable;
452 able[to->pointSprite](GL_POINT_SPRITE_ARB);
453 }
454 CLEARDIRTY(b->dirty, nbitID);
455}
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