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 | RT_FALL_THRU();
|
---|
198 | default:
|
---|
199 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactor passed to glBlendFunc: %d", sfactor);
|
---|
200 | return;
|
---|
201 | }
|
---|
202 |
|
---|
203 | switch (dfactor)
|
---|
204 | {
|
---|
205 | case GL_ZERO:
|
---|
206 | case GL_ONE:
|
---|
207 | case GL_SRC_COLOR:
|
---|
208 | case GL_ONE_MINUS_SRC_COLOR:
|
---|
209 | case GL_SRC_ALPHA:
|
---|
210 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
211 | case GL_DST_ALPHA:
|
---|
212 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
213 | break; /* OK */
|
---|
214 | #ifdef CR_EXT_blend_color
|
---|
215 | case GL_CONSTANT_COLOR_EXT:
|
---|
216 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
217 | case GL_CONSTANT_ALPHA_EXT:
|
---|
218 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
219 | if (g->extensions.EXT_blend_color)
|
---|
220 | break; /* OK */
|
---|
221 | #endif
|
---|
222 | RT_FALL_THRU();
|
---|
223 | default:
|
---|
224 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactor passed to glBlendFunc: %d", dfactor);
|
---|
225 | return;
|
---|
226 | }
|
---|
227 |
|
---|
228 | b->blendSrcRGB = sfactor;
|
---|
229 | b->blendDstRGB = dfactor;
|
---|
230 | b->blendSrcA = sfactor;
|
---|
231 | b->blendDstA = dfactor;
|
---|
232 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
233 | DIRTY(bb->blendFunc, g->neg_bitid);
|
---|
234 | }
|
---|
235 |
|
---|
236 | void STATE_APIENTRY crStateBlendColorEXT( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
|
---|
237 | {
|
---|
238 | CRContext *g = GetCurrentContext();
|
---|
239 | CRBufferState *b = &(g->buffer);
|
---|
240 | CRStateBits *sb = GetCurrentBits();
|
---|
241 | CRBufferBits *bb = &(sb->buffer);
|
---|
242 |
|
---|
243 | if (g->current.inBeginEnd)
|
---|
244 | {
|
---|
245 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendColorEXT called inside a Begin/End" );
|
---|
246 | return;
|
---|
247 | }
|
---|
248 |
|
---|
249 | b->blendColor.r = red;
|
---|
250 | b->blendColor.g = green;
|
---|
251 | b->blendColor.b = blue;
|
---|
252 | b->blendColor.a = alpha;
|
---|
253 | DIRTY(bb->blendColor, g->neg_bitid);
|
---|
254 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
255 | }
|
---|
256 |
|
---|
257 | #ifdef CR_EXT_blend_func_separate
|
---|
258 | void STATE_APIENTRY crStateBlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA )
|
---|
259 | {
|
---|
260 | CRContext *g = GetCurrentContext();
|
---|
261 | CRBufferState *b = &(g->buffer);
|
---|
262 | CRStateBits *sb = GetCurrentBits();
|
---|
263 | CRBufferBits *bb = &(sb->buffer);
|
---|
264 |
|
---|
265 | if (g->current.inBeginEnd)
|
---|
266 | {
|
---|
267 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendFuncSeparateEXT called inside a Begin/End" );
|
---|
268 | return;
|
---|
269 | }
|
---|
270 |
|
---|
271 | FLUSH();
|
---|
272 |
|
---|
273 | switch (sfactorRGB)
|
---|
274 | {
|
---|
275 | case GL_ZERO:
|
---|
276 | case GL_ONE:
|
---|
277 | case GL_DST_COLOR:
|
---|
278 | case GL_ONE_MINUS_DST_COLOR:
|
---|
279 | case GL_SRC_ALPHA:
|
---|
280 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
281 | case GL_DST_ALPHA:
|
---|
282 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
283 | case GL_SRC_ALPHA_SATURATE:
|
---|
284 | break; /* OK */
|
---|
285 | #ifdef CR_EXT_blend_color
|
---|
286 | case GL_CONSTANT_COLOR_EXT:
|
---|
287 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
288 | case GL_CONSTANT_ALPHA_EXT:
|
---|
289 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
290 | if (g->extensions.EXT_blend_color)
|
---|
291 | break; /* OK */
|
---|
292 | #endif
|
---|
293 | RT_FALL_THRU();
|
---|
294 | default:
|
---|
295 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorRGB passed to glBlendFuncSeparateEXT: %d", sfactorRGB);
|
---|
296 | return;
|
---|
297 | }
|
---|
298 |
|
---|
299 | switch (sfactorA)
|
---|
300 | {
|
---|
301 | case GL_ZERO:
|
---|
302 | case GL_ONE:
|
---|
303 | case GL_DST_COLOR:
|
---|
304 | case GL_ONE_MINUS_DST_COLOR:
|
---|
305 | case GL_SRC_ALPHA:
|
---|
306 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
307 | case GL_DST_ALPHA:
|
---|
308 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
309 | case GL_SRC_ALPHA_SATURATE:
|
---|
310 | break; /* OK */
|
---|
311 | #ifdef CR_EXT_blend_color
|
---|
312 | case GL_CONSTANT_COLOR_EXT:
|
---|
313 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
314 | case GL_CONSTANT_ALPHA_EXT:
|
---|
315 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
316 | if (g->extensions.EXT_blend_color)
|
---|
317 | break; /* OK */
|
---|
318 | #endif
|
---|
319 | RT_FALL_THRU();
|
---|
320 | default:
|
---|
321 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorA passed to glBlendFuncSeparateEXT: %d", sfactorA);
|
---|
322 | return;
|
---|
323 | }
|
---|
324 |
|
---|
325 | switch (dfactorRGB)
|
---|
326 | {
|
---|
327 | case GL_ZERO:
|
---|
328 | case GL_ONE:
|
---|
329 | case GL_SRC_COLOR:
|
---|
330 | case GL_DST_COLOR:
|
---|
331 | case GL_ONE_MINUS_DST_COLOR:
|
---|
332 | case GL_ONE_MINUS_SRC_COLOR:
|
---|
333 | case GL_SRC_ALPHA:
|
---|
334 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
335 | case GL_DST_ALPHA:
|
---|
336 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
337 | case GL_SRC_ALPHA_SATURATE:
|
---|
338 | break; /* OK */
|
---|
339 | #ifdef CR_EXT_blend_color
|
---|
340 | case GL_CONSTANT_COLOR_EXT:
|
---|
341 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
342 | case GL_CONSTANT_ALPHA_EXT:
|
---|
343 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
344 | if (g->extensions.EXT_blend_color)
|
---|
345 | break; /* OK */
|
---|
346 | #endif
|
---|
347 | RT_FALL_THRU();
|
---|
348 | default:
|
---|
349 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorRGB passed to glBlendFuncSeparateEXT: %d", dfactorRGB);
|
---|
350 | return;
|
---|
351 | }
|
---|
352 |
|
---|
353 | switch (dfactorA)
|
---|
354 | {
|
---|
355 | case GL_ZERO:
|
---|
356 | case GL_ONE:
|
---|
357 | case GL_DST_COLOR:
|
---|
358 | case GL_SRC_COLOR:
|
---|
359 | case GL_ONE_MINUS_SRC_COLOR:
|
---|
360 | case GL_ONE_MINUS_DST_COLOR:
|
---|
361 | case GL_SRC_ALPHA:
|
---|
362 | case GL_ONE_MINUS_SRC_ALPHA:
|
---|
363 | case GL_DST_ALPHA:
|
---|
364 | case GL_ONE_MINUS_DST_ALPHA:
|
---|
365 | case GL_SRC_ALPHA_SATURATE:
|
---|
366 | break; /* OK */
|
---|
367 | #ifdef CR_EXT_blend_color
|
---|
368 | case GL_CONSTANT_COLOR_EXT:
|
---|
369 | case GL_ONE_MINUS_CONSTANT_COLOR_EXT:
|
---|
370 | case GL_CONSTANT_ALPHA_EXT:
|
---|
371 | case GL_ONE_MINUS_CONSTANT_ALPHA_EXT:
|
---|
372 | if (g->extensions.EXT_blend_color)
|
---|
373 | break; /* OK */
|
---|
374 | #endif
|
---|
375 | RT_FALL_THRU();
|
---|
376 | default:
|
---|
377 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorA passed to glBlendFuncSeparateEXT: %d", dfactorA);
|
---|
378 | return;
|
---|
379 | }
|
---|
380 |
|
---|
381 | b->blendSrcRGB = sfactorRGB;
|
---|
382 | b->blendDstRGB = dfactorRGB;
|
---|
383 | b->blendSrcA = sfactorA;
|
---|
384 | b->blendDstA = dfactorA;
|
---|
385 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
386 | DIRTY(bb->blendFuncSeparate, g->neg_bitid);
|
---|
387 | }
|
---|
388 | #endif
|
---|
389 |
|
---|
390 | void STATE_APIENTRY crStateBlendEquationEXT( GLenum mode )
|
---|
391 | {
|
---|
392 | CRContext *g = GetCurrentContext();
|
---|
393 | CRBufferState *b = &(g->buffer);
|
---|
394 | CRStateBits *sb = GetCurrentBits();
|
---|
395 | CRBufferBits *bb = &(sb->buffer);
|
---|
396 |
|
---|
397 | if( g->current.inBeginEnd )
|
---|
398 | {
|
---|
399 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendEquationEXT called inside a Begin/End" );
|
---|
400 | return;
|
---|
401 | }
|
---|
402 | switch( mode )
|
---|
403 | {
|
---|
404 | #if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
|
---|
405 | case GL_FUNC_ADD_EXT:
|
---|
406 | #ifdef CR_EXT_blend_subtract
|
---|
407 | case GL_FUNC_SUBTRACT_EXT:
|
---|
408 | case GL_FUNC_REVERSE_SUBTRACT_EXT:
|
---|
409 | #endif /* CR_EXT_blend_subtract */
|
---|
410 | #ifdef CR_EXT_blend_minmax
|
---|
411 | case GL_MIN_EXT:
|
---|
412 | case GL_MAX_EXT:
|
---|
413 | #endif /* CR_EXT_blend_minmax */
|
---|
414 | #ifdef CR_EXT_blend_logic_op
|
---|
415 | case GL_LOGIC_OP:
|
---|
416 | #endif /* CR_EXT_blend_logic_op */
|
---|
417 | b->blendEquation = mode;
|
---|
418 | break;
|
---|
419 | #endif /* defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op) */
|
---|
420 | default:
|
---|
421 | crStateError( __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
422 | "BlendEquationEXT: mode called with illegal parameter: 0x%x", (GLenum) mode );
|
---|
423 | return;
|
---|
424 | }
|
---|
425 | DIRTY(bb->blendEquation, g->neg_bitid);
|
---|
426 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
427 | }
|
---|
428 |
|
---|
429 | void STATE_APIENTRY crStateLogicOp (GLenum opcode)
|
---|
430 | {
|
---|
431 | CRContext *g = GetCurrentContext();
|
---|
432 | CRBufferState *b = &(g->buffer);
|
---|
433 | CRStateBits *sb = GetCurrentBits();
|
---|
434 | CRBufferBits *bb = &(sb->buffer);
|
---|
435 |
|
---|
436 | if (g->current.inBeginEnd)
|
---|
437 | {
|
---|
438 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glLogicOp called in begin/end");
|
---|
439 | return;
|
---|
440 | }
|
---|
441 |
|
---|
442 | FLUSH();
|
---|
443 |
|
---|
444 | switch (opcode)
|
---|
445 | {
|
---|
446 | case GL_CLEAR:
|
---|
447 | case GL_SET:
|
---|
448 | case GL_COPY:
|
---|
449 | case GL_COPY_INVERTED:
|
---|
450 | case GL_NOOP:
|
---|
451 | case GL_INVERT:
|
---|
452 | case GL_AND:
|
---|
453 | case GL_NAND:
|
---|
454 | case GL_OR:
|
---|
455 | case GL_NOR:
|
---|
456 | case GL_XOR:
|
---|
457 | case GL_EQUIV:
|
---|
458 | case GL_AND_REVERSE:
|
---|
459 | case GL_AND_INVERTED:
|
---|
460 | case GL_OR_REVERSE:
|
---|
461 | case GL_OR_INVERTED:
|
---|
462 | break;
|
---|
463 | default:
|
---|
464 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLogicOp called with bogus opcode: %d", opcode);
|
---|
465 | return;
|
---|
466 | }
|
---|
467 |
|
---|
468 | b->logicOpMode = opcode;
|
---|
469 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
470 | DIRTY(bb->logicOp, g->neg_bitid);
|
---|
471 | DIRTY(bb->indexLogicOp, g->neg_bitid);
|
---|
472 | }
|
---|
473 |
|
---|
474 | void STATE_APIENTRY crStateDrawBuffer (GLenum mode)
|
---|
475 | {
|
---|
476 | CRContext *g = GetCurrentContext();
|
---|
477 | CRBufferState *b = &(g->buffer);
|
---|
478 | CRStateBits *sb = GetCurrentBits();
|
---|
479 | CRBufferBits *bb = &(sb->buffer);
|
---|
480 |
|
---|
481 | if (g->current.inBeginEnd)
|
---|
482 | {
|
---|
483 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer called in begin/end");
|
---|
484 | return;
|
---|
485 | }
|
---|
486 |
|
---|
487 | FLUSH();
|
---|
488 |
|
---|
489 | switch (mode)
|
---|
490 | {
|
---|
491 | case GL_NONE:
|
---|
492 | break;
|
---|
493 | case GL_FRONT_LEFT:
|
---|
494 | case GL_FRONT_RIGHT:
|
---|
495 | case GL_BACK_LEFT:
|
---|
496 | case GL_BACK_RIGHT:
|
---|
497 | case GL_FRONT:
|
---|
498 | case GL_BACK:
|
---|
499 | case GL_LEFT:
|
---|
500 | case GL_RIGHT:
|
---|
501 | case GL_FRONT_AND_BACK:
|
---|
502 | case GL_AUX0:
|
---|
503 | case GL_AUX1:
|
---|
504 | case GL_AUX2:
|
---|
505 | case GL_AUX3:
|
---|
506 | if (g->framebufferobject.drawFB)
|
---|
507 | {
|
---|
508 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is active");
|
---|
509 | return;
|
---|
510 | }
|
---|
511 | break;
|
---|
512 | default:
|
---|
513 | if (mode>=GL_COLOR_ATTACHMENT0_EXT && mode<=GL_COLOR_ATTACHMENT15_EXT)
|
---|
514 | {
|
---|
515 | if (!g->framebufferobject.drawFB)
|
---|
516 | {
|
---|
517 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalid mode while fbo is inactive");
|
---|
518 | return;
|
---|
519 | }
|
---|
520 | }
|
---|
521 | else
|
---|
522 | {
|
---|
523 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glDrawBuffer called with bogus mode: %d", mode);
|
---|
524 | return;
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | if (g->framebufferobject.drawFB)
|
---|
529 | {
|
---|
530 | g->framebufferobject.drawFB->drawbuffer[0] = mode;
|
---|
531 | }
|
---|
532 | else
|
---|
533 | {
|
---|
534 | b->drawBuffer = mode;
|
---|
535 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
536 | DIRTY(bb->drawBuffer, g->neg_bitid);
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 | void STATE_APIENTRY crStateReadBuffer (GLenum mode)
|
---|
541 | {
|
---|
542 | CRContext *g = GetCurrentContext();
|
---|
543 | CRBufferState *b = &(g->buffer);
|
---|
544 | CRStateBits *sb = GetCurrentBits();
|
---|
545 | CRBufferBits *bb = &(sb->buffer);
|
---|
546 |
|
---|
547 | if (g->current.inBeginEnd)
|
---|
548 | {
|
---|
549 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
|
---|
550 | return;
|
---|
551 | }
|
---|
552 |
|
---|
553 | FLUSH();
|
---|
554 |
|
---|
555 | switch (mode)
|
---|
556 | {
|
---|
557 | case GL_NONE:
|
---|
558 | break;
|
---|
559 | case GL_FRONT_LEFT:
|
---|
560 | case GL_FRONT_RIGHT:
|
---|
561 | case GL_BACK_LEFT:
|
---|
562 | case GL_BACK_RIGHT:
|
---|
563 | case GL_FRONT:
|
---|
564 | case GL_BACK:
|
---|
565 | case GL_LEFT:
|
---|
566 | case GL_RIGHT:
|
---|
567 | case GL_FRONT_AND_BACK:
|
---|
568 | case GL_AUX0:
|
---|
569 | case GL_AUX1:
|
---|
570 | case GL_AUX2:
|
---|
571 | case GL_AUX3:
|
---|
572 | if (g->framebufferobject.readFB)
|
---|
573 | {
|
---|
574 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is active");
|
---|
575 | return;
|
---|
576 | }
|
---|
577 | break;
|
---|
578 | default:
|
---|
579 | if (mode>=GL_COLOR_ATTACHMENT0_EXT && mode<=GL_COLOR_ATTACHMENT15_EXT)
|
---|
580 | {
|
---|
581 | if (!g->framebufferobject.readFB)
|
---|
582 | {
|
---|
583 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalid mode while fbo is inactive");
|
---|
584 | return;
|
---|
585 | }
|
---|
586 | else
|
---|
587 | {
|
---|
588 | /*@todo, check if fbo binding is complete*/
|
---|
589 | }
|
---|
590 | }
|
---|
591 | else
|
---|
592 | {
|
---|
593 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glReadBuffer called with bogus mode: %d", mode);
|
---|
594 | return;
|
---|
595 | }
|
---|
596 | }
|
---|
597 |
|
---|
598 | if (g->framebufferobject.readFB)
|
---|
599 | {
|
---|
600 | g->framebufferobject.readFB->readbuffer = mode;
|
---|
601 | }
|
---|
602 | else
|
---|
603 | {
|
---|
604 | b->readBuffer = mode;
|
---|
605 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
606 | DIRTY(bb->readBuffer, g->neg_bitid);
|
---|
607 | }
|
---|
608 | }
|
---|
609 |
|
---|
610 | void STATE_APIENTRY crStateIndexMask (GLuint mask)
|
---|
611 | {
|
---|
612 | CRContext *g = GetCurrentContext();
|
---|
613 | CRBufferState *b = &(g->buffer);
|
---|
614 | CRStateBits *sp = GetCurrentBits();
|
---|
615 | CRBufferBits *bb = &(sp->buffer);
|
---|
616 |
|
---|
617 | if (g->current.inBeginEnd)
|
---|
618 | {
|
---|
619 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
|
---|
620 | return;
|
---|
621 | }
|
---|
622 |
|
---|
623 | FLUSH();
|
---|
624 |
|
---|
625 | b->indexWriteMask = mask;
|
---|
626 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
627 | DIRTY(bb->indexMask, g->neg_bitid);
|
---|
628 | }
|
---|
629 |
|
---|
630 | void STATE_APIENTRY crStateColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
|
---|
631 | {
|
---|
632 | CRContext *g = GetCurrentContext();
|
---|
633 | CRBufferState *b = &(g->buffer);
|
---|
634 | CRStateBits *sp = GetCurrentBits();
|
---|
635 | CRBufferBits *bb = &(sp->buffer);
|
---|
636 |
|
---|
637 | if (g->current.inBeginEnd)
|
---|
638 | {
|
---|
639 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
|
---|
640 | return;
|
---|
641 | }
|
---|
642 |
|
---|
643 | FLUSH();
|
---|
644 |
|
---|
645 | b->colorWriteMask.r = red;
|
---|
646 | b->colorWriteMask.g = green;
|
---|
647 | b->colorWriteMask.b = blue;
|
---|
648 | b->colorWriteMask.a = alpha;
|
---|
649 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
650 | DIRTY(bb->colorWriteMask, g->neg_bitid);
|
---|
651 | }
|
---|
652 |
|
---|
653 | void STATE_APIENTRY crStateClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
|
---|
654 | {
|
---|
655 | CRContext *g = GetCurrentContext();
|
---|
656 | CRBufferState *b = &(g->buffer);
|
---|
657 | CRStateBits *sp = GetCurrentBits();
|
---|
658 | CRBufferBits *bb = &(sp->buffer);
|
---|
659 |
|
---|
660 | if (g->current.inBeginEnd)
|
---|
661 | {
|
---|
662 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearColor called in begin/end");
|
---|
663 | return;
|
---|
664 | }
|
---|
665 |
|
---|
666 | FLUSH();
|
---|
667 |
|
---|
668 | if (red < 0.0f) red = 0.0f;
|
---|
669 | if (red > 1.0f) red = 1.0f;
|
---|
670 | if (green < 0.0f) green = 0.0f;
|
---|
671 | if (green > 1.0f) green = 1.0f;
|
---|
672 | if (blue < 0.0f) blue = 0.0f;
|
---|
673 | if (blue > 1.0f) blue = 1.0f;
|
---|
674 | if (alpha < 0.0f) alpha = 0.0f;
|
---|
675 | if (alpha > 1.0f) alpha = 1.0f;
|
---|
676 |
|
---|
677 | b->colorClearValue.r = red;
|
---|
678 | b->colorClearValue.g = green;
|
---|
679 | b->colorClearValue.b = blue;
|
---|
680 | b->colorClearValue.a = alpha;
|
---|
681 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
682 | DIRTY(bb->clearColor, g->neg_bitid);
|
---|
683 | }
|
---|
684 |
|
---|
685 | void STATE_APIENTRY crStateClearIndex (GLfloat c)
|
---|
686 | {
|
---|
687 | CRContext *g = GetCurrentContext();
|
---|
688 | CRBufferState *b = &(g->buffer);
|
---|
689 | CRStateBits *sp = GetCurrentBits();
|
---|
690 | CRBufferBits *bb = &(sp->buffer);
|
---|
691 |
|
---|
692 | if (g->current.inBeginEnd)
|
---|
693 | {
|
---|
694 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearIndex called in begin/end");
|
---|
695 | return;
|
---|
696 | }
|
---|
697 |
|
---|
698 | b->indexClearValue = c;
|
---|
699 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
700 | DIRTY(bb->clearIndex, g->neg_bitid);
|
---|
701 | }
|
---|
702 |
|
---|
703 | void STATE_APIENTRY crStateClearDepth (GLclampd depth)
|
---|
704 | {
|
---|
705 | CRContext *g = GetCurrentContext();
|
---|
706 | CRBufferState *b = &(g->buffer);
|
---|
707 | CRStateBits *sp = GetCurrentBits();
|
---|
708 | CRBufferBits *bb = &(sp->buffer);
|
---|
709 |
|
---|
710 | if (g->current.inBeginEnd)
|
---|
711 | {
|
---|
712 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearDepth called in begin/end");
|
---|
713 | return;
|
---|
714 | }
|
---|
715 |
|
---|
716 | FLUSH();
|
---|
717 |
|
---|
718 | if (depth < 0.0) depth = 0.0;
|
---|
719 | if (depth > 1.0) depth = 1.0;
|
---|
720 |
|
---|
721 | b->depthClearValue = (GLdefault) depth;
|
---|
722 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
723 | DIRTY(bb->clearDepth, g->neg_bitid);
|
---|
724 | }
|
---|
725 |
|
---|
726 | void STATE_APIENTRY crStateClearAccum (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
|
---|
727 | {
|
---|
728 | CRContext *g = GetCurrentContext();
|
---|
729 | CRBufferState *b = &(g->buffer);
|
---|
730 | CRStateBits *sp = GetCurrentBits();
|
---|
731 | CRBufferBits *bb = &(sp->buffer);
|
---|
732 |
|
---|
733 | if (g->current.inBeginEnd)
|
---|
734 | {
|
---|
735 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearAccum called in begin/end");
|
---|
736 | return;
|
---|
737 | }
|
---|
738 |
|
---|
739 | FLUSH();
|
---|
740 |
|
---|
741 | if (red < -1.0f) red = 0.0f;
|
---|
742 | if (red > 1.0f) red = 1.0f;
|
---|
743 | if (green < -1.0f) green = 0.0f;
|
---|
744 | if (green > 1.0f) green = 1.0f;
|
---|
745 | if (blue < -1.0f) blue = 0.0f;
|
---|
746 | if (blue > 1.0f) blue = 1.0f;
|
---|
747 | if (alpha < -1.0f) alpha = 0.0f;
|
---|
748 | if (alpha > 1.0f) alpha = 1.0f;
|
---|
749 |
|
---|
750 | b->accumClearValue.r = red;
|
---|
751 | b->accumClearValue.g = green;
|
---|
752 | b->accumClearValue.b = blue;
|
---|
753 | b->accumClearValue.a = alpha;
|
---|
754 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
755 | DIRTY(bb->clearAccum, g->neg_bitid);
|
---|
756 | }
|
---|
757 |
|
---|
758 | void STATE_APIENTRY crStateDepthMask (GLboolean b)
|
---|
759 | {
|
---|
760 | CRContext *g = GetCurrentContext();
|
---|
761 | CRBufferState *bs = &(g->buffer);
|
---|
762 | CRStateBits *sp = GetCurrentBits();
|
---|
763 | CRBufferBits *bb = &(sp->buffer);
|
---|
764 |
|
---|
765 | if (g->current.inBeginEnd)
|
---|
766 | {
|
---|
767 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "DepthMask called in begin/end");
|
---|
768 | return;
|
---|
769 | }
|
---|
770 |
|
---|
771 | FLUSH();
|
---|
772 |
|
---|
773 | bs->depthMask = b;
|
---|
774 | DIRTY(bb->dirty, g->neg_bitid);
|
---|
775 | DIRTY(bb->depthMask, g->neg_bitid);
|
---|
776 | }
|
---|