Shader.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #ifndef SE_INCL_SHADER_H
  13. #define SE_INCL_SHADER_H
  14. #ifdef PRAGMA_ONCE
  15. #pragma once
  16. #endif
  17. #include <Engine/Base/CTString.h>
  18. #include <Engine/Base/Serial.h>
  19. #include <Engine/Math/Vector.h>
  20. #include <Engine/Graphics/Color.h>
  21. #include <Engine/Graphics/GfxLibrary.h>
  22. // Shader flags
  23. #define BASE_DOUBLE_SIDED (1UL<<0) // Double sided
  24. #define BASE_FULL_BRIGHT (1UL<<1) // Full bright
  25. struct ShaderDesc
  26. {
  27. CStaticArray<class CTString> sd_astrTextureNames;
  28. CStaticArray<class CTString> sd_astrTexCoordNames;
  29. CStaticArray<class CTString> sd_astrColorNames;
  30. CStaticArray<class CTString> sd_astrFloatNames;
  31. CStaticArray<class CTString> sd_astrFlagNames;
  32. CTString sd_strShaderInfo;
  33. };
  34. struct ShaderParams
  35. {
  36. ShaderParams() {
  37. sp_ulFlags = 0;
  38. }
  39. ~ShaderParams() {
  40. sp_aiTextureIDs.Clear();
  41. sp_aiTexCoordsIndex.Clear();
  42. sp_acolColors.Clear();
  43. sp_afFloats.Clear();
  44. }
  45. CStaticArray<INDEX> sp_aiTextureIDs;
  46. CStaticArray<INDEX> sp_aiTexCoordsIndex;
  47. CStaticArray<COLOR> sp_acolColors;
  48. CStaticArray<FLOAT> sp_afFloats;
  49. ULONG sp_ulFlags;
  50. };
  51. class ENGINE_API CShader : public CSerial
  52. {
  53. public:
  54. CShader();
  55. ~CShader();
  56. HINSTANCE hLibrary;
  57. void (*ShaderFunc)(void);
  58. void (*GetShaderDesc)(ShaderDesc &shDesc);
  59. void Read_t( CTStream *istrFile); // throw char *
  60. void Write_t( CTStream *ostrFile); // throw char *
  61. void Clear(void);
  62. SLONG GetUsedMemory(void);
  63. };
  64. // Begin shader using
  65. ENGINE_API void shaBegin(CAnyProjection3D &aprProjection,CShader *pShader);
  66. // End shader using
  67. ENGINE_API void shaEnd(void);
  68. // Render given model
  69. ENGINE_API void shaRender(void);
  70. // Render aditional pass for fog and haze
  71. ENGINE_API void shaDoFogPass(void);
  72. // Modify color for fog
  73. ENGINE_API void shaModifyColorForFog(void);
  74. // Calculate lightning for given model
  75. ENGINE_API void shaCalculateLight(void);
  76. // Calculate lightning for given model (for specular shader)
  77. ENGINE_API void shaCalculateLightForSpecular(void);
  78. // Clear temp vars used by shader
  79. ENGINE_API void shaClean(void);
  80. // Set array of vertices
  81. ENGINE_API void shaSetVertexArray(GFXVertex4 *paVertices,INDEX ctVertices);
  82. // Set array of normals
  83. ENGINE_API void shaSetNormalArray(GFXNormal *paNormals);
  84. // Set array of indices
  85. ENGINE_API void shaSetIndices(INDEX *paIndices, INDEX ctIndices);
  86. // Set array of texture objects for shader
  87. ENGINE_API void shaSetTextureArray(CTextureObject **paTextureObject, INDEX ctTextures);
  88. // Set array of uv maps
  89. ENGINE_API void shaSetUVMapsArray(GFXTexCoord **paUVMaps, INDEX ctUVMaps);
  90. // Set array of shader colors
  91. ENGINE_API void shaSetColorArray(COLOR *paColors, INDEX ctColors);
  92. // Set array of floats for shader
  93. ENGINE_API void shaSetFloatArray(FLOAT *paFloats, INDEX ctFloats);
  94. // Set shading flags
  95. ENGINE_API void shaSetFlags(ULONG ulFlags);
  96. // Set base color of model
  97. ENGINE_API void shaSetModelColor(COLOR &colModel);
  98. // Set light direction
  99. ENGINE_API void shaSetLightDirection(const FLOAT3D &vLightDir);
  100. // Set light color
  101. ENGINE_API void shaSetLightColor(COLOR colAmbient, COLOR colLight);
  102. // Set object to view matrix
  103. ENGINE_API void shaSetObjToViewMatrix(Matrix12 &mat);
  104. // Set object to abs matrix
  105. ENGINE_API void shaSetObjToAbsMatrix(Matrix12 &mat);
  106. // Set current texture index
  107. ENGINE_API void shaSetTexture(INDEX iTexture);
  108. // Set current uvmap index
  109. ENGINE_API void shaSetUVMap(INDEX iUVMap);
  110. // Set current color index
  111. ENGINE_API void shaSetColor(INDEX icolIndex);
  112. // Set array of texcoords index
  113. ENGINE_API void shaSetTexCoords(GFXTexCoord *uvNewMap);
  114. // Set array of vertex colors
  115. ENGINE_API void shaSetVertexColors(GFXColor *paColors);
  116. // Set constant color
  117. ENGINE_API void shaSetConstantColor(const COLOR colConstant);
  118. // Get vertex count
  119. ENGINE_API INDEX shaGetVertexCount(void);
  120. // Get index count
  121. ENGINE_API INDEX shaGetIndexCount(void);
  122. // Get float from array of floats
  123. ENGINE_API FLOAT shaGetFloat(INDEX iFloatIndex);
  124. // Get texture from array of textures
  125. ENGINE_API CTextureObject *shaGetTexture( INDEX iTextureIndex);
  126. // Get base color from array of colors
  127. ENGINE_API COLOR &shaGetColor(INDEX iColorIndex);
  128. // Get shading flags
  129. ENGINE_API ULONG &shaGetFlags();
  130. // Get base color of model
  131. ENGINE_API COLOR &shaGetModelColor(void);
  132. // Get light direction
  133. ENGINE_API FLOAT3D &shaGetLightDirection(void);
  134. // Get current light color
  135. ENGINE_API COLOR &shaGetLightColor(void);
  136. // Get current ambient volor
  137. ENGINE_API COLOR &shaGetAmbientColor(void);
  138. // Get current set color
  139. ENGINE_API COLOR &shaGetCurrentColor(void);
  140. // Get vertex array
  141. ENGINE_API GFXVertex4 *shaGetVertexArray(void);
  142. // Get index array
  143. ENGINE_API INDEX *shaGetIndexArray(void);
  144. // Get normal array
  145. ENGINE_API GFXNormal *shaGetNormalArray(void);
  146. // Get uvmap array from array of uvmaps
  147. ENGINE_API GFXTexCoord *shaGetUVMap( INDEX iUVMapIndex);
  148. // Get color array
  149. ENGINE_API GFXColor *shaGetColorArray(void);
  150. // Get empty color array for modifying
  151. ENGINE_API GFXColor *shaGetNewColorArray(void);
  152. // Get empty texcoords array for modifying
  153. ENGINE_API GFXTexCoord *shaGetNewTexCoordArray(void);
  154. // Get empty v array for modifying
  155. ENGINE_API GFXVertex *shaGetNewVertexArray(void);
  156. // Get current projection
  157. ENGINE_API CAnyProjection3D *shaGetProjection(void);
  158. // Get object to view matrix
  159. ENGINE_API Matrix12 *shaGetObjToViewMatrix(void);
  160. // Get object to abs matrix
  161. ENGINE_API Matrix12 *shaGetObjToAbsMatrix(void);
  162. // Set face culling
  163. ENGINE_API void shaCullFace(GfxFace eFace);
  164. // Set blending operations
  165. ENGINE_API void shaBlendFunc(GfxBlend eSrc, GfxBlend eDst);
  166. // Set texture modulation mode
  167. ENGINE_API void shaSetTextureModulation(INDEX iScale);
  168. // Enable/Disable blening
  169. ENGINE_API void shaEnableBlend(void);
  170. ENGINE_API void shaDisableBlend(void);
  171. // Enable/Disable alpha test
  172. ENGINE_API void shaEnableAlphaTest(void);
  173. ENGINE_API void shaDisableAlphaTest(void);
  174. // Enable/Disable depth test
  175. ENGINE_API void shaEnableDepthTest(void);
  176. ENGINE_API void shaDisableDepthTest(void);
  177. // Enable/Disable depth write
  178. ENGINE_API void shaEnableDepthWrite(void);
  179. ENGINE_API void shaDisableDepthWrite(void);
  180. // Set depth buffer compare mode
  181. ENGINE_API void shaDepthFunc(GfxComp eComp);
  182. // Set texture wrapping
  183. ENGINE_API void shaSetTextureWrapping( enum GfxWrap eWrapU, enum GfxWrap eWrapV);
  184. // Set uvmap for fog
  185. ENGINE_API void shaSetFogUVMap(GFXTexCoord *paFogUVMap);
  186. // Set uvmap for haze
  187. ENGINE_API void shaSetHazeUVMap(GFXTexCoord *paHazeUVMap);
  188. // Set array of vertex colors used in haze
  189. ENGINE_API void shaSetHazeColorArray(GFXColor *paHazeColors);
  190. // Is overbrightning enabled
  191. ENGINE_API BOOL shaOverBrightningEnabled(void);
  192. #if (defined _MSC_VER)
  193. #define DECLSPEC_DLLEXPORT _declspec (dllexport)
  194. #else
  195. #define DECLSPEC_DLLEXPORT
  196. #endif
  197. #define SHADER_MAIN(name) \
  198. extern "C" void DECLSPEC_DLLEXPORT Shader_##name (void);\
  199. SYMBOLLOCATOR(Shader_##name);\
  200. extern "C" void DECLSPEC_DLLEXPORT Shader_##name (void)
  201. #define SHADER_DESC(name,x) \
  202. extern "C" void DECLSPEC_DLLEXPORT Shader_Desc_##name (x);\
  203. SYMBOLLOCATOR(Shader_Desc_##name);\
  204. extern "C" void DECLSPEC_DLLEXPORT Shader_Desc_##name (x)
  205. #endif /* include-once check. */