Add IShaderConstantSetCallBack::OnCreate to allow earlier access to IMaterialRendererServices

Accessing IMaterialRendererServices outside of OnSetConstants can be useful and Irrlicht made this a bit too hard to access.
Also OnCreate allows actually for nicer code where initialization and update of shader constants are strictly separated (see changed example).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6465 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2023-04-21 14:41:01 +00:00
parent 02165eccc8
commit 16c960c5ed
7 changed files with 41 additions and 14 deletions

View File

@ -48,19 +48,15 @@ class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
MyShaderCallBack() : WorldViewProjID(-1), TransWorldID(-1), InvWorldID(-1), PositionID(-1),
ColorID(-1), TextureID(-1), FirstUpdate(true)
ColorID(-1), TextureID(-1)
{
}
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
virtual void OnCreate(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// get shader constants id.
if (UseHighLevelShaders && FirstUpdate)
if (UseHighLevelShaders)
{
// get shader constants id.
WorldViewProjID = services->getVertexShaderConstantID("mWorldViewProj");
TransWorldID = services->getVertexShaderConstantID("mTransWorld");
InvWorldID = services->getVertexShaderConstantID("mInvWorld");
@ -68,12 +64,16 @@ public:
ColorID = services->getVertexShaderConstantID("mLightColor");
// Textures ID are important only for OpenGL interface.
video::IVideoDriver* driver = services->getVideoDriver();
if(driver->getDriverType() == video::EDT_OPENGL)
TextureID = services->getVertexShaderConstantID("myTexture");
FirstUpdate = false;
}
}
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set inverted world matrix
// if we are using highlevel shaders (the user can select this when
@ -143,8 +143,6 @@ private:
s32 PositionID;
s32 ColorID;
s32 TextureID;
bool FirstUpdate;
};
/*