CmD3D9HLSLProgram.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __D3D9HLSLProgram_H__
  25. #define __D3D9HLSLProgram_H__
  26. #include "CmD3D9Prerequisites.h"
  27. #include "CmHighLevelGpuProgram.h"
  28. namespace CamelotEngine {
  29. /** Specialisation of HighLevelGpuProgram to provide support for D3D9
  30. High-Level Shader Language (HLSL).
  31. @remarks
  32. Note that the syntax of D3D9 HLSL is identical to nVidia's Cg language, therefore
  33. unless you know you will only ever be deploying on Direct3D, or you have some specific
  34. reason for not wanting to use the Cg plugin, I suggest you use Cg instead since that
  35. can produce programs for OpenGL too.
  36. */
  37. class _OgreD3D9Export D3D9HLSLProgram : public HighLevelGpuProgram
  38. {
  39. protected:
  40. /** Internal load implementation, must be implemented by subclasses.
  41. */
  42. void loadFromSource(void);
  43. /** Internal method for creating an appropriate low-level program from this
  44. high-level program, must be implemented by subclasses. */
  45. void createLowLevelImpl(void);
  46. /// Internal unload implementation, must be implemented by subclasses
  47. void unloadHighLevelImpl(void);
  48. /// Populate the passed parameters with name->index map, must be overridden
  49. void buildConstantDefinitions() const;
  50. // Recursive utility method for buildParamNameMap
  51. void processParamElement(D3DXHANDLE parent, String prefix, unsigned int index) const;
  52. void populateDef(D3DXCONSTANT_DESC& d3dDesc, GpuConstantDefinition& def) const;
  53. String mPreprocessorDefines;
  54. bool mColumnMajorMatrices;
  55. LPD3DXBUFFER mpMicroCode;
  56. LPD3DXCONSTANTTABLE mpConstTable;
  57. public:
  58. LPD3DXBUFFER getMicroCode();
  59. public:
  60. /// Shader optimisation level
  61. enum OptimisationLevel
  62. {
  63. /// default - no optimisation in debug mode, OPT_1 in release mode
  64. OPT_DEFAULT,
  65. /// No optimisation
  66. OPT_NONE,
  67. /// Optimisation level 0
  68. OPT_0,
  69. /// Optimisation level 1
  70. OPT_1,
  71. /// Optimisation level 2
  72. OPT_2,
  73. /// Optimisation level 3
  74. OPT_3
  75. };
  76. protected:
  77. OptimisationLevel mOptimisationLevel;
  78. public:
  79. D3D9HLSLProgram();
  80. ~D3D9HLSLProgram();
  81. /** Sets the entry point for this program ie the first method called. */
  82. void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
  83. /** Gets the entry point defined for this program. */
  84. const String& getEntryPoint(void) const { return mEntryPoint; }
  85. /** Sets the shader target to compile down to, e.g. 'vs_1_1'. */
  86. void setTarget(const String& target);
  87. /** Gets the shader target to compile down to, e.g. 'vs_1_1'. */
  88. const String getTarget(void) const;
  89. /** Sets the preprocessor defines use to compile the program. */
  90. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  91. /** Sets the preprocessor defines use to compile the program. */
  92. const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
  93. /** Sets whether matrix packing in column-major order. */
  94. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  95. /** Gets whether matrix packed in column-major order. */
  96. bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
  97. /** Sets the optimisation level to use.
  98. @param opt Optimisation level
  99. */
  100. void setOptimisationLevel(OptimisationLevel opt) { mOptimisationLevel = opt; }
  101. /** Gets the optimisation level to use. */
  102. OptimisationLevel getOptimisationLevel() const { return mOptimisationLevel; }
  103. /// Overridden from GpuProgram
  104. bool isSupported(void) const;
  105. /// Overridden from GpuProgram
  106. GpuProgramParametersSharedPtr createParameters(void);
  107. /// Overridden from GpuProgram
  108. const String& getLanguage(void) const;
  109. };
  110. }
  111. #endif