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 //if (m_texUnitEnabled[1])
628 glTexCoordPointer(2, GL_FLOAT, 0, &tex2);
630 glDisableClientState(GL_TEXTURE_COORD_ARRAY);*/
631 glClientActiveTexture( GL_TEXTURE0 );
633 //if (m_texUnitEnabled[0])
634 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
636 glDisableClientState(GL_TEXTURE_COORD_ARRAY);*/
638 glColorPointer(4, GL_FLOAT,0, &colour );
639 glVertexPointer(4,GL_FLOAT, 0, &vertices);
640 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
642 glDrawArrays(GL_TRIANGLE_FAN,0,4);
645 //Restore old pointers
646 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
648 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
649 // if (m_texUnitEnabled[0])
650 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
652 glEnableClientState(GL_TEXTURE_COORD_ARRAY);*/
653 if( m_bMultiTexture )
655 glClientActiveTexture( GL_TEXTURE1 );
656 // if (m_texUnitEnabled[1])
657 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
659 glEnableClientState( GL_TEXTURE_COORD_ARRAY );*/
663 glBegin(GL_TRIANGLE_FAN);
665 glColor4f(g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a);
666 TexCoord(g_texRectTVtx[3]);
667 glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, depth);
669 glColor4f(g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a);
670 TexCoord(g_texRectTVtx[2]);
671 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, depth);
673 glColor4f(g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a);
674 TexCoord(g_texRectTVtx[1]);
675 glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, depth);
677 glColor4f(g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a);
678 TexCoord(g_texRectTVtx[0]);
679 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, depth);
685 #elif SDL_VIDEO_OPENGL_ES2
687 g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a,
688 g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a,
689 g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a,
690 g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a
694 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
695 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
696 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
697 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v
700 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
702 GLfloat vertices[] = {
703 -inv + g_texRectTVtx[3].x / w, inv - g_texRectTVtx[3].y / h, depth, 1,
704 -inv + g_texRectTVtx[2].x / w, inv - g_texRectTVtx[2].y / h, depth, 1,
705 -inv + g_texRectTVtx[1].x / w, inv - g_texRectTVtx[1].y / h, depth, 1,
706 -inv + g_texRectTVtx[0].x / w, inv - g_texRectTVtx[0].y / h, depth, 1
709 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_TRUE, 0, &colour );
710 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
711 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
713 glDrawArrays(GL_TRIANGLE_FAN,0,4);
716 //Restore old pointers
717 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
718 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
719 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
722 if( cullface ) glEnable(GL_CULL_FACE);
728 bool OGLRender::RenderFillRect(uint32 dwColor, float depth)
730 float a = (dwColor>>24)/255.0f;
731 float r = ((dwColor>>16)&0xFF)/255.0f;
732 float g = ((dwColor>>8)&0xFF)/255.0f;
733 float b = (dwColor&0xFF)/255.0f;
734 glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
737 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
738 glDisable(GL_CULL_FACE);
749 GLfloat vertices[] = {
750 m_fillRectVtx[0].x, m_fillRectVtx[1].y, depth, 1,
751 m_fillRectVtx[1].x, m_fillRectVtx[1].y, depth, 1,
752 m_fillRectVtx[1].x, m_fillRectVtx[0].y, depth, 1,
753 m_fillRectVtx[0].x, m_fillRectVtx[0].y, depth, 1
756 glColorPointer(4, GL_FLOAT, 0, &colour );
757 glVertexPointer(4,GL_FLOAT, 0,&vertices);
758 if( m_bMultiTexture ) {
759 if (m_texUnitEnabled[1])
761 glClientActiveTexture( GL_TEXTURE1 );
762 glActiveTexture( GL_TEXTURE1 );
763 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
764 glDisable(GL_TEXTURE_2D);
767 if (m_texUnitEnabled[0]) {
768 glClientActiveTexture( GL_TEXTURE0 );
769 glActiveTexture( GL_TEXTURE0 );
770 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
771 glDisable(GL_TEXTURE_2D);
775 glDrawArrays(GL_TRIANGLE_FAN,0,4);
777 //Restore old pointers
778 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
779 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
780 if (m_texUnitEnabled[0]) {
781 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
782 glEnable(GL_TEXTURE_2D);
784 if( m_bMultiTexture ) {
785 glClientActiveTexture( GL_TEXTURE1 );
786 glActiveTexture( GL_TEXTURE1 );
787 if (m_texUnitEnabled[1])
789 glEnable(GL_TEXTURE_2D);
790 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
792 glActiveTexture( GL_TEXTURE0 );
796 glBegin(GL_TRIANGLE_FAN);
798 glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[1].y, depth, 1);
799 glVertex4f(m_fillRectVtx[1].x, m_fillRectVtx[1].y, depth, 1);
800 glVertex4f(m_fillRectVtx[1].x, m_fillRectVtx[0].y, depth, 1);
801 glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[0].y, depth, 1);
805 #elif SDL_VIDEO_OPENGL_ES2
813 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
815 GLfloat vertices[] = {
816 -inv + m_fillRectVtx[0].x / w, inv - m_fillRectVtx[1].y / h, depth, 1,
817 -inv + m_fillRectVtx[1].x / w, inv - m_fillRectVtx[1].y / h, depth, 1,
818 -inv + m_fillRectVtx[1].x / w, inv - m_fillRectVtx[0].y / h, depth, 1,
819 -inv + m_fillRectVtx[0].x / w, inv - m_fillRectVtx[0].y / h, depth, 1
822 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
823 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
824 glDisableVertexAttribArray(VS_TEXCOORD0);
826 glDrawArrays(GL_TRIANGLE_FAN,0,4);
829 //Restore old pointers
830 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
831 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
832 glEnableVertexAttribArray(VS_TEXCOORD0);
836 if( cullface ) glEnable(GL_CULL_FACE);
842 bool OGLRender::RenderLine3D()
845 ApplyZBias(0); // disable z offsets
849 m_line3DVtx[1].r,m_line3DVtx[1].g,m_line3DVtx[1].b,m_line3DVtx[1].a,
850 m_line3DVtx[1].r,m_line3DVtx[1].g,m_line3DVtx[1].b,m_line3DVtx[1].a,
851 m_line3DVtx[0].r,m_line3DVtx[0].g,m_line3DVtx[0].b,m_line3DVtx[0].a,
852 m_line3DVtx[0].r,m_line3DVtx[0].g,m_line3DVtx[0].b,m_line3DVtx[0].a};
854 GLfloat vertices[] = {
855 m_line3DVector[3].x, m_line3DVector[3].y, -m_line3DVtx[1].z, 1,
856 m_line3DVector[2].x, m_line3DVector[2].y, -m_line3DVtx[0].z, 1,
857 m_line3DVector[1].x, m_line3DVector[1].y, -m_line3DVtx[1].z, 1,
858 m_line3DVector[0].x, m_line3DVector[0].y, -m_line3DVtx[0].z, 1
861 glColorPointer(4, GL_FLOAT, 0, &colour );
862 glVertexPointer(4,GL_FLOAT, 0,&vertices);
863 if( m_bMultiTexture )
865 glClientActiveTexture( GL_TEXTURE1 );
866 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
867 glClientActiveTexture( GL_TEXTURE0 );
869 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
871 glDrawArrays(GL_TRIANGLE_FAN,0,4);
873 //Restore old pointers
874 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
875 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
876 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
877 if( m_bMultiTexture )
879 glClientActiveTexture( GL_TEXTURE1 );
880 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
883 glBegin(GL_TRIANGLE_FAN);
885 glColor4f(m_line3DVtx[1].r, m_line3DVtx[1].g, m_line3DVtx[1].b, m_line3DVtx[1].a);
886 glVertex3f(m_line3DVector[3].x, m_line3DVector[3].y, -m_line3DVtx[1].z);
887 glVertex3f(m_line3DVector[2].x, m_line3DVector[2].y, -m_line3DVtx[0].z);
889 glColor4ub(m_line3DVtx[0].r, m_line3DVtx[0].g, m_line3DVtx[0].b, m_line3DVtx[0].a);
890 glVertex3f(m_line3DVector[1].x, m_line3DVector[1].y, -m_line3DVtx[1].z);
891 glVertex3f(m_line3DVector[0].x, m_line3DVector[0].y, -m_line3DVtx[0].z);
897 ApplyZBias(m_dwZBias); // set Z offset back to previous value
903 extern FiddledVtx * g_pVtxBase;
905 // This is so weired that I can not do vertex transform by myself. I have to use
906 // OpenGL internal transform
907 bool OGLRender::RenderFlushTris()
909 if( !m_bSupportFogCoordExt )
910 SetFogFlagForNegativeW();
913 if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
919 ApplyZBias(m_dwZBias); // set the bias factors
921 glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW, false);
924 // if (options.bOGLVertexClipper == FALSE )
926 glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_SHORT, g_vtxIndex );
931 //ClipVertexesOpenGL();
934 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5Clipped[0][0]) );
935 glEnableClientState( GL_VERTEX_ARRAY );
937 pglClientActiveTextureARB( GL_TEXTURE0_ARB );
938 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[0].u) );
939 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
941 pglClientActiveTextureARB( GL_TEXTURE1_ARB );
942 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_clippedVtxBuffer[0].tcord[1].u) );
943 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
945 glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_SHORT, g_vtxIndex );
948 pglClientActiveTextureARB( GL_TEXTURE0_ARB );
949 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
950 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
952 pglClientActiveTextureARB( GL_TEXTURE1_ARB );
953 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
954 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
956 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
957 glEnableClientState( GL_VERTEX_ARRAY );
961 if( !m_bSupportFogCoordExt )
965 if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
973 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)
975 if( status.bVIOriginIsUpdated == true && currentRomOptions.screenUpdateSetting==SCREEN_UPDATE_AT_1ST_PRIMITIVE )
977 status.bVIOriginIsUpdated=false;
978 CGraphicsContext::Get()->UpdateFrame();
979 DEBUGGER_PAUSE_AND_DUMP_NO_UPDATE(NEXT_SET_CIMG,{DebuggerAppendMsg("Screen Update at 1st Simple2DTexture");});
982 StartDrawSimple2DTexture(x0, y0, x1, y1, u0, v0, u1, v1, dif, spe, z, rhw);
984 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
985 glDisable(GL_CULL_FACE);
988 glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
991 float a = (g_texRectTVtx[0].dcDiffuse >>24)/255.0f;
992 float r = ((g_texRectTVtx[0].dcDiffuse>>16)&0xFF)/255.0f;
993 float g = ((g_texRectTVtx[0].dcDiffuse>>8)&0xFF)/255.0f;
994 float b = (g_texRectTVtx[0].dcDiffuse&0xFF)/255.0f;
1008 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1009 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
1010 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1011 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1012 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1013 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v
1016 GLfloat vertices[] = {
1017 g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
1018 g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z, 1,
1019 g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
1020 g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
1021 g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
1022 g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z, 1
1025 glColorPointer(4, GL_FLOAT, 0, &colour );
1026 glVertexPointer(4,GL_FLOAT, 0,&vertices);
1027 if( m_bMultiTexture )
1029 glClientActiveTexture( GL_TEXTURE1 );
1030 // if (m_texUnitEnabled[1])
1031 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
1033 glDisableClientState( GL_TEXTURE_COORD_ARRAY );*/
1034 glClientActiveTexture( GL_TEXTURE0 );
1036 // if (m_texUnitEnabled[0])
1037 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
1039 glDisableClientState( GL_TEXTURE_COORD_ARRAY );*/
1040 glDrawArrays(GL_TRIANGLES,0,6);
1041 //Restore old pointers
1042 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1043 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
1044 // if (m_texUnitEnabled[1])
1045 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
1047 glEnableClientState( GL_TEXTURE_COORD_ARRAY );*/
1048 if( m_bMultiTexture )
1050 glClientActiveTexture( GL_TEXTURE1 );
1051 // if (m_texUnitEnabled[1])
1052 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
1054 glEnableClientState( GL_TEXTURE_COORD_ARRAY );*/
1057 glBegin(GL_TRIANGLES);
1061 OGLRender::TexCoord(g_texRectTVtx[0]);
1062 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
1064 OGLRender::TexCoord(g_texRectTVtx[1]);
1065 glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
1067 OGLRender::TexCoord(g_texRectTVtx[2]);
1068 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
1070 OGLRender::TexCoord(g_texRectTVtx[0]);
1071 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
1073 OGLRender::TexCoord(g_texRectTVtx[2]);
1074 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
1076 OGLRender::TexCoord(g_texRectTVtx[3]);
1077 glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
1080 OPENGL_CHECK_ERRORS;
1082 #elif SDL_VIDEO_OPENGL_ES2
1084 GLfloat colour[] = {
1094 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1095 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
1096 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1098 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
1099 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
1100 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
1103 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
1105 GLfloat vertices[] = {
1106 -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
1107 -inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
1108 -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
1110 -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
1111 -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
1112 -inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
1115 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
1116 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
1117 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
1118 OPENGL_CHECK_ERRORS;
1119 glDrawArrays(GL_TRIANGLES,0,6);
1120 OPENGL_CHECK_ERRORS;
1122 //Restore old pointers
1123 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1124 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
1125 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
1129 if( cullface ) glEnable(GL_CULL_FACE);
1130 OPENGL_CHECK_ERRORS;
1133 void OGLRender::DrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColor, float depth, float rhw)
1135 StartDrawSimpleRect(nX0, nY0, nX1, nY1, dwColor, depth, rhw);
1137 GLboolean cullface = glIsEnabled(GL_CULL_FACE);
1138 glDisable(GL_CULL_FACE);
1139 OPENGL_CHECK_ERRORS;
1141 float a = (dwColor>>24)/255.0f;
1142 float r = ((dwColor>>16)&0xFF)/255.0f;
1143 float g = ((dwColor>>8)&0xFF)/255.0f;
1144 float b = (dwColor&0xFF)/255.0f;
1146 #if SDL_VIDEO_OPENGL
1149 GLfloat colour[] = {
1155 GLfloat vertices[] = {
1156 m_simpleRectVtx[1].x, m_simpleRectVtx[0].y, -depth, 1,
1157 m_simpleRectVtx[1].x, m_simpleRectVtx[1].y, -depth, 1,
1158 m_simpleRectVtx[0].x, m_simpleRectVtx[1].y, -depth, 1,
1159 m_simpleRectVtx[0].x, m_simpleRectVtx[0].y, -depth, 1
1162 glColorPointer(4, GL_FLOAT, 0, &colour );
1163 glVertexPointer(4,GL_FLOAT, 0,&vertices);
1164 if( m_bMultiTexture )
1166 glClientActiveTexture( GL_TEXTURE1 );
1167 if (m_texUnitEnabled[1]) {
1168 glActiveTexture( GL_TEXTURE1 );
1169 glDisable(GL_TEXTURE_2D);
1171 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1172 glClientActiveTexture( GL_TEXTURE0 );
1174 if (m_texUnitEnabled[0]) {
1175 glActiveTexture( GL_TEXTURE0 );
1176 glDisable(GL_TEXTURE_2D);
1178 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1179 OPENGL_CHECK_ERRORS;
1181 glDrawArrays(GL_TRIANGLE_FAN,0,4);
1182 OPENGL_CHECK_ERRORS;
1183 //Restore old pointers
1184 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1185 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1186 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
1187 if (m_texUnitEnabled[0]) {
1188 glEnable(GL_TEXTURE_2D);
1190 if( m_bMultiTexture )
1192 if (m_texUnitEnabled[1]) {
1193 glActiveTexture( GL_TEXTURE1 );
1194 glEnable(GL_TEXTURE_2D);
1196 glClientActiveTexture( GL_TEXTURE1 );
1197 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1200 glBegin(GL_TRIANGLE_FAN);
1203 glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[0].y, -depth);
1204 glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[1].y, -depth);
1205 glVertex3f(m_simpleRectVtx[0].x, m_simpleRectVtx[1].y, -depth);
1206 glVertex3f(m_simpleRectVtx[0].x, m_simpleRectVtx[0].y, -depth);
1210 OPENGL_CHECK_ERRORS;
1212 #elif SDL_VIDEO_OPENGL_ES2
1214 GLfloat colour[] = {
1219 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
1221 GLfloat vertices[] = {
1222 -inv + m_simpleRectVtx[1].x / w, inv - m_simpleRectVtx[0].y / h, -depth, 1,
1223 -inv + m_simpleRectVtx[1].x / w, inv - m_simpleRectVtx[1].y / h, -depth, 1,
1224 -inv + m_simpleRectVtx[0].x / w, inv - m_simpleRectVtx[1].y / h, -depth, 1,
1225 -inv + m_simpleRectVtx[0].x / w, inv - m_simpleRectVtx[0].y / h, -depth, 1
1228 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
1229 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
1230 glDisableVertexAttribArray(VS_TEXCOORD0);
1231 OPENGL_CHECK_ERRORS;
1232 glDrawArrays(GL_TRIANGLE_FAN,0,4);
1233 OPENGL_CHECK_ERRORS;
1235 //Restore old pointers
1236 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
1237 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
1238 glEnableVertexAttribArray(VS_TEXCOORD0);
1242 if( cullface ) glEnable(GL_CULL_FACE);
1243 OPENGL_CHECK_ERRORS;
1246 void OGLRender::InitCombinerBlenderForSimpleRectDraw(uint32 tile)
1248 //glEnable(GL_CULL_FACE);
1249 EnableTexUnit(0,FALSE);
1250 OPENGL_CHECK_ERRORS;
1252 OPENGL_CHECK_ERRORS;
1253 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1254 OPENGL_CHECK_ERRORS;
1255 //glEnable(GL_ALPHA_TEST);
1258 COLOR OGLRender::PostProcessDiffuseColor(COLOR curDiffuseColor)
1260 uint32 color = curDiffuseColor;
1261 uint32 colorflag = m_pColorCombiner->m_pDecodedMux->m_dwShadeColorChannelFlag;
1262 uint32 alphaflag = m_pColorCombiner->m_pDecodedMux->m_dwShadeAlphaChannelFlag;
1263 if( colorflag+alphaflag != MUX_0 )
1265 if( (colorflag & 0xFFFFFF00) == 0 && (alphaflag & 0xFFFFFF00) == 0 )
1267 color = (m_pColorCombiner->GetConstFactor(colorflag, alphaflag, curDiffuseColor));
1270 color = (CalculateConstFactor(colorflag, alphaflag, curDiffuseColor));
1273 //return (color<<8)|(color>>24);
1277 COLOR OGLRender::PostProcessSpecularColor()
1282 void OGLRender::SetViewportRender()
1284 glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW);
1285 OPENGL_CHECK_ERRORS;
1288 void OGLRender::RenderReset()
1290 CRender::RenderReset();
1292 glMatrixMode(GL_PROJECTION);
1293 OPENGL_CHECK_ERRORS;
1295 OPENGL_CHECK_ERRORS;
1296 glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
1297 OPENGL_CHECK_ERRORS;
1300 glMatrixMode(GL_MODELVIEW);
1301 OPENGL_CHECK_ERRORS;
1303 OPENGL_CHECK_ERRORS;
1306 void OGLRender::SetAlphaTestEnable(BOOL bAlphaTestEnable)
1309 if( bAlphaTestEnable && debuggerEnableAlphaTest )
1311 if( bAlphaTestEnable )
1313 #if SDL_VIDEO_OPENGL
1314 glEnable(GL_ALPHA_TEST);
1316 glDisable(GL_ALPHA_TEST);
1317 #elif SDL_VIDEO_OPENGL_ES2
1319 COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
1320 frag->m_AlphaRef = m_dwAlpha / 255.0f;
1324 COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
1325 frag->m_AlphaRef = 0.0f;
1328 OPENGL_CHECK_ERRORS;
1331 void OGLRender::BindTexture(GLuint texture, int unitno)
1336 DebuggerAppendMsg("Check me, base ogl bind texture, unit no != 0");
1339 if( m_curBoundTex[0] != texture )
1341 glBindTexture(GL_TEXTURE_2D,texture);
1342 OPENGL_CHECK_ERRORS;
1343 m_curBoundTex[0] = texture;
1347 void OGLRender::DisBindTexture(GLuint texture, int unitno)
1349 //EnableTexUnit(0,FALSE);
1350 //glBindTexture(GL_TEXTURE_2D, 0); //Not to bind any texture
1353 void OGLRender::EnableTexUnit(int unitno, BOOL flag)
1358 DebuggerAppendMsg("Check me, in the base ogl render, unitno!=0");
1361 if( m_texUnitEnabled[0] != flag ) //strange, why 0 and not unitno?
1363 m_texUnitEnabled[0] = flag;
1364 #if SDL_VIDEO_OPENGL
1365 if( flag == TRUE ) {
1366 // pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1367 glEnable(GL_TEXTURE_2D);
1369 // pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1370 glDisable(GL_TEXTURE_2D);
1372 /* if (m_bMultiTexture)
1373 pglActiveTexture(GL_TEXTURE1_ARB);*/
1374 #elif SDL_VIDEO_OPENGL_ES2
1377 pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1378 OPENGL_CHECK_ERRORS;
1379 glBindTexture(GL_TEXTURE_2D,m_curBoundTex[unitno]);
1383 pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1384 OPENGL_CHECK_ERRORS;
1385 glEnable(GL_BLEND); //Need blend for transparent disabled texture
1386 glBindTexture(GL_TEXTURE_2D,disabledTextureID);
1389 OPENGL_CHECK_ERRORS;
1393 void OGLRender::TexCoord2f(float u, float v)
1396 printf("*SEB* TexCoord2f(%f, %f)\n", u, v);
1402 void OGLRender::TexCoord(TLITVERTEX &vtxInfo)
1405 printf("*SEB* TexCoord(%f, %f)\n", vtxInfo.tcord[0].u, vtxInfo.tcord[0].v);
1407 glTexCoord2f(vtxInfo.tcord[0].u, vtxInfo.tcord[0].v);
1411 void OGLRender::UpdateScissor()
1413 if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
1416 uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
1417 uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
1418 glEnable(GL_SCISSOR_TEST);
1419 OPENGL_CHECK_ERRORS;
1420 glScissor(80, int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
1421 int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
1422 OPENGL_CHECK_ERRORS;
1426 UpdateScissorWithClipRatio();
1430 void OGLRender::ApplyRDPScissor(bool force)
1432 if( !force && status.curScissor == RDP_SCISSOR ) return;
1434 if( options.bEnableHacks && g_CI.dwWidth == 0x200 && gRDP.scissor.right == 0x200 && g_CI.dwWidth>(*g_GraphicsInfo.VI_WIDTH_REG & 0xFFF) )
1437 uint32 width = *g_GraphicsInfo.VI_WIDTH_REG & 0xFFF;
1438 uint32 height = (gRDP.scissor.right*gRDP.scissor.bottom)/width;
1439 glEnable(GL_SCISSOR_TEST);
1440 OPENGL_CHECK_ERRORS;
1441 glScissor(80, int(height*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
1442 int(width*windowSetting.fMultX), int(height*windowSetting.fMultY) );
1443 OPENGL_CHECK_ERRORS;
1447 glScissor(80+int(gRDP.scissor.left*windowSetting.fMultX), int((windowSetting.uViHeight-gRDP.scissor.bottom)*windowSetting.fMultY+windowSetting.statusBarHeightToUse),
1448 int((gRDP.scissor.right-gRDP.scissor.left)*windowSetting.fMultX), int((gRDP.scissor.bottom-gRDP.scissor.top)*windowSetting.fMultY ));
1449 OPENGL_CHECK_ERRORS;
1452 status.curScissor = RDP_SCISSOR;
1455 void OGLRender::ApplyScissorWithClipRatio(bool force)
1457 if( !force && status.curScissor == RSP_SCISSOR ) return;
1459 glEnable(GL_SCISSOR_TEST);
1460 OPENGL_CHECK_ERRORS;
1461 glScissor(80+windowSetting.clipping.left, int((windowSetting.uViHeight-gRSP.real_clip_scissor_bottom)*windowSetting.fMultY)+windowSetting.statusBarHeightToUse,
1462 windowSetting.clipping.width, windowSetting.clipping.height);
1463 OPENGL_CHECK_ERRORS;
1465 status.curScissor = RSP_SCISSOR;
1468 void OGLRender::SetFogMinMax(float fMin, float fMax)
1470 #if SDL_VIDEO_OPENGL
1471 glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
1472 OPENGL_CHECK_ERRORS;
1473 glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
1474 OPENGL_CHECK_ERRORS;
1475 #elif SDL_VIDEO_OPENGL_ES2
1476 ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
1477 OPENGL_CHECK_ERRORS;
1481 void OGLRender::TurnFogOnOff(bool flag)
1483 #if SDL_VIDEO_OPENGL
1488 OPENGL_CHECK_ERRORS;
1489 #elif SDL_VIDEO_OPENGL_ES2
1490 ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(flag);
1491 OPENGL_CHECK_ERRORS;
1495 void OGLRender::SetFogEnable(bool bEnable)
1497 DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != (bEnable==TRUE) && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
1499 gRSP.bFogEnabled = bEnable&&(options.fogMethod == 1);
1502 if(options.fogMethod == 2)
1504 gRSP.bFogEnabled = true;
1507 #if SDL_VIDEO_OPENGL
1508 if( gRSP.bFogEnabled )
1510 //TRACE2("Enable fog, min=%f, max=%f",gRSPfFogMin,gRSPfFogMax );
1511 glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
1512 OPENGL_CHECK_ERRORS;
1513 glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
1514 OPENGL_CHECK_ERRORS;
1515 glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
1516 OPENGL_CHECK_ERRORS;
1518 OPENGL_CHECK_ERRORS;
1523 OPENGL_CHECK_ERRORS;
1525 #elif SDL_VIDEO_OPENGL_ES2
1526 ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
1527 OPENGL_CHECK_ERRORS;
1531 void OGLRender::SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
1533 gRDP.fogColor = COLOR_RGBA(r, g, b, a);
1534 gRDP.fvFogColor[0] = r/255.0f; //r
1535 gRDP.fvFogColor[1] = g/255.0f; //g
1536 gRDP.fvFogColor[2] = b/255.0f; //b
1537 gRDP.fvFogColor[3] = a/255.0f; //a
1538 #if SDL_VIDEO_OPENGL
1539 glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
1541 OPENGL_CHECK_ERRORS;
1544 void OGLRender::DisableMultiTexture()
1546 pglActiveTexture(GL_TEXTURE1_ARB);
1547 OPENGL_CHECK_ERRORS;
1548 EnableTexUnit(1,FALSE);
1549 pglActiveTexture(GL_TEXTURE0_ARB);
1550 OPENGL_CHECK_ERRORS;
1551 EnableTexUnit(0,FALSE);
1552 pglActiveTexture(GL_TEXTURE0_ARB);
1553 OPENGL_CHECK_ERRORS;
1554 EnableTexUnit(0,TRUE);
1557 void OGLRender::EndRendering(void)
1559 #if SDL_VIDEO_OPENGL
1561 OPENGL_CHECK_ERRORS;
1563 if( CRender::gRenderReferenceCount > 0 )
1564 CRender::gRenderReferenceCount--;
1567 void OGLRender::glViewportWrapper(GLint x, GLint y, GLsizei width, GLsizei height, bool flag)
1569 static GLint mx=0,my=0;
1570 static GLsizei m_width=0, m_height=0;
1571 static bool mflag=true;
1575 if( x!=mx || y!=my || width!=m_width || height!=m_height || mflag!=flag)
1582 glMatrixMode(GL_PROJECTION);
1583 OPENGL_CHECK_ERRORS;
1585 OPENGL_CHECK_ERRORS;
1586 if( flag ) glOrtho(0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, 0, -1, 1);
1587 OPENGL_CHECK_ERRORS;
1588 glViewport(x,y,width,height);
1589 //printf("glViewport(%i, %i, %i, %i)\n", x, y, width, height);
1590 OPENGL_CHECK_ERRORS;