Rice GLES2 (from mupen64plus-ae) plugin. Compile but doesn't works well on the OpenPa...
[mupen64plus-pandora.git] / source / gles2rice / src / OGLExtCombiner.h
1 /*
2 Copyright (C) 2003 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 _OGLEXT_COMBINER_H_
20 #define _OGLEXT_COMBINER_H_
21
22 #include <vector>
23
24 #include "osal_opengl.h"
25
26 #include "OGLCombiner.h"
27 #include "GeneralCombiner.h"
28
29 typedef union 
30 {
31     struct {
32         uint8   arg0;
33         uint8   arg1;
34         uint8   arg2;
35     };
36     uint8 args[3];
37 } OGLExt1CombType;
38
39 typedef struct {
40     union {
41         struct {
42             GLenum  rgbOp;
43             GLenum  alphaOp;
44         };
45         GLenum ops[2];
46     };
47
48     union {
49         struct {
50             uint8   rgbArg0;
51             uint8   rgbArg1;
52             uint8   rgbArg2;
53             uint8   alphaArg0;
54             uint8   alphaArg1;
55             uint8   alphaArg2;
56         };
57         struct {
58             OGLExt1CombType rgbComb;
59             OGLExt1CombType alphaComb;
60         };
61         OGLExt1CombType Combs[2];
62     };
63
64     union {
65         struct {
66             GLint   rgbArg0gl;
67             GLint   rgbArg1gl;
68             GLint   rgbArg2gl;
69         };
70         GLint glRGBArgs[3];
71     };
72
73     union {
74         struct {
75             GLint   rgbFlag0gl;
76             GLint   rgbFlag1gl;
77             GLint   rgbFlag2gl;
78         };
79         GLint glRGBFlags[3];
80     };
81
82     union {
83         struct {
84             GLint   alphaArg0gl;
85             GLint   alphaArg1gl;
86             GLint   alphaArg2gl;
87         };
88         GLint glAlphaArgs[3];
89     };
90
91     union {
92         struct {
93             GLint   alphaFlag0gl;
94             GLint   alphaFlag1gl;
95             GLint   alphaFlag2gl;
96         };
97         GLint glAlphaFlags[3];
98     };
99
100     int     tex;
101     bool    textureIsUsed;
102     //float scale;      //Will not be used
103 } OGLExtCombinerType;
104
105 typedef struct {
106     uint32  dwMux0;
107     uint32  dwMux1;
108     OGLExtCombinerType units[8];
109     int     numOfUnits;
110     uint32  constantColor;
111
112     // For 1.4 v2 combiner
113     bool    primIsUsed;
114     bool    envIsUsed;
115     bool    lodFracIsUsed;
116 } OGLExtCombinerSaveType;
117
118
119 //========================================================================
120 // OpenGL 1.4 combiner which support Texture Crossbar feature
121 class COGLColorCombiner4 : public COGLColorCombiner
122 {
123 public:
124     bool Initialize(void);
125 protected:
126     friend class OGLDeviceBuilder;
127     void InitCombinerCycle12(void);
128     void InitCombinerCycleFill(void);
129     virtual void GenerateCombinerSetting(int index);
130     virtual void GenerateCombinerSettingConstants(int index);
131     virtual int ParseDecodedMux();
132
133     COGLColorCombiner4(CRender *pRender);
134     ~COGLColorCombiner4() {};
135
136     bool m_bOGLExtCombinerSupported;        // Is this OGL extension combiner supported by the video card driver?
137     bool m_bSupportModAdd_ATI;
138     bool m_bSupportModSub_ATI;
139     GLint m_maxTexUnits;
140     int m_lastIndex;
141     uint32 m_dwLastMux0;
142     uint32 m_dwLastMux1;
143
144 #ifdef DEBUGGER
145     void DisplaySimpleMuxString(void);
146 #endif
147
148 protected:
149     virtual int SaveParsedResult(OGLExtCombinerSaveType &result);
150     static GLint MapRGBArgFlags(uint8 arg);
151     static GLint MapAlphaArgFlags(uint8 arg);
152     std::vector<OGLExtCombinerSaveType>     m_vCompiledSettings;
153     static GLint RGBArgsMap4[];
154     static const char* GetOpStr(GLenum op);
155
156 private:
157     virtual int ParseDecodedMux2Units();
158     virtual int FindCompiledMux();
159
160     virtual GLint MapRGBArgs(uint8 arg);
161     virtual GLint MapAlphaArgs(uint8 arg);
162 };
163
164
165 class COGLColorCombiner4v2 : public COGLColorCombiner4
166 {
167     /************************************************************************
168      * Version 2 of OGL 1.4 combiner
169      * Will support up to 4 texture units
170      * Texture unit 0 and 1 are for N64 texture T0 and T1
171      * Texture unit 2 and 3 will be used to map constant colors
172      * Constant color mapping:
173      *    OGL constant factor:      MUX_PRIM
174      *    ARB_TEXTURE2:             MUX_ENV
175      *    ARB_TEXTURE3:             MUX_LODFRAC
176      ************************************************************************/
177 protected:
178     friend class OGLDeviceBuilder;
179     virtual void GenerateCombinerSettingConstants(int index);
180     virtual int SaveParsedResult(OGLExtCombinerSaveType &result);
181
182     COGLColorCombiner4v2(CRender *pRender);
183     ~COGLColorCombiner4v2() {};
184
185     static GLint RGBArgsMap4v2[];
186
187 private:
188     virtual GLint MapRGBArgs(uint8 arg);
189     virtual GLint MapAlphaArgs(uint8 arg);
190 };
191
192 //////////////////////////////////////////////////////////////////////////
193 // OpenGL 1.2, 1.3 combiner which does not support Texture Crossbar feature
194 class COGLColorCombiner2 : public COGLColorCombiner4, CGeneralCombiner
195 {
196 public:
197     bool Initialize(void);
198
199 #ifdef DEBUGGER
200     void DisplaySimpleMuxString(void);
201 #endif
202
203 protected:
204     friend class OGLDeviceBuilder;
205
206     COGLColorCombiner2(CRender *pRender);
207     ~COGLColorCombiner2() {};
208
209 private:
210     virtual int ParseDecodedMux();
211     virtual void GenerateCombinerSetting(int index);
212     virtual void GenerateCombinerSettingConstants(int index);
213
214     virtual GLint MapRGBArgs(uint8 arg);
215     virtual GLint MapAlphaArgs(uint8 arg);
216     static GLint RGBArgsMap2[];
217 };
218
219
220 #endif
221