GLES11RICE: Some fixes on multi texturing
[mupen64plus-pandora.git] / source / rice_gles / src / OGLRenderExt.cpp
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 #include "osal_opengl.h"
20
21 #include "OGLRender.h"
22
23 extern Matrix g_MtxReal;
24 extern uObjMtxReal gObjMtxReal;
25
26 //========================================================================
27
28 void OGLRender::DrawText(const char* str, RECT *rect)
29 {
30     return;
31 }
32
33 void OGLRender::DrawSpriteR_Render()    // With Rotation
34 {
35     glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
36
37     GLboolean cullface = glIsEnabled(GL_CULL_FACE);
38     glDisable(GL_CULL_FACE);
39
40 #if SDL_VIDEO_OPENGL
41
42 #ifdef HAVE_GLES
43     GLfloat colour[] = {
44             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
45             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
46             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
47
48             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
49             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
50             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
51     };
52
53     GLfloat tex[] = {
54             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
55             g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
56             g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
57
58             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
59             g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
60             g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
61     };
62
63     GLfloat tex2[] = {
64             g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
65             g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
66             g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
67
68             g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
69             g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
70             g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v,
71     };
72
73     GLfloat vertices[] = {
74             g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
75             g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z, 1,
76             g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
77
78             g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
79             g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
80             g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z, 1
81     };
82
83     glColorPointer(4, GL_FLOAT, 0, &colour );
84     glVertexPointer(4,GL_FLOAT, 0,&vertices);
85     if( m_bMultiTexture )
86     {
87                 glClientActiveTexture( GL_TEXTURE1 );
88                 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
89                 glTexCoordPointer(2, GL_FLOAT, 0, &tex2);
90         glClientActiveTexture( GL_TEXTURE0 );
91     }
92         glTexCoordPointer(2, GL_FLOAT, 0, &tex);
93     glDrawArrays(GL_TRIANGLES,0,6);
94     //Restore old pointers
95     glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
96         glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
97     glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
98     if( m_bMultiTexture )
99     {
100                 glClientActiveTexture( GL_TEXTURE1 );
101                 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
102     }
103 #else
104     glBegin(GL_TRIANGLES);
105     glColor4fv(gRDP.fvPrimitiveColor);
106
107     OGLRender::TexCoord(g_texRectTVtx[0]);
108     glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
109
110     OGLRender::TexCoord(g_texRectTVtx[1]);
111     glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
112
113     OGLRender::TexCoord(g_texRectTVtx[2]);
114     glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
115
116     OGLRender::TexCoord(g_texRectTVtx[0]);
117     glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
118
119     OGLRender::TexCoord(g_texRectTVtx[2]);
120     glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
121
122     OGLRender::TexCoord(g_texRectTVtx[3]);
123     glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
124
125     glEnd();
126 #endif
127 #elif SDL_VIDEO_OPENGL_ES2
128
129     GLfloat colour[] = {
130             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
131             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
132             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
133
134             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
135             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
136             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
137     };
138
139     GLfloat tex[] = {
140             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
141             g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
142             g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
143
144             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
145             g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
146             g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
147     };
148
149      float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
150
151     GLfloat vertices[] = {
152             -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
153             -inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
154             -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
155
156             -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
157             -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
158             -inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
159     };
160
161
162     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
163     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
164     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
165     //OPENGL_CHECK_ERRORS;
166     glDrawArrays(GL_TRIANGLES,0,6);
167     //OPENGL_CHECK_ERRORS;
168
169     //Restore old pointers
170     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
171     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
172     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
173
174 #endif
175
176     if( cullface ) glEnable(GL_CULL_FACE);
177 }
178
179
180 void OGLRender::DrawObjBGCopy(uObjBg &info)
181 {
182     if( IsUsedAsDI(g_CI.dwAddr) )
183     {
184         DebugMessage(M64MSG_WARNING, "Unimplemented: write into Z buffer.  Was mostly commented out in Rice Video 6.1.0");
185         return;
186     }
187     else
188     {
189         CRender::LoadObjBGCopy(info);
190         CRender::DrawObjBGCopy(info);
191     }
192 }
193
194