Shader.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "Array.h"
  3. #include "Critical.h"
  4. namespace Framework
  5. {
  6. class DXBuffer;
  7. enum ShaderType
  8. {
  9. UNBEKANNT,
  10. VERTEX,
  11. PIXEL
  12. };
  13. //! A Shader class that manages all constant buffers of a shader
  14. class Shader : public virtual ReferenceCounter
  15. {
  16. protected:
  17. ShaderType type;
  18. RCArray<DXBuffer>* constBuffers;
  19. public:
  20. //! Constructor
  21. DLLEXPORT Shader();
  22. //! Destructor
  23. DLLEXPORT virtual ~Shader();
  24. //! Sets the compiled shader
  25. //! zD3d11Device: The device with which the shader should be created
  26. //! \param bytes The bytes of the compiled code
  27. //! \param length The length of the byte array
  28. //! \return true if bytes is valid, false otherwise
  29. virtual bool setCompiledByteArray(unsigned char* bytes, int length) = 0;
  30. //! After calling this function, this shader is used as a pixel shader
  31. //! zD3d11Context: The context object with which the shader should
  32. //! be used
  33. virtual void useShader() = 0;
  34. //! Creates a constant buffer that passes constant data to the shader.
  35. //! A maximum of 14 buffers can be created.
  36. //! zD3d11Device: The device with which the buffer should be created
  37. //! \param size The size of the buffer in bytes
  38. //! \param index The position of the buffer in the buffer array. An
  39. //! existing buffer will be replaced. Buffer 1 cannot be created
  40. //! if buffer 0 has not been created yet, etc.
  41. virtual bool createConstBuffer(int size, int index) = 0;
  42. //! Deletes a constant buffer
  43. //! \param index The index of the buffer to delete. Buffer 0 cannot
  44. //! be deleted while buffer 1 still exists, etc.
  45. DLLEXPORT bool removeConstBuffer(int index);
  46. //! Copies data into a constant buffer
  47. //! zD3d11Context: The context object to use for copying
  48. //! \param data A pointer to a byte array of the buffer's size
  49. //! \param index The index of the buffer
  50. //! \param len The length of the data in bytes (-1 for the maximum
  51. //! buffer size)
  52. DLLEXPORT bool fillConstBuffer(char* data, int index, int len = -1);
  53. //! Returns the length of a constant buffer
  54. //! \param index The index of the buffer
  55. DLLEXPORT int getConstBufferLaenge(int index) const;
  56. //! Returns the shader type
  57. DLLEXPORT ShaderType getType() const;
  58. //! Returns the index of the first uninitialized buffer
  59. DLLEXPORT int getFirstUninitializedBufferIndex() const;
  60. };
  61. } // namespace Framework