~ubuntu-branches/ubuntu/trusty/mupen64plus-video-rice/trusty

« back to all changes in this revision

Viewing changes to .pc/wom_corruption.patch/src/OGLRender.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2011-07-24 14:24:45 UTC
  • Revision ID: james.westby@ubuntu.com-20110724142445-uczh2xgij7tkx2rt
Tags: 1.99.4-3
* Upload to unstable
* debian/rules:
  - Mark all targets as phony
  - Force PIC using Makefile option
  - Remove unintended optimization flags
* debian/patches:
  - Remove default-optimisations.patch, hurd_os.patch
  - Add rewrite_makefile.patch, Rewrite Makefile to fix flags and linking
  - Add png_truecolor_conversation.patch, Convert 8-bit png to truecolor when
    needed
  - Add divide_by_zero.patch, Fix random crash due to divide-by-zero error
  - Add undefined_functions.patch, Add header for undefined min/max/memcpy
  - Add portable_movsxl.patch, Replace movsxl with more portable mnemonic
    movslq
  - Add infinit_loop.patch, Fix double infinit loop in GetValidTmemInfoIndex
  - Add wom_corruption.patch, Remove write-only member variables m_bClampS and
    m_bClampT
  - Add z_coordinate_lines.patch, Fix z coordinate in 3d line rendering
  - Add mipmapping.patch, Synchronize MipMapping options in Arachnoid and Rice
* Depend on pkg-config in debian/control for new Makefile

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003 Rice1964
 
3
 
 
4
This program is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU General Public License
 
6
as published by the Free Software Foundation; either version 2
 
7
of the License, or (at your option) any later version.
 
8
 
 
9
This program is distributed in the hope that it will be useful,
 
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
GNU General Public License for more details.
 
13
 
 
14
You should have received a copy of the GNU General Public License
 
15
along with this program; if not, write to the Free Software
 
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
17
*/
 
18
 
 
19
#include "OGLExtensions.h"
 
20
#include "OGLDebug.h"
 
21
#include "OGLRender.h"
 
22
#include "OGLGraphicsContext.h"
 
23
#include "OGLTexture.h"
 
24
#include "TextureManager.h"
 
25
 
 
26
// Fix me, use OGL internal L/T and matrix stack
 
27
// Fix me, use OGL lookupAt function
 
28
// Fix me, use OGL DisplayList
 
29
 
 
30
UVFlagMap OGLXUVFlagMaps[] =
 
31
{
 
32
{TEXTURE_UV_FLAG_WRAP, GL_REPEAT},
 
33
{TEXTURE_UV_FLAG_MIRROR, GL_MIRRORED_REPEAT_ARB},
 
34
{TEXTURE_UV_FLAG_CLAMP, GL_CLAMP},
 
35
};
 
36
 
 
37
//===================================================================
 
38
OGLRender::OGLRender()
 
39
{
 
40
    COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
 
41
    m_bSupportFogCoordExt = pcontext->m_bSupportFogCoord;
 
42
    m_bMultiTexture = pcontext->m_bSupportMultiTexture;
 
43
    m_bSupportClampToEdge = false;
 
44
    m_bClampS[0] = false;
 
45
    m_bClampT[0] = m_bClampT[1] = false;
 
46
    for( int i=0; i<8; i++ )
 
47
    {
 
48
        m_curBoundTex[i]=0;
 
49
        m_texUnitEnabled[i]=FALSE;
 
50
    }
 
51
    m_bEnableMultiTexture = false;
 
52
}
 
53
 
 
54
OGLRender::~OGLRender()
 
55
{
 
56
    ClearDeviceObjects();
 
57
}
 
58
 
 
59
bool OGLRender::InitDeviceObjects()
 
60
{
 
61
    // enable Z-buffer by default
 
62
    ZBufferEnable(true);
 
63
    return true;
 
64
}
 
65
 
 
66
bool OGLRender::ClearDeviceObjects()
 
67
{
 
68
    return true;
 
69
}
 
70
 
 
71
void OGLRender::Initialize(void)
 
72
{
 
73
    glMatrixMode(GL_MODELVIEW);
 
74
    OPENGL_CHECK_ERRORS;
 
75
    glLoadIdentity();
 
76
    OPENGL_CHECK_ERRORS;
 
77
 
 
78
    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
 
79
    OPENGL_CHECK_ERRORS;
 
80
 
 
81
    COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
 
82
    if( pcontext->IsExtensionSupported("GL_IBM_texture_mirrored_repeat") )
 
83
    {
 
84
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_IBM;
 
85
    }
 
86
    else if( pcontext->IsExtensionSupported("ARB_texture_mirrored_repeat") )
 
87
    {
 
88
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_ARB;
 
89
    }
 
90
    else
 
91
    {
 
92
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_REPEAT;
 
93
    }
 
94
 
 
95
    if( pcontext->IsExtensionSupported("GL_ARB_texture_border_clamp") || pcontext->IsExtensionSupported("GL_EXT_texture_edge_clamp") )
 
96
    {
 
97
        m_bSupportClampToEdge = true;
 
98
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
 
99
    }
 
100
    else
 
101
    {
 
102
        m_bSupportClampToEdge = false;
 
103
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP;
 
104
    }
 
105
 
 
106
    glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
 
107
    OPENGL_CHECK_ERRORS;
 
108
    glEnableClientState( GL_VERTEX_ARRAY );
 
109
    OPENGL_CHECK_ERRORS;
 
110
 
 
111
    if( m_bMultiTexture )
 
112
    {
 
113
        pglClientActiveTextureARB( GL_TEXTURE0_ARB );
 
114
        OPENGL_CHECK_ERRORS;
 
115
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
 
116
        OPENGL_CHECK_ERRORS;
 
117
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
118
        OPENGL_CHECK_ERRORS;
 
119
 
 
120
        pglClientActiveTextureARB( GL_TEXTURE1_ARB );
 
121
        OPENGL_CHECK_ERRORS;
 
122
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
 
123
        OPENGL_CHECK_ERRORS;
 
124
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
125
        OPENGL_CHECK_ERRORS;
 
126
    }
 
127
    else
 
128
    {
 
129
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
 
130
        OPENGL_CHECK_ERRORS;
 
131
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
132
        OPENGL_CHECK_ERRORS;
 
133
    }
 
134
 
 
135
    if (m_bSupportFogCoordExt)
 
136
    {
 
137
        pglFogCoordPointerEXT( GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][4]) );
 
