This commit is contained in:
kaetemi 2013-09-10 15:59:31 +02:00
parent f507a1cf3e
commit 54ccd5d129
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, // 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. // 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. // 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 struct CGPUProgramFeatures
{ {
CGPUProgramFeatures() : DriverFlags(0), MaterialFlags(0) { } CGPUProgramFeatures() : DriverFlags(0), MaterialFlags(0) { }
@ -72,26 +81,12 @@ struct CGPUProgramFeatures
enum TDriverFlags enum TDriverFlags
{ {
// Matrices // Matrices
ModelView = 0x00000001, Matrices = 0x00000001,
ModelViewInverse = 0x00000002,
ModelViewTranspose = 0x00000004,
ModelViewInverseTranspose = 0x00000008,
Projection = 0x00000010,
ProjectionInverse = 0x00000020,
ProjectionTranspose = 0x00000040,
ProjectionInverseTranspose = 0x00000080,
ModelViewProjection = 0x00000100,
ModelViewProjectionInverse = 0x00000200,
ModelViewProjectionTranspose = 0x00000400,
ModelViewProjectionInverseTranspose = 0x00000800,
// Fog // Fog
Fog = 0x00001000, Fog = 0x00000002,
}; };
uint32 DriverFlags; uint32 DriverFlags;
// uint NumLights;
enum TMaterialFlags enum TMaterialFlags
{ {

View file

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

View file

@ -1208,7 +1208,7 @@ void CLandscape::render(const CVector &refineCenter, const CVector &frontVecto
// c[4] take useful constants. // c[4] take useful constants.
driver->setUniform4f(IDriver::VertexProgram, program->idx().ProgramConstants0, 0, 1, 0.5f, 0); driver->setUniform4f(IDriver::VertexProgram, program->idx().ProgramConstants0, 0, 1, 0.5f, 0);
// c[5] take RefineCenter // 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. // c[6] take info for Geomorph trnasition to TileNear.
driver->setUniform2f(IDriver::VertexProgram, program->idx().TileDist, CLandscapeGlobals::TileDistFarSqr, CLandscapeGlobals::OOTileDistDeltaSqr); driver->setUniform2f(IDriver::VertexProgram, program->idx().TileDist, CLandscapeGlobals::TileDistFarSqr, CLandscapeGlobals::OOTileDistDeltaSqr);
// c[10] take the fog vector. // c[10] take the fog vector.