BsD3D9GpuProgram.h 3.5 KB

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