138
        OPENGL_CHECK_ERRORS;
 
139
        glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
 
140
        OPENGL_CHECK_ERRORS;
 
141
        glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
 
142
        OPENGL_CHECK_ERRORS;
 
143
        glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode
 
144
        OPENGL_CHECK_ERRORS;
 
145
        glFogf(GL_FOG_DENSITY, 1.0f); // How Dense Will The Fog Be
 
146
        OPENGL_CHECK_ERRORS;
 
147
        glHint(GL_FOG_HINT, GL_FASTEST); // Fog Hint Value
 
148
        OPENGL_CHECK_ERRORS;
 
149
        glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
 
150
        OPENGL_CHECK_ERRORS;
 
151
        glFogf( GL_FOG_START, 0.0f );
 
152
        OPENGL_CHECK_ERRORS;
 
153
        glFogf( GL_FOG_END, 1.0f );
 
154
        OPENGL_CHECK_ERRORS;
 
155
    }
 
156
 
 
157
    //glColorPointer( 1, GL_UNSIGNED_BYTE, sizeof(TLITVERTEX), &g_vtxBuffer[0].r);
 
158
    glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
 
159
    OPENGL_CHECK_ERRORS;
 
160
    glEnableClientState( GL_COLOR_ARRAY );
 
161
    OPENGL_CHECK_ERRORS;
 
162
 
 
163
    if( pcontext->IsExtensionSupported("GL_NV_depth_clamp") )
 
164
    {
 
165
        glEnable(GL_DEPTH_CLAMP_NV);
 
166
        OPENGL_CHECK_ERRORS;
 
167
    }
 
168
 
 
169
}
 
170
//===================================================================
 
171
TextureFilterMap OglTexFilterMap[2]=
 
172
{
 
173
    {FILTER_POINT, GL_NEAREST},
 
174
    {FILTER_LINEAR, GL_LINEAR},
 
175
};
 
176
 
 
177
void OGLRender::ApplyTextureFilter()
 
178
{
 
179
    static uint32 minflag=0xFFFF, magflag=0xFFFF;
 
180
    static uint32 mtex;
 
181
 
 
182
    if( m_texUnitEnabled[0] )
 
183
    {
 
184
        if( mtex != m_curBoundTex[0] )
 
185
        {
 
186
            mtex = m_curBoundTex[0];
 
187
            minflag = m_dwMinFilter;
 
188
            magflag = m_dwMagFilter;
 
189
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, OglTexFilterMap[m_dwMinFilter].realFilter);
 
190
            OPENGL_CHECK_ERRORS;
 
191
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, OglTexFilterMap[m_dwMagFilter].realFilter);
 
192
            OPENGL_CHECK_ERRORS;
 
193
        }
 
194
        else
 
195
        {
 
196
            if( minflag != (unsigned int)m_dwMinFilter )
 
197
            {
 
198
                minflag = m_dwMinFilter;
 
199
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, OglTexFilterMap[m_dwMinFilter].realFilter);
 
200
                OPENGL_CHECK_ERRORS;
 
201
            }
 
202
            if( magflag != (unsigned int)m_dwMagFilter )
 
203
            {
 
204
                magflag = m_dwMagFilter;
 
205
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, OglTexFilterMap[m_dwMagFilter].realFilter);
 
206
                OPENGL_CHECK_ERRORS;
 
207
            }   
 
208
        }
 
209
    }
 
210
}
 
211
 
 
212
void OGLRender::SetShadeMode(RenderShadeMode mode)
 
213
{
 
214
    if( mode == SHADE_SMOOTH )
 
215
        glShadeModel(GL_SMOOTH);
 
216
    else
 
217
        glShadeModel(GL_FLAT);
 
218
    OPENGL_CHECK_ERRORS;
 
219
}
 
220
 
 
221
void OGLRender::ZBufferEnable(BOOL bZBuffer)
 
222
{
 
223
    gRSP.bZBufferEnabled = bZBuffer;
 
224
    if( g_curRomInfo.bForceDepthBuffer )
 
225
        bZBuffer = TRUE;
 
226
    if( bZBuffer )
 
227
    {
 
228
        glDepthMask(GL_TRUE);
 
229
        OPENGL_CHECK_ERRORS;
 
230
        //glEnable(GL_DEPTH_TEST);
 
231
        glDepthFunc( GL_LEQUAL );
 
232
        OPENGL_CHECK_ERRORS;
 
233
    }
 
234
    else
 
235
    {
 
236
        glDepthMask(GL_FALSE);
 
237
        OPENGL_CHECK_ERRORS;
 
238
        //glDisable(GL_DEPTH_TEST);
 
239
        glDepthFunc( GL_ALWAYS );
 
240
        OPENGL_CHECK_ERRORS;
 
241
    }
 
242
}
 
243
 
 
244
void OGLRender::ClearBuffer(bool cbuffer, bool zbuffer)
 
