MaterialX 1.38.10
Loading...
Searching...
No Matches
GlslMaterial.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_GLSLMATERIAL_H
7#define MATERIALX_GLSLMATERIAL_H
8
11
14
17
18MATERIALX_NAMESPACE_BEGIN
19
20using GlslMaterialPtr = std::shared_ptr<class GlslMaterial>;
21
24class MX_RENDERGLSL_API GlslMaterial : public ShaderMaterial
25{
26 public:
27 GlslMaterial() :
29 {
30 }
31 ~GlslMaterial() { }
32
33 static GlslMaterialPtr create()
34 {
35 return std::make_shared<GlslMaterial>();
36 }
37
39 bool loadSource(const FilePath& vertexShaderFile,
40 const FilePath& pixelShaderFile,
41 bool hasTransparency) override;
42
45 bool generateShader(GenContext& context) override;
46
48 bool generateShader(ShaderPtr hwShader) override;
49
51 void copyShader(MaterialPtr material) override
52 {
53 _hwShader = std::static_pointer_cast<GlslMaterial>(material)->_hwShader;
54 _glProgram = std::static_pointer_cast<GlslMaterial>(material)->_glProgram;
55 }
56
58 GlslProgramPtr getProgram() const
59 {
60 return _glProgram;
61 }
62
64 bool bindShader() const override;
65
67 void bindViewInformation(CameraPtr camera) override;
68
70 void bindImages(ImageHandlerPtr imageHandler,
71 const FileSearchPath& searchPath,
72 bool enableMipmaps = true) override;
73
75 void unbindImages(ImageHandlerPtr imageHandler) override;
76
78 ImagePtr bindImage(const FilePath& filePath,
79 const std::string& uniformName,
80 ImageHandlerPtr imageHandler,
81 const ImageSamplingProperties& samplingProperties) override;
82
84 void bindLighting(LightHandlerPtr lightHandler,
85 ImageHandlerPtr imageHandler,
86 const ShadowState& shadowState) override;
87
89 void bindMesh(MeshPtr mesh) override;
90
92 bool bindPartition(MeshPartitionPtr part) const override;
93
95 void drawPartition(MeshPartitionPtr part) const override;
96
98 void unbindGeometry() override;
99
101 VariableBlock* getPublicUniforms() const override;
102
104 ShaderPort* findUniform(const std::string& path) const override;
105
107 void modifyUniform(const std::string& path,
108 ConstValuePtr value,
109 std::string valueString = EMPTY_STRING) override;
110
111 protected:
112 void clearShader() override;
113
114 protected:
115 GlslProgramPtr _glProgram;
116};
117
118MATERIALX_NAMESPACE_END
119
120#endif
GLSL Program interfaces.
GLSL shader generator.
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:25
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:146
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:230
ShaderMaterial helper classes.
Unit system classes.
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:27
A sequence of file paths, which may be queried to find the first instance of a given filename on the ...
Definition: File.h:219
A context class for shader generation.
Definition: GenContext.h:31
Helper class for GLSL generation and rendering of a material.
Definition: GlslMaterial.h:25
GlslProgramPtr getProgram() const
Return the underlying GLSL program.
Definition: GlslMaterial.h:58
void copyShader(MaterialPtr material) override
Copy shader from one material to this one.
Definition: GlslMaterial.h:51
Interface to describe sampling properties for images.
Definition: ImageHandler.h:43
Abstract class for shader generation and rendering of a ShaderMaterial.
Definition: ShaderMaterial.h:40
virtual void unbindImages(ImageHandlerPtr imageHandler)=0
Unbbind all images for this ShaderMaterial.
virtual void bindMesh(MeshPtr mesh)=0
Bind the given mesh to this ShaderMaterial.
virtual bool generateShader(GenContext &context)=0
Generate a shader from our currently stored element and the given generator context.
virtual bool bindShader() const =0
Bind shader.
virtual bool loadSource(const FilePath &vertexShaderFile, const FilePath &pixelShaderFile, bool hasTransparency)=0
Load shader source from file.
virtual ImagePtr bindImage(const FilePath &filePath, const std::string &uniformName, ImageHandlerPtr imageHandler, const ImageSamplingProperties &samplingProperties)=0
Bind a single image.
virtual void bindLighting(LightHandlerPtr lightHandler, ImageHandlerPtr imageHandler, const ShadowState &shadowState)=0
Bind lights to shader.
virtual void bindViewInformation(CameraPtr camera)=0
Bind viewing information for this ShaderMaterial.
virtual VariableBlock * getPublicUniforms() const =0
Return the block of public uniforms for this ShaderMaterial.
virtual bool bindPartition(MeshPartitionPtr part) const =0
Bind a mesh partition to this ShaderMaterial.
virtual void modifyUniform(const std::string &path, ConstValuePtr value, std::string valueString=EMPTY_STRING)=0
Modify the value of the uniform with the given path.
virtual void unbindGeometry()=0
Unbind all geometry from this ShaderMaterial.
virtual void bindImages(ImageHandlerPtr imageHandler, const FileSearchPath &searchPath, bool enableMipmaps=true)=0
Bind all images for this ShaderMaterial.
virtual ShaderPort * findUniform(const std::string &path) const =0
Find a public uniform from its MaterialX path.
virtual void drawPartition(MeshPartitionPtr part) const =0
Draw the given mesh partition.
An input or output port on a ShaderNode.
Definition: ShaderNode.h:123
Helper class representing shadow rendering state.
Definition: ShaderMaterial.h:29
A block of variables in a shader stage.
Definition: ShaderStage.h:61