Ocular Engine
Material.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_GRAPHICS_GRAPHICS_MATERIAL_H__
19 #define __H__OCULAR_GRAPHICS_GRAPHICS_MATERIAL_H__
20 
21 #include "Graphics/Shader/Uniform/UniformBuffer.hpp"
22 #include "Graphics/RenderState/RasterState.hpp"
23 #include "Renderer/RenderPriority.hpp"
24 
25 #include "Resources/Resource.hpp"
26 #include "ObjectIO/ObjectIO.hpp"
27 #include "Math/Matrix4x4.hpp"
28 
29 #include <unordered_map>
30 
31 //------------------------------------------------------------------------------------------
32 
37 namespace Ocular
38 {
43  namespace Graphics
44  {
45  class Texture;
46  class VertexShader;
47  class GeometryShader;
48  class FragmentShader;
49  class PreTessellationShader;
50  class PostTessellationShader;
51 
53  {
54  Texture* texture;
55  std::string samplerName;
56  uint32_t samplerRegister;
57  };
58 
62  class Material : public Core::Resource, public Core::ObjectIO
63  {
64  public:
65 
66  Material();
67  virtual ~Material();
68 
69  virtual void bind();
70  virtual void unbind();
71 
72  virtual void unload() override;
73 
74  //------------------------------------------------------------
75  // Inherited Methods
76  //------------------------------------------------------------
77 
78  virtual void onLoad(Core::BuilderNode const* node) override;
79  virtual void onSave(Core::BuilderNode* node) const override;
80 
81  //------------------------------------------------------------
82  // Texture Methods
83  //------------------------------------------------------------
84 
104  virtual bool setTexture(uint32_t index, std::string const& name, Texture* texture);
105 
110  Texture* getTexture(uint32_t index) const;
111 
116  virtual void removeTexture(uint32_t index);
117 
121  uint32_t getNumTextures() const;
122 
127  std::vector<TextureSamplerInfo> const* getTextures() const;
128 
129  //------------------------------------------------------------
130  // Shader Methods
131  //------------------------------------------------------------
132 
141  bool setVertexShader(std::string const& name);
142 
147  void setVertexShader(VertexShader* shader);
148 
157  bool setGeometryShader(std::string const& name);
158 
163  void setGeometryShader(GeometryShader* shader);
164 
173  bool setFragmentShader(std::string const& name);
174 
179  void setFragmentShader(FragmentShader* shader);
180 
189  bool setPreTessellationShader(std::string const& name);
190 
196 
205  bool setPostTessellationShader(std::string const& name);
206 
212 
216  VertexShader* getVertexShader() const;
217 
222 
227 
232 
237 
238  //------------------------------------------------------------
239  // Uniform Methods
240  //------------------------------------------------------------
241 
253  virtual void setUniform(std::string const& name, uint32_t registerIndex, float value);
254 
264  virtual bool getUniform(std::string const& name, float& value);
265 
278  virtual void setUniform(std::string const& name, uint32_t registerIndex, Math::Vector4f const& value, std::string const& type = Utils::TypeName<Math::Vector4f>::name);
279 
289  virtual bool getUniform(std::string const& name, Math::Vector4f& value);
290 
302  virtual void setUniform(std::string const& name, uint32_t registerIndex, Math::Matrix3x3 const& value);
303 
313  virtual bool getUniform(std::string const& name, Math::Matrix3x3& value);
314 
326  virtual void setUniform(std::string const& name, uint32_t registerIndex, Math::Matrix4x4 const& value);
327 
337  virtual bool getUniform(std::string const& name, Math::Matrix4x4& value);
338 
342  UniformBuffer const* getUniformBuffer() const;
343 
344  //------------------------------------------------------------
345  // Render State Changes
346  //------------------------------------------------------------
347 
352  void setPrimitiveStyle(PrimitiveStyle style);
353 
357  PrimitiveStyle getPrimitiveStyle() const;
358 
363  void setFillMode(FillMode mode);
364 
368  FillMode getFillMode() const;
369 
377  void setRenderPriority(uint32_t priority);
378 
382  uint32_t getRenderPriority() const;
383 
384  //------------------------------------------------------------
385  // Node Names (used for saving and loading)
386 
387  static const std::string ShaderNodeName;
388  static const std::string TextureNodeName;
389  static const std::string UniformNodeName;
390  static const std::string RenderStateNodeName;
391 
392  protected:
393 
394  void setDefaults();
395 
396  void bindShaders();
397  void unbindShaders();
398 
399  void bindStateChanges();
400  void unbindStateChanges();
401 
402  //------------------------------------------------------------
403 
404  VertexShader* m_VertexShader;
405  GeometryShader* m_GeometryShader;
406  FragmentShader* m_FragmentShader;
407  PreTessellationShader* m_PreTessellationShader;
408  PostTessellationShader* m_PostTessellationShader;
409 
410  RasterState m_StoredRasterState;
411 
412  std::vector<TextureSamplerInfo> m_Textures;
413  UniformBuffer* m_UniformBuffer;
414 
415  uint32_t m_RenderPriority;
416 
417  private:
418  };
419  }
423 }
428 //------------------------------------------------------------------------------------------
429 
430 #endif
virtual void unload() override
Definition: Material.cpp:95
Definition: Matrix3x3.hpp:39
Definition: Material.hpp:52
virtual void removeTexture(uint32_t index)
Definition: Material.cpp:488
void setRenderPriority(uint32_t priority)
Definition: Material.cpp:897
Definition: FragmentShader.hpp:40
Definition: VertexShader.hpp:40
virtual void onLoad(Core::BuilderNode const *node) override
Definition: Material.cpp:100
FillMode getFillMode() const
Definition: Material.cpp:892
void setFillMode(FillMode mode)
Definition: Material.cpp:887
void setPrimitiveStyle(PrimitiveStyle style)
Definition: Material.cpp:877
std::vector< TextureSamplerInfo > const * getTextures() const
Definition: Material.cpp:511
VertexShader * getVertexShader() const
Definition: Material.cpp:680
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: PreTessellationShader.hpp:40
bool setPostTessellationShader(std::string const &name)
Definition: Material.cpp:648
virtual void onSave(Core::BuilderNode *node) const override
Definition: Material.cpp:320
Utility structure to convert a type T to a string representation.
Definition: Types.hpp:66
Definition: ObjectIO.hpp:38
Texture * getTexture(uint32_t index) const
Definition: Material.cpp:466
UniformBuffer const * getUniformBuffer() const
Definition: Material.cpp:868
bool setFragmentShader(std::string const &name)
Definition: Material.cpp:584
GeometryShader * getGeometryShader() const
Definition: Material.cpp:685
virtual bool setTexture(uint32_t index, std::string const &name, Texture *texture)
Definition: Material.cpp:427
uint32_t getNumTextures() const
Definition: Material.cpp:506
bool setGeometryShader(std::string const &name)
Definition: Material.cpp:552
A 3x3 column-major float matrix.
Definition: Matrix3x3.hpp:63
uint32_t getRenderPriority() const
Definition: Material.cpp:902
virtual void setUniform(std::string const &name, uint32_t registerIndex, float value)
Definition: Material.cpp:709
PrimitiveStyle getPrimitiveStyle() const
Definition: Material.cpp:882
Generic node system used for loading and saving SceneObjects and their components.
Definition: BuilderNode.hpp:51
PreTessellationShader * getPreTessellationShader() const
Definition: Material.cpp:695
Definition: RasterState.hpp:92
Definition: PostTessellationShader.hpp:40
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
PostTessellationShader * getPostTessellationShader() const
Definition: Material.cpp:700
bool setPreTessellationShader(std::string const &name)
Definition: Material.cpp:616
virtual bool getUniform(std::string const &name, float &value)
Definition: Material.cpp:720
bool setVertexShader(std::string const &name)
Definition: Material.cpp:520
FragmentShader * getFragmentShader() const
Definition: Material.cpp:690
Generic buffer for storing and binding of shader uniforms.
Definition: UniformBuffer.hpp:73
Definition: GeometryShader.hpp:40
Definition: Material.hpp:62
Definition: Resource.hpp:46
Base class for all texture objects.
Definition: Texture.hpp:45