BsD3D9GpuProgram.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsGpuProgram.h"
  4. #include "BsD3D9Resource.h"
  5. namespace BansheeEngine
  6. {
  7. enum OptimizationLevel
  8. {
  9. OPT_DEFAULT,
  10. OPT_NONE,
  11. OPT_0,
  12. OPT_1,
  13. OPT_2,
  14. OPT_3
  15. };
  16. /** Direct3D implementation of a few things common to low-level vertex & fragment programs. */
  17. class BS_D3D9_EXPORT D3D9GpuProgram : public GpuProgram, public D3D9Resource
  18. {
  19. public:
  20. ~D3D9GpuProgram();
  21. /** Sets the preprocessor defines use to compile the program. */
  22. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  23. /** Sets the preprocessor defines use to compile the program. */
  24. const String& getPreprocessorDefines() const { return mPreprocessorDefines; }
  25. /** Sets whether matrix packing in column-major order. */
  26. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  27. /** Gets whether matrix packed in column-major order. */
  28. bool getColumnMajorMatrices() const { return mColumnMajorMatrices; }
  29. /** Sets the optimisation level to use.
  30. @param opt Optimisation level
  31. */
  32. void setOptimizationLevel(OptimizationLevel opt) { mOptimisationLevel = opt; }
  33. /** Gets the optimisation level to use. */
  34. OptimizationLevel getOptimizationLevel() const { return mOptimisationLevel; }
  35. /// Overridden from GpuProgram
  36. GpuParamsPtr createParameters();
  37. /// Overridden from GpuProgram
  38. const String& getLanguage() const;
  39. protected:
  40. friend class D3D9HLSLProgramFactory;
  41. D3D9GpuProgram(const String& source, const String& entryPoint,
  42. GpuProgramType gptype, GpuProgramProfile profile,
  43. const Vector<HGpuProgInclude>* includes);
  44. void createInternalResources(IDirect3DDevice9* d3d9Device);
  45. /**
  46. * @copydoc GpuProgram::initialize_internal().
  47. */
  48. void initialize_internal();
  49. /**
  50. * @copydoc GpuProgram::destroy_internal().
  51. */
  52. void destroy_internal();
  53. /** Loads this program from microcode, must be overridden by subclasses. */
  54. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  55. protected:
  56. OptimizationLevel mOptimisationLevel;
  57. String mPreprocessorDefines;
  58. bool mColumnMajorMatrices;
  59. ID3DXBuffer* mMicrocode;
  60. /************************************************************************/
  61. /* SERIALIZATION */
  62. /************************************************************************/
  63. public:
  64. friend class D3D9GpuProgramRTTI;
  65. static RTTITypeBase* getRTTIStatic();
  66. virtual RTTITypeBase* getRTTI() const;
  67. };
  68. /** Direct3D implementation of low-level vertex programs. */
  69. class BS_D3D9_EXPORT D3D9GpuVertexProgram : public D3D9GpuProgram
  70. {
  71. public:
  72. ~D3D9GpuVertexProgram();
  73. /// Gets the vertex shader
  74. IDirect3DVertexShader9* getVertexShader();
  75. // Called immediately after the Direct3D device has been created.
  76. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  77. // Called before the Direct3D device is going to be destroyed.
  78. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  79. protected:
  80. friend class D3D9HLSLProgramFactory;
  81. D3D9GpuVertexProgram(const String& source, const String& entryPoint, GpuProgramProfile profile,
  82. const Vector<HGpuProgInclude>* includes);
  83. /**
  84. * @copydoc D3D9GpuProgram::destroy_internal.
  85. */
  86. void destroy_internal();
  87. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  88. protected:
  89. typedef Map<IDirect3DDevice9*, IDirect3DVertexShader9*> DeviceToVertexShaderMap;
  90. typedef DeviceToVertexShaderMap::iterator DeviceToVertexShaderIterator;
  91. DeviceToVertexShaderMap mMapDeviceToVertexShader;
  92. /************************************************************************/
  93. /* SERIALIZATION */
  94. /************************************************************************/
  95. public:
  96. friend class D3D9GpuVertexProgramRTTI;
  97. static RTTITypeBase* getRTTIStatic();
  98. virtual RTTITypeBase* getRTTI() const;
  99. };
  100. /** Direct3D implementation of low-level fragment programs. */
  101. class BS_D3D9_EXPORT D3D9GpuFragmentProgram : public D3D9GpuProgram
  102. {
  103. public:
  104. ~D3D9GpuFragmentProgram();
  105. /// Gets the pixel shader
  106. IDirect3DPixelShader9* getPixelShader();
  107. // Called immediately after the Direct3D device has been created.
  108. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  109. // Called before the Direct3D device is going to be destroyed.
  110. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  111. protected:
  112. friend class D3D9HLSLProgramFactory;
  113. D3D9GpuFragmentProgram(const String& source, const String& entryPoint, GpuProgramProfile profile,
  114. const Vector<HGpuProgInclude>* includes);
  115. /**
  116. * @copydoc D3D9GpuProgram::destroy_internal.
  117. */
  118. void destroy_internal();
  119. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  120. protected:
  121. typedef Map<IDirect3DDevice9*, IDirect3DPixelShader9*> DeviceToPixelShaderMap;
  122. typedef DeviceToPixelShaderMap::iterator DeviceToPixelShaderIterator;
  123. DeviceToPixelShaderMap mMapDeviceToPixelShader;
  124. /************************************************************************/
  125. /* SERIALIZATION */
  126. /************************************************************************/
  127. public:
  128. friend class D3D9GpuFragmentProgramRTTI;
  129. static RTTITypeBase* getRTTIStatic();
  130. virtual RTTITypeBase* getRTTI() const;
  131. };
  132. typedef std::shared_ptr<D3D9GpuProgram> D3D9GpuProgramPtr;
  133. }