2
0

BsD3D9GpuProgram.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. /** @addtogroup D3D9
  11. * @{
  12. */
  13. /** Available optimization levels when compiling a GPU program. */
  14. enum OptimizationLevel
  15. {
  16. OPT_DEFAULT,
  17. OPT_NONE,
  18. OPT_0,
  19. OPT_1,
  20. OPT_2,
  21. OPT_3
  22. };
  23. /** DirectX 9 implementation of a GPU program. */
  24. class BS_D3D9_EXPORT D3D9GpuProgramCore : public GpuProgramCore, public D3D9Resource
  25. {
  26. public:
  27. virtual ~D3D9GpuProgramCore();
  28. /** Sets the preprocessor defines use to compile the program. */
  29. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  30. /** Sets optimization level to use when compiling the shader. */
  31. void setOptimizationLevel(OptimizationLevel opt) { mOptimisationLevel = opt; }
  32. protected:
  33. friend class D3D9HLSLProgramFactory;
  34. D3D9GpuProgramCore(const String& source, const String& entryPoint,
  35. GpuProgramType gptype, GpuProgramProfile profile);
  36. /** @copydoc GpuProgramCore::initialize */
  37. void initialize() override;
  38. /** Loads the GPU program from compiled microcode. */
  39. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  40. protected:
  41. OptimizationLevel mOptimisationLevel;
  42. String mPreprocessorDefines;
  43. Vector<D3D9EmulatedParamBlock> mBlocks;
  44. bool mColumnMajorMatrices;
  45. ID3DXBuffer* mMicrocode;
  46. };
  47. /** DirectX 9 implementation of a vertex GPU program. */
  48. class BS_D3D9_EXPORT D3D9GpuVertexProgramCore : public D3D9GpuProgramCore
  49. {
  50. public:
  51. ~D3D9GpuVertexProgramCore();
  52. /** Returns internal DX9 vertex shader object. */
  53. IDirect3DVertexShader9* getVertexShader();
  54. /** @copydoc D3D9Resource::notifyOnDeviceCreate */
  55. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
  56. /** @copydoc D3D9Resource::notifyOnDeviceDestroy */
  57. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
  58. protected:
  59. friend class D3D9HLSLProgramFactory;
  60. D3D9GpuVertexProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
  61. /** @copydoc D3D9GpuProgramCore::loadFromMicrocode */
  62. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) override;
  63. protected:
  64. Map<IDirect3DDevice9*, IDirect3DVertexShader9*> mMapDeviceToVertexShader;
  65. };
  66. /** Direct3D implementation of low-level fragment programs. */
  67. class BS_D3D9_EXPORT D3D9GpuFragmentProgramCore : public D3D9GpuProgramCore
  68. {
  69. public:
  70. ~D3D9GpuFragmentProgramCore();
  71. /** Returns internal DX9 pixel shader object. */
  72. IDirect3DPixelShader9* getPixelShader();
  73. /** @copydoc D3D9Resource::notifyOnDeviceCreate */
  74. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
  75. /** @copydoc D3D9Resource::notifyOnDeviceDestroy */
  76. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
  77. protected:
  78. friend class D3D9HLSLProgramFactory;
  79. D3D9GpuFragmentProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
  80. /** @copydoc D3D9GpuProgramCore::loadFromMicrocode */
  81. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) override;
  82. protected:
  83. Map<IDirect3DDevice9*, IDirect3DPixelShader9*> mMapDeviceToPixelShader;
  84. };
  85. /** @} */
  86. }