1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
/*
* PARSEC - Rasterizer API Functions
*
* $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:40 $
*
* Orginally written by:
* Copyright (c) Markus Hadwiger <msh@parsec.org> 1999
* Copyright (c) Clemens Beer <cbx@parsec.org> 1999
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// C library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// compilation flags/debug support
#include "config.h"
#include "debug.h"
// general definitions
#include "general.h"
#include "objstruc.h"
// global externals
#include "globals.h"
// local module header
#include "ro_api.h"
// opengl header
#include "r_gl.h"
// proprietary module headers
#include "con_aux.h"
// current opengl state as relevant to rasterization --------------------------
//
struct openglstate_s {
// glEnable state
bool
texturing, // GL_TEXTURE_2D
alphatest, // GL_ALPHA_TEST
blending, // GL_BLEND
depthtest, // GL_DEPTH_TEST
linesmooth, // GL_LINE_SMOOTH
pointsmooth; // GL_POINT_SMOOTH
// depth buffer config
GLenum depthfunc; // glDepthFunc()
GLboolean depthmask; // glDepthMask()
// depth range [glDepthRange()]
GLclampd depthrange_zNear;
GLclampd depthrange_zFar;
// blend function [glBlendFunc()]
GLenum blendfunc_sfactor;
GLenum blendfunc_dfactor;
// alpha test function [glAlphaFunc()]
GLenum alphatest_func;
GLclampf alphatest_ref;
// point size [glPointSize()]
GLfloat pointsize;
// vertex arrays (client states and pointers)
dword clientstate_bits; // glEnableClientState()
int clientstate_user; // user id
void* clientstate_base; // gl{Vertex|Color|TexCoord}Pointer()
};
openglstate_s DefaultOpenGLState = {
false,
false,
false,
false,
false,
false,
GL_LESS,
GL_TRUE,
0.0,
1.0,
GL_ONE,
GL_ZERO,
GL_ALWAYS,
0.0f,
1.0f,
VTXARRAY_NONE,
VTXPTRS_NONE,
0,
};
openglstate_s OpenGLState = DefaultOpenGLState;
// Initialize tracked state values based on current GL state ------------------
//
void RO_InitializeState()
{
openglstate_s &state = OpenGLState;
// glEnable state
state.texturing = glIsEnabled(GL_TEXTURE_2D) == GL_TRUE;
state.alphatest = glIsEnabled(GL_ALPHA_TEST) == GL_TRUE;
state.blending = glIsEnabled(GL_BLEND) == GL_TRUE;
state.depthtest = glIsEnabled(GL_DEPTH_TEST) == GL_TRUE;
state.linesmooth = glIsEnabled(GL_LINE_SMOOTH) == GL_TRUE;
state.pointsmooth = glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE;
// depth buffer
glGetIntegerv(GL_DEPTH_FUNC, (GLint *) &state.depthfunc);
glGetBooleanv(GL_DEPTH_WRITEMASK, &state.depthmask);
// depth range
GLfloat depthrange[] = {0.0f, 1.0f};
glGetFloatv(GL_DEPTH_RANGE, depthrange);
state.depthrange_zNear = depthrange[0];
state.depthrange_zFar = depthrange[1];
// blending
glGetIntegerv(GL_BLEND_SRC_RGB, (GLint *) &state.blendfunc_sfactor);
glGetIntegerv(GL_BLEND_DST_RGB, (GLint *) &state.blendfunc_dfactor);
// alpha testing
glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *) &state.alphatest_func);
glGetFloatv(GL_ALPHA_TEST_REF, &state.alphatest_ref);
// point size
glGetFloatv(GL_POINT_SIZE, &state.pointsize);
// vertex array crap
state.clientstate_user = VTXPTRS_NONE;
state.clientstate_base = NULL;
// disable all vertex array attributes
state.clientstate_bits = 0;
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
// set GL server-side capabilities --------------------------------------------
//
void RO_SetCapability(GLenum cap, bool enable)
{
bool * curstate = NULL;
switch (cap) {
case GL_TEXTURE_2D:
curstate = &OpenGLState.texturing;
break;
case GL_ALPHA_TEST:
curstate = &OpenGLState.alphatest;
break;
case GL_BLEND:
curstate = &OpenGLState.blending;
break;
case GL_DEPTH_TEST:
curstate = &OpenGLState.depthtest;
break;
case GL_LINE_SMOOTH:
curstate = &OpenGLState.linesmooth;
break;
case GL_POINT_SMOOTH:
curstate = &OpenGLState.pointsmooth;
break;
}
if (curstate == NULL || *curstate != enable) {
if (enable) {
glEnable(cap);
} else {
glDisable(cap);
}
if (curstate != NULL) {
*curstate = enable;
}
}
}
// determine if depth compare is enabled --------------------------------------
//
int RO_DepthCmpEnabled()
{
return OpenGLState.depthtest;
}
// determine if depth write is enabled ----------------------------------------
//
int RO_DepthWriteEnabled()
{
return OpenGLState.depthmask;
// return ( OpenGLState.depthtest && OpenGLState.depthmask );
}
// wrapper for GL_DEPTH_TEST state --------------------------------------------
//
void RO_EnableDepthTest( int enable )
{
RO_SetCapability(GL_DEPTH_TEST, enable);
}
// wrapper for glDepthFunc() --------------------------------------------------
//
void RO_DepthFunc( GLenum func )
{
if ( func != OpenGLState.depthfunc )
glDepthFunc( func );
OpenGLState.depthfunc = func;
}
// wrapper for glDepthMask() --------------------------------------------------
//
void RO_DepthMask( GLboolean flag )
{
if ( flag != OpenGLState.depthmask )
glDepthMask( flag );
OpenGLState.depthmask = flag;
}
// wrapper for glBlendFunc() --------------------------------------------------
//
void RO_BlendFunc( GLenum sfactor, GLenum dfactor )
{
if ( sfactor != OpenGLState.blendfunc_sfactor || dfactor != OpenGLState.blendfunc_dfactor )
glBlendFunc( sfactor, dfactor );
OpenGLState.blendfunc_sfactor = sfactor;
OpenGLState.blendfunc_dfactor = dfactor;
}
// wrapper for glAlphaFunc() --------------------------------------------------
//
void RO_AlphaFunc( GLenum func, GLclampf ref )
{
if ( func != OpenGLState.alphatest_func || ref != OpenGLState.alphatest_ref )
glAlphaFunc( func, ref );
OpenGLState.alphatest_func = func;
OpenGLState.alphatest_ref = ref;
}
// wrapper for glEnable/glDisable( GL_ALPHA_TEST ) ----------------------------
//
void RO_AlphaTest( int enable )
{
RO_SetCapability(GL_ALPHA_TEST, enable);
}
// wrapper for glEnable/glDisable( GL_POINT_SMOOTH ) --------------------------
//
void RO_PointSmooth( int enable )
{
RO_SetCapability(GL_POINT_SMOOTH, enable);
}
// wrapper for glEnable/glDisable( GL_LINE_SMOOTH ) ---------------------------
//
void RO_LineSmooth( int enable )
{
RO_SetCapability(GL_LINE_SMOOTH, enable);
}
// wrapper for glPointSize() --------------------------------------------------
//
void RO_PointSize( GLfloat size )
{
if ( OpenGLState.pointsize != size ) {
glPointSize( size );
}
OpenGLState.pointsize = size;
}
// enable/disable opengl client state -----------------------------------------
//
PRIVATE
inline void RO_CheckClientState(dword statebits, int state, GLenum glstate)
{
if (statebits & state) {
if ((OpenGLState.clientstate_bits & state) == 0) {
OpenGLState.clientstate_bits |= state;
glEnableClientState(glstate);
}
} else {
if (OpenGLState.clientstate_bits & state) {
OpenGLState.clientstate_bits &= ~state;
glDisableClientState(glstate);
}
}
}
// enable/disable client state vector -----------------------------------------
//
void RO_ClientState( dword statebits )
{
RO_CheckClientState( statebits, VTXARRAY_VERTICES, GL_VERTEX_ARRAY );
RO_CheckClientState( statebits, VTXARRAY_COLORS, GL_COLOR_ARRAY );
RO_CheckClientState( statebits, VTXARRAY_TEXCOORDS, GL_TEXTURE_COORD_ARRAY );
// RO_CheckClientState( statebits, VTXARRAY_EDGEFLAGS, GL_EDGE_FLAG_ARRAY );
RO_CheckClientState( statebits, VTXARRAY_NORMALS, GL_NORMAL_ARRAY );
}
// check whether vertex pointers must be made current, remember as current ----
//
int RO_ArrayMakeCurrent( int userid, void *base )
{
// user id and base pointer must match
if ( ( OpenGLState.clientstate_user == userid ) &&
( OpenGLState.clientstate_base == base ) )
return FALSE;
OpenGLState.clientstate_user = userid;
OpenGLState.clientstate_base = base;
return TRUE;
}
// possible states of texture environment -------------------------------------
//
struct configs_textureenvironment_s {
int texturingon;
GLint texenvmode;
GLenum shademodel;
} Configs_TextureEnvironment[] = {
// [ITER_CONSTRGB] = [FLAT SHADING / DONT_CARE]
// color_out = color_constant;
// alpha_out = undefined;
{
FALSE,
0,
GL_FLAT
},
// [ITER_CONSTRGBA] = [FLAT SHADING / CONST_ALPHA]
// color_out = color_constant;
// alpha_out = alpha_constant;
{
FALSE,
0,
GL_FLAT
},
// [ITER_RGB] = [GOURAUD SHADING / DONT_CARE]
// color_out = color_iterated;
// alpha_out = undefined;
{
FALSE,
0,
GL_SMOOTH
},
// [ITER_RGBA] = [GOURAUD SHADING / ITERATED_ALPHA]
// color_out = color_iterated;
// alpha_out = alpha_iterated;
{
FALSE,
0,
GL_SMOOTH
},
// [ITER_TEXONLY] = [UNSHADED TEXTURE / TEXTURE_ALPHA]
// color_out = color_texture;
// alpha_out = alpha_texture;
{
TRUE,
GL_REPLACE,
GL_FLAT,
},
// [ITER_TEXCONSTA] = [UNSHADED TEXTURE / SCALED_TEXTURE_ALPHA]
// color_out = color_texture;
// alpha_out = alpha_texture * alpha_constant;
{
TRUE,
GL_REPLACE,
GL_FLAT,
},
// [ITER_TEXCONSTRGB] = [FLAT-SHADED TEXTURE / TEXTURE_ALPHA]
// color_out = color_texture * color_constant;
// alpha_out = alpha_texture;
{
TRUE,
GL_MODULATE,
GL_FLAT
},
// [ITER_TEXCONSTRGBA] = [FLAT-SHADED TEXTURE / SCALED_TEXTURE_ALPHA]
// color_out = color_texture * color_constant;
// alpha_out = alpha_texture * alpha_constant;
{
TRUE,
GL_MODULATE,
GL_FLAT
},
// [ITER_TEXA] = [UNSHADED TEXTURE / MODULATED_TEXTURE_ALPHA]
// color_out = color_texture;
// alpha_out = alpha_texture * alpha_iterated;
{
TRUE,
GL_MODULATE,
GL_SMOOTH,
},
// [ITER_TEXRGB] = [GOURAUD-SHADED (DIFFUSELY LIT) TEXTURE / TEXTURE_ALPHA]
// color_out = color_texture * color_iterated;
// alpha_out = alpha_texture;
{
TRUE, // must be GL_RGBA
GL_MODULATE,
GL_SMOOTH // alpha of glColor() must be 1.0
},
// [ITER_TEXRGBA] = [GOURAUD-SHADED (DIFFUSELY LIT) TEXTURE / MODULATED_TEXTURE_ALPHA]
// color_out = color_texture * color_iterated;
// alpha_out = alpha_texture * alpha_iterated;
{
TRUE, // must be GL_RGBA
GL_MODULATE,
GL_SMOOTH
},
// [CONSTRGBTEXA] = [FLAT SHADING / TEXTURE_ALPHA]
// color_out = color_constant;
// alpha_out = alpha_texture;
{
TRUE, // must be GL_ALPHA
GL_REPLACE,
GL_FLAT
},
// [CONSTRGBATEXA] = [FLAT SHADING / SCALED_TEXTURE_ALPHA]
// color_out = color_constant;
// alpha_out = alpha_texture * alpha_constant;
{
TRUE, // must be GL_ALPHA
GL_MODULATE,
GL_FLAT
},
// [ITER_RGBTEXA] = [GOURAUD SHADING / TEXTURE_ALPHA]
// color_out = color_iterated;
// alpha_out = alpha_texture;
{
TRUE, // must be GL_ALPHA
GL_REPLACE,
GL_SMOOTH
},
// [ITER_RGBATEXA] = [GOURAUD SHADING / MODULATED_TEXTURE_ALPHA]
// color_out = color_iterated;
// alpha_out = alpha_texture * alpha_iterated;
{
TRUE, // must be GL_ALPHA
GL_MODULATE,
GL_SMOOTH
},
};
#define CONFIG_TEXTUREENVIRONMENT_CONSTRGB 0
#define CONFIG_TEXTUREENVIRONMENT_CONSTRGBA 1
#define CONFIG_TEXTUREENVIRONMENT_RGB 2
#define CONFIG_TEXTUREENVIRONMENT_RGBA 3
#define CONFIG_TEXTUREENVIRONMENT_TEXONLY 4
#define CONFIG_TEXTUREENVIRONMENT_TEXCONSTA 5
#define CONFIG_TEXTUREENVIRONMENT_TEXCONSTRGB 6
#define CONFIG_TEXTUREENVIRONMENT_TEXCONSTRGBA 7
#define CONFIG_TEXTUREENVIRONMENT_TEXA 8
#define CONFIG_TEXTUREENVIRONMENT_TEXRGB 9
#define CONFIG_TEXTUREENVIRONMENT_TEXRGBA 10
#define CONFIG_TEXTUREENVIRONMENT_CONSTRGBTEXA 11
#define CONFIG_TEXTUREENVIRONMENT_CONSTRGBATEXA 12
#define CONFIG_TEXTUREENVIRONMENT_RGBTEXA 13
#define CONFIG_TEXTUREENVIRONMENT_RGBATEXA 14
#define CONFIG_TEXTUREENVIRONMENT_NUMCONFIGS 15
#define CONFIG_TEXTUREENVIRONMENT_NUMCONFIGS_BASE 15
#define CONFIG_TEXTUREENVIRONMENT_UNDEFINED -1
int Iter_TextureEnvironment[] = {
CONFIG_TEXTUREENVIRONMENT_CONSTRGB, // iter_constrgb
CONFIG_TEXTUREENVIRONMENT_CONSTRGBA, // iter_constrgba
CONFIG_TEXTUREENVIRONMENT_RGB, // iter_rgb
CONFIG_TEXTUREENVIRONMENT_RGBA, // iter_rgba
CONFIG_TEXTUREENVIRONMENT_TEXONLY, // iter_texonly
CONFIG_TEXTUREENVIRONMENT_TEXCONSTA, // iter_texconsta
CONFIG_TEXTUREENVIRONMENT_TEXCONSTRGB, // iter_texconstrgb
CONFIG_TEXTUREENVIRONMENT_TEXCONSTRGBA, // iter_texconstrgba
CONFIG_TEXTUREENVIRONMENT_TEXA, // iter_texa
CONFIG_TEXTUREENVIRONMENT_TEXRGB, // iter_texrgb
CONFIG_TEXTUREENVIRONMENT_TEXRGBA, // iter_texrgba
CONFIG_TEXTUREENVIRONMENT_CONSTRGBTEXA, // iter_constrgbtexa
CONFIG_TEXTUREENVIRONMENT_CONSTRGBATEXA, // iter_constrgbatexa
CONFIG_TEXTUREENVIRONMENT_RGBTEXA, // iter_rgbtexa
CONFIG_TEXTUREENVIRONMENT_RGBATEXA, // iter_rgbatexa
};
#define CONFIG_TEXTUREENVIRONMENT_NUMTYPES CALC_NUM_ARRAY_ENTRIES( Iter_TextureEnvironment )
// possible states of blend function ------------------------------------------
//
struct configs_blendfunction_s {
int active;
GLenum blendfunc_sfactor;
GLenum blendfunc_dfactor;
} Configs_BlendFunction[] = {
// [OVERWRITE]
// color_out = color_src;
// alpha_out = alpha_src;
{
FALSE,
GL_ONE,
GL_ZERO
},
// [WEIGHTED_BLEND]
// color_out = color_src * alpha + color_dst * ( 1 - alpha );
// alpha_out = alpha_src;
{
TRUE,
GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA
},
// [MODULATE]
// color_out = color_src * color_dst;
// alpha_out = alpha_src;
{
TRUE,
GL_DST_COLOR,
GL_ZERO
},
// [SPECULAR_ADD]
// color_out = color_src + color_dst;
// alpha_out = alpha_src;
{
TRUE,
GL_ONE,
GL_ONE
},
// [PREMULTIPLIED_BLEND]
// color_out = color_src + color_dst * ( 1 - alpha );
// alpha_out = alpha_src;
{
TRUE,
GL_ONE,
GL_ONE_MINUS_SRC_ALPHA
},
// [ADDITIVE_BLEND]
// color_out = color_src * color_alpha + color_dst;
// alpha_out = alpha_src;
{
TRUE,
GL_SRC_ALPHA,
GL_ONE
},
};
#define CONFIG_BLENDFUNCTION_OVERWRITE 0
#define CONFIG_BLENDFUNCTION_WEIGHTED_BLEND 1
#define CONFIG_BLENDFUNCTION_MODULATE 2
#define CONFIG_BLENDFUNCTION_SPECULAR_ADD 3
#define CONFIG_BLENDFUNCTION_PREMULTIPLIED_BLEND 4
#define CONFIG_BLENDFUNCTION_ADDITIVE_BLEND 5
#define CONFIG_BLENDFUNCTION_NUMCONFIGS 6
#define CONFIG_BLENDFUNCTION_UNDEFINED -1
int Iter_BlendFunction[] = {
CONFIG_BLENDFUNCTION_OVERWRITE, // iter_overwrite
CONFIG_BLENDFUNCTION_WEIGHTED_BLEND, // iter_alphablend
CONFIG_BLENDFUNCTION_MODULATE, // iter_modulate
CONFIG_BLENDFUNCTION_SPECULAR_ADD, // iter_specularadd
CONFIG_BLENDFUNCTION_PREMULTIPLIED_BLEND, // iter_premulblend
CONFIG_BLENDFUNCTION_ADDITIVE_BLEND, // iter_additiveblend
};
#define CONFIG_BLENDFUNCTION_NUMTYPES CALC_NUM_ARRAY_ENTRIES( Iter_BlendFunction )
// currently active configurations --------------------------------------------
//
int last_texenv_config = CONFIG_TEXTUREENVIRONMENT_UNDEFINED;
int last_blendfunc_config = CONFIG_BLENDFUNCTION_UNDEFINED;
// invalidate rasterizer state ------------------------------------------------
//
void RO_InvalidateRasterizerState()
{
last_texenv_config = CONFIG_TEXTUREENVIRONMENT_UNDEFINED;
last_blendfunc_config = CONFIG_BLENDFUNCTION_UNDEFINED;
OpenGLState = DefaultOpenGLState;
}
// init rasterizer to specified state -----------------------------------------
//
void RO_InitRasterizerState( dword itertype, dword raststate, dword rastmask )
{
//NOTE:
// the following things cannot be set here due
// to the inner workings of OpenGL texture mapping:
// - texture clamp mode
// - mip-map mode
// - filtering mode
// (the corresponding rast_xx flags will be ignored.)
// isolate basic iteration type
dword iterbase = itertype & iter_base_mask;
// fetch desired config
ASSERT( iterbase < CONFIG_TEXTUREENVIRONMENT_NUMTYPES );
int texenv_config = Iter_TextureEnvironment[ iterbase ];
ASSERT( texenv_config >= 0 );
ASSERT( texenv_config < CONFIG_TEXTUREENVIRONMENT_NUMCONFIGS );
// check if texture environment configuration needs to be changed
if ( texenv_config != last_texenv_config ) {
// remember config
last_texenv_config = texenv_config;
// configure shading model
glShadeModel( Configs_TextureEnvironment[ texenv_config ].shademodel );
bool texturingon = Configs_TextureEnvironment[ texenv_config ].texturingon;
RO_SetCapability(GL_TEXTURE_2D, texturingon);
if ( texturingon ) {
// configure texture environment
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
Configs_TextureEnvironment[ texenv_config ].texenvmode );
}
}
// isolate composition type
dword comptype = ( itertype & iter_compose_mask ) >> iter_compose_shift;
// fetch desired config
ASSERT( comptype < CONFIG_BLENDFUNCTION_NUMTYPES );
int blendfunc_config = Iter_BlendFunction[ comptype ];
ASSERT( blendfunc_config >= 0 );
ASSERT( blendfunc_config < CONFIG_BLENDFUNCTION_NUMCONFIGS );
// check if blend function configuration needs to be changed
if ( blendfunc_config != last_blendfunc_config ) {
// remember config
last_blendfunc_config = blendfunc_config;
bool blendactive = Configs_BlendFunction[ blendfunc_config ].active;
RO_SetCapability(GL_BLEND, blendactive);
// configure blend function
if ( blendactive ) {
glBlendFunc(
Configs_BlendFunction[ blendfunc_config ].blendfunc_sfactor,
Configs_BlendFunction[ blendfunc_config ].blendfunc_dfactor );
}
}
// depth buffer write
if ( ( rastmask & rast_mask_zwrite ) == 0 ) {
int depthmask = ( raststate & rast_zwrite ) ? GL_TRUE : GL_FALSE;
RO_DepthMask(depthmask);
}
// depth buffer compare
if ( ( rastmask & rast_mask_zcompare ) == 0 ) {
bool depthtest = ( raststate & rast_zcompare ) != 0;
RO_SetCapability(GL_DEPTH_TEST, depthtest);
if ( depthtest ) {
RO_DepthFunc(GL_GREATER);
}
}
}
// set combine state of texture units (mostly for multipass mapping) ----------
//
void RO_TextureCombineState( dword texcomb )
{
//TODO:
}
// set rasterizer state to default --------------------------------------------
//
#ifndef NO_DEFAULT_RASTERIZER_STATE
void RO_DefaultRasterizerState()
{
if ( AUX_NO_DEFAULT_RASTERIZER_STATE )
return;
dword itertype = iter_rgb;
dword raststate = rast_chromakeyoff;
dword rastmask = rast_mask_zbuffer | rast_mask_texclamp |
rast_mask_mipmap | rast_mask_texfilter;
RO_InitRasterizerState( itertype, raststate, rastmask );
RO_TextureCombineState( texcomb_decal );
}
#endif
|