Improve documentation

What Irrlicht calls ShaderConstants is called uniforms by everyone else. So let's mention this at least.
Also reworked setVertexShaderConstant interface had an example for the old interface in the header.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6497 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2023-06-12 19:26:43 +00:00
parent a44e5e3d17
commit cdcb8274ee
2 changed files with 30 additions and 26 deletions

View File

@ -57,6 +57,9 @@ public:
if (UseHighLevelShaders)
{
// Get shader constants id.
// Constants are "uniforms" in most modern shading languages.
// And they are not constant at all but can be changed before every draw call
// (the naming probably has some historical reasons which got lost in time)
WorldViewProjID = services->getVertexShaderConstantID("mWorldViewProj");
TransWorldID = services->getVertexShaderConstantID("mTransWorld");
InvWorldID = services->getVertexShaderConstantID("mInvWorld");

View File

@ -24,7 +24,7 @@ public:
//! Destructor
virtual ~IMaterialRendererServices() {}
//! Return an index constant for the vertex shader based on a name.
//! Return an index constant for the vertex shader based on a uniform variable name.
virtual s32 getVertexShaderConstantID(const c8* name) = 0;
//! Call when you set shader constants outside of IShaderConstantSetCallBack
@ -41,27 +41,8 @@ public:
//! Call this when you are done setting shader constants outside of OnCreate or OnSetConstants
virtual void stopUseProgram() {}
//! Sets a constant for the vertex shader based on a name.
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. Example: If you created a shader which has
variables named 'mWorldViewProj' (containing the WorldViewProjection
matrix) and another one named 'fTime' containing one float, you can set
them in your IShaderConstantSetCallBack derived class like this:
\code
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
f32 time = (f32)os::Timer::getTime()/100000.0f;
services->setVertexShaderConstant("fTime", &time, 1);
core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
\endcode
\param index Index of the variable
//! Sets a value for a vertex shader uniform variable.
/**\param index Index of the variable (as received from getVertexShaderConstantID)
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful.
@ -75,7 +56,7 @@ public:
/* NOTE: UINT only works with GLSL, not supported for other shaders */
virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) = 0;
//! Sets a vertex shader constant.
//! Sets a vertex shader constant (or "uniform" in more modern terms)
/** Can be used if you created a shader using pixel/vertex shader
assembler or ARB_fragment_program or ARB_vertex_program.
\param data: Data to be set in the constants
@ -83,14 +64,14 @@ public:
\param constantAmount: Amount of registers to be set. One register consists of 4 floats. */
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! Return an index constant for the pixel shader based on a name.
//! Return an index constant for the pixel shader for the given uniform variable name
virtual s32 getPixelShaderConstantID(const c8* name) = 0;
//! Sets a constant for the pixel shader based on a name.
//! Sets a value for the given pixel shader uniform variable
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. See setVertexShaderConstant() for an
example on how to use this.
\param index Index of the variable
\param index Index of the variable (as received from getPixelShaderConstantID)
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful. */
@ -112,6 +93,26 @@ public:
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! \deprecated. This method may be removed by Irrlicht 2.0
/** This can be used if you use a high level shader language like GLSL
or HLSL to create a shader. Example: If you created a shader which has
variables named 'mWorldViewProj' (containing the WorldViewProjection
matrix) and another one named 'fTime' containing one float, you can set
them in your IShaderConstantSetCallBack derived class like this:
\code
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
f32 time = (f32)os::Timer::getTime()/100000.0f;
services->setVertexShaderConstant("fTime", &time, 1);
core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
\endcode
**/
IRR_DEPRECATED bool setVertexShaderConstant(const c8* name, const f32* floats, int count)
{
return setVertexShaderConstant(getVertexShaderConstantID(name), floats, count);