2
Copyright (C) 2003 Rice1964
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.
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.
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.
19
#include "OGLExtensions.h"
21
#include "OGLRender.h"
22
#include "OGLGraphicsContext.h"
23
#include "OGLTexture.h"
24
#include "TextureManager.h"
26
// Fix me, use OGL internal L/T and matrix stack
27
// Fix me, use OGL lookupAt function
28
// Fix me, use OGL DisplayList
30
UVFlagMap OGLXUVFlagMaps[] =
32
{TEXTURE_UV_FLAG_WRAP, GL_REPEAT},
33
{TEXTURE_UV_FLAG_MIRROR, GL_MIRRORED_REPEAT_ARB},
34
{TEXTURE_UV_FLAG_CLAMP, GL_CLAMP},
37
//===================================================================
38
OGLRender::OGLRender()
40
COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
41
m_bSupportFogCoordExt = pcontext->m_bSupportFogCoord;
42
m_bMultiTexture = pcontext->m_bSupportMultiTexture;
43
m_bSupportClampToEdge = false;
45
m_bClampT[0] = m_bClampT[1] = false;
46
for( int i=0; i<8; i++ )
49
m_texUnitEnabled[i]=FALSE;
51
m_bEnableMultiTexture = false;
54
OGLRender::~OGLRender()
59
bool OGLRender::InitDeviceObjects()
61
// enable Z-buffer by default
66
bool OGLRender::ClearDeviceObjects()
71
void OGLRender::Initialize(void)
73
glMatrixMode(GL_MODELVIEW);
78
glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
81
COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
82
if( pcontext->IsExtensionSupported("GL_IBM_texture_mirrored_repeat") )
84
OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_IBM;
86
else if( pcontext->IsExtensionSupported("ARB_texture_mirrored_repeat") )
88
OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_ARB;
92
OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_REPEAT;
95
if( pcontext->IsExtensionSupported("GL_ARB_texture_border_clamp") || pcontext->IsExtensionSupported("GL_EXT_texture_edge_clamp") )
97
m_bSupportClampToEdge = true;
98
OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
102
m_bSupportClampToEdge = false;
103
OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP;
106
glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
108
glEnableClientState( GL_VERTEX_ARRAY );
111
if( m_bMultiTexture )
113
pglClientActiveTextureARB( GL_TEXTURE0_ARB );
115
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
117
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
120
pglClientActiveTextureARB( GL_TEXTURE1_ARB );
122
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
124
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
129
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
131
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
135
if (m_bSupportFogCoordExt)
137
pglFogCoordPointerEXT( GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][4]) );
139
glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
141
glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
143
glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode
145
glFogf(GL_FOG_DENSITY, 1.0f); // How Dense Will The Fog Be
147
glHint(GL_FOG_HINT, GL_FASTEST); // Fog Hint Value
149
glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
151
glFogf( GL_FOG_START, 0.0f );
153
glFogf( GL_FOG_END, 1.0f );
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]) );
160
glEnableClientState( GL_COLOR_ARRAY );
163
if( pcontext->IsExtensionSupported("GL_NV_depth_clamp") )
165
glEnable(GL_DEPTH_CLAMP_NV);
170
//===================================================================
171
TextureFilterMap OglTexFilterMap[2]=
173
{FILTER_POINT, GL_NEAREST},
174
{FILTER_LINEAR, GL_LINEAR},
177
void OGLRender::ApplyTextureFilter()
179
static uint32 minflag=0xFFFF, magflag=0xFFFF;
182
if( m_texUnitEnabled[0] )
184
if( mtex != m_curBoundTex[0] )
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);
191
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, OglTexFilterMap[m_dwMagFilter].realFilter);
196
if( minflag != (unsigned int)m_dwMinFilter )
198
minflag = m_dwMinFilter;
199
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, OglTexFilterMap[m_dwMinFilter].realFilter);
202
if( magflag != (unsigned int)m_dwMagFilter )
204
magflag = m_dwMagFilter;
205
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, OglTexFilterMap[m_dwMagFilter].realFilter);
212
void OGLRender::SetShadeMode(RenderShadeMode mode)
214
if( mode == SHADE_SMOOTH )
215
glShadeModel(GL_SMOOTH);
217
glShadeModel(GL_FLAT);
221
void OGLRender::ZBufferEnable(BOOL bZBuffer)
223
gRSP.bZBufferEnabled = bZBuffer;
224
if( g_curRomInfo.bForceDepthBuffer )
228
glDepthMask(GL_TRUE);
230
//glEnable(GL_DEPTH_TEST);
231
glDepthFunc( GL_LEQUAL );
236
glDepthMask(GL_FALSE);
238
//glDisable(GL_DEPTH_TEST);
239
glDepthFunc( GL_ALWAYS );
244
void OGLRender::ClearBuffer(bool cbuffer, bool zbuffer)
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;
256
void OGLRender::ClearZBuffer(float depth)
258
uint32 flag=GL_DEPTH_BUFFER_BIT;
265
void OGLRender::SetZCompare(BOOL bZCompare)
267
if( g_curRomInfo.bForceDepthBuffer )
270
gRSP.bZBufferEnabled = bZCompare;
271
if( bZCompare == TRUE )
273
//glEnable(GL_DEPTH_TEST);
274
glDepthFunc( GL_LEQUAL );
279
//glDisable(GL_DEPTH_TEST);
280
glDepthFunc( GL_ALWAYS );
285
void OGLRender::SetZUpdate(BOOL bZUpdate)
287
if( g_curRomInfo.bForceDepthBuffer )
292
//glEnable(GL_DEPTH_TEST);
293
glDepthMask(GL_TRUE);
298
glDepthMask(GL_FALSE);
303
void OGLRender::ApplyZBias(int bias)
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
309
glEnable(GL_POLYGON_OFFSET_FILL); // enable z offsets
314
glDisable(GL_POLYGON_OFFSET_FILL); // disable z offsets
317
glPolygonOffset(f1, f2); // set bias functions
321
void OGLRender::SetZBias(int bias)
323
#if defined(DEBUGGER)
324
if( pauseAtNext == true )
325
DebuggerAppendMsg("Set zbias = %d", bias);
327
// set member variable and apply the setting in opengl
332
void OGLRender::SetAlphaRef(uint32 dwAlpha)
334
if (m_dwAlpha != dwAlpha)
337
glAlphaFunc(GL_GEQUAL, (float)dwAlpha);
342
void OGLRender::ForceAlphaRef(uint32 dwAlpha)
344
float ref = dwAlpha/255.0f;
345
glAlphaFunc(GL_GEQUAL, ref);
349
void OGLRender::SetFillMode(FillMode mode)
351
if( mode == RICE_FILLMODE_WINFRAME )
353
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
358
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
363
void OGLRender::SetCullMode(bool bCullFront, bool bCullBack)
365
CRender::SetCullMode(bCullFront, bCullBack);
366
if( bCullFront && bCullBack )
368
glCullFace(GL_FRONT_AND_BACK);
370
glEnable(GL_CULL_FACE);
373
else if( bCullFront )
375
glCullFace(GL_FRONT);
377
glEnable(GL_CULL_FACE);
384
glEnable(GL_CULL_FACE);
389
glDisable(GL_CULL_FACE);
394
bool OGLRender::SetCurrentTexture(int tile, CTexture *handler,uint32 dwTileWidth, uint32 dwTileHeight, TxtrCacheEntry *pTextureEntry)
396
RenderTexture &texture = g_textures[tile];
397
texture.pTextureEntry = pTextureEntry;
399
if( handler!= NULL && texture.m_lpsTexturePtr != handler->GetTexture() )
401
texture.m_pCTexture = handler;
402
texture.m_lpsTexturePtr = handler->GetTexture();
404
texture.m_dwTileWidth = dwTileWidth;
405
texture.m_dwTileHeight = dwTileHeight;
407
if( handler->m_bIsEnhancedTexture )
409
texture.m_fTexWidth = (float)pTextureEntry->pTexture->m_dwCreatedTextureWidth;
410
texture.m_fTexHeight = (float)pTextureEntry->pTexture->m_dwCreatedTextureHeight;
414
texture.m_fTexWidth = (float)handler->m_dwCreatedTextureWidth;
415
texture.m_fTexHeight = (float)handler->m_dwCreatedTextureHeight;
422
bool OGLRender::SetCurrentTexture(int tile, TxtrCacheEntry *pEntry)
424
if (pEntry != NULL && pEntry->pTexture != NULL)
426
SetCurrentTexture( tile, pEntry->pTexture, pEntry->ti.WidthToCreate, pEntry->ti.HeightToCreate, pEntry);
431
SetCurrentTexture( tile, NULL, 64, 64, NULL );
437
void OGLRender::SetAddressUAllStages(uint32 dwTile, TextureUVFlag dwFlag)
439
SetTextureUFlag(dwFlag, dwTile);
442
void OGLRender::SetAddressVAllStages(uint32 dwTile, TextureUVFlag dwFlag)
444
SetTextureVFlag(dwFlag, dwTile);
447
void OGLRender::SetTexWrapS(int unitno,GLuint flag)
454
DebuggerAppendMsg("Check me, unitno != 0 in base ogl");
457
if( m_curBoundTex[0] != mtex || mflag != flag )
459
mtex = m_curBoundTex[0];
461
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, flag);
465
void OGLRender::SetTexWrapT(int unitno,GLuint flag)
469
if( m_curBoundTex[0] != mtex || mflag != flag )
471
mtex = m_curBoundTex[0];
473
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, flag);
478
void OGLRender::SetTextureUFlag(TextureUVFlag dwFlag, uint32 dwTile)
480
TileUFlags[dwTile] = dwFlag;
481
if( dwTile == gRSP.curTile ) // For basic OGL, only support the 1st texel
483
COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
486
EnableTexUnit(0,TRUE);
487
BindTexture(pTexture->m_dwTextureName, 0);
489
SetTexWrapS(0, OGLXUVFlagMaps[dwFlag].realFlag);
490
m_bClampS[0] = dwFlag==TEXTURE_UV_FLAG_CLAMP?true:false;
493
void OGLRender::SetTextureVFlag(TextureUVFlag dwFlag, uint32 dwTile)
495
TileVFlags[dwTile] = dwFlag;
496
if( dwTile == gRSP.curTile ) // For basic OGL, only support the 1st texel
498
COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
501
EnableTexUnit(0,TRUE);
502
BindTexture(pTexture->m_dwTextureName, 0);
504
SetTexWrapT(0, OGLXUVFlagMaps[dwFlag].realFlag);
505
m_bClampT[0] = dwFlag==TEXTURE_UV_FLAG_CLAMP?true:false;
509
// Basic render drawing functions
511
bool OGLRender::RenderTexRect()
513
glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
516
GLboolean cullface = glIsEnabled(GL_CULL_FACE);
517
glDisable(GL_CULL_FACE);
520
glBegin(GL_TRIANGLE_FAN);
522
float depth = -(g_texRectTVtx[3].z*2-1);
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);
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);
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);
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);
543
if( cullface ) glEnable(GL_CULL_FACE);
549
bool OGLRender::RenderFillRect(uint32 dwColor, float depth)
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);
558
GLboolean cullface = glIsEnabled(GL_CULL_FACE);
559
glDisable(GL_CULL_FACE);
562
glBegin(GL_TRIANGLE_FAN);
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);
571
if( cullface ) glEnable(GL_CULL_FACE);
577
bool OGLRender::RenderLine3D()
579
ApplyZBias(0); // disable z offsets
581
glBegin(GL_TRIANGLE_FAN);
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);
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);
594
ApplyZBias(m_dwZBias); // set Z offset back to previous value
599
extern FiddledVtx * g_pVtxBase;
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()
605
if( !m_bSupportFogCoordExt )
606
SetFogFlagForNegativeW();
609
if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
616
ApplyZBias(m_dwZBias); // set the bias factors
618
glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW, false);
621
//if options.bOGLVertexClipper == FALSE )
623
glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_INT, g_vtxIndex );
628
//ClipVertexesOpenGL();
631
glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5Clipped[0][0]) );
632
glEnableClientState( GL_VERTEX_ARRAY );
634
pglClientActiveTextureARB( GL_TEXTURE0_ARB );
635
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[0].u) );
636
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
638
pglClientActiveTextureARB( GL_TEXTURE1_ARB );
639
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[1].u) );
640
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
642
glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_INT, g_vtxIndex );
645
pglClientActiveTextureARB( GL_TEXTURE0_ARB );
646
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
647
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
649
pglClientActiveTextureARB( GL_TEXTURE1_ARB );
650
glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
651
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
653
glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
654
glEnableClientState( GL_VERTEX_ARRAY );
658
if( !m_bSupportFogCoordExt )
662
if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
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)
673
if( status.bVIOriginIsUpdated == true && currentRomOptions.screenUpdateSetting==SCREEN_UPDATE_AT_1ST_PRIMITIVE )
675
status.bVIOriginIsUpdated=false;
676
CGraphicsContext::Get()->UpdateFrame();
677
DEBUGGER_PAUSE_AND_DUMP_NO_UPDATE(NEXT_SET_CIMG,{DebuggerAppendMsg("Screen Update at 1st Simple2DTexture");});
680
StartDrawSimple2DTexture(x0, y0, x1, y1, u0, v0, u1, v1, dif, spe, z, rhw);
682
GLboolean cullface = glIsEnabled(GL_CULL_FACE);
683
glDisable(GL_CULL_FACE);
686
glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
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;
696
OGLRender::TexCoord(g_texRectTVtx[0]);
697
glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
699
OGLRender::TexCoord(g_texRectTVtx[1]);
700
glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
702
OGLRender::TexCoord(g_texRectTVtx[2]);
703
glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
705
OGLRender::TexCoord(g_texRectTVtx[0]);
706
glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
708
OGLRender::TexCoord(g_texRectTVtx[2]);
709
glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
711
OGLRender::TexCoord(g_texRectTVtx[3]);
712
glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
717
if( cullface ) glEnable(GL_CULL_FACE);
721
void OGLRender::DrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColor, float depth, float rhw)
723
StartDrawSimpleRect(nX0, nY0, nX1, nY1, dwColor, depth, rhw);
725
GLboolean cullface = glIsEnabled(GL_CULL_FACE);
726
glDisable(GL_CULL_FACE);
729
glBegin(GL_TRIANGLE_FAN);
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;
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);
744
if( cullface ) glEnable(GL_CULL_FACE);
748
void OGLRender::InitCombinerBlenderForSimpleRectDraw(uint32 tile)
750
//glEnable(GL_CULL_FACE);
751
EnableTexUnit(0,FALSE);
755
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
757
//glEnable(GL_ALPHA_TEST);
760
COLOR OGLRender::PostProcessDiffuseColor(COLOR curDiffuseColor)
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 )
767
if( (colorflag & 0xFFFFFF00) == 0 && (alphaflag & 0xFFFFFF00) == 0 )
769
color = (m_pColorCombiner->GetConstFactor(colorflag, alphaflag, curDiffuseColor));
772
color = (CalculateConstFactor(colorflag, alphaflag, curDiffuseColor));
775
//return (color<<8)|(color>>24);
779
COLOR OGLRender::PostProcessSpecularColor()
784
void OGLRender::SetViewportRender()
786
glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW);
790
void OGLRender::RenderReset()
792
CRender::RenderReset();
794
glMatrixMode(GL_PROJECTION);
798
glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
802
glMatrixMode(GL_MODELVIEW);
808
void OGLRender::SetAlphaTestEnable(BOOL bAlphaTestEnable)
811
if( bAlphaTestEnable && debuggerEnableAlphaTest )
813
if( bAlphaTestEnable )
815
glEnable(GL_ALPHA_TEST);
817
glDisable(GL_ALPHA_TEST);
821
void OGLRender::BindTexture(GLuint texture, int unitno)
826
DebuggerAppendMsg("Check me, base ogl bind texture, unit no != 0");
829
if( m_curBoundTex[0] != texture )
831
glBindTexture(GL_TEXTURE_2D,texture);
833
m_curBoundTex[0] = texture;
837
void OGLRender::DisBindTexture(GLuint texture, int unitno)
839
//EnableTexUnit(0,FALSE);
840
//glBindTexture(GL_TEXTURE_2D, 0); //Not to bind any texture
843
void OGLRender::EnableTexUnit(int unitno, BOOL flag)
848
DebuggerAppendMsg("Check me, in the base ogl render, unitno!=0");
851
if( m_texUnitEnabled[0] != flag )
853
m_texUnitEnabled[0] = flag;
855
glEnable(GL_TEXTURE_2D);
857
glDisable(GL_TEXTURE_2D);
862
void OGLRender::TexCoord2f(float u, float v)
867
void OGLRender::TexCoord(TLITVERTEX &vtxInfo)
869
glTexCoord2f(vtxInfo.tcord[0].u, vtxInfo.tcord[0].v);
872
void OGLRender::UpdateScissor()
874
if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
877
uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
878
uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
879
glEnable(GL_SCISSOR_TEST);
881
glScissor(0, int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
882
int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
887
UpdateScissorWithClipRatio();
891
void OGLRender::ApplyRDPScissor(bool force)
893
if( !force && status.curScissor == RDP_SCISSOR ) return;
895
if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
898
uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
899
uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
900
glEnable(GL_SCISSOR_TEST);
902
glScissor(0, int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
903
int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
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 ));
913
status.curScissor = RDP_SCISSOR;
916
void OGLRender::ApplyScissorWithClipRatio(bool force)
918
if( !force && status.curScissor == RSP_SCISSOR ) return;
920
glEnable(GL_SCISSOR_TEST);
922
glScissor(windowSetting.clipping.left, int((windowSetting.uViHeight-gRSP.real_clip_scissor_bottom)*windowSetting.fMultY)+windowSetting.statusBarHeightToUse,
923
windowSetting.clipping.width, windowSetting.clipping.height);
926
status.curScissor = RSP_SCISSOR;
929
void OGLRender::SetFogMinMax(float fMin, float fMax)
931
glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
933
glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
937
void OGLRender::TurnFogOnOff(bool flag)
946
void OGLRender::SetFogEnable(bool bEnable)
948
DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != (bEnable==TRUE) && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
950
gRSP.bFogEnabled = bEnable&&(options.fogMethod == 1);
953
if(options.fogMethod == 2)
955
gRSP.bFogEnabled = true;
958
if( gRSP.bFogEnabled )
960
//TRACE2("Enable fog, min=%f, max=%f",gRSPfFogMin,gRSPfFogMax );
961
glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
963
glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
965
glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
977
void OGLRender::SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
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
988
void OGLRender::DisableMultiTexture()
990
pglActiveTexture(GL_TEXTURE1_ARB);
992
EnableTexUnit(1,FALSE);
993
pglActiveTexture(GL_TEXTURE0_ARB);
995
EnableTexUnit(0,FALSE);
996
pglActiveTexture(GL_TEXTURE0_ARB);
998
EnableTexUnit(0,TRUE);
1001
void OGLRender::EndRendering(void)
1004
OPENGL_CHECK_ERRORS;
1005
if( CRender::gRenderReferenceCount > 0 )
1006
CRender::gRenderReferenceCount--;
1009
void OGLRender::glViewportWrapper(GLint x, GLint y, GLsizei width, GLsizei height, bool flag)
1011
static GLint mx=0,my=0;
1012
static GLsizei m_width=0, m_height=0;
1013
static bool mflag=true;
1015
if( x!=mx || y!=my || width!=m_width || height!=m_height || mflag!=flag)
1022
glMatrixMode(GL_PROJECTION);
1023
OPENGL_CHECK_ERRORS;
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;