245
{
 
246
    uint32 flag=0;
 
247
    if( cbuffer )   flag |= GL_COLOR_BUFFER_BIT;
 
248
    if( zbuffer )   flag |= GL_DEPTH_BUFFER_BIT;
 
249
    float depth = ((gRDP.originalFillColor&0xFFFF)>>2)/(float)0x3FFF;
 
250
    glClearDepth(depth);
 
251
    OPENGL_CHECK_ERRORS;
 
252
    glClear(flag);
 
253
    OPENGL_CHECK_ERRORS;
 
254
}
 
255
 
 
256
void OGLRender::ClearZBuffer(float depth)
 
257
{
 
258
    uint32 flag=GL_DEPTH_BUFFER_BIT;
 
259
    glClearDepth(depth);
 
260
    OPENGL_CHECK_ERRORS;
 
261
    glClear(flag);
 
262
    OPENGL_CHECK_ERRORS;
 
263
}
 
264
 
 
265
void OGLRender::SetZCompare(BOOL bZCompare)
 
266
{
 
267
    if( g_curRomInfo.bForceDepthBuffer )
 
268
        bZCompare = TRUE;
 
269
 
 
270
    gRSP.bZBufferEnabled = bZCompare;
 
271
    if( bZCompare == TRUE )
 
272
    {
 
273
        //glEnable(GL_DEPTH_TEST);
 
274
        glDepthFunc( GL_LEQUAL );
 
275
        OPENGL_CHECK_ERRORS;
 
276
    }
 
277
    else
 
278
    {
 
279
        //glDisable(GL_DEPTH_TEST);
 
280
        glDepthFunc( GL_ALWAYS );
 
281
        OPENGL_CHECK_ERRORS;
 
282
    }
 
283
}
 
284
 
 
285
void OGLRender::SetZUpdate(BOOL bZUpdate)
 
286
{
 
287
    if( g_curRomInfo.bForceDepthBuffer )
 
288
        bZUpdate = TRUE;
 
289
 
 
290
    if( bZUpdate )
 
291
    {
 
292
        //glEnable(GL_DEPTH_TEST);
 
293
        glDepthMask(GL_TRUE);
 
294
        OPENGL_CHECK_ERRORS;
 
295
    }
 
296
    else
 
297
    {
 
298
        glDepthMask(GL_FALSE);
 
299
        OPENGL_CHECK_ERRORS;
 
300
    }
 
301
}
 
302
 
 
303
void OGLRender::ApplyZBias(int bias)
 
304
{
 
305
    float f1 = bias > 0 ? -3.0f : 0.0f;  // z offset = -3.0 * max(abs(dz/dx),abs(dz/dy)) per pixel delta z slope
 
306
    float f2 = bias > 0 ? -3.0f : 0.0f;  // z offset += -3.0 * 1 bit
 
307
    if (bias > 0)
 
308
    {
 
309
        glEnable(GL_POLYGON_OFFSET_FILL);  // enable z offsets
 
310
        OPENGL_CHECK_ERRORS;
 
311
    }
 
312
    else
 
313
    {
 
314
        glDisable(GL_POLYGON_OFFSET_FILL);  // disable z offsets
 
315
        OPENGL_CHECK_ERRORS;
 
316
    }
 
317
    glPolygonOffset(f1, f2);  // set bias functions
 
318
    OPENGL_CHECK_ERRORS;
 
319
}
 
320
 
 
321
void OGLRender::SetZBias(int bias)
 
322
{
 
323
#if defined(DEBUGGER)
 
324
    if( pauseAtNext == true )
 
325
      DebuggerAppendMsg("Set zbias = %d", bias);
 
326
#endif
 
327
    // set member variable and apply the setting in opengl
 
328
    m_dwZBias = bias;
 
329
    ApplyZBias(bias);
 
330
}
 
331
 
 
332
void OGLRender::SetAlphaRef(uint32 dwAlpha)
 
333
{
 
334
    if (m_dwAlpha != dwAlpha)
 
335
    {
 
336
        m_dwAlpha = dwAlpha;
 
337
        glAlphaFunc(GL_GEQUAL, (float)dwAlpha);
 
338
        OPENGL_CHECK_ERRORS;
 
339
    }
 
340
}
 
341
 
 
342
void OGLRender::ForceAlphaRef(uint32 dwAlpha)
 
343
{
 
344
    float ref = dwAlpha/255.0f;
 
345
    glAlphaFunc(GL_GEQUAL, ref);
 
346
    OPENGL_CHECK_ERRORS;
 
347
}
 
348
 
 
349
void OGLRender::SetFillMode(FillMode mode)
 
350
{
 
351
    if( mode == RICE_FILLMODE_WINFRAME )
 
352
    {
 
353
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
354
        OPENGL_CHECK_ERRORS;
 
355
    }
 
356
    else
 
357
    {
 
358
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
359
        OPENGL_CHECK_ERRORS;
 
360
    }
 
361
}
 
362
 
 
363
void OGLRender::SetCullMode(bool bCullFront, bool bCullBack)
 
364
{
 
365
    CRender::SetCullMode(bCullFront, bCullBack);
 
366
    if( bCullFront && bCullBack )
 
367
    {
 
368
        glCullFace(GL_FRONT_AND_BACK);
 
369
        OPENGL_CHECK_ERRORS;
 
370
        glEnable(GL_CULL_FACE);
 
371
        OPENGL_CHECK_ERRORS;
 
372
    }
 
373
    else if( bCullFront )
 
374
    {
 
375
        glCullFace(GL_FRONT);
 
376
        OPENGL_CHECK_ERRORS;
 
377
        glEnable(GL_CULL_FACE);
 
378
        OPENGL_CHECK_ERRORS;
 
379
    }
 
380
    else if( bCullBack )
 
381
    {
 
382
        glCullFace(GL_BACK);
 
383
        OPENGL_CHECK_ERRORS;
 
384
        glEnable(GL_CULL_FACE);
 
385
        OPENGL_CHECK_ERRORS;
 
386
    }
 
387
    else
 
388
    {
 
389
        glDisable(GL_CULL_FACE);
 
390
        OPENGL_CHECK_ERRORS;
 
391
    }
 
392
}
 
