rice: avoid redundant gl calls
[mupen64plus-pandora.git] / source / gles2rice / src / OGLES2FragmentShaders.h
1 /*
2 Copyright (C) 2005 Rice1964
3
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.
8
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.
13
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.
17 */
18
19 #ifndef _OGL_FRAGMENT_SHADER_H_
20 #define _OGL_FRAGMENT_SHADER_H_
21
22 #include <vector>
23
24 #include "osal_opengl.h"
25
26 #include "OGLCombiner.h"
27 #include "OGLExtCombiner.h"
28 #include "GeneralCombiner.h"
29
30 typedef struct {
31     uint32  dwMux0;
32     uint32  dwMux1;
33
34     bool    fogIsUsed;
35     bool    alphaTest;
36     GLuint  fragmentShaderID;
37     GLuint  vertexShaderID;
38     GLuint  programID;
39
40     GLint  PrimColorLocation;
41     GLint  EnvColorLocation;
42     GLint  PrimFracLocation;
43     GLint  EnvFracLocation;
44     GLint  AlphaRefLocation;
45     GLint FogColorLocation;
46     GLint FogMinMaxLocation;
47
48     float PrimColors[4];
49     float EnvColors[4];
50     float PrimLODFrac;
51     float EnvLODFrac;
52     float AlphaRef;
53     float FogColors[4];
54     float FogMin;
55     float FogMax;
56 } OGLShaderCombinerSaveType;
57
58
59 class COGL_FragmentProgramCombiner : public COGLColorCombiner4
60 {
61 public:
62     bool Initialize(void);
63     void SetFogState(bool bEnable)
64     {
65         bFogState = bEnable;
66     }
67     void SetAlphaTestState(bool bEnable)
68     {
69         bAlphaTestState = bEnable;
70     }
71
72 protected:
73     friend class OGLDeviceBuilder;
74
75     void DisableCombiner(void);
76     void InitCombinerCycleCopy(void);
77     void InitCombinerCycleFill(void);
78     void InitCombinerCycle12(void);
79
80     COGL_FragmentProgramCombiner(CRender *pRender);
81     ~COGL_FragmentProgramCombiner();
82
83     bool m_bFragmentProgramIsSupported;
84     std::vector<OGLShaderCombinerSaveType>      m_vCompiledShaders;
85
86 private:
87     virtual int ParseDecodedMux();
88     virtual void GenerateProgramStr();
89     int FindCompiledMux();
90     virtual void GenerateCombinerSetting(int index);
91     virtual void GenerateCombinerSettingConstants(int index);
92     float m_AlphaRef;
93     bool bAlphaTestState;
94     bool bAlphaTestPreviousState;
95     bool bFogState;
96     bool bFogPreviousState;
97
98     void UseProgram(GLuint program);
99     GLuint currentProgram;
100
101 #ifdef DEBUGGER
102     void DisplaySimpleMuxString(void);
103 #endif
104
105 };
106
107
108
109 class COGLFragmentShaderCombiner : public COGLColorCombiner
110 {
111 public:
112     bool Initialize(void);
113     void InitCombinerBlenderForSimpleTextureDraw(uint32 tile=0);
114 protected:
115     friend class OGLDeviceBuilder;
116
117     void DisableCombiner(void);
118     void InitCombinerCycleCopy(void);
119     void InitCombinerCycleFill(void);
120     void InitCombinerCycle12(void);
121
122     COGLFragmentShaderCombiner(CRender *pRender);
123     ~COGLFragmentShaderCombiner();
124
125     bool m_bShaderIsSupported;
126
127 #ifdef DEBUGGER
128     void DisplaySimpleMuxString(void);
129 #endif
130
131 };
132
133
134 #endif
135