16
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
#include "osal_opengl.h"
19
22
#include "OGLExtensions.h"
23
#elif SDL_VIDEO_OPENGL_ES2
24
#include "OGLES2FragmentShaders.h"
20
26
#include "OGLDebug.h"
21
27
#include "OGLRender.h"
22
28
#include "OGLGraphicsContext.h"
23
29
#include "OGLTexture.h"
24
30
#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
32
// FIXME: Use OGL internal L/T and matrix stack
33
// FIXME: Use OGL lookupAt function
34
// FIXME: Use OGL DisplayList
30
36
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},
38
{TEXTURE_UV_FLAG_WRAP, GL_REPEAT},
39
{TEXTURE_UV_FLAG_MIRROR, GL_MIRRORED_REPEAT_ARB},
40
{TEXTURE_UV_FLAG_CLAMP, GL_CLAMP},
43
#if SDL_VIDEO_OPENGL_ES2
44
static GLuint disabledTextureID;
37
47
//===================================================================
38
48
OGLRender::OGLRender()
46
56
m_curBoundTex[i]=0;
47
57
m_texUnitEnabled[i]=FALSE;
49
61
m_bEnableMultiTexture = false;
63
#elif SDL_VIDEO_OPENGL_ES2
64
m_bEnableMultiTexture = true;
66
//Create a texture as replacement for glEnable/Disable(GL_TEXTURE_2D)
68
white.r = white.g = white.b = 0;
70
glGenTextures(1,&disabledTextureID);
72
glBindTexture(GL_TEXTURE_2D, disabledTextureID);
74
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
76
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &white.dcDiffuse);
52
81
OGLRender::~OGLRender()
332
369
if (m_dwAlpha != dwAlpha)
334
371
m_dwAlpha = dwAlpha;
335
373
glAlphaFunc(GL_GEQUAL, (float)dwAlpha);
336
374
OPENGL_CHECK_ERRORS;
340
379
void OGLRender::ForceAlphaRef(uint32 dwAlpha)
342
382
float ref = dwAlpha/255.0f;
343
383
glAlphaFunc(GL_GEQUAL, ref);
344
384
OPENGL_CHECK_ERRORS;
385
#elif SDL_VIDEO_OPENGL_ES2
347
390
void OGLRender::SetFillMode(FillMode mode)
349
393
if( mode == RICE_FILLMODE_WINFRAME )
351
395
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
513
558
glDisable(GL_CULL_FACE);
514
559
OPENGL_CHECK_ERRORS;
516
glBegin(GL_TRIANGLE_FAN);
518
561
float depth = -(g_texRectTVtx[3].z*2-1);
565
glBegin(GL_TRIANGLE_FAN);
520
567
glColor4f(g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a);
521
568
TexCoord(g_texRectTVtx[3]);
522
569
glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, depth);
537
584
OPENGL_CHECK_ERRORS;
586
#elif SDL_VIDEO_OPENGL_ES2
589
g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a,
590
g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a,
591
g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a,
592
g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a
596
g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
597
g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
598
g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
599
g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v
602
float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
604
GLfloat vertices[] = {
605
-inv + g_texRectTVtx[3].x / w, inv - g_texRectTVtx[3].y / h, depth, 1,
606
-inv + g_texRectTVtx[2].x / w, inv - g_texRectTVtx[2].y / h, depth, 1,
607
-inv + g_texRectTVtx[1].x / w, inv - g_texRectTVtx[1].y / h, depth, 1,
608
-inv + g_texRectTVtx[0].x / w, inv - g_texRectTVtx[0].y / h, depth, 1
611
glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_TRUE, 0, &colour );
612
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
613
glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
615
glDrawArrays(GL_TRIANGLE_FAN,0,4);
618
//Restore old pointers
619
glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
620
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
621
glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
539
625
if( cullface ) glEnable(GL_CULL_FACE);
540
626
OPENGL_CHECK_ERRORS;
565
653
OPENGL_CHECK_ERRORS;
655
#elif SDL_VIDEO_OPENGL_ES2
663
float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
665
GLfloat vertices[] = {
666
-inv + m_fillRectVtx[0].x / w, inv - m_fillRectVtx[1].y / h, depth, 1,
667
-inv + m_fillRectVtx[1].x / w, inv - m_fillRectVtx[1].y / h, depth, 1,
668
-inv + m_fillRectVtx[1].x / w, inv - m_fillRectVtx[0].y / h, depth, 1,
669
-inv + m_fillRectVtx[0].x / w, inv - m_fillRectVtx[0].y / h, depth, 1
672
glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
673
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
674
glDisableVertexAttribArray(VS_TEXCOORD0);
676
glDrawArrays(GL_TRIANGLE_FAN,0,4);
679
//Restore old pointers
680
glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
681
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
682
glEnableVertexAttribArray(VS_TEXCOORD0);
567
686
if( cullface ) glEnable(GL_CULL_FACE);
568
687
OPENGL_CHECK_ERRORS;
605
726
if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
612
ApplyZBias(m_dwZBias); // set the bias factors
732
ApplyZBias(m_dwZBias); // set the bias factors
614
734
glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW, false);
615
735
OPENGL_CHECK_ERRORS;
617
737
//if options.bOGLVertexClipper == FALSE )
619
glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_INT, g_vtxIndex );
739
glDrawElements( GL_TRIANGLES, gRSP.numVertices, GL_UNSIGNED_SHORT, g_vtxIndex );
620
740
OPENGL_CHECK_ERRORS;
682
801
glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
683
802
OPENGL_CHECK_ERRORS;
685
glBegin(GL_TRIANGLES);
686
804
float a = (g_texRectTVtx[0].dcDiffuse >>24)/255.0f;
687
805
float r = ((g_texRectTVtx[0].dcDiffuse>>16)&0xFF)/255.0f;
688
806
float g = ((g_texRectTVtx[0].dcDiffuse>>8)&0xFF)/255.0f;
689
807
float b = (g_texRectTVtx[0].dcDiffuse&0xFF)/255.0f;
811
glBegin(GL_TRIANGLES);
690
813
glColor4f(r,g,b,a);
692
815
OGLRender::TexCoord(g_texRectTVtx[0]);
711
834
OPENGL_CHECK_ERRORS;
836
#elif SDL_VIDEO_OPENGL_ES2
848
g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
849
g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
850
g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
852
g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
853
g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
854
g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
857
float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
859
GLfloat vertices[] = {
860
-inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
861
-inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
862
-inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
864
-inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
865
-inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
866
-inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
869
glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
870
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
871
glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
873
glDrawArrays(GL_TRIANGLES,0,6);
876
//Restore old pointers
877
glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
878
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
879
glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
713
883
if( cullface ) glEnable(GL_CULL_FACE);
714
884
OPENGL_CHECK_ERRORS;
722
892
glDisable(GL_CULL_FACE);
723
893
OPENGL_CHECK_ERRORS;
725
glBegin(GL_TRIANGLE_FAN);
727
895
float a = (dwColor>>24)/255.0f;
728
896
float r = ((dwColor>>16)&0xFF)/255.0f;
729
897
float g = ((dwColor>>8)&0xFF)/255.0f;
730
898
float b = (dwColor&0xFF)/255.0f;
902
glBegin(GL_TRIANGLE_FAN);
731
904
glColor4f(r,g,b,a);
732
905
glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[0].y, -depth);
733
906
glVertex3f(m_simpleRectVtx[1].x, m_simpleRectVtx[1].y, -depth);
738
911
OPENGL_CHECK_ERRORS;
913
#elif SDL_VIDEO_OPENGL_ES2
920
float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
922
GLfloat vertices[] = {
923
-inv + m_simpleRectVtx[1].x / w, inv - m_simpleRectVtx[0].y / h, -depth, 1,
924
-inv + m_simpleRectVtx[1].x / w, inv - m_simpleRectVtx[1].y / h, -depth, 1,
925
-inv + m_simpleRectVtx[0].x / w, inv - m_simpleRectVtx[1].y / h, -depth, 1,
926
-inv + m_simpleRectVtx[0].x / w, inv - m_simpleRectVtx[0].y / h, -depth, 1
929
glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
930
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
931
glDisableVertexAttribArray(VS_TEXCOORD0);
933
glDrawArrays(GL_TRIANGLE_FAN,0,4);
936
//Restore old pointers
937
glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
938
glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
939
glEnableVertexAttribArray(VS_TEXCOORD0);
740
943
if( cullface ) glEnable(GL_CULL_FACE);
741
944
OPENGL_CHECK_ERRORS;
847
1062
if( m_texUnitEnabled[0] != flag )
849
1064
m_texUnitEnabled[0] = flag;
1065
#if SDL_VIDEO_OPENGL
850
1066
if( flag == TRUE )
851
1067
glEnable(GL_TEXTURE_2D);
853
1069
glDisable(GL_TEXTURE_2D);
1070
#elif SDL_VIDEO_OPENGL_ES2
1073
pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1074
OPENGL_CHECK_ERRORS;
1075
glBindTexture(GL_TEXTURE_2D,m_curBoundTex[unitno]);
1079
pglActiveTexture(GL_TEXTURE0_ARB + unitno);
1080
OPENGL_CHECK_ERRORS;
1081
glEnable(GL_BLEND); //Need blend for transparent disabled texture
1082
glBindTexture(GL_TEXTURE_2D,disabledTextureID);
854
1085
OPENGL_CHECK_ERRORS;
925
1156
void OGLRender::SetFogMinMax(float fMin, float fMax)
1158
#if SDL_VIDEO_OPENGL
927
1159
glFogf(GL_FOG_START, gRSPfFogMin); // Fog Start Depth
928
1160
OPENGL_CHECK_ERRORS;
929
1161
glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
930
1162
OPENGL_CHECK_ERRORS;
1163
#elif SDL_VIDEO_OPENGL_ES2
1164
((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
1165
OPENGL_CHECK_ERRORS;
933
1169
void OGLRender::TurnFogOnOff(bool flag)
1171
#if SDL_VIDEO_OPENGL
936
1173
glEnable(GL_FOG);
938
1175
glDisable(GL_FOG);
939
1176
OPENGL_CHECK_ERRORS;
1177
#elif SDL_VIDEO_OPENGL_ES2
1178
((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(flag);
1179
OPENGL_CHECK_ERRORS;
942
1183
void OGLRender::SetFogEnable(bool bEnable)
975
1221
gRDP.fogColor = COLOR_RGBA(r, g, b, a);
976
1222
gRDP.fvFogColor[0] = r/255.0f; //r
977
1223
gRDP.fvFogColor[1] = g/255.0f; //g
978
gRDP.fvFogColor[2] = b/255.0f; //b
1224
gRDP.fvFogColor[2] = b/255.0f; //b
979
1225
gRDP.fvFogColor[3] = a/255.0f; //a
1226
#if SDL_VIDEO_OPENGL
980
1227
glFogfv(GL_FOG_COLOR, gRDP.fvFogColor); // Set Fog Color
981
1229
OPENGL_CHECK_ERRORS;