MaterialX 1.39.1
Loading...
Searching...
No Matches
GlslRenderer.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_GLSLRENDERER_H
7#define MATERIALX_GLSLRENDERER_H
8
11
13
17
19
20MATERIALX_NAMESPACE_BEGIN
21
22using GLContextPtr = std::shared_ptr<class GLContext>;
23using SimpleWindowPtr = std::shared_ptr<class SimpleWindow>;
24
26using GlslRendererPtr = std::shared_ptr<class GlslRenderer>;
27
42class MX_RENDERGLSL_API GlslRenderer : public ShaderRenderer
43{
44 public:
46 static GlslRendererPtr create(unsigned int width = 512, unsigned int height = 512, Image::BaseType baseType = Image::BaseType::UINT8);
47
50 {
51 return GLTextureHandler::create(imageLoader);
52 }
53
55 virtual ~GlslRenderer() { }
56
59
65 void initialize(RenderContextHandle renderContextHandle = nullptr) override;
66
70
73 void createProgram(ShaderPtr shader) override;
74
77 void createProgram(const StageMap& stages) override;
78
80 void validateInputs() override;
81
83 void updateUniform(const string& name, ConstValuePtr value) override;
84
86 void setSize(unsigned int width, unsigned int height) override;
87
89 void render() override;
90
92 void renderTextureSpace(const Vector2& uvMin, const Vector2& uvMax);
93
97
99 ImagePtr captureImage(ImagePtr image = nullptr) override;
100
103 {
104 return _framebuffer;
105 }
106
108 GlslProgramPtr getProgram()
109 {
110 return _program;
111 }
112
114 void drawScreenSpaceQuad(const Vector2& uvMin = Vector2(0.0f), const Vector2& uvMax = Vector2(1.0f));
115
117 void setScreenColor(const Color3& screenColor)
118 {
119 _screenColor = screenColor;
120 }
121
124 {
125 return _screenColor;
126 }
127
129
130 protected:
131 GlslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType);
132
133 private:
134 GlslProgramPtr _program;
135 GLFramebufferPtr _framebuffer;
136
137 bool _initialized;
138
139 SimpleWindowPtr _window;
140 GLContextPtr _context;
141 Color3 _screenColor;
142};
143
144MATERIALX_NAMESPACE_END
145
146#endif
std::shared_ptr< class GLContext > GLContextPtr
GLContext shared pointer.
Definition: GLContext.h:37
OpenGL framebuffer handling.
std::shared_ptr< GLFramebuffer > GLFramebufferPtr
Shared pointer to a GLFramebuffer.
Definition: GLFramebuffer.h:21
OpenGL texture handler.
GLSL Program interfaces.
std::shared_ptr< class GlslRenderer > GlslRendererPtr
Shared pointer to a GlslRenderer.
Definition: GlslRenderer.h:26
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
std::shared_ptr< ImageLoader > ImageLoaderPtr
Shared pointer to an ImageLoader.
Definition: ImageHandler.h:35
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
Macros for declaring imported and exported symbols.
Base class for shader rendering.
void * RenderContextHandle
Render context handle Provides a provision for an application to share any renderer specific settings...
Definition: ShaderRenderer.h:23
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
A three-component color value.
Definition: Types.h:342
Helper class for rendering generated GLSL code to produce images.
Definition: GlslRenderer.h:43
void validateInputs() override
Validate inputs for the program.
Color3 getScreenColor() const
Return the screen background color.
Definition: GlslRenderer.h:123
void setScreenColor(const Color3 &screenColor)
Set the screen background color.
Definition: GlslRenderer.h:117
void updateUniform(const string &name, ConstValuePtr value) override
Update the program with value of the uniform.
static GlslRendererPtr create(unsigned int width=512, unsigned int height=512, Image::BaseType baseType=Image::BaseType::UINT8)
Create a GLSL renderer instance.
void drawScreenSpaceQuad(const Vector2 &uvMin=Vector2(0.0f), const Vector2 &uvMax=Vector2(1.0f))
Submit geometry for a screen-space quad.
void createProgram(ShaderPtr shader) override
Create GLSL program based on an input shader.
GLFramebufferPtr getFramebuffer() const
Return the GL frame buffer.
Definition: GlslRenderer.h:102
GlslProgramPtr getProgram()
Return the GLSL program.
Definition: GlslRenderer.h:108
ImageHandlerPtr createImageHandler(ImageLoaderPtr imageLoader)
Create a texture handler for OpenGL textures.
Definition: GlslRenderer.h:49
void render() override
Render the current program to an offscreen buffer.
void renderTextureSpace(const Vector2 &uvMin, const Vector2 &uvMax)
Render the current program in texture space to an off-screen buffer.
ImagePtr captureImage(ImagePtr image=nullptr) override
Capture the current contents of the off-screen hardware buffer as an image.
virtual ~GlslRenderer()
Destructor.
Definition: GlslRenderer.h:55
void createProgram(const StageMap &stages) override
Create GLSL program based on shader stage source code.
void initialize(RenderContextHandle renderContextHandle=nullptr) override
Internal initialization of stages and OpenGL constructs required for program validation and rendering...
void setSize(unsigned int width, unsigned int height) override
Set the size of the rendered image.
Base class for renderers that generate shader code to produce images.
Definition: ShaderRenderer.h:31
StringMap StageMap
A map with name and source code for each shader stage.
Definition: ShaderRenderer.h:40
A vector of two floating-point values.
Definition: Types.h:286