~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/GuestHost/OpenGL/state_tracker/state_buffer.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
void crStateBufferInit (CRContext *ctx)
13
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);
 
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
40
#ifdef CR_EXT_blend_func_separate
41
 
        b->blendSrcA = GL_ONE;
42
 
        b->blendDstA = GL_ZERO;
43
 
        RESET(bb->blendFuncSeparate, ctx->bitid);
 
41
    b->blendSrcA = GL_ONE;
 
42
    b->blendDstA = GL_ZERO;
 
43
    RESET(bb->blendFuncSeparate, ctx->bitid);
44
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);
 
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
65
 
66
66
#ifdef CR_EXT_blend_color
67
 
        b->blendColor = zero_colorf;
68
 
        RESET(bb->blendColor, ctx->bitid);
 
67
    b->blendColor = zero_colorf;
 
68
    RESET(bb->blendColor, ctx->bitid);
69
69
#endif
70
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);
 
71
    b->blendEquation = GL_FUNC_ADD_EXT;
 
72
    RESET(bb->blendEquation, ctx->bitid);
73
73
#endif
74
74
 
75
 
        RESET(bb->dirty, ctx->bitid);
 
75
    RESET(bb->dirty, ctx->bitid);
76
76
}
77
77
 
78
78
void STATE_APIENTRY crStateAlphaFunc (GLenum func, GLclampf ref) 
79
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);
 
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
116
}
117
117
 
118
118
void STATE_APIENTRY crStateDepthFunc (GLenum func) 
119
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);
 
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
153
}
154
154
 
155
155
void STATE_APIENTRY crStateBlendFunc (GLenum sfactor, GLenum dfactor) 
156
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);
 
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
225
}
226
226
 
227
227
void STATE_APIENTRY crStateBlendColorEXT( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
228
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);
 
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
246
}
247
247
 
248
248
#ifdef CR_EXT_blend_func_separate
249
249
void STATE_APIENTRY crStateBlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA )
250
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);
 
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
374
}
375
375
#endif
376
376
 
377
377
void STATE_APIENTRY crStateBlendEquationEXT( GLenum mode )
378
378
{
379
 
        CRContext *g = GetCurrentContext();
380
 
        CRBufferState *b = &(g->buffer);
381
 
        CRStateBits *sb = GetCurrentBits();
382
 
        CRBufferBits *bb = &(sb->buffer);
 
379
    CRContext *g = GetCurrentContext();
 
380
    CRBufferState *b = &(g->buffer);
 
381
    CRStateBits *sb = GetCurrentBits();
 
382
    CRBufferBits *bb = &(sb->buffer);
383
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
 
        {
 
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
391
#if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
392
 
                case GL_FUNC_ADD_EXT:
 
392
        case GL_FUNC_ADD_EXT:
393
393
#ifdef CR_EXT_blend_subtract
394
 
                case GL_FUNC_SUBTRACT_EXT:
395
 
                case GL_FUNC_REVERSE_SUBTRACT_EXT:
 
394
        case GL_FUNC_SUBTRACT_EXT:
 
395
        case GL_FUNC_REVERSE_SUBTRACT_EXT:
396
396
#endif /* CR_EXT_blend_subtract */
397
397
#ifdef CR_EXT_blend_minmax
398
 
                case GL_MIN_EXT:
399
 
                case GL_MAX_EXT:
 
398
        case GL_MIN_EXT:
 
399
        case GL_MAX_EXT:
400
400
#endif /* CR_EXT_blend_minmax */
401
401
#ifdef CR_EXT_blend_logic_op
402
 
                case GL_LOGIC_OP:
 
402
        case GL_LOGIC_OP:
403
403
#endif /* CR_EXT_blend_logic_op */
404
 
                        b->blendEquation = mode;
405
 
                        break;
 
404
            b->blendEquation = mode;
 
405
            break;
406
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);
 
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
414
}
415
415
 
416
416
void STATE_APIENTRY crStateLogicOp (GLenum opcode) 
417
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);
 
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
459
}
460
460
 
461
461
void STATE_APIENTRY crStateDrawBuffer (GLenum mode) 
462
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
 
                        break;
493
 
                default:
494
 
                        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glDrawBuffer called with bogus mode: %d", mode);
495
 
                        return;
496
 
        }
497
 
 
498
 
        b->drawBuffer = mode;
