Duckcpp 2.1.0
Duckcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
dcpp::video::IShaderConstantSetCallBack Class Referenceabstract

Interface making it possible to set constants for gpu programs every frame. More...

#include <duckcpp/core/engine/IShaderConstantSetCallBack.hpp>

Inheritance diagram for dcpp::video::IShaderConstantSetCallBack:
Inheritance graph
Collaboration diagram for dcpp::video::IShaderConstantSetCallBack:
Collaboration graph

Public Member Functions

virtual void OnSetMaterial (const SMaterial &material)
 Called to let the callBack know the used material (optional method)
 
virtual void OnSetConstants (IMaterialRendererServices *services, dcpp::int32_kt userData)=0
 Called by the engine when the vertex and/or pixel shader constants for an material renderer should be set.
 
- Public Member Functions inherited from dcpp::IReferenceCounted
 IReferenceCounted ()
 Constructor.
 
virtual ~IReferenceCounted ()
 Destructor.
 
void grab () const
 Grabs the object. Increments the reference counter by one.
 
bool drop () const
 Drops the object. Decrements the reference counter by one.
 
dcpp::int32_kt getReferenceCount () const
 Get the reference count.
 
const dcpp::char_ktgetDebugName () const
 Returns the debug name of the object.
 

Additional Inherited Members

- Protected Member Functions inherited from dcpp::IReferenceCounted
void setDebugName (const dcpp::char_kt *newName)
 Sets the debug name of the object.
 

Detailed Description

Interface making it possible to set constants for gpu programs every frame.

Implement this interface in an own class and pass a pointer to it to one of the methods in IGPUProgrammingServices when creating a shader. The OnSetConstants method will be called every frame now.

Member Function Documentation

◆ OnSetConstants()

virtual void dcpp::video::IShaderConstantSetCallBack::OnSetConstants ( IMaterialRendererServices services,
dcpp::int32_kt  userData 
)
pure virtual

Called by the engine when the vertex and/or pixel shader constants for an material renderer should be set.

Implement the IShaderConstantSetCallBack in an own class and implement your own OnSetConstants method using the given IMaterialRendererServices interface. Pass a pointer to this class to one of the methods in IGPUProgrammingServices when creating a shader. The OnSetConstants method will now be called every time before geometry is being drawn using your shader material. A sample implementation would look like this:

{
// set clip matrix at register 4
worldViewProj *= driver->getTransform(dcpp::video::ETS_VIEW);
worldViewProj *= driver->getTransform(dcpp::video::ETS_WORLD);
services->setVertexShaderConstant(&worldViewProj.M[0], 4, 4);
// for high level shading languages, this would be another solution:
//services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
// set some light color at register 9
dcpp::video::SColorf col(0.0f,1.0f,1.0f,0.0f);
services->setVertexShaderConstant(reinterpret_cast<const dcpp::float32_kt*>(&col), 9, 1);
// for high level shading languages, this would be another solution:
//services->setVertexShaderConstant("myColor", reinterpret_cast<dcpp::float32_kt*>(&col), 4);
}
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.hpp:49
Interface providing some methods for changing advanced, internal states of a IVideoDriver.
Definition IMaterialRendererServices.hpp:21
virtual bool setVertexShaderConstant(dcpp::int32_kt index, const dcpp::float32_kt *floats, int count)=0
Sets a constant for the vertex shader based on a name.
virtual IVideoDriver * getVideoDriver()=0
Get pointer to the IVideoDriver interface.
virtual void OnSetConstants(IMaterialRendererServices *services, dcpp::int32_kt userData)=0
Called by the engine when the vertex and/or pixel shader constants for an material renderer should be...
Interface to driver which is able to perform 2d and 3d graphics functions.
Definition IVideoDriver.hpp:152
virtual const dcpp::nub::matrix4 & getTransform(E_TRANSFORMATION_STATE state) const =0
Returns the transformation set by setTransform.
Class representing a color with four floats.
Definition SColor.hpp:574
@ ETS_PROJECTION
Projection transformation.
Definition IVideoDriver.hpp:60
@ ETS_VIEW
View transformation.
Definition IVideoDriver.hpp:56
@ ETS_WORLD
World transformation.
Definition IVideoDriver.hpp:58
float float32_kt
32 bit floating point variable.
Definition irrTypes.hpp:108
signed int int32_kt
32 bit signed variable.
Definition irrTypes.hpp:72
Parameters
servicesPointer to an interface providing methods to set the constants for the shader.
userDataUserdata int which can be specified when creating the shader.

◆ OnSetMaterial()

virtual void dcpp::video::IShaderConstantSetCallBack::OnSetMaterial ( const SMaterial material)
inlinevirtual

Called to let the callBack know the used material (optional method)

class MyCallBack : public IShaderConstantSetCallBack
{
const dcpp::video::SMaterial *UsedMaterial;
OnSetMaterial(const dcpp::video::SMaterial& material)
{
UsedMaterial=&material;
}
OnSetConstants(IMaterialRendererServices* services, dcpp::int32_kt userData)
{
services->setVertexShaderConstant("myColor", reinterpret_cast<dcpp::float32_kt*>(&UsedMaterial->color), 4);
}
}
Interface making it possible to set constants for gpu programs every frame.
Definition IShaderConstantSetCallBack.hpp:22
Class for holding parameters for a material renderer.
Definition SMaterial.hpp:304

The documentation for this class was generated from the following file:

Duckcpp    @cppfx.xyz