OGLTextureCube.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Oorni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "RenderSurface.h"
  25. #include "Ptr.h"
  26. #include "Texture.h"
  27. namespace Urho3D
  28. {
  29. class Deserializer;
  30. class Image;
  31. /// Cube texture resource.
  32. class TextureCube : public Texture
  33. {
  34. OBJECT(TextureCube);
  35. public:
  36. /// Construct.
  37. TextureCube(Context* context);
  38. /// Destruct.
  39. virtual ~TextureCube();
  40. /// Register object factory.
  41. static void RegisterObject(Context* context);
  42. /// Load resource. Return true if successful.
  43. virtual bool Load(Deserializer& source);
  44. /// Mark the GPU resource destroyed on context destruction.
  45. virtual void OnDeviceLost();
  46. /// Recreate the GPU resource and restore data if applicable.
  47. virtual void OnDeviceReset();
  48. /// Release the texture.
  49. virtual void Release();
  50. /// Set size, format and usage. Return true if successful.
  51. bool SetSize(int size, unsigned format, TextureUsage usage = TEXTURE_STATIC);
  52. /// Set data either partially or fully on a face's mip level. Return true if successful.
  53. bool SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
  54. /// Load one face from a stream. Return true if successful.
  55. bool Load(CubeMapFace face, Deserializer& source);
  56. /// Load one face from an image. Return true if successful.
  57. bool Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha = false);
  58. /// Get data from a face's mip level. The destination buffer must be big enough. Return true if successful.
  59. bool GetData(CubeMapFace face, unsigned level, void* dest) const;
  60. /// Return render surface for one face.
  61. RenderSurface* GetRenderSurface(CubeMapFace face) const { return renderSurfaces_[face]; }
  62. private:
  63. /// Create texture.
  64. bool Create();
  65. /// Render surfaces.
  66. SharedPtr<RenderSurface> renderSurfaces_[MAX_CUBEMAP_FACES];
  67. /// Memory use per face.
  68. unsigned faceMemoryUse_[MAX_CUBEMAP_FACES];
  69. };
  70. }