28 #ifndef HPL_MATERIAL_H 29 #define HPL_MATERIAL_H 31 #include "common/array.h" 32 #include "common/list.h" 33 #include "hpl1/engine/graphics/GPUProgram.h" 34 #include "hpl1/engine/graphics/LowLevelGraphics.h" 35 #include "hpl1/engine/graphics/Texture.h" 36 #include "hpl1/engine/resources/ResourceBase.h" 37 #include "hpl1/engine/resources/ResourceImage.h" 38 #include "hpl1/engine/system/SystemTypes.h" 44 #define kMaxProgramNum (5) 46 enum eMaterialQuality {
47 eMaterialQuality_VeryLow = 0,
48 eMaterialQuality_Low = 1,
49 eMaterialQuality_Medium = 2,
50 eMaterialQuality_High = 3,
51 eMaterialQuality_VeryHigh = 4,
52 eMaterialQuality_LastEnum = 5
55 enum eMaterialTexture {
56 eMaterialTexture_Diffuse,
57 eMaterialTexture_NMap,
58 eMaterialTexture_Specular,
59 eMaterialTexture_Alpha,
60 eMaterialTexture_Illumination,
61 eMaterialTexture_CubeMap,
62 eMaterialTexture_Refraction,
63 eMaterialTexture_LastEnum
69 eMaterialType_Diffuse,
70 eMaterialType_DiffuseAlpha,
71 eMaterialType_DiffuseAdditive,
72 eMaterialType_DiffuseNMap,
73 eMaterialType_DiffuseSpecular,
74 eMaterialType_BumpSpec,
77 eMaterialType_FontNormal,
79 eMaterialType_LastEnum
82 enum eMaterialPicture {
83 eMaterialPicture_Image,
84 eMaterialPicture_Texture,
85 eMaterialPicture_LastEnum
88 enum eMaterialRenderType {
89 eMaterialRenderType_Z,
90 eMaterialRenderType_Light,
91 eMaterialRenderType_Diffuse,
92 eMaterialRenderType_LastEnum
95 enum eMaterialBlendMode {
96 eMaterialBlendMode_None,
97 eMaterialBlendMode_Add,
98 eMaterialBlendMode_Mul,
99 eMaterialBlendMode_MulX2,
100 eMaterialBlendMode_Replace,
101 eMaterialBlendMode_Alpha,
102 eMaterialBlendMode_DestAlphaAdd,
103 eMaterialBlendMode_LastEnum
106 enum eMaterialAlphaMode {
107 eMaterialAlphaMode_Solid,
108 eMaterialAlphaMode_Trans,
109 eMaterialAlphaMode_LastEnum,
113 enum eMaterialChannelMode {
114 eMaterialChannelMode_RGBA,
115 eMaterialChannelMode_RGB,
116 eMaterialChannelMode_A,
117 eMaterialChannelMode_Z,
118 eMaterialChannelMode_LastEnum,
125 class cRenderSettings;
126 class cTextureManager;
128 class cGpuProgramManager;
144 if (mbSetUpDone ==
false) {
145 mpLowGfx = apLowLevelGraphics;
151 virtual void Bind() = 0;
152 virtual void UnBind() = 0;
154 bool CreateFromFile(
const tString &asFile,
const tString &asEntry) {
return false; }
155 bool SetFloat(
const tString &asName,
float afX) {
return false; }
157 bool SetVec2f(
const tString &asName,
float afX,
float afY) {
return false; }
158 bool SetVec3f(
const tString &asName,
float afX,
float afY,
float afZ) {
return false; }
159 bool SetVec4f(
const tString &asName,
float afX,
float afY,
float afZ,
float afW) {
return false; }
160 bool SetMatrixf(
const tString &asName,
const cMatrixf &mMtx) {
return false; }
161 bool SetMatrixf(
const tString &asName, eGpuProgramMatrix mType, eGpuProgramMatrixOp mOp) {
return false; }
162 bool SetTexture(
const tString &asName,
iTexture *apTexture,
bool abAutoDisable =
true) {
return false; }
163 bool SetTextureToUnit(
int alUnit,
iTexture *apTexture) {
return false; }
165 eGpuProgramType GetType() {
return eGpuProgramType_LastEnum; }
176 virtual void InitData() = 0;
192 cTextureType(
tString asSuffix, eMaterialTexture aType) : msSuffix(asSuffix), mType(aType) {}
195 eMaterialTexture mType;
208 eMaterialPicture aPicture,
cRenderer3D *apRenderer3D);
216 virtual void Compile() = 0;
218 virtual void Update(
float afTimeStep) {}
221 virtual iGpuProgram *getGpuProgram(
const eMaterialRenderType aType,
const int alPass,
iLight3D *apLight) {
return nullptr; }
224 virtual iGpuProgram *GetVertexProgram(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return NULL; }
225 virtual bool VertexProgramUsesLight(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return false; }
226 virtual bool VertexProgramUsesEye(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return false; }
229 virtual iGpuProgram *GetFragmentProgram(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return NULL; }
232 virtual eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return eMaterialAlphaMode_Solid; }
233 virtual eMaterialBlendMode GetBlendMode(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return eMaterialBlendMode_Replace; }
234 virtual eMaterialChannelMode GetChannelMode(eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return eMaterialChannelMode_RGBA; }
236 virtual iTexture *GetTexture(
int alUnit, eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return NULL; }
237 virtual eMaterialBlendMode GetTextureBlend(
int alUnit, eMaterialRenderType aType,
int alPass,
iLight3D *apLight) {
return eMaterialBlendMode_None; }
239 virtual int GetNumOfPasses(eMaterialRenderType aType,
iLight3D *apLight) {
return 0; }
241 virtual bool UsesType(eMaterialRenderType aType) {
return false; }
243 bool HasAlpha() {
return mbHasAlpha; }
244 void SetHasAlpha(
bool abX) { mbHasAlpha = abX; }
246 bool GetDepthTest() {
return mbDepthTest; }
247 void SetDepthTest(
bool abX) { mbDepthTest = abX; }
249 float GetValue() {
return mfValue; }
250 void SetValue(
float afX) { mfValue = afX; }
252 virtual bool LoadData(
TiXmlElement *apRootElem) {
return true; }
261 virtual bool StartRendering(eMaterialRenderType aType,
iCamera *apCam,
iLight *pLight) = 0;
266 virtual void EndRendering(eMaterialRenderType mType) = 0;
272 virtual tVtxBatchFlag GetBatchFlags(eMaterialRenderType mType) = 0;
279 virtual bool NextPass(eMaterialRenderType mType) = 0;
285 virtual bool HasMultiplePasses(eMaterialRenderType mType) = 0;
292 virtual eMaterialType GetType(eMaterialRenderType mType) = 0;
293 virtual void EditVertexes(eMaterialRenderType mType,
iCamera *apCam,
iLight *pLight,
296 iTexture *GetTexture(eMaterialTexture aType);
297 cRect2f GetTextureOffset(eMaterialTexture aType);
299 void SetTexture(
iTexture *apTex, eMaterialTexture aType) { mvTexture[aType] = apTex; }
301 mvImage[aType] = apImg;
303 cResourceImage *GetImage(eMaterialTexture aType) {
return mvImage[aType]; }
305 void SetProgram(
iGpuProgram *apProgram, eGpuProgramType aType,
unsigned int alNum) {
306 mpProgram[aType][alNum] = apProgram;
308 iGpuProgram *GetProgram(eGpuProgramType aType,
unsigned int alNum) {
309 return mpProgram[aType][alNum];
317 virtual bool IsGlowing() {
return mbIsGlowing; }
324 virtual tTextureTypeList GetTextureTypes() {
325 tTextureTypeList vTypes;
334 void SetId(
int alId) { mlId = alId; }
335 int GetId() {
return mlId; }
337 virtual iGpuProgram *getRefractionProgram() {
return nullptr; }
339 virtual bool GetRefractionUsesDiffuse() {
return false; }
340 virtual eMaterialTexture GetRefractionDiffuseTexture() {
return eMaterialTexture_Diffuse; }
342 virtual bool GetRefractionUsesEye() {
return false; }
343 virtual bool GetRefractionUsesTime() {
return false; }
344 virtual bool GetRefractionSkipsStandardTrans() {
return false; }
346 const tString &GetPhysicsMaterial() {
return msPhysicsMaterial; }
347 void SetPhysicsMaterial(
const tString &asName) { msPhysicsMaterial = asName; }
349 static void SetQuality(eMaterialQuality aQuality) { mQuality = aQuality; }
350 static eMaterialQuality GetQuality() {
return mQuality; }
361 static eMaterialQuality mQuality;
363 bool mbIsTransperant;
378 eMaterialPicture mPicture;
393 virtual bool IsCorrect(
tString asName) = 0;
397 eMaterialPicture aPicture,
cRenderer3D *apRenderer3D) = 0;
405 #endif // HPL_MATERIAL_H
void destroy()
Definition: Material.h:169
Definition: Material.h:390
Definition: Renderer3D.h:77
Definition: ResourceBase.h:36
Definition: Light3D.h:117
Definition: Material.h:190
Definition: GpuProgramManager.h:39
iMaterial * * iterator
Definition: array.h:54
Definition: Material.h:181
virtual bool IsTransperant()
Definition: Material.h:316
Definition: ResourceImage.h:43
bool reload()
Definition: Material.h:212
bool reload()
Definition: Material.h:167
Definition: Renderer2D.h:79
Definition: Renderer3D.h:139
Definition: TextureManager.h:47
Definition: Material.h:135
Definition: ImageManager.h:48
Definition: tinyxml.h:864
Definition: list_intern.h:51
void destroy()
Definition: Material.h:214
virtual bool UsesLights()
Definition: Material.h:322
Definition: Material.h:203
void push_back(const t_T &element)
Definition: list.h:140
void SetId(int alId)
Definition: Material.h:334
void unload()
Definition: Material.h:213
Definition: LowLevelGraphics.h:200
Definition: GPUProgram.h:62
void unload()
Definition: Material.h:168