processedFFMaterial.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MATERIALS_PROCESSEDFFMATERIAL_H_
  23. #define _MATERIALS_PROCESSEDFFMATERIAL_H_
  24. #ifndef _MATERIALS_PROCESSEDMATERIAL_H_
  25. #include "materials/processedMaterial.h"
  26. #endif
  27. class LightInfo;
  28. struct GFXShaderConstDesc;
  29. /// Fixed function rendering. Does not load or use shaders. Does not rely on GFXMaterialFeatureData.
  30. /// Tries very hard to not rely on anything possibly related to shaders.
  31. ///
  32. /// @note Does not always succeed.
  33. class ProcessedFFMaterial : public ProcessedMaterial
  34. {
  35. typedef ProcessedMaterial Parent;
  36. public:
  37. ProcessedFFMaterial();
  38. ProcessedFFMaterial(Material &mat, const bool isLightingMaterial = false);
  39. ~ProcessedFFMaterial();
  40. /// @name Render state setting
  41. ///
  42. /// @{
  43. /// Sets necessary textures and texture ops for rendering
  44. virtual void setTextureStages(SceneRenderState *, const SceneData &sgData, U32 pass );
  45. virtual MaterialParameters* allocMaterialParameters();
  46. virtual MaterialParameterHandle* getMaterialParameterHandle(const String& name);
  47. virtual MaterialParameters* getDefaultMaterialParameters();
  48. virtual void setTransforms(const MatrixSet &matrixSet, SceneRenderState *state, const U32 pass);
  49. virtual void setSceneInfo(SceneRenderState *, const SceneData& sgData, U32 pass);
  50. /// @}
  51. virtual bool init( const FeatureSet &features,
  52. const GFXVertexFormat *vertexFormat,
  53. const MatFeaturesDelegate &featuresDelegate );
  54. /// Sets up the given pass
  55. ///
  56. /// @returns false if the pass could not be set up
  57. virtual bool setupPass(SceneRenderState *, const SceneData& sgData, U32 pass);
  58. /// Returns the number of stages we're using (not to be confused with the number of passes)
  59. virtual U32 getNumStages();
  60. protected:
  61. MaterialParameterHandle* mDefaultHandle;
  62. MaterialParameters* mDefaultParameters;
  63. struct FixedFuncFeatureData
  64. {
  65. enum
  66. {
  67. DiffuseMap,
  68. LightMap,
  69. ToneMap,
  70. NumFeatures
  71. };
  72. bool features[NumFeatures];
  73. };
  74. bool mIsLightingMaterial;
  75. Vector<GFXShaderConstDesc> mParamDesc;
  76. /// @name Internal functions
  77. ///
  78. /// @{
  79. /// Adds a pass for the given stage
  80. virtual void _addPass(U32 stageNum, FixedFuncFeatureData& featData);
  81. /// Chooses a blend op for the pass during pass creation
  82. virtual void _setPassBlendOp();
  83. /// Creates all necessary passes for the given stage
  84. void _createPasses( U32 stageNum, const FeatureSet &features );
  85. /// Determine what features we need
  86. void _determineFeatures( U32 stageNum,
  87. FixedFuncFeatureData &featData,
  88. const FeatureSet &features);
  89. /// Sets light info for the first light
  90. virtual void _setPrimaryLightInfo(const MatrixF &objTrans, LightInfo* light, U32 pass);
  91. /// Sets light info for the second light
  92. virtual void _setSecondaryLightInfo(const MatrixF &objTrans, LightInfo* light);
  93. /// Does the base render state block setting, normally per pass
  94. virtual void _initPassStateBlock( RenderPassData *rpd, GFXStateBlockDesc &result );
  95. /// @}
  96. void _construct();
  97. };
  98. #endif