GLE2RICE: Some fixes from muppen64plus-ae
[mupen64plus-pandora.git] / source / rice_gles / src / OGLRenderExt.cpp
CommitLineData
d07c171f 1/*
2Copyright (C) 2003 Rice1964
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#include "osal_opengl.h"
20
21#include "OGLRender.h"
22
23extern Matrix g_MtxReal;
24extern uObjMtxReal gObjMtxReal;
25
26//========================================================================
27
28void OGLRender::DrawText(const char* str, RECT *rect)
29{
30 return;
31}
32
33void 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 vertices[] = {
64 g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
65 g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z, 1,
66 g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
67
68 g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
69 g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
70 g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z, 1
71 };
72
73 glColorPointer(4, GL_FLOAT, 0, &colour );
74 glVertexPointer(4,GL_FLOAT, 0,&vertices);
75 if( m_bMultiTexture )
76 {
77 glClientActiveTexture( GL_TEXTURE1 );
78// if (m_texUnitEnabled[1])
79// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
80// glTexCoordPointer(2, GL_FLOAT, 0, &tex);
81// else
82 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
83 glClientActiveTexture( GL_TEXTURE0 );
84 }
85// if (m_texUnitEnabled[0])
86// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
87 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
88// else
89// glDisableClientState( GL_TEXTURE_COORD_ARRAY );
90 glDrawArrays(GL_TRIANGLES,0,6);
91 //Restore old pointers
92 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
93// if (m_texUnitEnabled[1])
94 glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
95// else
96// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
97 glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
98 if( m_bMultiTexture )
99 {
100 glClientActiveTexture( GL_TEXTURE1 );
101// if (m_texUnitEnabled[1])
102// glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
103// else
104 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
105 }
106#else
107 glBegin(GL_TRIANGLES);
108 glColor4fv(gRDP.fvPrimitiveColor);
109
110 OGLRender::TexCoord(g_texRectTVtx[0]);
111 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
112
113 OGLRender::TexCoord(g_texRectTVtx[1]);
114 glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
115
116 OGLRender::TexCoord(g_texRectTVtx[2]);
117 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
118
119 OGLRender::TexCoord(g_texRectTVtx[0]);
120 glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
121
122 OGLRender::TexCoord(g_texRectTVtx[2]);
123 glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
124
125 OGLRender::TexCoord(g_texRectTVtx[3]);
126 glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
127
128 glEnd();
129#endif
130#elif SDL_VIDEO_OPENGL_ES2
131
132 GLfloat colour[] = {
133 gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
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
137 gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
138 gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
139 gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
140 };
141
142 GLfloat tex[] = {
143 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
144 g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
145 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
146
147 g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
148 g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
149 g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
150 };
151
152 float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
153
154 GLfloat vertices[] = {
155 -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
156 -inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
157 -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
158
159 -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
160 -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
161 -inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
162 };
163
164
165 glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
166 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
167 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
168 //OPENGL_CHECK_ERRORS;
169 glDrawArrays(GL_TRIANGLES,0,6);
170 //OPENGL_CHECK_ERRORS;
171
172 //Restore old pointers
173 glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
174 glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
175 glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
176
177#endif
178
179 if( cullface ) glEnable(GL_CULL_FACE);
180}
181
182
183void OGLRender::DrawObjBGCopy(uObjBg &info)
184{
185 if( IsUsedAsDI(g_CI.dwAddr) )
186 {
187 DebugMessage(M64MSG_WARNING, "Unimplemented: write into Z buffer. Was mostly commented out in Rice Video 6.1.0");
188 return;
189 }
190 else
191 {
192 CRender::LoadObjBGCopy(info);
193 CRender::DrawObjBGCopy(info);
194 }
195}
196
197