BsD3D9GpuProgram.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsGpuProgram.h"
  4. #include "BsD3D9Resource.h"
  5. #include "BsD3D9EmulatedParamBlocks.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Available optimization levels when compiling a GPU program.
  10. */
  11. enum OptimizationLevel
  12. {
  13. OPT_DEFAULT,
  14. OPT_NONE,
  15. OPT_0,
  16. OPT_1,
  17. OPT_2,
  18. OPT_3
  19. };
  20. /**
  21. * @brief DirectX 9 implementation of a GPU program.
  22. */
  23. class BS_D3D9_EXPORT D3D9GpuProgramCore : public GpuProgramCore, public D3D9Resource
  24. {
  25. public:
  26. virtual ~D3D9GpuProgramCore();
  27. /**
  28. * @brief Sets the preprocessor defines use to compile the program.
  29. */
  30. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  31. /**
  32. * @brief Sets optimization level to use when compiling the shader.
  33. */
  34. void setOptimizationLevel(OptimizationLevel opt) { mOptimisationLevel = opt; }
  35. /**
  36. * @copydoc GpuProgramCore::hasColumnMajorMatrices
  37. */
  38. bool hasColumnMajorMatrices() const { return mColumnMajorMatrices; }
  39. protected:
  40. friend class D3D9HLSLProgramFactory;
  41. D3D9GpuProgramCore(const String& source, const String& entryPoint,
  42. GpuProgramType gptype, GpuProgramProfile profile);
  43. /**
  44. * @copydoc GpuProgramCore::initialize
  45. */
  46. void initialize();
  47. /**
  48. * @copydoc GpuProgramCore::destroy
  49. */
  50. void destroy();
  51. /**
  52. * @brief Loads the GPU program from compiled microcode.
  53. */
  54. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  55. protected:
  56. OptimizationLevel mOptimisationLevel;
  57. String mPreprocessorDefines;
  58. Vector<D3D9EmulatedParamBlock> mBlocks;
  59. bool mColumnMajorMatrices;
  60. ID3DXBuffer* mMicrocode;
  61. };
  62. /**
  63. * @brief DirectX 9 implementation of a vertex GPU program.
  64. */
  65. class BS_D3D9_EXPORT D3D9GpuVertexProgramCore : public D3D9GpuProgramCore
  66. {
  67. public:
  68. ~D3D9GpuVertexProgramCore();
  69. /**
  70. * @brief Returns internal DX9 vertex shader object.
  71. */
  72. IDirect3DVertexShader9* getVertexShader();
  73. /**
  74. * @copydoc D3D9Resource::notifyOnDeviceCreate
  75. */
  76. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  77. /**
  78. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  79. */
  80. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  81. protected:
  82. friend class D3D9HLSLProgramFactory;
  83. D3D9GpuVertexProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
  84. /**
  85. * @copydoc D3D9GpuProgramCore::destroy.
  86. */
  87. void destroy();
  88. /**
  89. * @copydoc D3D9GpuProgramCore::loadFromMicrocode
  90. */
  91. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  92. protected:
  93. Map<IDirect3DDevice9*, IDirect3DVertexShader9*> mMapDeviceToVertexShader;
  94. };
  95. /** Direct3D implementation of low-level fragment programs. */
  96. class BS_D3D9_EXPORT D3D9GpuFragmentProgramCore : public D3D9GpuProgramCore
  97. {
  98. public:
  99. ~D3D9GpuFragmentProgramCore();
  100. /**
  101. * @brief Returns internal DX9 pixel shader object.
  102. */
  103. IDirect3DPixelShader9* getPixelShader();
  104. /**
  105. * @copydoc D3D9Resource::notifyOnDeviceCreate
  106. */
  107. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  108. /**
  109. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  110. */
  111. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  112. protected:
  113. friend class D3D9HLSLProgramFactory;
  114. D3D9GpuFragmentProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
  115. /**
  116. * @copydoc D3D9GpuProgramCore::destroy
  117. */
  118. void destroy();
  119. /**
  120. * @copydoc D3D9GpuProgramCore::loadFromMicrocode
  121. */
  122. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  123. protected:
  124. Map<IDirect3DDevice9*, IDirect3DPixelShader9*> mMapDeviceToPixelShader;
  125. };
  126. }