GPUObject.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/Ptr.h"
  5. namespace Urho3D
  6. {
  7. class Graphics;
  8. /// API-specific GPU object representation
  9. union GPUObjectHandle
  10. {
  11. /// Object pointer (Direct3D)
  12. void* ptr_;
  13. /// Object name (OpenGL)
  14. u32 name_;
  15. };
  16. /// Base class for GPU resources.
  17. class URHO3D_API GPUObject
  18. {
  19. public:
  20. /// Construct with graphics subsystem pointer.
  21. explicit GPUObject(Graphics* graphics);
  22. /// Destruct. Remove from the Graphics.
  23. virtual ~GPUObject();
  24. /// Mark the GPU resource destroyed on graphics context destruction.
  25. virtual void OnDeviceLost();
  26. /// Recreate the GPU resource and restore data if applicable.
  27. virtual void OnDeviceReset();
  28. /// Unconditionally release the GPU resource.
  29. virtual void Release();
  30. /// Clear the data lost flag.
  31. void ClearDataLost();
  32. /// Return the graphics subsystem associated with this GPU object.
  33. Graphics* GetGraphics() const;
  34. /// Return the object pointer. Applicable only on Direct3D.
  35. void* GetGPUObject() const { return object_.ptr_; }
  36. /// Return the object name. Applicable only on OpenGL.
  37. u32 GetGPUObjectName() const { return object_.name_; }
  38. /// Return whether data is lost due to context loss.
  39. /// @property
  40. bool IsDataLost() const { return dataLost_; }
  41. /// Return whether has pending data assigned while graphics context was lost.
  42. bool HasPendingData() const { return dataPending_; }
  43. protected:
  44. /// Graphics subsystem.
  45. WeakPtr<Graphics> graphics_;
  46. /// Object pointer or name.
  47. GPUObjectHandle object_{};
  48. /// Data lost flag.
  49. bool dataLost_{};
  50. /// Data pending flag.
  51. bool dataPending_{};
  52. };
  53. }