From 7b5aaf7e0fc8c267d90ded3a2b41a7d87e2f9cc5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 24 Sep 2013 23:58:32 +0200 Subject: [PATCH] Some cleanup, most of the old OpenGL stuff should be gone. --HG-- branch : gsoc2013-dfighter --- .../src/3d/driver/OpenGL3/driver_opengl.cpp | 53 -- .../nel/src/3d/driver/OpenGL3/driver_opengl.h | 99 +--- .../3d/driver/OpenGL3/driver_opengl_light.cpp | 186 ------ .../driver/OpenGL3/driver_opengl_material.cpp | 135 +---- .../driver/OpenGL3/driver_opengl_matrix.cpp | 82 --- .../driver/OpenGL3/driver_opengl_program.cpp | 8 - .../driver/OpenGL3/driver_opengl_states.cpp | 309 +--------- .../driver/OpenGL3/driver_opengl_texture.cpp | 123 ---- .../driver/OpenGL3/driver_opengl_vertex.cpp | 215 +------ .../OpenGL3/driver_opengl_vertex_program.cpp | 536 ------------------ 10 files changed, 21 insertions(+), 1725 deletions(-) diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp index 70f16a878..fcf54fb12 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp @@ -232,13 +232,7 @@ CDriverGL3::CDriverGL3() _RenderTargetFBO = false; - _LightSetupDirty= false; - _ModelViewMatrixDirty= false; - _RenderSetupDirty= false; - // All lights default pos. uint i; - for(i=0;i _LastSetuppedVP; @@ -1347,7 +1293,6 @@ private: // user texture matrix NLMISC::CMatrix _UserTexMat[IDRV_MAT_MAXTEXTURES]; - bool _UserTexMatDirty[IDRV_MAT_MAXTEXTURES]; uint _UserTexMatEnabled; // bitm ask for user texture coords // Static const @@ -1372,7 +1317,6 @@ private: private: -#ifdef GLSL CGLSLShaderGenerator *shaderGenerator; CUsrShaderManager *usrShaderManager; @@ -1381,9 +1325,6 @@ private: /// The current user shader program IProgramObject *dynMatProgram; -#endif - - bool setupARBVertexProgram (const CVPParser::TProgram &parsedProgram, GLuint id, bool &specularWritten); // init EMBM settings (set each stage to modify the next) void initEMBM(); @@ -1477,20 +1418,6 @@ public: }; -// *************************************************************************** -class CVertexProgamDrvInfosGL3 : public IVertexProgramDrvInfos -{ -public: - // The GL Id. - GLuint ID; - - // ARB_vertex_program specific -> must know if specular part is written - bool SpecularWritten; - - // The gl id is auto created here. - CVertexProgamDrvInfosGL3 (CDriverGL3 *drv, ItVtxPrgDrvInfoPtrList it); -}; - #ifdef NL_STATIC } // NLDRIVERGL/ES #endif diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp index d0f946b5c..f80d0a937 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp @@ -69,54 +69,7 @@ void CDriverGL3::setLightInternal(uint8 num, const CLight& light) // Copy the mode _LightMode[num]=mode; -#ifdef GLSL _UserLight[num] = light; -#endif - -#ifndef GLSL - // Set the ambiant color - GLfloat colorGL[4]; - CRGBA colorNeL=light.getAmbiant (); - colorGL[0]=(float)colorNeL.R/255.f; - colorGL[1]=(float)colorNeL.G/255.f; - colorGL[2]=(float)colorNeL.B/255.f; - colorGL[3]=1.f; - glLightfv (lightNum, GL_AMBIENT, colorGL); - - // Set the diffuse color - colorNeL=light.getDiffuse (); - colorGL[0]=(float)colorNeL.R/255.f; - colorGL[1]=(float)colorNeL.G/255.f; - colorGL[2]=(float)colorNeL.B/255.f; - colorGL[3]=1.f; - glLightfv (lightNum, GL_DIFFUSE, colorGL); - - // Set the specular color - colorNeL=light.getSpecular (); - // don't know why, but with ATI cards, specular of 0 causes incorrect rendering (random specular is added) - if (_Extensions.ATITextureEnvCombine3) - { - // special case for ATI (there will be some specular, but there's a bug otherwise) - colorGL[0]=std::max(1.f / 1024.f, (float)colorNeL.R/255.f); - colorGL[1]=std::max(1.f / 1024.f, (float)colorNeL.G/255.f); - colorGL[2]=std::max(1.f / 1024.f, (float)colorNeL.B/255.f); - colorGL[3]=1.f; - } - else - { - colorGL[0]=(float)colorNeL.R/255.f; - colorGL[1]=(float)colorNeL.G/255.f; - colorGL[2]=(float)colorNeL.B/255.f; - colorGL[3]=1.f; - } - glLightfv (lightNum, GL_SPECULAR, colorGL); - - // Set light attenuation - glLightf (lightNum, GL_CONSTANT_ATTENUATION, light.getConstantAttenuation()); - glLightf (lightNum, GL_LINEAR_ATTENUATION, light.getLinearAttenuation()); - glLightf (lightNum, GL_QUADRATIC_ATTENUATION, light.getQuadraticAttenuation()); - -#endif // Set the position if ((mode==CLight::DirectionalLight)||(mode==CLight::SpotLight)) @@ -136,35 +89,11 @@ void CDriverGL3::setLightInternal(uint8 num, const CLight& light) // Get the exponent of the spot float exponent=light.getExponent (); -#ifndef GLSL - // Set it - glLightf (lightNum, GL_SPOT_EXPONENT, exponent); -#endif - // Get the cutoff of the spot float cutoff=180.f*(light.getCutoff ()/(float)NLMISC::Pi); -#ifndef GLSL - // Set it - glLightf (lightNum, GL_SPOT_CUTOFF, cutoff); -#endif - - } - else - { -#ifndef GLSL - // Disable spot properties - glLighti (lightNum, GL_SPOT_CUTOFF, 180); - glLighti (lightNum, GL_SPOT_EXPONENT, 0); -#endif } - // Flag this light as dirt. - _LightDirty[num]= true; - - // dirt the lightSetup and hence the render setup - _LightSetupDirty= true; - _RenderSetupDirty=true; } } @@ -198,12 +127,6 @@ void CDriverGL3::enableLightInternal(uint8 num, bool enable) { _DriverGLStates.enableLight(num, enable); - // If this light is dirty, and reenabled, then it must be refresh at next render => set the global flag. - if (enable && _LightDirty[num]) - { - _LightSetupDirty= true; - _RenderSetupDirty= true; - } } } @@ -214,112 +137,6 @@ void CDriverGL3::setAmbientColor (CRGBA color) { H_AUTO_OGL(CDriverGL3_setAmbientColor ) -#ifndef GLSL - // Gl array - GLfloat array[4]; - array[0]=(float)color.R/255.f; - array[1]=(float)color.G/255.f; - array[2]=(float)color.B/255.f; - array[3]=1.f; - - // Set the color - glLightModelfv (GL_LIGHT_MODEL_AMBIENT, array); -#endif - -} - - -// *************************************************************************** -void CDriverGL3::cleanLightSetup () -{ - H_AUTO_OGL(CDriverGL3_cleanLightSetup ) - // Should be dirty - nlassert (_LightSetupDirty); - -#ifndef GLSL - - // First light - bool first=true; - - // For each lights - for (uint i=0; i<_MaxDriverLight; i++) - { - // Is this light enabled and dirty? - if (_DriverGLStates.isLightEnabled(i) && _LightDirty[i]) - { - // If first light - if (first) - { - first=false; - - // Push the matrix - glPushMatrix (); - - // Load the view matrix - glLoadMatrixf (_ViewMtx.get()); - } - - // Light is directionnal ? - if (_LightMode[i]==(uint)CLight::DirectionalLight) - { - // GL vector - GLfloat vectorGL[4]; - - // Set the GL array - vectorGL[0]=-_WorldLightDirection[i].x; - vectorGL[1]=-_WorldLightDirection[i].y; - vectorGL[2]=-_WorldLightDirection[i].z; - vectorGL[3]=0.f; - - // Set it - glLightfv ((GLenum)(GL_LIGHT0+i), (GLenum)GL_POSITION, vectorGL); - } - - // Spotlight ? - if (_LightMode[i]==(uint)CLight::SpotLight) - { - // GL vector - GLfloat vectorGL[4]; - - // Set the GL array - vectorGL[0]=_WorldLightDirection[i].x; - vectorGL[1]=_WorldLightDirection[i].y; - vectorGL[2]=_WorldLightDirection[i].z; - - // Set it - glLightfv ((GLenum)(GL_LIGHT0+i), (GLenum)GL_SPOT_DIRECTION, vectorGL); - } - - // Position - if (_LightMode[i]!=(uint)CLight::DirectionalLight) - { - // GL vector - GLfloat vectorGL[4]; - - // Set the GL array - // Must Substract CameraPos, because ViewMtx may not be the exact view. - vectorGL[0]=_WorldLightPos[i].x - _PZBCameraPos.x; - vectorGL[1]=_WorldLightPos[i].y - _PZBCameraPos.y; - vectorGL[2]=_WorldLightPos[i].z - _PZBCameraPos.z; - vectorGL[3]=1.f; - - // Set it - glLightfv ((GLenum)(GL_LIGHT0+i), (GLenum)GL_POSITION, vectorGL); - } - - // Cleaned! - _LightDirty[i]= false; - } - } - - // Pop old matrix - if (!first) - glPopMatrix (); - -#endif - - // Clean flag - _LightSetupDirty=false; } @@ -371,9 +188,6 @@ void CDriverGL3::setupLightMapDynamicLighting(bool enable) for(uint i=0;i<_MaxDriverLight;i++) enableLightInternal(i, _UserLightEnable[i]); } - - // in all case, must refresh render setup, cause lighting may be modified - refreshRenderSetup(); } #ifdef NL_STATIC diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp index 9c29c8459..73ddcb483 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp @@ -176,7 +176,6 @@ void CDriverGL3::setupUserTextureMatrix(uint numStages, CMaterial& mat) if (newMask & shiftMask) // user matrix for this stage { _UserTexMat[ k ] = mat.getUserTexMat( k ); - _UserTexMatDirty[ k ] = true; _UserTexMatEnabled |= shiftMask; } else @@ -187,7 +186,6 @@ void CDriverGL3::setupUserTextureMatrix(uint numStages, CMaterial& mat) ) { _UserTexMat[ k ].identity(); - _UserTexMatDirty[ k ] = true; _UserTexMatEnabled &= ~shiftMask; } } @@ -207,7 +205,6 @@ void CDriverGL3::disableUserTextureMatrix() if (_UserTexMatEnabled & (1 << k)) // user matrix for this stage { _UserTexMat[ k ].identity(); - _UserTexMatDirty[ k ] = true; _UserTexMatEnabled &= ~ (1 << k); } ++k; @@ -236,16 +233,12 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) { H_AUTO_OGL(CDriverGL3_setupMaterial) -#ifdef GLSL - if( mat.getDynMat() != NULL ) { _CurrentMaterial = &mat; return true; } -#endif - CShaderGL3* pShader; GLenum glenum = GL_ZERO; uint32 touched = mat.getTouched(); @@ -390,11 +383,6 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) // activate the texture, or disable texturing if NULL. activateTexture(stage,text); -#ifndef GLSL - // If texture not NULL, Change texture env function. - //================================================== - setTextureEnvFunction(stage, mat); -#endif } } @@ -458,12 +446,6 @@ bool CDriverGL3::setupMaterial(CMaterial& mat) } else { -#ifndef GLSL - // Color unlit part. - CRGBA col= mat.getColor(); - glColor4ub(col.R, col.G, col.B, col.A); -#endif - _DriverGLStates.setVertexColorLighted(false); } @@ -510,10 +492,8 @@ sint CDriverGL3::beginMultiPass() { H_AUTO_OGL(CDriverGL3_beginMultiPass) -#ifdef GLSL if( _CurrentMaterial->getDynMat() != NULL ) return _CurrentMaterial->getDynMat()->getPassCount(); -#endif // Depending on material type and hardware, return number of pass required to draw this material. switch(_CurrentMaterialSupportedShader) @@ -543,12 +523,9 @@ bool CDriverGL3::setupPass(uint pass) { H_AUTO_OGL(CDriverGL3_setupPass) -#ifdef GLSL if( _CurrentMaterial->getDynMat() != NULL ) return setupDynMatPass( pass ); -#endif - switch(_CurrentMaterialSupportedShader) { case CMaterial::Normal: @@ -585,10 +562,8 @@ void CDriverGL3::endMultiPass() { H_AUTO_OGL(CDriverGL3_endMultiPass) -#ifdef GLSL if( _CurrentMaterial->getDynMat() != NULL ) return; -#endif switch(_CurrentMaterialSupportedShader) { @@ -620,7 +595,6 @@ void CDriverGL3::endMultiPass() bool CDriverGL3::setupDynMatPass( uint pass ) { -#ifdef GLSL if( !setupDynMatProgram( *_CurrentMaterial, pass ) ) return false; @@ -705,7 +679,6 @@ bool CDriverGL3::setupDynMatPass( uint pass ) //////////////////////////////////////////////////////////////////////////////////////////////////// -#endif return true; } @@ -913,7 +886,7 @@ void CDriverGL3::setupLightMapPass(uint pass) // setup constant color with Lightmap factor. stdEnv.ConstantColor=lmapFactor; -#ifdef GLSL + int cl = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Constant0 + stage ) ); if( cl != -1 ) { @@ -927,7 +900,7 @@ void CDriverGL3::setupLightMapPass(uint pass) { setUniform1i( tl, stage ); } -#endif + activateTexEnvColor(stage, stdEnv); // Setup env for texture stage. @@ -939,26 +912,6 @@ void CDriverGL3::setupLightMapPass(uint pass) { // TexEnv is special. _CurrentTexEnvSpecial[stage] = TexEnvSpecialLightMap; - -#ifndef GLSL - { - // ATI EnvCombine3 - // What we want to setup is Texture*Constant + Previous. - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); - // Operator. - glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE_ADD_ATI); - glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE_ADD_ATI); - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR); - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_CONSTANT_EXT ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR); - // Arg2. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR); - } -#endif } } @@ -990,13 +943,11 @@ void CDriverGL3::setupLightMapPass(uint pass) _DriverGLStates.activeTextureARB(stage); _DriverGLStates.setTexGenMode(stage, 0); -#ifdef GLSL int tl = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Sampler0 + stage ) ); if( tl != -1 ) { setUniform1i( tl, stage ); } -#endif // setup UV, with UV0. Only if needed (cached) if( !_LastVertexSetupIsLightMap || _LightMapUVMap[stage]!=0 ) @@ -1005,14 +956,6 @@ void CDriverGL3::setupLightMapPass(uint pass) _LightMapUVMap[stage]= 0; } -#ifndef GLSL - if (mat._LightMapsMulx2) - { - // Multiply x 2 - glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2); - } -#endif - } } else @@ -1028,13 +971,6 @@ void CDriverGL3::setupLightMapPass(uint pass) /* If multi-pass, then must setup a black Fog color for 1+ pass (just do it for the pass 1). This is because Transparency ONE/ONE is used. */ -#ifndef GLSL - if(pass==1 && _FogEnabled) - { - static GLfloat blackFog[4]= {0,0,0,0}; - glFogfv(GL_FOG_COLOR, blackFog); - } -#endif // Blend is different if the material is blended or not if( !mat.getBlend() ) @@ -1106,29 +1042,10 @@ void CDriverGL3::endLightMapMultiPass() if(_NLightMaps!=0) _LastVertexSetupIsLightMap= true; - // If multi-pass, then must reset the fog color - if(_NLightMapPass>=2 && _FogEnabled) - { -#ifndef GLSL - glFogfv(GL_FOG_COLOR, _CurrentFogColor); -#endif - } - // nothing to do with blending/lighting, since always setuped in activeMaterial(). // If material is the same, then it is still a lightmap material (if changed => touched => different!) // So no need to reset blending/lighting here. - // Clean up all stage for Multiply x 2 - if (_CurrentMaterial->_LightMapsMulx2) - { -#ifndef GLSL - for (uint32 i = 0; i < (_NLightMapPerPass+1); ++i) - { - _DriverGLStates.activeTextureARB(i); - glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1); - } -#endif - } } // *************************************************************************** @@ -1198,15 +1115,8 @@ void CDriverGL3::setupSpecularBegin() // For all cases, setup the TexCoord gen for stage1 _DriverGLStates.activeTextureARB(1); -#ifndef GLSL - // todo hulud remove - // _DriverGLStates.setTextureMode(CDriverGLStates3::TextureCubeMap); - _DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_ARB); -#endif - // setup the good matrix for stage 1. _UserTexMat[ 1 ] = _SpecularTexMtx; - _UserTexMatDirty[ 1 ] = true; } @@ -1220,7 +1130,6 @@ void CDriverGL3::setupSpecularEnd() // Happiness !!! we have already enabled the stage 1 _UserTexMat[ 1 ].identity(); - _UserTexMatDirty[ 1 ] = true; } // *************************************************************************** @@ -1268,8 +1177,6 @@ void CDriverGL3::setupSpecularPass(uint pass) return; } -#ifdef GLSL - int sl0 = currentProgram->getUniformIndex( IProgramObject::Sampler0 ); if( sl0 != -1 ) { @@ -1288,8 +1195,6 @@ void CDriverGL3::setupSpecularPass(uint pass) setUniformMatrix4fv( tml, 1, false, _UserTexMat[ 1 ].get() ); } -#endif - { // Ok we can do it in a single pass @@ -1308,42 +1213,6 @@ void CDriverGL3::setupSpecularPass(uint pass) _DriverGLStates.activeTextureARB(1); -#ifndef GLSL - - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); - // Operator Add (Arg0*Arg2+Arg1) - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE_ADD_ATI ); - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE_ADD_ATI ); - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR ); - // Arg2. - if( newEnvStage1 == TexEnvSpecialSpecularStage1NoText ) - { - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_ZERO ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_ONE_MINUS_SRC_COLOR); - } - else - { - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PREVIOUS_EXT ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA ); - } - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR ); - // Result : Texture*Previous.Alpha+Previous - // Setup Alpha Diffuse Copy - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA ); - // Arg2. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, GL_ZERO ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA ); - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_ZERO ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA); - -#endif - } } } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp index 1f47f0814..4d6721fdc 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp @@ -33,7 +33,6 @@ void CDriverGL3::setFrustum(float left, float right, float bottom, float top, fl else _GLProjMat.ortho( left, right, bottom, top, znear, zfar ); - _ProjMatDirty = true; _OODeltaZ = 1 / ( zfar - znear ); } @@ -45,8 +44,6 @@ void CDriverGL3::setFrustumMatrix(CMatrix &frustumMatrix) H_AUTO_OGL(CDriverGL3_setFrustum) _GLProjMat = frustumMatrix; - _ProjMatDirty = true; - } // *************************************************************************** @@ -77,14 +74,6 @@ void CDriverGL3::setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos) _ViewMtx.setPos(CVector::Null); _PZBCameraPos= cameraPos; - // Anything that depend on the view martix must be updated. - _LightSetupDirty= true; - _ModelViewMatrixDirty= true; - _RenderSetupDirty= true; - // All lights must be refresh. - for(uint i=0;igetUniformIndex( IProgramObject::MVPMatrix ); if( mvpIndex != -1 ) { @@ -542,7 +535,6 @@ namespace NL3D } -#endif } } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp index 42eb88dba..809a2707e 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp @@ -120,11 +120,6 @@ void CDriverGLStates3::forceDefaults(uint nbStages) glStencilFunc(_CurStencilFunc, _CurStencilRef, _CurStencilMask); glStencilOp(_CurStencilOpFail, _CurStencilOpZFail, _CurStencilOpZPass); glStencilMask(_CurStencilWriteMask); -#ifndef GLSL - glAlphaFunc(GL_GREATER, _CurAlphaTestThreshold); -#endif - - // Materials. uint32 packedOne= (CRGBA(255,255,255,255)).getPacked(); @@ -142,13 +137,6 @@ void CDriverGLStates3::forceDefaults(uint nbStages) // setup GLStates. static const GLfloat one[4]= {1,1,1,1}; static const GLfloat zero[4]= {0,0,0,1}; -#ifndef GLSL - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, zero); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, one); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, one); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, _CurShininess); -#endif // TexModes uint stage; @@ -298,13 +286,6 @@ void CDriverGLStates3::enableLight(uint num, uint enable) { // new state. _CurLight[num]= enabled; - // Setup GLState. -#ifndef GLSL - if(_CurLight[num]) - glEnable ((GLenum)(GL_LIGHT0+num)); - else - glDisable ((GLenum)(GL_LIGHT0+num)); -#endif } } @@ -425,10 +406,6 @@ void CDriverGLStates3::alphaFunc(float threshold) { // new state _CurAlphaTestThreshold= threshold; - // setup function. -#ifndef GLSL - glAlphaFunc(GL_GREATER, _CurAlphaTestThreshold); -#endif } } @@ -496,9 +473,6 @@ void CDriverGLStates3::setEmissive(uint32 packedColor, const GLfloat color[4]) #endif { _CurEmissive= packedColor; -#ifndef GLSL - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); -#endif } } @@ -511,9 +485,6 @@ void CDriverGLStates3::setAmbient(uint32 packedColor, const GLfloat color[4]) #endif { _CurAmbient= packedColor; -#ifndef GLSL - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); -#endif } } @@ -526,9 +497,6 @@ void CDriverGLStates3::setDiffuse(uint32 packedColor, const GLfloat color[4]) #endif { _CurDiffuse= packedColor; -#ifndef GLSL - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); -#endif } } @@ -541,9 +509,6 @@ void CDriverGLStates3::setSpecular(uint32 packedColor, const GLfloat color[4]) #endif { _CurSpecular= packedColor; -#ifndef GLSL - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); -#endif } } @@ -556,9 +521,6 @@ void CDriverGLStates3::setShininess(float shin) #endif { _CurShininess= shin; -#ifndef GLSL - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin); -#endif } } @@ -583,29 +545,6 @@ void CDriverGLStates3::setVertexColorLighted(bool enable) #endif { _VertexColorLighted= enable; - -#ifndef GLSL - - if (_VertexColorLighted) - { - glEnable (GL_COLOR_MATERIAL); - glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); - } - else - { - glDisable (GL_COLOR_MATERIAL); - // Since we leave glColorMaterial mode, GL diffuse is now scracth. reset him to current value. - CRGBA diffCol; - diffCol.R= (uint8)((_CurDiffuse >> 24) & 255); - diffCol.G= (uint8)((_CurDiffuse >> 16) & 255); - diffCol.B= (uint8)((_CurDiffuse >> 8) & 255); - diffCol.A= (uint8)((_CurDiffuse ) & 255); - GLfloat glColor[4]; - convColor(diffCol, glColor); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, glColor); - } - -#endif } } @@ -660,48 +599,6 @@ void CDriverGLStates3::setTexGenMode (uint stage, GLint mode) #endif { _TexGenMode[stage] = mode; - -#ifndef GLSL - - if (!_TextureCubeMapSupported) return; - - if(mode==0) - { - glDisable( GL_TEXTURE_GEN_S ); - glDisable( GL_TEXTURE_GEN_T ); - glDisable( GL_TEXTURE_GEN_R ); - glDisable( GL_TEXTURE_GEN_Q ); - } - else - { - glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, mode); - glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, mode); - glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, mode); - - /* Object or Eye Space ? => enable W generation. VERY IMPORTANT because - was a bug with VegetableRender and ShadowRender: - - Vegetable use the TexCoord1.w in his VertexProgram - - Shadow Render don't use any TexCoord in VB (since projected) - => TexCoord1.w dirty!! - */ - - if(mode==GL_OBJECT_LINEAR || mode==GL_EYE_LINEAR) - { - glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, mode); - glEnable( GL_TEXTURE_GEN_Q ); - } - else - { - glDisable( GL_TEXTURE_GEN_Q ); - } - - // Enable All. - glEnable( GL_TEXTURE_GEN_S ); - glEnable( GL_TEXTURE_GEN_T ); - glEnable( GL_TEXTURE_GEN_R ); - } -#endif - } } @@ -710,22 +607,6 @@ void CDriverGLStates3::resetTextureMode() { H_AUTO_OGL(CDriverGLStates3_resetTextureMode); -#ifndef GLSL - - glDisable(GL_TEXTURE_2D); - - if (_TextureCubeMapSupported) - { - glDisable(GL_TEXTURE_CUBE_MAP_ARB); - } - - if (_TextureRectangleSupported) - { - glDisable(GL_TEXTURE_RECTANGLE_NV); - } - -#endif - _TextureMode[_CurrentActiveTextureARB]= TextureDisabled; } @@ -738,67 +619,7 @@ void CDriverGLStates3::setTextureMode(TTextureMode texMode) if(oldTexMode != texMode) { -#ifndef GLSL - - // Disable first old mode. - if (oldTexMode == Texture2D) - { - glDisable(GL_TEXTURE_2D); - } - else if(oldTexMode == TextureRect) - { - if(_TextureRectangleSupported) - { - glDisable(GL_TEXTURE_RECTANGLE_NV); - } - else - { - glDisable(GL_TEXTURE_2D); - } - } - else if(oldTexMode == TextureCubeMap) - { - if(_TextureCubeMapSupported) - { - glDisable(GL_TEXTURE_CUBE_MAP_ARB); - } - else - { - glDisable(GL_TEXTURE_2D); - } - } - - // Enable new mode. - if(texMode == Texture2D) - { - glEnable(GL_TEXTURE_2D); - } - else if(texMode == TextureRect) - { - if(_TextureRectangleSupported) - { - glEnable(GL_TEXTURE_RECTANGLE_NV); - } - else - { - glEnable(GL_TEXTURE_2D); - } - } - else if(texMode == TextureCubeMap) - { - if(_TextureCubeMapSupported) - { - glEnable(GL_TEXTURE_CUBE_MAP_ARB); - } - else - { - glEnable(GL_TEXTURE_2D); - } - } - -#endif - - // new mode. + // new mode. _TextureMode[_CurrentActiveTextureARB]= texMode; } } @@ -830,158 +651,43 @@ void CDriverGLStates3::forceActiveTextureARB(uint stage) // *************************************************************************** void CDriverGLStates3::enableVertexArray(bool enable) { -#ifndef GLSL - - H_AUTO_OGL(CDriverGLStates3_enableVertexArray); - - if(_VertexArrayEnabled != enable) - { - if(enable) - glEnableClientState(GL_VERTEX_ARRAY); - else - glDisableClientState(GL_VERTEX_ARRAY); - - _VertexArrayEnabled= enable; - } - -#endif - } + // *************************************************************************** void CDriverGLStates3::enableNormalArray(bool enable) { -#ifndef GLSL - - H_AUTO_OGL(CDriverGLStates3_enableNormalArray) - if(_NormalArrayEnabled != enable) - { - if(enable) - glEnableClientState(GL_NORMAL_ARRAY); - else - glDisableClientState(GL_NORMAL_ARRAY); - _NormalArrayEnabled= enable; - - - } - -#endif - } + // *************************************************************************** void CDriverGLStates3::enableWeightArray(bool enable) { -#ifndef GLSL - H_AUTO_OGL(CDriverGLStates3_enableWeightArray); - - if(_WeightArrayEnabled != enable) - { - if(enable) - glEnableClientState(GL_VERTEX_WEIGHTING_EXT); - else - glDisableClientState(GL_VERTEX_WEIGHTING_EXT); - - _WeightArrayEnabled= enable; - } -#endif - } + // *************************************************************************** void CDriverGLStates3::enableColorArray(bool enable) { -#ifndef GLSL - H_AUTO_OGL(CDriverGLStates3_enableColorArray); - - if(_ColorArrayEnabled != enable) - { - if(enable) - glEnableClientState(GL_COLOR_ARRAY); - else - glDisableClientState(GL_COLOR_ARRAY); - _ColorArrayEnabled= enable; - - - } -#endif - } // *************************************************************************** void CDriverGLStates3::enableSecondaryColorArray(bool enable) { -#ifndef GLSL - H_AUTO_OGL(CDriverGLStates3_enableSecondaryColorArray); - - if(_SecondaryColorArrayEnabled != enable) - { - if(enable) - glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT); - else - glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT); - - _SecondaryColorArrayEnabled= enable; - - // If disable - if(!enable) - { - // GeForceFx Bug: Must reset Secondary color to 0 (if comes from a VP), else bugs - nglSecondaryColor3ubEXT(0,0,0); - } - } -#endif } // *************************************************************************** void CDriverGLStates3::clientActiveTextureARB(uint stage) { -#ifndef GLSL - H_AUTO_OGL(CDriverGLStates3_clientActiveTextureARB); - - if( _CurrentClientActiveTextureARB != stage ) - { - nglClientActiveTextureARB(GL_TEXTURE0_ARB+stage); - _CurrentClientActiveTextureARB= stage; - } -#endif - } // *************************************************************************** void CDriverGLStates3::enableTexCoordArray(bool enable) { -#ifndef GLSL - H_AUTO_OGL(CDriverGLStates3_enableTexCoordArray); - - if(_TexCoordArrayEnabled[_CurrentClientActiveTextureARB] != enable) - { - if(enable) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - else - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - - _TexCoordArrayEnabled[_CurrentClientActiveTextureARB]= enable; - } -#endif - } // *************************************************************************** void CDriverGLStates3::enableVertexAttribArray(uint glIndex, bool enable) { -#ifndef GLSL - H_AUTO_OGL(CDriverGLStates3_enableVertexAttribArray); - - if(_VertexAttribArrayEnabled[glIndex] != enable) - { - if(enable) - glEnableClientState(glIndex+GL_VERTEX_ATTRIB_ARRAY0_NV); - else - glDisableClientState(glIndex+GL_VERTEX_ATTRIB_ARRAY0_NV); - _VertexAttribArrayEnabled[glIndex]= enable; - } -#endif } // *************************************************************************** @@ -1014,13 +720,6 @@ void CDriverGLStates3::enableFog(uint enable) { // new state. _CurFog= enabled; -#ifndef GLSL - // Setup GLState. - if(_CurFog) - glEnable(GL_FOG); - else - glDisable(GL_FOG); -#endif } } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_texture.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_texture.cpp index 6732db158..f2513292e 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_texture.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_texture.cpp @@ -1442,129 +1442,6 @@ void CDriverGL3::forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv _CurrentTexEnv[stage].EnvPacked= env.EnvPacked; // Disable Special tex env f(). _CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled; - -#ifndef GLSL - - // Setup the gl env mode. - _DriverGLStates.activeTextureARB(stage); - - // if the Mad operator is used, then - // "Normal drivers", setup EnvCombine. - if(_Extensions.EXTTextureEnvCombine) - { - { - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); - // RGB. - //===== - if (env.Env.OpRGB == CMaterial::Mad) - { - // - if (_Extensions.ATITextureEnvCombine3) - { - glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE_ADD_ATI); - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, SourceLUT[env.Env.SrcArg0RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, OperandLUT[env.Env.OpArg0RGB]); - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, SourceLUT[env.Env.SrcArg1RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, OperandLUT[env.Env.OpArg1RGB]); - // Arg2. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, SourceLUT[env.Env.SrcArg2RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, OperandLUT[env.Env.OpArg2RGB]); - } - else - { - // fallback to modulate .. - glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); - // - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, SourceLUT[env.Env.SrcArg0RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, OperandLUT[env.Env.OpArg0RGB]); - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, SourceLUT[env.Env.SrcArg1RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, OperandLUT[env.Env.OpArg1RGB]); - } - } - else - { - // Operator. - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, OperatorLUT[env.Env.OpRGB] ); - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, SourceLUT[env.Env.SrcArg0RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, OperandLUT[env.Env.OpArg0RGB]); - // Arg1. - if(env.Env.OpRGB > CMaterial::Replace) - { - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, SourceLUT[env.Env.SrcArg1RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, OperandLUT[env.Env.OpArg1RGB]); - // Arg2. - if(env.Env.OpRGB >= CMaterial::InterpolateTexture ) - { - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, InterpolateSrcLUT[env.Env.OpRGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA); - } - } - } - // Alpha. - //===== - if (env.Env.OpAlpha == CMaterial::Mad) - { - if (_Extensions.ATITextureEnvCombine3) - { - glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE_ADD_ATI); - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, SourceLUT[env.Env.SrcArg0Alpha] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, OperandLUT[env.Env.OpArg0Alpha]); - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, SourceLUT[env.Env.SrcArg1Alpha] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, OperandLUT[env.Env.OpArg1Alpha]); - // Arg2. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, SourceLUT[env.Env.SrcArg2Alpha] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, OperandLUT[env.Env.OpArg2Alpha]); - } - else - { - // fallback to modulate .. - glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); - // - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, SourceLUT[env.Env.SrcArg0RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, OperandLUT[env.Env.OpArg0RGB]); - // Arg1. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, SourceLUT[env.Env.SrcArg1RGB] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, OperandLUT[env.Env.OpArg1RGB]); - } - } - else - { - // Operator. - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, OperatorLUT[env.Env.OpAlpha] ); - // Arg0. - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, SourceLUT[env.Env.SrcArg0Alpha] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, OperandLUT[env.Env.OpArg0Alpha]); - // Arg1. - if(env.Env.OpAlpha > CMaterial::Replace) - { - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, SourceLUT[env.Env.SrcArg1Alpha] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, OperandLUT[env.Env.OpArg1Alpha]); - // Arg2. - if(env.Env.OpAlpha >= CMaterial::InterpolateTexture ) - { - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, InterpolateSrcLUT[env.Env.OpAlpha] ); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, GL_SRC_ALPHA); - } - } - } - } - } - // Very Bad drivers. - else - { - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } - -#endif - } // *************************************************************************** diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp index e8cff02d5..2382053d2 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp @@ -207,17 +207,13 @@ bool CDriverGL3::activeIndexBuffer(CIndexBuffer& IB) bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines) { H_AUTO_OGL(CDriverGL3_renderLines) - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); // setup material if ( !setupMaterial(mat) || _LastIB._Values == NULL ) return false; -#ifdef GLSL if( !setupProgram( mat ) ) return false; -#endif if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; // render primitives. @@ -232,8 +228,6 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines) if( !setupPass(pass) ) return false; - refreshTexMatrices(); - // draw the primitives. if(nlines) { @@ -264,19 +258,12 @@ bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris { H_AUTO_OGL(CDriverGL3_renderTriangles); - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); - // setup material if ( !setupMaterial(mat) || _LastIB._Values == NULL ) return false; -#ifdef GLSL if( !setupProgram( mat ) ) return false; -#endif - - refreshTexMatrices(); if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; @@ -294,8 +281,6 @@ bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris if( !setupPass(pass) ) return false; - refreshTexMatrices(); - // draw the primitives. if(ntris) { @@ -329,9 +314,6 @@ bool CDriverGL3::renderSimpleTriangles(uint32 firstTri, uint32 ntris) nlassert(ntris>0); - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); - if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; // Don't setup any material here. @@ -362,17 +344,13 @@ bool CDriverGL3::renderSimpleTriangles(uint32 firstTri, uint32 ntris) bool CDriverGL3::renderRawPoints(CMaterial& mat, uint32 startIndex, uint32 numPoints) { H_AUTO_OGL(CDriverGL3_renderRawPoints) - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); // setup material if ( !setupMaterial(mat) ) return false; -#ifdef GLSL if( !setupProgram( mat ) ) return false; -#endif if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; // render primitives. @@ -387,8 +365,6 @@ bool CDriverGL3::renderRawPoints(CMaterial& mat, uint32 startIndex, uint32 numPo if( !setupPass(pass) ) return false; - refreshTexMatrices(); - // draw the primitives. if(numPoints) glDrawArrays(GL_POINTS, startIndex, numPoints); @@ -409,17 +385,13 @@ bool CDriverGL3::renderRawPoints(CMaterial& mat, uint32 startIndex, uint32 numPo bool CDriverGL3::renderRawLines(CMaterial& mat, uint32 startIndex, uint32 numLines) { H_AUTO_OGL(CDriverGL3_renderRawLines) - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); // setup material if ( !setupMaterial(mat) ) return false; -#ifdef GLSL if( !setupProgram( mat ) ) return false; -#endif if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; // render primitives. @@ -434,8 +406,6 @@ bool CDriverGL3::renderRawLines(CMaterial& mat, uint32 startIndex, uint32 numLin if( !setupPass(pass) ) return false; - refreshTexMatrices(); - // draw the primitives. if(numLines) glDrawArrays(GL_LINES, startIndex << 1, numLines << 1); @@ -456,17 +426,13 @@ bool CDriverGL3::renderRawLines(CMaterial& mat, uint32 startIndex, uint32 numLin bool CDriverGL3::renderRawTriangles(CMaterial& mat, uint32 startIndex, uint32 numTris) { H_AUTO_OGL(CDriverGL3_renderRawTriangles) - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); // setup material if ( !setupMaterial(mat) ) return false; -#ifdef GLSL if( !setupProgram( mat ) ) return false; -#endif if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; // render primitives. @@ -481,8 +447,6 @@ bool CDriverGL3::renderRawTriangles(CMaterial& mat, uint32 startIndex, uint32 nu if( !setupPass(pass) ) return false; - refreshTexMatrices(); - // draw the primitives. if(numTris) { @@ -506,17 +470,13 @@ bool CDriverGL3::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQua { H_AUTO_OGL(CDriverGL3_renderRawQuads) if (!numQuads) return true; - // update matrix and Light in OpenGL if needed - refreshRenderSetup(); // setup material if ( !setupMaterial(mat) ) return false; -#ifdef GLSL if( !setupProgram( mat ) ) return false; -#endif if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; @@ -553,8 +513,6 @@ bool CDriverGL3::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQua if( !setupPass(pass) ) return false; - refreshTexMatrices(); - uint32 currIndex = startIndex; uint32 numLeftQuads = numQuads; @@ -633,37 +591,6 @@ bool CDriverGL3::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQua void CDriverGL3::setupUVPtr(uint stage, CVertexBufferInfo &VB, uint uvId) { -#ifndef GLSL - - H_AUTO_OGL(CDriverGL3_setupUVPtr) - // sould not be called with vertex program Array setuped. - nlassert(!_LastSetupGLArrayVertexProgram); - - _DriverGLStates.clientActiveTextureARB(stage); - if (VB.VertexFormat & (CVertexBuffer::TexCoord0Flag<= 2); - _DriverGLStates.enableVertexArray(true); - glVertexPointer(numVertexCoord, GL_FLOAT, vb.VertexSize, vb.ValuePtr[CVertexBuffer::Position]); - - // setup normal ptr. - //----------- - // Check for normal param in vertex buffer - if (flags & CVertexBuffer::NormalFlag) - { - // Check type - nlassert (vb.Type[CVertexBuffer::Normal]==CVertexBuffer::Float3); - - _DriverGLStates.enableNormalArray(true); - glNormalPointer(GL_FLOAT, vb.VertexSize, vb.ValuePtr[CVertexBuffer::Normal]); - } - else - { - _DriverGLStates.enableNormalArray(false); - } - - // Setup Color - //----------- - // Check for color param in vertex buffer - if (flags & CVertexBuffer::PrimaryColorFlag) - { - // Check type - nlassert (vb.Type[CVertexBuffer::PrimaryColor]==CVertexBuffer::UChar4); - _DriverGLStates.enableColorArray(true); - // Setup ATI VBHard or std ptr. - glColorPointer(4,GL_UNSIGNED_BYTE, vb.VertexSize, vb.ValuePtr[CVertexBuffer::PrimaryColor]); - } - else - { - _DriverGLStates.enableColorArray(false); - } - } - } - - // Setup Uvs - //----------- - // Get the routing - for(uint i=0; i translate to FRC - out = ARBVertexProgramInstrToName[instr.Opcode]; - uint nbOp = instr.getNumUsedSrc(); - std::string destOperand; - ARBVertexProgramDumpOperand(instr.Dest, true, destOperand); - out += destOperand; - for(uint k = 0; k < nbOp; ++k) - { - out += ", "; - std::string srcOperand; - ARBVertexProgramDumpOperand(instr.getSrc(k), false, srcOperand); - out += srcOperand; - } - out +="; \n"; - -} - -// *************************************************************************** -bool CDriverGL3::setupARBVertexProgram (const CVPParser::TProgram &inParsedProgram, GLuint id, bool &specularWritten) -{ - H_AUTO_OGL(CDriverGL3_setupARBVertexProgram); - - // tmp - CVPParser::TProgram parsedProgram = inParsedProgram; - // - std::string code; - code = "!!ARBvp1.0\n"; - // declare temporary registers - code += "TEMP "; - const uint NUM_TEMPORARIES = 12; - for(uint k = 0; k < NUM_TEMPORARIES; ++k) - { - code += toString("R%d", (int) k); - if (k != (NUM_TEMPORARIES - 1)) - { - code +=", "; - } - } - code += "; \n"; - // declare address register - code += "ADDRESS A0;\n"; - // declare constant register - code += "PARAM c[96] = {program.env[0..95]}; \n"; - uint writtenSpecularComponents = 0; - for(uint k = 0; k < parsedProgram.size(); ++k) - { - if (parsedProgram[k].Dest.Type == CVPOperand::OutputRegister && parsedProgram[k].Dest.Value.OutputRegisterValue == CVPOperand::OSecondaryColor) - { - writtenSpecularComponents |= parsedProgram[k].Dest.WriteMask; - } - } - // tmp fix : write unwritten components of specular (seems that glDisable(GL_COLOR_SUM_ARB) does not work in a rare case for me ...) - if (writtenSpecularComponents != 0xf) - { - // add a new instruction to write 0 in unwritten components - CVPSwizzle sw; - sw.Comp[0] = CVPSwizzle::X; - sw.Comp[1] = CVPSwizzle::Y; - sw.Comp[2] = CVPSwizzle::Z; - sw.Comp[3] = CVPSwizzle::W; - - CVPInstruction vpi; - vpi.Opcode = CVPInstruction::ADD; - vpi.Dest.WriteMask = 0xf ^ writtenSpecularComponents; - vpi.Dest.Type = CVPOperand::OutputRegister; - vpi.Dest.Value.OutputRegisterValue = CVPOperand::OSecondaryColor; - vpi.Dest.Indexed = false; - vpi.Dest.Negate = false; - vpi.Dest.Swizzle = sw; - vpi.Src1.Type = CVPOperand::InputRegister; - vpi.Src1.Value.InputRegisterValue = CVPOperand::IPosition; // tmp -> check that position is present - vpi.Src1.Indexed = false; - vpi.Src1.Negate = false; - vpi.Src1.Swizzle = sw; - vpi.Src2.Type = CVPOperand::InputRegister; - vpi.Src2.Value.InputRegisterValue = CVPOperand::IPosition; // tmp -> chec - vpi.Src2.Indexed = false; - vpi.Src2.Negate = true; - vpi.Src2.Swizzle = sw; - // - parsedProgram.push_back(vpi); - } - specularWritten = (writtenSpecularComponents != 0); - - for(uint k = 0; k < parsedProgram.size(); ++k) - { - std::string instr; - ARBVertexProgramDumpInstr(parsedProgram[k], instr); - code += instr + "\r\n"; - } - code += "END\n"; - // - /* - static COFile output; - static bool opened = false; - if (!opened) - { - output.open("vp.txt", false, true); - opened = true; - } - std::string header = "====================================================================================="; - output.serial(header); - output.serial(code); - */ - // - nglBindProgramARB( GL_VERTEX_PROGRAM_ARB, id); - glGetError(); - nglProgramStringARB( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)code.size(), code.c_str() ); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - { - if (err == GL_INVALID_OPERATION) - { - GLint position; - glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &position); - nlassert(position != -1); // there was an error.. - nlassert(position < (GLint) code.size()); - uint line = 0; - const char *lineStart = code.c_str(); - for(uint k = 0; k < (uint) position; ++k) - { - if (code[k] == '\n') - { - lineStart = code.c_str() + k; - ++line; - } - } - nlwarning("ARB vertex program parse error at line %d.", (int) line); - // search end of line - const char *lineEnd = code.c_str() + code.size(); - for(uint k = position; k < code.size(); ++k) - { - if (code[k] == '\n') - { - lineEnd = code.c_str() + k; - break; - } - } - nlwarning(std::string(lineStart, lineEnd).c_str()); - // display the gl error msg - const GLubyte *errorMsg = glGetString(GL_PROGRAM_ERROR_STRING_ARB); - nlassert((const char *) errorMsg); - nlwarning((const char *) errorMsg); - } - nlassert(0); - return false; - } - -#ifdef NL_OS_MAC - // Wait for GPU to finish program upload, else draw comands might crash. - // Happened to CVegetableBlendLayerModel (glDrawElements()). - // For more information, see http://dev.ryzom.com/issues/1006 - glFinish(); -#endif - - return true; -} - - - -// *************************************************************************** -bool CDriverGL3::activeARBVertexProgram (CVertexProgram *program) -{ - H_AUTO_OGL(CDriverGL3_activeARBVertexProgram); - - // Setup or unsetup ? - if (program) - { - // Driver info - CVertexProgamDrvInfosGL3 *drvInfo; - - // Program setuped ? - if (program->_DrvInfo==NULL) - { - // try to parse the program - CVPParser parser; - CVPParser::TProgram parsedProgram; - std::string errorOutput; - bool result = parser.parse(program->getProgram().c_str(), parsedProgram, errorOutput); - if (!result) - { - nlwarning("Unable to parse a vertex program."); - #ifdef NL_DEBUG - nlerror(errorOutput.c_str()); - #endif - return false; - } - // Insert into driver list. (so it is deleted when driver is deleted). - ItVtxPrgDrvInfoPtrList it= _VtxPrgDrvInfos.insert(_VtxPrgDrvInfos.end(), (NL3D::IVertexProgramDrvInfos*)NULL); - - // Create a driver info - *it = drvInfo = new CVertexProgamDrvInfosGL3 (this, it); - // Set the pointer - program->_DrvInfo=drvInfo; - - if (!setupARBVertexProgram(parsedProgram, drvInfo->ID, drvInfo->SpecularWritten)) - { - delete drvInfo; - program->_DrvInfo = NULL; - _VtxPrgDrvInfos.erase(it); - return false; - } - } - else - { - // Cast the driver info pointer - drvInfo=safe_cast((IVertexProgramDrvInfos*)program->_DrvInfo); - } - glEnable( GL_VERTEX_PROGRAM_ARB ); - _VertexProgramEnabled = true; - nglBindProgramARB( GL_VERTEX_PROGRAM_ARB, drvInfo->ID ); - if (drvInfo->SpecularWritten) - { - glEnable( GL_COLOR_SUM_ARB ); - } - else - { - glDisable( GL_COLOR_SUM_ARB ); // no specular written - } - _LastSetuppedVP = program; - } - else - { - glDisable( GL_VERTEX_PROGRAM_ARB ); - glDisable( GL_COLOR_SUM_ARB ); -#ifndef GLSL - _VertexProgramEnabled = false; -#endif - } - return true; -} - -// *************************************************************************** -bool CDriverGL3::activeVertexProgram (CVertexProgram *program) -{ - H_AUTO_OGL(CDriverGL3_activeVertexProgram) - // Extension here ? - return activeARBVertexProgram(program); - - // Can't do anything - return false; -} - - -// *************************************************************************** - -void CDriverGL3::setConstant (uint index, float f0, float f1, float f2, float f3) -{ - H_AUTO_OGL(CDriverGL3_setConstant); - - // Vertex program exist ? - nglProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, index, f0, f1, f2, f3); - -} - - -// *************************************************************************** - -void CDriverGL3::setConstant (uint index, double d0, double d1, double d2, double d3) -{ - H_AUTO_OGL(CDriverGL3_setConstant); - - nglProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, index, d0, d1, d2, d3); -} - - -// *************************************************************************** - -void CDriverGL3::setConstant (uint index, const NLMISC::CVector& value) -{ - H_AUTO_OGL(CDriverGL3_setConstant); - - nglProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, index, value.x, value.y, value.z, 0); -} - - -// *************************************************************************** - -void CDriverGL3::setConstant (uint index, const NLMISC::CVectorD& value) -{ - H_AUTO_OGL(CDriverGL3_setConstant); - - nglProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, index, value.x, value.y, value.z, 0); -} - - -// *************************************************************************** -void CDriverGL3::setConstant (uint index, uint num, const float *src) -{ - H_AUTO_OGL(CDriverGL3_setConstant); - - for(uint k = 0; k < num; ++k) - { - nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index + k, src + 4 * k); - } - -} - -// *************************************************************************** -void CDriverGL3::setConstant (uint index, uint num, const double *src) -{ - H_AUTO_OGL(CDriverGL3_setConstant); - - for(uint k = 0; k < num; ++k) - { - nglProgramEnvParameter4dvARB(GL_VERTEX_PROGRAM_ARB, index + k, src + 4 * k); - } -} - -// *************************************************************************** - -const uint CDriverGL3::GLMatrix[IDriver::NumMatrix]= -{ - GL_MODELVIEW, - GL_PROJECTION, - GL_MODELVIEW_PROJECTION_NV -}; - - -// *************************************************************************** - -const uint CDriverGL3::GLTransform[IDriver::NumTransform]= -{ - GL_IDENTITY_NV, - GL_INVERSE_NV, - GL_TRANSPOSE_NV, - GL_INVERSE_TRANSPOSE_NV -}; - - -// *************************************************************************** - -void CDriverGL3::setConstantMatrix (uint index, IDriver::TMatrix matrix, IDriver::TTransform transform) -{ - H_AUTO_OGL(CDriverGL3_setConstantMatrix); - - { - // First, ensure that the render setup is correctly setuped. - refreshRenderSetup(); - CMatrix mat; - switch (matrix) - { - case IDriver::ModelView: - mat = _ModelViewMatrix; - break; - case IDriver::Projection: - { - mat = _GLProjMat; - } - break; - case IDriver::ModelViewProjection: - mat = _GLProjMat * _ModelViewMatrix; - break; - default: - break; - } - - switch(transform) - { - case IDriver::Identity: break; - case IDriver::Inverse: - mat.invert(); - break; - case IDriver::Transpose: - mat.transpose(); - break; - case IDriver::InverseTranspose: - mat.invert(); - mat.transpose(); - break; - default: - break; - } - mat.transpose(); - float matDatas[16]; - mat.get(matDatas); - - nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index, matDatas); - nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index + 1, matDatas + 4); - nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index + 2, matDatas + 8); - nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index + 3, matDatas + 12); - - } -} - -// *************************************************************************** - -void CDriverGL3::setConstantFog (uint index) -{ - H_AUTO_OGL(CDriverGL3_setConstantFog) - const float *values = _ModelViewMatrix.get(); - setConstant (index, -values[2], -values[6], -values[10], -values[14]); -} - -// *************************************************************************** - void CDriverGL3::enableVertexProgramDoubleSidedColor(bool doubleSided) { H_AUTO_OGL(CDriverGL3_enableVertexProgramDoubleSidedColor);