X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=source%2Frice_gles%2Fsrc%2FOGLExtRender.cpp;fp=source%2Frice_gles%2Fsrc%2FOGLExtRender.cpp;h=dc4eb59cfcb58d44a1713d7126c571519ba2f59a;hb=d07c171fa694cae985ad7045f9ce2b2f1a5699b4;hp=0000000000000000000000000000000000000000;hpb=ca22e7b76883b946060a6b40bb8709c1981e1cf6;p=mupen64plus-pandora.git diff --git a/source/rice_gles/src/OGLExtRender.cpp b/source/rice_gles/src/OGLExtRender.cpp new file mode 100755 index 0000000..dc4eb59 --- /dev/null +++ b/source/rice_gles/src/OGLExtRender.cpp @@ -0,0 +1,335 @@ +/* +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" + +#if SDL_VIDEO_OPENGL +#include "OGLExtensions.h" +#endif +#include "OGLDebug.h" +#include "OGLExtRender.h" +#include "OGLTexture.h" + +void COGLExtRender::Initialize(void) +{ + OGLRender::Initialize(); + + // Initialize multitexture + glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB,&m_maxTexUnits); + OPENGL_CHECK_ERRORS; + + for( int i=0; i<8; i++ ) + m_textureUnitMap[i] = -1; + m_textureUnitMap[0] = 0; // T0 is usually using texture unit 0 + m_textureUnitMap[1] = 1; // T1 is usually using texture unit 1 +} + + +void COGLExtRender::BindTexture(GLuint texture, int unitno) +{ + if( m_bEnableMultiTexture ) + { + if( unitno < m_maxTexUnits ) + { + if( m_curBoundTex[unitno] != texture ) + { + pglActiveTexture(GL_TEXTURE0_ARB+unitno); + OPENGL_CHECK_ERRORS; + glBindTexture(GL_TEXTURE_2D,texture); + OPENGL_CHECK_ERRORS; + m_curBoundTex[unitno] = texture; + } + } + } + else + { + OGLRender::BindTexture(texture, unitno); + } +} + +void COGLExtRender::DisBindTexture(GLuint texture, int unitno) +{ + if( m_bEnableMultiTexture ) + { + pglActiveTexture(GL_TEXTURE0_ARB+unitno); + OPENGL_CHECK_ERRORS; + glBindTexture(GL_TEXTURE_2D, 0); //Not to bind any texture + OPENGL_CHECK_ERRORS; + } + else + OGLRender::DisBindTexture(texture, unitno); +} + +void COGLExtRender::TexCoord2f(float u, float v) +{ +#if SDL_VIDEO_OPENGL + if( m_bEnableMultiTexture ) + { +//printf("*SEB* overloaded TexCoord2f(%f, %f)\n", u, v); + for( int i=0; i<8; i++ ) + { + if( m_textureUnitMap[i] >= 0 ) + { + pglMultiTexCoord2f(GL_TEXTURE0_ARB+i, u, v); + } + } + } + else + { + OGLRender::TexCoord2f(u,v); + } +#endif +} + +void COGLExtRender::TexCoord(TLITVERTEX &vtxInfo) +{ +#if SDL_VIDEO_OPENGL + if( m_bEnableMultiTexture ) + { +//printf("*SEB* overloaded TexCoord(%f, %f)\n", vtxInfo.tcord[0].u, vtxInfo.tcord[0].v); + for( int i=0; i<8; i++ ) + { + if( m_textureUnitMap[i] >= 0 ) + { + pglMultiTexCoord2fv(GL_TEXTURE0_ARB+i, &(vtxInfo.tcord[m_textureUnitMap[i]].u)); + } + } + } + else + { + OGLRender::TexCoord(vtxInfo); + } +#endif +} + + +void COGLExtRender::SetTexWrapS(int unitno,GLuint flag) +{ + static GLuint mflag[8]; + static GLuint mtex[8]; + if( m_curBoundTex[unitno] != mtex[unitno] || mflag[unitno] != flag ) + { + mtex[unitno] = m_curBoundTex[0]; + mflag[unitno] = flag; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, flag); + OPENGL_CHECK_ERRORS; + } +} +void COGLExtRender::SetTexWrapT(int unitno,GLuint flag) +{ + static GLuint mflag[8]; + static GLuint mtex[8]; + if( m_curBoundTex[unitno] != mtex[unitno] || mflag[unitno] != flag ) + { + mtex[unitno] = m_curBoundTex[0]; + mflag[unitno] = flag; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, flag); + OPENGL_CHECK_ERRORS; + } +} + +extern UVFlagMap OGLXUVFlagMaps[]; +void COGLExtRender::SetTextureUFlag(TextureUVFlag dwFlag, uint32 dwTile) +{ + TileUFlags[dwTile] = dwFlag; + if( !m_bEnableMultiTexture ) + { + OGLRender::SetTextureUFlag(dwFlag, dwTile); + return; + } + + int tex; + if( dwTile == gRSP.curTile ) + tex=0; + else if( dwTile == ((gRSP.curTile+1)&7) ) + tex=1; + else + { + if( dwTile == ((gRSP.curTile+2)&7) ) + tex=2; + else if( dwTile == ((gRSP.curTile+3)&7) ) + tex=3; + else + { + TRACE2("Incorrect tile number for OGL SetTextureUFlag: cur=%d, tile=%d", gRSP.curTile, dwTile); + return; + } + } + + for( int textureNo=0; textureNo<8; textureNo++) + { + if( m_textureUnitMap[textureNo] == tex ) + { + pglActiveTexture(GL_TEXTURE0_ARB+textureNo); + OPENGL_CHECK_ERRORS; + COGLTexture* pTexture = g_textures[(gRSP.curTile+tex)&7].m_pCOGLTexture; + if( pTexture ) + { + EnableTexUnit(textureNo,TRUE); + BindTexture(pTexture->m_dwTextureName, textureNo); + } + SetTexWrapS(textureNo, OGLXUVFlagMaps[dwFlag].realFlag); + } + } +} +void COGLExtRender::SetTextureVFlag(TextureUVFlag dwFlag, uint32 dwTile) +{ + TileVFlags[dwTile] = dwFlag; + if( !m_bEnableMultiTexture ) + { + OGLRender::SetTextureVFlag(dwFlag, dwTile); + return; + } + + int tex; + if( dwTile == gRSP.curTile ) + tex=0; + else if( dwTile == ((gRSP.curTile+1)&7) ) + tex=1; + else + { + if( dwTile == ((gRSP.curTile+2)&7) ) + tex=2; + else if( dwTile == ((gRSP.curTile+3)&7) ) + tex=3; + else + { + TRACE2("Incorrect tile number for OGL SetTextureVFlag: cur=%d, tile=%d", gRSP.curTile, dwTile); + return; + } + } + + for( int textureNo=0; textureNo<8; textureNo++) + { + if( m_textureUnitMap[textureNo] == tex ) + { + COGLTexture* pTexture = g_textures[(gRSP.curTile+tex)&7].m_pCOGLTexture; + if( pTexture ) + { + EnableTexUnit(textureNo,TRUE); + BindTexture(pTexture->m_dwTextureName, textureNo); + } + SetTexWrapT(textureNo, OGLXUVFlagMaps[dwFlag].realFlag); + } + } +} + +void COGLExtRender::EnableTexUnit(int unitno, BOOL flag) +{ + if( m_texUnitEnabled[unitno] != flag ) + { + m_texUnitEnabled[unitno] = flag; + pglActiveTexture(GL_TEXTURE0_ARB+unitno); + OPENGL_CHECK_ERRORS; + if( flag == TRUE ) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + OPENGL_CHECK_ERRORS; + } +} + +void COGLExtRender::ApplyTextureFilter() +{ + static uint32 minflag[8], magflag[8]; + static uint32 mtex[8]; + + int iMinFilter, iMagFilter; + + for( int i=0; i= -1 || tex <= 1)) + m_textureUnitMap[unit] = tex; +} +