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

« back to all changes in this revision

Viewing changes to src/OGLRender.cpp

  • Committer: Package Import Robot
  • Author(s): Sven Eckelmann
  • Date: 2013-07-05 22:53:25 UTC
  • mfrom: (1.2.2) (3.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130705225325-k0fbb2m44xnrju66
Tags: 2.0-1
* New Upstream Version
* Upload to unstable
* debian/control:
  - Build-Depend on debhelper 9.20130604 for support of parameters when
    detecting targets in dh_auto_*
* debian/rules:
  - Work around new debhelper 9.20130624 dh_auto_{clean,test} behavior
    which is causing a FTBFS by adding an explicit
    override_dh_auto_{clean,test} rule
* debian/watch:
  - Verify new upstream versions using GPG key 954F81B094AA5BB226F5

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
17
*/
18
18
 
 
19
#include "osal_opengl.h"
 
20
 
 
21
#if SDL_VIDEO_OPENGL
19
22
#include "OGLExtensions.h"
 
23
#elif SDL_VIDEO_OPENGL_ES2
 
24
#include "OGLES2FragmentShaders.h"
 
25
#endif
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"
25
31
 
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
29
35
 
30
36
UVFlagMap OGLXUVFlagMaps[] =
31
37
{
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},
35
41
};
36
42
 
 
43
#if SDL_VIDEO_OPENGL_ES2
 
44
  static GLuint disabledTextureID;
 
45
#endif
 
46
 
37
47
//===================================================================
38
48
OGLRender::OGLRender()
39
49
{
46
56
        m_curBoundTex[i]=0;
47
57
        m_texUnitEnabled[i]=FALSE;
48
58
    }
 
59
 
 
60
#if SDL_VIDEO_OPENGL
49
61
    m_bEnableMultiTexture = false;
 
62
 
 
63
#elif SDL_VIDEO_OPENGL_ES2
 
64
    m_bEnableMultiTexture = true;
 
65
 
 
66
    //Create a texture as replacement for glEnable/Disable(GL_TEXTURE_2D)
 
67
    TLITVERTEX white;
 
68
    white.r = white.g = white.b = 0;
 
69
    white.a = 0;
 
70
    glGenTextures(1,&disabledTextureID);
 
71
    OPENGL_CHECK_ERRORS;
 
72
    glBindTexture(GL_TEXTURE_2D, disabledTextureID);
 
73
    OPENGL_CHECK_ERRORS;
 
74
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
75
    OPENGL_CHECK_ERRORS;
 
76
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &white.dcDiffuse);
 
77
    OPENGL_CHECK_ERRORS;
 
78
#endif
50
79
}
51
80
 
52
81
OGLRender::~OGLRender()
76
105
    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
77
106
    OPENGL_CHECK_ERRORS;
78
107
 
 
108
#if SDL_VIDEO_OPENGL
79
109
    COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
80
110
    if( pcontext->IsExtensionSupported("GL_IBM_texture_mirrored_repeat") )
81
111
    {
164
194
        OPENGL_CHECK_ERRORS;
165
195
    }
166
196
 
 
197
#elif SDL_VIDEO_OPENGL_ES2
 
198
    OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT;
 
199
    m_bSupportClampToEdge = true;
 
200
    OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
 
201
#endif
167
202
}
168
203
//===================================================================
169
204
TextureFilterMap OglTexFilterMap[2]=
209
244
 
210
245
void OGLRender::SetShadeMode(RenderShadeMode mode)
211
246
{
 
247
#if SDL_VIDEO_OPENGL
212
248
    if( mode == SHADE_SMOOTH )
213
249
        glShadeModel(GL_SMOOTH);
214
250
    else
215
251
        glShadeModel(GL_FLAT);
216
252
    OPENGL_CHECK_ERRORS;
 
253
#endif
217
254
}
218
255
 
219
256
void OGLRender::ZBufferEnable(BOOL bZBuffer)
332
369
    if (m_dwAlpha != dwAlpha)