393
 
 
394
bool OGLRender::SetCurrentTexture(int tile, CTexture *handler,uint32 dwTileWidth, uint32 dwTileHeight, TxtrCacheEntry *pTextureEntry)
 
395
{
 
396
    RenderTexture &texture = g_textures[tile];
 
397
    texture.pTextureEntry = pTextureEntry;
 
398
 
 
399
    if( handler!= NULL  && texture.m_lpsTexturePtr != handler->GetTexture() )
 
400
    {
 
401
        texture.m_pCTexture = handler;
 
402
        texture.m_lpsTexturePtr = handler->GetTexture();
 
403
 
 
404
        texture.m_dwTileWidth = dwTileWidth;
 
405
        texture.m_dwTileHeight = dwTileHeight;
 
406
 
 
407
        if( handler->m_bIsEnhancedTexture )
 
408
        {
 
409
            texture.m_fTexWidth = (float)pTextureEntry->pTexture->m_dwCreatedTextureWidth;
 
410
            texture.m_fTexHeight = (float)pTextureEntry->pTexture->m_dwCreatedTextureHeight;
 
411
        }
 
412
        else
 
413
        {
 
414
            texture.m_fTexWidth = (float)handler->m_dwCreatedTextureWidth;
 
415
            texture.m_fTexHeight = (float)handler->m_dwCreatedTextureHeight;
 
416
        }
 
417
    }
 
418
    
 
419
    return true;
 
420
}
 
421
 
 
422
bool OGLRender::SetCurrentTexture(int tile, TxtrCacheEntry *pEntry)
 
423
{
 
424
    if (pEntry != NULL && pEntry->pTexture != NULL)
 
425
    {   
 
426
        SetCurrentTexture( tile, pEntry->pTexture,  pEntry->ti.WidthToCreate, pEntry->ti.HeightToCreate, pEntry);
 
427
        return true;
 
428
    }
 
429
    else
 
430
    {
 
431
        SetCurrentTexture( tile, NULL, 64, 64, NULL );
 
432
        return false;
 
433
    }
 
434
    return true;
 
435
}
 
436
 
 
437
void OGLRender::SetAddressUAllStages(uint32 dwTile, TextureUVFlag dwFlag)
 
438
{
 
439
    SetTextureUFlag(dwFlag, dwTile);
 
440
}
 
441
 
 
442
void OGLRender::SetAddressVAllStages(uint32 dwTile, TextureUVFlag dwFlag)
 
443
{
 
444
    SetTextureVFlag(dwFlag, dwTile);
 
445
}
 
446
 
 
447
void OGLRender::SetTexWrapS(int unitno,GLuint flag)
 
448
{
 
449
    static GLuint mflag;
 
450
    static GLuint mtex;
 
451
#ifdef DEBUGGER
 
452
    if( unitno != 0 )
 
453
    {
 
454
        DebuggerAppendMsg("Check me, unitno != 0 in base ogl");
 
455
    }
 
456
#endif
 
457
    if( m_curBoundTex[0] != mtex || mflag != flag )
 
458
    {
 
459
        mtex = m_curBoundTex[0];
 
460
        mflag = flag;
 
461
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, flag);
 
462
        OPENGL_CHECK_ERRORS;
 
463
    }
 
464
}
 
465
void OGLRender::SetTexWrapT(int unitno,GLuint flag)
 
466
{
 
467
    static GLuint mflag;
 
468
    static GLuint mtex;
 
469
    if( m_curBoundTex[0] != mtex || mflag != flag )
 
470
    {
 
471
        mtex = m_curBoundTex[0];
 
472
        mflag = flag;
 
473
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, flag);
 
474
        OPENGL_CHECK_ERRORS;
 
475
    }
 
476
}
 
477
 
 
478
void OGLRender::SetTextureUFlag(TextureUVFlag dwFlag, uint32 dwTile)
 
479
{
 
480
    TileUFlags[dwTile] = dwFlag;
 
481
    if( dwTile == gRSP.curTile )    // For basic OGL, only support the 1st texel
 
482
    {
 
483
        COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
 
484
        if( pTexture )
 
485
        {
 
486
            EnableTexUnit(0,TRUE);
 
487
            BindTexture(pTexture->m_dwTextureName, 0);
 
488
        }
 
489
        SetTexWrapS(0, OGLXUVFlagMaps[dwFlag].realFlag);
 
490
        m_bClampS[0] = dwFlag==TEXTURE_UV_FLAG_CLAMP?true:false;
 
491
    }
 
492
}
 
493
void OGLRender::SetTextureVFlag(TextureUVFlag dwFlag, uint32 dwTile)
 
494
{
 
495
    TileVFlags[dwTile] = dwFlag;
 
496
    if( dwTile == gRSP.curTile )    // For basic OGL, only support the 1st texel
 
497
    {
 
498
        COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
 
499
        if( pTexture ) 
 
500
        {
 
501
            EnableTexUnit(0,TRUE);
 
502
            BindTexture(pTexture->m_dwTextureName, 0);
 
503
        }
 
504
        SetTexWrapT(0, OGLXUVFlagMaps[dwFlag].realFlag);
 
505
        m_bClampT[0] = dwFlag==TEXTURE_UV_FLAG_CLAMP?true:false;
 
506
    }
 
507
}
 
