BsD3D9GpuProgram.h 5.7 KB

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