~ubuntu-branches/ubuntu/wily/mupen64plus/wily

« back to all changes in this revision

Viewing changes to glide64/wrapper/geometry.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2011-07-24 14:23:26 UTC
  • mfrom: (10.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110724142326-x9z5qu8j9jecrmod
Tags: 1.99.4+2
* Upload to unstable
* Remove overrides for lintian warning about change to native package
* Update Vcs-* fields to new anonscm.debian.org URLs in debian/control
* Fix spelling of "Flexible" in debian/control (Closes: #633693)
* Mark all targets in debian/rules as phony
* Add some information about the mupen64plus 2.0 vision in debian/NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 
 *   Mupen64plus - glide64/wrapper/geometry.cpp                            *
3
 
 *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4
 
 *   Copyright (C) 2005-2006 Hacktarux                                     *
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
 
 *   (at your option) 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                         *
18
 
 *   Free Software Foundation, Inc.,                                       *
19
 
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
20
 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
 
 
22
 
#include <stdio.h>
23
 
 
24
 
#define GL_GLEXT_PROTOTYPES
25
 
#include <SDL_opengl.h>
26
 
 
27
 
#include "glide.h"
28
 
#include "main.h"
29
 
 
30
 
#define Z_MAX (65536.0f)
31
 
//#define Z_MAX 1000.0f
32
 
 
33
 
static int xy_off;
34
 
static int xy_en;
35
 
static int z_en;
36
 
static int z_off;
37
 
static int q_off;
38
 
static int q_en;
39
 
static int pargb_off;
40
 
static int pargb_en;
41
 
static int st0_off;
42
 
static int st0_en;
43
 
static int st1_off;
44
 
static int st1_en;
45
 
static int fog_ext_off;
46
 
static int fog_ext_en;
47
 
 
48
 
int w_buffer_mode;
49
 
int inverted_culling;
50
 
int culling_mode;
51
 
//static float depth_bias;
52
 
 
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;
57
 
  return res;
58
 
}
59
 
 
60
 
#define zclamp (1.0f-1.0f/zscale)
61
 
static inline void zclamp_glVertex4f(float a, float b, float c, float d)
62
 
{
63
 
  if (c<zclamp) c = zclamp;
64
 
  glVertex4f(a,b,c,d);
65
 
}
66
 
#define glVertex4f(a,b,c,d) zclamp_glVertex4f(a,b,c,d)
67
 
 
68
 
 
69
 
static inline float ytex(int tmu, float y) {
70
 
  if (invtex[tmu])
71
 
    return invtex[tmu] - y;
72
 
  else
73
 
    return y;
74
 
}
75
 
 
76
 
void init_geometry()
77
 
{
78
 
    xy_en = q_en = pargb_en = st0_en = st1_en = z_en = 0;
79
 
    w_buffer_mode = 0;
80
 
    inverted_culling = 0;
81
 
 
82
 
    glDisable(GL_CULL_FACE);
83
 
    glDisable(GL_DEPTH_TEST);
84
 
}
85
 
 
86
 
FX_ENTRY void FX_CALL 
87
 
grCoordinateSpace( GrCoordinateSpaceMode_t mode )
88
 
{
89
 
    LOG("grCoordinateSpace(%d)\r\n", mode);
90
 
    switch(mode)
91
 
    {
92
 
    case GR_WINDOW_COORDS:
93
 
        break;
94
 
    default:
95
 
        display_warning("unknwown coordinate space : %x", mode);
96
 
    }
97
 
}
98
 
 
99
 
FX_ENTRY void FX_CALL
100
 
grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode)
101
 
{
102
 
    LOG("grVertexLayout(%d,%d,%d)\r\n", param, offset, mode);
103
 
    switch(param)
104
 
    {
105
 
    case GR_PARAM_XY:
106
 
        xy_en = mode;
107
 
        xy_off = offset;
108
 
        break;
109
 
    case GR_PARAM_Z:
110
 
        z_en = mode;
111
 
        z_off = offset;
112
 
        break;
113
 
    case GR_PARAM_Q:
114
 
        q_en = mode;
115
 
        q_off = offset;
116
 
        break;
117
 
    case GR_PARAM_FOG_EXT:
118
 
        fog_ext_en = mode;
119
 
        fog_ext_off = offset;
120
 
        break;
121
 
    case GR_PARAM_PARGB:
122
 
        pargb_en = mode;
123
 
        pargb_off = offset;
124
 
        break;
125
 
    case GR_PARAM_ST0:
126
 
        st0_en = mode;
127
 
        st0_off = offset;
128
 
        break;
129
 
    case GR_PARAM_ST1:
130
 
        st1_en = mode;
131
 
        st1_off = offset;
132
 
        break;
133
 
    default:
134
 
        display_warning("unknown grVertexLayout parameter : %x", param);
135
 
    }
136
 
}
137
 
 
138
 
