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 "osal_opengl.h"
22 #include "OGLExtensions.h"
23 #elif SDL_VIDEO_OPENGL_ES2
24 #include "OGLES2FragmentShaders.h"
27 #include "OGLRender.h"
28 #include "OGLGraphicsContext.h"
29 #include "OGLTexture.h"
30 #include "TextureManager.h"
33 //include "ae_bridge.h"
34 //static int hardwareType = HARDWARE_TYPE_UNKNOWN;
37 // FIXME: Use OGL internal L/T and matrix stack
38 // FIXME: Use OGL lookupAt function
39 // FIXME: Use OGL DisplayList
41 UVFlagMap OGLXUVFlagMaps[] =
43 {TEXTURE_UV_FLAG_WRAP, GL_REPEAT},
44 {TEXTURE_UV_FLAG_MIRROR, GL_MIRRORED_REPEAT_ARB},
45 {TEXTURE_UV_FLAG_CLAMP, GL_CLAMP},
48 #if SDL_VIDEO_OPENGL_ES2
49 static GLuint disabledTextureID;
52 //===================================================================
53 OGLRender::OGLRender()
55 COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
56 m_bSupportFogCoordExt = pcontext->m_bSupportFogCoord;
57 m_bMultiTexture = pcontext->m_bSupportMultiTexture;
59 m_bSupportClampToEdge = true;
61 m_bSupportClampToEdge = false;
63 for( int i=0; i<8; i++ )
66 m_texUnitEnabled[i]=FALSE;
71 m_bEnableMultiTexture = true;
73 m_bEnableMultiTexture = false;
76 #elif SDL_VIDEO_OPENGL_ES2
77 m_bEnableMultiTexture = true;
79 //Create a texture as replacement for glEnable/Disable(GL_TEXTURE_2D)
80 unsigned int white[8*8];
81 for (int i=0; i<8*8; i++) {
82 //white[i].r = white[i].g = white[i].b = 0;
86 glGenTextures(1,&disabledTextureID);
88 glBindTexture(GL_TEXTURE_2D, disabledTextureID);
90 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
92 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, white);
97 OGLRender::~OGLRender()
102 bool OGLRender::InitDeviceObjects()
104 // enable Z-buffer by default
109 bool OGLRender::ClearDeviceObjects()
114 void OGLRender::Initialize(void)
116 glMatrixMode(GL_MODELVIEW);
121 glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
125 COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
127 if( pcontext->IsExtensionSupported("GL_IBM_texture_mirrored_repeat") )
129 OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_IBM;
131 else if( pcontext->IsExtensionSupported("ARB_texture_mirrored_repeat") )
134 OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_ARB;
139 OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_REPEAT;
141 if( pcontext->IsExtensionSupported("GL_ARB_texture_border_clamp") || pcontext->IsExtensionSupported("GL_EXT_texture_edge_clamp") )
144 m_bSupportClampToEdge = true;
145 OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
150 m_bSupportClampToEdge = false;
151 OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP;
154 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
156 glEnableClientState( GL_VERTEX_ARRAY );
159 if( m_bMultiTexture )
161 pglClientActiveTextureARB( GL_TEXTURE0_ARB );
163 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
165 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
168 pglClientActiveTextureARB( GL_TEXTURE1_ARB );
170 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
172 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
177 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
179 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
183 if (m_bSupportFogCoordExt)
185 pglFogCoordPointerEXT( GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][4]) );
187 glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
189 glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
191 glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode
193 glFogf(GL_FOG_DENSITY, 1.0f); // How Dense Will The Fog Be
195 glHint(GL_FOG_HINT, GL_FASTEST); // Fog Hint Value
197 glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
199 glFogf( GL_FOG_START, 0.0f );
201 glFogf( GL_FOG_END, 1.0f );
205 //glColorPointer( 1, GL_UNSIGNED_BYTE, sizeof(TLITVERTEX), &g_vtxBuffer[0].r);
206 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
208 glEnableClientState( GL_COLOR_ARRAY );
211 if( pcontext->IsExtensionSupported("GL_NV_depth_clamp") )
213 glEnable(GL_DEPTH_CLAMP_NV);
217 #elif SDL_VIDEO_OPENGL_ES2
218 OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT;
219 m_bSupportClampToEdge = true;
220 OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
224 // hardwareType = Android_JNI_GetHardwareType();
227 //===================================================================
228 TextureFilterMap OglTexFilterMap[2]=
230 {FILTER_POINT, GL_NEAREST},
231 {FILTER_LINEAR, GL_LINEAR},
234 void OGLRender::ApplyTextureFilter()
236 static uint32 minflag=0xFFFF, magflag=0xFFFF;
239 if( m_texUnitEnabled[0] )
241 if( mtex != m_curBoundTex[0] )
243 mtex = m_curBoundTex[0];
244 minflag = m_dwMinFilter;
245 magflag = m_dwMagFilter;
246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, OglTexFilterMap[m_dwMinFilter].realFilter);
248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, OglTexFilterMap[m_dwMagFilter].realFilter);
253 if( minflag != (unsigned int)m_dwMinFilter )
255 minflag = m_dwMinFilter;
256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, OglTexFilterMap[m_dwMinFilter].realFilter);
259 if( magflag != (unsigned int)m_dwMagFilter )
261 magflag = m_dwMagFilter;
262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, OglTexFilterMap[m_dwMagFilter].realFilter);
269 void OGLRender::SetShadeMode(RenderShadeMode mode)
272 if( mode == SHADE_SMOOTH )
273 glShadeModel(GL_SMOOTH);
275 glShadeModel(GL_FLAT);
280 void OGLRender::ZBufferEnable(BOOL bZBuffer)
282 gRSP.bZBufferEnabled = bZBuffer;
283 if( g_curRomInfo.bForceDepthBuffer )
287 glDepthMask(GL_TRUE);
289 //glEnable(GL_DEPTH_TEST);
290 glDepthFunc( GL_LEQUAL );
295 glDepthMask(GL_FALSE);
297 //glDisable(GL_DEPTH_TEST);
298 glDepthFunc( GL_ALWAYS );
303 void OGLRender::ClearBuffer(bool cbuffer, bool zbuffer)
306 if( cbuffer ) flag |= GL_COLOR_BUFFER_BIT;
307 if( zbuffer ) flag |= GL_DEPTH_BUFFER_BIT;
308 float depth = ((gRDP.originalFillColor&0xFFFF)>>2)/(float)0x3FFF;
315 void OGLRender::ClearZBuffer(float depth)
317 uint32 flag=GL_DEPTH_BUFFER_BIT;
324 void OGLRender::SetZCompare(BOOL bZCompare)
326 if( g_curRomInfo.bForceDepthBuffer )
329 gRSP.bZBufferEnabled = bZCompare;
330 if( bZCompare == TRUE )
332 //glEnable(GL_DEPTH_TEST);
333 glDepthFunc( GL_LEQUAL );
338 //glDisable(GL_DEPTH_TEST);
339 glDepthFunc( GL_ALWAYS );
344 void OGLRender::SetZUpdate(BOOL bZUpdate)
346 if( g_curRomInfo.bForceDepthBuffer )
351 //glEnable(GL_DEPTH_TEST);
352 glDepthMask(GL_TRUE);
357 glDepthMask(GL_FALSE);
362 void OGLRender::ApplyZBias(int bias)
364 float f1 = bias > 0 ? -3.0f : 0.0f; // z offset = -3.0 * max(abs(dz/dx),abs(dz/dy)) per pixel delta z slope
365 float f2 = bias > 0 ? -3.0f : 0.0f; // z offset += -3.0 * 1 bit
368 // Android_JNI_GetPolygonOffset(hardwareType, bias, &f1, &f2);
369 // glPolygonOffset(0.2f, 0.2f);
374 glEnable(GL_POLYGON_OFFSET_FILL); // enable z offsets
379 glDisable(GL_POLYGON_OFFSET_FILL); // disable z offsets
382 glPolygonOffset(f1, f2); // set bias functions
386 void OGLRender::SetZBias(int bias)
388 #if defined(DEBUGGER)
389 if( pauseAtNext == true )
390 DebuggerAppendMsg("Set zbias = %d", bias);
392 // set member variable and apply the setting in opengl
397 void OGLRender::SetAlphaRef(uint32 dwAlpha)
399 if (m_dwAlpha != dwAlpha)
403 glAlphaFunc(GL_GEQUAL, (float)dwAlpha);
409 void OGLRender::ForceAlphaRef(uint32 dwAlpha)
412 float ref = dwAlpha/255.0f;
413 glAlphaFunc(GL_GEQUAL, ref);
415 #elif SDL_VIDEO_OPENGL_ES2
420 void OGLRender::SetFillMode(FillMode mode)
424 if( mode == RICE_FILLMODE_WINFRAME )
426 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
431 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
438 void OGLRender::SetCullMode(bool bCullFront, bool bCullBack)
440 CRender::SetCullMode(bCullFront, bCullBack);
441 if( bCullFront && bCullBack )
443 glCullFace(GL_FRONT_AND_BACK);
445 glEnable(GL_CULL_FACE);
448 else if( bCullFront )
450 glCullFace(GL_FRONT);
452 glEnable(GL_CULL_FACE);
459 glEnable(GL_CULL_FACE);
464 glDisable(GL_CULL_FACE);
469 bool OGLRender::SetCurrentTexture(int tile, CTexture *handler,uint32 dwTileWidth, uint32 dwTileHeight, TxtrCacheEntry *pTextureEntry)
471 RenderTexture &texture = g_textures[tile];
472 texture.pTextureEntry = pTextureEntry;
474 if( handler!= NULL && texture.m_lpsTexturePtr != handler->GetTexture() )
476 texture.m_pCTexture = handler;
477 texture.m_lpsTexturePtr = handler->GetTexture();
479 texture.m_dwTileWidth = dwTileWidth;
480 texture.m_dwTileHeight = dwTileHeight;
482 if( handler->m_bIsEnhancedTexture )
484 texture.m_fTexWidth = (float)pTextureEntry->pTexture->m_dwCreatedTextureWidth;
485 texture.m_fTexHeight = (float)pTextureEntry->pTexture->m_dwCreatedTextureHeight;
489 texture.m_fTexWidth = (float)handler->m_dwCreatedTextureWidth;
490 texture.m_fTexHeight = (float)handler->m_dwCreatedTextureHeight;
497 bool OGLRender::SetCurrentTexture(int tile, TxtrCacheEntry *pEntry)
499 if (pEntry != NULL && pEntry->pTexture != NULL)
501 SetCurrentTexture( tile, pEntry->pTexture, pEntry->ti.WidthToCreate, pEntry->ti.HeightToCreate, pEntry);
506 SetCurrentTexture( tile, NULL, 64, 64, NULL );
512 void OGLRender::SetAddressUAllStages(uint32 dwTile, TextureUVFlag dwFlag)
514 SetTextureUFlag(dwFlag, dwTile);
517 void OGLRender::SetAddressVAllStages(uint32 dwTile, TextureUVFlag dwFlag)
519 SetTextureVFlag(dwFlag, dwTile);
522 void OGLRender::SetTexWrapS(int unitno,GLuint flag)
529 DebuggerAppendMsg("Check me, unitno != 0 in base ogl");
532 if( m_curBoundTex[0] != mtex || mflag != flag )
534 mtex = m_curBoundTex[0];
536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, flag);
540 void OGLRender::SetTexWrapT(int unitno,GLuint flag)
544 if( m_curBoundTex[0] != mtex || mflag != flag )
546 mtex = m_curBoundTex[0];
548 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, flag);
553 void OGLRender::SetTextureUFlag(TextureUVFlag dwFlag, uint32 dwTile)
555 TileUFlags[dwTile] = dwFlag;
556 if( dwTile == gRSP.curTile ) // For basic OGL, only support the 1st texel
558 COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
561 EnableTexUnit(0,TRUE);
562 BindTexture(pTexture->m_dwTextureName, 0);
564 SetTexWrapS(0, OGLXUVFlagMaps[dwFlag].realFlag);
567 void OGLRender::SetTextureVFlag(TextureUVFlag dwFlag, uint32 dwTile)
569 TileVFlags[dwTile] = dwFlag;
570 if( dwTile == gRSP.curTile ) // For basic OGL, only support the 1st texel
572 COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
575 EnableTexUnit(0,TRUE);
576 BindTexture(pTexture->m_dwTextureName, 0);
578 SetTexWrapT(0, OGLXUVFlagMaps[dwFlag].realFlag);
582 // Basic render drawing functions
584 bool OGLRender::RenderTexRect()
586 glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
589 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
590 glDisable(GL_CULL_FACE);
593 float depth = -(g_texRectTVtx[3].z*2-1);
598 g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a,
599 g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a,
600 g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a,
601 g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a
605 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
606 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
607 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
608 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v
611 g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v,
612 g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
613 g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
614 g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v
617 GLfloat vertices[] = {
618 g_texRectTVtx[3].x, g_texRectTVtx[3].y, depth, 1,
619 g_texRectTVtx[2].x, g_texRectTVtx[2].y, depth, 1,
620 g_texRectTVtx[1].x, g_texRectTVtx[1].y, depth, 1,
621 g_texRectTVtx[0].x, g_texRectTVtx[0].y, depth, 1
624 if( m_bMultiTexture )
626 glClientActiveTexture( GL_TEXTURE1 );
627 glTexCoordPointer(2, GL_FLOAT, 0, &tex2);
628 glClientActiveTexture( GL_TEXTURE0 );
630 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
632 glColorPointer(4, GL_FLOAT,0, &colour );
633 glVertexPointer(4,GL_FLOAT, 0, &vertices);
634 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
636 glDrawArrays(GL_TRIANGLE_FAN,0,4);
639 //Restore old pointers
640 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
642 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
643 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
644 if( m_bMultiTexture )
646 glClientActiveTexture( GL_TEXTURE1 );
647 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
651 glBegin(GL_TRIANGLE_FAN);
653 glColor4f(g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a);
654 TexCoord(g_texRectTVtx[3]);
655 glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, depth);
657 glColor4f(g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a);
658 TexCoord(g_texRectTVtx[2]);
659 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, depth);
661 glColor4f(g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a);
662 TexCoord(g_texRectTVtx[1]);
663 glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, depth);
665 glColor4f(g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a);
666 TexCoord(g_texRectTVtx[0]);
667 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, depth);
673 #elif SDL_VIDEO_OPENGL_ES2
675 g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a,
676 g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a,
677 g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a,
678 g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a
682 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
683 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
684 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
685 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v
688 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
690 GLfloat vertices[] = {
691 -inv + g_texRectTVtx[3].x / w, inv - g_texRectTVtx[3].y / h, depth, 1,
692 -inv + g_texRectTVtx[2].x / w, inv - g_texRectTVtx[2].y / h, depth, 1,
693 -inv + g_texRectTVtx[1].x / w, inv - g_texRectTVtx[1].y / h, depth, 1,
694 -inv + g_texRectTVtx[0].x / w, inv - g_texRectTVtx[0].y / h, depth, 1
697 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_TRUE, 0, &colour );
698 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
699 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
701 glDrawArrays(GL_TRIANGLE_FAN,0,4);
704 //Restore old pointers
705 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
706 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
707 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
710 if( cullface ) glEnable(GL_CULL_FACE);
716 bool OGLRender::RenderFillRect(uint32 dwColor, float depth)
718 float a = (dwColor>>24)/255.0f;
719 float r = ((dwColor>>16)&0xFF)/255.0f;
720 float g = ((dwColor>>8)&0xFF)/255.0f;
721 float b = (dwColor&0xFF)/255.0f;
722 glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
725 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
726 glDisable(GL_CULL_FACE);
737 GLfloat vertices[] = {
738 m_fillRectVtx[0].x, m_fillRectVtx[1].y, depth, 1,
739 m_fillRectVtx[1].x, m_fillRectVtx[1].y, depth, 1,
740 m_fillRectVtx[1].x, m_fillRectVtx[0].y, depth, 1,
741 m_fillRectVtx[0].x, m_fillRectVtx[0].y, depth, 1
744 glColorPointer(4, GL_FLOAT, 0, &colour );
745 glVertexPointer(4,GL_FLOAT, 0,&vertices);
746 if( m_bMultiTexture ) {
747 if (m_texUnitEnabled[1])
749 glClientActiveTexture( GL_TEXTURE1 );
750 glActiveTexture( GL_TEXTURE1 );
751 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
752 glDisable(GL_TEXTURE_2D);
755 if (m_texUnitEnabled[0]) {
756 glClientActiveTexture( GL_TEXTURE0 );
757 glActiveTexture( GL_TEXTURE0 );
758 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
759 glDisable(GL_TEXTURE_2D);
763 glDrawArrays(GL_TRIANGLE_FAN,0,4);
765 //Restore old pointers
766 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
767 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
768 if (m_texUnitEnabled[0]) {
769 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
770 glEnable(GL_TEXTURE_2D);
772 if( m_bMultiTexture ) {
773 glClientActiveTexture( GL_TEXTURE1 );
774 glActiveTexture( GL_TEXTURE1 );
775 if (m_texUnitEnabled[1])
777 glEnable(GL_TEXTURE_2D);
778 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
780 glActiveTexture( GL_TEXTURE0 );
784 glBegin(GL_TRIANGLE_FAN);
786 glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[1].y, depth, 1);
787 glVertex4f(m_fillRectVtx[1].x, m_fillRectVtx[1].y, depth, 1);
788 glVertex4f(m_fillRectVtx[1].x, m_fillRectVtx[0].y, depth, 1);
789 glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[0].y, depth, 1);
793 #elif SDL_VIDEO_OPENGL_ES2
801 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
803 GLfloat vertices[] = {
804 -inv + m_fillRectVtx[0].x / w, inv - m_fillRectVtx[1].y / h, depth, 1,
805 -inv + m_fillRectVtx[1].x / w, inv - m_fillRectVtx[1].y / h, depth, 1,
806 -inv + m_fillRectVtx[1].x / w, inv - m_fillRectVtx[0].y / h, depth, 1,
807 -inv + m_fillRectVtx[0].x / w, inv - m_fillRectVtx[0].y / h, depth, 1
810 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
811 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
812 glDisableVertexAttribArray(VS_TEXCOORD0);
814 glDrawArrays(GL_TRIANGLE_FAN,0,4);
817 //Restore old pointers
818 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
819 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
820 glEnableVertexAttribArray(VS_TEXCOORD0);
824 if( cullface ) glEnable(GL_CULL_FACE);
830 bool OGLRender::RenderLine3D()
833 ApplyZBias(0); // disable z offsets
837 m_line3DVtx[1].r,m_line3DVtx[1].g,m_line3DVtx[1].b,m_line3DVtx[1].a,
838 m_line3DVtx[1].r,m_line3DVtx[1].g,m_line3DVtx[1].b,m_line3DVtx[1].a,
839 m_line3DVtx[0].r,m_line3DVtx[0].g,m_line3DVtx[0].b,m_line3DVtx[0].a,
840 m_line3DVtx[0].r,m_line3DVtx[0].g,m_line3DVtx[0].b,m_line3DVtx[0].a};
842 GLfloat vertices[] = {
843 m_line3DVector[3].x, m_line3DVector[3].y, -m_line3DVtx[1].z, 1,
844 m_line3DVector[2].x, m_line3DVector[2].y, -m_line3DVtx[0].z, 1,
845 m_line3DVector[1].x, m_line3DVector[1].y, -m_line3DVtx[1].z, 1,
846 m_line3DVector[0].x, m_line3DVector[0].y, -m_line3DVtx[0].z, 1
849 glColorPointer(4, GL_FLOAT, 0, &colour );
850 glVertexPointer(4,GL_FLOAT, 0,&vertices);
851 if( m_bMultiTexture )
853 glClientActiveTexture( GL_TEXTURE1 );
854 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
855 glClientActiveTexture( GL_TEXTURE0 );
857 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
859 glDrawArrays(GL_TRIANGLE_FAN,0,4);
861 //Restore old pointers
862 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
863 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
864 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
865 if( m_bMultiTexture )
867 glClientActiveTexture( GL_TEXTURE1 );
868 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
871 glBegin(GL_TRIANGLE_FAN);
873 glColor4f(m_line3DVtx[1].r, m_line3DVtx[1].g, m_line3DVtx[1].b, m_line3DVtx[1].a);
874 glVertex3f(m_line3DVector[3].x, m_line3DVector[3].y, -m_line3DVtx[1].z);
875 glVertex3f(m_line3DVector[2].x, m_line3DVector[2].y, -m_line3DVtx[0].z);
877 glColor4ub(m_line3DVtx[0].r, m_line3DVtx[0].g, m_line3DVtx[0].b, m_line3DVtx[0].a);
878 glVertex3f(m_line3DVector[1].x, m_line3DVector[1].y, -m_line3DVtx[1].z);
879 glVertex3f(m_line3DVector[0].x, m_line3DVector[0].y, -m_line3DVtx[0].z);
885 ApplyZBias(m_dwZBias); // set Z offset back to previous value
891 extern FiddledVtx * g_pVtxBase;
893 // This is so weired that I can not do vertex transform by myself. I have to use
894 // OpenGL internal transform
895 bool OGLRender::RenderFlushTris()
897 if( !m_bSupportFogCoordExt )
898 SetFogFlagForNegativeW();
901 if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
907 ApplyZBias(m_dwZBias); // set the bias factors
909 glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW, false);
912 // if (options.bOGLVertexClipper == FALSE )
914 glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_SHORT, g_vtxIndex );
919 //ClipVertexesOpenGL();
922 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5Clipped[0][0]) );
923 glEnableClientState( GL_VERTEX_ARRAY );
925 pglClientActiveTextureARB( GL_TEXTURE0_ARB );
926 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[0].u) );
927 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
929 pglClientActiveTextureARB( GL_TEXTURE1_ARB );
930 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[1].u) );
931 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
933 glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_SHORT, g_vtxIndex );
936 pglClientActiveTextureARB( GL_TEXTURE0_ARB );
937 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
938 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
940 pglClientActiveTextureARB( GL_TEXTURE1_ARB );
941 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
942 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
944 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
945 glEnableClientState( GL_VERTEX_ARRAY );
949 if( !m_bSupportFogCoordExt )
953 if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
961 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)
963 if( status.bVIOriginIsUpdated == true && currentRomOptions.screenUpdateSetting==SCREEN_UPDATE_AT_1ST_PRIMITIVE )
965 status.bVIOriginIsUpdated=false;
966 CGraphicsContext::Get()->UpdateFrame();
967 DEBUGGER_PAUSE_AND_DUMP_NO_UPDATE(NEXT_SET_CIMG,{DebuggerAppendMsg("Screen Update at 1st Simple2DTexture");});
970 StartDrawSimple2DTexture(x0, y0, x1, y1, u0, v0, u1, v1, dif, spe, z, rhw);
972 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
973 glDisable(GL_CULL_FACE);
976 glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
979 float a = (g_texRectTVtx[0].dcDiffuse >>24)/255.0f;
980 float r = ((g_texRectTVtx[0].dcDiffuse>>16)&0xFF)/255.0f;
981 float g = ((g_texRectTVtx[0].dcDiffuse>>8)&0xFF)/255.0f;
982 float b = (g_texRectTVtx[0].dcDiffuse&0xFF)/255.0f;
996 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
997 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
998 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
999 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1000 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1001 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v
1005 g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
1006 g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
1007 g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
1008 g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
1009 g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
1010 g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v
1013 GLfloat vertices[] = {
1014 g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
1015 g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z, 1,
1016 g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
1017 g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
1018 g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
1019 g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z, 1
1022 glColorPointer(4, GL_FLOAT, 0, &colour );
1023 glVertexPointer(4,GL_FLOAT, 0,&vertices);
1024 if( m_bMultiTexture )
1026 glClientActiveTexture( GL_TEXTURE1 );
1027 glTexCoordPointer(2, GL_FLOAT, 0, &tex2);
1028 glClientActiveTexture( GL_TEXTURE0 );
1030 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
1031 glDrawArrays(GL_TRIANGLES,0,6);
1032 //Restore old pointers
1033 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1034 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
1035 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
1036 if( m_bMultiTexture )
1038 glClientActiveTexture( GL_TEXTURE1 );
1039 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
1042 glBegin(GL_TRIANGLES);
1046 OGLRender::TexCoord(g_texRectTVtx[0]);
1047 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
1049 OGLRender::TexCoord(g_texRectTVtx[1]);
1050 glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
1052 OGLRender::TexCoord(g_texRectTVtx[2]);
1053 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
1055 OGLRender::TexCoord(g_texRectTVtx[0]);
1056 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
1058 OGLRender::TexCoord(g_texRectTVtx[2]);
1059 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
1061 OGLRender::TexCoord(g_texRectTVtx[3]);
1062 glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
1065 OPENGL_CHECK_ERRORS;
1067 #elif SDL_VIDEO_OPENGL_ES2
1069 GLfloat colour[] = {
1079 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1080 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
1081 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1083 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1084 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1085 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
1088 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
1090 GLfloat vertices[] = {
1091 -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
1092 -inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
1093 -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
1095 -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
1096 -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
1097 -inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
1100 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
1101 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
1102 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
1103 OPENGL_CHECK_ERRORS;
1104 glDrawArrays(GL_TRIANGLES,0,6);
1105 OPENGL_CHECK_ERRORS;
1107 //Restore old pointers
1108 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1109 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
1110 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
1114 if( cullface ) glEnable(GL_CULL_FACE);
1115 OPENGL_CHECK_ERRORS;
1118 void OGLRender::DrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColor, float depth, float rhw)
1120 StartDrawSimpleRect(nX0, nY0, nX1, nY1, dwColor, depth, rhw);
1122 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
1123 glDisable(GL_CULL_FACE);
1124 OPENGL_CHECK_ERRORS;
1126 float a = (dwColor>>24)/255.0f;
1127 float r = ((dwColor>>16)&0xFF)/255.0f;
1128 float g = ((dwColor>>8)&0xFF)/255.0f;
1129 float b = (dwColor&0xFF)/255.0f;
1131 #if SDL_VIDEO_OPENGL
1134 GLfloat colour[] = {
1140 GLfloat vertices[] = {
1141 m_simpleRectVtx[1].x, m_simpleRectVtx[0].y, -depth, 1,
1142 m_simpleRectVtx[1].x, m_simpleRectVtx[1].y, -depth, 1,
1143 m_simpleRectVtx[0].x, m_simpleRectVtx[1].y, -depth, 1,
1144 m_simpleRectVtx[0].x, m_simpleRectVtx[0].y, -depth, 1
1147 glColorPointer(4, GL_FLOAT, 0, &colour );
1148 glVertexPointer(4,GL_FLOAT, 0,&vertices);
1149 if( m_bMultiTexture )
1151 glClientActiveTexture( GL_TEXTURE1 );
1152 glActiveTexture( GL_TEXTURE1 );
1153 glDisable(GL_TEXTURE_2D);
1154 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1155 glClientActiveTexture( GL_TEXTURE0 );
1157 glActiveTexture( GL_TEXTURE0 );
1158 glDisable(GL_TEXTURE_2D);
1160 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1161 OPENGL_CHECK_ERRORS;
1163 glDrawArrays(GL_TRIANGLE_FAN,0,4);
1164 OPENGL_CHECK_ERRORS;
1165 //Restore old pointers
1166 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1167 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1168 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
1169 glEnable(GL_TEXTURE_2D);
1170 if( m_bMultiTexture )
1172 glActiveTexture( GL_TEXTURE1 );
1173 glEnable(GL_TEXTURE_2D);
1174 glClientActiveTexture( GL_TEXTURE1 );
1175 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1178 glBegin(GL_TRIANGLE_FAN);
1181 glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[0].y, -depth);
1182 glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[1].y, -depth);
1183 glVertex3f(m_simpleRectVtx[0].x, m_simpleRectVtx[1].y, -depth);
1184 glVertex3f(m_simpleRectVtx[0].x, m_simpleRectVtx[0].y, -depth);
1188 OPENGL_CHECK_ERRORS;
1190 #elif SDL_VIDEO_OPENGL_ES2
1192 GLfloat colour[] = {
1197 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
1199 GLfloat vertices[] = {
1200 -inv + m_simpleRectVtx[1].x / w, inv - m_simpleRectVtx[0].y / h, -depth, 1,
1201 -inv + m_simpleRectVtx[1].x / w, inv - m_simpleRectVtx[1].y / h, -depth, 1,
1202 -inv + m_simpleRectVtx[0].x / w, inv - m_simpleRectVtx[1].y / h, -depth, 1,
1203 -inv + m_simpleRectVtx[0].x / w, inv - m_simpleRectVtx[0].y / h, -depth, 1
1206 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
1207 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
1208 glDisableVertexAttribArray(VS_TEXCOORD0);
1209 OPENGL_CHECK_ERRORS;
1210 glDrawArrays(GL_TRIANGLE_FAN,0,4);
1211 OPENGL_CHECK_ERRORS;
1213 //Restore old pointers
1214 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1215 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
1216 glEnableVertexAttribArray(VS_TEXCOORD0);
1220 if( cullface ) glEnable(GL_CULL_FACE);
1221 OPENGL_CHECK_ERRORS;
1224 void OGLRender::InitCombinerBlenderForSimpleRectDraw(uint32 tile)
1226 //glEnable(GL_CULL_FACE);
1227 EnableTexUnit(0,FALSE);
1228 OPENGL_CHECK_ERRORS;
1230 OPENGL_CHECK_ERRORS;
1231 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1232 OPENGL_CHECK_ERRORS;
1233 //glEnable(GL_ALPHA_TEST);
1236 COLOR OGLRender::PostProcessDiffuseColor(COLOR curDiffuseColor)
1238 uint32 color = curDiffuseColor;
1239 uint32 colorflag = m_pColorCombiner->m_pDecodedMux->m_dwShadeColorChannelFlag;
1240 uint32 alphaflag = m_pColorCombiner->m_pDecodedMux->m_dwShadeAlphaChannelFlag;
1241 if( colorflag+alphaflag != MUX_0 )
1243 if( (colorflag & 0xFFFFFF00) == 0 && (alphaflag & 0xFFFFFF00) == 0 )
1245 color = (m_pColorCombiner->GetConstFactor(colorflag, alphaflag, curDiffuseColor));
1248 color = (CalculateConstFactor(colorflag, alphaflag, curDiffuseColor));
1251 //return (color<<8)|(color>>24);
1255 COLOR OGLRender::PostProcessSpecularColor()
1260 void OGLRender::SetViewportRender()
1262 glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW);
1263 OPENGL_CHECK_ERRORS;
1266 void OGLRender::RenderReset()
1268 CRender::RenderReset();
1270 glMatrixMode(GL_PROJECTION);
1271 OPENGL_CHECK_ERRORS;
1273 OPENGL_CHECK_ERRORS;
1274 glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
1275 OPENGL_CHECK_ERRORS;
1278 glMatrixMode(GL_MODELVIEW);
1279 OPENGL_CHECK_ERRORS;
1281 OPENGL_CHECK_ERRORS;
1284 void OGLRender::SetAlphaTestEnable(BOOL bAlphaTestEnable)
1287 if( bAlphaTestEnable && debuggerEnableAlphaTest )
1289 if( bAlphaTestEnable )
1291 #if SDL_VIDEO_OPENGL
1292 glEnable(GL_ALPHA_TEST);
1294 glDisable(GL_ALPHA_TEST);
1295 #elif SDL_VIDEO_OPENGL_ES2
1297 COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
1298 frag->m_AlphaRef = m_dwAlpha / 255.0f;
1302 COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
1303 frag->m_AlphaRef = 0.0f;
1306 OPENGL_CHECK_ERRORS;
1309 void OGLRender::BindTexture(GLuint texture, int unitno)
1314 DebuggerAppendMsg("Check me, base ogl bind texture, unit no != 0");
1317 if( m_curBoundTex[0] != texture )
1319 glBindTexture(GL_TEXTURE_2D,texture);
1320 OPENGL_CHECK_ERRORS;
1321 m_curBoundTex[0] = texture;
1325 void OGLRender::DisBindTexture(GLuint texture, int unitno)
1327 //EnableTexUnit(0,FALSE);
1328 //glBindTexture(GL_TEXTURE_2D, 0); //Not to bind any texture
1331 void OGLRender::EnableTexUnit(int unitno, BOOL flag)
1336 DebuggerAppendMsg("Check me, in the base ogl render, unitno!=0");
1339 if( m_texUnitEnabled[0] != flag ) //strange, why 0 and not unitno?
1341 m_texUnitEnabled[0] = flag;
1342 #if SDL_VIDEO_OPENGL
1343 if( flag == TRUE ) {
1344 // pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1345 glEnable(GL_TEXTURE_2D);
1347 // pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1348 glDisable(GL_TEXTURE_2D);
1350 /* if (m_bMultiTexture)
1351 pglActiveTexture(GL_TEXTURE1_ARB);*/
1352 #elif SDL_VIDEO_OPENGL_ES2
1355 pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1356 OPENGL_CHECK_ERRORS;
1357 glBindTexture(GL_TEXTURE_2D,m_curBoundTex[unitno]);
1361 pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1362 OPENGL_CHECK_ERRORS;
1363 glEnable(GL_BLEND); //Need blend for transparent disabled texture
1364 glBindTexture(GL_TEXTURE_2D,disabledTextureID);
1367 OPENGL_CHECK_ERRORS;
1371 void OGLRender::TexCoord2f(float u, float v)
1374 printf("*SEB* TexCoord2f(%f, %f)\n", u, v);
1380 void OGLRender::TexCoord(TLITVERTEX &vtxInfo)
1383 printf("*SEB* TexCoord(%f, %f)\n", vtxInfo.tcord[0].u, vtxInfo.tcord[0].v);
1385 glTexCoord2f(vtxInfo.tcord[0].u, vtxInfo.tcord[0].v);
1389 void OGLRender::UpdateScissor()
1391 if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
1394 uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
1395 uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
1396 glEnable(GL_SCISSOR_TEST);
1397 OPENGL_CHECK_ERRORS;
1398 glScissor(windowSetting.uDisplayX, windowSetting.uDisplayY+int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
1399 int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
1400 OPENGL_CHECK_ERRORS;
1404 UpdateScissorWithClipRatio();
1408 void OGLRender::ApplyRDPScissor(bool force)
1410 if( !force && status.curScissor == RDP_SCISSOR ) return;
1412 if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
1415 uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
1416 uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
1417 glEnable(GL_SCISSOR_TEST);
1418 OPENGL_CHECK_ERRORS;
1419 glScissor(windowSetting.uDisplayX, windowSetting.uDisplayY+int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
1420 int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
1421 OPENGL_CHECK_ERRORS;
1425 glScissor(windowSetting.uDisplayX+int(gRDP.scissor.left*windowSetting.fMultX), windowSetting.uDisplayY+int((windowSetting.uViHeight-gRDP.scissor.bottom)*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
1426 int((gRDP.scissor.right-gRDP.scissor.left)*windowSetting.fMultX), int((gRDP.scissor.bottom-gRDP.scissor.top)*windowSetting.fMultY ));
1427 OPENGL_CHECK_ERRORS;
1430 status.curScissor = RDP_SCISSOR;
1433 void OGLRender::ApplyScissorWithClipRatio(bool force)
1435 if( !force && status.curScissor == RSP_SCISSOR ) return;
1437 glEnable(GL_SCISSOR_TEST);
1438 OPENGL_CHECK_ERRORS;
1439 glScissor(windowSetting.uDisplayX+windowSetting.clipping.left, windowSetting.uDisplayY+int((windowSetting.uViHeight-gRSP.real_clip_scissor_bottom)*windowSetting.fMultY)+windowSetting.statusBarHeightToUse,
1440 windowSetting.clipping.width, windowSetting.clipping.height);
1441 OPENGL_CHECK_ERRORS;
1443 status.curScissor = RSP_SCISSOR;
1446 void OGLRender::SetFogMinMax(float fMin, float fMax)
1448 #if SDL_VIDEO_OPENGL
1449 glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
1450 OPENGL_CHECK_ERRORS;
1451 glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
1452 OPENGL_CHECK_ERRORS;
1453 #elif SDL_VIDEO_OPENGL_ES2
1454 ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
1455 OPENGL_CHECK_ERRORS;
1459 void OGLRender::TurnFogOnOff(bool flag)
1461 #if SDL_VIDEO_OPENGL
1466 OPENGL_CHECK_ERRORS;
1467 #elif SDL_VIDEO_OPENGL_ES2
1468 ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(flag);
1469 OPENGL_CHECK_ERRORS;
1473 void OGLRender::SetFogEnable(bool bEnable)
1475 DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != (bEnable==TRUE) && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
1477 gRSP.bFogEnabled = bEnable&&(options.fogMethod == 1);
1480 if(options.fogMethod == 2)
1482 gRSP.bFogEnabled = true;
1485 #if SDL_VIDEO_OPENGL
1486 if( gRSP.bFogEnabled )
1488 //TRACE2("Enable fog, min=%f, max=%f",gRSPfFogMin,gRSPfFogMax );
1489 glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
1490 OPENGL_CHECK_ERRORS;
1491 glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
1492 OPENGL_CHECK_ERRORS;
1493 glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
1494 OPENGL_CHECK_ERRORS;
1496 OPENGL_CHECK_ERRORS;
1501 OPENGL_CHECK_ERRORS;
1503 #elif SDL_VIDEO_OPENGL_ES2
1504 ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
1505 OPENGL_CHECK_ERRORS;
1509 void OGLRender::SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
1511 gRDP.fogColor = COLOR_RGBA(r, g, b, a);
1512 gRDP.fvFogColor[0] = r/255.0f; //r
1513 gRDP.fvFogColor[1] = g/255.0f; //g
1514 gRDP.fvFogColor[2] = b/255.0f; //b
1515 gRDP.fvFogColor[3] = a/255.0f; //a
1516 #if SDL_VIDEO_OPENGL
1517 glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
1519 OPENGL_CHECK_ERRORS;
1522 void OGLRender::DisableMultiTexture()
1524 pglActiveTexture(GL_TEXTURE1_ARB);
1525 OPENGL_CHECK_ERRORS;
1526 EnableTexUnit(1,FALSE);
1527 pglActiveTexture(GL_TEXTURE0_ARB);
1528 OPENGL_CHECK_ERRORS;
1529 EnableTexUnit(0,FALSE);
1530 pglActiveTexture(GL_TEXTURE0_ARB);
1531 OPENGL_CHECK_ERRORS;
1532 EnableTexUnit(0,TRUE);
1535 void OGLRender::EndRendering(void)
1537 #if SDL_VIDEO_OPENGL
1539 OPENGL_CHECK_ERRORS;
1541 if( CRender::gRenderReferenceCount > 0 )
1542 CRender::gRenderReferenceCount--;
1545 void OGLRender::glViewportWrapper(GLint x, GLint y, GLsizei width, GLsizei height, bool flag)
1547 static GLint mx=0,my=0;
1548 static GLsizei m_width=0, m_height=0;
1549 static bool mflag=true;
1551 x+=windowSetting.uDisplayX;
1552 y+=windowSetting.uDisplayY;
1554 if( x!=mx || y!=my || width!=m_width || height!=m_height || mflag!=flag)
1561 glMatrixMode(GL_PROJECTION);
1562 OPENGL_CHECK_ERRORS;
1564 OPENGL_CHECK_ERRORS;
1565 if( flag ) glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
1566 OPENGL_CHECK_ERRORS;
1567 glViewport(x,y,width,height);
1568 //printf("glViewport(%i, %i, %i, %i)\n", x, y, width, height);
1569 OPENGL_CHECK_ERRORS;