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 crStateStencilInit(CRContext *ctx)
|
---|
13 | {
|
---|
14 | CRStencilState *s = &ctx->stencil;
|
---|
15 | CRStateBits *stateb = GetCurrentBits();
|
---|
16 | CRStencilBits *sb = &(stateb->stencil);
|
---|
17 |
|
---|
18 | s->stencilTest = GL_FALSE;
|
---|
19 | RESET(sb->enable, ctx->bitid);
|
---|
20 |
|
---|
21 | s->func = GL_ALWAYS;
|
---|
22 | s->mask = 0xFFFFFFFF;
|
---|
23 | s->ref = 0;
|
---|
24 | RESET(sb->func, ctx->bitid);
|
---|
25 |
|
---|
26 | s->fail = GL_KEEP;
|
---|
27 | s->passDepthFail = GL_KEEP;
|
---|
28 | s->passDepthPass = GL_KEEP;
|
---|
29 | RESET(sb->op, ctx->bitid);
|
---|
30 |
|
---|
31 | s->clearValue = 0;
|
---|
32 | RESET(sb->clearValue, ctx->bitid);
|
---|
33 |
|
---|
34 | s->writeMask = 0xFFFFFFFF;
|
---|
35 | RESET(sb->writeMask, ctx->bitid);
|
---|
36 |
|
---|
37 | RESET(sb->dirty, ctx->bitid);
|
---|
38 | }
|
---|
39 |
|
---|
40 | void STATE_APIENTRY crStateStencilFunc(GLenum func, GLint ref, GLuint mask)
|
---|
41 | {
|
---|
42 | CRContext *g = GetCurrentContext();
|
---|
43 | CRStencilState *s = &(g->stencil);
|
---|
44 | CRStateBits *stateb = GetCurrentBits();
|
---|
45 | CRStencilBits *sb = &(stateb->stencil);
|
---|
46 |
|
---|
47 |
|
---|
48 | if (g->current.inBeginEnd)
|
---|
49 | {
|
---|
50 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
51 | "glStencilFunc called in begin/end");
|
---|
52 | return;
|
---|
53 | }
|
---|
54 |
|
---|
55 | FLUSH();
|
---|
56 |
|
---|
57 | if (func != GL_NEVER &&
|
---|
58 | func != GL_LESS &&
|
---|
59 | func != GL_LEQUAL &&
|
---|
60 | func != GL_GREATER &&
|
---|
61 | func != GL_GEQUAL &&
|
---|
62 | func != GL_EQUAL &&
|
---|
63 | func != GL_NOTEQUAL &&
|
---|
64 | func != GL_ALWAYS)
|
---|
65 | {
|
---|
66 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
67 | "glStencilFunc called with bogu func: %d", func);
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | s->func = func;
|
---|
72 | s->ref = ref;
|
---|
73 | s->mask = mask;
|
---|
74 |
|
---|
75 | DIRTY(sb->func, g->neg_bitid);
|
---|
76 | DIRTY(sb->dirty, g->neg_bitid);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void STATE_APIENTRY crStateStencilOp (GLenum fail, GLenum zfail, GLenum zpass)
|
---|
80 | {
|
---|
81 | CRContext *g = GetCurrentContext();
|
---|
82 | CRStencilState *s = &(g->stencil);
|
---|
83 | CRStateBits *stateb = GetCurrentBits();
|
---|
84 | CRStencilBits *sb = &(stateb->stencil);
|
---|
85 |
|
---|
86 | if (g->current.inBeginEnd)
|
---|
87 | {
|
---|
88 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
89 | "glStencilOp called in begin/end");
|
---|
90 | return;
|
---|
91 | }
|
---|
92 |
|
---|
93 | FLUSH();
|
---|
94 |
|
---|
95 | switch (fail) {
|
---|
96 | case GL_KEEP:
|
---|
97 | case GL_ZERO:
|
---|
98 | case GL_REPLACE:
|
---|
99 | case GL_INCR:
|
---|
100 | case GL_DECR:
|
---|
101 | case GL_INVERT:
|
---|
102 | #ifdef CR_EXT_stencil_wrap
|
---|
103 | case GL_INCR_WRAP_EXT:
|
---|
104 | case GL_DECR_WRAP_EXT:
|
---|
105 | #endif
|
---|
106 | break;
|
---|
107 | default:
|
---|
108 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
109 | "glStencilOp called with bogus fail: %d", fail);
|
---|
110 | return;
|
---|
111 | }
|
---|
112 |
|
---|
113 | switch (zfail) {
|
---|
114 | case GL_KEEP:
|
---|
115 | case GL_ZERO:
|
---|
116 | case GL_REPLACE:
|
---|
117 | case GL_INCR:
|
---|
118 | case GL_DECR:
|
---|
119 | case GL_INVERT:
|
---|
120 | #ifdef CR_EXT_stencil_wrap
|
---|
121 | case GL_INCR_WRAP_EXT:
|
---|
122 | case GL_DECR_WRAP_EXT:
|
---|
123 | #endif
|
---|
124 | break;
|
---|
125 | default:
|
---|
126 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
127 | "glStencilOp called with bogus zfail: %d", zfail);
|
---|
128 | return;
|
---|
129 | }
|
---|
130 |
|
---|
131 | switch (zpass) {
|
---|
132 | case GL_KEEP:
|
---|
133 | case GL_ZERO:
|
---|
134 | case GL_REPLACE:
|
---|
135 | case GL_INCR:
|
---|
136 | case GL_DECR:
|
---|
137 | case GL_INVERT:
|
---|
138 | #ifdef CR_EXT_stencil_wrap
|
---|
139 | case GL_INCR_WRAP_EXT:
|
---|
140 | case GL_DECR_WRAP_EXT:
|
---|
141 | #endif
|
---|
142 | break;
|
---|
143 | default:
|
---|
144 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
145 | "glStencilOp called with bogus zpass: %d", zpass);
|
---|
146 | return;
|
---|
147 | }
|
---|
148 |
|
---|
149 | s->fail = fail;
|
---|
150 | s->passDepthFail = zfail;
|
---|
151 | s->passDepthPass = zpass;
|
---|
152 |
|
---|
153 | DIRTY(sb->op, g->neg_bitid);
|
---|
154 | DIRTY(sb->dirty, g->neg_bitid);
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | void STATE_APIENTRY crStateClearStencil (GLint c)
|
---|
159 | {
|
---|
160 | CRContext *g = GetCurrentContext();
|
---|
161 | CRStencilState *s = &(g->stencil);
|
---|
162 | CRStateBits *stateb = GetCurrentBits();
|
---|
163 | CRStencilBits *sb = &(stateb->stencil);
|
---|
164 |
|
---|
165 | if (g->current.inBeginEnd)
|
---|
166 | {
|
---|
167 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
168 | "glClearStencil called in begin/end");
|
---|
169 | return;
|
---|
170 | }
|
---|
171 |
|
---|
172 | FLUSH();
|
---|
173 |
|
---|
174 |
|
---|
175 | s->clearValue = c;
|
---|
176 |
|
---|
177 | DIRTY(sb->clearValue, g->neg_bitid);
|
---|
178 | DIRTY(sb->dirty, g->neg_bitid);
|
---|
179 | }
|
---|
180 |
|
---|
181 | void STATE_APIENTRY crStateStencilMask (GLuint mask)
|
---|
182 | {
|
---|
183 | CRContext *g = GetCurrentContext();
|
---|
184 | CRStencilState *s = &(g->stencil);
|
---|
185 | CRStateBits *stateb = GetCurrentBits();
|
---|
186 | CRStencilBits *sb = &(stateb->stencil);
|
---|
187 |
|
---|
188 | if (g->current.inBeginEnd)
|
---|
189 | {
|
---|
190 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
191 | "glStencilMask called in begin/end");
|
---|
192 | return;
|
---|
193 | }
|
---|
194 |
|
---|
195 | FLUSH();
|
---|
196 |
|
---|
197 | s->writeMask = mask;
|
---|
198 |
|
---|
199 | DIRTY(sb->writeMask, g->neg_bitid);
|
---|
200 | DIRTY(sb->dirty, g->neg_bitid);
|
---|
201 | }
|
---|