GteLightingEffect.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.1 (2016/11/13)
7 
8 #pragma once
9 
11 #include <Graphics/GteMaterial.h>
12 #include <Graphics/GteLighting.h>
14 
15 namespace gte
16 {
17 
19 {
20 protected:
21  // Construction (abstract base class). The shader source code string
22  // arrays must contain strings for any supported graphics API.
23  LightingEffect(std::shared_ptr<ProgramFactory> const& factory,
24  BufferUpdater const& updater, std::string const* vsSource[],
25  std::string const* psSource[], std::shared_ptr<Material> const& material,
26  std::shared_ptr<Lighting> const& lighting,
27  std::shared_ptr<LightCameraGeometry> const& geometry);
28 
29 public:
30  // Member access.
31  inline void SetMaterial(std::shared_ptr<Material> const& material);
32  inline void SetLighting(std::shared_ptr<Lighting> const& lighting);
33  inline void SetGeometry(std::shared_ptr<LightCameraGeometry> const& geometry);
34  inline std::shared_ptr<Material> const& GetMaterial() const;
35  inline std::shared_ptr<Lighting> const& GetLighting() const;
36  inline std::shared_ptr<LightCameraGeometry> const& GetGeometry() const;
37  inline std::shared_ptr<ConstantBuffer> const& GetPVWMatrixConstant() const;
38  inline std::shared_ptr<ConstantBuffer> const& GetMaterialConstant() const;
39  inline std::shared_ptr<ConstantBuffer> const& GetLightingConstant() const;
40  inline std::shared_ptr<ConstantBuffer> const& GetGeometryConstant() const;
41 
42  void SetPVWMatrixConstant(std::shared_ptr<ConstantBuffer> const& pvwMatrix);
43 
44  // After you set or modify 'material', 'light', or 'geometry', call the update
45  // to inform any listener that the corresponding constant buffer has changed.
46  // The derived classes construct the constant buffers to store the minimal
47  // information from Material, Light, or Camera. The pvw-matrix constant update
48  // requires knowledge of the world transform of the object to which the effect
49  // is attached, so its update must occur outside of this class. Derived
50  // classes update the system memory of the constant buffers and the base class
51  // updates video memory.
52  virtual void UpdateMaterialConstant();
53  virtual void UpdateLightingConstant();
54  virtual void UpdateGeometryConstant();
55 
56 protected:
57  std::shared_ptr<Material> mMaterial;
58  std::shared_ptr<Lighting> mLighting;
59  std::shared_ptr<LightCameraGeometry> mGeometry;
60 
61  std::shared_ptr<ConstantBuffer> mPVWMatrixConstant;
62 
63  // The derived-class constructors are responsible for creating these
64  // according to their needs.
65  std::shared_ptr<ConstantBuffer> mMaterialConstant;
66  std::shared_ptr<ConstantBuffer> mLightingConstant;
67  std::shared_ptr<ConstantBuffer> mGeometryConstant;
68 
69  // HLSL has a shader intrinsic lit() function.
70  // This inline string of code reproduces that function for GLSL.
71  // Static method used here because this string needs to be generated
72  // before code (which may also be in global initializers) tries to use it.
73  static std::string GetShaderSourceLitFunctionGLSL();
74 };
75 
76 inline void LightingEffect::SetMaterial(std::shared_ptr<Material> const& material)
77 {
78  mMaterial = material;
79 }
80 
81 inline void LightingEffect::SetLighting(std::shared_ptr<Lighting> const& lighting)
82 {
83  mLighting = lighting;
84 }
85 
86 inline void LightingEffect::SetGeometry(std::shared_ptr<LightCameraGeometry> const& geometry)
87 {
88  mGeometry = geometry;
89 }
90 
91 inline std::shared_ptr<Material> const& LightingEffect::GetMaterial() const
92 {
93  return mMaterial;
94 }
95 
96 inline std::shared_ptr<Lighting> const& LightingEffect::GetLighting() const
97 {
98  return mLighting;
99 }
100 
101 inline std::shared_ptr<LightCameraGeometry> const& LightingEffect::GetGeometry() const
102 {
103  return mGeometry;
104 }
105 
106 inline std::shared_ptr<ConstantBuffer> const& LightingEffect::GetPVWMatrixConstant() const
107 {
108  return mPVWMatrixConstant;
109 }
110 
111 inline std::shared_ptr<ConstantBuffer> const& LightingEffect::GetMaterialConstant() const
112 {
113  return mMaterialConstant;
114 }
115 
116 inline std::shared_ptr<ConstantBuffer> const& LightingEffect::GetLightingConstant() const
117 {
118  return mLightingConstant;
119 }
120 
121 inline std::shared_ptr<ConstantBuffer> const& LightingEffect::GetGeometryConstant() const
122 {
123  return mGeometryConstant;
124 }
125 
126 }
std::shared_ptr< ConstantBuffer > const & GetPVWMatrixConstant() const
std::shared_ptr< Material > mMaterial
void SetLighting(std::shared_ptr< Lighting > const &lighting)
std::shared_ptr< Lighting > const & GetLighting() const
std::shared_ptr< LightCameraGeometry > mGeometry
std::function< void(std::shared_ptr< Buffer > const &)> BufferUpdater
Definition: GteBuffer.h:24
std::shared_ptr< ConstantBuffer > mGeometryConstant
void SetGeometry(std::shared_ptr< LightCameraGeometry > const &geometry)
std::shared_ptr< Lighting > mLighting
std::shared_ptr< LightCameraGeometry > const & GetGeometry() const
std::shared_ptr< ConstantBuffer > const & GetLightingConstant() const
std::shared_ptr< ConstantBuffer > const & GetGeometryConstant() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
std::shared_ptr< ConstantBuffer > mLightingConstant
std::shared_ptr< ConstantBuffer > const & GetMaterialConstant() const
std::shared_ptr< ConstantBuffer > mMaterialConstant
void SetMaterial(std::shared_ptr< Material > const &material)
std::shared_ptr< ConstantBuffer > mPVWMatrixConstant
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
std::shared_ptr< Material > const & GetMaterial() const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00