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:
29  {
30  }
32 
34  {
35  return std::make_shared<GlslMaterial>();
36  }
37 
38  /// Load shader source from file.
39  bool loadSource(const FilePath& vertexShaderFile,
40  const FilePath& pixelShaderFile,
41  bool hasTransparency) override;
42 
43  /// Generate a shader from our currently stored element and
44  /// the given generator context.
45  bool generateShader(GenContext& context) override;
46 
47  /// Generate a shader from the given hardware shader.
48  bool generateShader(ShaderPtr hwShader) override;
49 
50  /// Copy shader from one material to this one
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 
57  /// Return the underlying GLSL program.
59  {
60  return _glProgram;
61  }
62 
63  /// Bind shader
64  bool bindShader() const override;
65 
66  /// Bind viewing information for this material.
67  void bindViewInformation(CameraPtr camera) override;
68 
69  /// Bind all images for this material.
70  void bindImages(ImageHandlerPtr imageHandler,
71  const FileSearchPath& searchPath,
72  bool enableMipmaps = true) override;
73 
74  /// Unbbind all images for this material.
75  void unbindImages(ImageHandlerPtr imageHandler) override;
76 
77  /// Bind a single image.
78  ImagePtr bindImage(const FilePath& filePath,
79  const std::string& uniformName,
80  ImageHandlerPtr imageHandler,
81  const ImageSamplingProperties& samplingProperties) override;
82 
83  /// Bind lights to shader.
84  void bindLighting(LightHandlerPtr lightHandler,
85  ImageHandlerPtr imageHandler,
86  const ShadowState& shadowState) override;
87 
88  /// Bind the given mesh to this material.
89  void bindMesh(MeshPtr mesh) override;
90 
91  /// Bind a mesh partition to this material.
92  bool bindPartition(MeshPartitionPtr part) const override;
93 
94  /// Draw the given mesh partition.
95  void drawPartition(MeshPartitionPtr part) const override;
96 
97  /// Unbind all geometry from this material.
98  void unbindGeometry() override;
99 
100  /// Return the block of public uniforms for this material.
101  VariableBlock* getPublicUniforms() const override;
102 
103  /// Find a public uniform from its MaterialX path.
104  ShaderPort* findUniform(const std::string& path) const override;
105 
106  /// Modify the value of the uniform with the given path.
107  void modifyUniform(const std::string& path,
109  std::string valueString = EMPTY_STRING) override;
110 
111  protected:
112  void clearShader() override;
113 
114  protected:
116 };
117 
119 
120 #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:51
#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:115
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:33
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:58
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