BsD3D9GpuProgram.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. protected:
  36. friend class D3D9HLSLProgramFactory;
  37. D3D9GpuProgramCore(const String& source, const String& entryPoint,
  38. GpuProgramType gptype, GpuProgramProfile profile);
  39. /**
  40. * @copydoc GpuProgramCore::initialize
  41. */
  42. void initialize() override;
  43. /**
  44. * @brief Loads the GPU program from compiled microcode.
  45. */
  46. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  47. protected:
  48. OptimizationLevel mOptimisationLevel;
  49. String mPreprocessorDefines;
  50. Vector<D3D9EmulatedParamBlock> mBlocks;
  51. bool mColumnMajorMatrices;
  52. ID3DXBuffer* mMicrocode;
  53. };
  54. /**
  55. * @brief DirectX 9 implementation of a vertex GPU program.
  56. */
  57. class BS_D3D9_EXPORT D3D9GpuVertexProgramCore : public D3D9GpuProgramCore
  58. {
  59. public:
  60. ~D3D9GpuVertexProgramCore();
  61. /**
  62. * @brief Returns internal DX9 vertex shader object.
  63. */
  64. IDirect3DVertexShader9* getVertexShader();
  65. /**
  66. * @copydoc D3D9Resource::notifyOnDeviceCreate
  67. */
  68. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
  69. /**
  70. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  71. */
  72. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
  73. protected:
  74. friend class D3D9HLSLProgramFactory;
  75. D3D9GpuVertexProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
  76. /**
  77. * @copydoc D3D9GpuProgramCore::loadFromMicrocode
  78. */
  79. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) override;
  80. protected:
  81. Map<IDirect3DDevice9*, IDirect3DVertexShader9*> mMapDeviceToVertexShader;
  82. };
  83. /** Direct3D implementation of low-level fragment programs. */
  84. class BS_D3D9_EXPORT D3D9GpuFragmentProgramCore : public D3D9GpuProgramCore
  85. {
  86. public:
  87. ~D3D9GpuFragmentProgramCore();
  88. /**
  89. * @brief Returns internal DX9 pixel shader object.
  90. */
  91. IDirect3DPixelShader9* getPixelShader();
  92. /**
  93. * @copydoc D3D9Resource::notifyOnDeviceCreate
  94. */
  95. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
  96. /**
  97. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  98. */
  99. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
  100. protected:
  101. friend class D3D9HLSLProgramFactory;
  102. D3D9GpuFragmentProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
  103. /**
  104. * @copydoc D3D9GpuProgramCore::loadFromMicrocode
  105. */
  106. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) override;
  107. protected:
  108. Map<IDirect3DDevice9*, IDirect3DPixelShader9*> mMapDeviceToPixelShader;
  109. };
  110. }