Adjust landscape vertex program to use new interface

This commit is contained in:
kaetemi 2013-09-10 15:42:42 +02:00
parent 32288eabe8
commit 4de5eeb586
12 changed files with 199 additions and 256 deletions

View file

@ -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 &params) = 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;
// @}

View file

@ -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<CSource> m_Source;
CGPUProgramIndices m_Indices;
CGPUProgramIndex m_Index;
public:
/// The driver information. For the driver implementation only.

View file

@ -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<CVertexProgramLandscape> _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

View file

@ -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 &params); // set all user-provided params from the storage
virtual bool isUniformProgramState() { return false; }
// @}

View file

@ -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

View file

@ -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 &params); // set all user-provided params from the storage
virtual bool isUniformProgramState() { return false; }
// @}

View file

@ -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;

View file

@ -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();
}

View file

@ -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);
}
}

View file

@ -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;i<MaxVertexProgram;i++)
for (uint i = 0; i < MaxVertexProgram; ++i)
{
if(_VertexProgram[i])
if (_VertexProgram[i])
{
delete _VertexProgram[i];
_VertexProgram[i]= NULL;
_VertexProgram[i] = NULL; // smartptr
}
}
}
@ -560,10 +568,7 @@ void CLandscapeVBAllocator::setupVBFormatAndVertexProgram(bool withVertexProgr
_VB.initEx();
// Init the Vertex Program.
string vpgram= string(NL3D_LandscapeCommonStartProgram) +
string(NL3D_LandscapeFar0EndProgram);
_VertexProgram[0]= new CVertexProgram(vpgram.c_str());
// TODO_VP_GLSL
_VertexProgram[0]= new CVertexProgramLandscape(Far0);
}
else if(_Type==Far1)
{
@ -578,10 +583,7 @@ void CLandscapeVBAllocator::setupVBFormatAndVertexProgram(bool withVertexProgr
_VB.initEx();
// Init the Vertex Program.
string vpgram= string(NL3D_LandscapeCommonStartProgram) +
string(NL3D_LandscapeFar1EndProgram);
_VertexProgram[0]= new CVertexProgram(vpgram.c_str());
// TODO_VP_GLSL
_VertexProgram[0] = new CVertexProgramLandscape(Far1);
}
else
{
@ -596,22 +598,70 @@ void CLandscapeVBAllocator::setupVBFormatAndVertexProgram(bool withVertexProgr
_VB.initEx();
// Init the Vertex Program.
string vpgram= string(NL3D_LandscapeCommonStartProgram) +
string(NL3D_LandscapeTileEndProgram);
_VertexProgram[0]= new CVertexProgram(vpgram.c_str());
// TODO_VP_GLSL
_VertexProgram[0] = new CVertexProgramLandscape(Tile, false);
// Init the Vertex Program for lightmap pass
vpgram= string(NL3D_LandscapeCommonStartProgram) +
string(NL3D_LandscapeTileLightMapEndProgram);
_VertexProgram[1]= new CVertexProgram(vpgram.c_str());
// TODO_VP_GLSL
_VertexProgram[1] = new CVertexProgramLandscape(Tile, true);
}
}
}
CVertexProgramLandscape::CVertexProgramLandscape(CLandscapeVBAllocator::TType type, bool lightMap)
{
// nelvp
{
CSource *source = new CSource();
source->Profile = 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

View file

@ -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

View file

@ -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);
}