Texture3D.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/Ptr.h"
  5. #include "../GraphicsAPI/RenderSurface.h"
  6. #include "../GraphicsAPI/Texture.h"
  7. #include "../Resource/Image.h"
  8. namespace Urho3D
  9. {
  10. /// 3D texture resource.
  11. class URHO3D_API Texture3D : public Texture
  12. {
  13. URHO3D_OBJECT(Texture3D, Texture);
  14. public:
  15. /// Construct.
  16. explicit Texture3D(Context* context);
  17. /// Destruct.
  18. ~Texture3D() override;
  19. /// Register object factory.
  20. /// @nobind
  21. static void RegisterObject(Context* context);
  22. /// Load resource from stream. May be called from a worker thread. Return true if successful.
  23. bool BeginLoad(Deserializer& source) override;
  24. /// Finish resource loading. Always called from the main thread. Return true if successful.
  25. bool EndLoad() override;
  26. /// Mark the GPU resource destroyed on context destruction.
  27. void OnDeviceLost() override;
  28. /// Recreate the GPU resource and restore data if applicable.
  29. void OnDeviceReset() override;
  30. /// Release the texture.
  31. void Release() override;
  32. /// Set size, format and usage. Zero size will follow application window size. Return true if successful.
  33. bool SetSize(int width, int height, int depth, unsigned format, TextureUsage usage = TEXTURE_STATIC);
  34. /// Set data either partially or fully on a mip level. Return true if successful.
  35. bool SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
  36. /// Set data from an image. Return true if successful. Optionally make a single channel image alpha-only.
  37. bool SetData(Image* image, bool useAlpha = false);
  38. /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.
  39. bool GetData(unsigned level, void* dest) const;
  40. protected:
  41. /// Create the GPU texture.
  42. bool Create() override;
  43. private:
  44. #ifdef URHO3D_OPENGL
  45. void OnDeviceLost_OGL();
  46. void OnDeviceReset_OGL();
  47. void Release_OGL();
  48. bool SetData_OGL(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
  49. bool SetData_OGL(Image* image, bool useAlpha);
  50. bool GetData_OGL(unsigned level, void* dest) const;
  51. bool Create_OGL();
  52. #endif // def URHO3D_OPENGL
  53. #ifdef URHO3D_D3D11
  54. void OnDeviceLost_D3D11();
  55. void OnDeviceReset_D3D11();
  56. void Release_D3D11();
  57. bool SetData_D3D11(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
  58. bool SetData_D3D11(Image* image, bool useAlpha);
  59. bool GetData_D3D11(unsigned level, void* dest) const;
  60. bool Create_D3D11();
  61. #endif // def URHO3D_D3D11
  62. /// Image file acquired during BeginLoad.
  63. SharedPtr<Image> loadImage_;
  64. /// Parameter file acquired during BeginLoad.
  65. SharedPtr<XMLFile> loadParameters_;
  66. };
  67. }