Rice Video Plugin for GLES1.1
[mupen64plus-pandora.git] / source / rice_gles / src / OGLRenderExt.cpp
diff --git a/source/rice_gles/src/OGLRenderExt.cpp b/source/rice_gles/src/OGLRenderExt.cpp
new file mode 100755 (executable)
index 0000000..65e6843
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+Copyright (C) 2003 Rice1964
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#include "osal_opengl.h"
+
+#include "OGLRender.h"
+
+extern Matrix g_MtxReal;
+extern uObjMtxReal gObjMtxReal;
+
+//========================================================================
+
+void OGLRender::DrawText(const char* str, RECT *rect)
+{
+    return;
+}
+
+void OGLRender::DrawSpriteR_Render()    // With Rotation
+{
+    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
+
+    GLboolean cullface = glIsEnabled(GL_CULL_FACE);
+    glDisable(GL_CULL_FACE);
+
+#if SDL_VIDEO_OPENGL
+
+#ifdef HAVE_GLES
+    GLfloat colour[] = {
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+    };
+
+    GLfloat tex[] = {
+            g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
+            g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
+            g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
+
+            g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
+            g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
+            g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
+    };
+
+    GLfloat vertices[] = {
+            g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
+            g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z, 1,
+            g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
+
+            g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z, 1,
+            g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z, 1,
+            g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z, 1
+    };
+
+    glColorPointer(4, GL_FLOAT, 0, &colour );
+    glVertexPointer(4,GL_FLOAT, 0,&vertices);
+    if( m_bMultiTexture )
+    {
+               glClientActiveTexture( GL_TEXTURE1 );
+//             if (m_texUnitEnabled[1])
+//                     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+//                     glTexCoordPointer(2, GL_FLOAT, 0, &tex);
+//             else
+                       glDisableClientState( GL_TEXTURE_COORD_ARRAY );
+        glClientActiveTexture( GL_TEXTURE0 );
+    }
+//     if (m_texUnitEnabled[0])
+//     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+               glTexCoordPointer(2, GL_FLOAT, 0, &tex);
+//     else
+//             glDisableClientState( GL_TEXTURE_COORD_ARRAY );
+    glDrawArrays(GL_TRIANGLES,0,6);
+    //Restore old pointers
+    glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
+//     if (m_texUnitEnabled[1])
+               glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
+//     else
+//             glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+    glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
+    if( m_bMultiTexture )
+    {
+               glClientActiveTexture( GL_TEXTURE1 );
+//             if (m_texUnitEnabled[1])
+//                     glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
+//             else
+                       glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+    }
+#else
+    glBegin(GL_TRIANGLES);
+    glColor4fv(gRDP.fvPrimitiveColor);
+
+    OGLRender::TexCoord(g_texRectTVtx[0]);
+    glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
+
+    OGLRender::TexCoord(g_texRectTVtx[1]);
+    glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
+
+    OGLRender::TexCoord(g_texRectTVtx[2]);
+    glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
+
+    OGLRender::TexCoord(g_texRectTVtx[0]);
+    glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
+
+    OGLRender::TexCoord(g_texRectTVtx[2]);
+    glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
+
+    OGLRender::TexCoord(g_texRectTVtx[3]);
+    glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
+
+    glEnd();
+#endif
+#elif SDL_VIDEO_OPENGL_ES2
+
+    GLfloat colour[] = {
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+            gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
+    };
+
+    GLfloat tex[] = {
+            g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
+            g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
+            g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
+
+            g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
+            g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
+            g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
+    };
+
+     float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
+
+    GLfloat vertices[] = {
+            -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
+            -inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
+            -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
+
+            -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
+            -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
+            -inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
+    };
+
+
+    glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
+    glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
+    glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
+    //OPENGL_CHECK_ERRORS;
+    glDrawArrays(GL_TRIANGLES,0,6);
+    //OPENGL_CHECK_ERRORS;
+
+    //Restore old pointers
+    glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
+    glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
+    glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
+
+#endif
+
+    if( cullface ) glEnable(GL_CULL_FACE);
+}
+
+
+void OGLRender::DrawObjBGCopy(uObjBg &info)
+{
+    if( IsUsedAsDI(g_CI.dwAddr) )
+    {
+        DebugMessage(M64MSG_WARNING, "Unimplemented: write into Z buffer.  Was mostly commented out in Rice Video 6.1.0");
+        return;
+    }
+    else
+    {
+        CRender::LoadObjBGCopy(info);
+        CRender::DrawObjBGCopy(info);
+    }
+}
+
+