333
370
    {
334
371
        m_dwAlpha = dwAlpha;
 
372
#if SDL_VIDEO_OPENGL
335
373
        glAlphaFunc(GL_GEQUAL, (float)dwAlpha);
336
374
        OPENGL_CHECK_ERRORS;
 
375
#endif
337
376
    }
338
377
}
339
378
 
340
379
void OGLRender::ForceAlphaRef(uint32 dwAlpha)
341
380
{
 
381
#if SDL_VIDEO_OPENGL
342
382
    float ref = dwAlpha/255.0f;
343
383
    glAlphaFunc(GL_GEQUAL, ref);
344
384
    OPENGL_CHECK_ERRORS;
 
385
#elif SDL_VIDEO_OPENGL_ES2
 
386
    m_dwAlpha = dwAlpha;
 
387
#endif
345
388
}
346
389
 
347
390
void OGLRender::SetFillMode(FillMode mode)
348
391
{
 
392
#if SDL_VIDEO_OPENGL
349
393
    if( mode == RICE_FILLMODE_WINFRAME )
350
394
    {
351
395
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
356
400
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
357
401
        OPENGL_CHECK_ERRORS;
358
402
    }
 
403
#endif
359
404
}
360
405
 
361
406
void OGLRender::SetCullMode(bool bCullFront, bool bCullBack)
513
558
    glDisable(GL_CULL_FACE);
514
559
    OPENGL_CHECK_ERRORS;
515
560
 
516
 
    glBegin(GL_TRIANGLE_FAN);
517
 
 
518
561
    float depth = -(g_texRectTVtx[3].z*2-1);
519
562
 
 
563
#if SDL_VIDEO_OPENGL
 
564
 
 
565
    glBegin(GL_TRIANGLE_FAN);
 
566
 
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);
536
583
    glEnd();
537
584
    OPENGL_CHECK_ERRORS;
538
585
 
 
586
#elif SDL_VIDEO_OPENGL_ES2
 
587
 
 
588
    GLfloat colour[] = {
 
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
 
593
    };
 
594
 
 
595
    GLfloat tex[] = {
 
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
 
600
    };
 
601
 
 
602
    float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
603
 
 
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
 
609
    };
 
610
 
 
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);
 
614
    OPENGL_CHECK_ERRORS;
 
615
    glDrawArrays(GL_TRIANGLE_FAN,0,4);
 
616
    OPENGL_CHECK_ERRORS;
 
617
 
 
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));
 
622
 
 
623
#endif
 
624
 
539
625
    if( cullface ) glEnable(GL_CULL_FACE);
540
626
    OPENGL_CHECK_ERRORS;
541
627
 
555
641
    glDisable(GL_CULL_FACE);
556
642
    OPENGL_CHECK_ERRORS;
557
643
 
 
644
#if SDL_VIDEO_OPENGL
 
645
 
558
646
    glBegin(GL_TRIANGLE_FAN);
559
647
    glColor4f(r,g,b,a);
560
648
    glVertex4f(m_fillRectVtx[0].x, m_fillRectVtx[1].y, depth, 1);
564
652
    glEnd();
565
653
    OPENGL_CHECK_ERRORS;
566
654
 
 
655
#elif SDL_VIDEO_OPENGL_ES2
 
656
 
 
657
    GLfloat colour[] = {
 
658
            r,g,b,a,
 
659
            r,g,b,a,
 
660
            r,g,b,a,
 
661
            r,g,b,a};
 
662
 
 
663
    float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
664
 
 
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
 
670
    };
 
671
 
 
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);
 
675
    OPENGL_CHECK_ERRORS;
 
676
    glDrawArrays(GL_TRIANGLE_FAN,0,4);
 
677
    OPENGL_CHECK_ERRORS;
 
678
 
 
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);
 
683
 
 
684
#endif
 
685
 
567
686
    if( cullface ) glEnable(GL_CULL_FACE);
568
687
    OPENGL_CHECK_ERRORS;
569
688
 
572
691
 