508
 
 
509
// Basic render drawing functions
 
510
 
 
511
bool OGLRender::RenderTexRect()
 
512
{
 
513
    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
 
514
    OPENGL_CHECK_ERRORS;
 
515
 
 
516
    GLboolean cullface = glIsEnabled(GL_CULL_FACE);
 
517
    glDisable(GL_CULL_FACE);
 
518
    OPENGL_CHECK_ERRORS;
 
519
 
 
520
    glBegin(GL_TRIANGLE_FAN);
 
521
 
 
522
    float depth = -(g_texRectTVtx[3].z*2-1);
 
523
 
 
524
    glColor4f(g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a);
 
525
    TexCoord(g_texRectTVtx[3]);
 
526
    glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, depth);
 
527
    
 
528
    glColor4f(g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a);
 
529
    TexCoord(g_texRectTVtx[2]);
 
530
    glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, depth);
 
531
 
 
532
    glColor4f(g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a);
 
533
    TexCoord(g_texRectTVtx[1]);
 
534
    glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, depth);
 
535
 
 
536
    glColor4f(g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a);
 
537
    TexCoord(g_texRectTVtx[0]);
 
538
    glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, depth);
 
539
 
 
540
    glEnd();
 
541
    OPENGL_CHECK_ERRORS;
 
542
 
 
543
    if( cullface ) glEnable(GL_CULL_FACE);
 
544
    OPENGL_CHECK_ERRORS;
 
545
 
 
546
    return true;
 
547
}
 
548
 
 
549
bool OGLRender::RenderFillRect(uint32 dwColor, float depth)
 
550
{
 
551
    float a = (dwColor>>24)/255.0f;
 
552
    float r = ((dwColor>>16)&0xFF)/255.0f;
 
553
    float g = ((dwColor>>8)&0xFF)/255.0f;
 
554
    float b = (dwColor&0xFF)/255.0f;
 
555
    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
 
556
    OPENGL_CHECK_ERRORS;
 
557
 
 
558
    GLboolean cullface = glIsEnabled(GL_CULL_FACE);
 
559
    glDisable(GL_CULL_FACE);
 
560
    OPENGL_CHECK_ERRORS;
 
561
 
 
562
    glBegin(GL_TRIANGLE_FAN);
 
563
    glColor4f(r,g,b,a);
 
564
    glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[1].y, depth, 1);
 
565
    glVertex4f(m_fillRectVtx[1].x, m_fillRectVtx[1].y, depth, 1);
 
566
    glVertex4f(m_fillRectVtx[1].x, m_fillRectVtx[0].y, depth, 1);
 
567
    glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[0].y, depth, 1);
 
568
    glEnd();
 
569
    OPENGL_CHECK_ERRORS;
 
570
 
 
571
    if( cullface ) glEnable(GL_CULL_FACE);
 
572
    OPENGL_CHECK_ERRORS;
 
573
 
 
574
    return true;
 
575
}
 
576
 
 
577
bool OGLRender::RenderLine3D()
 
578
{
 
579
    ApplyZBias(0);  // disable z offsets
 
580
 
 
581
    glBegin(GL_TRIANGLE_FAN);
 
582
 
 
583
    glColor4f(m_line3DVtx[1].r, m_line3DVtx[1].g, m_line3DVtx[1].b, m_line3DVtx[1].a);
 
584
    glVertex3f(m_line3DVector[3].x, m_line3DVector[3].y, -m_line3DVtx[3].z);
 
585
    glVertex3f(m_line3DVector[2].x, m_line3DVector[2].y, -m_line3DVtx[2].z);
 
586
    
 
587
    glColor4ub(m_line3DVtx[0].r, m_line3DVtx[0].g, m_line3DVtx[0].b, m_line3DVtx[0].a);
 
588
    glVertex3f(m_line3DVector[1].x, m_line3DVector[1].y, -m_line3DVtx[1].z);
 
589
    glVertex3f(m_line3DVector[0].x, m_line3DVector[0].y, -m_line3DVtx[0].z);
 
590
 
 
591
    glEnd();
 
592
    OPENGL_CHECK_ERRORS;
 
593
 
 
594
    ApplyZBias(m_dwZBias);          // set Z offset back to previous value
 
595
 
 
596
    return true;
 
597
}
 
598
 
 
599
extern FiddledVtx * g_pVtxBase;
 
600
 
 
601
// This is so weired that I can not do vertex transform by myself. I have to use
 
602
// OpenGL internal transform
 
603
bool OGLRender::RenderFlushTris()
 
604
{
 
605
    if( !m_bSupportFogCoordExt )    
 
606
        SetFogFlagForNegativeW();
 
607
    else
 
608
    {
 
609
        if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
 
610
        {
 
611
            glDisable(GL_FOG);
 
612
            OPENGL_CHECK_ERRORS;
 
613
        }
 
614
    }
 
615
 
 
616
    ApplyZBias(m_dwZBias);                    // set the bias factors
 
617
 
 
618
    glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW, false);
 
619
    OPENGL_CHECK_ERRORS;
 
620
 
 
621
    //if options.bOGLVertexClipper == FALSE )
 
622
    {
 
623
        glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_INT, g_vtxIndex );
 
624
        OPENGL_CHECK_ERRORS;
 
625
    }
 
