PageRenderTime 60ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/COLLADAStreamWriter/include/COLLADASWRenderState.h

https://bitbucket.org/ZhangJingGuo/opencollada
C Header | 222 lines | 153 code | 32 blank | 37 comment | 0 complexity | 302cf72de7cefbef8369f057a9512372 MD5 | raw file
  1. /*
  2. Copyright (c) 2008-2009 NetAllied Systems GmbH
  3. This file is part of COLLADAStreamWriter.
  4. Licensed under the MIT Open Source License,
  5. for details please see LICENSE file or the website
  6. http://www.opensource.org/licenses/mit-license.php
  7. */
  8. #ifndef __COLLADASTREAMWRITER_RENDER_STATE_H__
  9. #define __COLLADASTREAMWRITER_RENDER_STATE_H__
  10. #include "COLLADASWPrerequisites.h"
  11. #include "COLLADASWStreamWriter.h"
  12. #include "COLLADASWConstants.h"
  13. #include "COLLADABUUtils.h"
  14. namespace COLLADASW
  15. {
  16. /** Declares the storage for the graphical representation of an object. */
  17. class RenderState
  18. {
  19. public:
  20. /** Enumerates the COLLADASW render states for effect passes.
  21. Each state description states the structure allocated in FCollada for this state.
  22. For example, ALPHA_FUNC describes: { FUDaePassStateFunction function = ALWAYS, float alphaComparison = 0.0f }.
  23. This implies a 8-byte structure with
  24. 1) FUDaePassStateFunction::Function at offset 0; it defaults to the ALWAYS enumerated type.
  25. 2) The alpha comparison value at offset 4; it defaults to 0.0f.
  26. All enumerated types are 4 byte in length. */
  27. enum PassState
  28. {
  29. ALPHA_FUNC = 0, /**< { FUDaePassStateFunction function = ALWAYS, float alphaComparison = 0.0f } */
  30. BLEND_FUNC, /**< { FUDaePassStateBlendType sourceBlend = ONE, FUDaePassStateBlendType destinationBlend = ZERO } */
  31. BLEND_FUNC_SEPARATE, /**< { FUDaePassStateBlendType sourceColorBlend = ONE, FUDaePassStateBlendType destinationColorBlend = ZERO, FUDaePassStateBlendType sourceAlphaBlend = ONE, FUDaePassStateBlendType destinationAlphaBlend = ZERO } */
  32. BLEND_EQUATION, /**< { FUDaePassStateBlendEquation blendEquation = ADD } */
  33. BLEND_EQUATION_SEPARATE, /**< { FUDaePassStateBlendEquation colorEquation = ADD, FUDaePassStateBlendEquation alphaEquation = ADD } */
  34. COLOR_MATERIAL, /**< { FUDaePassStateFaceType whichFaces = FRONT_AND_BACK, FUDaePassStateMaterialType material = AMBIENT_AND_DIFFUSE } */
  35. CULL_FACE, /**< { FUDaePassStateFaceType culledFaces = BACK } */
  36. DEPTH_FUNC, /**< { FUDaePassStateFunction depthAcceptFunction = ALWAYS } */
  37. FOG_MODE, /**< { FUDaePassStateFogType fogType = EXP } */
  38. FOG_COORD_SRC, /**< { FUDaePassStateFogCoordinateType type = FOG_COORDINATE } */
  39. FRONT_FACE = 10, /**< { FUDaePassStateFrontFaceType frontFaceSide = COUNTER_CLOCKWISE } */
  40. LIGHT_MODEL_COLOR_CONTROL, /**< { FUDaePassStateLightModelColorControlType controlType = SINGLE_COLOR } */
  41. LOGIC_OP, /**< { FUDaePassStateLogicOperation operation = COPY } */
  42. POLYGON_MODE, /**< { FUDaePassStateFaceType whichFaces = FRONT_AND_BACK, FUDaePassStatePolygonMode renderMode = FILL } */
  43. SHADE_MODEL, /**< { FUDaePassStateShadeModel model = SMOOTH } */
  44. STENCIL_FUNC, /**< { FUDaePassStateFunction acceptFunction = ALWAYS, uint8 referenceValue = 0, uint8 mask = 0xFF } */
  45. STENCIL_OP, /**< { FUDaePassStateStencilOperation failOperation = KEEP, FUDaePassStateStencilOperation depthFailOperation = KEEP, FUDaePassStateStencilOperation depthPassOperation = KEEP } */
  46. STENCIL_FUNC_SEPARATE, /**< { FUDaePassStateFunction frontFacesAcceptFunction = ALWAYS, FUDaePassStateFunction backFacesAcceptFunction = ALWAYS, uint8 referenceValue = 0, uint8 mask = 0xFF } */
  47. STENCIL_OP_SEPARATE, /**< { FUDaePassStateFaceType whichFaces = FRONT_AND_BACK, FUDaePassStateStencilOperation failOperation = KEEP, FUDaePassStateStencilOperation depthFailOperation = KEEP, FUDaePassStateStencilOperation depthPassOperation = KEEP } */
  48. STENCIL_MASK_SEPARATE, /**< { FUDaePassStateFaceType whichFaces = FRONT_AND_BACK, uint8 mask = 0xFF } */
  49. LIGHT_ENABLE = 20, /**< { uint8 lightIndex = 0, bool enabled = false } */
  50. LIGHT_AMBIENT, /**< { uint8 lightIndex = 0, FMVector4 ambientColor = [0,0,0,1] } */
  51. LIGHT_DIFFUSE, /**< { uint8 lightIndex = 0, FMVector4 diffuseColor = [0,0,0,0] } */
  52. LIGHT_SPECULAR, /**< { uint8 lightIndex = 0, FMVector4 specularColor = [0,0,0,0] } */
  53. LIGHT_POSITION, /**< { uint8 lightIndex = 0, FMVector4 position = [0,0,1,0] } */
  54. LIGHT_CONSTANT_ATTENUATION, /**< { uint8 lightIndex = 0, float constantAttenuation = 1.0f } */
  55. LIGHT_LINEAR_ATTENUATION, /**< { uint8 lightIndex = 0, float linearAttenuation = 0.0f } */
  56. LIGHT_QUADRATIC_ATTENUATION, /**< { uint8 lightIndex = 0, float quadraticAttenuation = 0.0f } */
  57. LIGHT_SPOT_CUTOFF, /**< { uint8 lightIndex = 0, float cutoff = 180.0f } */
  58. LIGHT_SPOT_DIRECTION, /**< { uint8 lightIndex = 0, FMVector4 direction = [0,0,-1] } */
  59. LIGHT_SPOT_EXPONENT = 30, /**< { uint8 lightIndex = 0, float exponent = 0.0f } */
  60. TEXTURE1D = 31, /**< { uint8 textureIndex = 0, uint32 textureId = 0 } */
  61. TEXTURE2D, /**< { uint8 textureIndex = 0, uint32 textureId = 0 } */
  62. TEXTURE3D, /**< { uint8 textureIndex = 0, uint32 textureId = 0 } */
  63. TEXTURECUBE, /**< { uint8 textureIndex = 0, uint32 textureId = 0 } */
  64. TEXTURERECT, /**< { uint8 textureIndex = 0, uint32 textureId = 0 } */
  65. TEXTUREDEPTH, /**< { uint8 textureIndex = 0, uint32 textureId = 0 } */
  66. TEXTURE1D_ENABLE, /**< { uint8 textureIndex = 0, bool enabled = false } */
  67. TEXTURE2D_ENABLE, /**< { uint8 textureIndex = 0, bool enabled = false } */
  68. TEXTURE3D_ENABLE, /**< { uint8 textureIndex = 0, bool enabled = false } */
  69. TEXTURECUBE_ENABLE, /**< { uint8 textureIndex = 0, bool enabled = false } */
  70. TEXTURERECT_ENABLE, /**< { uint8 textureIndex = 0, bool enabled = false } */
  71. TEXTUREDEPTH_ENABLE, /**< { uint8 textureIndex = 0, bool enabled = false } */
  72. TEXTURE_ENV_COLOR, /**< { uint8 textureIndex = 0, FMVector4 environmentColor = [0,0,0,0] } */
  73. TEXTURE_ENV_MODE, /**< { uint8 textureIndex = 0, char environmentMode[255] = "" } */
  74. CLIP_PLANE = 45, /**< { uint8 planeIndex = 0, FMVector4 planeValue = [0,0,0,0] } */
  75. CLIP_PLANE_ENABLE, /**< { uint8 planeIndex = 0, bool enabled = false } */
  76. BLEND_COLOR, /**< { FMVector4 blendColor = [0,0,0,0] } */
  77. CLEAR_COLOR, /**< { FMVector4 clearColor = [0,0,0,0] } */
  78. CLEAR_STENCIL, /**< { uint32 clearStencilValue = 0 } */
  79. CLEAR_DEPTH, /**< { float clearDepthValue = 1.0f } */
  80. COLOR_MASK, /**< { bool redWriteMask = true, bool greenWriteMask = true, bool blueWriteMask = true, bool alphaWriteMask = true } */
  81. DEPTH_BOUNDS, /**< { FMVector2 depthBounds = [0,1] } */
  82. DEPTH_MASK, /**< { bool depthWriteMask = true } */
  83. DEPTH_RANGE, /**< { float minimumDepthValue = 0.0f, float maximumDepthValue = 1.0f } */
  84. FOG_DENSITY = 55, /**< { float fogDensity = 1.0f } */
  85. FOG_START, /**< { float fogStartDepthValue = 0.0f } */
  86. FOG_END, /**< { float fogEndDepthValue = 1.0f } */
  87. FOG_COLOR, /**< { FMVector4 fogColor = [0,0,0,0] } */
  88. LIGHT_MODEL_AMBIENT, /**< { FMVector4 ambientColor = [0.2,0.2,0.2,1] } */
  89. LIGHTING_ENABLE, /**< { bool enabled = false } */
  90. LINE_STIPPLE, /**< { uint16 lineStippleStart = 1, uint16 lineStippleEnd = 0xFF } */
  91. LINE_WIDTH, /**< { float lineWidth = 1.0f } */
  92. MATERIAL_AMBIENT = 63, /**< { FMVector4 ambientColor = [0.2,0.2,0.2,1] } */
  93. MATERIAL_DIFFUSE, /**< { FMVector4 diffuseColor = [0.8,0.8,0.8,1] } */
  94. MATERIAL_EMISSION, /**< { FMVector4 emissionColor = [0,0,0,1] } */
  95. MATERIAL_SHININESS, /**< { float shininessOrSpecularLevel = 0.0f } */
  96. MATERIAL_SPECULAR, /**< { FMVector4 specularColor = [0,0,0,1] } */
  97. MODEL_VIEW_MATRIX, /**< { FMMatrix44 modelViewMatrix = FMMatrix44::Identity } */
  98. POINT_DISTANCE_ATTENUATION, /**< { FMVector3 attenuation = [1,0,0] } */
  99. POINT_FADE_THRESHOLD_SIZE, /**< { float threshold = 1.0f } */
  100. POINT_SIZE, /**< { float size = 1.0f } */
  101. POINT_SIZE_MIN, /**< { float minimum = 0.0f } */
  102. POINT_SIZE_MAX, /**< { float maximum = 1.0f } */
  103. POLYGON_OFFSET = 74, /**< { float factor = 0.0f, float units = 0.0f } */
  104. PROJECTION_MATRIX, /**< { FMMatrix44 projectionMatrix = FMMatrix44::Identity } */
  105. SCISSOR, /**< { FMVector4 scissor = [0,0,0,0] } */
  106. STENCIL_MASK, /**< { uint32 mask = 0xFFFFFFFF } */
  107. ALPHA_TEST_ENABLE, /**< { bool enabled = false } */
  108. AUTO_NORMAL_ENABLE, /**< { bool enabled = false } */
  109. BLEND_ENABLE, /**< { bool enabled = false } */
  110. COLOR_LOGIC_OP_ENABLE, /**< { bool enabled = false } */
  111. COLOR_MATERIAL_ENABLE, /**< { bool enabled = true } */
  112. CULL_FACE_ENABLE, /**< { bool enabled = false } */
  113. DEPTH_BOUNDS_ENABLE = 84, /**< { bool enabled = false } */
  114. DEPTH_CLAMP_ENABLE, /**< { bool enabled = false } */
  115. DEPTH_TEST_ENABLE, /**< { bool enabled = false } */
  116. DITHER_ENABLE, /**< { bool enabled = false } */
  117. FOG_ENABLE, /**< { bool enabled = false } */
  118. LIGHT_MODEL_LOCAL_VIEWER_ENABLE, /**< { bool enabled = false } */
  119. LIGHT_MODEL_TWO_SIDE_ENABLE, /**< { bool enabled = false } */
  120. LINE_SMOOTH_ENABLE, /**< { bool enabled = false } */
  121. LINE_STIPPLE_ENABLE, /**< { bool enabled = false } */
  122. LOGIC_OP_ENABLE, /**< { bool enabled = false } */
  123. MULTISAMPLE_ENABLE, /**< { bool enabled = false } */
  124. NORMALIZE_ENABLE = 95, /**< { bool enabled = false } */
  125. POINT_SMOOTH_ENABLE, /**< { bool enabled = false } */
  126. POLYGON_OFFSET_FILL_ENABLE, /**< { bool enabled = false } */
  127. POLYGON_OFFSET_LINE_ENABLE, /**< { bool enabled = false } */
  128. POLYGON_OFFSET_POINT_ENABLE, /**< { bool enabled = false } */
  129. POLYGON_SMOOTH_ENABLE, /**< { bool enabled = false } */
  130. POLYGON_STIPPLE_ENABLE, /**< { bool enabled = false } */
  131. RESCALE_NORMAL_ENABLE, /**< { bool enabled = false } */
  132. SAMPLE_ALPHA_TO_COVERAGE_ENABLE = 103, /**< { bool enabled = false } */
  133. SAMPLE_ALPHA_TO_ONE_ENABLE, /**< { bool enabled = false } */
  134. SAMPLE_COVERAGE_ENABLE, /**< { bool enabled = false } */
  135. SCISSOR_TEST_ENABLE, /**< { bool enabled = false } */
  136. STENCIL_TEST_ENABLE, /**< { bool enabled = false } */
  137. COUNT = 108, /**< The number of supported render states. */
  138. PASS_STATE_INVALID /**< An invalid render state. */
  139. };
  140. /** Enumerates the COLLADASW render state function types.
  141. The usage of this enumeration type depends on the render state.
  142. For the alpha-test and the depth-test, this function determines
  143. when a given pixel will be kept when compared against the
  144. color/depth buffer's current alpha/depth value. */
  145. enum PassStateFunction
  146. {
  147. PASS_STATE_FN_NEVER = 0x0200, /**< Never kept. */
  148. PASS_STATE_FN_LESS = 0x0201, /**< The pixel is kept when its value is lesser to the current value. */
  149. PASS_STATE_FN_EQUAL = 0x0202, /**< The pixel is kept when its value is equal to the current value. */
  150. PASS_STATE_FN_LESS_EQUAL = 0x0203, /**< The pixel is kept when its value is lesser or equal to the current value. */
  151. PASS_STATE_FN_GREATER = 0x0204, /**< The pixel is kept when its value is greater to the current value. */
  152. PASS_STATE_FN_NOT_EQUAL = 0x0205, /**< The pixel is kept when its value is not equal to the current value. */
  153. PASS_STATE_FN_GREATER_EQUAL = 0x0206, /**< The pixel is kept when its value is greater or equal to the current value. */
  154. PASS_STATE_FN_ALWAYS = 0x0207, /** Always kept. */
  155. PASS_STATE_FN_INVALID /**< An invalid function. */
  156. };
  157. public:
  158. /** The render states for effect passes. */
  159. static const String CG_RENDER_STATE_NAMES[];
  160. static const PassState CG_RENDER_STATES_XREF[];
  161. public:
  162. /** Constructor. */
  163. RenderState () {}
  164. /** Destructor. */
  165. ~RenderState () {}
  166. /** Returns the enumeration type of the current CG state. */
  167. static const PassState getRenderStateFromCgName ( const char* cgName );
  168. /** Returns the collada name of the current CG state. */
  169. static const String getCgRenderStateName ( const PassState& state );
  170. /** Returns the render state count. */
  171. static size_t getTotalRenderStateCount();
  172. /** Converts the render state enumeration type to its COLLADASW render state name string.
  173. @param state The render state enumeration type.
  174. @return The render state name string. */
  175. static const String& getColladaRenderStateName ( const PassState& state );
  176. /** Converts the COLLADASW render state function string to the render state function type.
  177. @param value The render state function string.
  178. @return The render state function type. */
  179. static const PassStateFunction getPassStateFunction ( const char* val );
  180. inline const PassStateFunction getPassStateFunction ( const String& value )
  181. { return getPassStateFunction ( value.c_str() ); } /**< See above. */
  182. /** Converts the render state function type to its COLLADASW render state function string.
  183. @param fn The render state function type.
  184. @return The render state function string. */
  185. static const String& getColladaPassStateString ( const PassStateFunction& fn );
  186. };
  187. }
  188. #endif // __COLLADASTREAMWRITER_RENDER_STATE_H__