mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-10 09:43:52 +01:00
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:
parent
02165eccc8
commit
16c960c5ed
@ -1,6 +1,7 @@
|
|||||||
--------------------------
|
--------------------------
|
||||||
Changes in 1.9 (not yet released)
|
Changes in 1.9 (not yet released)
|
||||||
|
|
||||||
|
- Add IShaderConstantSetCallBack::OnCreate to allow earlier access to IMaterialRendererServices
|
||||||
- CIrrDeviceWin32::yield() now uses Sleep(0) instead of Sleep(1).
|
- CIrrDeviceWin32::yield() now uses Sleep(0) instead of Sleep(1).
|
||||||
We had Sleep(1) to allow yielding to all processes back in Windows XP time.
|
We had Sleep(1) to allow yielding to all processes back in Windows XP time.
|
||||||
But a) This caused Windows apps to sleep for 15ms usually and b) behavior for Sleep(0) was changed after Window XP to do what we want it to do.
|
But a) This caused Windows apps to sleep for 15ms usually and b) behavior for Sleep(0) was changed after Window XP to do what we want it to do.
|
||||||
|
@ -48,19 +48,15 @@ class MyShaderCallBack : public video::IShaderConstantSetCallBack
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyShaderCallBack() : WorldViewProjID(-1), TransWorldID(-1), InvWorldID(-1), PositionID(-1),
|
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,
|
virtual void OnCreate(video::IMaterialRendererServices* services, s32 userData)
|
||||||
s32 userData)
|
|
||||||
{
|
{
|
||||||
video::IVideoDriver* driver = services->getVideoDriver();
|
if (UseHighLevelShaders)
|
||||||
|
|
||||||
// get shader constants id.
|
|
||||||
|
|
||||||
if (UseHighLevelShaders && FirstUpdate)
|
|
||||||
{
|
{
|
||||||
|
// get shader constants id.
|
||||||
WorldViewProjID = services->getVertexShaderConstantID("mWorldViewProj");
|
WorldViewProjID = services->getVertexShaderConstantID("mWorldViewProj");
|
||||||
TransWorldID = services->getVertexShaderConstantID("mTransWorld");
|
TransWorldID = services->getVertexShaderConstantID("mTransWorld");
|
||||||
InvWorldID = services->getVertexShaderConstantID("mInvWorld");
|
InvWorldID = services->getVertexShaderConstantID("mInvWorld");
|
||||||
@ -68,12 +64,16 @@ public:
|
|||||||
ColorID = services->getVertexShaderConstantID("mLightColor");
|
ColorID = services->getVertexShaderConstantID("mLightColor");
|
||||||
|
|
||||||
// Textures ID are important only for OpenGL interface.
|
// Textures ID are important only for OpenGL interface.
|
||||||
|
video::IVideoDriver* driver = services->getVideoDriver();
|
||||||
if(driver->getDriverType() == video::EDT_OPENGL)
|
if(driver->getDriverType() == video::EDT_OPENGL)
|
||||||
TextureID = services->getVertexShaderConstantID("myTexture");
|
TextureID = services->getVertexShaderConstantID("myTexture");
|
||||||
|
|
||||||
FirstUpdate = false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnSetConstants(video::IMaterialRendererServices* services,
|
||||||
|
s32 userData)
|
||||||
|
{
|
||||||
|
video::IVideoDriver* driver = services->getVideoDriver();
|
||||||
|
|
||||||
// set inverted world matrix
|
// set inverted world matrix
|
||||||
// if we are using highlevel shaders (the user can select this when
|
// if we are using highlevel shaders (the user can select this when
|
||||||
@ -143,8 +143,6 @@ private:
|
|||||||
s32 PositionID;
|
s32 PositionID;
|
||||||
s32 ColorID;
|
s32 ColorID;
|
||||||
s32 TextureID;
|
s32 TextureID;
|
||||||
|
|
||||||
bool FirstUpdate;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -22,6 +22,14 @@ class IShaderConstantSetCallBack : public virtual IReferenceCounted
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//! Called by the engine after a shader material has been created successfully
|
||||||
|
/** If you are using one callback instance per shader (much recommended)
|
||||||
|
this is a good place to get shader constant id's for high level shaders.
|
||||||
|
\param services: Pointer to an interface providing methods to set/get the constants for the shader.
|
||||||
|
\param userData: Userdata int which can be specified when creating the shader. */
|
||||||
|
virtual void OnCreate(IMaterialRendererServices* services, s32 userData) { }
|
||||||
|
|
||||||
|
|
||||||
//! Called to let the callBack know the used material (optional method)
|
//! Called to let the callBack know the used material (optional method)
|
||||||
/**
|
/**
|
||||||
\code
|
\code
|
||||||
|
@ -3176,6 +3176,10 @@ s32 CD3D9Driver::addShaderMaterial(const c8* vertexShaderProgram,
|
|||||||
callback, getMaterialRenderer(baseMaterial), userData);
|
callback, getMaterialRenderer(baseMaterial), userData);
|
||||||
|
|
||||||
r->drop();
|
r->drop();
|
||||||
|
|
||||||
|
if (callback && nr >= 0)
|
||||||
|
callback->OnCreate(this, userData);
|
||||||
|
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3213,6 +3217,9 @@ s32 CD3D9Driver::addHighLevelShaderMaterial(
|
|||||||
|
|
||||||
r->drop();
|
r->drop();
|
||||||
|
|
||||||
|
if (callback && nr >= 0)
|
||||||
|
callback->OnCreate(r, userData);
|
||||||
|
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3725,6 +3725,10 @@ s32 COpenGLDriver::addShaderMaterial(const c8* vertexShaderProgram,
|
|||||||
callback, baseMaterial, userData);
|
callback, baseMaterial, userData);
|
||||||
|
|
||||||
r->drop();
|
r->drop();
|
||||||
|
|
||||||
|
if (callback && nr >= 0)
|
||||||
|
callback->OnCreate(this, userData);
|
||||||
|
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3759,6 +3763,9 @@ s32 COpenGLDriver::addHighLevelShaderMaterial(
|
|||||||
|
|
||||||
r->drop();
|
r->drop();
|
||||||
|
|
||||||
|
if (callback && nr >= 0)
|
||||||
|
callback->OnCreate(r, userData);
|
||||||
|
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4654,6 +4654,9 @@ s32 CBurningVideoDriver::addShaderMaterial(const c8* vertexShaderProgram,
|
|||||||
|
|
||||||
shader->drop();
|
shader->drop();
|
||||||
|
|
||||||
|
if (callback && materialID >= 0)
|
||||||
|
callback->OnCreate(shader, userData);
|
||||||
|
|
||||||
return materialID;
|
return materialID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4691,6 +4694,9 @@ s32 CBurningVideoDriver::addHighLevelShaderMaterial(
|
|||||||
|
|
||||||
shader->drop();
|
shader->drop();
|
||||||
|
|
||||||
|
if (callback && materialID >= 0)
|
||||||
|
callback->OnCreate(shader, userData);
|
||||||
|
|
||||||
return materialID;
|
return materialID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Tests finished. 72 tests of 72 passed.
|
Tests finished. 72 tests of 72 passed.
|
||||||
Compiled as DEBUG
|
Compiled as DEBUG
|
||||||
Test suite pass at GMT Fri Apr 21 13:49:43 2023
|
Test suite pass at GMT Fri Apr 21 14:37:22 2023
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user