1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
* Mupen64plus - glide64/wrapper/geometry.cpp *
3
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4
* Copyright (C) 2005-2006 Hacktarux *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
#define GL_GLEXT_PROTOTYPES
25
#include <SDL_opengl.h>
30
#define Z_MAX (65536.0f)
31
//#define Z_MAX 1000.0f
45
static int fog_ext_off;
46
static int fog_ext_en;
51
//static float depth_bias;
53
inline float ZCALC(const float & z, const float & q) {
54
//float res = z_en ? ((z) / Z_MAX) / (q-(float)depth_bias*q*q*zscale*2/128.0f) : 1.0f;
55
//float res = z_en ? ((z) / Z_MAX) / (q-(float)depth_bias*zscale*9/255000000.0f) : 1.0f;
56
float res = z_en ? ((z) / Z_MAX) / (q) : 1.0f;
60
#define zclamp (1.0f-1.0f/zscale)
61
static inline void zclamp_glVertex4f(float a, float b, float c, float d)
63
if (c<zclamp) c = zclamp;
66
#define glVertex4f(a,b,c,d) zclamp_glVertex4f(a,b,c,d)
69
static inline float ytex(int tmu, float y) {
71
return invtex[tmu] - y;
78
xy_en = q_en = pargb_en = st0_en = st1_en = z_en = 0;
82
glDisable(GL_CULL_FACE);
83
glDisable(GL_DEPTH_TEST);
87
grCoordinateSpace( GrCoordinateSpaceMode_t mode )
89
LOG("grCoordinateSpace(%d)\r\n", mode);
92
case GR_WINDOW_COORDS:
95
display_warning("unknwown coordinate space : %x", mode);
100
grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode)
102
LOG("grVertexLayout(%d,%d,%d)\r\n", param, offset, mode);
117
case GR_PARAM_FOG_EXT:
119
fog_ext_off = offset;
134
display_warning("unknown grVertexLayout parameter : %x", param);
138
FX_ENTRY void FX_CALL
139
grCullMode( GrCullMode_t mode )
141
LOG("grCullMode(%d)\r\n", mode);
142
static int oldmode = -1, oldinv = -1;
144
if (inverted_culling == oldinv && oldmode == mode)
147
oldinv = inverted_culling;
150
case GR_CULL_DISABLE:
151
glDisable(GL_CULL_FACE);
153
case GR_CULL_NEGATIVE:
154
if (!inverted_culling)
155
glCullFace(GL_FRONT);
158
glEnable(GL_CULL_FACE);
160
case GR_CULL_POSITIVE:
161
if (!inverted_culling)
164
glCullFace(GL_FRONT);
165
glEnable(GL_CULL_FACE);
168
display_warning("unknown cull mode : %x", mode);
174
FX_ENTRY void FX_CALL
175
grDepthBufferMode( GrDepthBufferMode_t mode )
177
LOG("grDepthBufferMode(%d)\r\n", mode);
180
case GR_DEPTHBUFFER_DISABLE:
181
glDisable(GL_DEPTH_TEST);
184
case GR_DEPTHBUFFER_WBUFFER:
185
case GR_DEPTHBUFFER_WBUFFER_COMPARE_TO_BIAS:
186
glEnable(GL_DEPTH_TEST);
189
case GR_DEPTHBUFFER_ZBUFFER:
190
case GR_DEPTHBUFFER_ZBUFFER_COMPARE_TO_BIAS:
191
glEnable(GL_DEPTH_TEST);
195
display_warning("unknown depth buffer mode : %x", mode);
199
FX_ENTRY void FX_CALL
200
grDepthBufferFunction( GrCmpFnc_t function )
202
LOG("grDepthBufferFunction(%d)\r\n", function);
207
glDepthFunc(GL_LEQUAL);
209
glDepthFunc(GL_GEQUAL);
213
glDepthFunc(GL_GEQUAL);
215
glDepthFunc(GL_LEQUAL);
219
glDepthFunc(GL_GREATER);
221
glDepthFunc(GL_LESS);
224
glDepthFunc(GL_ALWAYS);
227
// if (w_buffer_mode)
228
// glDepthFunc(GL_NOTEQUAL);
230
glDepthFunc(GL_EQUAL);
234
glDepthFunc(GL_LESS);
236
glDepthFunc(GL_GREATER);
239
glDepthFunc(GL_NEVER);
241
case GR_CMP_NOTEQUAL:
242
// if (w_buffer_mode)
243
// glDepthFunc(GL_EQUAL);
245
glDepthFunc(GL_NOTEQUAL);
249
display_warning("unknown depth buffer function : %x", function);
253
FX_ENTRY void FX_CALL
254
grDepthMask( FxBool mask )
256
LOG("grDepthMask(%d)\r\n", mask);
261
float biasFactor = 0;
262
void FindBestDepthBias()
264
float f, bestz = 0.25f;
266
if (biasFactor) return;
267
biasFactor = 64.0f; // default value
268
glPushAttrib(GL_ALL_ATTRIB_BITS);
269
glEnable(GL_DEPTH_TEST);
270
glDepthFunc(GL_ALWAYS);
271
glEnable(GL_POLYGON_OFFSET_FILL);
272
glDrawBuffer(GL_BACK);
273
glReadBuffer(GL_BACK);
275
glDisable(GL_ALPHA_TEST);
276
glColor4ub(255,255,255,255);
277
glDepthMask(GL_TRUE);
278
for (x=0, f=1.0f; f<=65536.0f; x+=4, f*=2.0f) {
280
glPolygonOffset(0, f);
281
glBegin(GL_TRIANGLE_STRIP);
282
glVertex3f(float(x+4 - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5);
283
glVertex3f(float(x - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5);
284
glVertex3f(float(x+4 - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5);
285
glVertex3f(float(x - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5);
288
glReadPixels(x+2, 2+viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
295
printf("f %g z %g\n", f, z);
297
printf(" --> bias factor %g\n", biasFactor);
300
// SDL_GL_SwapBuffers();
304
FX_ENTRY void FX_CALL
305
grDepthBiasLevel( FxI32 level )
307
LOG("grDepthBiasLevel(%d)\r\n", level);
308
//depth_bias = level;
312
glPolygonOffset(1.0f, -(float)level*zscale/255.0f);
314
glPolygonOffset(0, (float)level*biasFactor);
315
//glPolygonOffset(0, (float)level*128.0f*zscale/2);
316
glEnable(GL_POLYGON_OFFSET_FILL);
320
glPolygonOffset(0,0);
321
glDisable(GL_POLYGON_OFFSET_FILL);
327
FX_ENTRY void FX_CALL
328
grDrawTriangle( const void *a, const void *b, const void *c )
330
float *a_x = (float*)a + xy_off/sizeof(float);
331
float *a_y = (float*)a + xy_off/sizeof(float) + 1;
332
float *a_z = (float*)a + z_off/sizeof(float);
333
float *a_q = (float*)a + q_off/sizeof(float);
334
unsigned char *a_pargb = (unsigned char*)a + pargb_off;
335
float *a_s0 = (float*)a + st0_off/sizeof(float);
336
float *a_t0 = (float*)a + st0_off/sizeof(float) + 1;
337
float *a_s1 = (float*)a + st1_off/sizeof(float);
338
float *a_t1 = (float*)a + st1_off/sizeof(float) + 1;
339
float *a_fog = (float*)a + fog_ext_off/sizeof(float);
341
float *b_x = (float*)b + xy_off/sizeof(float);
342
float *b_y = (float*)b + xy_off/sizeof(float) + 1;
343
float *b_z = (float*)b + z_off/sizeof(float);
344
float *b_q = (float*)b + q_off/sizeof(float);
345
unsigned char *b_pargb = (unsigned char*)b + pargb_off;
346
float *b_s0 = (float*)b + st0_off/sizeof(float);
347
float *b_t0 = (float*)b + st0_off/sizeof(float) + 1;
348
float *b_s1 = (float*)b + st1_off/sizeof(float);
349
float *b_t1 = (float*)b + st1_off/sizeof(float) + 1;
350
float *b_fog = (float*)b + fog_ext_off/sizeof(float);
352
float *c_x = (float*)c + xy_off/sizeof(float);
353
float *c_y = (float*)c + xy_off/sizeof(float) + 1;
354
float *c_z = (float*)c + z_off/sizeof(float);
355
float *c_q = (float*)c + q_off/sizeof(float);
356
unsigned char *c_pargb = (unsigned char*)c + pargb_off;
357
float *c_s0 = (float*)c + st0_off/sizeof(float);
358
float *c_t0 = (float*)c + st0_off/sizeof(float) + 1;
359
float *c_s1 = (float*)c + st1_off/sizeof(float);
360
float *c_t1 = (float*)c + st1_off/sizeof(float) + 1;
361
float *c_fog = (float*)c + fog_ext_off/sizeof(float);
362
LOG("grDrawTriangle()\r\n");
364
//if(*a_fog == 0.0f) *a_fog = 1.0f;
365
//if(*b_fog == 0.0f) *b_fog = 1.0f;
366
//if(*c_fog == 0.0f) *c_fog = 1.0f;
368
// ugly ? i know but nvidia drivers are losing the viewport otherwise
369
if(!render_to_texture && viewport_width)
371
glViewport(0, viewport_offset, viewport_width, viewport_height);
377
if(glsl_support && need_to_compile) compile_shader();
379
glBegin(GL_TRIANGLES);
381
if (nbTextureUnits > 2)
384
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width,
385
ytex(0, *a_t0 / *a_q / (float)tex1_height));
387
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width,
388
ytex(1, *a_t1 / *a_q / (float)tex0_height));
393
glTexCoord2f(*a_s0 / *a_q / (float)tex0_width,
394
ytex(0, *a_t0 / *a_q / (float)tex0_height));
397
glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f);
398
if (fog_enabled && fog_coord_support)
402
if(!fog_ext_en || fog_enabled != 2)
403
glFogCoordfEXT((1.0f / *a_q)/*/256.0f*/);
405
glFogCoordfEXT((1.0f / *a_fog)/*/256.0f*/);
409
if(!fog_ext_en || fog_enabled != 2)
410
glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
412
glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f);
413
/*if(!fog_ext_en || fog_enabled != 2)
414
glFogCoordfEXT((1.0f / *a_q)/255.0f);
416
glFogCoordfEXT((1.0f / *a_fog)/255.0f);*/
419
glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q,
420
-(*a_y - (float)heighto) / (float)(height/2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q);
422
if (nbTextureUnits > 2)
425
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width,
426
ytex(0, *b_t0 / *b_q / (float)tex1_height));
428
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width,
429
ytex(1, *b_t1 / *b_q / (float)tex0_height));
434
glTexCoord2f(*b_s0 / *b_q / (float)tex0_width,
435
ytex(0, *b_t0 / *b_q / (float)tex0_height));
438
glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f);
439
if (fog_enabled && fog_coord_support)
443
if(!fog_ext_en || fog_enabled != 2)
444
glFogCoordfEXT((1.0f / *b_q)/*/256.0f*/);
446
glFogCoordfEXT((1.0f / *b_fog)/*/256.0f*/);
450
if(!fog_ext_en || fog_enabled != 2)
451
glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
453
glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f);
454
/*if(!fog_ext_en || fog_enabled != 2)
455
glFogCoordfEXT((1.0f / *b_q)/255.0f);
457
glFogCoordfEXT((1.0f / *b_fog)/255.0f);*/
461
glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q,
462
-(*b_y - (float)heighto) / (float)(height/2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q);
464
if (nbTextureUnits > 2)
467
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *c_s0 / *c_q / (float)tex1_width,
468
ytex(0, *c_t0 / *c_q / (float)tex1_height));
470
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *c_s1 / *c_q / (float)tex0_width,
471
ytex(1, *c_t1 / *c_q / (float)tex0_height));
476
glTexCoord2f(*c_s0 / *c_q / (float)tex0_width,
477
ytex(0, *c_t0 / *c_q / (float)tex0_height));
480
glColor4f(c_pargb[2]/255.0f, c_pargb[1]/255.0f, c_pargb[0]/255.0f, c_pargb[3]/255.0f);
481
if (fog_enabled && fog_coord_support)
485
if(!fog_ext_en || fog_enabled != 2)
486
glFogCoordfEXT((1.0f / *c_q)/*/256.0f*/);
488
glFogCoordfEXT((1.0f / *c_fog)/*/256.0f*/);
492
if(!fog_ext_en || fog_enabled != 2)
493
glSecondaryColor3f((1.0f / *c_q) / 255.0f, 0.0f, 0.0f);
495
glSecondaryColor3f((1.0f / *c_fog) / 255.0f, 0.0f, 0.0f);
496
/*if(!fog_ext_en || fog_enabled != 2)
497
glFogCoordfEXT((1.0f / *c_q)/255.0f);
499
glFogCoordfEXT((1.0f / *c_fog)/255.0f);*/
502
glVertex4f((*c_x - (float)widtho) / (float)(width/2) / *c_q,
503
-(*c_y - (float)heighto) / (float)(height/2) / *c_q, ZCALC(*c_z ,*c_q), 1.0f / *c_q);
508
FX_ENTRY void FX_CALL
509
grDrawPoint( const void *pt )
511
float *x = (float*)pt + xy_off/sizeof(float);
512
float *y = (float*)pt + xy_off/sizeof(float) + 1;
513
float *z = (float*)pt + z_off/sizeof(float);
514
float *q = (float*)pt + q_off/sizeof(float);
515
unsigned char *pargb = (unsigned char*)pt + pargb_off;
516
float *s0 = (float*)pt + st0_off/sizeof(float);
517
float *t0 = (float*)pt + st0_off/sizeof(float) + 1;
518
float *s1 = (float*)pt + st1_off/sizeof(float);
519
float *t1 = (float*)pt + st1_off/sizeof(float) + 1;
520
float *fog = (float*)pt + fog_ext_off/sizeof(float);
521
LOG("grDrawPoint()\r\n");
525
if(glsl_support && need_to_compile) compile_shader();
529
if (nbTextureUnits > 2)
532
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
533
ytex(0, *t0 / *q / (float)tex1_height));
535
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
536
ytex(1, *t1 / *q / (float)tex0_height));
541
glTexCoord2f(*s0 / *q / (float)tex0_width,
542
ytex(0, *t0 / *q / (float)tex0_height));
545
glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f);
546
if (fog_enabled && fog_coord_support)
550
if(!fog_ext_en || fog_enabled != 2)
551
glFogCoordfEXT((1.0f / *q)/*/256.0f*/);
553
glFogCoordfEXT((1.0f / *fog)/*/256.0f*/);
557
if(!fog_ext_en || fog_enabled != 2)
558
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
560
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
561
/*if(!fog_ext_en || fog_enabled != 2)
562
glFogCoordfEXT((1.0f / *q)/255.0f);
564
glFogCoordfEXT((1.0f / *fog)/255.0f);*/
567
glVertex4f((*x - (float)widtho) / (float)(width/2) / *q,
568
-(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z ,*q), 1.0f / *q);
573
FX_ENTRY void FX_CALL
574
grDrawLine( const void *a, const void *b )
576
float *a_x = (float*)a + xy_off/sizeof(float);
577
float *a_y = (float*)a + xy_off/sizeof(float) + 1;
578
float *a_z = (float*)a + z_off/sizeof(float);
579
float *a_q = (float*)a + q_off/sizeof(float);
580
unsigned char *a_pargb = (unsigned char*)a + pargb_off;
581
float *a_s0 = (float*)a + st0_off/sizeof(float);
582
float *a_t0 = (float*)a + st0_off/sizeof(float) + 1;
583
float *a_s1 = (float*)a + st1_off/sizeof(float);
584
float *a_t1 = (float*)a + st1_off/sizeof(float) + 1;
585
float *a_fog = (float*)a + fog_ext_off/sizeof(float);
587
float *b_x = (float*)b + xy_off/sizeof(float);
588
float *b_y = (float*)b + xy_off/sizeof(float) + 1;
589
float *b_z = (float*)b + z_off/sizeof(float);
590
float *b_q = (float*)b + q_off/sizeof(float);
591
unsigned char *b_pargb = (unsigned char*)b + pargb_off;
592
float *b_s0 = (float*)b + st0_off/sizeof(float);
593
float *b_t0 = (float*)b + st0_off/sizeof(float) + 1;
594
float *b_s1 = (float*)b + st1_off/sizeof(float);
595
float *b_t1 = (float*)b + st1_off/sizeof(float) + 1;
596
float *b_fog = (float*)b + fog_ext_off/sizeof(float);
597
LOG("grDrawLine()\r\n");
599
//if(*a_fog == 0.0f) *a_fog = 1.0f;
600
//if(*b_fog == 0.0f) *b_fog = 1.0f;
604
if(glsl_support && need_to_compile) compile_shader();
608
if (nbTextureUnits > 2)
611
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, ytex(0, *a_t0 / *a_q / (float)tex1_height));
613
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, ytex(1, *a_t1 / *a_q / (float)tex0_height));
618
glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, ytex(0, *a_t0 / *a_q / (float)tex0_height));
621
glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f);
622
if (fog_enabled && fog_coord_support)
626
if(!fog_ext_en || fog_enabled != 2)
627
glFogCoordfEXT((1.0f / *a_q)/*/256.0f*/);
629
glFogCoordfEXT((1.0f / *a_fog)/*/256.0f*/);
633
if(!fog_ext_en || fog_enabled != 2)
634
glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
636
glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f);
637
/*if(!fog_ext_en || fog_enabled != 2)
638
glFogCoordfEXT((1.0f / *a_q)/255.0f);
640
glFogCoordfEXT((1.0f / *a_fog)/255.0f);*/
643
glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q,
644
-(*a_y - (float)heighto) / (float)(height/2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q);
646
if (nbTextureUnits > 2)
649
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width,
650
ytex(0, *b_t0 / *b_q / (float)tex1_height));
652
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width,
653
ytex(1, *b_t1 / *b_q / (float)tex0_height));
658
glTexCoord2f(*b_s0 / *b_q / (float)tex0_width,
659
ytex(0, *b_t0 / *b_q / (float)tex0_height));
662
glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f);
663
if (fog_enabled && fog_coord_support)
667
if(!fog_ext_en || fog_enabled != 2)
668
glFogCoordfEXT((1.0f / *b_q)/*/256.0f*/);
670
glFogCoordfEXT((1.0f / *b_fog)/*/256.0f*/);
674
if(!fog_ext_en || fog_enabled != 2)
675
glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
677
glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f);
678
/*if(!fog_ext_en || fog_enabled != 2)
679
glFogCoordfEXT((1.0f / *b_q)/255.0f);
681
glFogCoordfEXT((1.0f / *b_fog)/255.0f);*/
684
glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q,
685
-(*b_y - (float)heighto) / (float)(height/2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q);
690
FX_ENTRY void FX_CALL
691
grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers2)
694
float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
695
unsigned char *pargb;
696
void **pointers = (void**)pointers2;
697
LOG("grDrawVertexArray(%d,%d)\r\n", mode, Count);
701
if(glsl_support && need_to_compile) compile_shader();
705
case GR_TRIANGLE_FAN:
706
glBegin(GL_TRIANGLE_FAN);
709
display_warning("grDrawVertexArray : unknown mode : %x", mode);
712
for (i=0; i<Count; i++)
714
x = (float*)pointers[i] + xy_off/sizeof(float);
715
y = (float*)pointers[i] + xy_off/sizeof(float) + 1;
716
z = (float*)pointers[i] + z_off/sizeof(float);
717
q = (float*)pointers[i] + q_off/sizeof(float);
718
pargb = (unsigned char*)pointers[i] + pargb_off;
719
s0 = (float*)pointers[i] + st0_off/sizeof(float);
720
t0 = (float*)pointers[i] + st0_off/sizeof(float) + 1;
721
s1 = (float*)pointers[i] + st1_off/sizeof(float);
722
t1 = (float*)pointers[i] + st1_off/sizeof(float) + 1;
723
fog = (float*)pointers[i] + fog_ext_off/sizeof(float);
725
//if(*fog == 0.0f) *fog = 1.0f;
727
if (nbTextureUnits > 2)
730
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
731
ytex(0, *t0 / *q / (float)tex1_height));
733
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
734
ytex(1, *t1 / *q / (float)tex0_height));
739
glTexCoord2f(*s0 / *q / (float)tex0_width,
740
ytex(0, *t0 / *q / (float)tex0_height));
743
glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f);
744
if (fog_enabled && fog_coord_support)
748
if(!fog_ext_en || fog_enabled != 2)
749
glFogCoordfEXT((1.0f / *q)/*/256.0f*/);
751
glFogCoordfEXT((1.0f / *fog)/*/256.0f*/);
755
if(!fog_ext_en || fog_enabled != 2)
756
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
758
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
759
/*if(!fog_ext_en || fog_enabled != 2)
760
glFogCoordfEXT((1.0f / *q)/255.0f);
762
glFogCoordfEXT((1.0f / *fog)/255.0f);*/
765
//glFogCoordfEXT(192.0f);
766
//glSecondaryColor3f(192.0f / 256.0f,0,0);
767
//if((1.0f / *fog)/256.0f < 0.0f || (1.0f / *fog)/256.0f > 1.0f)
769
glVertex4f((*x - (float)widtho) / (float)(width/2) / *q,
770
-(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z, *q), 1.0f / *q);
775
FX_ENTRY void FX_CALL
776
grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count, void *pointers, FxU32 stride)
779
float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
780
unsigned char *pargb;
781
LOG("grDrawVertexArrayContiguous(%d,%d,%d)\r\n", mode, Count, stride);
783
// ZIGGY apparently, grDrawVertexArrayContiguous is only used to overwrite the
784
// whole screen, so we treat it as a grClearBuffer, no need to reload the texture
785
buffer_cleared = TRUE;
788
if(glsl_support && need_to_compile) compile_shader();
792
case GR_TRIANGLE_STRIP:
793
glBegin(GL_TRIANGLE_STRIP);
795
case GR_TRIANGLE_FAN:
796
glBegin(GL_TRIANGLE_FAN);
799
display_warning("grDrawVertexArrayContiguous : unknown mode : %x", mode);
802
for (i=0; i<Count; i++)
804
x = (float*)((unsigned char*)pointers+stride*i) + xy_off/sizeof(float);
805
y = (float*)((unsigned char*)pointers+stride*i) + xy_off/sizeof(float) + 1;
806
z = (float*)((unsigned char*)pointers+stride*i) + z_off/sizeof(float);
807
q = (float*)((unsigned char*)pointers+stride*i) + q_off/sizeof(float);
808
pargb = (unsigned char*)pointers+stride*i + pargb_off;
809
s0 = (float*)((unsigned char*)pointers+stride*i) + st0_off/sizeof(float);
810
t0 = (float*)((unsigned char*)pointers+stride*i) + st0_off/sizeof(float) + 1;
811
s1 = (float*)((unsigned char*)pointers+stride*i) + st1_off/sizeof(float);
812
t1 = (float*)((unsigned char*)pointers+stride*i) + st1_off/sizeof(float) + 1;
813
fog = (float*)((unsigned char*)pointers+stride*i) + fog_ext_off/sizeof(float);
815
//if(*fog == 0.0f) *fog = 1.0f;
817
if (nbTextureUnits > 2)
820
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
821
ytex(0, *t0 / *q / (float)tex1_height));
823
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
824
ytex(1, *t1 / *q / (float)tex0_height));
829
glTexCoord2f(*s0 / *q / (float)tex0_width,
830
ytex(0, *t0 / *q / (float)tex0_height));
833
glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f);
834
if (fog_enabled && fog_coord_support)
838
if(!fog_ext_en || fog_enabled != 2)
839
glFogCoordfEXT((1.0f / *q)/*/256.0f*/);
841
glFogCoordfEXT((1.0f / *fog)/*/256.0f*/);
845
if(!fog_ext_en || fog_enabled != 2)
846
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
848
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
850
/*if(!fog_ext_en || fog_enabled != 2)
851
glFogCoordfEXT((1.0f / *q)/255.0f);
853
glFogCoordfEXT((1.0f / *fog)/255.0f);*/
857
glVertex4f((*x - (float)widtho) / (float)(width/2) / *q,
858
-(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z, *q), 1.0f / *q);