00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __RE_OGLMaterial_h__
00021 #define __RE_OGLMaterial_h__
00022
00023 #include "RE_API.h"
00024 #include <UT/UT_RefCount.h>
00025 #include <UT/UT_String.h>
00026 #include <UT/UT_Vector3.h>
00027 #include <UT/UT_IntArray.h>
00028 #include <UT/UT_PtrArray.h>
00029 #include <UT/UT_BitArray.h>
00030
00031 class RE_Material;
00032 class RE_OGLRender;
00033 class RE_Texture2DMap;
00034 class RE_Shader;
00035 class TIL_TextureMap;
00036
00037 typedef RE_Texture2DMap *(* RE_MatTexCallback)( void *,float now,int layer);
00038
00039 class RE_API RE_TextureCallback
00040 {
00041 public:
00042
00043 RE_TextureCallback();
00044 virtual ~RE_TextureCallback();
00045
00046 virtual RE_Texture2DMap *createTexture(int layer);
00047 };
00048
00049 class RE_API RE_OGLMaterial : public UT_RefCount
00050 {
00051 public:
00052 RE_OGLMaterial(const char *materialName);
00053
00054 const char *getMaterialName() const { return myMaterialName; }
00055
00056
00057 void clearTextureIndex();
00058 void clearDiffuseMap();
00059
00060 void setDiffuseMap(TIL_TextureMap *map, int clamp = 0,
00061 int layer = 0);
00062 void setDiffuseMap(const char *mapname, const char *relativeTo,
00063 int layer = 0);
00064
00065 int getTextureIndex(int layer=0);
00066
00067 int isTextured() const;
00068 int isTransparent() const { return alpha() < 1.0F; }
00069
00070
00071
00072
00073
00074 void setCallback(RE_TextureCallback *cb);
00075 RE_TextureCallback *getCallback() { return myTexCallback; }
00076
00077
00078 void doLighting( int yes ) { myDoLighting = yes != 0; }
00079 int isLit() const { return myDoLighting; }
00080
00081 RE_Shader *createShader();
00082 RE_Shader *getShader() const;
00083
00084 void doAlphaTest(int yes) { myTestAlpha = yes != 0; }
00085 int testAlpha() const { return myTestAlpha; }
00086
00087
00088 float amb( unsigned idx ) const { return myAtimesD[idx]; }
00089 const float *amb() const { return myAtimesD; }
00090 float diff( unsigned idx ) const { return myDiff[idx]; }
00091 const float *diff() const { return myDiff; }
00092 float spec( unsigned idx ) const { return mySpec[idx]; }
00093 const float *spec() const { return mySpec; }
00094 float emit( unsigned idx ) const { return myEmit[idx]; }
00095 const float *emit() const { return myEmit; }
00096
00097 float alpha() const { return myAmb[3]; }
00098 float shininess() const { return myShininess; }
00099
00100 void setAlpha( float a );
00101
00102
00103 void setRoughness( float r );
00104
00105
00106 void setShininess( float r );
00107
00108 void setAmb( float r, float g, float b );
00109 void setDiff( float r, float g, float b );
00110 void setSpec( float r, float g, float b );
00111 void setEmit( float r, float g, float b );
00112
00113
00114
00115
00116
00117
00118
00119 void forceAmb( float r, float g, float b );
00120 float getUnscaledAmbient(unsigned idx) const { return myAmb[idx]; }
00121 const float *getUnscaledAmbient() const { return myAmb; }
00122
00123 virtual void getVexShader(UT_String &str, float now);
00124
00125 #ifdef UT_DEBUG
00126
00127 void output();
00128 #endif
00129
00130 RE_Material *cloneWithoutTexture() const;
00131
00132 protected:
00133 virtual ~RE_OGLMaterial();
00134
00135 void loadShaderAttribNames();
00136
00137
00138 void growLayers(int layer);
00139
00140 private:
00141 RE_TextureCallback *myTexCallback;
00142 float myAmb[4];
00143 float myDiff[4];
00144 float myAtimesD[4];
00145 float mySpec[4];
00146 float myEmit[4];
00147 float myShininess;
00148
00149
00150 UT_PtrArray<RE_Texture2DMap *> myTextureMap;
00151 UT_BitArray myIOwnMap;
00152
00153 UT_String myMaterialName;
00154 unsigned myDoLighting:1,
00155 myTestAlpha:1;
00156
00157 RE_Shader *myShader;
00158 };
00159
00160 #endif