FX_ENTRY void FX_CALL 
139
 
grCullMode( GrCullMode_t mode )
140
 
{
141
 
    LOG("grCullMode(%d)\r\n", mode);
142
 
  static int oldmode = -1, oldinv = -1;
143
 
    culling_mode = mode;
144
 
  if (inverted_culling == oldinv && oldmode == mode)
145
 
    return;
146
 
  oldmode = mode;
147
 
  oldinv = inverted_culling;
148
 
    switch(mode)
149
 
    {
150
 
    case GR_CULL_DISABLE:
151
 
        glDisable(GL_CULL_FACE);
152
 
        break;
153
 
    case GR_CULL_NEGATIVE:
154
 
        if (!inverted_culling)
155
 
            glCullFace(GL_FRONT);
156
 
        else
157
 
            glCullFace(GL_BACK);
158
 
        glEnable(GL_CULL_FACE);
159
 
        break;
160
 
    case GR_CULL_POSITIVE:
161
 
        if (!inverted_culling)
162
 
            glCullFace(GL_BACK);
163
 
        else
164
 
            glCullFace(GL_FRONT);
165
 
        glEnable(GL_CULL_FACE);
166
 
        break;
167
 
    default:
168
 
        display_warning("unknown cull mode : %x", mode);
169
 
    }
170
 
}
171
 
 
172
 
// Depth buffer
173
 
 
174
 
FX_ENTRY void FX_CALL
175
 
grDepthBufferMode( GrDepthBufferMode_t mode )
176
 
{
177
 
    LOG("grDepthBufferMode(%d)\r\n", mode);
178
 
    switch(mode)
179
 
    {
180
 
    case GR_DEPTHBUFFER_DISABLE:
181
 
      glDisable(GL_DEPTH_TEST);
182
 
      w_buffer_mode = 0;
183
 
      return;
184
 
    case GR_DEPTHBUFFER_WBUFFER:
185
 
    case GR_DEPTHBUFFER_WBUFFER_COMPARE_TO_BIAS:
186
 
        glEnable(GL_DEPTH_TEST);
187
 
        w_buffer_mode = 1;
188
 
        break;
189
 
    case GR_DEPTHBUFFER_ZBUFFER:
190
 
    case GR_DEPTHBUFFER_ZBUFFER_COMPARE_TO_BIAS:
191
 
        glEnable(GL_DEPTH_TEST);
192
 
        w_buffer_mode = 0;
193
 
        break;
194
 
    default:
195
 
        display_warning("unknown depth buffer mode : %x", mode);
196
 
    }
197
 
}
198
 
 
199
 
FX_ENTRY void FX_CALL 
200
 
grDepthBufferFunction( GrCmpFnc_t function )
201
 
{
202
 
    LOG("grDepthBufferFunction(%d)\r\n", function);
203
 
    switch(function)
204
 
    {
205
 
    case GR_CMP_GEQUAL:
206
 
               if (w_buffer_mode)
207
 
                       glDepthFunc(GL_LEQUAL);
208
 
               else
209
 
                       glDepthFunc(GL_GEQUAL);
210
 
               break;
211
 
    case GR_CMP_LEQUAL:
212
 
        if (w_buffer_mode)
213
 
            glDepthFunc(GL_GEQUAL);
214
 
        else
215
 
            glDepthFunc(GL_LEQUAL);
216
 
        break;
217
 
    case GR_CMP_LESS:
218
 
        if (w_buffer_mode)
219
 
            glDepthFunc(GL_GREATER);
220
 
        else
221
 
            glDepthFunc(GL_LESS);
222
 
        break;
223
 
    case GR_CMP_ALWAYS:
224
 
        glDepthFunc(GL_ALWAYS);
225
 
        break;
226
 
    case GR_CMP_EQUAL:
227
 
//    if (w_buffer_mode)
228
 
//      glDepthFunc(GL_NOTEQUAL);
229
 
//    else
230
 
        glDepthFunc(GL_EQUAL);
231
 
      break;
232
 
    case GR_CMP_GREATER:
233
 
      if (w_buffer_mode)
234
 
        glDepthFunc(GL_LESS);
235
 
      else
236
 
        glDepthFunc(GL_GREATER);
237
 
      break;
238
 
    case GR_CMP_NEVER:
239
 
      glDepthFunc(GL_NEVER);
240
 
      break;
241
 
    case GR_CMP_NOTEQUAL:
242
 
//    if (w_buffer_mode)
243
 
//      glDepthFunc(GL_EQUAL);
244
 
//    else
245
 
        glDepthFunc(GL_NOTEQUAL);
246
 
      break;
247
 
      
248
 
    default:
249
 
      display_warning("unknown depth buffer function : %x", function);
250
 
    }
251
 
}
252
 
 
253
 
