From abafc9b1ef99c1e2767162bbc4994f725bbf3884 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 10 Sep 2013 15:42:42 +0200 Subject: [PATCH] Adjust landscape vertex program to use new interface --HG-- branch : multipass-stereo --- code/nel/include/nel/3d/driver.h | 2 + code/nel/include/nel/3d/gpu_program.h | 98 ++++------- .../include/nel/3d/landscapevb_allocator.h | 26 ++- .../src/3d/driver/direct3d/driver_direct3d.h | 1 + .../direct3d/driver_direct3d_uniform.cpp | 2 +- code/nel/src/3d/driver/opengl/driver_opengl.h | 1 + .../driver/opengl/driver_opengl_uniform.cpp | 28 ++-- code/nel/src/3d/gpu_program.cpp | 154 +++--------------- code/nel/src/3d/landscape.cpp | 35 ++-- code/nel/src/3d/landscapevb_allocator.cpp | 96 ++++++++--- code/nel/src/3d/water_model.cpp | 6 +- code/nel/src/3d/water_shape.cpp | 6 - 12 files changed, 199 insertions(+), 256 deletions(-) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 9ad704f81..a97606a97 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -1202,6 +1202,8 @@ public: virtual bool setUniformDriver(TProgram program) = 0; // set all driver-specific features params (based on program->features->DriverFlags) (called automatically when rendering with cmaterial and using a user program) virtual bool setUniformMaterial(TProgram program, CMaterial &material) = 0; // set all material-specific feature params (based on program->features->MaterialFlags) (called automatically when rendering with cmaterial and using a user program) virtual void setUniformParams(TProgram program, CGPUProgramParams ¶ms) = 0; // set all user-provided params from the storage + // Return true if uniforms are kept as program state and switched together with programs, false if uniforms are driver state and stay accross program switches. + virtual bool isUniformProgramState() = 0; // @} diff --git a/code/nel/include/nel/3d/gpu_program.h b/code/nel/include/nel/3d/gpu_program.h index 01a48614b..30fa23c52 100644 --- a/code/nel/include/nel/3d/gpu_program.h +++ b/code/nel/include/nel/3d/gpu_program.h @@ -60,12 +60,13 @@ public: virtual uint getUniformIndex(const char *name) const = 0; }; -#define NL_GPU_PROGRAM_LIGHTS 8 - -/// Features exposed by a program. Used to set builtin parameters on user provided shaders +// Features exposed by a program. Used to set builtin parameters on user provided shaders. +// This is only used for user provided shaders, not for builtin shaders, +// as it is a slow method which has to go through all of the options every time. +// Builtin shaders should set all flags to 0. struct CGPUProgramFeatures { - CGPUProgramFeatures() : DriverFlags(0), MaterialFlags(0) /*, NumLights(0) */ { } + CGPUProgramFeatures() : DriverFlags(0), MaterialFlags(0) { } // Driver builtin parameters enum TDriverFlags @@ -73,11 +74,11 @@ struct CGPUProgramFeatures // Matrices ModelView = 0x00000001, ModelViewInverse = 0x00000002, - ModelViewTranspose = 0x00000004, + ModelViewTranspose = 0x00000004, ModelViewInverseTranspose = 0x00000008, Projection = 0x00000010, - ProjectionInverse = 0x00000020, + ProjectionInverse = 0x00000020, ProjectionTranspose = 0x00000040, ProjectionInverseTranspose = 0x00000080, @@ -88,84 +89,54 @@ struct CGPUProgramFeatures // Fog Fog = 0x00001000, - - // - // Rough example, modify as necessary. - // - - // Lighting (todo) - /// Driver ambient, must be ignored when material ambient is flagged - //DriverAmbient = 0x00001000, - /// Lights, does not set diffuses if material lights is flagged - //DriverLights = 0x00002000, - // etcetera - - // Fog (todo) - // Fog = ..., }; uint32 DriverFlags; - // uint NumLights; // number of lights supported by the program (not used yet, modify as necessary) + // uint NumLights; enum TMaterialFlags { /// Use the CMaterial texture stages as the textures for a Pixel Program - TextureStages = 0x00000001, // <- don't remove this one, it's already used, if you want to split them up into the different stages, then it's ok to change it + TextureStages = 0x00000001, TextureMatrices = 0x00000002, - - // - // Rough example, modify as necessary. - // - - // Lighting (todo) - /// Material ambient premultiplied with driver ambient - //MaterialAmbient = 0x00000002, - /// Premultiply lights diffuse with material diffuse, requires driver lights to be flagged - //MaterialLights = 0x00000004, - // etcetera - - // Add all necessary feature sets used with builtin materials here }; // Material builtin parameters uint32 MaterialFlags; }; -/// Stucture used to cache the indices of builtin parameters -struct CGPUProgramIndices +// Stucture used to cache the indices of builtin parameters which are used by the drivers +// Not used for parameters of specific nl3d programs +struct CGPUProgramIndex { - uint ModelView; - uint ModelViewInverse; - uint ModelViewTranspose; - uint ModelViewInverseTranspose; + enum TName + { + ModelView, + ModelViewInverse, + ModelViewTranspose, + ModelViewInverseTranspose, - uint Projection; - uint ProjectionInverse; - uint ProjectionTranspose; - uint ProjectionInverseTranspose; + Projection, + ProjectionInverse, + ProjectionTranspose, + ProjectionInverseTranspose, - uint ModelViewProjection; - uint ModelViewProjectionInverse; - uint ModelViewProjectionTranspose; - uint ModelViewProjectionInverseTranspose; + ModelViewProjection, + ModelViewProjectionInverse, + ModelViewProjectionTranspose, + ModelViewProjectionInverseTranspose, - uint Fog; + Fog, - // - // Rough example, modify as necessary. - // - //uint Ambient; - - //uint LightType[NL_GPU_PROGRAM_LIGHTS]; - //uint LightAmbient[NL_GPU_PROGRAM_LIGHTS]; - //uint LightDiffuse[NL_GPU_PROGRAM_LIGHTS]; - //uint LightPosition[NL_GPU_PROGRAM_LIGHTS]; - //uint LightDirection[NL_GPU_PROGRAM_LIGHTS]; + NUM_UNIFORMS + }; + static const char *Names[NUM_UNIFORMS]; + uint Indices[NUM_UNIFORMS]; }; /** * \brief IGPUProgram * \date 2013-09-07 15:00GMT * \author Jan Boon (Kaetemi) - * A compiled GPU program + * A generic GPU program */ class IGPUProgram : public NLMISC::CRefCount { @@ -234,6 +205,7 @@ public: const char *SourcePtr; size_t SourceLen; /// Copy the source code string + inline void setSource(const std::string &source) { SourceCopy = source; SourcePtr = &SourceCopy[0]; SourceLen = SourceCopy.size(); } inline void setSource(const char *source) { SourceCopy = source; SourcePtr = &SourceCopy[0]; SourceLen = SourceCopy.size(); } /// Set pointer to source code string without copying the string inline void setSourcePtr(const char *sourcePtr, size_t sourceLen) { SourceCopy.clear(); SourcePtr = sourcePtr; SourceLen = sourceLen; } @@ -262,11 +234,11 @@ public: // Get the idx of a parameter (ogl: uniform, d3d: constant, etcetera) by name. Invalid name returns ~0 inline uint getUniformIndex(const char *name) const { return m_DrvInfo->getUniformIndex(name); }; + inline uint getUniformIndex(CGPUProgramIndex::TName name) const { return m_Index.Indices[name]; } // Get feature information of the current program inline CSource *source() const { return m_Source; }; inline const CGPUProgramFeatures &features() const { return m_Source->Features; }; - inline const CGPUProgramIndices &indices() const { return m_Indices; }; inline TProfile profile() const { return m_Source->Profile; } // Build feature info, called automatically by the driver after compile succeeds @@ -281,7 +253,7 @@ protected: /// The source used for compilation NLMISC::CSmartPtr m_Source; - CGPUProgramIndices m_Indices; + CGPUProgramIndex m_Index; public: /// The driver information. For the driver implementation only. diff --git a/code/nel/include/nel/3d/landscapevb_allocator.h b/code/nel/include/nel/3d/landscapevb_allocator.h index d3a081e7b..0e485e990 100644 --- a/code/nel/include/nel/3d/landscapevb_allocator.h +++ b/code/nel/include/nel/3d/landscapevb_allocator.h @@ -21,6 +21,7 @@ #include "nel/misc/smart_ptr.h" #include "nel/3d/tessellation.h" #include "nel/3d/vertex_buffer.h" +#include "nel/3d/vertex_program.h" namespace NL3D @@ -41,6 +42,7 @@ class CVertexProgram; #define NL3D_LANDSCAPE_VPPOS_DELTAPOS (CVertexBuffer::TexCoord3) #define NL3D_LANDSCAPE_VPPOS_ALPHAINFO (CVertexBuffer::TexCoord4) +class CVertexProgramLandscape; // *************************************************************************** /** @@ -107,6 +109,8 @@ public: * Give a vertexProgram Id to activate. Always 0, but 1 For tile Lightmap Pass. */ void activate(uint vpId); + void activateVP(uint vpId); + inline CVertexProgramLandscape *getVP(uint vpId) const { return _VertexProgram[vpId]; } // @} @@ -151,15 +155,35 @@ private: /// \name Vertex Program mgt . // @{ +public: enum {MaxVertexProgram= 2,}; // Vertex Program , NULL if not enabled. - CVertexProgram *_VertexProgram[MaxVertexProgram]; +private: + NLMISC::CSmartPtr _VertexProgram[MaxVertexProgram]; void deleteVertexProgram(); void setupVBFormatAndVertexProgram(bool withVertexProgram); // @} }; +class CVertexProgramLandscape : public CVertexProgram +{ +public: + struct CIdx + { + uint ProgramConstants0; + uint RefineCenter; + uint TileDist; + uint PZBModelPosition; + }; + CVertexProgramLandscape(CLandscapeVBAllocator::TType type, bool lightMap = false); + virtual ~CVertexProgramLandscape() { } + virtual void buildInfo(); +public: + const CIdx &idx() const { return m_Idx; } + CIdx m_Idx; +}; + } // NL3D diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index a7567f0f8..b3a8f5f37 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -1211,6 +1211,7 @@ public: virtual bool setUniformDriver(TProgram program); // set all driver-specific features params (based on program->features->DriverFlags) virtual bool setUniformMaterial(TProgram program, CMaterial &material); // set all material-specific feature params (based on program->features->MaterialFlags) virtual void setUniformParams(TProgram program, CGPUProgramParams ¶ms); // set all user-provided params from the storage + virtual bool isUniformProgramState() { return false; } // @} diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_uniform.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_uniform.cpp index 78799584d..a77a86549 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_uniform.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_uniform.cpp @@ -222,7 +222,7 @@ bool CDriverD3D::setUniformDriver(TProgram program) return true; } -bool CDriverD3D::setUniformMaterial(TProgram program, const CMaterial &material) +bool CDriverD3D::setUniformMaterial(TProgram program, CMaterial &material) { // todo diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index aea5b825b..e20d7d4fa 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -1418,6 +1418,7 @@ private: virtual bool setUniformMaterial(TProgram program, CMaterial &material); // set all material-specific feature params (based on program->features->MaterialFlags) bool setUniformMaterialInternal(TProgram program, CMaterial &material); // set all material-specific feature params (based on program->features->MaterialFlags) virtual void setUniformParams(TProgram program, CGPUProgramParams ¶ms); // set all user-provided params from the storage + virtual bool isUniformProgramState() { return false; } // @} diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp index 382d2bd8a..a23235d06 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp @@ -311,55 +311,55 @@ bool CDriverGL::setUniformDriver(TProgram program) { if (features.DriverFlags & CGPUProgramFeatures::ModelView) { - setUniformMatrix(program, prog->indices().ModelView, ModelView, Identity); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelView), ModelView, Identity); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverse) { - setUniformMatrix(program, prog->indices().ModelViewInverse, ModelView, Inverse); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewInverse), ModelView, Inverse); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewTranspose) { - setUniformMatrix(program, prog->indices().ModelViewTranspose, ModelView, Transpose); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewTranspose), ModelView, Transpose); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverseTranspose) { - setUniformMatrix(program, prog->indices().ModelViewInverseTranspose, ModelView, InverseTranspose); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewInverseTranspose), ModelView, InverseTranspose); } if (features.DriverFlags & CGPUProgramFeatures::Projection) { - setUniformMatrix(program, prog->indices().Projection, Projection, Identity); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::Projection), Projection, Identity); } if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverse) { - setUniformMatrix(program, prog->indices().ProjectionInverse, Projection, Inverse); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ProjectionInverse), Projection, Inverse); } if (features.DriverFlags & CGPUProgramFeatures::ProjectionTranspose) { - setUniformMatrix(program, prog->indices().ProjectionTranspose, Projection, Transpose); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ProjectionTranspose), Projection, Transpose); } if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverseTranspose) { - setUniformMatrix(program, prog->indices().ProjectionInverseTranspose, Projection, InverseTranspose); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ProjectionInverseTranspose), Projection, InverseTranspose); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjection) { - setUniformMatrix(program, prog->indices().ModelViewProjection, ModelViewProjection, Identity); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjection), ModelViewProjection, Identity); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverse) { - setUniformMatrix(program, prog->indices().ModelViewProjectionInverse, ModelViewProjection, Inverse); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionInverse), ModelViewProjection, Inverse); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionTranspose) { - setUniformMatrix(program, prog->indices().ModelViewProjectionTranspose, ModelViewProjection, Transpose); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionTranspose), ModelViewProjection, Transpose); } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverseTranspose) { - setUniformMatrix(program, prog->indices().ModelViewProjectionInverseTranspose, ModelViewProjection, InverseTranspose); + setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionInverseTranspose), ModelViewProjection, InverseTranspose); } if (features.DriverFlags & CGPUProgramFeatures::Fog) { - setUniformFog(program, prog->indices().Fog); + setUniformFog(program, prog->getUniformIndex(CGPUProgramIndex::Fog)); } } @@ -432,7 +432,7 @@ bool CDriverGL::setUniformMaterialInternal(TProgram program, CMaterial &material if (features.MaterialFlags & ~(CGPUProgramFeatures::TextureStages | CGPUProgramFeatures::TextureMatrices)) { - // todo + // none } return true; diff --git a/code/nel/src/3d/gpu_program.cpp b/code/nel/src/3d/gpu_program.cpp index 0ffdb49d9..4e5916398 100644 --- a/code/nel/src/3d/gpu_program.cpp +++ b/code/nel/src/3d/gpu_program.cpp @@ -72,6 +72,26 @@ IGPUProgram::~IGPUProgram() m_DrvInfo.kill(); } +const char *CGPUProgramIndex::Names[NUM_UNIFORMS] = +{ + "modelView", + "modelViewInverse", + "modelViewTranspose", + "modelViewInverseTranspose", + + "projection", + "projectionInverse", + "projectionTranspose", + "projectionInverseTranspose", + + "modelViewProjection", + "modelViewProjectionInverse", + "modelViewProjectionTranspose", + "modelViewProjectionInverseTranspose", + + "fog", +}; + void IGPUProgram::buildInfo(CSource *source) { nlassert(!m_Source); @@ -79,140 +99,10 @@ void IGPUProgram::buildInfo(CSource *source) m_Source = source; // Fill index cache - CGPUProgramFeatures &features = m_Source->Features; - TProfile profile = m_Source->Profile; // for special cases - - if (features.DriverFlags & CGPUProgramFeatures::ModelView) + for (int i = 0; i < CGPUProgramIndex::NUM_UNIFORMS; ++i) { - m_Indices.ModelView = getUniformIndex("modelView"); - if (m_Indices.ModelView == ~0) - { - nlwarning("Missing 'modelView' in gpu program '%s', ModelView disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelView; - } + m_Index.Indices[i] = getUniformIndex(m_Index.Names[i]); } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverse) - { - m_Indices.ModelViewInverse = getUniformIndex("modelViewInverse"); - if (m_Indices.ModelViewInverse == ~0) - { - nlwarning("Missing 'modelViewInverse' in gpu program '%s', ModelViewInverse disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewInverse; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewTranspose) - { - m_Indices.ModelViewTranspose = getUniformIndex("modelViewTranspose"); - if (m_Indices.ModelViewTranspose == ~0) - { - nlwarning("Missing 'modelViewTranspose' in gpu program '%s', ModelViewTranspose disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewTranspose; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverseTranspose) - { - m_Indices.ModelViewInverseTranspose = getUniformIndex("modelViewInverseTranspose"); - if (m_Indices.ModelViewInverseTranspose == ~0) - { - nlwarning("Missing 'modelViewInverseTranspose' in gpu program '%s', ModelViewInverseTranspose disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewInverseTranspose; - } - } - if (features.DriverFlags & CGPUProgramFeatures::Projection) - { - m_Indices.Projection = getUniformIndex("projection"); - if (m_Indices.Projection == ~0) - { - nlwarning("Missing 'projection' in gpu program '%s', Projection disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::Projection; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverse) - { - m_Indices.ProjectionInverse = getUniformIndex("projectionInverse"); - if (m_Indices.ProjectionInverse == ~0) - { - nlwarning("Missing 'projectionInverse' in gpu program '%s', ProjectionInverse disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ProjectionInverse; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ProjectionTranspose) - { - m_Indices.ProjectionTranspose = getUniformIndex("projectionTranspose"); - if (m_Indices.ProjectionTranspose == ~0) - { - nlwarning("Missing 'projectionTranspose' in gpu program '%s', ProjectionTranspose disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ProjectionTranspose; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverseTranspose) - { - m_Indices.ProjectionInverseTranspose = getUniformIndex("projectionInverseTranspose"); - if (m_Indices.ProjectionInverseTranspose == ~0) - { - nlwarning("Missing 'projectionInverseTranspose' in gpu program '%s', ProjectionInverseTranspose disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ProjectionInverseTranspose; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjection) - { - m_Indices.ModelViewProjection = getUniformIndex("modelViewProjection"); - if (m_Indices.ModelViewProjection == ~0) - { - nlwarning("Missing 'modelViewProjection' in gpu program '%s', ModelViewProjection disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjection; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverse) - { - m_Indices.ModelViewProjectionInverse = getUniformIndex("modelViewProjectionInverse"); - if (m_Indices.ModelViewProjectionInverse == ~0) - { - nlwarning("Missing 'modelViewProjectionInverse' in gpu program '%s', ModelViewProjectionInverse disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionInverse; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionTranspose) - { - m_Indices.ModelViewProjectionTranspose = getUniformIndex("modelViewProjectionTranspose"); - if (m_Indices.ModelViewProjectionTranspose == ~0) - { - nlwarning("Missing 'modelViewProjectionTranspose' in gpu program '%s', ModelViewProjectionTranspose disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionTranspose; - } - } - if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverseTranspose) - { - m_Indices.ModelViewProjectionInverseTranspose = getUniformIndex("modelViewProjectionInverseTranspose"); - if (m_Indices.ModelViewProjectionInverseTranspose == ~0) - { - nlwarning("Missing 'modelViewProjectionInverseTranspose' in gpu program '%s', ModelViewProjectionInverseTranspose disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionInverseTranspose; - } - } - if (features.DriverFlags & CGPUProgramFeatures::Fog) - { - m_Indices.Fog = getUniformIndex("fog"); - if (m_Indices.Fog == ~0) - { - nlwarning("Missing 'fog' in gpu program '%s', Fog disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::Fog; - } - } - - // - // Rough example, modify as necessary. - // - /*if (features.DriverFlags & CGPUProgramFeatures::DriverAmbient || features.MaterialFlags & CGPUProgramFeatures::MaterialAmbient) - { - m_Indices.Ambient = getUniformIndex("nlAmbient"); - if (m_Indices.Ambient == ~0) - { - nlwarning("Missing 'nlAmbient' in gpu program '%s', Ambient disabled", source->DisplayName.c_str()); - features.DriverFlags &= ~CGPUProgramFeatures::DriverAmbient; - features.MaterialFlags &= ~CGPUProgramFeatures::MaterialAmbient; - } - }*/ buildInfo(); } diff --git a/code/nel/src/3d/landscape.cpp b/code/nel/src/3d/landscape.cpp index e842ae369..bf4cad45f 100644 --- a/code/nel/src/3d/landscape.cpp +++ b/code/nel/src/3d/landscape.cpp @@ -1193,20 +1193,29 @@ void CLandscape::render(const CVector &refineCenter, const CVector &frontVecto // If VertexShader enabled, setup VertexProgram Constants. - if(_VertexShaderOk) + if (_VertexShaderOk) { - // c[0..3] take the ModelViewProjection Matrix. - driver->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity); - // c[4] take useful constants. - driver->setConstant(4, 0, 1, 0.5f, 0); - // c[5] take RefineCenter - driver->setConstant(5, refineCenter); - // c[6] take info for Geomorph trnasition to TileNear. - driver->setConstant(6, CLandscapeGlobals::TileDistFarSqr, CLandscapeGlobals::OOTileDistDeltaSqr, 0, 0); - // c[10] take the fog vector. - driver->setConstantFog(10); - // c[12] take the current landscape Center / delta Pos to apply - driver->setConstant(12, _PZBModelPosition); + bool uprogstate = driver->isUniformProgramState(); + uint nbvp = uprogstate ? CLandscapeVBAllocator::MaxVertexProgram : 1; + for (uint i = 0; i < nbvp; ++i) + { + // activate the program to set the uniforms in the program state for all programs + // note: when uniforms are driver state, the indices must be the same across programs + if (uprogstate) _TileVB.activateVP(i); + CVertexProgramLandscape *program = _TileVB.getVP(i); + // c[0..3] take the ModelViewProjection Matrix. + driver->setUniformMatrix(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::ModelViewProjection), IDriver::ModelViewProjection, IDriver::Identity); + // c[4] take useful constants. + driver->setUniform4f(IDriver::VertexProgram, program->idx().ProgramConstants0, 0, 1, 0.5f, 0); + // c[5] take RefineCenter + driver->setuniform3f(IDriver::VertexProgram, program->idx().RefineCenter, refineCenter); + // c[6] take info for Geomorph trnasition to TileNear. + driver->setUniform2f(IDriver::VertexProgram, program->idx().TileDist, CLandscapeGlobals::TileDistFarSqr, CLandscapeGlobals::OOTileDistDeltaSqr); + // c[10] take the fog vector. + driver->setUniformFog(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::Fog)); + // c[12] take the current landscape Center / delta Pos to apply + driver->setUniform3f(IDriver::VertexProgram, program->idx().PZBModelPosition, _PZBModelPosition); + } } diff --git a/code/nel/src/3d/landscapevb_allocator.cpp b/code/nel/src/3d/landscapevb_allocator.cpp index eccfac66e..4af75c729 100644 --- a/code/nel/src/3d/landscapevb_allocator.cpp +++ b/code/nel/src/3d/landscapevb_allocator.cpp @@ -247,14 +247,23 @@ void CLandscapeVBAllocator::activate(uint vpId) nlassert(_Driver); nlassert(!_BufferLocked); + activateVP(vpId); + + _Driver->activeVertexBuffer(_VB); +} + + +// *************************************************************************** +void CLandscapeVBAllocator::activateVP(uint vpId) +{ + nlassert(_Driver); + // If enabled, activate Vertex program first. - if(_VertexProgram[vpId]) + if (_VertexProgram[vpId]) { //nlinfo("\nSTARTVP\n%s\nENDVP\n", _VertexProgram[vpId]->getProgram().c_str()); nlverify(_Driver->activeVertexProgram(_VertexProgram[vpId])); } - - _Driver->activeVertexBuffer(_VB); } @@ -516,12 +525,11 @@ const char* NL3D_LandscapeTileLightMapEndProgram= // *************************************************************************** void CLandscapeVBAllocator::deleteVertexProgram() { - for(uint i=0;iProfile = nelvp; + source->DisplayName = "Landscape/nelvp"; + switch (type) + { + case CLandscapeVBAllocator::Far0: + source->DisplayName += "/far0"; + source->setSource(std::string(NL3D_LandscapeCommonStartProgram) + + std::string(NL3D_LandscapeFar0EndProgram)); + break; + case CLandscapeVBAllocator::Far1: + source->DisplayName += "/far1"; + source->setSource(std::string(NL3D_LandscapeCommonStartProgram) + + std::string(NL3D_LandscapeFar1EndProgram)); + break; + case CLandscapeVBAllocator::Tile: + source->DisplayName += "/tile"; + if (lightMap) + { + source->DisplayName += "/lightmap"; + source->setSource(std::string(NL3D_LandscapeCommonStartProgram) + + std::string(NL3D_LandscapeTileLightMapEndProgram)); + } + else + { + source->setSource(std::string(NL3D_LandscapeCommonStartProgram) + + std::string(NL3D_LandscapeTileEndProgram)); + } + break; + } + source->ParamIndices["modelViewProjection"] = 0; + source->ParamIndices["programConstants0"] = 4; + source->ParamIndices["refineCenter"] = 5; + source->ParamIndices["tileDist"] = 6; + source->ParamIndices["fog"] = 10; + source->ParamIndices["pzbModelPosition"] = 12; + addSource(source); + } + // TODO_VP_GLSL + { + // .... + } +} +void CVertexProgramLandscape::buildInfo() +{ + m_Idx.ProgramConstants0 = getUniformIndex("programConstants0"); + m_Idx.RefineCenter = getUniformIndex("refineCenter"); + m_Idx.TileDist = getUniformIndex("tileDist"); + m_Idx.PZBModelPosition = getUniformIndex("pzbModelPosition"); +} } // NL3D diff --git a/code/nel/src/3d/water_model.cpp b/code/nel/src/3d/water_model.cpp index 3614d0905..6a239b6e0 100644 --- a/code/nel/src/3d/water_model.cpp +++ b/code/nel/src/3d/water_model.cpp @@ -957,9 +957,9 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c drv->setUniform4f(IDriver::VertexProgram, program->idx().DiffuseMapVector0, _ColorMapMatColumn0.x, _ColorMapMatColumn1.x, 0, _ColorMapMatColumn0.x * obsPos.x + _ColorMapMatColumn1.x * obsPos.y + _ColorMapMatPos.x); drv->setUniform4f(IDriver::VertexProgram, program->idx().DiffuseMapVector1, _ColorMapMatColumn0.y, _ColorMapMatColumn1.y, 0, _ColorMapMatColumn0.y * obsPos.x + _ColorMapMatColumn1.y * obsPos.y + _ColorMapMatPos.y); } - /// temp - // drv->setUniformMatrix(IDriver::VertexProgram, program->indices().ModelViewProjection, IDriver::ModelViewProjection, IDriver::Identity); // now set by setUniformDriver in setupMaterial - // drv->setUniformFog(IDriver::VertexProgram, program->indices().Fog); // now set by setUniformDriver in setupMaterial + // set builtins + drv->setUniformMatrix(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::ModelViewProjection), IDriver::ModelViewProjection, IDriver::Identity); + drv->setUniformFog(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::Fog)); // retrieve current time double date = scene->getCurrentTime(); // set bumpmaps pos diff --git a/code/nel/src/3d/water_shape.cpp b/code/nel/src/3d/water_shape.cpp index ac586d168..2fff229c8 100644 --- a/code/nel/src/3d/water_shape.cpp +++ b/code/nel/src/3d/water_shape.cpp @@ -89,9 +89,6 @@ CVertexProgramWaterVPNoWave::CVertexProgramWaterVPNoWave(bool diffuse) CSource *source = new CSource(); source->Profile = nelvp; source->DisplayName = "WaterVPNoWave/nelvp"; - source->Features.DriverFlags = - CGPUProgramFeatures::ModelViewProjection - | CGPUProgramFeatures::Fog; source->ParamIndices["modelViewProjection"] = 0; source->ParamIndices["fog"] = 4; source->ParamIndices["bumpMap0Scale"] = 5; @@ -120,9 +117,6 @@ CVertexProgramWaterVPNoWave::CVertexProgramWaterVPNoWave(bool diffuse) // source->Profile = glsl330v; // source->DisplayName = "WaterVPNoWave/glsl330v"; // if (diffuse) source->DisplayName += "/diffuse"; - // source->Features.DriverFlags = - // CGPUProgramFeatures::ModelViewProjection - // | CGPUProgramFeatures::Fog; // source->setSource... // addSource(source); }