ConstantBuffer.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/ArrayPtr.h"
  5. #include "../Core/Object.h"
  6. #include "../GraphicsAPI/GPUObject.h"
  7. #include "../GraphicsAPI/GraphicsDefs.h"
  8. namespace Urho3D
  9. {
  10. /// Hardware constant buffer.
  11. class URHO3D_API ConstantBuffer : public Object, public GPUObject
  12. {
  13. URHO3D_OBJECT(ConstantBuffer, Object);
  14. public:
  15. /// Construct.
  16. explicit ConstantBuffer(Context* context);
  17. /// Destruct.
  18. ~ConstantBuffer() override;
  19. /// Recreate the GPU resource and restore data if applicable.
  20. void OnDeviceReset() override;
  21. /// Release the buffer.
  22. void Release() override;
  23. /// Set size and create GPU-side buffer. Return true on success.
  24. bool SetSize(unsigned size);
  25. /// Set a generic parameter and mark buffer dirty.
  26. void SetParameter(unsigned offset, unsigned size, const void* data);
  27. /// Set a Vector3 array parameter and mark buffer dirty.
  28. void SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data);
  29. /// Apply to GPU.
  30. void Apply();
  31. /// Return size.
  32. unsigned GetSize() const { return size_; }
  33. /// Return whether has unapplied data.
  34. bool IsDirty() const { return dirty_; }
  35. private:
  36. #ifdef URHO3D_OPENGL
  37. void Release_OGL();
  38. void OnDeviceReset_OGL();
  39. bool SetSize_OGL(unsigned size);
  40. void Apply_OGL();
  41. #endif // def URHO3D_OPENGL
  42. #ifdef URHO3D_D3D11
  43. void Release_D3D11();
  44. void OnDeviceReset_D3D11();
  45. bool SetSize_D3D11(unsigned size);
  46. void Apply_D3D11();
  47. #endif // def URHO3D_D3D11
  48. /// Shadow data.
  49. SharedArrayPtr<unsigned char> shadowData_;
  50. /// Buffer byte size.
  51. unsigned size_{};
  52. /// Dirty flag.
  53. bool dirty_{};
  54. };
  55. }