626
/*  else
 
627
    {
 
628
        //ClipVertexesOpenGL();
 
629
        // Redo the index
 
630
        // Set the array
 
631
        glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5Clipped[0][0]) );
 
632
        glEnableClientState( GL_VERTEX_ARRAY );
 
633
 
 
634
        pglClientActiveTextureARB( GL_TEXTURE0_ARB );
 
635
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[0].u) );
 
636
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
637
 
 
638
        pglClientActiveTextureARB( GL_TEXTURE1_ARB );
 
639
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[1].u) );
 
640
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
641
 
 
642
        glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_INT, g_vtxIndex );
 
643
 
 
644
        // Reset the array
 
645
        pglClientActiveTextureARB( GL_TEXTURE0_ARB );
 
646
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
 
647
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
648
 
 
649
        pglClientActiveTextureARB( GL_TEXTURE1_ARB );
 
650
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
 
651
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
652
 
 
653
        glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
 
654
        glEnableClientState( GL_VERTEX_ARRAY );
 
655
    }
 
656
*/
 
657
 
 
658
    if( !m_bSupportFogCoordExt )    
 
659
        RestoreFogFlag();
 
660
    else
 
661
    {
 
662
        if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
 
663
        {
 
664
            glEnable(GL_FOG);
 
665
            OPENGL_CHECK_ERRORS;
 
666
        }
 
667
    }
 
668
    return true;
 
669
}
 
670
 
 
671
void OGLRender::DrawSimple2DTexture(float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, COLOR dif, COLOR spe, float z, float rhw)
 
672
{
 
673
    if( status.bVIOriginIsUpdated == true && currentRomOptions.screenUpdateSetting==SCREEN_UPDATE_AT_1ST_PRIMITIVE )
 
674
    {
 
675
        status.bVIOriginIsUpdated=false;
 
676
        CGraphicsContext::Get()->UpdateFrame();
 
677
        DEBUGGER_PAUSE_AND_DUMP_NO_UPDATE(NEXT_SET_CIMG,{DebuggerAppendMsg("Screen Update at 1st Simple2DTexture");});
 
678
    }
 
679
 
 
680
    StartDrawSimple2DTexture(x0, y0, x1, y1, u0, v0, u1, v1, dif, spe, z, rhw);
 
681
 
 
682
    GLboolean cullface = glIsEnabled(GL_CULL_FACE);
 
683
    glDisable(GL_CULL_FACE);
 
684
    OPENGL_CHECK_ERRORS;
 
685
 
 
686
    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
 
687
    OPENGL_CHECK_ERRORS;
 
688
 
 
689
    glBegin(GL_TRIANGLES);
 
690
    float a = (g_texRectTVtx[0].dcDiffuse >>24)/255.0f;
 
691
    float r = ((g_texRectTVtx[0].dcDiffuse>>16)&0xFF)/255.0f;
 
692
    float g = ((g_texRectTVtx[0].dcDiffuse>>8)&0xFF)/255.0f;
 
693
    float b = (g_texRectTVtx[0].dcDiffuse&0xFF)/255.0f;
 
694
    glColor4f(r,g,b,a);
 
695
 
 
696
    OGLRender::TexCoord(g_texRectTVtx[0]);
 
697
    glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
 
698
 
 
699
    OGLRender::TexCoord(g_texRectTVtx[1]);
 
700
    glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
 
701
 
 
702
    OGLRender::TexCoord(g_texRectTVtx[2]);
 
703
    glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
 
704
 
 
705
    OGLRender::TexCoord(g_texRectTVtx[0]);
 
706
    glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
 
707
 
 
708
    OGLRender::TexCoord(g_texRectTVtx[2]);
 
709
    glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
 
710
 
 
711
    OGLRender::TexCoord(g_texRectTVtx[3]);
 
712
    glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
 
713
    
 
714
    glEnd();
 
715
    OPENGL_CHECK_ERRORS;
 
716
 
 
717
    if( cullface ) glEnable(GL_CULL_FACE);
 
718
    OPENGL_CHECK_ERRORS;
 
719
}
 
720
 
 
721
void OGLRender::DrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColor, float depth, float rhw)
 
722
{
 
723
    StartDrawSimpleRect(nX0, nY0, nX1, nY1, dwColor, depth, rhw);
 
724
 
 
725
    GLboolean cullface = glIsEnabled(GL_CULL_FACE);
 
726
    glDisable(GL_CULL_FACE);
 
727
    OPENGL_CHECK_ERRORS;
 
728
 
 
729
    glBegin(GL_TRIANGLE_FAN);
 
730
 
 
731
    float a = (dwColor>>24)/255.0f;
 
732
    float r = ((dwColor>>16)&0xFF)/255.0f;
 
733
    float g = ((dwColor>>8)&0xFF)/255.0f;
 
734
    float b = (dwColor&0xFF)/255.0f;
 
735
    glColor4f(r,g,b,a);
 
736
    glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[0].y, -depth);
 
737
    glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[1].y, -depth);
 
738
    glVertex3f(m_simpleRectVtx[0].x, m_simpleRectVtx[1].y, -depth);
 
739
    glVertex3f(m_simpleRectVtx[0].x, m_simpleRectVtx[0].y, -depth);
 
740
    
 
741
    glEnd();
 
742
    OPENGL_CHECK_ERRORS;
 
743
 
 
744
    if( cullface ) glEnable(GL_CULL_FACE);
 
745
    OPENGL_CHECK_ERRORS;
 
746
}
 
747
 
 
748
void OGLRender::InitCombinerBlenderForSimpleRectDraw(uint32 tile)
 
749
{
 
750
    //glEnable(GL_CULL_FACE);
 
751
    EnableTexUnit(0,FALSE);
 
752
    OPENGL_CHECK_ERRORS;
 
753
    glEnable(GL_BLEND);
 
754
    OPENGL_CHECK_ERRORS;
 
755
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
756
    OPENGL_CHECK_ERRORS;
 
757
    //glEnable(GL_ALPHA_TEST);
 
758
}
 
759
 
 
760
COLOR OGLRender::PostProcessDiffuseColor(COLOR curDiffuseColor)
 
