This commit is contained in:
kaetemi 2013-09-10 15:59:31 +02:00
parent 4de5eeb586
commit 26f4073ad7
3 changed files with 65 additions and 64 deletions

View file

@ -64,6 +64,15 @@ public:
// 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.
// Example:
// User shader flags Matrices in the Vertex Program:
// -> When rendering with a material, the driver will call setUniformDriver,
// which will check if the flag Matrices exists, and if so, it will use
// the index cache to find which matrices are needed by the shader,
// and set those which are found.
// This does not work extremely efficient, but it's the most practical option
// for passing builtin parameters onto user provided shaders.
// Note: May need additional flags related to scene sorting, etcetera.
struct CGPUProgramFeatures
{
CGPUProgramFeatures() : DriverFlags(0), MaterialFlags(0) { }
@ -72,26 +81,12 @@ struct CGPUProgramFeatures
enum TDriverFlags
{
// Matrices
ModelView = 0x00000001,
ModelViewInverse = 0x00000002,
ModelViewTranspose = 0x00000004,
ModelViewInverseTranspose = 0x00000008,
Projection = 0x00000010,
ProjectionInverse = 0x00000020,
ProjectionTranspose = 0x00000040,
ProjectionInverseTranspose = 0x00000080,
ModelViewProjection = 0x00000100,
ModelViewProjectionInverse = 0x00000200,
ModelViewProjectionTranspose = 0x00000400,
ModelViewProjectionInverseTranspose = 0x00000800,
Matrices = 0x00000001,
// Fog
Fog = 0x00001000,
Fog = 0x00000002,
};
uint32 DriverFlags;
// uint NumLights;
enum TMaterialFlags
{

View file

@ -309,59 +309,65 @@ bool CDriverGL::setUniformDriver(TProgram program)
if (features.DriverFlags)
{
if (features.DriverFlags & CGPUProgramFeatures::ModelView)
if (features.DriverFlags & CGPUProgramFeatures::Matrices)
{
if (prog->getUniformIndex(CGPUProgramIndex::ModelView) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelView), ModelView, Identity);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverse)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewInverse) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewInverse), ModelView, Inverse);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewTranspose)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewTranspose) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewTranspose), ModelView, Transpose);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverseTranspose)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewInverseTranspose) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewInverseTranspose), ModelView, InverseTranspose);
}
if (features.DriverFlags & CGPUProgramFeatures::Projection)
if (prog->getUniformIndex(CGPUProgramIndex::Projection) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::Projection), Projection, Identity);
}
if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverse)
if (prog->getUniformIndex(CGPUProgramIndex::ProjectionInverse) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ProjectionInverse), Projection, Inverse);
}
if (features.DriverFlags & CGPUProgramFeatures::ProjectionTranspose)
if (prog->getUniformIndex(CGPUProgramIndex::ProjectionTranspose) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ProjectionTranspose), Projection, Transpose);
}
if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverseTranspose)
if (prog->getUniformIndex(CGPUProgramIndex::ProjectionInverseTranspose) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ProjectionInverseTranspose), Projection, InverseTranspose);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjection)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewProjection) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjection), ModelViewProjection, Identity);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverse)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionInverse) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionInverse), ModelViewProjection, Inverse);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionTranspose)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionTranspose) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionTranspose), ModelViewProjection, Transpose);
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverseTranspose)
if (prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionInverseTranspose) != ~0)
{
setUniformMatrix(program, prog->getUniformIndex(CGPUProgramIndex::ModelViewProjectionInverseTranspose), ModelViewProjection, InverseTranspose);
}
}
if (features.DriverFlags & CGPUProgramFeatures::Fog)
{
if (prog->getUniformIndex(CGPUProgramIndex::Fog) != ~0)
{
setUniformFog(program, prog->getUniformIndex(CGPUProgramIndex::Fog));
}
}
}
return true;
}

View file

@ -1208,7 +1208,7 @@ void CLandscape::render(const CVector &refineCenter, const CVector &frontVecto
// 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);
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.