MaterialX 1.39.1
Loading...
Searching...
No Matches
ShaderRenderer.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_SHADERRENDERER_H
7#define MATERIALX_SHADERRENDERER_H
8
11
12#include <MaterialXRender/Camera.h>
16
18
19MATERIALX_NAMESPACE_BEGIN
20
23using RenderContextHandle = void*;
24
26using ShaderRendererPtr = std::shared_ptr<class ShaderRenderer>;
27
30class MX_RENDER_API ShaderRenderer
31{
32 public:
35 {
36 OpenGL = 0,
37 Metal = 1
38 };
41
42 public:
43 virtual ~ShaderRenderer() { }
44
47
49 virtual void initialize(RenderContextHandle = nullptr) { }
50
52 void setCamera(CameraPtr camera)
53 {
54 _camera = camera;
55 }
56
58 CameraPtr getCamera() const
59 {
60 return _camera;
61 }
62
65 {
66 _imageHandler = imageHandler;
67 }
68
71 {
72 return _imageHandler;
73 }
74
77 {
78 _lightHandler = lightHandler;
79 }
80
83 {
84 return _lightHandler;
85 }
86
89 {
90 _geometryHandler = geometryHandler;
91 }
92
95 {
96 return _geometryHandler;
97 }
98
102
104 virtual void createProgram(ShaderPtr shader);
105
108 virtual void createProgram(const StageMap& stages);
109
111 virtual void validateInputs() { }
112
114 virtual void updateUniform(const string& name, ConstValuePtr value);
115
117 virtual void setSize(unsigned int width, unsigned int height);
118
120 virtual void render() { }
121
125
127 virtual ImagePtr captureImage(ImagePtr image = nullptr)
128 {
129 return nullptr;
130 }
131
133
134 protected:
135 ShaderRenderer(unsigned int width, unsigned int height, Image::BaseType baseType,
136 MatrixConvention matrixConvention = MatrixConvention::OpenGL);
137
138 protected:
139 unsigned int _width;
140 unsigned int _height;
141 Image::BaseType _baseType;
142
143 MatrixConvention _matrixConvention;
144
145 CameraPtr _camera;
146 ImageHandlerPtr _imageHandler;
147 GeometryHandlerPtr _geometryHandler;
148 LightHandlerPtr _lightHandler;
149};
150
155class MX_RENDER_API ExceptionRenderError : public Exception
156{
157 public:
158 ExceptionRenderError(const string& msg, const StringVec& errorLog = StringVec()) :
159 Exception(msg),
160 _errorLog(errorLog)
161 {
162 }
163
165 Exception(e),
166 _errorLog(e._errorLog)
167 {
168 }
169
170 ExceptionRenderError& operator=(const ExceptionRenderError& e)
171 {
172 Exception::operator=(e);
173 _errorLog = e._errorLog;
174 return *this;
175 }
176
177 const StringVec& errorLog() const
178 {
179 return _errorLog;
180 }
181
182 private:
183 StringVec _errorLog;
184};
185
186MATERIALX_NAMESPACE_END
187
188#endif
Geometry loader interfaces.
std::shared_ptr< class GeometryHandler > GeometryHandlerPtr
Shared pointer to an GeometryHandler.
Definition: GeometryHandler.h:55
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
Image handler interfaces.
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
Handler for hardware lights.
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:25
vector< string > StringVec
A vector of strings.
Definition: Library.h:55
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:57
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
Shader instance class created during shader generation.
void * RenderContextHandle
Render context handle Provides a provision for an application to share any renderer specific settings...
Definition: ShaderRenderer.h:23
std::shared_ptr< class ShaderRenderer > ShaderRendererPtr
Shared pointer to a shader renderer.
Definition: ShaderRenderer.h:26
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition: Exception.h:22
An exception that is thrown when a rendering operation fails.
Definition: ShaderRenderer.h:156
Base class for renderers that generate shader code to produce images.
Definition: ShaderRenderer.h:31
virtual void createProgram(const StageMap &stages)
Create program based on shader stage source code.
virtual ImagePtr captureImage(ImagePtr image=nullptr)
Capture the current rendered output as an image.
Definition: ShaderRenderer.h:127
virtual void render()
Render the current program to produce an image.
Definition: ShaderRenderer.h:120
void setImageHandler(ImageHandlerPtr imageHandler)
Set the image handler used by this renderer for image I/O.
Definition: ShaderRenderer.h:64
void setLightHandler(LightHandlerPtr lightHandler)
Set the light handler used by this renderer for light bindings.
Definition: ShaderRenderer.h:76
virtual void validateInputs()
Validate inputs for the program.
Definition: ShaderRenderer.h:111
void setGeometryHandler(GeometryHandlerPtr geometryHandler)
Set the geometry handler.
Definition: ShaderRenderer.h:88
GeometryHandlerPtr getGeometryHandler() const
Return the geometry handler.
Definition: ShaderRenderer.h:94
ImageHandlerPtr getImageHandler() const
Return the image handler.
Definition: ShaderRenderer.h:70
MatrixConvention
Viewing API matrix conventions designation (default to OpenGL).
Definition: ShaderRenderer.h:35
virtual void setSize(unsigned int width, unsigned int height)
Set the size of the rendered image.
void setCamera(CameraPtr camera)
Set the camera.
Definition: ShaderRenderer.h:52
virtual void createProgram(ShaderPtr shader)
Create program based on an input shader.
CameraPtr getCamera() const
Return the camera.
Definition: ShaderRenderer.h:58
LightHandlerPtr getLightHandler() const
Return the light handler.
Definition: ShaderRenderer.h:82
virtual void updateUniform(const string &name, ConstValuePtr value)
Update the program with value of the uniform.
StringMap StageMap
A map with name and source code for each shader stage.
Definition: ShaderRenderer.h:40
virtual void initialize(RenderContextHandle=nullptr)
Initialize the renderer.
Definition: ShaderRenderer.h:49