761
{
 
762
    uint32 color = curDiffuseColor;
 
763
    uint32 colorflag = m_pColorCombiner->m_pDecodedMux->m_dwShadeColorChannelFlag;
 
764
    uint32 alphaflag = m_pColorCombiner->m_pDecodedMux->m_dwShadeAlphaChannelFlag;
 
765
    if( colorflag+alphaflag != MUX_0 )
 
766
    {
 
767
        if( (colorflag & 0xFFFFFF00) == 0 && (alphaflag & 0xFFFFFF00) == 0 )
 
768
        {
 
769
            color = (m_pColorCombiner->GetConstFactor(colorflag, alphaflag, curDiffuseColor));
 
770
        }
 
771
        else
 
772
            color = (CalculateConstFactor(colorflag, alphaflag, curDiffuseColor));
 
773
    }
 
774
 
 
775
    //return (color<<8)|(color>>24);
 
776
    return color;
 
777
}
 
778
 
 
779
COLOR OGLRender::PostProcessSpecularColor()
 
780
{
 
781
    return 0;
 
782
}
 
783
 
 
784
void OGLRender::SetViewportRender()
 
785
{
 
786
    glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW);
 
787
    OPENGL_CHECK_ERRORS;
 
788
}
 
789
 
 
790
void OGLRender::RenderReset()
 
791
{
 
792
    CRender::RenderReset();
 
793
 
 
794
    glMatrixMode(GL_PROJECTION);
 
795
    OPENGL_CHECK_ERRORS;
 
796
    glLoadIdentity();
 
797
    OPENGL_CHECK_ERRORS;
 
798
    glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
 
799
    OPENGL_CHECK_ERRORS;
 
800
 
 
801
    // position viewer 
 
802
    glMatrixMode(GL_MODELVIEW);
 
803
    OPENGL_CHECK_ERRORS;
 
804
    glLoadIdentity();
 
805
    OPENGL_CHECK_ERRORS;
 
806
}
 
807
 
 
808
void OGLRender::SetAlphaTestEnable(BOOL bAlphaTestEnable)
 
809
{
 
810
#ifdef DEBUGGER
 
811
    if( bAlphaTestEnable && debuggerEnableAlphaTest )
 
812
#else
 
813
    if( bAlphaTestEnable )
 
814
#endif
 
815
        glEnable(GL_ALPHA_TEST);
 
816
    else
 
817
        glDisable(GL_ALPHA_TEST);
 
818
    OPENGL_CHECK_ERRORS;
 
819
}
 
820
 
 
821
void OGLRender::BindTexture(GLuint texture, int unitno)
 
822
{
 
823
#ifdef DEBUGGER
 
824
    if( unitno != 0 )
 
825
    {
 
826
        DebuggerAppendMsg("Check me, base ogl bind texture, unit no != 0");
 
827
    }
 
828
#endif
 
829
    if( m_curBoundTex[0] != texture )
 
830
    {
 
831
        glBindTexture(GL_TEXTURE_2D,texture);
 
832
        OPENGL_CHECK_ERRORS;
 
833
        m_curBoundTex[0] = texture;
 
834
    }
 
835
}
 
836
 
 
837
void OGLRender::DisBindTexture(GLuint texture, int unitno)
 
838
{
 
839
    //EnableTexUnit(0,FALSE);
 
840
    //glBindTexture(GL_TEXTURE_2D, 0);  //Not to bind any texture
 
841
}
 
842
 
 
843
void OGLRender::EnableTexUnit(int unitno, BOOL flag)
 
844
{
 
845
#ifdef DEBUGGER
 
846
    if( unitno != 0 )
 
847
    {
 
848
        DebuggerAppendMsg("Check me, in the base ogl render, unitno!=0");
 
849
    }
 
850
#endif
 
851
    if( m_texUnitEnabled[0] != flag )
 
852
    {
 
853
        m_texUnitEnabled[0] = flag;
 
854
        if( flag == TRUE )
 
855
            glEnable(GL_TEXTURE_2D);
 
856
        else
 
857
            glDisable(GL_TEXTURE_2D);
 
858
        OPENGL_CHECK_ERRORS;
 
859
    }
 
860
}
 
861
 
 
862
void OGLRender::TexCoord2f(float u, float v)
 
863
{
 
864
    glTexCoord2f(u, v);
 
865
}
 
866
 
 
867
void OGLRender::TexCoord(TLITVERTEX &vtxInfo)
 
868
{
 
869
    glTexCoord2f(vtxInfo.tcord[0].u, vtxInfo.tcord[0].v);
 
870
}
 
871
 
 
872
void OGLRender::UpdateScissor()
 
