Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glitch64/geometry.cpp
2 views
1
/*
2
* Glide64 - Glide video plugin for Nintendo 64 emulators.
3
* Copyright (c) 2002 Dave2001
4
* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
5
*
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
* any later version.
10
*
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.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*/
20
21
#include <stdio.h>
22
#ifdef _WIN32
23
#include <windows.h>
24
#endif // _WIN32
25
#include "glide.h"
26
#include "main.h"
27
28
#define Z_MAX (65536.0f)
29
30
static int xy_off;
31
static int xy_en;
32
static int z_en;
33
static int z_off;
34
static int q_off;
35
static int q_en;
36
static int pargb_off;
37
static int pargb_en;
38
static int st0_off;
39
static int st0_en;
40
static int st1_off;
41
static int st1_en;
42
static int fog_ext_off;
43
static int fog_ext_en;
44
45
int w_buffer_mode;
46
int inverted_culling;
47
int culling_mode;
48
49
inline float ZCALC(const float & z, const float & q) {
50
float res = z_en ? ((z) / Z_MAX) / (q) : 1.0f;
51
return res;
52
}
53
54
#define zclamp (1.0f-1.0f/zscale)
55
static inline void zclamp_glVertex4f(float a, float b, float c, float d)
56
{
57
if (c<zclamp) c = zclamp;
58
glVertex4f(a,b,c,d);
59
}
60
#define glVertex4f(a,b,c,d) zclamp_glVertex4f(a,b,c,d)
61
62
63
static inline float ytex(int tmu, float y) {
64
if (invtex[tmu])
65
return invtex[tmu] - y;
66
else
67
return y;
68
}
69
70
void init_geometry()
71
{
72
xy_en = q_en = pargb_en = st0_en = st1_en = z_en = 0;
73
w_buffer_mode = 0;
74
inverted_culling = 0;
75
76
glDisable(GL_CULL_FACE);
77
glDisable(GL_DEPTH_TEST);
78
}
79
80
FX_ENTRY void FX_CALL
81
grCoordinateSpace( GrCoordinateSpaceMode_t mode )
82
{
83
LOG("grCoordinateSpace(%d)\r\n", mode);
84
switch(mode)
85
{
86
case GR_WINDOW_COORDS:
87
break;
88
default:
89
display_warning("unknwown coordinate space : %x", mode);
90
}
91
}
92
93
FX_ENTRY void FX_CALL
94
grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode)
95
{
96
LOG("grVertexLayout(%d,%d,%d)\r\n", param, offset, mode);
97
switch(param)
98
{
99
case GR_PARAM_XY:
100
xy_en = mode;
101
xy_off = offset;
102
break;
103
case GR_PARAM_Z:
104
z_en = mode;
105
z_off = offset;
106
break;
107
case GR_PARAM_Q:
108
q_en = mode;
109
q_off = offset;
110
break;
111
case GR_PARAM_FOG_EXT:
112
fog_ext_en = mode;
113
fog_ext_off = offset;
114
break;
115
case GR_PARAM_PARGB:
116
pargb_en = mode;
117
pargb_off = offset;
118
break;
119
case GR_PARAM_ST0:
120
st0_en = mode;
121
st0_off = offset;
122
break;
123
case GR_PARAM_ST1:
124
st1_en = mode;
125
st1_off = offset;
126
break;
127
default:
128
display_warning("unknown grVertexLayout parameter : %x", param);
129
}
130
}
131
132
FX_ENTRY void FX_CALL
133
grCullMode( GrCullMode_t mode )
134
{
135
LOG("grCullMode(%d)\r\n", mode);
136
static int oldmode = -1, oldinv = -1;
137
culling_mode = mode;
138
if (inverted_culling == oldinv && oldmode == mode)
139
return;
140
oldmode = mode;
141
oldinv = inverted_culling;
142
switch(mode)
143
{
144
case GR_CULL_DISABLE:
145
glDisable(GL_CULL_FACE);
146
break;
147
case GR_CULL_NEGATIVE:
148
if (!inverted_culling)
149
glCullFace(GL_FRONT);
150
else
151
glCullFace(GL_BACK);
152
glEnable(GL_CULL_FACE);
153
break;
154
case GR_CULL_POSITIVE:
155
if (!inverted_culling)
156
glCullFace(GL_BACK);
157
else
158
glCullFace(GL_FRONT);
159
glEnable(GL_CULL_FACE);
160
break;
161
default:
162
display_warning("unknown cull mode : %x", mode);
163
}
164
}
165
166
// Depth buffer
167
168
FX_ENTRY void FX_CALL
169
grDepthBufferMode( GrDepthBufferMode_t mode )
170
{
171
LOG("grDepthBufferMode(%d)\r\n", mode);
172
switch(mode)
173
{
174
case GR_DEPTHBUFFER_DISABLE:
175
glDisable(GL_DEPTH_TEST);
176
w_buffer_mode = 0;
177
return;
178
case GR_DEPTHBUFFER_WBUFFER:
179
case GR_DEPTHBUFFER_WBUFFER_COMPARE_TO_BIAS:
180
glEnable(GL_DEPTH_TEST);
181
w_buffer_mode = 1;
182
break;
183
case GR_DEPTHBUFFER_ZBUFFER:
184
case GR_DEPTHBUFFER_ZBUFFER_COMPARE_TO_BIAS:
185
glEnable(GL_DEPTH_TEST);
186
w_buffer_mode = 0;
187
break;
188
default:
189
display_warning("unknown depth buffer mode : %x", mode);
190
}
191
}
192
193
FX_ENTRY void FX_CALL
194
grDepthBufferFunction( GrCmpFnc_t function )
195
{
196
LOG("grDepthBufferFunction(%d)\r\n", function);
197
switch(function)
198
{
199
case GR_CMP_GEQUAL:
200
if (w_buffer_mode)
201
glDepthFunc(GL_LEQUAL);
202
else
203
glDepthFunc(GL_GEQUAL);
204
break;
205
case GR_CMP_LEQUAL:
206
if (w_buffer_mode)
207
glDepthFunc(GL_GEQUAL);
208
else
209
glDepthFunc(GL_LEQUAL);
210
break;
211
case GR_CMP_LESS:
212
if (w_buffer_mode)
213
glDepthFunc(GL_GREATER);
214
else
215
glDepthFunc(GL_LESS);
216
break;
217
case GR_CMP_ALWAYS:
218
glDepthFunc(GL_ALWAYS);
219
break;
220
case GR_CMP_EQUAL:
221
glDepthFunc(GL_EQUAL);
222
break;
223
case GR_CMP_GREATER:
224
if (w_buffer_mode)
225
glDepthFunc(GL_LESS);
226
else
227
glDepthFunc(GL_GREATER);
228
break;
229
case GR_CMP_NEVER:
230
glDepthFunc(GL_NEVER);
231
break;
232
case GR_CMP_NOTEQUAL:
233
glDepthFunc(GL_NOTEQUAL);
234
break;
235
236
default:
237
display_warning("unknown depth buffer function : %x", function);
238
}
239
}
240
241
FX_ENTRY void FX_CALL
242
grDepthMask( FxBool mask )
243
{
244
LOG("grDepthMask(%d)\r\n", mask);
245
glDepthMask(mask);
246
}
247
248
float biasFactor = 0;
249
void FindBestDepthBias()
250
{
251
float f, bestz = 0.25f;
252
int x;
253
if (biasFactor) return;
254
biasFactor = 64.0f; // default value
255
glPushAttrib(GL_ALL_ATTRIB_BITS);
256
glEnable(GL_DEPTH_TEST);
257
glDepthFunc(GL_ALWAYS);
258
glEnable(GL_POLYGON_OFFSET_FILL);
259
glDrawBuffer(GL_BACK);
260
glReadBuffer(GL_BACK);
261
glDisable(GL_BLEND);
262
glDisable(GL_ALPHA_TEST);
263
glColor4ub(255,255,255,255);
264
glDepthMask(GL_TRUE);
265
for (x=0, f=1.0f; f<=65536.0f; x+=4, f*=2.0f) {
266
float z;
267
glPolygonOffset(0, f);
268
glBegin(GL_TRIANGLE_STRIP);
269
glVertex3f(float(x+4 - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5);
270
glVertex3f(float(x - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5);
271
glVertex3f(float(x+4 - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5);
272
glVertex3f(float(x - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5);
273
glEnd();
274
275
glReadPixels(x+2, 2+viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
276
z -= 0.75f + 8e-6f;
277
if (z<0.0f) z = -z;
278
if (z > 0.01f) continue;
279
if (z < bestz) {
280
bestz = z;
281
biasFactor = f;
282
}
283
//printf("f %g z %g\n", f, z);
284
}
285
//printf(" --> bias factor %g\n", biasFactor);
286
glPopAttrib();
287
}
288
289
FX_ENTRY void FX_CALL
290
grDepthBiasLevel( FxI32 level )
291
{
292
LOG("grDepthBiasLevel(%d)\r\n", level);
293
if (level)
294
{
295
if(w_buffer_mode)
296
glPolygonOffset(1.0f, -(float)level*zscale/255.0f);
297
else
298
glPolygonOffset(0, (float)level*biasFactor);
299
glEnable(GL_POLYGON_OFFSET_FILL);
300
}
301
else
302
{
303
glPolygonOffset(0,0);
304
glDisable(GL_POLYGON_OFFSET_FILL);
305
}
306
}
307
308
// draw
309
310
FX_ENTRY void FX_CALL
311
grDrawTriangle( const void *a, const void *b, const void *c )
312
{
313
float *a_x = (float*)a + xy_off/sizeof(float);
314
float *a_y = (float*)a + xy_off/sizeof(float) + 1;
315
float *a_z = (float*)a + z_off/sizeof(float);
316
float *a_q = (float*)a + q_off/sizeof(float);
317
unsigned char *a_pargb = (unsigned char*)a + pargb_off;
318
float *a_s0 = (float*)a + st0_off/sizeof(float);
319
float *a_t0 = (float*)a + st0_off/sizeof(float) + 1;
320
float *a_s1 = (float*)a + st1_off/sizeof(float);
321
float *a_t1 = (float*)a + st1_off/sizeof(float) + 1;
322
float *a_fog = (float*)a + fog_ext_off/sizeof(float);
323
324
float *b_x = (float*)b + xy_off/sizeof(float);
325
float *b_y = (float*)b + xy_off/sizeof(float) + 1;
326
float *b_z = (float*)b + z_off/sizeof(float);
327
float *b_q = (float*)b + q_off/sizeof(float);
328
unsigned char *b_pargb = (unsigned char*)b + pargb_off;
329
float *b_s0 = (float*)b + st0_off/sizeof(float);
330
float *b_t0 = (float*)b + st0_off/sizeof(float) + 1;
331
float *b_s1 = (float*)b + st1_off/sizeof(float);
332
float *b_t1 = (float*)b + st1_off/sizeof(float) + 1;
333
float *b_fog = (float*)b + fog_ext_off/sizeof(float);
334
335
float *c_x = (float*)c + xy_off/sizeof(float);
336
float *c_y = (float*)c + xy_off/sizeof(float) + 1;
337
float *c_z = (float*)c + z_off/sizeof(float);
338
float *c_q = (float*)c + q_off/sizeof(float);
339
unsigned char *c_pargb = (unsigned char*)c + pargb_off;
340
float *c_s0 = (float*)c + st0_off/sizeof(float);
341
float *c_t0 = (float*)c + st0_off/sizeof(float) + 1;
342
float *c_s1 = (float*)c + st1_off/sizeof(float);
343
float *c_t1 = (float*)c + st1_off/sizeof(float) + 1;
344
float *c_fog = (float*)c + fog_ext_off/sizeof(float);
345
LOG("grDrawTriangle()\r\n");
346
347
// ugly ? i know but nvidia drivers are losing the viewport otherwise
348
349
if(nvidia_viewport_hack && !render_to_texture)
350
{
351
glViewport(0, viewport_offset, viewport_width, viewport_height);
352
nvidia_viewport_hack = 0;
353
}
354
355
reloadTexture();
356
357
if(need_to_compile) compile_shader();
358
359
glBegin(GL_TRIANGLES);
360
361
if (nbTextureUnits > 2)
362
{
363
if (st0_en)
364
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width,
365
ytex(0, *a_t0 / *a_q / (float)tex1_height));
366
if (st1_en)
367
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width,
368
ytex(1, *a_t1 / *a_q / (float)tex0_height));
369
}
370
else
371
{
372
if (st0_en)
373
glTexCoord2f(*a_s0 / *a_q / (float)tex0_width,
374
ytex(0, *a_t0 / *a_q / (float)tex0_height));
375
}
376
if (pargb_en)
377
glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f);
378
if (fog_enabled && fog_coord_support)
379
{
380
if(!fog_ext_en || fog_enabled != 2)
381
glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
382
else
383
glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f);
384
}
385
glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q,
386
-(*a_y - (float)heighto) / (float)(height/2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q);
387
388
if (nbTextureUnits > 2)
389
{
390
if (st0_en)
391
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width,
392
ytex(0, *b_t0 / *b_q / (float)tex1_height));
393
if (st1_en)
394
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width,
395
ytex(1, *b_t1 / *b_q / (float)tex0_height));
396
}
397
else
398
{
399
if (st0_en)
400
glTexCoord2f(*b_s0 / *b_q / (float)tex0_width,
401
ytex(0, *b_t0 / *b_q / (float)tex0_height));
402
}
403
if (pargb_en)
404
glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f);
405
if (fog_enabled && fog_coord_support)
406
{
407
if(!fog_ext_en || fog_enabled != 2)
408
glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
409
else
410
glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f);
411
}
412
413
glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q,
414
-(*b_y - (float)heighto) / (float)(height/2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q);
415
416
if (nbTextureUnits > 2)
417
{
418
if (st0_en)
419
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *c_s0 / *c_q / (float)tex1_width,
420
ytex(0, *c_t0 / *c_q / (float)tex1_height));
421
if (st1_en)
422
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *c_s1 / *c_q / (float)tex0_width,
423
ytex(1, *c_t1 / *c_q / (float)tex0_height));
424
}
425
else
426
{
427
if (st0_en)
428
glTexCoord2f(*c_s0 / *c_q / (float)tex0_width,
429
ytex(0, *c_t0 / *c_q / (float)tex0_height));
430
}
431
if (pargb_en)
432
glColor4f(c_pargb[2]/255.0f, c_pargb[1]/255.0f, c_pargb[0]/255.0f, c_pargb[3]/255.0f);
433
if (fog_enabled && fog_coord_support)
434
{
435
if(!fog_ext_en || fog_enabled != 2)
436
glSecondaryColor3f((1.0f / *c_q) / 255.0f, 0.0f, 0.0f);
437
else
438
glSecondaryColor3f((1.0f / *c_fog) / 255.0f, 0.0f, 0.0f);
439
}
440
glVertex4f((*c_x - (float)widtho) / (float)(width/2) / *c_q,
441
-(*c_y - (float)heighto) / (float)(height/2) / *c_q, ZCALC(*c_z ,*c_q), 1.0f / *c_q);
442
443
glEnd();
444
}
445
446
FX_ENTRY void FX_CALL
447
grDrawPoint( const void *pt )
448
{
449
float *x = (float*)pt + xy_off/sizeof(float);
450
float *y = (float*)pt + xy_off/sizeof(float) + 1;
451
float *z = (float*)pt + z_off/sizeof(float);
452
float *q = (float*)pt + q_off/sizeof(float);
453
unsigned char *pargb = (unsigned char*)pt + pargb_off;
454
float *s0 = (float*)pt + st0_off/sizeof(float);
455
float *t0 = (float*)pt + st0_off/sizeof(float) + 1;
456
float *s1 = (float*)pt + st1_off/sizeof(float);
457
float *t1 = (float*)pt + st1_off/sizeof(float) + 1;
458
float *fog = (float*)pt + fog_ext_off/sizeof(float);
459
LOG("grDrawPoint()\r\n");
460
461
if(nvidia_viewport_hack && !render_to_texture)
462
{
463
glViewport(0, viewport_offset, viewport_width, viewport_height);
464
nvidia_viewport_hack = 0;
465
}
466
467
reloadTexture();
468
469
if(need_to_compile) compile_shader();
470
471
glBegin(GL_POINTS);
472
473
if (nbTextureUnits > 2)
474
{
475
if (st0_en)
476
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
477
ytex(0, *t0 / *q / (float)tex1_height));
478
if (st1_en)
479
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
480
ytex(1, *t1 / *q / (float)tex0_height));
481
}
482
else
483
{
484
if (st0_en)
485
glTexCoord2f(*s0 / *q / (float)tex0_width,
486
ytex(0, *t0 / *q / (float)tex0_height));
487
}
488
if (pargb_en)
489
glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f);
490
if (fog_enabled && fog_coord_support)
491
{
492
if(!fog_ext_en || fog_enabled != 2)
493
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
494
else
495
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
496
}
497
glVertex4f((*x - (float)widtho) / (float)(width/2) / *q,
498
-(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z ,*q), 1.0f / *q);
499
500
glEnd();
501
}
502
503
FX_ENTRY void FX_CALL
504
grDrawLine( const void *a, const void *b )
505
{
506
float *a_x = (float*)a + xy_off/sizeof(float);
507
float *a_y = (float*)a + xy_off/sizeof(float) + 1;
508
float *a_z = (float*)a + z_off/sizeof(float);
509
float *a_q = (float*)a + q_off/sizeof(float);
510
unsigned char *a_pargb = (unsigned char*)a + pargb_off;
511
float *a_s0 = (float*)a + st0_off/sizeof(float);
512
float *a_t0 = (float*)a + st0_off/sizeof(float) + 1;
513
float *a_s1 = (float*)a + st1_off/sizeof(float);
514
float *a_t1 = (float*)a + st1_off/sizeof(float) + 1;
515
float *a_fog = (float*)a + fog_ext_off/sizeof(float);
516
517
float *b_x = (float*)b + xy_off/sizeof(float);
518
float *b_y = (float*)b + xy_off/sizeof(float) + 1;
519
float *b_z = (float*)b + z_off/sizeof(float);
520
float *b_q = (float*)b + q_off/sizeof(float);
521
unsigned char *b_pargb = (unsigned char*)b + pargb_off;
522
float *b_s0 = (float*)b + st0_off/sizeof(float);
523
float *b_t0 = (float*)b + st0_off/sizeof(float) + 1;
524
float *b_s1 = (float*)b + st1_off/sizeof(float);
525
float *b_t1 = (float*)b + st1_off/sizeof(float) + 1;
526
float *b_fog = (float*)b + fog_ext_off/sizeof(float);
527
LOG("grDrawLine()\r\n");
528
529
if(nvidia_viewport_hack && !render_to_texture)
530
{
531
glViewport(0, viewport_offset, viewport_width, viewport_height);
532
nvidia_viewport_hack = 0;
533
}
534
535
reloadTexture();
536
537
if(need_to_compile) compile_shader();
538
539
glBegin(GL_LINES);
540
541
if (nbTextureUnits > 2)
542
{
543
if (st0_en)
544
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, ytex(0, *a_t0 / *a_q / (float)tex1_height));
545
if (st1_en)
546
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, ytex(1, *a_t1 / *a_q / (float)tex0_height));
547
}
548
else
549
{
550
if (st0_en)
551
glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, ytex(0, *a_t0 / *a_q / (float)tex0_height));
552
}
553
if (pargb_en)
554
glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f);
555
if (fog_enabled && fog_coord_support)
556
{
557
if(!fog_ext_en || fog_enabled != 2)
558
glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
559
else
560
glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f);
561
}
562
glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q,
563
-(*a_y - (float)heighto) / (float)(height/2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q);
564
565
if (nbTextureUnits > 2)
566
{
567
if (st0_en)
568
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width,
569
ytex(0, *b_t0 / *b_q / (float)tex1_height));
570
if (st1_en)
571
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width,
572
ytex(1, *b_t1 / *b_q / (float)tex0_height));
573
}
574
else
575
{
576
if (st0_en)
577
glTexCoord2f(*b_s0 / *b_q / (float)tex0_width,
578
ytex(0, *b_t0 / *b_q / (float)tex0_height));
579
}
580
if (pargb_en)
581
glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f);
582
if (fog_enabled && fog_coord_support)
583
{
584
if(!fog_ext_en || fog_enabled != 2)
585
glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
586
else
587
glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f);
588
}
589
glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q,
590
-(*b_y - (float)heighto) / (float)(height/2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q);
591
592
glEnd();
593
}
594
595
FX_ENTRY void FX_CALL
596
grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers2)
597
{
598
unsigned int i;
599
float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
600
unsigned char *pargb;
601
void **pointers = (void**)pointers2;
602
LOG("grDrawVertexArray(%d,%d)\r\n", mode, Count);
603
604
if(nvidia_viewport_hack && !render_to_texture)
605
{
606
glViewport(0, viewport_offset, viewport_width, viewport_height);
607
nvidia_viewport_hack = 0;
608
}
609
610
reloadTexture();
611
612
if(need_to_compile) compile_shader();
613
614
switch(mode)
615
{
616
case GR_TRIANGLE_FAN:
617
glBegin(GL_TRIANGLE_FAN);
618
break;
619
default:
620
display_warning("grDrawVertexArray : unknown mode : %x", mode);
621
}
622
623
for (i=0; i<Count; i++)
624
{
625
x = (float*)pointers[i] + xy_off/sizeof(float);
626
y = (float*)pointers[i] + xy_off/sizeof(float) + 1;
627
z = (float*)pointers[i] + z_off/sizeof(float);
628
q = (float*)pointers[i] + q_off/sizeof(float);
629
pargb = (unsigned char*)pointers[i] + pargb_off;
630
s0 = (float*)pointers[i] + st0_off/sizeof(float);
631
t0 = (float*)pointers[i] + st0_off/sizeof(float) + 1;
632
s1 = (float*)pointers[i] + st1_off/sizeof(float);
633
t1 = (float*)pointers[i] + st1_off/sizeof(float) + 1;
634
fog = (float*)pointers[i] + fog_ext_off/sizeof(float);
635
636
if (nbTextureUnits > 2)
637
{
638
if (st0_en)
639
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
640
ytex(0, *t0 / *q / (float)tex1_height));
641
if (st1_en)
642
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
643
ytex(1, *t1 / *q / (float)tex0_height));
644
}
645
else
646
{
647
if (st0_en)
648
glTexCoord2f(*s0 / *q / (float)tex0_width,
649
ytex(0, *t0 / *q / (float)tex0_height));
650
}
651
if (pargb_en)
652
glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f);
653
if (fog_enabled && fog_coord_support)
654
{
655
if(!fog_ext_en || fog_enabled != 2)
656
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
657
else
658
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
659
}
660
glVertex4f((*x - (float)widtho) / (float)(width/2) / *q,
661
-(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z, *q), 1.0f / *q);
662
}
663
glEnd();
664
}
665
666
FX_ENTRY void FX_CALL
667
grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count, void *pointers, FxU32 stride)
668
{
669
unsigned int i;
670
float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
671
unsigned char *pargb;
672
LOG("grDrawVertexArrayContiguous(%d,%d,%d)\r\n", mode, Count, stride);
673
674
if(nvidia_viewport_hack && !render_to_texture)
675
{
676
glViewport(0, viewport_offset, viewport_width, viewport_height);
677
nvidia_viewport_hack = 0;
678
}
679
680
reloadTexture();
681
682
if(need_to_compile) compile_shader();
683
684
switch(mode)
685
{
686
case GR_TRIANGLE_STRIP:
687
glBegin(GL_TRIANGLE_STRIP);
688
break;
689
case GR_TRIANGLE_FAN:
690
glBegin(GL_TRIANGLE_FAN);
691
break;
692
default:
693
display_warning("grDrawVertexArrayContiguous : unknown mode : %x", mode);
694
}
695
696
for (i=0; i<Count; i++)
697
{
698
x = (float*)((unsigned char*)pointers+stride*i) + xy_off/sizeof(float);
699
y = (float*)((unsigned char*)pointers+stride*i) + xy_off/sizeof(float) + 1;
700
z = (float*)((unsigned char*)pointers+stride*i) + z_off/sizeof(float);
701
q = (float*)((unsigned char*)pointers+stride*i) + q_off/sizeof(float);
702
pargb = (unsigned char*)pointers+stride*i + pargb_off;
703
s0 = (float*)((unsigned char*)pointers+stride*i) + st0_off/sizeof(float);
704
t0 = (float*)((unsigned char*)pointers+stride*i) + st0_off/sizeof(float) + 1;
705
s1 = (float*)((unsigned char*)pointers+stride*i) + st1_off/sizeof(float);
706
t1 = (float*)((unsigned char*)pointers+stride*i) + st1_off/sizeof(float) + 1;
707
fog = (float*)((unsigned char*)pointers+stride*i) + fog_ext_off/sizeof(float);
708
709
//if(*fog == 0.0f) *fog = 1.0f;
710
711
if (nbTextureUnits > 2)
712
{
713
if (st0_en)
714
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
715
ytex(0, *t0 / *q / (float)tex1_height));
716
if (st1_en)
717
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
718
ytex(1, *t1 / *q / (float)tex0_height));
719
}
720
else
721
{
722
if (st0_en)
723
glTexCoord2f(*s0 / *q / (float)tex0_width,
724
ytex(0, *t0 / *q / (float)tex0_height));
725
}
726
if (pargb_en)
727
glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f);
728
if (fog_enabled && fog_coord_support)
729
{
730
if(!fog_ext_en || fog_enabled != 2)
731
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
732
else
733
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
734
}
735
736
glVertex4f((*x - (float)widtho) / (float)(width/2) / *q,
737
-(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z, *q), 1.0f / *q);
738
}
739
glEnd();
740
}
741
742