FX_ENTRY void FX_CALL 
254
 
grDepthMask( FxBool mask )
255
 
{
256
 
    LOG("grDepthMask(%d)\r\n", mask);
257
 
    glDepthMask(mask);
258
 
}
259
 
 
260
 
#include <SDL/SDL.h>
261
 
float biasFactor = 0;
262
 
void FindBestDepthBias()
263
 
{
264
 
  float f, bestz = 0.25f;
265
 
  int x;
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);
274
 
  glDisable(GL_BLEND);
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) {
279
 
    float z;
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);
286
 
    glEnd();
287
 
 
288
 
    glReadPixels(x+2, 2+viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
289
 
    z -= 0.75f + 8e-6f;
290
 
    if (z<0.0f) z = -z;
291
 
    if (z < bestz) {
292
 
      bestz = z;
293
 
      biasFactor = f;
294
 
    }
295
 
    printf("f %g z %g\n", f, z);
296
 
  }
297
 
  printf(" --> bias factor %g\n", biasFactor);
298
 
  glPopAttrib();
299
 
 
300
 
//   SDL_GL_SwapBuffers();
301
 
//   getchar();
302
 
}
303
 
 
304
 
FX_ENTRY void FX_CALL 
305
 
grDepthBiasLevel( FxI32 level )
306
 
{
307
 
    LOG("grDepthBiasLevel(%d)\r\n", level);
308
 
  //depth_bias = level;
309
 
    if (level)
310
 
    {
311
 
        if(w_buffer_mode)
312
 
            glPolygonOffset(1.0f, -(float)level*zscale/255.0f);
313
 
        else
314
 
            glPolygonOffset(0, (float)level*biasFactor);
315
 
    //glPolygonOffset(0, (float)level*128.0f*zscale/2);
316
 
        glEnable(GL_POLYGON_OFFSET_FILL);
317
 
    }
318
 
    else
319
 
    {
320
 
        glPolygonOffset(0,0);
321
 
        glDisable(GL_POLYGON_OFFSET_FILL);
322
 
    }
323
 
}
324
 
 
325
 
// draw
326
 
 
327
 
FX_ENTRY void FX_CALL
328
 
grDrawTriangle( const void *a, const void *b, const void *c )
329
 
{
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);
340
 
 
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);
351
 
 
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");
363
 
 
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;
367
 
 
368
 
    // ugly ? i know but nvidia drivers are losing the viewport otherwise
369
 
    if(!render_to_texture && viewport_width)
370
 
    {
371
 
        glViewport(0, viewport_offset, viewport_width, viewport_height);
372
 
        viewport_width=0;
373
 
    }
374
 
 
375
 
  reloadTexture();
376
 
 
377
 
    if(glsl_support && need_to_compile) compile_shader();
378
 
 
379
 
    glBegin(GL_TRIANGLES);
380
 
 
381
 
    if (nbTextureUnits > 2)
382
 
    {
383
 
        if (st0_en)
384
 
            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width,
385
 
                           ytex(0, *a_t0 / *a_q / (float)tex1_height));
386
 
        if (st1_en)
387
 
            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width,
388
 
                           ytex(1, *a_t1 / *a_q / (float)tex0_height));
389
 
    }
390
 
    else
391
 
    {
392
 
        if (st0_en)
393
 
            glTexCoord2f(*a_s0 / *a_q / (float)tex0_width,
394
 
                   ytex(0, *a_t0 / *a_q / (float)tex0_height));
395
 
    }
