DX11Shader.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "Shader.h"
  3. struct ID3D10Blob;
  4. struct ID3D11PixelShader;
  5. struct ID3D11VertexShader;
  6. struct ID3D11Device;
  7. struct ID3D11DeviceContext;
  8. struct D3D11_INPUT_ELEMENT_DESC;
  9. struct ID3D11Buffer;
  10. struct ID3D11InputLayout;
  11. namespace Framework
  12. {
  13. class DX11Shader : public Shader
  14. {
  15. protected:
  16. ID3D11Device* device;
  17. ID3D11DeviceContext* context;
  18. Critical& deviceLock;
  19. public:
  20. DLLEXPORT DX11Shader(ID3D11Device* device,
  21. ID3D11DeviceContext* context,
  22. Critical& deviceLock);
  23. DLLEXPORT virtual ~DX11Shader();
  24. //! Creates a constant buffer that passes constant data to the shader.
  25. //! A maximum of 14 buffers can be created.
  26. //! zD3d11Device: The device with which the buffer should be created
  27. //! \param size The size of the buffer in bytes
  28. //! \param index The position of the buffer in the buffer array. An
  29. //! existing buffer will be replaced. Buffer 1 cannot be created
  30. //! if buffer 0 has not been created yet, etc.
  31. DLLEXPORT virtual bool createConstBuffer(int size, int index) override;
  32. };
  33. //! Manages a pixel shader
  34. class DX11PixelShader : public DX11Shader
  35. {
  36. private:
  37. ID3D11PixelShader* pixelShader;
  38. public:
  39. //! Constructor
  40. DLLEXPORT DX11PixelShader(ID3D11Device* device,
  41. ID3D11DeviceContext* context,
  42. Critical& deviceLock);
  43. //! Destructor
  44. DLLEXPORT ~DX11PixelShader();
  45. //! Sets the compiled shader
  46. //! zD3d11Device: The device with which the shader should be created
  47. //! \param bytes The bytes of the compiled code
  48. //! \param length The length of the byte array
  49. //! \return true if bytes is valid, false otherwise
  50. DLLEXPORT bool setCompiledByteArray(
  51. unsigned char* bytes, int length) override;
  52. //! After calling this function, this shader is used as a pixel shader
  53. //! zD3d11Context: The context object with which the shader should
  54. //! be used
  55. DLLEXPORT void useShader() override;
  56. };
  57. //! Manages a vertex shader
  58. class DX11VertexShader : public DX11Shader
  59. {
  60. private:
  61. ID3D11VertexShader* vertexShader;
  62. ID3D11InputLayout* inputLayout;
  63. unsigned char* shaderByteBuffer;
  64. int byteBufferSize;
  65. public:
  66. //! Constructor
  67. DLLEXPORT DX11VertexShader(ID3D11Device* device,
  68. ID3D11DeviceContext* context,
  69. Critical& deviceLock);
  70. //! Destructor
  71. DLLEXPORT ~DX11VertexShader();
  72. //! Sets the compiled shader
  73. //! zD3d11Device: The device with which the shader should be created
  74. //! \param bytes The bytes of the compiled code
  75. //! \param length The length of the byte array
  76. //! \return true if bytes is valid, false otherwise
  77. DLLEXPORT bool setCompiledByteArray(
  78. unsigned char* bytes, int length) override;
  79. //! Creates an input layout for the shader.
  80. //! May only be called after compile.
  81. //! zD3d11Device: The device with which the layout should be created
  82. //! \param descArray An array with initialization data
  83. //! \param anz The number of elements in the array
  84. DLLEXPORT bool createInputLayout(
  85. D3D11_INPUT_ELEMENT_DESC* descArray, int anz);
  86. //! After calling this function, this shader is used as a vertex shader
  87. //! zD3d11Context: The context object with which the shader should
  88. //! be used
  89. DLLEXPORT void useShader() override;
  90. };
  91. } // namespace Framework