Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::OpenGL::Program Class Reference

Wraps an OpenGL shader program with lazy build and render helpers. More...

#include <spk_program.hpp>

Inheritance diagram for spk::OpenGL::Program:
Inheritance graph
Collaboration diagram for spk::OpenGL::Program:
Collaboration graph

Public Member Functions

 Program (std::string p_vertexShaderCode, std::string p_fragmentShaderCode)
 Builds a shader program from vertex and fragment shader source code.
 Program (const Program &p_other)
 Copies program sources and rebuilds the GL program id when needed.
Programoperator= (const Program &p_other)
 Assigns shader sources from another program instance.
 Program (Program &&)=delete
Programoperator= (Program &&)=delete
GLuint id () const
 Returns the GL program id, building if needed.
void render (GLsizei p_nbIndexes, GLsizei p_nbInstance)
 Renders using glDrawElementsInstanced with the current program.
void renderIndirect (GLintptr p_commandOffset, GLsizei p_drawCount, GLsizei p_stride)
 Renders using glMultiDrawElementsIndirect with the current program.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.

Additional Inherited Members

Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Detailed Description

Wraps an OpenGL shader program with lazy build and render helpers.

See also
spk::OpenGLUtils for raw utilities.
spk::OpenGL::Program prog(loadVert(), loadFrag());
prog.activate();
prog.render(indexCount, instanceCount);
Wraps an OpenGL shader program with lazy build and render helpers.
Definition spk_program.hpp:27

Constructor & Destructor Documentation

◆ Program() [1/2]

spk::OpenGL::Program::Program ( std::string p_vertexShaderCode,
std::string p_fragmentShaderCode )

Builds a shader program from vertex and fragment shader source code.

Parameters
p_vertexShaderCodeGLSL vertex shader text.
p_fragmentShaderCodeGLSL fragment shader text.

◆ Program() [2/2]

spk::OpenGL::Program::Program ( const Program & p_other)

Copies program sources and rebuilds the GL program id when needed.

Parameters
p_otherProgram to copy.
Here is the call graph for this function:

Member Function Documentation

◆ id()

GLuint spk::OpenGL::Program::id ( ) const

Returns the GL program id, building if needed.

Returns
Program object id.

◆ operator=()

Program & spk::OpenGL::Program::operator= ( const Program & p_other)

Assigns shader sources from another program instance.

Parameters
p_otherProgram to copy from.
Returns
Reference to this program.
Here is the call graph for this function:

◆ render()

void spk::OpenGL::Program::render ( GLsizei p_nbIndexes,
GLsizei p_nbInstance )

Renders using glDrawElementsInstanced with the current program.

Parameters
p_nbIndexesIndex count.
p_nbInstanceInstance count.
Here is the call graph for this function:

◆ renderIndirect()

void spk::OpenGL::Program::renderIndirect ( GLintptr p_commandOffset,
GLsizei p_drawCount,
GLsizei p_stride )

Renders using glMultiDrawElementsIndirect with the current program.

Parameters
p_commandOffsetByte offset into indirect buffer.
p_drawCountNumber of draw commands.
p_strideStride between commands in the buffer.
Here is the call graph for this function:

The documentation for this class was generated from the following files:
  • includes/structure/opengl/spk_program.hpp
  • srcs/structure/opengl/spk_program.cpp