396
 
    if (pargb_en)
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)
399
 
    {
400
 
        if(!glsl_support)
401
 
        {
402
 
            if(!fog_ext_en || fog_enabled != 2)
403
 
                glFogCoordfEXT((1.0f / *a_q)/*/256.0f*/);
404
 
            else
405
 
                glFogCoordfEXT((1.0f / *a_fog)/*/256.0f*/);
406
 
        }
407
 
        else
408
 
        {
409
 
            if(!fog_ext_en || fog_enabled != 2)
410
 
                glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
411
 
            else
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);
415
 
            else
416
 
                glFogCoordfEXT((1.0f / *a_fog)/255.0f);*/
417
 
        }
418
 
    }
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);
421
 
 
422
 
    if (nbTextureUnits > 2)
423
 
    {
424
 
        if (st0_en)
425
 
            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width,
426
 
                           ytex(0, *b_t0 / *b_q / (float)tex1_height));
427
 
        if (st1_en)
428
 
            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width,
429
 
                           ytex(1, *b_t1 / *b_q / (float)tex0_height));
430
 
    }
431
 
    else
432
 
    {
433
 
        if (st0_en)
434
 
            glTexCoord2f(*b_s0 / *b_q / (float)tex0_width,
435
 
                   ytex(0, *b_t0 / *b_q / (float)tex0_height));
436
 
    }
437
 
    if (pargb_en)
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)
440
 
    {
441
 
        if(!glsl_support)
442
 
        {
443
 
            if(!fog_ext_en || fog_enabled != 2)
444
 
                glFogCoordfEXT((1.0f / *b_q)/*/256.0f*/);
445
 
            else
446
 
                glFogCoordfEXT((1.0f / *b_fog)/*/256.0f*/);
447
 
        }
448
 
        else
449
 
        {
450
 
            if(!fog_ext_en || fog_enabled != 2)
451
 
                glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
452
 
            else
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);
456
 
            else
457
 
                glFogCoordfEXT((1.0f / *b_fog)/255.0f);*/
458
 
        }
459
 
    }
460
 
 
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);
463
 
 
464
 
    if (nbTextureUnits > 2)
465
 
    {
466
 
        if (st0_en)
467
 
            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *c_s0 / *c_q / (float)tex1_width,
468
 
                           ytex(0, *c_t0 / *c_q / (float)tex1_height));
469
 
        if (st1_en)
470
 
            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *c_s1 / *c_q / (float)tex0_width,
471
 
                           ytex(1, *c_t1 / *c_q / (float)tex0_height));
472
 
    }
473
 
    else
474
 
    {
475
 
        if (st0_en)
476
 
            glTexCoord2f(*c_s0 / *c_q / (float)tex0_width,
477
 
                   ytex(0, *c_t0 / *c_q / (float)tex0_height));
478
 
    }
479
 
    if (pargb_en)
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)
482
 
    {
483
 
        if(!glsl_support)
484
 
        {
485
 
            if(!fog_ext_en || fog_enabled != 2)
486
 
                glFogCoordfEXT((1.0f / *c_q)/*/256.0f*/);
487
 
            else
488
 
                glFogCoordfEXT((1.0f / *c_fog)/*/256.0f*/);
489
 
        }
490
 
        else
491
 
        {
492
 
            if(!fog_ext_en || fog_enabled != 2)
493
 
                glSecondaryColor3f((1.0f / *c_q) / 255.0f, 0.0f, 0.0f);
494
 
            else
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);
498
 
            else
499
 
                glFogCoordfEXT((1.0f / *c_fog)/255.0f);*/
500
 
        }
501
 
    }
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);
504
 
 
505
 
    glEnd();
506
 
}
507
 
 
508
 
FX_ENTRY void FX_CALL
509
 
grDrawPoint( const void *pt )
510
 
{
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");
522
 
 
523
 
  reloadTexture();
524
 
 
525
 
    if(glsl_support && need_to_compile) compile_shader();
526
 
 
527
 
    glBegin(GL_POINTS);
528
 
 
529
 
    if (nbTextureUnits > 2)
530
 
    {
531
 
        if (st0_en)
532
 
            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
533
 
                           ytex(0, *t0 / *q / (float)tex1_height));
534
 
        if (st1_en)
535
 
            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
536
 
                           ytex(1, *t1 / *q / (float)tex0_height));
537
 
    }
538
 
    else
539
 
    {
540
 
        if (st0_en)
541
 
            glTexCoord2f(*s0 / *q / (float)tex0_width,
542
 
                   ytex(0, *t0 / *q / (float)tex0_height));
543
 
    }