873
{
 
874
    if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
 
875
    {
 
876
        // Hack for RE2
 
877
        uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
 
878
        uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
 
879
        glEnable(GL_SCISSOR_TEST);
 
880
        OPENGL_CHECK_ERRORS;
 
881
        glScissor(0, int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
 
882
            int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
 
883
        OPENGL_CHECK_ERRORS;
 
884
    }
 
885
    else
 
886
    {
 
887
        UpdateScissorWithClipRatio();
 
888
    }
 
889
}
 
890
 
 
891
void OGLRender::ApplyRDPScissor(bool force)
 
892
{
 
893
    if( !force && status.curScissor == RDP_SCISSOR )    return;
 
894
 
 
895
    if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
 
896
    {
 
897
        // Hack for RE2
 
898
        uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
 
899
        uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
 
900
        glEnable(GL_SCISSOR_TEST);
 
901
        OPENGL_CHECK_ERRORS;
 
902
        glScissor(0, int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
 
903
            int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
 
904
        OPENGL_CHECK_ERRORS;
 
905
    }
 
906
    else
 
907
    {
 
908
        glScissor(int(gRDP.scissor.left*windowSetting.fMultX), int((windowSetting.uViHeight-gRDP.scissor.bottom)*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
 
909
            int((gRDP.scissor.right-gRDP.scissor.left)*windowSetting.fMultX), int((gRDP.scissor.bottom-gRDP.scissor.top)*windowSetting.fMultY ));
 
910
        OPENGL_CHECK_ERRORS;
 
911
    }
 
912
 
 
913
    status.curScissor = RDP_SCISSOR;
 
914
}
 
915
 
 
916
void OGLRender::ApplyScissorWithClipRatio(bool force)
 
917
{
 
918
    if( !force && status.curScissor == RSP_SCISSOR )    return;
 
919
 
 
920
    glEnable(GL_SCISSOR_TEST);
 
921
    OPENGL_CHECK_ERRORS;
 
922
    glScissor(windowSetting.clipping.left, int((windowSetting.uViHeight-gRSP.real_clip_scissor_bottom)*windowSetting.fMultY)+windowSetting.statusBarHeightToUse,
 
923
        windowSetting.clipping.width, windowSetting.clipping.height);
 
924
    OPENGL_CHECK_ERRORS;
 
925
 
 
926
    status.curScissor = RSP_SCISSOR;
 
927
}
 
928
 
 
929
void OGLRender::SetFogMinMax(float fMin, float fMax)
 
930
{
 
931
    glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
 
932
    OPENGL_CHECK_ERRORS;
 
933
    glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
 
934
    OPENGL_CHECK_ERRORS;
 
935
}
 
936
 
 
937
void OGLRender::TurnFogOnOff(bool flag)
 
938
{
 
939
    if( flag )
 
940
        glEnable(GL_FOG);
 
941
    else
 
942
        glDisable(GL_FOG);
 
943
    OPENGL_CHECK_ERRORS;
 
944
}
 
945
 
 
946
void OGLRender::SetFogEnable(bool bEnable)
 
947
{
 
948
    DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != (bEnable==TRUE) && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
 
949
 
 
950
    gRSP.bFogEnabled = bEnable&&(options.fogMethod == 1);
 
951
    
 
952
    // If force fog
 
953
    if(options.fogMethod == 2)
 
954
    {
 
955
        gRSP.bFogEnabled = true;
 
956
    }
 
957
 
 
958
    if( gRSP.bFogEnabled )
 
959
    {
 
960
        //TRACE2("Enable fog, min=%f, max=%f",gRSPfFogMin,gRSPfFogMax );
 
961
        glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
 
962
        OPENGL_CHECK_ERRORS;
 
963
        glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
 
964
        OPENGL_CHECK_ERRORS;
 
965
        glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
 
966
        OPENGL_CHECK_ERRORS;
 
967
        glEnable(GL_FOG);
 
968
        OPENGL_CHECK_ERRORS;
 
969
    }
 
970
    else
 
971
    {
 
972
        glDisable(GL_FOG);
 
973
        OPENGL_CHECK_ERRORS;
 
974
    }
 
975
}
 
976
 
 
977
void OGLRender::SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
 
978
{
 
979
    gRDP.fogColor = COLOR_RGBA(r, g, b, a); 
 
980
    gRDP.fvFogColor[0] = r/255.0f;      //r
 
981
    gRDP.fvFogColor[1] = g/255.0f;      //g
 
982
    gRDP.fvFogColor[2] = b/255.0f;          //b
 
983
    gRDP.fvFogColor[3] = a/255.0f;      //a
 
984
    glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
 
985
    OPENGL_CHECK_ERRORS;
 
986
}
 
987
 
 
988
void OGLRender::DisableMultiTexture()
 
989
{
 
990
    pglActiveTexture(GL_TEXTURE1_ARB);
 
991
    OPENGL_CHECK_ERRORS;
 
992
    EnableTexUnit(1,FALSE);
 
993
    pglActiveTexture(GL_TEXTURE0_ARB);
 
994
    OPENGL_CHECK_ERRORS;
 
995
    EnableTexUnit(0,FALSE);
 
996
    pglActiveTexture(GL_TEXTURE0_ARB);
 
997
    OPENGL_CHECK_ERRORS;
 
998
    EnableTexUnit(0,TRUE);
 
999
}
 
1000
 
 
1001
void OGLRender::EndRendering(void)
 
1002
{
 
1003
    glFlush();
 
1004
    OPENGL_CHECK_ERRORS;
 
1005
    if( CRender::gRenderReferenceCount > 0 ) 
 
1006
        CRender::gRenderReferenceCount--;
 
1007
}
 
1008
 
 
1009
void OGLRender::glViewportWrapper(GLint x, GLint y, GLsizei width, GLsizei height, bool flag)
 
1010
{
 
1011
    static GLint mx=0,my=0;
 
1012
    static GLsizei m_width=0, m_height=0;
 
1013
    static bool mflag=true;
 
1014
 
 
1015
    if( x!=mx || y!=my || width!=m_width || height!=m_height || mflag!=flag)
 
1016
    {
 
1017
        mx=x;
 
1018
        my=y;
 
1019
        m_width=width;
 
1020
        m_height=height;
 
1021
        mflag=flag;
 
1022
        glMatrixMode(GL_PROJECTION);
 
1023
        OPENGL_CHECK_ERRORS;
 
1024
        glLoadIdentity();
 
1025
        OPENGL_CHECK_ERRORS;
 
1026
        if( flag )  glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
 
1027
        OPENGL_CHECK_ERRORS;
 
1028
        glViewport(x,y,width,height);
 
1029
        OPENGL_CHECK_ERRORS;
 
1030
    }
 
1031
}
 
1032