diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp index 06152d02f..990b8c79a 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp @@ -129,9 +129,6 @@ uint CDriverGL3::_Registered=0; // Version of the driver. Not the interface version!! Increment when implementation of the driver change. const uint32 CDriverGL3::ReleaseVersion = 0x11; -// Number of register to allocate for the EXTVertexShader extension -const uint CDriverGL3::_EVSNumConstant = 97; - GLenum CDriverGL3::NLCubeFaceToGLCubeFace[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, @@ -526,43 +523,6 @@ bool CDriverGL3::setupDisplay() // check whether per pixel lighting shader is supported checkForPerPixelLightingSupport(); - // if EXTVertexShader is used, bind the standard GL arrays, and allocate constant - if ( !_Extensions.ARBVertexProgram && _Extensions.EXTVertexShader) - { - _EVSPositionHandle = nglBindParameterEXT(GL_CURRENT_VERTEX_EXT); - _EVSNormalHandle = nglBindParameterEXT(GL_CURRENT_NORMAL); - _EVSColorHandle = nglBindParameterEXT(GL_CURRENT_COLOR); - - if (!_EVSPositionHandle || !_EVSNormalHandle || !_EVSColorHandle) - { - nlwarning("Unable to bind input parameters for use with EXT_vertex_shader, vertex program support is disabled"); - _Extensions.EXTVertexShader = false; - } - else - { - // bind texture units - for(uint k = 0; k < 8; ++k) - { - _EVSTexHandle[k] = nglBindTextureUnitParameterEXT(GL_TEXTURE0_ARB + k, GL_CURRENT_TEXTURE_COORDS); - } - // Other attributes are managed using variant pointers : - // Secondary color - // Fog Coords - // Skin Weight - // Skin palette - // This mean that they must have 4 components - - // Allocate invariants. One assitionnal variant is needed for fog coordinate if fog bug is not fixed in driver version - _EVSConstantHandle = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_INVARIANT_EXT, GL_FULL_RANGE_EXT, _EVSNumConstant + (_ATIFogRangeFixed ? 0 : 1)); - - if (_EVSConstantHandle == 0) - { - nlwarning("Unable to allocate constants for EXT_vertex_shader, vertex program support is disabled"); - _Extensions.EXTVertexShader = false; - } - } - } - // Reset the vbl interval setSwapVBLInterval(_Interval); @@ -1186,23 +1146,6 @@ void CDriverGL3::setupFog(float start, float end, CRGBA color) glFogfv(GL_FOG_COLOR, _CurrentFogColor); - /** Special : with vertex program, using the extension EXT_vertex_shader, fog is emulated using 1 more constant to scale result to [0, 1] - */ - if (_Extensions.EXTVertexShader && !_Extensions.ARBVertexProgram) - { - if (!_ATIFogRangeFixed) - { - // last constant is used to store fog information (fog must be rescaled to [0, 1], because of a driver bug) - if (start != end) - { - setConstant(_EVSNumConstant, 1.f / (start - end), - end / (start - end), 0, 0); - } - else - { - setConstant(_EVSNumConstant, 0.f, 0, 0, 0); - } - } - } _FogStart = start; _FogEnd = end; } @@ -1323,7 +1266,7 @@ bool CDriverGL3::isWaterShaderSupported() const if(_Extensions.ARBFragmentProgram && ARBWaterShader[0] != 0) return true; - if (!_Extensions.EXTVertexShader && !_Extensions.ARBVertexProgram) return false; // should support vertex programs + if (!_Extensions.ARBVertexProgram) return false; // should support vertex programs if (!_Extensions.NVTextureShader && !_Extensions.ATIFragmentShader && !_Extensions.ARBFragmentProgram) return false; return true; } @@ -1389,12 +1332,12 @@ void CDriverGL3::checkForPerPixelLightingSupport() _SupportPerPixelShaderNoSpec = (_Extensions.NVTextureEnvCombine4 || _Extensions.ATITextureEnvCombine3) && _Extensions.ARBTextureCubeMap && _Extensions.NbTextureStages >= 3 - && ( _Extensions.ARBVertexProgram || _Extensions.EXTVertexShader); + && ( _Extensions.ARBVertexProgram ); _SupportPerPixelShader = (_Extensions.NVTextureEnvCombine4 || _Extensions.ATITextureEnvCombine3) && _Extensions.ARBTextureCubeMap && _Extensions.NbTextureStages >= 2 - && ( _Extensions.ARBVertexProgram || _Extensions.EXTVertexShader); + && ( _Extensions.ARBVertexProgram ); } // *************************************************************************** diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index 5754db6aa..b2f298bd4 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -1171,9 +1171,7 @@ private: /// Tools fct used by setupGLArrays void setupGlArraysStd(CVertexBufferInfo &vb); void setupGlArraysForARBVertexProgram(CVertexBufferInfo &vb); - void setupGlArraysForEXTVertexShader(CVertexBufferInfo &vb); void toggleGlArraysForARBVertexProgram(); - void toggleGlArraysForEXTVertexShader(); /// Test/activate normalisation of normal. void enableGlNormalize(bool normalize) @@ -1291,7 +1289,6 @@ private: /// \name Vertex program implementation // @{ bool activeARBVertexProgram (CVertexProgram *program); - bool activeEXTVertexShader (CVertexProgram *program); //@} @@ -1348,31 +1345,9 @@ private: NLMISC::CRGBA _CurrentBlendConstantColor; - /// \name EXTVertexShader specifics. - // @{ - // Variants offset used for : - // Secondary color - // Fog Coords - // Skin Weight - // Palette Skin - // This mean that they must have 4 components - public: - enum EEVSVariants { EVSSecondaryColorVariant = 0, EVSFogCoordsVariant = 1, EVSSkinWeightVariant = 2, EVSPaletteSkinVariant = 3, EVSNumVariants }; - private: - // Handle for standard gl arrays - GLuint _EVSPositionHandle; - GLuint _EVSNormalHandle; - GLuint _EVSColorHandle; - GLuint _EVSTexHandle[8]; - // Handle of the first constant c[0]. In vertex program we have 96 constant c[0] .. c[95] - GLuint _EVSConstantHandle; - // number of constant - static const uint _EVSNumConstant; - // - bool setupEXTVertexShader(const CVPParser::TProgram &program, GLuint id, uint variants[EVSNumVariants], uint16 &usedInputRegisters); - bool setupARBVertexProgram (const CVPParser::TProgram &parsedProgram, GLuint id, bool &specularWritten); - // - // @} + private: + + bool setupARBVertexProgram (const CVPParser::TProgram &parsedProgram, GLuint id, bool &specularWritten); // init EMBM settings (set each stage to modify the next) void initEMBM(); @@ -1470,17 +1445,6 @@ public: // ARB_vertex_program specific -> must know if specular part is written bool SpecularWritten; - /** EXTVertexShader specific - * handle of allocated variants - */ - GLuint Variants[CDriverGL3::EVSNumVariants]; - /** EXTVertexShader specific - * Used input registers. - * This allow to activate only the gl arrays that are needed by a given shader. - */ - uint16 UsedVertexComponents; - - // The gl id is auto created here. CVertexProgamDrvInfosGL3 (CDriverGL3 *drv, ItVtxPrgDrvInfoPtrList it); }; diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.cpp index be09e1638..af1941843 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.cpp @@ -115,42 +115,6 @@ NEL_PFNGLVERTEXWEIGHTFEXTPROC nglVertexWeightfEXT; NEL_PFNGLVERTEXWEIGHTFVEXTPROC nglVertexWeightfvEXT; NEL_PFNGLVERTEXWEIGHTPOINTEREXTPROC nglVertexWeightPointerEXT; -// VertexShaderExt extension -NEL_PFNGLBEGINVERTEXSHADEREXTPROC nglBeginVertexShaderEXT; -NEL_PFNGLENDVERTEXSHADEREXTPROC nglEndVertexShaderEXT; -NEL_PFNGLBINDVERTEXSHADEREXTPROC nglBindVertexShaderEXT; -NEL_PFNGLGENVERTEXSHADERSEXTPROC nglGenVertexShadersEXT; -NEL_PFNGLDELETEVERTEXSHADEREXTPROC nglDeleteVertexShaderEXT; -NEL_PFNGLSHADEROP1EXTPROC nglShaderOp1EXT; -NEL_PFNGLSHADEROP2EXTPROC nglShaderOp2EXT; -NEL_PFNGLSHADEROP3EXTPROC nglShaderOp3EXT; -NEL_PFNGLSWIZZLEEXTPROC nglSwizzleEXT; -NEL_PFNGLWRITEMASKEXTPROC nglWriteMaskEXT; -NEL_PFNGLINSERTCOMPONENTEXTPROC nglInsertComponentEXT; -NEL_PFNGLEXTRACTCOMPONENTEXTPROC nglExtractComponentEXT; -NEL_PFNGLGENSYMBOLSEXTPROC nglGenSymbolsEXT; -NEL_PFNGLSETINVARIANTEXTPROC nglSetInvariantEXT; -NEL_PFNGLSETLOCALCONSTANTEXTPROC nglSetLocalConstantEXT; -NEL_PFNGLVARIANTPOINTEREXTPROC nglVariantPointerEXT; -NEL_PFNGLENABLEVARIANTCLIENTSTATEEXTPROC nglEnableVariantClientStateEXT; -NEL_PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC nglDisableVariantClientStateEXT; -NEL_PFNGLBINDLIGHTPARAMETEREXTPROC nglBindLightParameterEXT; -NEL_PFNGLBINDMATERIALPARAMETEREXTPROC nglBindMaterialParameterEXT; -NEL_PFNGLBINDTEXGENPARAMETEREXTPROC nglBindTexGenParameterEXT; -NEL_PFNGLBINDTEXTUREUNITPARAMETEREXTPROC nglBindTextureUnitParameterEXT; -NEL_PFNGLBINDPARAMETEREXTPROC nglBindParameterEXT; -NEL_PFNGLISVARIANTENABLEDEXTPROC nglIsVariantEnabledEXT; -NEL_PFNGLGETVARIANTBOOLEANVEXTPROC nglGetVariantBooleanvEXT; -NEL_PFNGLGETVARIANTINTEGERVEXTPROC nglGetVariantIntegervEXT; -NEL_PFNGLGETVARIANTFLOATVEXTPROC nglGetVariantFloatvEXT; -NEL_PFNGLGETVARIANTPOINTERVEXTPROC nglGetVariantPointervEXT; -NEL_PFNGLGETINVARIANTBOOLEANVEXTPROC nglGetInvariantBooleanvEXT; -NEL_PFNGLGETINVARIANTINTEGERVEXTPROC nglGetInvariantIntegervEXT; -NEL_PFNGLGETINVARIANTFLOATVEXTPROC nglGetInvariantFloatvEXT; -NEL_PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC nglGetLocalConstantBooleanvEXT; -NEL_PFNGLGETLOCALCONSTANTINTEGERVEXTPROC nglGetLocalConstantIntegervEXT; -NEL_PFNGLGETLOCALCONSTANTFLOATVEXTPROC nglGetLocalConstantFloatvEXT; - // SecondaryColor extension NEL_PFNGLSECONDARYCOLOR3BEXTPROC nglSecondaryColor3bEXT; NEL_PFNGLSECONDARYCOLOR3BVEXTPROC nglSecondaryColor3bvEXT; @@ -592,81 +556,6 @@ static bool setupARBTextureCubeMap(const char *glext) return true; } - -// ********************************* -static bool setupEXTVertexShader(const char *glext) -{ - H_AUTO_OGL(setupEXTVertexShader); - CHECK_EXT("GL_EXT_vertex_shader"); - - CHECK_ADDRESS(NEL_PFNGLBEGINVERTEXSHADEREXTPROC, glBeginVertexShaderEXT); - CHECK_ADDRESS(NEL_PFNGLENDVERTEXSHADEREXTPROC, glEndVertexShaderEXT); - CHECK_ADDRESS(NEL_PFNGLBINDVERTEXSHADEREXTPROC, glBindVertexShaderEXT); - CHECK_ADDRESS(NEL_PFNGLGENVERTEXSHADERSEXTPROC, glGenVertexShadersEXT); - CHECK_ADDRESS(NEL_PFNGLDELETEVERTEXSHADEREXTPROC, glDeleteVertexShaderEXT); - CHECK_ADDRESS(NEL_PFNGLSHADEROP1EXTPROC, glShaderOp1EXT); - CHECK_ADDRESS(NEL_PFNGLSHADEROP2EXTPROC, glShaderOp2EXT); - CHECK_ADDRESS(NEL_PFNGLSHADEROP3EXTPROC, glShaderOp3EXT); - CHECK_ADDRESS(NEL_PFNGLSWIZZLEEXTPROC, glSwizzleEXT); - CHECK_ADDRESS(NEL_PFNGLWRITEMASKEXTPROC, glWriteMaskEXT); - CHECK_ADDRESS(NEL_PFNGLINSERTCOMPONENTEXTPROC, glInsertComponentEXT); - CHECK_ADDRESS(NEL_PFNGLEXTRACTCOMPONENTEXTPROC, glExtractComponentEXT); - CHECK_ADDRESS(NEL_PFNGLGENSYMBOLSEXTPROC, glGenSymbolsEXT); - CHECK_ADDRESS(NEL_PFNGLSETINVARIANTEXTPROC, glSetInvariantEXT); - CHECK_ADDRESS(NEL_PFNGLSETLOCALCONSTANTEXTPROC, glSetLocalConstantEXT); - CHECK_ADDRESS(NEL_PFNGLVARIANTPOINTEREXTPROC, glVariantPointerEXT); - CHECK_ADDRESS(NEL_PFNGLENABLEVARIANTCLIENTSTATEEXTPROC, glEnableVariantClientStateEXT); - CHECK_ADDRESS(NEL_PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC, glDisableVariantClientStateEXT); - CHECK_ADDRESS(NEL_PFNGLBINDLIGHTPARAMETEREXTPROC, glBindLightParameterEXT); - CHECK_ADDRESS(NEL_PFNGLBINDMATERIALPARAMETEREXTPROC, glBindMaterialParameterEXT); - CHECK_ADDRESS(NEL_PFNGLBINDTEXGENPARAMETEREXTPROC, glBindTexGenParameterEXT); - CHECK_ADDRESS(NEL_PFNGLBINDTEXTUREUNITPARAMETEREXTPROC, glBindTextureUnitParameterEXT); - CHECK_ADDRESS(NEL_PFNGLBINDPARAMETEREXTPROC, glBindParameterEXT); - CHECK_ADDRESS(NEL_PFNGLISVARIANTENABLEDEXTPROC, glIsVariantEnabledEXT); - CHECK_ADDRESS(NEL_PFNGLGETVARIANTBOOLEANVEXTPROC, glGetVariantBooleanvEXT); - CHECK_ADDRESS(NEL_PFNGLGETVARIANTINTEGERVEXTPROC, glGetVariantIntegervEXT); - CHECK_ADDRESS(NEL_PFNGLGETVARIANTFLOATVEXTPROC, glGetVariantFloatvEXT); - CHECK_ADDRESS(NEL_PFNGLGETVARIANTPOINTERVEXTPROC, glGetVariantPointervEXT); - CHECK_ADDRESS(NEL_PFNGLGETINVARIANTBOOLEANVEXTPROC, glGetInvariantBooleanvEXT); - CHECK_ADDRESS(NEL_PFNGLGETINVARIANTINTEGERVEXTPROC, glGetInvariantIntegervEXT); - CHECK_ADDRESS(NEL_PFNGLGETINVARIANTFLOATVEXTPROC, glGetInvariantFloatvEXT); - CHECK_ADDRESS(NEL_PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC, glGetLocalConstantBooleanvEXT); - CHECK_ADDRESS(NEL_PFNGLGETLOCALCONSTANTINTEGERVEXTPROC, glGetLocalConstantIntegervEXT); - CHECK_ADDRESS(NEL_PFNGLGETLOCALCONSTANTFLOATVEXTPROC, glGetLocalConstantFloatvEXT); - - // we require at least 128 instructions, 15 local register (r0, r1,..,r11) + 3 temporary vector for swizzle emulation + 1 vector for indexing temp + 3 temporary scalar for LOGG, EXPP and LIT emulation, 1 address register - // we require 11 variants (4 textures + position + normal + primary color + secondary color + weight + palette skin + fog) - // we also require 2 local constants (0 and 1) - // 96 invariants (c[0], c[1] ..) + 1 invariants for fog emulation (fog coordinate must range from 0 to 1 with EXT_VERTEX_shader) - GLint numVSInst; - glGetIntegerv(GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT, &numVSInst); - if (numVSInst < 128) return false; - // - GLint numVSLocals; - glGetIntegerv(GL_MAX_VERTEX_SHADER_LOCALS_EXT, &numVSLocals); - if (numVSLocals < 4 * (12 + 4) + 1 + 3) - { - nlwarning("EXT_vertex_shader extension has not much register. Some vertex program may fail loading"); - return false; - } - // - GLint numVSLocalConstants; - glGetIntegerv(GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT, &numVSLocalConstants); - if (numVSLocalConstants < 2) return false; - // - GLint numVSInvariants; - glGetIntegerv(GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT, &numVSInvariants); - if (numVSInvariants < 96 + 1) return false; - // - GLint numVSVariants; - glGetIntegerv(GL_MAX_VERTEX_SHADER_VARIANTS_EXT, &numVSVariants); - if (numVSInvariants < 4) return false; - - return true; - -} - - // ********************************* static bool setupEXTSecondaryColor(const char *glext) { @@ -1093,12 +982,10 @@ void registerGlExtensions(CGlExtensions &ext) // Disable feature ??? if(!ext.DisableHardwareVertexProgram) { - ext.EXTVertexShader = setupEXTVertexShader(glext); ext.ARBVertexProgram= setupARBVertexProgram(glext); } else { - ext.EXTVertexShader = false; ext.ARBVertexProgram = false; } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.h index f31238e3d..4614af097 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension.h @@ -47,7 +47,6 @@ struct CGlExtensions bool EXTSeparateSpecularColor; bool NVTextureEnvCombine4; bool ARBTextureCubeMap; - bool EXTVertexShader; bool NVTextureShader; bool NVOcclusionQuery; bool NVTextureRectangle; @@ -127,7 +126,6 @@ public: EXTBlendColor= false; ATIEnvMapBumpMap = false; ATIFragmentShader = false; - EXTVertexShader= false; ARBFragmentProgram = false; ARBVertexProgram = false; NVTextureRectangle = false; @@ -182,7 +180,6 @@ public: result += ATIFragmentShader ? "ATIFragmentShader " : ""; result += ARBFragmentProgram ? "ARBFragmentProgram " : ""; result += ARBVertexProgram ? "ARBVertexProgram " : ""; - result += EXTVertexShader ? "EXTVertexShader " : ""; result += "\n Misc: "; result += EXTVertexWeighting ? "EXTVertexWeighting " : ""; @@ -308,44 +305,6 @@ extern NEL_PFNGLVERTEXWEIGHTFVEXTPROC nglVertexWeightfvEXT; extern NEL_PFNGLVERTEXWEIGHTPOINTEREXTPROC nglVertexWeightPointerEXT; -// VertexShaderExtension. -//======================== -extern NEL_PFNGLBEGINVERTEXSHADEREXTPROC nglBeginVertexShaderEXT; -extern NEL_PFNGLENDVERTEXSHADEREXTPROC nglEndVertexShaderEXT; -extern NEL_PFNGLBINDVERTEXSHADEREXTPROC nglBindVertexShaderEXT; -extern NEL_PFNGLGENVERTEXSHADERSEXTPROC nglGenVertexShadersEXT; -extern NEL_PFNGLDELETEVERTEXSHADEREXTPROC nglDeleteVertexShaderEXT; -extern NEL_PFNGLSHADEROP1EXTPROC nglShaderOp1EXT; -extern NEL_PFNGLSHADEROP2EXTPROC nglShaderOp2EXT; -extern NEL_PFNGLSHADEROP3EXTPROC nglShaderOp3EXT; -extern NEL_PFNGLSWIZZLEEXTPROC nglSwizzleEXT; -extern NEL_PFNGLWRITEMASKEXTPROC nglWriteMaskEXT; -extern NEL_PFNGLINSERTCOMPONENTEXTPROC nglInsertComponentEXT; -extern NEL_PFNGLEXTRACTCOMPONENTEXTPROC nglExtractComponentEXT; -extern NEL_PFNGLGENSYMBOLSEXTPROC nglGenSymbolsEXT; -extern NEL_PFNGLSETINVARIANTEXTPROC nglSetInvariantEXT; -extern NEL_PFNGLSETLOCALCONSTANTEXTPROC nglSetLocalConstantEXT; -extern NEL_PFNGLVARIANTPOINTEREXTPROC nglVariantPointerEXT; -extern NEL_PFNGLENABLEVARIANTCLIENTSTATEEXTPROC nglEnableVariantClientStateEXT; -extern NEL_PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC nglDisableVariantClientStateEXT; -extern NEL_PFNGLBINDLIGHTPARAMETEREXTPROC nglBindLightParameterEXT; -extern NEL_PFNGLBINDMATERIALPARAMETEREXTPROC nglBindMaterialParameterEXT; -extern NEL_PFNGLBINDTEXGENPARAMETEREXTPROC nglBindTexGenParameterEXT; -extern NEL_PFNGLBINDTEXTUREUNITPARAMETEREXTPROC nglBindTextureUnitParameterEXT; -extern NEL_PFNGLBINDPARAMETEREXTPROC nglBindParameterEXT; -extern NEL_PFNGLISVARIANTENABLEDEXTPROC nglIsVariantEnabledEXT; -extern NEL_PFNGLGETVARIANTBOOLEANVEXTPROC nglGetVariantBooleanvEXT; -extern NEL_PFNGLGETVARIANTINTEGERVEXTPROC nglGetVariantIntegervEXT; -extern NEL_PFNGLGETVARIANTFLOATVEXTPROC nglGetVariantFloatvEXT; -extern NEL_PFNGLGETVARIANTPOINTERVEXTPROC nglGetVariantPointervEXT; -extern NEL_PFNGLGETINVARIANTBOOLEANVEXTPROC nglGetInvariantBooleanvEXT; -extern NEL_PFNGLGETINVARIANTINTEGERVEXTPROC nglGetInvariantIntegervEXT; -extern NEL_PFNGLGETINVARIANTFLOATVEXTPROC nglGetInvariantFloatvEXT; -extern NEL_PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC nglGetLocalConstantBooleanvEXT; -extern NEL_PFNGLGETLOCALCONSTANTINTEGERVEXTPROC nglGetLocalConstantIntegervEXT; -extern NEL_PFNGLGETLOCALCONSTANTFLOATVEXTPROC nglGetLocalConstantFloatvEXT; - - // ATI_envmap_bumpmap extension extern PFNGLTEXBUMPPARAMETERIVATIPROC nglTexBumpParameterivATI; diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension_def.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension_def.h index 2919e865f..e2320d419 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension_def.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_extension_def.h @@ -91,44 +91,6 @@ typedef void (APIENTRY * NEL_PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight) typedef void (APIENTRY * NEL_PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); -// VertexShaderExtension (EXT) -//============================ -typedef void (APIENTRY * NEL_PFNGLBEGINVERTEXSHADEREXTPROC) ( void ); -typedef void (APIENTRY * NEL_PFNGLENDVERTEXSHADEREXTPROC) ( void ); -typedef void (APIENTRY * NEL_PFNGLBINDVERTEXSHADEREXTPROC) ( GLuint id ); -typedef GLuint (APIENTRY * NEL_PFNGLGENVERTEXSHADERSEXTPROC) ( GLuint range ); -typedef void (APIENTRY * NEL_PFNGLDELETEVERTEXSHADEREXTPROC) ( GLuint id ); -typedef void (APIENTRY * NEL_PFNGLSHADEROP1EXTPROC) ( GLenum op, GLuint res, GLuint arg1 ); -typedef void (APIENTRY * NEL_PFNGLSHADEROP2EXTPROC) ( GLenum op, GLuint res, GLuint arg1, GLuint arg2 ); -typedef void (APIENTRY * NEL_PFNGLSHADEROP3EXTPROC) ( GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3 ); -typedef void (APIENTRY * NEL_PFNGLSWIZZLEEXTPROC) ( GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW ); -typedef void (APIENTRY * NEL_PFNGLWRITEMASKEXTPROC) ( GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW ); -typedef void (APIENTRY * NEL_PFNGLINSERTCOMPONENTEXTPROC) ( GLuint res, GLuint src, GLuint num ); -typedef void (APIENTRY * NEL_PFNGLEXTRACTCOMPONENTEXTPROC) ( GLuint res, GLuint src, GLuint num ); -typedef GLuint (APIENTRY * NEL_PFNGLGENSYMBOLSEXTPROC) ( GLenum datatype, GLenum storagetype, GLenum range, GLuint components ) ; -typedef void (APIENTRY * NEL_PFNGLSETINVARIANTEXTPROC) ( GLuint id, GLenum type, void *addr ); -typedef void (APIENTRY * NEL_PFNGLSETLOCALCONSTANTEXTPROC) ( GLuint id, GLenum type, void *addr ); -typedef void (APIENTRY * NEL_PFNGLVARIANTPOINTEREXTPROC) ( GLuint id, GLenum type, GLuint stride, void *addr ); -typedef void (APIENTRY * NEL_PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) ( GLuint id); -typedef void (APIENTRY * NEL_PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) ( GLuint id); -typedef GLuint (APIENTRY * NEL_PFNGLBINDLIGHTPARAMETEREXTPROC) ( GLenum light, GLenum value); -typedef GLuint (APIENTRY * NEL_PFNGLBINDMATERIALPARAMETEREXTPROC) ( GLenum face, GLenum value); -typedef GLuint (APIENTRY * NEL_PFNGLBINDTEXGENPARAMETEREXTPROC) ( GLenum unit, GLenum coord, GLenum value); -typedef GLuint (APIENTRY * NEL_PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) ( GLenum unit, GLenum value); -typedef GLuint (APIENTRY * NEL_PFNGLBINDPARAMETEREXTPROC) ( GLenum value); -typedef GLboolean (APIENTRY * NEL_PFNGLISVARIANTENABLEDEXTPROC) ( GLuint id, GLenum cap); -typedef void (APIENTRY * NEL_PFNGLGETVARIANTBOOLEANVEXTPROC) ( GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRY * NEL_PFNGLGETVARIANTINTEGERVEXTPROC) ( GLuint id, GLenum value, GLint *data); -typedef void (APIENTRY * NEL_PFNGLGETVARIANTFLOATVEXTPROC) ( GLuint id, GLenum value, GLfloat *data); -typedef void (APIENTRY * NEL_PFNGLGETVARIANTPOINTERVEXTPROC) ( GLuint id, GLenum value, void **data); -typedef void (APIENTRY * NEL_PFNGLGETINVARIANTBOOLEANVEXTPROC) ( GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRY * NEL_PFNGLGETINVARIANTINTEGERVEXTPROC) ( GLuint id, GLenum value, GLint *data); -typedef void (APIENTRY * NEL_PFNGLGETINVARIANTFLOATVEXTPROC) ( GLuint id, GLenum value, GLfloat *data); -typedef void (APIENTRY * NEL_PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) ( GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRY * NEL_PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) ( GLuint id, GLenum value, GLint *data); -typedef void (APIENTRY * NEL_PFNGLGETLOCALCONSTANTFLOATVEXTPROC) ( GLuint id, GLenum value, GLfloat *data); - - // SecondaryColor extension //======================== typedef void (APIENTRY * NEL_PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); 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 a30727261..81ef9b592 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp @@ -2123,14 +2123,7 @@ void CDriverGL3::setupWaterPassARB(const CMaterial &mat) * So we must add a special path for this case, where the fog coordinate is 'unscaled' again. * NB : this is fixed in later drivers (from 6.14.10.6343), so check this */ - if (_Extensions.EXTVertexShader && !_ATIFogRangeFixed) - { - nglProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, 1.f, 0.f, 0.f, 0.f); - } - else - { - nglProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, - 1.f/ (_FogEnd - _FogStart), _FogEnd / (_FogEnd - _FogStart), 0.f, 0.f); - } + nglProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, - 1.f/ (_FogEnd - _FogStart), _FogEnd / (_FogEnd - _FogStart), 0.f, 0.f); } } } 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 d5f2d8bbd..75a16ab18 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.cpp @@ -940,72 +940,6 @@ void CDriverGLStates3::enableVertexAttribArrayARB(uint glIndex,bool enable) } } -// *************************************************************************** -void CDriverGLStates3::enableVertexAttribArrayForEXTVertexShader(uint glIndex, bool enable, uint *variants) -{ - H_AUTO_OGL(CDriverGLStates3_enableVertexAttribArrayForEXTVertexShader); - - if(_VertexAttribArrayEnabled[glIndex] != enable) - { - switch(glIndex) - { - case 0: // position - enableVertexArray(enable); - break; - case 1: // skin weight - if(enable) - nglEnableVariantClientStateEXT(variants[CDriverGL3::EVSSkinWeightVariant]); - else - nglDisableVariantClientStateEXT(variants[CDriverGL3::EVSSkinWeightVariant]); - break; - case 2: // normal - enableNormalArray(enable); - break; - case 3: // color - enableColorArray(enable); - break; - case 4: // secondary color - if(enable) - nglEnableVariantClientStateEXT(variants[CDriverGL3::EVSSecondaryColorVariant]); - else - nglDisableVariantClientStateEXT(variants[CDriverGL3::EVSSecondaryColorVariant]); - break; - case 5: // fog coordinate - if(enable) - nglEnableVariantClientStateEXT(variants[CDriverGL3::EVSFogCoordsVariant]); - else - nglDisableVariantClientStateEXT(variants[CDriverGL3::EVSFogCoordsVariant]); - break; - case 6: // palette skin - if(enable) - nglEnableVariantClientStateEXT(variants[CDriverGL3::EVSPaletteSkinVariant]); - else - nglDisableVariantClientStateEXT(variants[CDriverGL3::EVSPaletteSkinVariant]); - break; - case 7: // empty - nlstop; - break; - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - clientActiveTextureARB(glIndex - 8); - enableTexCoordArray(enable); - break; - default: - nlstop; // invalid value - break; - } - _VertexAttribArrayEnabled[glIndex]= enable; - } -} - - - // *************************************************************************** void CDriverGLStates3::enableFog(uint enable) { 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 c30e894b2..38f9cfd73 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_states.h @@ -168,10 +168,6 @@ public: /** For vertexProgram. do not check if supported or not. */ void enableVertexAttribArray(uint glIndex, bool enable); - /** Same as enableVertexAttribArray, but for EXTVertexShader (need variant ID) - * \param firstVariantSymbol the first variant symbol - */ - void enableVertexAttribArrayForEXTVertexShader(uint glIndex, bool enable, uint *variants); // special version for ARB_vertex_program used with ARB_vertex_buffer or ATI_vertex_attrib_array_object void enableVertexAttribArrayARB(uint glIndex, bool enable); 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 e9148624e..fb7f1c390 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp @@ -929,55 +929,6 @@ void CDriverGL3::toggleGlArraysForARBVertexProgram() } } - - -// *************************************************************************** -void CDriverGL3::toggleGlArraysForEXTVertexShader() -{ - H_AUTO_OGL(CDriverGL3_toggleGlArraysForEXTVertexShader) - // If change of setup type, must disable olds. - //======================= - - - // If last was a VertexProgram setup, and now it is a standard GL array setup. - if( _LastSetupGLArrayVertexProgram && !isVertexProgramEnabled () ) - { - CVertexProgram *vp = _LastSetuppedVP; - if (vp) - { - CVertexProgamDrvInfosGL3 *drvInfo = NLMISC::safe_cast((IVertexProgramDrvInfos *) vp->_DrvInfo); - if (drvInfo) - { - // Disable all VertexAttribs. - for (uint value=0; valueVariants); - } - } - } - // no more a vertex program setup. - _LastSetupGLArrayVertexProgram= false; - } - - // If last was a standard GL array setup, and now it is a VertexProgram setup. - if( !_LastSetupGLArrayVertexProgram && isVertexProgramEnabled () ) - { - // Disable all standards ptrs. - _DriverGLStates.enableVertexArray(false); - _DriverGLStates.enableNormalArray(false); - _DriverGLStates.enableColorArray(false); - _DriverGLStates.enableSecondaryColorArray(false); - for(uint i=0; i((IVertexProgramDrvInfos *) vp->_DrvInfo); - if (!drvInfo) return; - - uint32 flags= vb.VertexFormat; - - - _DriverGLStates.bindARBVertexBuffer(vb.VertexObjectId); - - // For each value - for (uint value=0; valueUsedVertexComponents) - { - _DriverGLStates.enableVertexAttribArrayForEXTVertexShader(glIndex, true, drvInfo->Variants); - - // use variant or open gl standard array - - { - switch(value) - { - case CVertexBuffer::Position: // position - { - nlassert(NumCoordinatesType[type] >= 2); - glVertexPointer(NumCoordinatesType[type], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - case CVertexBuffer::Weight: // skin weight - { - nlassert(NumCoordinatesType[type] == 4); // variant, only 4 component supported - nglVariantPointerEXT(drvInfo->Variants[CDriverGL3::EVSSkinWeightVariant], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - case CVertexBuffer::Normal: // normal - { - nlassert(NumCoordinatesType[type] == 3); // must have 3 components for normals - glNormalPointer(GLType[type], vb.VertexSize, vb.ValuePtr[CVertexBuffer::Normal]); - } - break; - case CVertexBuffer::PrimaryColor: // color - { - nlassert(NumCoordinatesType[type] >= 3); // must have 3 or 4 components for primary color - glColorPointer(NumCoordinatesType[type], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - case CVertexBuffer::SecondaryColor: // secondary color - { - // implemented using a variant, as not available with EXTVertexShader - nlassert(NumCoordinatesType[type] == 4); // variant, only 4 component supported - nglVariantPointerEXT(drvInfo->Variants[CDriverGL3::EVSSecondaryColorVariant], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - case CVertexBuffer::Fog: // fog coordinate - { - // implemented using a variant - nlassert(NumCoordinatesType[type] == 4); // variant, only 4 component supported - nglVariantPointerEXT(drvInfo->Variants[CDriverGL3::EVSFogCoordsVariant], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - case CVertexBuffer::PaletteSkin: // palette skin - { - // implemented using a variant - nlassert(NumCoordinatesType[type] == 4); // variant, only 4 component supported - nglVariantPointerEXT(drvInfo->Variants[CDriverGL3::EVSPaletteSkinVariant], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - case CVertexBuffer::Empty: // empty - nlstop; - break; - case CVertexBuffer::TexCoord0: - case CVertexBuffer::TexCoord1: - case CVertexBuffer::TexCoord2: - case CVertexBuffer::TexCoord3: - case CVertexBuffer::TexCoord4: - case CVertexBuffer::TexCoord5: - case CVertexBuffer::TexCoord6: - case CVertexBuffer::TexCoord7: - { - _DriverGLStates.clientActiveTextureARB(value - CVertexBuffer::TexCoord0); - glTexCoordPointer(NumCoordinatesType[type], GLType[type], vb.VertexSize, vb.ValuePtr[value]); - } - break; - default: - nlstop; // invalid value - break; - } - } - } - else - { - _DriverGLStates.enableVertexAttribArrayForEXTVertexShader(glIndex, false, drvInfo->Variants); - } - } -} - - - // *************************************************************************** void CDriverGL3::setupGlArrays(CVertexBufferInfo &vb) { @@ -1175,19 +1011,6 @@ void CDriverGL3::setupGlArrays(CVertexBufferInfo &vb) setupGlArraysForARBVertexProgram(vb); } } - else if (_Extensions.EXTVertexShader) - { - toggleGlArraysForEXTVertexShader(); - // Use a vertex program ? - if (!isVertexProgramEnabled ()) - { - setupGlArraysStd(vb); - } - else - { - setupGlArraysForEXTVertexShader(vb); - } - } else { // no vertex programs 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 03061cd70..5cb01bfae 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 @@ -42,18 +42,10 @@ CVertexProgamDrvInfosGL3::CVertexProgamDrvInfosGL3 (CDriverGL3 *drv, ItVtxPrgDrv H_AUTO_OGL(CVertexProgamDrvInfosGL_CVertexProgamDrvInfosGL); // Extension must exist - nlassert (drv->_Extensions.EXTVertexShader - || drv->_Extensions.ARBVertexProgram - ); + nlassert ( drv->_Extensions.ARBVertexProgram ); + + nglGenProgramsARB(1, &ID); - if (drv->_Extensions.ARBVertexProgram) // ARB implementation - { - nglGenProgramsARB(1, &ID); - } - else - { - ID = nglGenVertexShadersEXT(1); // ATI implementation - } } @@ -61,982 +53,7 @@ CVertexProgamDrvInfosGL3::CVertexProgamDrvInfosGL3 (CDriverGL3 *drv, ItVtxPrgDrv bool CDriverGL3::isVertexProgramSupported () const { H_AUTO_OGL(CVertexProgamDrvInfosGL_isVertexProgramSupported) - return _Extensions.EXTVertexShader || _Extensions.ARBVertexProgram; -} - -// *************************************************************************** -static -inline GLenum convSwizzleToGLFormat(CVPSwizzle::EComp comp, bool negate) -{ - H_AUTO_OGL(convSwizzleToGLFormat); - - if (!negate) - { - switch(comp) - { - case CVPSwizzle::X: return GL_X_EXT; - case CVPSwizzle::Y: return GL_Y_EXT; - case CVPSwizzle::Z: return GL_Z_EXT; - case CVPSwizzle::W: return GL_W_EXT; - - default: - nlstop; - return 0; - break; - } - } - else - { - switch(comp) - { - case CVPSwizzle::X: return GL_NEGATIVE_X_EXT; - case CVPSwizzle::Y: return GL_NEGATIVE_Y_EXT; - case CVPSwizzle::Z: return GL_NEGATIVE_Z_EXT; - case CVPSwizzle::W: return GL_NEGATIVE_W_EXT; - - default: - nlstop; - return 0; - break; - } - } -} - -// *************************************************************************** -/** Convert an output register to a EXTVertexShader register - */ -static GLuint convOutputRegisterToEXTVertexShader(CVPOperand::EOutputRegister r) -{ - H_AUTO_OGL(convOutputRegisterToEXTVertexShader); - - switch (r) - { - case CVPOperand::OHPosition: return GL_OUTPUT_VERTEX_EXT; - case CVPOperand::OPrimaryColor: return GL_OUTPUT_COLOR0_EXT; - case CVPOperand::OSecondaryColor: return GL_OUTPUT_COLOR1_EXT; - case CVPOperand::OBackFacePrimaryColor: - nlwarning("Backface color used in a vertex program is not supported by device, defaulting to front color"); - return GL_OUTPUT_COLOR0_EXT; - break; - case CVPOperand::OBackFaceSecondaryColor: - nlwarning("Backface color used in a vertex program is not supported by device, defaulting to front color"); - return GL_OUTPUT_COLOR1_EXT; - break; - case CVPOperand::OFogCoord: return GL_OUTPUT_FOG_EXT; - case CVPOperand::OPointSize: nlstop; return 0; // sorry, not supported - case CVPOperand::OTex0: return GL_OUTPUT_TEXTURE_COORD0_EXT; - case CVPOperand::OTex1: return GL_OUTPUT_TEXTURE_COORD1_EXT; - case CVPOperand::OTex2: return GL_OUTPUT_TEXTURE_COORD2_EXT; - case CVPOperand::OTex3: return GL_OUTPUT_TEXTURE_COORD3_EXT; - case CVPOperand::OTex4: return GL_OUTPUT_TEXTURE_COORD4_EXT; - case CVPOperand::OTex5: return GL_OUTPUT_TEXTURE_COORD5_EXT; - case CVPOperand::OTex6: return GL_OUTPUT_TEXTURE_COORD6_EXT; - case CVPOperand::OTex7: return GL_OUTPUT_TEXTURE_COORD7_EXT; - default: - nlstop; - break; - } - - return 0; -} - -// *************************************************************************** -/** Convert an input register to a vertex buffer flag - */ -static uint convInputRegisterToVBFlag(uint index) -{ - H_AUTO_OGL(convInputRegisterToVBFlag) - switch (index) - { - case CVPOperand::IPosition: return CVertexBuffer::PositionFlag; - case CVPOperand::IWeight: return CVertexBuffer::WeightFlag; - case CVPOperand::INormal: return CVertexBuffer::NormalFlag; - case CVPOperand::IPrimaryColor: return CVertexBuffer::PrimaryColorFlag; - case CVPOperand::ISecondaryColor: return CVertexBuffer::SecondaryColorFlag; - case CVPOperand::IFogCoord: return CVertexBuffer::FogFlag; - case CVPOperand::IPaletteSkin: return CVertexBuffer::PaletteSkinFlag; - case CVPOperand::IEmpty: nlassert(0); break; - case CVPOperand::ITex0: - case CVPOperand::ITex1: - case CVPOperand::ITex2: - case CVPOperand::ITex3: - case CVPOperand::ITex4: - case CVPOperand::ITex5: - case CVPOperand::ITex6: - case CVPOperand::ITex7: - return CVertexBuffer::TexCoord0Flag << (index - CVPOperand::ITex0); - default: - nlassert(0); - break; - } - return 0; -} - - - -// A macro to debug the generated instruction -//#define DEBUG_SETUP_EXT_VERTEX_SHADER - -#ifdef DEBUG_SETUP_EXT_VERTEX_SHADER - #define EVS_INFO(what) nlinfo(what) -#else - #define EVS_INFO(what) -#endif - - -// For debugging with swizzling -static void doSwizzle(GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW) -{ - H_AUTO_OGL(doSwizzle); - - nglSwizzleEXT(res, in, outX, outY, outZ, outW); -#ifdef DEBUG_SETUP_EXT_VERTEX_SHADER - std::string swzStr = "Swizzle : "; - GLenum swz[] = { outX, outY, outZ, outW }; - for(uint k = 0; k < 4; ++k) - { - switch(swz[k]) - { - case GL_X_EXT: - swzStr +=" X"; - break; - case GL_NEGATIVE_X_EXT: - swzStr +=" -X"; - break; - case GL_Y_EXT: - swzStr +=" Y"; - break; - case GL_NEGATIVE_Y_EXT: - swzStr +=" -Y"; - break; - break; - case GL_Z_EXT: - swzStr +=" Z"; - break; - case GL_NEGATIVE_Z_EXT: - swzStr +=" -Z"; - break; - case GL_W_EXT: - swzStr +=" W"; - break; - case GL_NEGATIVE_W_EXT: - swzStr +=" -W"; - break; - case GL_ZERO_EXT: - swzStr +="0"; - break; - case GL_ONE_EXT: - swzStr +="1"; - break; - } - } - EVS_INFO(swzStr.c_str()); -#endif -} - -// Perform write mask and output de bug information -static void doWriteMask(GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW) -{ - H_AUTO_OGL(doWriteMask); - - nglWriteMaskEXT(res, in, outX, outY, outZ, outW); - #ifdef DEBUG_SETUP_EXT_VERTEX_SHADER - nlinfo("3D: Write Mask : %c%c%c%c", - outX ? 'x' : '-', - outY ? 'y' : '-', - outZ ? 'z' : '-', - outW ? 'w' : '-' - ); - #endif -} - -// *************************************************************************** -/** Setup a vertex shader from its parsed program - */ -bool CDriverGL3::setupEXTVertexShader(const CVPParser::TProgram &program, GLuint id, uint variants[EVSNumVariants], uint16 &usedInputRegisters) -{ - H_AUTO_OGL(CDriverGL3_setupEXTVertexShader); - - // counter to see what is generated - uint numOp = 0; - uint numOpIndex = 0; - uint numSwizzle = 0; - uint numEC = 0; // extract component - uint numIC = 0; // insert component - uint numWM = 0; // write maks - - -#ifdef DEBUG_SETUP_EXT_VERTEX_SHADER - nlinfo("3D: **********************************************************"); -#endif - - // clear last error - GLenum glError = glGetError(); - - //variants[EVSSecondaryColorVariant] = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_NORMALIZED_RANGE_EXT, 1); - //variants[EVSSecondaryColorVariant] = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_NORMALIZED_RANGE_EXT, 1); - - // allocate the symbols - nglBindVertexShaderEXT(id); - nglBeginVertexShaderEXT(); - { - - // Allocate register and variant - - // allocate registers - GLuint firstRegister = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 12); // 12 register - GLuint firstTempRegister = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 4); // 4 temp register used for swizzle & indexing - GLuint firstTempScalar = nglGenSymbolsEXT(GL_SCALAR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 3); // 3 temp scalars used for EXPP & LOGG emulation - GLuint firstAddressRegister = nglGenSymbolsEXT(GL_SCALAR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1); - - // allocate needed variants - if (CVPParser::isInputUsed(program, CVPOperand::ISecondaryColor)) - { - variants[EVSSecondaryColorVariant] = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_NORMALIZED_RANGE_EXT, 1); - - if (!variants[EVSSecondaryColorVariant]) - { - nlwarning("EXT_vertex_shader : can't allocate variant for secondary color"); - return false; - } - } - else - { - variants[EVSSecondaryColorVariant] = 0; - } - - if (CVPParser::isInputUsed(program, CVPOperand::IFogCoord)) - { - variants[EVSFogCoordsVariant] = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_FULL_RANGE_EXT, 1); - - if (!variants[EVSFogCoordsVariant]) - { - nlwarning("EXT_vertex_shader : can't allocate variant for fog coords"); - return false; - } - } - else - { - variants[EVSFogCoordsVariant] = 0; - } - - if (CVPParser::isInputUsed(program, CVPOperand::IWeight)) - { - variants[EVSSkinWeightVariant] = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_FULL_RANGE_EXT, 1); - - if (!variants[EVSSkinWeightVariant]) - { - nlwarning("EXT_vertex_shader : can't allocate variant for skin weight"); - return false; - } - } - else - { - variants[EVSSkinWeightVariant] = 0; - } - - if (CVPParser::isInputUsed(program, CVPOperand::IPaletteSkin)) - { - variants[EVSPaletteSkinVariant] = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_FULL_RANGE_EXT, 1); - - if (!variants[EVSPaletteSkinVariant]) - { - nlwarning("EXT_vertex_shader : can't allocate variant for palette skin"); - return false; - } - } - else - { - variants[EVSPaletteSkinVariant] = 0; - } - - // allocate one temporary register for fog before conversion - GLuint fogTemp = 0; - if (!_ATIFogRangeFixed) - { - fogTemp = nglGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1); - } - - - // local constant : 0 and 1 - GLuint cteOne = nglGenSymbolsEXT(GL_SCALAR_EXT, GL_LOCAL_CONSTANT_EXT, GL_FULL_RANGE_EXT, 1); - GLuint cteZero = nglGenSymbolsEXT(GL_SCALAR_EXT, GL_LOCAL_CONSTANT_EXT, GL_FULL_RANGE_EXT, 1); - - - float oneValue = 1.f; - float zeroValue = 0.f; - - nglSetLocalConstantEXT( cteOne, GL_FLOAT, &oneValue); - nglSetLocalConstantEXT( cteZero, GL_FLOAT, &zeroValue); - - - - if (firstRegister == 0) - { - nlwarning("Unable to allocate local registers for EXT_vertex_shader"); - return false; - } - if (firstTempRegister == 0) - { - nlwarning("Unable to allocate local temp registers for EXT_vertex_shader"); - return false; - } - if (firstTempScalar == 0) - { - nlwarning("Unable to allocate temp scalar registers for EXT_vertex_shader"); - return false; - } - if (firstAddressRegister == 0) - { - nlwarning("Unable to allocate address register for EXT_vertex_shader"); - return false; - } - - // Mask of output component that are being written - uint componentWritten[16]; - std::fill(componentWritten, componentWritten + 16, 0); - - // - GLuint srcValue[3]; - // - GLuint destValue; - GLuint maskedDestValue = 0; - - - uint l; - // convert each instruction of the vertex program - for(uint k = 0; k < program.size(); ++k) - { - // get src values, eventually applying swizzle, negate, and index on them - uint numSrc = program[k].getNumUsedSrc(); - for(l = 0; l < numSrc; ++l) - { - EVS_INFO(("Build source " + toString(l)).c_str()); - const CVPOperand &operand = program[k].getSrc(l); - switch (operand.Type) - { - case CVPOperand::InputRegister: - { - switch(operand.Value.InputRegisterValue) - { - case 0: srcValue[l] = _EVSPositionHandle; EVS_INFO("Src = position"); break; - case 1: srcValue[l] = variants[EVSSkinWeightVariant]; EVS_INFO("Src = skin weight"); break; - case 2: srcValue[l] = _EVSNormalHandle; EVS_INFO("Src = normal"); break; - case 3: srcValue[l] = _EVSColorHandle; EVS_INFO("Src = color 0"); break; - case 4: srcValue[l] = variants[EVSSecondaryColorVariant]; EVS_INFO("Src = color 1"); break; - case 5: srcValue[l] = variants[EVSFogCoordsVariant]; EVS_INFO("Src = fog coord"); break; - case 6: srcValue[l] = variants[EVSPaletteSkinVariant]; EVS_INFO("Src = palette skin"); break; - case 7: nlstop; // not supported - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - { - EVS_INFO(("Src = Tex" + toString(operand.Value.InputRegisterValue - 8)).c_str()); - srcValue[l] = _EVSTexHandle[operand.Value.InputRegisterValue - 8]; - if (srcValue[l] == 0) - { - nlwarning("Trying to read an unaccessible texture coords for the device when using EXT_vertex_shader, shader loading failed."); - return false; - } - } - break; - default: - nlstop; // invalid value - break; - } - } - break; - case CVPOperand::Constant: - nlassert(uint(operand.Value.ConstantValue) < _EVSNumConstant); // constant index too high - srcValue[l] = _EVSConstantHandle + operand.Value.ConstantValue; - EVS_INFO(("Src = constant" + toString(operand.Value.ConstantValue)).c_str()); - break; - case CVPOperand::Variable: - srcValue[l] = firstRegister + operand.Value.VariableValue; - EVS_INFO(("Src = variable register" + toString(operand.Value.VariableValue)).c_str()); - break; - default: - nlassert(0); - break; - } - // test if indexed access is used (can be used on one register only) - if (operand.Type == CVPOperand::Constant && operand.Indexed) - { - nglShaderOp2EXT(GL_OP_INDEX_EXT, firstTempRegister + 3, firstAddressRegister, srcValue[l]); - EVS_INFO("GL_OP_INDEX_EXT"); - ++ numOpIndex; - srcValue[l] = firstTempRegister + 3; - glError = glGetError(); - nlassert(glError == GL_NO_ERROR); - } - - // test if swizzle or negate is used - if (!operand.Swizzle.isIdentity() || operand.Negate) - { - // if the instruction reads a scalar, no need for swizzle (except if negate is used) - if (! - ( - (program[k].Opcode == CVPInstruction::RSQ - || program[k].Opcode == CVPInstruction::RCP - || program[k].Opcode == CVPInstruction::LOG - || program[k].Opcode == CVPInstruction::EXPP - ) - && - !operand.Negate - ) - ) - { - // need a temp register for swizzle and/or negate - doSwizzle(firstTempRegister + l, srcValue[l], - convSwizzleToGLFormat(operand.Swizzle.Comp[0], operand.Negate), - convSwizzleToGLFormat(operand.Swizzle.Comp[1], operand.Negate), - convSwizzleToGLFormat(operand.Swizzle.Comp[2], operand.Negate), - convSwizzleToGLFormat(operand.Swizzle.Comp[3], operand.Negate)); - ++numSwizzle; - srcValue[l] = firstTempRegister + l; - glError = glGetError(); - nlassert(glError == GL_NO_ERROR); - } - } - } - - // get dest value - const CVPOperand &destOperand = program[k].Dest; - switch(destOperand.Type) - { - case CVPOperand::Variable: - destValue = firstRegister + destOperand.Value.VariableValue; - break; - case CVPOperand::OutputRegister: - if (_ATIFogRangeFixed || destOperand.Value.OutputRegisterValue != CVPOperand::OFogCoord) - { - destValue = convOutputRegisterToEXTVertexShader(destOperand.Value.OutputRegisterValue); - } - else - { - destValue = fogTemp; - } - break; - case CVPOperand::AddressRegister: - destValue = firstAddressRegister; - break; - default: - nlassert(0); - break; - } - - uint writeMask = program[k].Dest.WriteMask; - CVPInstruction::EOpcode opcode = program[k].Opcode; - uint outputRegisterIndex = 0; - if (destOperand.Type != CVPOperand::AddressRegister) - { - outputRegisterIndex = destOperand.Value.OutputRegisterValue; - nlassert(outputRegisterIndex < 16); - } - - // Tells whether the output has already been written before the final write mask. This happens with instructions LOG, EXPP, LIT, RSQ and RCP, - // because they write their output component by components - bool outputWritten = false; - - // test for write mask - if (writeMask != 0x0f) - { - /** Don't know why, but on some implementation of EXT_vertex_shader, can't write a single components to the fog coordinate.. - * So we force the mask to 0xf (only the x coordinate is used anyway). - */ - if (!(destOperand.Type == CVPOperand::OutputRegister && destOperand.Value.OutputRegisterValue == CVPOperand::OFogCoord)) - { - // For instructions that write their output components by components, we don't need an intermediary register - if (opcode == CVPInstruction::LOG - || opcode == CVPInstruction::EXPP - || opcode == CVPInstruction::LIT - || opcode == CVPInstruction::RSQ - || opcode == CVPInstruction::RCP - ) - { - outputWritten = true; - } - else - { - maskedDestValue = destValue; - // use a temp register before masking - destValue = firstTempRegister; - } - } - else - { - componentWritten[outputRegisterIndex] = 0xf; - } - } - else - { - if (destOperand.Type == CVPOperand::OutputRegister) - { - componentWritten[outputRegisterIndex] = 0xf; // say all components have been written for that output - } - } - - // generate opcode - switch (opcode) - { - case CVPInstruction::ARL: - { - nlassert(program[k].Src1.Swizzle.isScalar()); - GLuint index = program[k].Src1.Swizzle.Comp[0]; - nglExtractComponentEXT(firstAddressRegister, srcValue[0], index); - EVS_INFO("Extract component"); - ++numEC; - } - break; - case CVPInstruction::MOV: - { - nglShaderOp1EXT(GL_OP_MOV_EXT, destValue, srcValue[0]); - EVS_INFO("GL_OP_MOV_EXT"); - ++numOp; - } - break; - case CVPInstruction::MUL: - nglShaderOp2EXT(GL_OP_MUL_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_MUL_EXT"); - ++numOp; - break; - case CVPInstruction::ADD: - nglShaderOp2EXT(GL_OP_ADD_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_ADD_EXT"); - ++numOp; - break; - case CVPInstruction::MAD: - nglShaderOp3EXT(GL_OP_MADD_EXT, destValue, srcValue[0], srcValue[1], srcValue[2]); - EVS_INFO("GL_OP_MADD_EXT"); - ++numOp; - break; - case CVPInstruction::RSQ: - { - nlassert(program[k].Src1.Swizzle.isScalar()); - // extract the component we need - GLuint index = program[k].Src1.Swizzle.Comp[0]; - nglExtractComponentEXT(firstTempScalar, srcValue[0], index); - EVS_INFO("Extract component"); - ++numEC; - nglShaderOp1EXT(GL_OP_RECIP_SQRT_EXT, firstTempScalar + 1, firstTempScalar); - EVS_INFO("GL_OP_RECIP_SQRT_EXT"); - ++numOp; - // duplicate result in destination - for(uint l = 0; l < 4; ++l) - { - if (writeMask & (1 << l)) - { - nglInsertComponentEXT(destValue, firstTempScalar + 1, l); - EVS_INFO("Insert component"); - nlassert(glGetError() == GL_NO_ERROR); - } - } - } - break; - case CVPInstruction::DP3: - nglShaderOp2EXT(GL_OP_DOT3_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_DOT3_EXT"); - ++numOp; - break; - case CVPInstruction::DP4: - nglShaderOp2EXT(GL_OP_DOT4_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_DOT4_EXT"); - ++numOp; - break; - case CVPInstruction::DST: - doSwizzle(firstTempRegister, srcValue[0], GL_ONE_EXT, GL_Y_EXT, GL_Z_EXT, GL_ONE_EXT); - EVS_INFO("GL_OP_DOT4_EXT"); - ++numOp; - doSwizzle(firstTempRegister + 1, srcValue[1], GL_ONE_EXT, GL_Y_EXT, GL_ONE_EXT, GL_W_EXT); - ++numSwizzle; - nglShaderOp2EXT(GL_OP_MUL_EXT, destValue, firstTempRegister, firstTempRegister + 1); - EVS_INFO("GL_OP_MUL_EXT"); - ++numOp; - break; - case CVPInstruction::LIT: - { - uint writeMask = program[k].Dest.WriteMask; - nglExtractComponentEXT(firstTempScalar, srcValue[0], 0); // extract X from the source - if (writeMask & 4) - { - nglExtractComponentEXT(firstTempScalar + 1, srcValue[0], 1); // extract Y from the source - EVS_INFO("Extract component"); - ++numEC; - nglExtractComponentEXT(firstTempScalar + 2, srcValue[0], 3); // extract W from the source - EVS_INFO("Extract component"); - ++numEC; - // result = X > 0 ? Y^W : 0 - nglShaderOp2EXT(GL_OP_POWER_EXT, firstTempScalar + 2, firstTempScalar + 1, firstTempScalar + 2); - EVS_INFO("GL_OP_POWER_EXT"); - ++numOp; - nglShaderOp2EXT(GL_OP_SET_GE_EXT, firstTempScalar + 1, firstTempScalar, cteZero); - EVS_INFO("GL_OP_SET_GE_EXT"); - ++numOp; - nglShaderOp2EXT(GL_OP_MUL_EXT, firstTempScalar + 2, firstTempScalar + 2, firstTempScalar + 1); - EVS_INFO("GL_OP_MUL_EXT"); - ++numOp; - // store result - nglInsertComponentEXT(destValue, firstTempScalar + 2, 2); - EVS_INFO("Insert component"); - ++numIC; - } - if (writeMask & 2) - { - // clamp N.L to [0, 1] - nglShaderOp3EXT(GL_OP_CLAMP_EXT, firstTempScalar, firstTempScalar, cteZero, cteOne); - EVS_INFO("GL_OP_CLAMP_EXT"); - ++numOp; - nglInsertComponentEXT(destValue, firstTempScalar, 1); - EVS_INFO("Insert component"); - ++numIC; - } - // set x and w to 1 if they are not masked - if (writeMask & (1 + 8)) - { - doSwizzle(destValue, destValue, - (writeMask & 1) ? GL_ONE_EXT : GL_X_EXT, - GL_Y_EXT, - GL_Z_EXT, - (writeMask & 8) ? GL_ONE_EXT : GL_W_EXT); - ++numSwizzle; - } - - } - break; - case CVPInstruction::MIN: - nglShaderOp2EXT(GL_OP_MIN_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_MIN_EXT"); - ++numOp; - break; - case CVPInstruction::MAX: - nglShaderOp2EXT(GL_OP_MAX_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_MAX_EXT"); - ++numOp; - break; - case CVPInstruction::SLT: - nglShaderOp2EXT(GL_OP_SET_LT_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_SET_LT_EXT"); - ++numOp; - break; - case CVPInstruction::SGE: - nglShaderOp2EXT(GL_OP_SET_GE_EXT, destValue, srcValue[0], srcValue[1]); - EVS_INFO("GL_OP_SET_GE_EXT"); - ++numOp; - break; - case CVPInstruction::EXPP: - { - uint writeMask = program[k].Dest.WriteMask; - nlassert(program[k].Src1.Swizzle.isScalar()); - GLuint compIndex = program[k].Src1.Swizzle.Comp[0]; - nglExtractComponentEXT(firstTempScalar + 2, srcValue[0], compIndex); // extract W from the source - EVS_INFO("Extract component"); - ++numEC; - if (writeMask & 1) - { - nglShaderOp1EXT(GL_OP_FLOOR_EXT, firstTempScalar, firstTempScalar + 2); // (int) W - EVS_INFO("GL_OP_FLOOR_EXT"); - ++numOp; - nglShaderOp1EXT(GL_OP_EXP_BASE_2_EXT, firstTempScalar, firstTempScalar); // 2 ^ (int) W - EVS_INFO("GL_OP_EXP_BASE_2_EXT"); - ++numOp; - } - if (writeMask & 2) - { - nglShaderOp1EXT(GL_OP_FRAC_EXT, firstTempScalar + 1, firstTempScalar + 2); // frac(W) - EVS_INFO("GL_OP_FRAC_EXT"); - ++numOp; - } - if (writeMask & 4) nglShaderOp1EXT(GL_OP_EXP_BASE_2_EXT, firstTempScalar + 2, firstTempScalar + 2); // 2 ^W - // store the results - if (writeMask & 1) { nglInsertComponentEXT(destValue, firstTempScalar, 0); EVS_INFO("Insert component"); ++numIC; } - if (writeMask & 2) { nglInsertComponentEXT(destValue, firstTempScalar + 1, 1); EVS_INFO("Insert component"); ++numIC; } - if (writeMask & 4) { nglInsertComponentEXT(destValue, firstTempScalar + 2, 2); EVS_INFO("Insert component"); ++numIC; } - // set W to 1 and leave other values unchanged - if (writeMask & 8) { doSwizzle(destValue, destValue, GL_X_EXT, GL_Y_EXT, GL_Z_EXT, GL_ONE_EXT); ++numSwizzle; } - } - break; - case CVPInstruction::LOG: - { - uint writeMask = program[k].Dest.WriteMask; - nlassert(program[k].Src1.Swizzle.isScalar()); - // extract the component we need - nglExtractComponentEXT(firstTempScalar, srcValue[0], (GLuint) program[k].Src1.Swizzle.Comp[0]); - EVS_INFO("Extract component"); - ++numEC; - // get abs(src) : abs(src) = max(src, -src) - nglShaderOp1EXT(GL_OP_NEGATE_EXT, firstTempScalar + 1, firstTempScalar); - EVS_INFO("GL_OP_NEGATE_EXT"); - ++numOp; - nglShaderOp2EXT(GL_OP_MAX_EXT, firstTempScalar, firstTempScalar, firstTempScalar + 1); - EVS_INFO("GL_OP_MAX_EXT"); - ++numOp; - nglShaderOp1EXT(GL_OP_LOG_BASE_2_EXT, firstTempScalar, firstTempScalar); // (int) W - EVS_INFO("GL_OP_LOG_BASE_2_EXT"); - ++numOp; - // store the results - for(uint l = 0; l < 4; ++l) - { - if (writeMask & (1 << l)) - { - nglInsertComponentEXT(destValue, firstTempScalar, l); - EVS_INFO("Insert component"); - nlassert(glGetError() == GL_NO_ERROR); - } - } - } - break; - case CVPInstruction::RCP: - { - uint writeMask = program[k].Dest.WriteMask; - nlassert(program[k].Src1.Swizzle.isScalar()); - // extract the component we need - nglExtractComponentEXT(firstTempScalar, srcValue[0], (GLuint) program[k].Src1.Swizzle.Comp[0]); - EVS_INFO("Extract component"); - ++numEC; - nglShaderOp1EXT(GL_OP_RECIP_EXT, firstTempScalar + 1, firstTempScalar); - EVS_INFO("GL_OP_RECIP_EXT"); - ++numOp; - // duplicate result in destination - for(uint l = 0; l < 4; ++l) - { - if (writeMask & (1 << l)) - { - nglInsertComponentEXT(destValue, firstTempScalar + 1, l); - EVS_INFO("insert component"); - ++numIC; - } - } - } - break; - default: - break; - } - - glError = glGetError(); - nlassert(glError == GL_NO_ERROR); - - - // apply write mask if any - if (writeMask != 0x0f) - { - if ((destOperand.Type == CVPOperand::OutputRegister && destOperand.Value.OutputRegisterValue != CVPOperand::OFogCoord)) - { - uint &outputMask = componentWritten[outputRegisterIndex]; - // is a texture coordinate or a color being written ? - if ((maskedDestValue >= GL_OUTPUT_TEXTURE_COORD0_EXT && maskedDestValue <= GL_OUTPUT_TEXTURE_COORD7_EXT) - || maskedDestValue == GL_OUTPUT_COLOR0_EXT - || maskedDestValue == GL_OUTPUT_COLOR1_EXT - ) - { - // test if this is the last time this output will be written - bool found = false; - // if this was the last write for this output, must set unfilled component - // NB : this loop could be optimized, but vertex program are rather short for now .. - for(uint m = k + 1; m < program.size(); ++m) - { - if (program[m].Dest.Type == CVPOperand::OutputRegister) // another output to this texture ? - { - if (program[m].Dest.Value.OutputRegisterValue == program[k].Dest.Value.OutputRegisterValue) - { - found = true; - break; - } - } - } - - if (found) - { - if (!outputWritten) - { - // write values - doWriteMask(maskedDestValue, destValue, - writeMask & 1 ? GL_TRUE : GL_FALSE, - writeMask & 2 ? GL_TRUE : GL_FALSE, - writeMask & 4 ? GL_TRUE : GL_FALSE, - writeMask & 8 ? GL_TRUE : GL_FALSE); - ++numWM; - } - } - else // this is the last write, check if the mask is complete - { - if ((outputMask | writeMask) == 0xf) - { - if (!outputWritten) - { - // ok, after this call everything has been written - // write values - doWriteMask(maskedDestValue, destValue, - writeMask & 1 ? GL_TRUE : GL_FALSE, - writeMask & 2 ? GL_TRUE : GL_FALSE, - writeMask & 4 ? GL_TRUE : GL_FALSE, - writeMask & 8 ? GL_TRUE : GL_FALSE); - ++numWM; - } - } - else - { - uint prevMask = outputMask; - uint newMask = writeMask | outputMask; - - // complete unused entries - - // if primary color is output, then the default color is white - if (maskedDestValue == GL_OUTPUT_COLOR0_EXT) - { - doSwizzle(firstTempRegister, destValue, - newMask & 1 ? GL_X_EXT : GL_ONE_EXT, - newMask & 2 ? GL_Y_EXT : GL_ONE_EXT, - newMask & 4 ? GL_Z_EXT : GL_ONE_EXT, - newMask & 8 ? GL_W_EXT : GL_ONE_EXT); - } - else - { - doSwizzle(firstTempRegister, destValue, - newMask & 1 ? GL_X_EXT : GL_ZERO_EXT, - newMask & 2 ? GL_Y_EXT : GL_ZERO_EXT, - newMask & 4 ? GL_Z_EXT : GL_ZERO_EXT, - newMask & 8 ? GL_W_EXT : GL_ONE_EXT); - } - if (!outputWritten) - { - ++numWM; - doWriteMask(maskedDestValue, firstTempRegister, - prevMask & 1 ? GL_FALSE : GL_TRUE, - prevMask & 2 ? GL_FALSE : GL_TRUE, - prevMask & 4 ? GL_FALSE : GL_TRUE, - prevMask & 8 ? GL_FALSE : GL_TRUE - ); - ++numWM; - } - outputMask = 0xf; - } - } - } - else - { - if (!outputWritten) - { - doWriteMask(maskedDestValue, destValue, - writeMask & 1 ? GL_TRUE : GL_FALSE, - writeMask & 2 ? GL_TRUE : GL_FALSE, - writeMask & 4 ? GL_TRUE : GL_FALSE, - writeMask & 8 ? GL_TRUE : GL_FALSE); - ++numWM; - } - } - // complete the mask - outputMask |= writeMask; - } - else if (destOperand.Type != CVPOperand::OutputRegister) - { - if (!outputWritten) - { - doWriteMask(maskedDestValue, destValue, - writeMask & 1 ? GL_TRUE : GL_FALSE, - writeMask & 2 ? GL_TRUE : GL_FALSE, - writeMask & 4 ? GL_TRUE : GL_FALSE, - writeMask & 8 ? GL_TRUE : GL_FALSE); - ++numWM; - } - } - } - - glError = glGetError(); - nlassert(glError == GL_NO_ERROR); - } - - - - // if color have not been written, write with default values - if (componentWritten[CVPOperand::OPrimaryColor] == 0) - { - // we specify vertex coord has input for swizzle, but we don't read any component.. - doSwizzle(GL_OUTPUT_COLOR0_EXT, _EVSPositionHandle, GL_ZERO_EXT, GL_ZERO_EXT, GL_ZERO_EXT, GL_ONE_EXT); - EVS_INFO("Swizzle (Complete primary color)"); - ++numSwizzle; - } - else - { - nlassert(componentWritten[CVPOperand::OPrimaryColor] == 0xf); - } - if (componentWritten[CVPOperand::OSecondaryColor] == 0) - { - // we specify vertex coord has input for swizzle, but we don't read any component.. - doSwizzle(GL_OUTPUT_COLOR1_EXT, _EVSPositionHandle, GL_ZERO_EXT, GL_ZERO_EXT, GL_ZERO_EXT, GL_ONE_EXT); - EVS_INFO("Swizzle (Complete secondary color)"); - ++numSwizzle; - } - else - { - nlassert(componentWritten[CVPOperand::OSecondaryColor] == 0xf); - } - nlassert(componentWritten[CVPOperand::OHPosition] == 0xf); // should have written all component of position - - glError = glGetError(); - nlassert(glError == GL_NO_ERROR); - - // if fog has been written, perform conversion (if there's no ATI driver fix) - if (!_ATIFogRangeFixed && componentWritten[CVPOperand::OFogCoord] == 0xf) - { - // Well this could be avoided, but we should make 2 cases for each vertex program.. :( - doSwizzle(firstTempRegister, _EVSConstantHandle + _EVSNumConstant, GL_X_EXT, GL_X_EXT, GL_X_EXT, GL_X_EXT); - doSwizzle(firstTempRegister + 1, _EVSConstantHandle + _EVSNumConstant, GL_Y_EXT, GL_Y_EXT, GL_Y_EXT, GL_Y_EXT); - nglShaderOp3EXT(GL_OP_MADD_EXT, firstTempRegister + 2, fogTemp, firstTempRegister, firstTempRegister + 1); - EVS_INFO("Use MAD for fog conversion"); - nglExtractComponentEXT(GL_OUTPUT_FOG_EXT, firstTempRegister + 2, 0); - EVS_INFO("Extract component to fog"); - } - - glError = glGetError(); - nlassert(glError == GL_NO_ERROR); - } - nglEndVertexShaderEXT(); - - /*glError = glGetError(); - nlassert(glError == GL_NO_ERROR);*/ - - GLboolean optimizedShader; - glGetBooleanv(GL_VERTEX_SHADER_OPTIMIZED_EXT, &optimizedShader); - if (!optimizedShader) - { - nlwarning("Failed to optimize a vertex program with the EXT_vertex_shader extension, this shader will be disabled"); - return false; - } - - // see which input registers are used - usedInputRegisters = 0; - - uint k, l; - // convert each instruction of the vertex program - for(k = 0; k < program.size(); ++k) - { - uint numSrc = program[k].getNumUsedSrc(); - for(l = 0; l < numSrc; ++l) - { - const CVPOperand &op = program[k].getSrc(l); - if (op.Type == CVPOperand::InputRegister) - { - usedInputRegisters |= convInputRegisterToVBFlag(op.Value.InputRegisterValue); - } - } - } - -#ifdef DEBUG_SETUP_EXT_VERTEX_SHADER - nlinfo("3D: ========================"); - nlinfo("3D: num Opcode = %d", numOp); - nlinfo("3D: num Indexing = %d", numOpIndex); - nlinfo("3D: num Swizzle = %d", numSwizzle); - nlinfo("3D: num extract component = %d", numEC); - nlinfo("3D: num insert component = %d", numIC); - nlinfo("3D: num write mask = %d", numWM); -#endif - - return true; + return _Extensions.ARBVertexProgram; } //================================================================================================= @@ -1401,94 +418,13 @@ bool CDriverGL3::activeARBVertexProgram (CVertexProgram *program) return true; } -// *************************************************************************** -bool CDriverGL3::activeEXTVertexShader (CVertexProgram *program) -{ - H_AUTO_OGL(CDriverGL3_activeEXTVertexShader); - - // 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; - } - - /* - FILE *f = fopen(getLogDirectory() + "test.txt", "wb"); - if (f) - { - std::string vpText; - CVPParser::dump(parsedProgram, vpText); - fwrite(vpText.c_str(), vpText.size(), 1, f); - fclose(f); - } - */ - - // 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 (!setupEXTVertexShader(parsedProgram, drvInfo->ID, drvInfo->Variants, drvInfo->UsedVertexComponents)) - { - 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_SHADER_EXT); - _VertexProgramEnabled = true; - nglBindVertexShaderEXT( drvInfo->ID ); - _LastSetuppedVP = program; - } - else - { - glDisable( GL_VERTEX_SHADER_EXT ); - _VertexProgramEnabled = false; - } - return true; -} - // *************************************************************************** bool CDriverGL3::activeVertexProgram (CVertexProgram *program) { H_AUTO_OGL(CDriverGL3_activeVertexProgram) // Extension here ? - if (_Extensions.ARBVertexProgram) - { - return activeARBVertexProgram(program); - } - else if (_Extensions.EXTVertexShader) - { - return activeEXTVertexShader(program); - } - + return activeARBVertexProgram(program); + // Can't do anything return false; } @@ -1501,15 +437,8 @@ void CDriverGL3::setConstant (uint index, float f0, float f1, float f2, float f3 H_AUTO_OGL(CDriverGL3_setConstant); // Vertex program exist ? - if (_Extensions.ARBVertexProgram) - { - nglProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, index, f0, f1, f2, f3); - } - else if (_Extensions.EXTVertexShader) - { - float datas[] = { f0, f1, f2, f3 }; - nglSetInvariantEXT(_EVSConstantHandle + index, GL_FLOAT, datas); - } + nglProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, index, f0, f1, f2, f3); + } @@ -1519,16 +448,7 @@ void CDriverGL3::setConstant (uint index, double d0, double d1, double d2, doubl { H_AUTO_OGL(CDriverGL3_setConstant); - // Vertex program exist ? - if (_Extensions.ARBVertexProgram) - { - nglProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, index, d0, d1, d2, d3); - } - else if (_Extensions.EXTVertexShader) - { - double datas[] = { d0, d1, d2, d3 }; - nglSetInvariantEXT(_EVSConstantHandle + index, GL_DOUBLE, datas); - } + nglProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, index, d0, d1, d2, d3); } @@ -1538,16 +458,7 @@ void CDriverGL3::setConstant (uint index, const NLMISC::CVector& value) { H_AUTO_OGL(CDriverGL3_setConstant); - // Vertex program exist ? - if (_Extensions.ARBVertexProgram) - { - nglProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, index, value.x, value.y, value.z, 0); - } - else if (_Extensions.EXTVertexShader) - { - float datas[] = { value.x, value.y, value.z, 0 }; - nglSetInvariantEXT(_EVSConstantHandle + index, GL_FLOAT, datas); - } + nglProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, index, value.x, value.y, value.z, 0); } @@ -1557,16 +468,7 @@ void CDriverGL3::setConstant (uint index, const NLMISC::CVectorD& value) { H_AUTO_OGL(CDriverGL3_setConstant); - // Vertex program exist ? - if (_Extensions.ARBVertexProgram) - { - nglProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, index, value.x, value.y, value.z, 0); - } - else if (_Extensions.EXTVertexShader) - { - double datas[] = { value.x, value.y, value.z, 0 }; - nglSetInvariantEXT(_EVSConstantHandle + index, GL_DOUBLE, datas); - } + nglProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, index, value.x, value.y, value.z, 0); } @@ -1575,21 +477,11 @@ void CDriverGL3::setConstant (uint index, uint num, const float *src) { H_AUTO_OGL(CDriverGL3_setConstant); - // Vertex program exist ? - if (_Extensions.ARBVertexProgram) - { - for(uint k = 0; k < num; ++k) - { - nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index + k, src + 4 * k); - } - } - else if (_Extensions.EXTVertexShader) + for(uint k = 0; k < num; ++k) { - for(uint k = 0; k < num; ++k) - { - nglSetInvariantEXT(_EVSConstantHandle + index + k, GL_FLOAT, (void *) (src + 4 * k)); - } + nglProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index + k, src + 4 * k); } + } // *************************************************************************** @@ -1597,20 +489,9 @@ void CDriverGL3::setConstant (uint index, uint num, const double *src) { H_AUTO_OGL(CDriverGL3_setConstant); - // Vertex program exist ? - if (_Extensions.ARBVertexProgram) + for(uint k = 0; k < num; ++k) { - for(uint k = 0; k < num; ++k) - { - nglProgramEnvParameter4dvARB(GL_VERTEX_PROGRAM_ARB, index + k, src + 4 * k); - } - } - else if (_Extensions.EXTVertexShader) - { - for(uint k = 0; k < num; ++k) - { - nglSetInvariantEXT(_EVSConstantHandle + index + k, GL_DOUBLE, (void *) (src + 4 * k)); - } + nglProgramEnvParameter4dvARB(GL_VERTEX_PROGRAM_ARB, index + k, src + 4 * k); } } @@ -1681,20 +562,12 @@ void CDriverGL3::setConstantMatrix (uint index, IDriver::TMatrix matrix, IDriver mat.transpose(); float matDatas[16]; mat.get(matDatas); - if (_Extensions.ARBVertexProgram) - { - 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); - } - else - { - nglSetInvariantEXT(_EVSConstantHandle + index, GL_FLOAT, matDatas); - nglSetInvariantEXT(_EVSConstantHandle + index + 1, GL_FLOAT, matDatas + 4); - nglSetInvariantEXT(_EVSConstantHandle + index + 2, GL_FLOAT, matDatas + 8); - nglSetInvariantEXT(_EVSConstantHandle + index + 3, GL_FLOAT, matDatas + 12); - } + + 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); + } }