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 <stdio.h>
|
---|
8 | #include "state.h"
|
---|
9 | #include "state/cr_statetypes.h"
|
---|
10 | #include "state_internals.h"
|
---|
11 |
|
---|
12 | void crStateBufferInit (CRContext *ctx)
|
---|
13 | {
|
---|
14 | CRBufferState *b = &ctx->buffer;
|
---|
15 | CRStateBits *sb = GetCurrentBits();
|
---|
16 | CRBufferBits *bb = &(sb->buffer);
|
---|
17 | GLcolorf zero_colorf = {0.0f, 0.0f, 0.0f, 0.0f};
|
---|
18 |
|
---|
19 | b->width = 640;
|
---|
20 | b->height = 480;
|
---|
21 | b->storedWidth = 0;
|
---|
22 | b->storedHeight = 0;
|
---|
23 | b->pFrontImg = NULL;
|
---|
24 | b->pBackImg = NULL;
|
---|
25 |
|
---|
26 | b->depthTest = GL_FALSE;
|
---|
27 | b->blend = GL_FALSE;
|
---|
28 | b->alphaTest = GL_FALSE;
|
---|
29 | b->dither = GL_TRUE;
|
---|
30 | RESET(bb->enable, ctx->bitid);
|
---|
31 |
|
---|
32 | b->logicOp = GL_FALSE;
|
---|
33 | RESET(bb->logicOp, ctx->bitid);
|
---|
34 | b->indexLogicOp = GL_FALSE;
|
---|
35 | RESET(bb->indexLogicOp, ctx->bitid);
|
---|
36 | b->depthMask = GL_TRUE;
|
---|
37 | RESET(bb->depthMask, ctx->bitid);
|
---|
38 |
|
---|
39 | b->alphaTestFunc = GL_ALWAYS;
|
---|
40 | b->alphaTestRef = 0;
|
---|
41 | RESET(bb->alphaFunc, ctx->bitid);
|
---|
42 | b->depthFunc = GL_LESS;
|
---|
43 | RESET(bb->depthFunc, ctx->bitid);
|
---|
44 | b->blendSrcRGB = GL_ONE;
|
---|
45 | b->blendDstRGB = GL_ZERO;
|
---|
46 | RESET(bb->blendFunc, ctx->bitid);
|
---|
47 | #ifdef CR_EXT_blend_func_separate
|
---|
48 | b->blendSrcA = GL_ONE;
|
---|
49 | b->blendDstA = GL_ZERO;
|
---|
50 | RESET(bb->blendFuncSeparate, ctx->bitid);
|
---|
51 | #endif
|
---|
52 | b->logicOpMode = GL_COPY;
|
---|
53 | b->drawBuffer = GL_BACK;
|
---|
54 | RESET(bb->drawBuffer, ctx->bitid);
|
---|
55 | b->readBuffer = GL_BACK;
|
---|
56 | RESET(bb->readBuffer, ctx->bitid);
|
---|
57 | b->indexWriteMask = 0xffffffff;
|
---|
58 | RESET(bb->indexMask, ctx->bitid);
|
---|
59 | b->colorWriteMask.r = GL_TRUE;
|
---|
60 | b->colorWriteMask.g = GL_TRUE;
|
---|
61 | b->colorWriteMask.b = GL_TRUE;
|
---|
62 | b->colorWriteMask.a = GL_TRUE;
|
---|
63 | RESET(bb->colorWriteMask, ctx->bitid);
|
---|
64 | b->colorClearValue = zero_colorf;
|
---|
65 | RESET(bb->clearColor, ctx->bitid);
|
---|
66 | b->indexClearValue = 0;
|
---|
67 | RESET(bb->clearIndex, ctx->bitid);
|
---|
68 | b->depthClearValue = (GLdefault) 1.0;
|
---|
69 | RESET(bb->clearDepth, ctx->bitid);
|
---|
70 | b->accumClearValue = zero_colorf;
|
---|
71 | RESET(bb->clearAccum, ctx->bitid);
|
---|
72 |
|
---|
73 | #ifdef CR_EXT_blend_color
|
---|
74 | b->blendColor = zero_colorf;
|
---|
75 | RESET(bb->blendColor, ctx->bitid);
|
---|
76 | #endif
|
---|
77 | #if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
|
---|
78 | b->blendEquation = GL_FUNC_ADD_EXT;
|
---|
79 | RESET(bb->blendEquation, ctx->bitid);
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | RESET(bb->dirty, ctx->bitid);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void STATE_APIENTRY crStateAlphaFunc (GLenum func, GLclampf ref)
|
---|
86 | {
|
---|
87 | CRContext *g = GetCurrentContext();
|
---|
88 | CRBufferState *b = &(g->buffer);
|
---|
89 | CRStateBits *sb = GetCurrentBits();
|
---|
90 | CRBufferBits *bb = &(sb->buffer);
|
---|
91 |
|
---|
92 | if (g->current.inBeginEnd)
|
---|
93 | {
|
---|
94 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glAlphaFunc called in begin/end");
|
---|
95 | return;
|
---|
96 | }
|
---|
97 |
|
---|
98 | FLUSH();
|
---|
99 |
|
---|
100 | switch (func)
|
---|
101 | {
|
---|
102 | case GL_NEVER:
|
---|
103 | case GL_LESS:
|
---|
104 | case GL_EQUAL:
|
---|
105 | case GL_LEQUAL:
|
---|
106 | case GL_GREATER:
|
---|
107 | case GL_GEQUAL:
|
---|
108 | case GL_NOTEQUAL:
|
---|
109 | case GL_ALWAYS:
|
---|
110 | break;
|
---|
111 | default:
|
---|
112 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glAlphaFunc: Invalid func: %d", func);
|
---|
113 | return;
|
---|
114 | }
|
---|
115 |
|
---|
116 | if (ref < 0.0f) ref = 0.0f;
|
---|
117 | if (ref > 1.0f) ref = 1.0f;
|
---|
118 |
|
---|
119 | b->alphaTestFunc = func;
|
---|
120 | b->alphaTestRef = ref;
|
---|
121 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
122 | DIRTY(bb->alphaFunc, g->neg_bitid);
|
---|
123 | }
|
---|
124 |
|
---|
125 | void STATE_APIENTRY crStateDepthFunc (GLenum func)
|
---|
126 | {
|
---|
127 | CRContext *g = GetCurrentContext();
|
---|
128 | CRBufferState *b = &(g->buffer);
|
---|
129 | CRStateBits *sb = GetCurrentBits();
|
---|
130 | CRBufferBits *bb = &(sb->buffer);
|
---|
131 |
|
---|
132 | if (g->current.inBeginEnd)
|
---|
133 | {
|
---|
134 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDepthFunc called in begin/end");
|
---|
135 | return;
|
---|
136 | }
|
---|
137 |
|
---|
138 | FLUSH();
|
---|
139 |
|
---|
140 | switch (func)
|
---|
141 | {
|
---|
142 | case GL_NEVER:
|
---|
143 | case GL_LESS:
|
---|
144 | case GL_EQUAL:
|
---|
145 | case GL_LEQUAL:
|
---|
146 | case GL_GREATER:
|
---|
147 | case GL_NOTEQUAL:
|
---|
148 | case GL_GEQUAL:
|
---|
149 | case GL_ALWAYS:
|
---|
150 | break;
|
---|
151 | default:
|
---|
152 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glDepthFunc: Invalid func: %d", func);
|
---|
153 | return;
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | b->depthFunc = func;
|
---|
158 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
159 | DIRTY(bb->depthFunc, g->neg_bitid);
|
---|
160 | }
|
---|
161 |
|
---|
162 | void STATE_APIENTRY crStateBlendFunc (GLenum sfactor, GLenum dfactor)
|
---|
163 | {
|
---|
164 | CRContext *g = GetCurrentContext();
|
---|
165 | CRBufferState *b = &(g->buffer);
|
---|
166 | CRStateBits *sb = GetCurrentBits();
|
---|
167 | CRBufferBits *bb = &(sb->buffer);
|
---|
168 |
|
---|
169 | if (g->current.inBeginEnd)
|
---|
170 | {
|
---|
171 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBlendFunc called in begin/end");
|
---|
172 | return;
|
---|
173 | }
|
---|
174 |
|
---|
175 | FLUSH();
|
---|
176 |
|
---|
177 | switch (sfactor)
|
---|
178 | {
|
---|
179 | case GL_ZERO:
|
---|
180 | case GL_ONE:
|
---|
181 | case GL_DST_COLOR:
|
---|
182 | case GL_ONE_MINUS_DST_COLOR:
|
---|
183 | case GL_SRC_ALPHA:
|
---|
184 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
185 | case GL_DST_ALPHA:
|
---|
186 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
187 | case GL_SRC_ALPHA_SATURATE:
|
---|
188 | break; /* OK */
|
---|
189 | #ifdef CR_EXT_blend_color
|
---|
190 | case GL_CONSTANT_COLOR_EXT:
|
---|
191 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
192 | case GL_CONSTANT_ALPHA_EXT:
|
---|
193 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
194 | if (g->extensions.EXT_blend_color)
|
---|
195 | break; /* OK */
|
---|
196 | #endif
|
---|
197 | default:
|
---|
198 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactor passed to glBlendFunc: %d", sfactor);
|
---|
199 | return;
|
---|
200 | }
|
---|
201 |
|
---|
202 | switch (dfactor)
|
---|
203 | {
|
---|
204 | case GL_ZERO:
|
---|
205 | case GL_ONE:
|
---|
206 | case GL_SRC_COLOR:
|
---|
207 | case GL_ONE_MINUS_SRC_COLOR:
|
---|
208 | case GL_SRC_ALPHA:
|
---|
209 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
210 | case GL_DST_ALPHA:
|
---|
211 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
212 | break; /* OK */
|
---|
213 | #ifdef CR_EXT_blend_color
|
---|
214 | case GL_CONSTANT_COLOR_EXT:
|
---|
215 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
216 | case GL_CONSTANT_ALPHA_EXT:
|
---|
217 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
218 | if (g->extensions.EXT_blend_color)
|
---|
219 | break; /* OK */
|
---|
220 | #endif
|
---|
221 | default:
|
---|
222 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactor passed to glBlendFunc: %d", dfactor);
|
---|
223 | return;
|
---|
224 | }
|
---|
225 |
|
---|
226 | b->blendSrcRGB = sfactor;
|
---|
227 | b->blendDstRGB = dfactor;
|
---|
228 | b->blendSrcA = sfactor;
|
---|
229 | b->blendDstA = dfactor;
|
---|
230 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
231 | DIRTY(bb->blendFunc, g->neg_bitid);
|
---|
232 | }
|
---|
233 |
|
---|
234 | void STATE_APIENTRY crStateBlendColorEXT( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
|
---|
235 | {
|
---|
236 | CRContext *g = GetCurrentContext();
|
---|
237 | CRBufferState *b = &(g->buffer);
|
---|
238 | CRStateBits *sb = GetCurrentBits();
|
---|
239 | CRBufferBits *bb = &(sb->buffer);
|
---|
240 |
|
---|
241 | if (g->current.inBeginEnd)
|
---|
242 | {
|
---|
243 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendColorEXT called inside a Begin/End" );
|
---|
244 | return;
|
---|
245 | }
|
---|
246 |
|
---|
247 | b->blendColor.r = red;
|
---|
248 | b->blendColor.g = green;
|
---|
249 | b->blendColor.b = blue;
|
---|
250 | b->blendColor.a = alpha;
|
---|
251 | DIRTY(bb->blendColor, g->neg_bitid);
|
---|
252 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
253 | }
|
---|
254 |
|
---|
255 | #ifdef CR_EXT_blend_func_separate
|
---|
256 | void STATE_APIENTRY crStateBlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA )
|
---|
257 | {
|
---|
258 | CRContext *g = GetCurrentContext();
|
---|
259 | CRBufferState *b = &(g->buffer);
|
---|
260 | CRStateBits *sb = GetCurrentBits();
|
---|
261 | CRBufferBits *bb = &(sb->buffer);
|
---|
262 |
|
---|
263 | if (g->current.inBeginEnd)
|
---|
264 | {
|
---|
265 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendFuncSeparateEXT called inside a Begin/End" );
|
---|
266 | return;
|
---|
267 | }
|
---|
268 |
|
---|
269 | FLUSH();
|
---|
270 |
|
---|
271 | switch (sfactorRGB)
|
---|
272 | {
|
---|
273 | case GL_ZERO:
|
---|
274 | case GL_ONE:
|
---|
275 | case GL_DST_COLOR:
|
---|
276 | case GL_ONE_MINUS_DST_COLOR:
|
---|
277 | case GL_SRC_ALPHA:
|
---|
278 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
279 | case GL_DST_ALPHA:
|
---|
280 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
281 | case GL_SRC_ALPHA_SATURATE:
|
---|
282 | break; /* OK */
|
---|
283 | #ifdef CR_EXT_blend_color
|
---|
284 | case GL_CONSTANT_COLOR_EXT:
|
---|
285 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
286 | case GL_CONSTANT_ALPHA_EXT:
|
---|
287 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
288 | if (g->extensions.EXT_blend_color)
|
---|
289 | break; /* OK */
|
---|
290 | #endif
|
---|
291 | default:
|
---|
292 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorRGB passed to glBlendFuncSeparateEXT: %d", sfactorRGB);
|
---|
293 | return;
|
---|
294 | }
|
---|
295 |
|
---|
296 | switch (sfactorA)
|
---|
297 | {
|
---|
298 | case GL_ZERO:
|
---|
299 | case GL_ONE:
|
---|
300 | case GL_DST_COLOR:
|
---|
301 | case GL_ONE_MINUS_DST_COLOR:
|
---|
302 | case GL_SRC_ALPHA:
|
---|
303 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
304 | case GL_DST_ALPHA:
|
---|
305 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
306 | case GL_SRC_ALPHA_SATURATE:
|
---|
307 | break; /* OK */
|
---|
308 | #ifdef CR_EXT_blend_color
|
---|
309 | case GL_CONSTANT_COLOR_EXT:
|
---|
310 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
311 | case GL_CONSTANT_ALPHA_EXT:
|
---|
312 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
313 | if (g->extensions.EXT_blend_color)
|
---|
314 | break; /* OK */
|
---|
315 | #endif
|
---|
316 | default:
|
---|
317 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorA passed to glBlendFuncSeparateEXT: %d", sfactorA);
|
---|
318 | return;
|
---|
319 | }
|
---|
320 |
|
---|
321 | switch (dfactorRGB)
|
---|
322 | {
|
---|
323 | case GL_ZERO:
|
---|
324 | case GL_ONE:
|
---|
325 | case GL_SRC_COLOR:
|
---|
326 | case GL_DST_COLOR:
|
---|
327 | case GL_ONE_MINUS_DST_COLOR:
|
---|
328 | case GL_ONE_MINUS_SRC_COLOR:
|
---|
329 | case GL_SRC_ALPHA:
|
---|
330 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
331 | case GL_DST_ALPHA:
|
---|
332 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
333 | case GL_SRC_ALPHA_SATURATE:
|
---|
334 | break; /* OK */
|
---|
335 | #ifdef CR_EXT_blend_color
|
---|
336 | case GL_CONSTANT_COLOR_EXT:
|
---|
337 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
338 | case GL_CONSTANT_ALPHA_EXT:
|
---|
339 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
340 | if (g->extensions.EXT_blend_color)
|
---|
341 | break; /* OK */
|
---|
342 | #endif
|
---|
343 | default:
|
---|
344 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorRGB passed to glBlendFuncSeparateEXT: %d", dfactorRGB);
|
---|
345 | return;
|
---|
346 | }
|
---|
347 |
|
---|
348 | switch (dfactorA)
|
---|
349 | {
|
---|
350 | case GL_ZERO:
|
---|
351 | case GL_ONE:
|
---|
352 | case GL_DST_COLOR:
|
---|
353 | case GL_SRC_COLOR:
|
---|
354 | case GL_ONE_MINUS_SRC_COLOR:
|
---|
355 | case GL_ONE_MINUS_DST_COLOR:
|
---|
356 | case GL_SRC_ALPHA:
|
---|
357 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
358 | case GL_DST_ALPHA:
|
---|
359 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
360 | case GL_SRC_ALPHA_SATURATE:
|
---|
361 | break; /* OK */
|
---|
362 | #ifdef CR_EXT_blend_color
|
---|
363 | case GL_CONSTANT_COLOR_EXT:
|
---|
364 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
365 | case GL_CONSTANT_ALPHA_EXT:
|
---|
366 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
367 | if (g->extensions.EXT_blend_color)
|
---|
368 | break; /* OK */
|
---|
369 | #endif
|
---|
370 | default:
|
---|
371 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorA passed to glBlendFuncSeparateEXT: %d", dfactorA);
|
---|
372 | return;
|
---|
373 | }
|
---|
374 |
|
---|
375 | b->blendSrcRGB = sfactorRGB;
|
---|
376 | b->blendDstRGB = dfactorRGB;
|
---|
377 | b->blendSrcA = sfactorA;
|
---|
378 | b->blendDstA = dfactorA;
|
---|
379 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
380 | DIRTY(bb->blendFuncSeparate, g->neg_bitid);
|
---|
381 | }
|
---|
382 | #endif
|
---|
383 |
|
---|
384 | void STATE_APIENTRY crStateBlendEquationEXT( GLenum mode )
|
---|
385 | {
|
---|
386 | CRContext *g = GetCurrentContext();
|
---|
387 | CRBufferState *b = &(g->buffer);
|
---|
388 | CRStateBits *sb = GetCurrentBits();
|
---|
389 | CRBufferBits *bb = &(sb->buffer);
|
---|
390 |
|
---|
391 | if( g->current.inBeginEnd )
|
---|
392 | {
|
---|
393 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendEquationEXT called inside a Begin/End" );
|
---|
394 | return;
|
---|
395 | }
|
---|
396 | switch( mode )
|
---|
397 | {
|
---|
398 | #if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
|
---|
399 | case GL_FUNC_ADD_EXT:
|
---|
400 | #ifdef CR_EXT_blend_subtract
|
---|
401 | case GL_FUNC_SUBTRACT_EXT:
|
---|
402 | case GL_FUNC_REVERSE_SUBTRACT_EXT:
|
---|
403 | #endif /* CR_EXT_blend_subtract */
|
---|
404 | #ifdef CR_EXT_blend_minmax
|
---|
405 | case GL_MIN_EXT:
|
---|
406 | case GL_MAX_EXT:
|
---|
407 | #endif /* CR_EXT_blend_minmax */
|
---|
408 | #ifdef CR_EXT_blend_logic_op
|
---|
409 | case GL_LOGIC_OP:
|
---|
410 | #endif /* CR_EXT_blend_logic_op */
|
---|
411 | b->blendEquation = mode;
|
---|
412 | break;
|
---|
413 | #endif /* defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op) */
|
---|
414 | default:
|
---|
415 | crStateError( __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
416 | "BlendEquationEXT: mode called with illegal parameter: 0x%x", (GLenum) mode );
|
---|
417 | return;
|
---|
418 | }
|
---|
419 | DIRTY(bb->blendEquation, g->neg_bitid);
|
---|
420 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
421 | }
|
---|
422 |
|
---|
423 | void STATE_APIENTRY crStateLogicOp (GLenum opcode)
|
---|
424 | {
|
---|
425 | CRContext *g = GetCurrentContext();
|
---|
426 | CRBufferState *b = &(g->buffer);
|
---|
427 | CRStateBits *sb = GetCurrentBits();
|
---|
428 | CRBufferBits *bb = &(sb->buffer);
|
---|
429 |
|
---|
430 | if (g->current.inBeginEnd)
|
---|
431 | {
|
---|
432 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glLogicOp called in begin/end");
|
---|
433 | return;
|
---|
434 | }
|
---|
435 |
|
---|
436 | FLUSH();
|
---|
437 |
|
---|
438 | switch (opcode)
|
---|
439 | {
|
---|
440 | case GL_CLEAR:
|
---|
441 | case GL_SET:
|
---|
442 | case GL_COPY:
|
---|
443 | case GL_COPY_INVERTED:
|
---|
444 | case GL_NOOP:
|
---|
445 | case GL_INVERT:
|
---|
446 | case GL_AND:
|
---|
447 | case GL_NAND:
|
---|
448 | case GL_OR:
|
---|
449 | case GL_NOR:
|
---|
450 | case GL_XOR:
|
---|
451 | case GL_EQUIV:
|
---|
452 | case GL_AND_REVERSE:
|
---|
453 | case GL_AND_INVERTED:
|
---|
454 | case GL_OR_REVERSE:
|
---|
455 | case GL_OR_INVERTED:
|
---|
456 | break;
|
---|
457 | default:
|
---|
458 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLogicOp called with bogus opcode: %d", opcode);
|
---|
459 | return;
|
---|
460 | }
|
---|
461 |
|
---|
462 | b->logicOpMode = opcode;
|
---|
463 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
464 | DIRTY(bb->logicOp, g->neg_bitid);
|
---|
465 | DIRTY(bb->indexLogicOp, g->neg_bitid);
|
---|
466 | }
|
---|
467 |
|
---|
468 | void STATE_APIENTRY crStateDrawBuffer (GLenum mode)
|
---|
469 | {
|
---|
470 | CRContext *g = GetCurrentContext();
|
---|
471 | CRBufferState *b = &(g->buffer);
|
---|
472 | CRStateBits *sb = GetCurrentBits();
|
---|
473 | CRBufferBits *bb = &(sb->buffer);
|
---|
474 |
|
---|
475 | if (g->current.inBeginEnd)
|
---|
476 | {
|
---|
477 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer called in begin/end");
|
---|
478 | return;
|
---|
479 | }
|
---|
480 |
|
---|
481 | FLUSH();
|
---|
482 |
|
---|
483 | switch (mode)
|
---|
484 | {
|
---|
485 | case GL_NONE:
|
---|
486 | break;
|
---|
487 | case GL_FRONT_LEFT:
|
---|
488 | case GL_FRONT_RIGHT:
|
---|
489 | case GL_BACK_LEFT:
|
---|
490 | case GL_BACK_RIGHT:
|
---|
491 | case GL_FRONT:
|
---|
492 | case GL_BACK:
|
---|
493 | case GL_LEFT:
|
---|
494 | case GL_RIGHT:
|
---|
495 | case GL_FRONT_AND_BACK:
|
---|
496 | case GL_AUX0:
|
---|
497 | case GL_AUX1:
|
---|
498 | case GL_AUX2:
|
---|
499 | case GL_AUX3:
|
---|
500 | if (g->framebufferobject.drawFB)
|
---|
501 | {
|
---|
502 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is active");
|
---|
503 | return;
|
---|
504 | }
|
---|
505 | break;
|
---|
506 | default:
|
---|
507 | if (mode>=GL_COLOR_ATTACHMENT0_EXT && mode<=GL_COLOR_ATTACHMENT15_EXT)
|
---|
508 | {
|
---|
509 | if (!g->framebufferobject.drawFB)
|
---|
510 | {
|
---|
511 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is inactive");
|
---|
512 | return;
|
---|
513 | }
|
---|
514 | }
|
---|
515 | else
|
---|
516 | {
|
---|
517 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glDrawBuffer called with bogus mode: %d", mode);
|
---|
518 | return;
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | if (g->framebufferobject.drawFB)
|
---|
523 | {
|
---|
524 | g->framebufferobject.drawFB->drawbuffer[0] = mode;
|
---|
525 | }
|
---|
526 | else
|
---|
527 | {
|
---|
528 | b->drawBuffer = mode;
|
---|
529 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
530 | DIRTY(bb->drawBuffer, g->neg_bitid);
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | void STATE_APIENTRY crStateReadBuffer (GLenum mode)
|
---|
535 | {
|
---|
536 | CRContext *g = GetCurrentContext();
|
---|
537 | CRBufferState *b = &(g->buffer);
|
---|
538 | CRStateBits *sb = GetCurrentBits();
|
---|
539 | CRBufferBits *bb = &(sb->buffer);
|
---|
540 |
|
---|
541 | if (g->current.inBeginEnd)
|
---|
542 | {
|
---|
543 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
|
---|
544 | return;
|
---|
545 | }
|
---|
546 |
|
---|
547 | FLUSH();
|
---|
548 |
|
---|
549 | switch (mode)
|
---|
550 | {
|
---|
551 | case GL_NONE:
|
---|
552 | break;
|
---|
553 | case GL_FRONT_LEFT:
|
---|
554 | case GL_FRONT_RIGHT:
|
---|
555 | case GL_BACK_LEFT:
|
---|
556 | case GL_BACK_RIGHT:
|
---|
557 | case GL_FRONT:
|
---|
558 | case GL_BACK:
|
---|
559 | case GL_LEFT:
|
---|
560 | case GL_RIGHT:
|
---|
561 | case GL_FRONT_AND_BACK:
|
---|
562 | case GL_AUX0:
|
---|
563 | case GL_AUX1:
|
---|
564 | case GL_AUX2:
|
---|
565 | case GL_AUX3:
|
---|
566 | if (g->framebufferobject.readFB)
|
---|
567 | {
|
---|
568 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is active");
|
---|
569 | return;
|
---|
570 | }
|
---|
571 | break;
|
---|
572 | default:
|
---|
573 | if (mode>=GL_COLOR_ATTACHMENT0_EXT && mode<=GL_COLOR_ATTACHMENT15_EXT)
|
---|
574 | {
|
---|
575 | if (!g->framebufferobject.readFB)
|
---|
576 | {
|
---|
577 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is inactive");
|
---|
578 | return;
|
---|
579 | }
|
---|
580 | else
|
---|
581 | {
|
---|
582 | /*@todo, check if fbo binding is complete*/
|
---|
583 | }
|
---|
584 | }
|
---|
585 | else
|
---|
586 | {
|
---|
587 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glReadBuffer called with bogus mode: %d", mode);
|
---|
588 | return;
|
---|
589 | }
|
---|
590 | }
|
---|
591 |
|
---|
592 | if (g->framebufferobject.readFB)
|
---|
593 | {
|
---|
594 | g->framebufferobject.readFB->readbuffer = mode;
|
---|
595 | }
|
---|
596 | else
|
---|
597 | {
|
---|
598 | b->readBuffer = mode;
|
---|
599 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
600 | DIRTY(bb->readBuffer, g->neg_bitid);
|
---|
601 | }
|
---|
602 | }
|
---|
603 |
|
---|
604 | void STATE_APIENTRY crStateIndexMask (GLuint mask)
|
---|
605 | {
|
---|
606 | CRContext *g = GetCurrentContext();
|
---|
607 | CRBufferState *b = &(g->buffer);
|
---|
608 | CRStateBits *sp = GetCurrentBits();
|
---|
609 | CRBufferBits *bb = &(sp->buffer);
|
---|
610 |
|
---|
611 | if (g->current.inBeginEnd)
|
---|
612 | {
|
---|
613 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
|
---|
614 | return;
|
---|
615 | }
|
---|
616 |
|
---|
617 | FLUSH();
|
---|
618 |
|
---|
619 | b->indexWriteMask = mask;
|
---|
620 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
621 | DIRTY(bb->indexMask, g->neg_bitid);
|
---|
622 | }
|
---|
623 |
|
---|
624 | void STATE_APIENTRY crStateColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
|
---|
625 | {
|
---|
626 | CRContext *g = GetCurrentContext();
|
---|
627 | CRBufferState *b = &(g->buffer);
|
---|
628 | CRStateBits *sp = GetCurrentBits();
|
---|
629 | CRBufferBits *bb = &(sp->buffer);
|
---|
630 |
|
---|
631 | if (g->current.inBeginEnd)
|
---|
632 | {
|
---|
633 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
|
---|
634 | return;
|
---|
635 | }
|
---|
636 |
|
---|
637 | FLUSH();
|
---|
638 |
|
---|
639 | b->colorWriteMask.r = red;
|
---|
640 | b->colorWriteMask.g = green;
|
---|
641 | b->colorWriteMask.b = blue;
|
---|
642 | b->colorWriteMask.a = alpha;
|
---|
643 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
644 | DIRTY(bb->colorWriteMask, g->neg_bitid);
|
---|
645 | }
|
---|
646 |
|
---|
647 | void STATE_APIENTRY crStateClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
|
---|
648 | {
|
---|
649 | CRContext *g = GetCurrentContext();
|
---|
650 | CRBufferState *b = &(g->buffer);
|
---|
651 | CRStateBits *sp = GetCurrentBits();
|
---|
652 | CRBufferBits *bb = &(sp->buffer);
|
---|
653 |
|
---|
654 | if (g->current.inBeginEnd)
|
---|
655 | {
|
---|
656 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearColor called in begin/end");
|
---|
657 | return;
|
---|
658 | }
|
---|
659 |
|
---|
660 | FLUSH();
|
---|
661 |
|
---|
662 | if (red < 0.0f) red = 0.0f;
|
---|
663 | if (red > 1.0f) red = 1.0f;
|
---|
664 | if (green < 0.0f) green = 0.0f;
|
---|
665 | if (green > 1.0f) green = 1.0f;
|
---|
666 | if (blue < 0.0f) blue = 0.0f;
|
---|
667 | if (blue > 1.0f) blue = 1.0f;
|
---|
668 | if (alpha < 0.0f) alpha = 0.0f;
|
---|
669 | if (alpha > 1.0f) alpha = 1.0f;
|
---|
670 |
|
---|
671 | b->colorClearValue.r = red;
|
---|
672 | b->colorClearValue.g = green;
|
---|
673 | b->colorClearValue.b = blue;
|
---|
674 | b->colorClearValue.a = alpha;
|
---|
675 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
676 | DIRTY(bb->clearColor, g->neg_bitid);
|
---|
677 | }
|
---|
678 |
|
---|
679 | void STATE_APIENTRY crStateClearIndex (GLfloat c)
|
---|
680 | {
|
---|
681 | CRContext *g = GetCurrentContext();
|
---|
682 | CRBufferState *b = &(g->buffer);
|
---|
683 | CRStateBits *sp = GetCurrentBits();
|
---|
684 | CRBufferBits *bb = &(sp->buffer);
|
---|
685 |
|
---|
686 | if (g->current.inBeginEnd)
|
---|
687 | {
|
---|
688 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearIndex called in begin/end");
|
---|
689 | return;
|
---|
690 | }
|
---|
691 |
|
---|
692 | b->indexClearValue = c;
|
---|
693 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
694 | DIRTY(bb->clearIndex, g->neg_bitid);
|
---|
695 | }
|
---|
696 |
|
---|
697 | void STATE_APIENTRY crStateClearDepth (GLclampd depth)
|
---|
698 | {
|
---|
699 | CRContext *g = GetCurrentContext();
|
---|
700 | CRBufferState *b = &(g->buffer);
|
---|
701 | CRStateBits *sp = GetCurrentBits();
|
---|
702 | CRBufferBits *bb = &(sp->buffer);
|
---|
703 |
|
---|
704 | if (g->current.inBeginEnd)
|
---|
705 | {
|
---|
706 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearDepth called in begin/end");
|
---|
707 | return;
|
---|
708 | }
|
---|
709 |
|
---|
710 | FLUSH();
|
---|
711 |
|
---|
712 | if (depth < 0.0) depth = 0.0;
|
---|
713 | if (depth > 1.0) depth = 1.0;
|
---|
714 |
|
---|
715 | b->depthClearValue = (GLdefault) depth;
|
---|
716 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
717 | DIRTY(bb->clearDepth, g->neg_bitid);
|
---|
718 | }
|
---|
719 |
|
---|
720 | void STATE_APIENTRY crStateClearAccum (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
|
---|
721 | {
|
---|
722 | CRContext *g = GetCurrentContext();
|
---|
723 | CRBufferState *b = &(g->buffer);
|
---|
724 | CRStateBits *sp = GetCurrentBits();
|
---|
725 | CRBufferBits *bb = &(sp->buffer);
|
---|
726 |
|
---|
727 | if (g->current.inBeginEnd)
|
---|
728 | {
|
---|
729 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearAccum called in begin/end");
|
---|
730 | return;
|
---|
731 | }
|
---|
732 |
|
---|
733 | FLUSH();
|
---|
734 |
|
---|
735 | if (red < -1.0f) red = 0.0f;
|
---|
736 | if (red > 1.0f) red = 1.0f;
|
---|
737 | if (green < -1.0f) green = 0.0f;
|
---|
738 | if (green > 1.0f) green = 1.0f;
|
---|
739 | if (blue < -1.0f) blue = 0.0f;
|
---|
740 | if (blue > 1.0f) blue = 1.0f;
|
---|
741 | if (alpha < -1.0f) alpha = 0.0f;
|
---|
742 | if (alpha > 1.0f) alpha = 1.0f;
|
---|
743 |
|
---|
744 | b->accumClearValue.r = red;
|
---|
745 | b->accumClearValue.g = green;
|
---|
746 | b->accumClearValue.b = blue;
|
---|
747 | b->accumClearValue.a = alpha;
|
---|
748 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
749 | DIRTY(bb->clearAccum, g->neg_bitid);
|
---|
750 | }
|
---|
751 |
|
---|
752 | void STATE_APIENTRY crStateDepthMask (GLboolean b)
|
---|
753 | {
|
---|
754 | CRContext *g = GetCurrentContext();
|
---|
755 | CRBufferState *bs = &(g->buffer);
|
---|
756 | CRStateBits *sp = GetCurrentBits();
|
---|
757 | CRBufferBits *bb = &(sp->buffer);
|
---|
758 |
|
---|
759 | if (g->current.inBeginEnd)
|
---|
760 | {
|
---|
761 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "DepthMask called in begin/end");
|
---|
762 | return;
|
---|
763 | }
|
---|
764 |
|
---|
765 | FLUSH();
|
---|
766 |
|
---|
767 | bs->depthMask = b;
|
---|
768 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
769 | DIRTY(bb->depthMask, g->neg_bitid);
|
---|
770 | }
|
---|