MaterialX 1.39.1
Loading...
Searching...
No Matches
GlslRenderer Class Reference

Helper class for rendering generated GLSL code to produce images. More...

#include <GlslRenderer.h>

Inheritance diagram for GlslRenderer:
ShaderRenderer TextureBaker< GlslRenderer, GlslShaderGenerator > TextureBakerGlsl

Public Member Functions

ImageHandlerPtr createImageHandler (ImageLoaderPtr imageLoader)
 Create a texture handler for OpenGL textures.
 
virtual ~GlslRenderer ()
 Destructor.
 
Setup
void initialize (RenderContextHandle renderContextHandle=nullptr) override
 Internal initialization of stages and OpenGL constructs required for program validation and rendering. More...
 
Rendering
void createProgram (ShaderPtr shader) override
 Create GLSL program based on an input shader. More...
 
void createProgram (const StageMap &stages) override
 Create GLSL program based on shader stage source code. More...
 
void validateInputs () override
 Validate inputs for the program. More...
 
void updateUniform (const string &name, ConstValuePtr value) override
 Update the program with value of the uniform. More...
 
void setSize (unsigned int width, unsigned int height) override
 Set the size of the rendered image. More...
 
void render () override
 Render the current program to an offscreen buffer. More...
 
void renderTextureSpace (const Vector2 &uvMin, const Vector2 &uvMax)
 Render the current program in texture space to an off-screen buffer.
 
Utilities
ImagePtr captureImage (ImagePtr image=nullptr) override
 Capture the current contents of the off-screen hardware buffer as an image. More...
 
GLFramebufferPtr getFramebuffer () const
 Return the GL frame buffer.
 
GlslProgramPtr getProgram ()
 Return the GLSL program.
 
void drawScreenSpaceQuad (const Vector2 &uvMin=Vector2(0.0f), const Vector2 &uvMax=Vector2(1.0f))
 Submit geometry for a screen-space quad.
 
void setScreenColor (const Color3 &screenColor)
 Set the screen background color.
 
Color3 getScreenColor () const
 Return the screen background color.
 
- Public Member Functions inherited from ShaderRenderer
void setCamera (CameraPtr camera)
 Set the camera.
 
CameraPtr getCamera () const
 Return the camera.
 
void setImageHandler (ImageHandlerPtr imageHandler)
 Set the image handler used by this renderer for image I/O.
 
ImageHandlerPtr getImageHandler () const
 Return the image handler.
 
void setLightHandler (LightHandlerPtr lightHandler)
 Set the light handler used by this renderer for light bindings.
 
LightHandlerPtr getLightHandler () const
 Return the light handler.
 
void setGeometryHandler (GeometryHandlerPtr geometryHandler)
 Set the geometry handler.
 
GeometryHandlerPtr getGeometryHandler () const
 Return the geometry handler.
 

Static Public Member Functions

static GlslRendererPtr create (unsigned int width=512, unsigned int height=512, Image::BaseType baseType=Image::BaseType::UINT8)
 Create a GLSL renderer instance.
 

Protected Member Functions

 GlslRenderer (unsigned int width, unsigned int height, Image::BaseType baseType)
 
- Protected Member Functions inherited from ShaderRenderer
 ShaderRenderer (unsigned int width, unsigned int height, Image::BaseType baseType, MatrixConvention matrixConvention=MatrixConvention::OpenGL)
 

Additional Inherited Members

- Public Types inherited from ShaderRenderer
enum class  MatrixConvention { OpenGL = 0 , Metal = 1 }
 Viewing API matrix conventions designation (default to OpenGL).
 
using StageMap = StringMap
 A map with name and source code for each shader stage.
 
- Protected Attributes inherited from ShaderRenderer
unsigned int _width
 
unsigned int _height
 
Image::BaseType _baseType
 
MatrixConvention _matrixConvention
 
CameraPtr _camera
 
ImageHandlerPtr _imageHandler
 
GeometryHandlerPtr _geometryHandler
 
LightHandlerPtr _lightHandler
 

Detailed Description

Helper class for rendering generated GLSL code to produce images.

There are two main interfaces which can be used. One which takes in a HwShader and one which allows for explicit setting of shader stage code.

The main services provided are:

  • Validation: All shader stages are compiled and atteched to a GLSL shader program.
  • Introspection: The compiled shader program is examined for uniforms and attributes.
  • Binding: Uniforms and attributes which match the predefined variables generated the GLSL code generator will have values assigned to this. This includes matrices, attribute streams, and textures.
  • Rendering: The program with bound inputs will be used to drawing geometry to an offscreen buffer. An interface is provided to save this offscreen buffer to disk using an externally defined image handler.

Member Function Documentation

◆ captureImage()

ImagePtr captureImage ( ImagePtr  image = nullptr)
overridevirtual

Capture the current contents of the off-screen hardware buffer as an image.

Reimplemented from ShaderRenderer.

◆ createProgram() [1/2]

void createProgram ( const StageMap stages)
overridevirtual

Create GLSL program based on shader stage source code.

Parameters
stagesMap of name and source code for the shader stages.

Reimplemented from ShaderRenderer.

◆ createProgram() [2/2]

void createProgram ( ShaderPtr  shader)
overridevirtual

Create GLSL program based on an input shader.

Parameters
shaderInput HwShader

Reimplemented from ShaderRenderer.

◆ initialize()

void initialize ( RenderContextHandle  renderContextHandle = nullptr)
overridevirtual

Internal initialization of stages and OpenGL constructs required for program validation and rendering.

An exception is thrown on failure. The exception will contain a list of initialization errors.

Parameters
renderContextHandleallows initializing the GlslRenderer with a Shared OpenGL Context

Reimplemented from ShaderRenderer.

◆ render()

void render ( )
overridevirtual

Render the current program to an offscreen buffer.

Reimplemented from ShaderRenderer.

◆ setSize()

void setSize ( unsigned int  width,
unsigned int  height 
)
overridevirtual

Set the size of the rendered image.

Reimplemented from ShaderRenderer.

◆ updateUniform()

void updateUniform ( const string &  name,
ConstValuePtr  value 
)
overridevirtual

Update the program with value of the uniform.

Reimplemented from ShaderRenderer.

◆ validateInputs()

void validateInputs ( )
overridevirtual

Validate inputs for the program.

Reimplemented from ShaderRenderer.


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