diff --git a/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp b/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp index af678ce24..db1210d8a 100644 --- a/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp @@ -95,6 +95,7 @@ namespace NL3D { case CMaterial::Normal: case CMaterial::UserColor: + case CMaterial::Specular: generateNormalPS(); break; @@ -102,9 +103,9 @@ namespace NL3D generateLightMapPS(); break; - case CMaterial::Specular: + /*case CMaterial::Specular: generateSpecularPS(); - break; + break;*/ case CMaterial::PerPixelLighting: case CMaterial::PerPixelLightingNoSpec: diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl.cpp index 9b51315d6..aec5c64d9 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl.cpp @@ -440,7 +440,7 @@ bool CDriverGL3::setupDisplay() _CurrentTexEnvSpecial[stage] = TexEnvSpecialDisabled; // set All TexGen by default to identity matrix (prefer use the textureMatrix scheme) - _DriverGLStates.activeTexture(stage); + setTexGenModeVP(stage, TexGenDisabled); // FIXME GL3 TEXGEN } if (!initProgramPipeline()) @@ -964,12 +964,12 @@ void CDriverGL3::copyFrameBufferToTexture(ITexture *tex, // gltext->activeFrameBufferObject(NULL); _DriverGLStates.activeTexture(0); // setup texture mode, after activeTexture() - CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; + // FIXME GL3 TEXTUREMODE CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; - if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) - textureMode = CDriverGLStates3::TextureRect; + // FIXME GL3 TEXTUREMODE if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) + // FIXME GL3 TEXTUREMODE textureMode = CDriverGLStates3::TextureRect; - _DriverGLStates.setTextureMode(textureMode); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(textureMode); if (tex->isTextureCube()) { glBindTexture(GL_TEXTURE_CUBE_MAP, gltext->ID); @@ -981,7 +981,7 @@ void CDriverGL3::copyFrameBufferToTexture(ITexture *tex, glCopyTexSubImage2D(gltext->TextureMode, level, offsetx, offsety, x, y, width, height); } // disable texturing. - _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); _CurrentTexture[0] = NULL; _CurrentTextureInfoGL[0] = NULL; //if (_RenderTargetFBO) @@ -1568,49 +1568,6 @@ void CDriverGL3::dumpMappedBuffers() } #endif -// *************************************************************************** -void CDriverGL3::checkTextureOn() const -{ - H_AUTO_OGL(CDriverGL3_checkTextureOn) - // tmp for debug - CDriverGLStates3 &dgs = const_cast(_DriverGLStates); - uint currTexStage = dgs.getActiveTexture(); - for (uint k = 0; k < this->getNbTextureStages(); ++k) - { - dgs.activeTexture(k); - GLboolean flag2D; - GLboolean flagCM; - GLboolean flagTR; - glGetBooleanv(GL_TEXTURE_2D, &flag2D); - glGetBooleanv(GL_TEXTURE_CUBE_MAP, &flagCM); - - glGetBooleanv(GL_TEXTURE_RECTANGLE, &flagTR); - - switch(dgs.getTextureMode()) - { - case CDriverGLStates3::TextureDisabled: - nlassert(!flag2D); - nlassert(!flagCM); - break; - case CDriverGLStates3::Texture2D: - nlassert(flag2D); - nlassert(!flagCM); - break; - case CDriverGLStates3::TextureRect: - nlassert(flagTR); - nlassert(!flagCM); - break; - case CDriverGLStates3::TextureCubeMap: - nlassert(!flag2D); - nlassert(flagCM); - break; - default: - break; - } - } - dgs.activeTexture(currTexStage); -} - // *************************************************************************** bool CDriverGL3::supportOcclusionQuery() const { @@ -1624,7 +1581,7 @@ bool CDriverGL3::supportTextureRectangle() const { H_AUTO_OGL(CDriverGL3_supportTextureRectangle); - return _Extensions.GLCore; + return false; // FIXME GL3 _Extensions.GLCore; } // *************************************************************************** diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl.h b/code/nel/src/3d/driver/opengl3/driver_opengl.h index db67c4fd4..979d5e8f2 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl.h @@ -1392,9 +1392,6 @@ public: #endif emptyProc ExitFunc; - - // tmp for debug - void checkTextureOn() const; private: /** Bind a texture at stage 0 for the good texture mode(2d or cube) * Parameters / part of the texture are ready to be changed in the gl after that diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp index c05031264..554c6dd9f 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp @@ -554,7 +554,11 @@ void CDriverGL3::setUniformFog(TProgram program, uint index) void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat) { desc.setShaderType(mat.getShader()); - desc.setVBFlags(_CurrentVertexBufferHard->VB->getVertexFormat()); + uint16 vbFlags = _CurrentVertexBufferHard->VB->getVertexFormat(); + for (sint i = 0; i < IDRV_MAT_MAXTEXTURES; ++i) + if (m_VPBuiltinCurrent.TexGenMode[0] >= 0) + vbFlags |= g_VertexFlags[TexCoord0 + i]; // texgen hack for keeping pp simpler + desc.setVBFlags(vbFlags); if (mat.getShader() == CMaterial::LightMap) desc.setNLightMaps(mat._LightMaps.size()); @@ -574,7 +578,9 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat) for (int i = 0; i < maxTextures; i++) { // GL3 TEX COORD - if (mat.getTexture(i) != NULL && (desc.hasVBFlags(g_VertexFlags[TexCoord0]) || desc.hasVBFlags(g_VertexFlags[TexCoord0 + i]))) + if (mat.getTexture(i) != NULL + && (desc.hasVBFlags(g_VertexFlags[TexCoord0]) || desc.hasVBFlags(g_VertexFlags[TexCoord0 + i])) + ) { desc.setUseTexStage(i, true); useTextures = true; diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h b/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h index 6675a79f2..8796c5f77 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h @@ -24,6 +24,9 @@ namespace NL3D class CVertexProgram; class CPixelProgram; + static uint8 Sampler2D = 0; + static uint8 SamplerCube = 1; + struct SShaderPair { SShaderPair() @@ -84,13 +87,16 @@ namespace NL3D CShaderDesc() { for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++) - texEnvMode[ i ] = 0; + texEnvMode[i] = 0; for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++) - lightMode[ i ] = Nolight; + lightMode[i] = Nolight; for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++) - useTextureStage[ i ] = false; + { + useTextureStage[i] = false; + textureSamplerMode[i] = Sampler2D; + } //useFirstTextureCoordSet = false; noTextures = true; @@ -255,8 +261,9 @@ namespace NL3D }; uint32 features; - uint32 texEnvMode[ IDRV_MAT_MAXTEXTURES ]; - bool useTextureStage[ IDRV_MAT_MAXTEXTURES ]; + uint32 texEnvMode[IDRV_MAT_MAXTEXTURES]; + bool useTextureStage[IDRV_MAT_MAXTEXTURES]; + uint8 textureSamplerMode[IDRV_MAT_MAXTEXTURES]; //bool useFirstTextureCoordSet; bool noTextures; uint32 vbFlags; @@ -264,7 +271,7 @@ namespace NL3D uint32 nlightmaps; float alphaTestTreshold; uint32 fogMode; - TLightMode lightMode[ NL_OPENGL3_MAX_LIGHT ]; + TLightMode lightMode[NL_OPENGL3_MAX_LIGHT]; bool pointLight; SShaderPair shaderPair; 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 50b2eedb6..5a333cc56 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_states.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_states.cpp @@ -98,15 +98,15 @@ void CDriverGLStates3::forceDefaults(uint nbStages) static const GLfloat zero[4] = { 0, 0, 0, 1 }; // TexModes - for (uint stage = 0; stage < nbStages; ++stage) - { + // FIXME GL3 TEXTUREMODE for (uint stage = 0; stage < nbStages; ++stage) + // FIXME GL3 TEXTUREMODE { // disable texturing. - nglActiveTexture(GL_TEXTURE0 + stage); - glDisable(GL_TEXTURE_2D); - glDisable(GL_TEXTURE_CUBE_MAP); - glDisable(GL_TEXTURE_RECTANGLE); - _TextureMode[stage]= TextureDisabled; - } + // FIXME GL3 TEXTUREMODE nglActiveTexture(GL_TEXTURE0 + stage); + // FIXME GL3 TEXTUREMODE glDisable(GL_TEXTURE_2D); + // FIXME GL3 TEXTUREMODE glDisable(GL_TEXTURE_CUBE_MAP); + // FIXME GL3 TEXTUREMODE glDisable(GL_TEXTURE_RECTANGLE); + // FIXME GL3 TEXTUREMODE _TextureMode[stage]= TextureDisabled; + // FIXME GL3 TEXTUREMODE } // ActiveTexture current texture to 0. nglActiveTexture(GL_TEXTURE0); @@ -381,42 +381,6 @@ void CDriverGLStates3::setDepthRange(float znear, float zfar) updateDepthRange(); } } -/* -// *************************************************************************** -void CDriverGLStates3::setTexGenMode (uint stage, GLint mode) -{ - H_AUTO_OGL(CDriverGLStates3_setTexGenMode); - -#ifndef NL3D_GLSTATE_DISABLE_CACHE - if (mode != _TexGenMode[stage]) -#endif - { - _TexGenMode[stage] = mode; - } -} -*/ -// *************************************************************************** -void CDriverGLStates3::resetTextureMode() -{ - H_AUTO_OGL(CDriverGLStates3_resetTextureMode); - - _TextureMode[_CurrentActiveTexture]= TextureDisabled; -} - - -// *************************************************************************** -void CDriverGLStates3::setTextureMode(TTextureMode texMode) -{ - H_AUTO_OGL(CDriverGLStates3_setTextureMode) - TTextureMode oldTexMode = _TextureMode[_CurrentActiveTexture]; - if (oldTexMode != texMode) - { - - // new mode. - _TextureMode[_CurrentActiveTexture]= texMode; - } -} - // *************************************************************************** void CDriverGLStates3::activeTexture(uint stage) 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 115b77c37..48ac58e7e 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_states.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_states.h @@ -119,20 +119,12 @@ public: /// \name Texture Mode setting. // @{ - enum TTextureMode {TextureDisabled, Texture2D, TextureRect, TextureCubeMap, TextureModeCount}; /// same as glActiveTexture(). useful for setTextureMode. void activeTexture(uint stage); /// same as active texture arb, but with no cache check void forceActiveTexture(uint stage); /// get active texture uint getActiveTexture() const { return _CurrentActiveTexture; } - /** change if needed the texture mode of the current active Texture ARB. - * NB: if CubeMap extension not supported, TextureCubeMap <=> TextureDisabled. - */ - void setTextureMode(TTextureMode texMode); - TTextureMode getTextureMode() const { return _TextureMode[_CurrentActiveTexture]; } - // reset texture mode to the default (disabled) for the current stage. It forces the state (useful after texture shaders) - void resetTextureMode(); // @} // special version for ARB_vertex_program used with ARB_vertex_buffer or ATI_vertex_attrib_array_object @@ -168,7 +160,6 @@ private: float _CurAlphaTestThreshold; uint _CurrentActiveTexture; - TTextureMode _TextureMode[8]; bool _VertexAttribArrayEnabled[CVertexBuffer::NumValue]; 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 c739fcbd1..ac1f1d8bb 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_texture.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_texture.cpp @@ -600,18 +600,18 @@ void CDriverGL3::bindTextureWithMode(ITexture &tex) _DriverGLStates.activeTexture(0); if (tex.isTextureCube()) { - _DriverGLStates.setTextureMode(CDriverGLStates3::TextureCubeMap); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(CDriverGLStates3::TextureCubeMap); // Bind this texture glBindTexture(GL_TEXTURE_CUBE_MAP, gltext->ID); } else { - CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; + // FIXME GL3 TEXTUREMODE CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; - if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) - textureMode = CDriverGLStates3::TextureRect; + // FIXME GL3 TEXTUREMODE if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) + // FIXME GL3 TEXTUREMODE textureMode = CDriverGLStates3::TextureRect; - _DriverGLStates.setTextureMode(textureMode); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(textureMode); // Bind this texture glBindTexture(gltext->TextureMode, gltext->ID); } @@ -692,7 +692,7 @@ bool CDriverGL3::setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded // Disable texture 0 _CurrentTexture[0] = NULL; _CurrentTextureInfoGL[0] = NULL; - _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); // } // @@ -1080,7 +1080,7 @@ bool CDriverGL3::setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded // Disable texture 0 _CurrentTexture[0]= NULL; _CurrentTextureInfoGL[0]= NULL; - _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); } // The texture is correctly setuped. @@ -1119,12 +1119,12 @@ bool CDriverGL3::uploadTexture (ITexture& tex, CRect& rect, uint8 nNumMipMap) // system of "backup the previous binded texture" seems to not work with some drivers.... _DriverGLStates.activeTexture (0); - CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; + // FIXME GL3 TEXTUREMODE CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; - if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) - textureMode = CDriverGLStates3::TextureRect; + // FIXME GL3 TEXTUREMODE if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) + // FIXME GL3 TEXTUREMODE textureMode = CDriverGLStates3::TextureRect; - _DriverGLStates.setTextureMode (textureMode); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode (textureMode); // Bind this texture, for reload... glBindTexture (gltext->TextureMode, gltext->ID); @@ -1172,7 +1172,7 @@ bool CDriverGL3::uploadTexture (ITexture& tex, CRect& rect, uint8 nNumMipMap) { _CurrentTexture[0]= NULL; _CurrentTextureInfoGL[0]= NULL; - _DriverGLStates.setTextureMode (CDriverGLStates3::TextureDisabled); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode (CDriverGLStates3::TextureDisabled); return false; } @@ -1215,7 +1215,7 @@ bool CDriverGL3::uploadTexture (ITexture& tex, CRect& rect, uint8 nNumMipMap) // Disable texture 0 _CurrentTexture[0]= NULL; _CurrentTextureInfoGL[0]= NULL; - _DriverGLStates.setTextureMode (CDriverGLStates3::TextureDisabled); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode (CDriverGLStates3::TextureDisabled); return true; } @@ -1256,7 +1256,7 @@ bool CDriverGL3::activateTexture(uint stage, ITexture *tex) if (tex->isTextureCube()) { // setup texture mode, after activeTexture() - _DriverGLStates.setTextureMode(CDriverGLStates3::TextureCubeMap); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(CDriverGLStates3::TextureCubeMap); // Activate texturing... //====================== @@ -1287,10 +1287,10 @@ bool CDriverGL3::activateTexture(uint stage, ITexture *tex) else { // setup texture mode, after activeTexture() - CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; - if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) - textureMode = CDriverGLStates3::TextureRect; - _DriverGLStates.setTextureMode(/*CDriverGLStates3::Texture2D*/textureMode); + // FIXME GL3 TEXTUREMODE CDriverGLStates3::TTextureMode textureMode= CDriverGLStates3::Texture2D; + // FIXME GL3 TEXTUREMODE if (gltext->TextureMode == GL_TEXTURE_RECTANGLE) + // FIXME GL3 TEXTUREMODE textureMode = CDriverGLStates3::TextureRect; + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(/*CDriverGLStates3::Texture2D*/textureMode); // Activate texture... //====================== @@ -1335,7 +1335,7 @@ bool CDriverGL3::activateTexture(uint stage, ITexture *tex) // Force no texturing for this stage. _CurrentTextureInfoGL[stage]= NULL; // setup texture mode, after activeTexture() - _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); + // FIXME GL3 TEXTUREMODE _DriverGLStates.setTextureMode(CDriverGLStates3::TextureDisabled); /*if (_Extensions.ATITextureEnvCombine3) { 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 b79fb02c2..bbba8902f 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 @@ -199,10 +199,16 @@ namespace for (int i = Weight; i < NumOffsets; ++i) if (hasFlag(desc.VertexFormat, g_VertexFlags[i])) - ss << "smooth out vec4 " << g_AttribNames[i] << ";" << std::endl; + ss << "smooth out vec4 " << g_AttribNames[i] << "; // vertex buffer" << std::endl; ss << std::endl; - - // if (!useTextures) { + + // For now shader will fail to compile if both texgen and vertex buffer tex coord are provided! This is by design. + for (int i = 0; i < IDRV_MAT_MAXTEXTURES; ++i) + if (desc.TexGenMode[i] >= 0) + ss << "smooth out vec4 texCoord" << i << "; // texgen (not implemented)" << std::endl; + ss << std::endl; + + // TODO: Texgen parameters // Ambient color of all lights is precalculated and added with self illumination, and multiplied with the material ambient. if (desc.Lighting) @@ -259,6 +265,14 @@ namespace } } + for (int i = 0; i < IDRV_MAT_MAXTEXTURES; ++i) + { + if (desc.TexGenMode[i] >= 0) + ss << "texCoord" << i << " = vec4(0.0, 0.0, 0.0, 0.0);" << std::endl; + + // TODO: Texgen calculation + } + ss << "}" << std::endl; result = ss.str(); } @@ -342,6 +356,8 @@ void CDriverGL3::setTexGenModeVP(uint stage, sint mode) H_AUTO_OGL(CDriverGL3_setTexGenModeVP) if (m_VPBuiltinCurrent.TexGenMode[stage] != mode) { + if (mode >= 0) + nlwarning("enable texgen %i, %i, not implemented", stage, mode); m_VPBuiltinCurrent.TexGenMode[stage] = mode; m_VPBuiltinTouched = true; }