HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
9 /// @file
10 /// GLSL material helper classes
11 
14 
17 
19 
20 using GlslMaterialPtr = std::shared_ptr<class GlslMaterial>;
21 
22 /// @class GlslMaterial
23 /// Helper class for GLSL generation and rendering of a material
25 {
26  public:
28  {
29  }
31 
33  {
34  return std::make_shared<GlslMaterial>();
35  }
36 
37  /// Load shader source from file.
38  bool loadSource(const FilePath& vertexShaderFile,
39  const FilePath& pixelShaderFile,
40  bool hasTransparency) override;
41 
42  /// Generate a shader from our currently stored element and
43  /// the given generator context.
44  bool generateShader(GenContext& context) override;
45 
46  /// Generate a shader from the given hardware shader.
47  bool generateShader(ShaderPtr hwShader) override;
48 
49  /// Copy shader from one material to this one
50  void copyShader(MaterialPtr material) override
51  {
52  _hwShader = std::static_pointer_cast<GlslMaterial>(material)->_hwShader;
53  _glProgram = std::static_pointer_cast<GlslMaterial>(material)->_glProgram;
54  }
55 
56  /// Return the underlying GLSL program.
58  {
59  return _glProgram;
60  }
61 
62  /// Bind shader
63  bool bindShader() const override;
64 
65  /// Bind viewing information for this material.
66  void bindViewInformation(CameraPtr camera) override;
67 
68  /// Bind all images for this material.
69  void bindImages(ImageHandlerPtr imageHandler,
70  const FileSearchPath& searchPath,
71  bool enableMipmaps = true) override;
72 
73  /// Unbbind all images for this material.
74  void unbindImages(ImageHandlerPtr imageHandler) override;
75 
76  /// Bind a single image.
77  ImagePtr bindImage(const FilePath& filePath,
78  const std::string& uniformName,
79  ImageHandlerPtr imageHandler,
80  const ImageSamplingProperties& samplingProperties) override;
81 
82  /// Bind lights to shader.
83  void bindLighting(LightHandlerPtr lightHandler,
84  ImageHandlerPtr imageHandler,
85  const ShadowState& shadowState) override;
86 
87  /// Bind the given mesh to this material.
88  void bindMesh(MeshPtr mesh) override;
89 
90  /// Bind a mesh partition to this material.
91  bool bindPartition(MeshPartitionPtr part) const override;
92 
93  /// Draw the given mesh partition.
94  void drawPartition(MeshPartitionPtr part) const override;
95 
96  /// Unbind all geometry from this material.
97  void unbindGeometry() override;
98 
99  /// Return the block of public uniforms for this material.
100  VariableBlock* getPublicUniforms() const override;
101 
102  /// Find a public uniform from its MaterialX path.
103  ShaderPort* findUniform(const std::string& path) const override;
104 
105  /// Modify the value of the uniform with the given path.
106  void modifyUniform(const std::string& path,
108  std::string valueString = EMPTY_STRING) override;
109 
110  protected:
111  void clearShader() override;
112 
113  protected:
115 };
116 
118 
119 #endif
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:230
std::shared_ptr< class Camera > CameraPtr
Shared pointer to a Camera.
Definition: Camera.h:14
virtual bool generateShader(GenContext &context)=0
Definition: File.h:26
void copyShader(MaterialPtr material) override
Copy shader from one material to this one.
Definition: GlslMaterial.h:50
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:146
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GlslProgramPtr _glProgram
Definition: GlslMaterial.h:114
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual void bindMesh(MeshPtr mesh)=0
Bind the given mesh to this ShaderMaterial.
virtual bool bindShader() const =0
Bind shader.
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
virtual bool bindPartition(MeshPartitionPtr part) const =0
Bind a mesh partition to this ShaderMaterial.
virtual void unbindImages(ImageHandlerPtr imageHandler)=0
Unbbind all images for this ShaderMaterial.
virtual void drawPartition(MeshPartitionPtr part) const =0
Draw the given mesh partition.
std::shared_ptr< class GlslMaterial > GlslMaterialPtr
Definition: GlslMaterial.h:20
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:25
virtual void bindImages(ImageHandlerPtr imageHandler, const FileSearchPath &searchPath, bool enableMipmaps=true)=0
Bind all images for this ShaderMaterial.
virtual void clearShader()=0
virtual ShaderPort * findUniform(const std::string &path) const =0
Find a public uniform from its MaterialX path.
std::shared_ptr< class GlslProgram > GlslProgramPtr
Definition: GlslProgram.h:24
static GlslMaterialPtr create()
Definition: GlslMaterial.h:32
virtual void bindLighting(LightHandlerPtr lightHandler, ImageHandlerPtr imageHandler, const ShadowState &shadowState)=0
Bind lights to shader.
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
virtual ImagePtr bindImage(const FilePath &filePath, const std::string &uniformName, ImageHandlerPtr imageHandler, const ImageSamplingProperties &samplingProperties)=0
Bind a single image.
#define MX_RENDERGLSL_API
Definition: Export.h:18
GlslProgramPtr getProgram() const
Return the underlying GLSL program.
Definition: GlslMaterial.h:57
virtual void unbindGeometry()=0
Unbind all geometry from this ShaderMaterial.
virtual VariableBlock * getPublicUniforms() const =0
Return the block of public uniforms for this ShaderMaterial.
virtual void bindViewInformation(CameraPtr camera)=0
Bind viewing information for this ShaderMaterial.
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
Definition: core.h:1131
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
virtual bool loadSource(const FilePath &vertexShaderFile, const FilePath &pixelShaderFile, bool hasTransparency)=0
Load shader source from file.
std::shared_ptr< class ShaderMaterial > MaterialPtr
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
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.
GLuint GLsizei GLsizei GLchar * uniformName
Definition: glcorearb.h:1464