My Project
effect_file_OpenGL.h
1 #pragma once
2 #include "effect_file.h"
3 #include "ParameterBlock.h"
4 #include "gleffects.h"
5 #include <unordered_map>
6 
7 namespace GLWrapper{
8  class GLProgram;
9  struct Uniform;
10 }
11 
12 namespace ParaEngine
13 {
14 
15 
17  {
18  public:
19  CEffectFileOpenGL(const char* filename);
20  CEffectFileOpenGL(const AssetKey& key);
21 
22  void Init();
23 
24  virtual ~CEffectFileOpenGL();
25 
29  virtual HRESULT RendererRecreated();
30 
31  public:
33  static void EnableTextures(bool bEnable);
34  static bool AreTextureEnabled();
35 
36  int totalPasses()const;
37 
39  void EnableSunLight(bool bEnableSunLight);
43  void applySurfaceMaterial(const ParaMaterial* pSurfaceMaterial, bool bUseGlobalAmbient = true);
44  void applyCameraMatrices();
45  void applyWorldMatrices();
46  void applyFogParameters(bool bEnableFog, const Vector4* fogParam, const LinearColor* fogColor);
47  void applyGlobalLightingData(CSunLight& sunlight);
48 
49  bool setParameter(eParameterHandles index, const void* data, int32 size = D3DX_DEFAULT);
50  bool setParameter(eParameterHandles index, const Vector2* data);
51  bool setParameter(eParameterHandles index, const Vector3* data);
52  bool setParameter(eParameterHandles index, const Vector4* data);
53 
54  bool setBool(eParameterHandles index, BOOL bBoolean);
55  bool setInt(eParameterHandles index, int nValue);
56  bool setFloat(eParameterHandles index, float fValue);
57 
58  HRESULT SetRawValue(const char* hParameter, const void* pData, uint32 ByteOffset, uint32 Bytes);
59  bool SetBool(const char* hParameter, BOOL bBoolean);
60  bool SetInt(const char* hParameter, int nValue);
61  bool SetFloat(const char* hParameter, float fValue);
62  bool SetVector2(const char* hParameter, const Vector2& vValue);
63  bool SetVector3(const char* hParameter, const Vector3& vValue);
64  bool SetVector4(const char* hParameter, const Vector4& vValue);
65  bool SetMatrix(const char* hParameter, const Matrix4& data);
66 
67  bool isParameterUsed(eParameterHandles index);
68  bool setMatrix(eParameterHandles index, const Matrix4* data);
69  bool isMatrixUsed(eParameterHandles index);
70 
71  bool setTexture(int index, TextureEntity* data);
72  bool setTexture(int index, DeviceTexturePtr_type pTex);
73 
74  bool SetBoolean(int nIndex, bool value);
75 
76  bool begin(bool bApplyParam = true, DWORD flag = 0);
77  bool BeginPass(int pass, bool bForceBegin = false);
78  void CommitChanges();
79  void EndPass(bool bForceEnd = false);
80  void end(bool bForceEnd = false);
81 
82  virtual HRESULT InitDeviceObjects();
83 
84  bool LoadBuildinShader();
85 
86  virtual HRESULT DeleteDeviceObjects();
90  void releaseEffect(int nTech = -1, int nPass = -1);
91 
93  void SetFileName(const std::string& filename);
94  const std::string& GetFileName();
95 
101  bool EnableEnvironmentMapping(bool bEnable);
108  bool EnableReflectionMapping(bool bEnable, float fSurfaceHeight = 0.f);
109 
114  void SetReflectFactor(float fFactor);
119  void EnableNormalMap(bool bEnable);
120 
125  void EnableLightMap(bool bEnable);
126 
128  void EnableAlphaBlending(bool bAlphaBlending);
130  void EnableAlphaTesting(bool bAlphaTesting);
131 
132 
138  bool SetFirstValidTechniqueByCategory(TechniqueCategory nCat);
145  bool SetTechniqueByIndex(int nIndex);
147  const TechniqueDesc* GetCurrentTechniqueDesc();
148 
149  public:
150  bool setParameter(GLWrapper::Uniform* uniform, const void* data, int32 size = D3DX_DEFAULT);
151 
152  GLWrapper::GLProgram* GetGLProgram(int nTech, int nPass, bool bCreateIfNotExist = false);
153 
156  bool initWithByteArrays(const char* vShaderByteArray, const char* fShaderByteArray, int nTech = 0, int nPass = 0);
157 
160  bool initWithFilenames(const std::string& vShaderFilename, const std::string& fShaderFilename, int nTech = 0, int nPass = 0);
161 
163  bool link(int nTech = 0, int nPass = 0);
165  bool use(int nTech = -1, int nPass = -1);
175  void updateUniforms(int nTech = -1, int nPass = -1);
176 
177  GLWrapper::Uniform* GetUniformByID(eParameterHandles id);
178  GLWrapper::Uniform* GetUniform(const std::string& sName);
179 
181  template <typename ValueType>
182  void AddParamChange(const std::string& sName, const ValueType& value)
183  {
184  for (uint32 i = 0; i < m_pendingChangesCount; ++i)
185  {
186  if (m_pendingChanges[i].GetName() == sName)
187  {
188  m_pendingChanges[i] = value;
189  return;
190  }
191  }
192  ++ m_pendingChangesCount;
193  if (m_pendingChanges.size() < m_pendingChangesCount)
194  m_pendingChanges.resize(m_pendingChangesCount + 4);
195  m_pendingChanges[m_pendingChangesCount - 1].SetName(sName);
196  m_pendingChanges[m_pendingChangesCount - 1] = value;
197  }
198 
199  void SetShadowMapSize(int nsize);
200 
201  protected:
202  bool MappingEffectUniforms();
203  bool GeneratePasses();
204 
205  protected:
206  std::unordered_map<uint32, std::string> m_ID2Names;
207  GLEffectsTree* m_Effect;
208 
210  {
211  std::vector<GLWrapper::GLProgram*> mPasses;
212  };
213  std::vector<TechniqueDescGL> mTechniques;
214  int mTechniqueIndex;
217  bool m_bIsBegin;
218  std::string m_filename;
219 
220  std::vector<CParameter> m_pendingChanges;
221  uint32 m_pendingChangesCount;
222  };
223 
224 
225  // this is the actually class used externally. it does following:
226  // typedef CEffectFileOpenGL CEffectFile;
227  class CEffectFile : public CEffectFileOpenGL
228  {
229  public:
230  CEffectFile(const char* filename) :CEffectFileOpenGL(filename){};
231  CEffectFile(const AssetKey& key) :CEffectFileOpenGL(key){};
232  virtual ~CEffectFile(){};
233  };
234 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
eParameterHandles
Definition: effect_file.h:41
Definition: effect_file_OpenGL.h:209
a technique description
Definition: effect_file.h:179
4-dimensional homogeneous vector.
Definition: ParaVector4.h:10
different physics engine has different winding order.
Definition: EventBinding.h:32
void AddParamChange(const std::string &sName, const ValueType &value)
add changes to shader parameters, those changes are commited to device when CommitChange() is called...
Definition: effect_file_OpenGL.h:182
TechniqueCategory
The game engine will identified some predefined technique name from the the effect file...
Definition: effect_file.h:27
Definition: effect_file_OpenGL.h:7
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc.
Definition: SunLight.h:26
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
int m_nActivePassIndex
current active pass
Definition: effect_file_OpenGL.h:216
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
Definition: RenderCore.h:50
Definition: enum_maker.hpp:46
Definition: effect_file.h:323
std::string AssetKey
the unique key object for asset entity.
Definition: AssetEntity.h:13
Definition: effect_file_OpenGL.h:16
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
asset entity: CEffectFile
Definition: effect_file.h:19