544
 
    if (pargb_en)
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)
547
 
    {
548
 
        if(!glsl_support)
549
 
        {
550
 
            if(!fog_ext_en || fog_enabled != 2)
551
 
                glFogCoordfEXT((1.0f / *q)/*/256.0f*/);
552
 
            else
553
 
                glFogCoordfEXT((1.0f / *fog)/*/256.0f*/);
554
 
        }
555
 
        else
556
 
        {
557
 
            if(!fog_ext_en || fog_enabled != 2)
558
 
                glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
559
 
            else
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);
563
 
            else
564
 
                glFogCoordfEXT((1.0f / *fog)/255.0f);*/
565
 
        }
566
 
    }
567
 
    glVertex4f((*x - (float)widtho) / (float)(width/2) / *q, 
568
 
           -(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z ,*q), 1.0f / *q);
569
 
 
570
 
    glEnd();
571
 
}
572
 
 
573
 
FX_ENTRY void FX_CALL
574
 
grDrawLine( const void *a, const void *b )
575
 
{
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);
586
 
 
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");
598
 
 
599
 
    //if(*a_fog == 0.0f) *a_fog = 1.0f;
600
 
    //if(*b_fog == 0.0f) *b_fog = 1.0f;
601
 
 
602
 
  reloadTexture();
603
 
 
604
 
    if(glsl_support && need_to_compile) compile_shader();
605
 
 
606
 
    glBegin(GL_LINES);
607
 
 
608
 
    if (nbTextureUnits > 2)
609
 
    {
610
 
        if (st0_en)
611
 
            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, ytex(0, *a_t0 / *a_q / (float)tex1_height));
612
 
        if (st1_en)
613
 
            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, ytex(1, *a_t1 / *a_q / (float)tex0_height));
614
 
    }
615
 
    else
616
 
    {
617
 
        if (st0_en)
618
 
            glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, ytex(0, *a_t0 / *a_q / (float)tex0_height));
619
 
    }
620
 
    if (pargb_en)
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)
623
 
    {
624
 
        if(!glsl_support)
625
 
        {
626
 
            if(!fog_ext_en || fog_enabled != 2)
627
 
                glFogCoordfEXT((1.0f / *a_q)/*/256.0f*/);
628
 
            else
629
 
                glFogCoordfEXT((1.0f / *a_fog)/*/256.0f*/);
630
 
        }
631
 
        else
632
 
        {
633
 
            if(!fog_ext_en || fog_enabled != 2)
634
 
                glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
635
 
            else
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);
639
 
            else
640
 
                glFogCoordfEXT((1.0f / *a_fog)/255.0f);*/
641
 
        }
642
 
    }
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);
645
 
 
646
 
    if (nbTextureUnits > 2)
647
 
    {
648
 
        if (st0_en)
649
 
            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width,
650
 
                           ytex(0, *b_t0 / *b_q / (float)tex1_height));
651
 
        if (st1_en)
652
 
            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width,
653
 
                           ytex(1, *b_t1 / *b_q / (float)tex0_height));
654
 
    }
655
 
    else
656
 
    {
657
 
        if (st0_en)
658
 
            glTexCoord2f(*b_s0 / *b_q / (float)tex0_width,
659
 
                   ytex(0, *b_t0 / *b_q / (float)tex0_height));
660
 
    }
661
 
    if (pargb_en)
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)
664
 
    {
665
 
        if(!glsl_support)
666
 
        {
667
 
            if(!fog_ext_en || fog_enabled != 2)
668
 
                glFogCoordfEXT((1.0f / *b_q)/*/256.0f*/);
669
 
            else
670
 
                glFogCoordfEXT((1.0f / *b_fog)/*/256.0f*/);
671
 
        }
672
 
        else
673
 
        {
674
 
            if(!fog_ext_en || fog_enabled != 2)
675
 
                glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
676
 
            else
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);
680
 
            else
681
 
                glFogCoordfEXT((1.0f / *b_fog)/255.0f);*/
682
 
        }
683
 
    }
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);
686
 
 
687
 
    glEnd();
688
 
}
689
 
 
690
 
FX_ENTRY void FX_CALL 
691
 
grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers2)
692
 
{
693
 
    unsigned int i;
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);
698
 
 
699
 
  reloadTexture();
700
 
 
701
 
    if(glsl_support && need_to_compile) compile_shader();
702
 
 
703
 
    switch(mode)
704
 
    {
705
 
    case GR_TRIANGLE_FAN:
706
 
        glBegin(GL_TRIANGLE_FAN);
707
 
        break;
708
 
    default:
709
 
        display_warning("grDrawVertexArray : unknown mode : %x", mode);
710
 
    }
