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