diff --git a/code/nel/include/nel/3d/program.h b/code/nel/include/nel/3d/program.h index c431e6869..9c8e53c51 100644 --- a/code/nel/include/nel/3d/program.h +++ b/code/nel/include/nel/3d/program.h @@ -145,6 +145,46 @@ struct CProgramIndex TexMatrix2, TexMatrix3, + TexGen0ObjectPlaneS, + TexGen1ObjectPlaneS, + TexGen2ObjectPlaneS, + TexGen3ObjectPlaneS, + + TexGen0ObjectPlaneT, + TexGen1ObjectPlaneT, + TexGen2ObjectPlaneT, + TexGen3ObjectPlaneT, + + TexGen0ObjectPlaneP, + TexGen1ObjectPlaneP, + TexGen2ObjectPlaneP, + TexGen3ObjectPlaneP, + + TexGen0ObjectPlaneQ, + TexGen1ObjectPlaneQ, + TexGen2ObjectPlaneQ, + TexGen3ObjectPlaneQ, + + TexGen0EyePlaneS, + TexGen1EyePlaneS, + TexGen2EyePlaneS, + TexGen3EyePlaneS, + + TexGen0EyePlaneT, + TexGen1EyePlaneT, + TexGen2EyePlaneT, + TexGen3EyePlaneT, + + TexGen0EyePlaneP, + TexGen1EyePlaneP, + TexGen2EyePlaneP, + TexGen3EyePlaneP, + + TexGen0EyePlaneQ, + TexGen1EyePlaneQ, + TexGen2EyePlaneQ, + TexGen3EyePlaneQ, + SelfIllumination, Light0DirOrPos, diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl.h b/code/nel/src/3d/driver/opengl3/driver_opengl.h index e063edea6..db67c4fd4 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl.h @@ -391,6 +391,7 @@ public: void enableLightingVP(bool enable); void touchLightVP(int i); void touchVertexFormatVP(); + void setTexGenModeVP(uint stage, sint mode); virtual void startSpecularBatch(); virtual void endSpecularBatch(); 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 cb2889574..ea287dc8a 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_material.cpp @@ -128,32 +128,32 @@ void CDriverGL3::setTextureEnvFunction(uint stage, CMaterial& mat) activateTexEnvColor(stage, env); // Activate texture generation mapping - _DriverGLStates.activeTexture(stage); - if (mat.getTexCoordGen (stage)) + //_DriverGLStates.activeTexture(stage); + if (mat.getTexCoordGen(stage)) { // set mode and enable. CMaterial::TTexCoordGenMode mode= mat.getTexCoordGenMode(stage); if (mode==CMaterial::TexCoordGenReflect) { // Cubic or normal ? - if (text->isTextureCube ()) - _DriverGLStates.setTexGenMode (stage, GL_REFLECTION_MAP_ARB); + if (text->isTextureCube()) + setTexGenModeVP(stage, TexGenReflectionMap); else - _DriverGLStates.setTexGenMode (stage, GL_SPHERE_MAP); + setTexGenModeVP(stage, TexGenSphereMap); } else if (mode==CMaterial::TexCoordGenObjectSpace) { - _DriverGLStates.setTexGenMode (stage, GL_OBJECT_LINEAR); + setTexGenModeVP(stage, TexGenObjectLinear); } else if (mode==CMaterial::TexCoordGenEyeSpace) { - _DriverGLStates.setTexGenMode (stage, GL_EYE_LINEAR); + setTexGenModeVP(stage, TexGenEyeLinear); } } else { // Disable. - _DriverGLStates.setTexGenMode(stage, 0); + setTexGenModeVP(stage, TexGenDisabled); } } } @@ -835,8 +835,7 @@ void CDriverGL3::setupLightMapPass(uint pass) // FIXME GL3 LIGHTMAP // Setup gen tex off - _DriverGLStates.activeTexture(0); - _DriverGLStates.setTexGenMode(0, 0); + setTexGenModeVP(0, TexGenDisabled); // And disable other stages. for (uint stage = 1; stage < inlGetNumTextStages(); stage++) @@ -932,8 +931,7 @@ void CDriverGL3::setupLightMapPass(uint pass) activateTexEnvColor(stage, stdEnv); // Setup env for texture stage. - _DriverGLStates.activeTexture(stage); - _DriverGLStates.setTexGenMode(stage, 0); + setTexGenModeVP(stage, TexGenDisabled); // setup TexEnvCombine4 (ignore alpha part). if (_CurrentTexEnvSpecial[stage] != TexEnvSpecialLightMap) @@ -961,8 +959,7 @@ void CDriverGL3::setupLightMapPass(uint pass) activateTexEnvMode(stage, _LightMapLastStageEnv); // Setup gen tex off - _DriverGLStates.activeTexture(stage); - _DriverGLStates.setTexGenMode(stage, 0); + setTexGenModeVP(stage, TexGenDisabled); } } else @@ -1087,8 +1084,7 @@ void CDriverGL3::setupSpecularBegin() activateTexEnvMode(0, env); // Disable texGen for stage 0 - _DriverGLStates.activeTexture(0); - _DriverGLStates.setTexGenMode(0, 0); + setTexGenModeVP(0, TexGenDisabled); // ---- Stage 1 Common Setup. // NB don't setup the TexEnv here (stage1 setuped in setupSpecularPass() according to extensions) @@ -1105,8 +1101,7 @@ void CDriverGL3::setupSpecularEnd() { H_AUTO_OGL(CDriverGL3_setupSpecularEnd) // Disable Texture coord generation. - _DriverGLStates.activeTexture(1); - _DriverGLStates.setTexGenMode(1, 0); + setTexGenModeVP(1, TexGenDisabled); // Happiness !!! we have already enabled the stage 1 _UserTexMat[ 1 ].identity(); diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_program.h b/code/nel/src/3d/driver/opengl3/driver_opengl_program.h index 3ef44ca38..8e5f96163 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_program.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_program.h @@ -25,12 +25,19 @@ namespace NL3D { namespace NLDRIVERGL3 { #endif +static sint TexGenDisabled = -1; +static sint TexGenReflectionMap = 0; // GL_REFLECTION_MAP_ARB +static sint TexGenSphereMap = 1; // GL_SPHERE_MAP +static sint TexGenObjectLinear = 2; // GL_OBJECT_LINEAR +static sint TexGenEyeLinear = 3; // GL_EYE_LINEAR + /// Builtin vertex program description struct CVPBuiltin { uint16 VertexFormat; bool Lighting; sint LightMode[NL_OPENGL3_MAX_LIGHT]; // -1 when disabled + sint TexGenMode[IDRV_MAT_MAXTEXTURES]; // -1 when disabled bool Specular; // Reflection bool Fog; // bool VertexColorLighted; 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 81e8f052c..50b2eedb6 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_states.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_states.cpp @@ -103,20 +103,9 @@ void CDriverGLStates3::forceDefaults(uint nbStages) // disable texturing. nglActiveTexture(GL_TEXTURE0 + stage); glDisable(GL_TEXTURE_2D); - glDisable(GL_TEXTURE_CUBE_MAP); - - _TextureMode[stage]= TextureDisabled; - - // Tex gen init - _TexGenMode[stage] = 0; - glDisable(GL_TEXTURE_RECTANGLE); - - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_R); - glDisable(GL_TEXTURE_GEN_Q); + _TextureMode[stage]= TextureDisabled; } // ActiveTexture current texture to 0. @@ -392,7 +381,7 @@ void CDriverGLStates3::setDepthRange(float znear, float zfar) updateDepthRange(); } } - +/* // *************************************************************************** void CDriverGLStates3::setTexGenMode (uint stage, GLint mode) { @@ -405,7 +394,7 @@ void CDriverGLStates3::setTexGenMode (uint stage, GLint mode) _TexGenMode[stage] = mode; } } - +*/ // *************************************************************************** void CDriverGLStates3::resetTextureMode() { diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_states.h b/code/nel/src/3d/driver/opengl3/driver_opengl_states.h index 13acf90d5..115b77c37 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_states.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_states.h @@ -113,8 +113,6 @@ public: * NB : this is done in window coordinate, not in world coordinate as with CMaterial */ void setZBias(float zbias); - // NB: set 0 to reset TexGen. - void setTexGenMode (uint stage, GLint mode); // @} @@ -174,8 +172,6 @@ private: bool _VertexAttribArrayEnabled[CVertexBuffer::NumValue]; - GLint _TexGenMode[8]; - uint _CurrARBVertexBuffer; float _DepthRangeNear; diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp index 8372255ef..b79fb02c2 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp @@ -41,6 +41,9 @@ bool operator<(const CVPBuiltin &left, const CVPBuiltin &right) for (sint i = 0; i < NL_OPENGL3_MAX_LIGHT; ++i) if (left.LightMode[i] != right.LightMode[i]) return left.LightMode[i] < right.LightMode[i]; + for (sint i = 0; i < IDRV_MAT_MAXTEXTURES; ++i) + if (left.TexGenMode[i] != right.TexGenMode[i]) + return left.TexGenMode[i] < right.TexGenMode[i]; if (left.Specular != right.Specular) return right.Specular; if (left.Fog != right.Fog) @@ -334,6 +337,16 @@ void CDriverGL3::touchVertexFormatVP() } } +void CDriverGL3::setTexGenModeVP(uint stage, sint mode) +{ + H_AUTO_OGL(CDriverGL3_setTexGenModeVP) + if (m_VPBuiltinCurrent.TexGenMode[stage] != mode) + { + m_VPBuiltinCurrent.TexGenMode[stage] = mode; + m_VPBuiltinTouched = true; + } +} + #ifdef NL_STATIC } // NLDRIVERGL3 #endif diff --git a/code/nel/src/3d/program.cpp b/code/nel/src/3d/program.cpp index 02689b634..f16840e2b 100644 --- a/code/nel/src/3d/program.cpp +++ b/code/nel/src/3d/program.cpp @@ -114,6 +114,46 @@ const char *CProgramIndex::Names[NUM_UNIFORMS] = "texMatrix1", "texMatrix2", "texMatrix3", + + "texGen0ObjectPlaneS", + "texGen1ObjectPlaneS", + "texGen2ObjectPlaneS", + "texGen3ObjectPlaneS", + + "texGen0ObjectPlaneT", + "texGen1ObjectPlaneT", + "texGen2ObjectPlaneT", + "texGen3ObjectPlaneT", + + "texGen0ObjectPlaneP", + "texGen1ObjectPlaneP", + "texGen2ObjectPlaneP", + "texGen3ObjectPlaneP", + + "texGen0ObjectPlaneQ", + "texGen1ObjectPlaneQ", + "texGen2ObjectPlaneQ", + "texGen3ObjectPlaneQ", + + "texGen0EyePlaneS", + "texGen1EyePlaneS", + "texGen2EyePlaneS", + "texGen3EyePlaneS", + + "texGen0EyePlaneT", + "texGen1EyePlaneT", + "texGen2EyePlaneT", + "texGen3EyePlaneT", + + "texGen0EyePlaneP", + "texGen1EyePlaneP", + "texGen2EyePlaneP", + "texGen3EyePlaneP", + + "texGen0EyePlaneQ", + "texGen1EyePlaneQ", + "texGen2EyePlaneQ", + "texGen3EyePlaneQ", "selfIllumination",