711
 
 
712
 
    for (i=0; i<Count; i++)
713
 
    {
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);
724
 
 
725
 
        //if(*fog == 0.0f) *fog = 1.0f;
726
 
 
727
 
        if (nbTextureUnits > 2)
728
 
        {
729
 
            if (st0_en)
730
 
                glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
731
 
                             ytex(0, *t0 / *q / (float)tex1_height));
732
 
            if (st1_en)
733
 
                glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
734
 
                             ytex(1, *t1 / *q / (float)tex0_height));
735
 
        }
736
 
        else
737
 
        {
738
 
            if (st0_en)
739
 
                glTexCoord2f(*s0 / *q / (float)tex0_width,
740
 
                     ytex(0, *t0 / *q / (float)tex0_height));
741
 
        }
742
 
        if (pargb_en)
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)
745
 
        {
746
 
            if(!glsl_support)
747
 
            {
748
 
                if(!fog_ext_en || fog_enabled != 2)
749
 
                    glFogCoordfEXT((1.0f / *q)/*/256.0f*/);
750
 
                else
751
 
                    glFogCoordfEXT((1.0f / *fog)/*/256.0f*/);
752
 
            }
753
 
            else
754
 
            {
755
 
                if(!fog_ext_en || fog_enabled != 2)
756
 
                    glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
757
 
                else
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);
761
 
                else
762
 
                    glFogCoordfEXT((1.0f / *fog)/255.0f);*/
763
 
            }
764
 
        }
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)
768
 
        
769
 
        glVertex4f((*x - (float)widtho) / (float)(width/2) / *q, 
770
 
               -(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z, *q), 1.0f / *q);
771
 
    }
772
 
    glEnd();
773
 
}
774
 
 
775
 
FX_ENTRY void FX_CALL 
776
 
grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count, void *pointers, FxU32 stride)
777
 
{
778
 
    unsigned int i;
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);
782
 
 
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;
786
 
  //reloadTexture();
787
 
 
788
 
    if(glsl_support && need_to_compile) compile_shader();
789
 
 
790
 
    switch(mode)
791
 
    {
792
 
    case GR_TRIANGLE_STRIP:
793
 
        glBegin(GL_TRIANGLE_STRIP);
794
 
        break;
795
 
    case GR_TRIANGLE_FAN:
796
 
        glBegin(GL_TRIANGLE_FAN);
797
 
        break;
798
 
    default:
799
 
        display_warning("grDrawVertexArrayContiguous : unknown mode : %x", mode);
800
 
    }
801
 
 
802
 
    for (i=0; i<Count; i++)
803
 
    {
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);
814
 
 
815
 
        //if(*fog == 0.0f) *fog = 1.0f;
816
 
 
817
 
        if (nbTextureUnits > 2)
818
 
        {
819
 
            if (st0_en)
820
 
                glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width,
821
 
                             ytex(0, *t0 / *q / (float)tex1_height));
822
 
            if (st1_en)
823
 
                glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width,
824
 
                             ytex(1, *t1 / *q / (float)tex0_height));
825
 
        }
826
 
        else
827
 
        {
828
 
            if (st0_en)
829
 
                glTexCoord2f(*s0 / *q / (float)tex0_width,
830
 
                     ytex(0, *t0 / *q / (float)tex0_height));
831
 
        }
832
 
        if (pargb_en)
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)
835
 
        {
836
 
            if(!glsl_support)
837
 
            {
838
 
                if(!fog_ext_en || fog_enabled != 2)
839
 
                    glFogCoordfEXT((1.0f / *q)/*/256.0f*/);
840
 
                else
841
 
                    glFogCoordfEXT((1.0f / *fog)/*/256.0f*/);
842
 
            }
843
 
            else
844
 
            {
845
 
                if(!fog_ext_en || fog_enabled != 2)
846
 
                    glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
847
 
                else
848
 
                    glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
849
 
 
850
 
                /*if(!fog_ext_en || fog_enabled != 2)
851
 
                    glFogCoordfEXT((1.0f / *q)/255.0f);
852
 
                else
853
 
                    glFogCoordfEXT((1.0f / *fog)/255.0f);*/
854
 
            }
855
 
        }
856
 
        
857
 
        glVertex4f((*x - (float)widtho) / (float)(width/2) / *q, 
858
 
               -(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z, *q), 1.0f / *q);
859
 
    }
860
 
    glEnd();
861
 
}
862