mirror of
https://github.com/minetest/irrlicht.git
synced 2025-06-28 06:20:21 +02:00
Add IMaterialRendererServices::startUseProgram/stopUseProgram
This makes it possible to set high-level shader constants (which are attached to shader programs) to be set outside of OnSetConstants. IShaderConstantSetCallBack::OnCreate has it set automatically now so it works the same as OnSetConstants. D3D9 and burnings both work different, so there hadn't been a problem with those. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6469 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
@ -56,7 +56,7 @@ public:
|
||||
{
|
||||
if (UseHighLevelShaders)
|
||||
{
|
||||
// get shader constants id.
|
||||
// Get shader constants id.
|
||||
WorldViewProjID = services->getVertexShaderConstantID("mWorldViewProj");
|
||||
TransWorldID = services->getVertexShaderConstantID("mTransWorld");
|
||||
InvWorldID = services->getVertexShaderConstantID("mInvWorld");
|
||||
@ -68,6 +68,27 @@ public:
|
||||
if(driver->getDriverType() == video::EDT_OPENGL)
|
||||
TextureID = services->getVertexShaderConstantID("myTexture");
|
||||
}
|
||||
|
||||
// Set light color
|
||||
// That could be set as well in OnSetConstants, but there's some cost to setting shader constants
|
||||
// So when we have non-changing shader constants it's more performant to set them only once.
|
||||
video::SColorf col(0.0f,1.0f,1.0f,0.0f);
|
||||
if (UseHighLevelShaders)
|
||||
{
|
||||
services->setVertexShaderConstant(ColorID, reinterpret_cast<f32*>(&col), 4);
|
||||
|
||||
// Note: Since Irrlicht 1.9 it's possible to call setVertexShaderConstant
|
||||
// from anywhere. To do that save the services pointer here in OnCreate, it
|
||||
// won't change as long as you use one IShaderConstantSetCallBack per shader
|
||||
// material. But when calling it ouside of IShaderConstantSetCallBack functions
|
||||
// you have to call services->startUseProgram()stopUseProgram() before/after doing so.
|
||||
// At least for high-level shader constants, low level constants are not attached
|
||||
// to programs, so for those it doesn't matter.
|
||||
// Doing that sometimes makes sense for performance reasons, like for constants which
|
||||
// do only change once per frame or even less.
|
||||
}
|
||||
else
|
||||
services->setVertexShaderConstant(reinterpret_cast<f32*>(&col), 9, 1);
|
||||
}
|
||||
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices* services,
|
||||
@ -109,16 +130,6 @@ public:
|
||||
else
|
||||
services->setVertexShaderConstant(reinterpret_cast<f32*>(&pos), 8, 1);
|
||||
|
||||
// set light color
|
||||
|
||||
video::SColorf col(0.0f,1.0f,1.0f,0.0f);
|
||||
|
||||
if (UseHighLevelShaders)
|
||||
services->setVertexShaderConstant(ColorID,
|
||||
reinterpret_cast<f32*>(&col), 4);
|
||||
else
|
||||
services->setVertexShaderConstant(reinterpret_cast<f32*>(&col), 9, 1);
|
||||
|
||||
// set transposed world matrix
|
||||
|
||||
core::matrix4 world = driver->getTransform(video::ETS_WORLD);
|
||||
|
Reference in New Issue
Block a user