573
692
bool OGLRender::RenderLine3D()
574
693
{
 
694
#if SDL_VIDEO_OPENGL
575
695
    ApplyZBias(0);  // disable z offsets
576
696
 
577
697
    glBegin(GL_TRIANGLE_FAN);
587
707
    glEnd();
588
708
    OPENGL_CHECK_ERRORS;
589
709
 
590
 
    ApplyZBias(m_dwZBias);          // set Z offset back to previous value
 
710
    ApplyZBias(m_dwZBias);  // set Z offset back to previous value
 
711
#endif
591
712
 
592
713
    return true;
593
714
}
604
725
    {
605
726
        if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
606
727
        {
607
 
            glDisable(GL_FOG);
608
 
            OPENGL_CHECK_ERRORS;
 
728
            TurnFogOnOff(false);
609
729
        }
610
730
    }
611
731
 
612
 
    ApplyZBias(m_dwZBias);                    // set the bias factors
 
732
    ApplyZBias(m_dwZBias);  // set the bias factors
613
733
 
614
734
    glViewportWrapper(windowSetting.vpLeftW, windowSetting.uDisplayHeight-windowSetting.vpTopW-windowSetting.vpHeightW+windowSetting.statusBarHeightToUse, windowSetting.vpWidthW, windowSetting.vpHeightW, false);
615
735
    OPENGL_CHECK_ERRORS;
616
736
 
617
737
    //if options.bOGLVertexClipper == FALSE )
618
738
    {
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;
621
741
    }