499
 
        DIRTY(bb->dirty, g->neg_bitid);
500
 
        DIRTY(bb->drawBuffer, g->neg_bitid);
 
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 invalud 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 invalud 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
    }
501
524
}
502
525
 
503
526
void STATE_APIENTRY crStateReadBuffer (GLenum mode) 
504
527
{
505
 
        CRContext *g = GetCurrentContext();
506
 
        CRBufferState *b = &(g->buffer);
507
 
        CRStateBits *sb = GetCurrentBits();
508
 
        CRBufferBits *bb = &(sb->buffer);
509
 
 
510
 
        if (g->current.inBeginEnd)
511
 
        {
512
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
513
 
                return;
514
 
        }
515
 
 
516
 
        FLUSH();
517
 
 
518
 
        switch (mode) 
519
 
        {
520
 
                case GL_NONE:
521
 
                case GL_FRONT_LEFT:
522
 
                case GL_FRONT_RIGHT:
523
 
                case GL_BACK_LEFT:
524
 
                case GL_BACK_RIGHT:
525
 
                case GL_FRONT:
526
 
                case GL_BACK:
527
 
                case GL_LEFT:
528
 
                case GL_RIGHT:
529
 
                case GL_FRONT_AND_BACK:
530
 
                case GL_AUX0:
531
 
                case GL_AUX1:
532
 
                case GL_AUX2:
533
 
                case GL_AUX3:
534
 
                        break;
535
 
                default:
536
 
                        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glReadBuffer called with bogus mode: %d", mode);
537
 
                        return;
538
 
        }
539
 
 
540
 
        b->readBuffer = mode;
541
 
        DIRTY(bb->dirty, g->neg_bitid);
542
 
        DIRTY(bb->readBuffer, g->neg_bitid);
 
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 invalud 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 invalud 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
    }
543
593
}
544
594
 
545
595
void STATE_APIENTRY crStateIndexMask (GLuint mask) 
546
596
{
547
 
        CRContext *g = GetCurrentContext();
548
 
        CRBufferState *b = &(g->buffer);
549
 
        CRStateBits *sp = GetCurrentBits();
550
 
        CRBufferBits *bb = &(sp->buffer);
551
 
 
552
 
        if (g->current.inBeginEnd)
553
 
        {
554
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
555
 
                return;
556
 
        }
557
 
 
558
 
        FLUSH();
559
 
 
560
 
        b->indexWriteMask = mask;
561
 
        DIRTY(bb->dirty, g->neg_bitid);
562
 
        DIRTY(bb->indexMask, g->neg_bitid);
 
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);
563
613
}
564
614
 
565
615
void STATE_APIENTRY crStateColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) 
566
616
{
567
 
        CRContext *g = GetCurrentContext();
568
 
        CRBufferState *b = &(g->buffer);
569
 
        CRStateBits *sp = GetCurrentBits();
570
 
        CRBufferBits *bb = &(sp->buffer);
571
 
 
572
 
        if (g->current.inBeginEnd)
573
 
        {
574
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer called in begin/end");
575
 
                return;
576
 
        }
577
 
 
578
 
        FLUSH();
579
 
 
580
 
        b->colorWriteMask.r = red;
581
 
        b->colorWriteMask.g = green;
582
 
        b->colorWriteMask.b = blue;
583
 
        b->colorWriteMask.a = alpha;
584
 
        DIRTY(bb->dirty, g->neg_bitid);
585
 
        DIRTY(bb->colorWriteMask, g->neg_bitid);
 
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);
586
636
}
587
637
 
588
638
void STATE_APIENTRY crStateClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) 
589
639
{
590
 
        CRContext *g = GetCurrentContext();
591
 
        CRBufferState *b = &(g->buffer);
592
 
        CRStateBits *sp = GetCurrentBits();
593
 
        CRBufferBits *bb = &(sp->buffer);
594
 
 
595
 
        if (g->current.inBeginEnd)
596
 
        {
597
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearColor called in begin/end");
598
 
                return;
599
 
        }
600
 
 
601
 
        FLUSH();
602
 
 
603
 
        if (red < 0.0f) red = 0.0f;
604
 
        if (red > 1.0f) red = 1.0f;
605
 
        if (green < 0.0f) green = 0.0f;
606
 
        if (green > 1.0f) green = 1.0f;
607
 
        if (blue < 0.0f) blue = 0.0f;
608
 
        if (blue > 1.0f) blue = 1.0f;
609
 
        if (alpha < 0.0f) alpha = 0.0f;
610
 
        if (alpha > 1.0f) alpha = 1.0f;
611
 
 
612
 
        b->colorClearValue.r = red;
613
 
        b->colorClearValue.g = green;
614
 
        b->colorClearValue.b = blue;
615
 
        b->colorClearValue.a = alpha;
616
 
        DIRTY(bb->dirty, g->neg_bitid);
617
 
        DIRTY(bb->clearColor, g->neg_bitid);
 
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);
618
668
}
619
669
 
