BsD3D9GpuProgram.h 3.8 KB

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