622
742
/*  else
657
777
    {
658
778
        if( !gRDP.bFogEnableInBlender && gRSP.bFogEnabled )
659
779
        {
660
 
            glEnable(GL_FOG);
661
 
            OPENGL_CHECK_ERRORS;
 
780
            TurnFogOnOff(true);
662
781
        }
663
782
    }
664
783
    return true;
682
801
    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
683
802
    OPENGL_CHECK_ERRORS;
684
803
 
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;
 
808
 
 
809
#if SDL_VIDEO_OPENGL
 
810
 
 
811
    glBegin(GL_TRIANGLES);
 
812
 
690
813
    glColor4f(r,g,b,a);
691
814
 
692
815
    OGLRender::TexCoord(g_texRectTVtx[0]);
710
833
    glEnd();
711
834
    OPENGL_CHECK_ERRORS;
712
835
 
 
836
#elif SDL_VIDEO_OPENGL_ES2
 
837
 
 
838
    GLfloat colour[] = {
 
839
            r,g,b,a,
 
840
            r,g,b,a,
 
841
            r,g,b,a,
 
842
            r,g,b,a,
 
843
            r,g,b,a,
 
844
            r,g,b,a
 
845
    };
 
846
 
 
847
    GLfloat tex[] = {
 
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,
 
851
 
 
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,
 
855
    };
 
856
 
 
857
     float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
858
 
 
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,
 
863
 
 
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
 
867
    };
 
868
 
 
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);
 
872
    OPENGL_CHECK_ERRORS;
 
873
    glDrawArrays(GL_TRIANGLES,0,6);
 
874
    OPENGL_CHECK_ERRORS;
 
875
 
 
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));
 
880
 
 
881
#endif
 
882
 
713
883
    if( cullface ) glEnable(GL_CULL_FACE);
714
884
    OPENGL_CHECK_ERRORS;
715
885
}
722
892
    glDisable(GL_CULL_FACE);
723
893
    OPENGL_CHECK_ERRORS;
724
894
 
725
 
    glBegin(GL_TRIANGLE_FAN);
726
 
 
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;
 
899
 
 
900
#if SDL_VIDEO_OPENGL
 
901
 
 
902
    glBegin(GL_TRIANGLE_FAN);
 
903
 
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);
737
910
    glEnd();
738
911
    OPENGL_CHECK_ERRORS;
739
912
 
 
913
#elif SDL_VIDEO_OPENGL_ES2
 
914
 
 
915
    GLfloat colour[] = {
 
916
            r,g,b,a,
 
917
            r,g,b,a,
 
918
            r,g,b,a,
 
919
            r,g,b,a};
 
920
    float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
921
 
 
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
 
927
    };
 
928
 
 
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);
 
932
    OPENGL_CHECK_ERRORS;
 
933
    glDrawArrays(GL_TRIANGLE_FAN,0,4);
 
934
    OPENGL_CHECK_ERRORS;
 
935
 
 
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);
 
940
 
 
941
#endif
 
942
 
740
943
    if( cullface ) glEnable(GL_CULL_FACE);
741
944
    OPENGL_CHECK_ERRORS;
742
945
}
808
1011
#else
809
1012
    if( bAlphaTestEnable )
810
1013
#endif
 
1014
#if SDL_VIDEO_OPENGL
811
1015
        glEnable(GL_ALPHA_TEST);
812
1016
    else
813
1017
        glDisable(GL_ALPHA_TEST);
 
1018
#elif SDL_VIDEO_OPENGL_ES2
 
1019
    {
 
1020
        COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
 
1021
        frag->m_AlphaRef = m_dwAlpha / 255.0f;
 
1022
    }
 
1023
    else
 
1024
    {
 
1025
        COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
 
1026
        frag->m_AlphaRef = 0.0f;
 
1027
    }
 
1028
#endif
814
1029
    OPENGL_CHECK_ERRORS;
815
1030
}
816
1031
 
847
1062
    if( m_texUnitEnabled[0] != flag )
848
1063
    {
849
1064
        m_texUnitEnabled[0] = flag;
 
1065
#if SDL_VIDEO_OPENGL
850
1066
        if( flag == TRUE )
851
1067
            glEnable(GL_TEXTURE_2D);
852
1068
        else
853
1069
            glDisable(GL_TEXTURE_2D);
 
1070
#elif SDL_VIDEO_OPENGL_ES2
 
1071
        if(flag)
 
1072
        {
 
1073
            pglActiveTexture(GL_TEXTURE0_ARB + unitno);
 
1074
            OPENGL_CHECK_ERRORS;
 
1075
            glBindTexture(GL_TEXTURE_2D,m_curBoundTex[unitno]);
 
1076
        }
 
1077
        else
 
1078
        {
 
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);
 
1083
        }
 
1084
#endif
854
1085
        OPENGL_CHECK_ERRORS;
855
1086
    }
856
1087
}
924
1155
 
925
1156
void OGLRender::SetFogMinMax(float fMin, float fMax)
926
1157
{
 
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;
 
1166
#endif
931
1167
}
932
1168
 
933
1169
void OGLRender::TurnFogOnOff(bool flag)
934
1170
{
 
1171
#if SDL_VIDEO_OPENGL
935
1172
    if( flag )
936
1173
        glEnable(GL_FOG);
937
1174
    else
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;
 
1180
#endif
940
1181
}
941
1182
 
942
1183
void OGLRender::SetFogEnable(bool bEnable)
951
1192
        gRSP.bFogEnabled = true;
952
1193
    }
953
1194
 
 
1195
#if SDL_VIDEO_OPENGL
954
1196
    if( gRSP.bFogEnabled )
955
1197
    {
956
1198
        //TRACE2("Enable fog, min=%f, max=%f",gRSPfFogMin,gRSPfFogMax );
968
1210
        glDisable(GL_FOG);
969
1211
        OPENGL_CHECK_ERRORS;
970
1212
    }
 
1213
#elif SDL_VIDEO_OPENGL_ES2
 
1214
    ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
 
1215
    OPENGL_CHECK_ERRORS;
 
1216
#endif
971
1217
}
972
1218
 
973
1219
void OGLRender::SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
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
 
1228
#endif
981
1229
    OPENGL_CHECK_ERRORS;
982
1230
}
983
1231
 
996
1244
 
997
1245
void OGLRender::EndRendering(void)
998
1246
{
 
1247
#if SDL_VIDEO_OPENGL
999
1248
    glFlush();
1000
1249
    OPENGL_CHECK_ERRORS;
 
1250
#endif
1001
1251
    if( CRender::gRenderReferenceCount > 0 ) 
1002
1252
        CRender::gRenderReferenceCount--;
1003
1253
}