620
670
void STATE_APIENTRY crStateClearIndex (GLfloat c) 
621
671
{
622
 
        CRContext *g = GetCurrentContext();
623
 
        CRBufferState *b = &(g->buffer);
624
 
        CRStateBits *sp = GetCurrentBits();
625
 
        CRBufferBits *bb = &(sp->buffer);
626
 
 
627
 
        if (g->current.inBeginEnd)
628
 
        {
629
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearIndex called in begin/end");
630
 
                return;
631
 
        }
632
 
 
633
 
        b->indexClearValue = c;
634
 
        DIRTY(bb->dirty, g->neg_bitid);
635
 
        DIRTY(bb->clearIndex, g->neg_bitid);
 
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);
636
686
}
637
687
 
638
688
void STATE_APIENTRY crStateClearDepth (GLclampd depth) 
639
689
{
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, "glClearDepth called in begin/end");
648
 
                return;
649
 
        }
650
 
 
651
 
        FLUSH();
652
 
 
653
 
        if (depth < 0.0) depth = 0.0;
654
 
        if (depth > 1.0) depth = 1.0;
655
 
 
656
 
        b->depthClearValue = (GLdefault) depth;
657
 
        DIRTY(bb->dirty, g->neg_bitid);
658
 
        DIRTY(bb->clearDepth, g->neg_bitid);
 
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);
659
709
}
660
710
 
661
711
void STATE_APIENTRY crStateClearAccum (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) 
662
712
{
663
 
        CRContext *g = GetCurrentContext();
664
 
        CRBufferState *b = &(g->buffer);
665
 
        CRStateBits *sp = GetCurrentBits();
666
 
        CRBufferBits *bb = &(sp->buffer);
667
 
 
668
 
        if (g->current.inBeginEnd)
669
 
        {
670
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glClearAccum called in begin/end");
671
 
                return;
672
 
        }
673
 
        
674
 
        FLUSH();
675
 
 
676
 
        if (red < -1.0f) red = 0.0f;
677
 
        if (red > 1.0f) red = 1.0f;
678
 
        if (green < -1.0f) green = 0.0f;
679
 
        if (green > 1.0f) green = 1.0f;
680
 
        if (blue < -1.0f) blue = 0.0f;
681
 
        if (blue > 1.0f) blue = 1.0f;
682
 
        if (alpha < -1.0f) alpha = 0.0f;
683
 
        if (alpha > 1.0f) alpha = 1.0f;
684
 
 
685
 
        b->accumClearValue.r = red;
686
 
        b->accumClearValue.g = green;
687
 
        b->accumClearValue.b = blue;
688
 
        b->accumClearValue.a = alpha;
689
 
        DIRTY(bb->dirty, g->neg_bitid);
690
 
        DIRTY(bb->clearAccum, g->neg_bitid);
 
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);
691
741
}
692
742
 
693
743
void STATE_APIENTRY crStateDepthMask (GLboolean b) 
694
744
{
695
 
        CRContext *g = GetCurrentContext();
696
 
        CRBufferState *bs = &(g->buffer);
697
 
        CRStateBits *sp = GetCurrentBits();
698
 
        CRBufferBits *bb = &(sp->buffer);
699
 
 
700
 
        if (g->current.inBeginEnd)
701
 
        {
702
 
                crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "DepthMask called in begin/end");
703
 
                return;
704
 
        }
705
 
 
706
 
        FLUSH();
707
 
 
708
 
        bs->depthMask = b;
709
 
        DIRTY(bb->dirty, g->neg_bitid);
710
 
        DIRTY(bb->depthMask, g->neg_bitid);
 
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);
711
761
}