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)
46enum 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
55enum 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
82enum eMaterialPicture {
83 eMaterialPicture_Image,
84 eMaterialPicture_Texture,
85 eMaterialPicture_LastEnum
88enum eMaterialRenderType {
89 eMaterialRenderType_Z,
90 eMaterialRenderType_Light,
91 eMaterialRenderType_Diffuse,
92 eMaterialRenderType_LastEnum
95enum 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
106enum eMaterialAlphaMode {
107 eMaterialAlphaMode_Solid,
108 eMaterialAlphaMode_Trans,
109 eMaterialAlphaMode_LastEnum,
113enum eMaterialChannelMode {
114 eMaterialChannelMode_RGBA,
115 eMaterialChannelMode_RGB,
116 eMaterialChannelMode_A,
117 eMaterialChannelMode_Z,
118 eMaterialChannelMode_LastEnum,
125class cRenderSettings;
126class cTextureManager;
128class cGpuProgramManager;
144 if (mbSetUpDone ==
false) {
145 mpLowGfx = apLowLevelGraphics;
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; }
222 virtual iMaterialProgramSetup *getGpuProgramSetup(
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; }
227 virtual iMaterialProgramSetup *GetVertexProgramSetup(eMaterialRenderType aType,
int alPass, iLight3D *apLight) {
return NULL; }
229 virtual iGpuProgram *GetFragmentProgram(eMaterialRenderType aType,
int alPass, iLight3D *apLight) {
return NULL; }
230 virtual iMaterialProgramSetup *GetFragmentProgramSetup(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; }
279 virtual bool NextPass(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; }
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; }
353 iLowLevelGraphics *mpLowLevelGraphics;
354 cImageManager *mpImageManager;
355 cTextureManager *mpTextureManager;
356 cRenderer2D *mpRenderer;
357 cRenderer3D *mpRenderer3D;
358 cRenderSettings *mpRenderSettings;
359 cGpuProgramManager *mpProgramManager;
361 static eMaterialQuality mQuality;
363 bool mbIsTransperant;
372 tString msPhysicsMaterial;
374 tTextureVec mvTexture;
375 tResourceImageVec mvImage;
378 eMaterialPicture mPicture;
380 iGpuProgram *mpProgram[2][kMaxProgramNum];
393 virtual bool IsCorrect(
tString asName) = 0;
397 eMaterialPicture aPicture,
cRenderer3D *apRenderer3D) = 0;
iMaterial * * iterator
Definition: array.h:54
void push_back(const t_T &element)
Definition: list.h:174
Definition: tinyxml.h:864
Definition: GpuProgramManager.h:39
Definition: ImageManager.h:48
Definition: Renderer3D.h:77
Definition: Renderer2D.h:79
Definition: Renderer3D.h:139
Definition: ResourceImage.h:43
Definition: TextureManager.h:47
Definition: Material.h:190
Definition: Material.h:135
bool reload()
Definition: Material.h:167
void unload()
Definition: Material.h:168
void destroy()
Definition: Material.h:169
Definition: GPUProgram.h:62
Definition: LowLevelGraphics.h:200
Definition: Material.h:203
virtual void EndRendering(eMaterialRenderType mType)=0
virtual bool IsTransperant()
Definition: Material.h:316
bool reload()
Definition: Material.h:212
virtual tVtxBatchFlag GetBatchFlags(eMaterialRenderType mType)=0
virtual bool UsesLights()
Definition: Material.h:322
virtual bool NextPass(eMaterialRenderType mType)=0
virtual bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight)=0
virtual bool HasMultiplePasses(eMaterialRenderType mType)=0
void unload()
Definition: Material.h:213
void SetId(int alId)
Definition: Material.h:334
void destroy()
Definition: Material.h:214
virtual eMaterialType GetType(eMaterialRenderType mType)=0
Definition: Material.h:181
Definition: Material.h:390
Definition: ResourceBase.h:36
Definition: list_intern.h:54