D3D9TextureCube.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  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. class Deserializer;
  28. class Image;
  29. /// Cube texture resource.
  30. class TextureCube : public Texture
  31. {
  32. OBJECT(TextureCube);
  33. public:
  34. /// Construct.
  35. TextureCube(Context* context);
  36. /// Destruct.
  37. virtual ~TextureCube();
  38. /// Register object factory.
  39. static void RegisterObject(Context* context);
  40. /// Load resource. Return true if successful.
  41. virtual bool Load(Deserializer& source);
  42. /// Release default pool resources.
  43. virtual void OnDeviceLost();
  44. /// ReCreate default pool resources.
  45. virtual void OnDeviceReset();
  46. /// Release texture.
  47. virtual void Release();
  48. /// %Set size, format and usage. Return true if successful.
  49. bool SetSize(int size, unsigned format, TextureUsage usage = TEXTURE_STATIC);
  50. /// %Set data either partially or fully on a face's mip level. Return true if successful.
  51. bool SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
  52. /// Load one face from a stream. Return true if successful.
  53. bool Load(CubeMapFace face, Deserializer& source);
  54. /// Load one face from an image. Return true if successful.
  55. bool Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha = false);
  56. /// Get data from a face's mip level. The destination buffer must be big enough. Return true if successful.
  57. bool GetData(CubeMapFace face, unsigned level, void* dest) const;
  58. /// Return render surface for one face.
  59. RenderSurface* GetRenderSurface(CubeMapFace face) const { return renderSurfaces_[face]; }
  60. private:
  61. /// Create texture.
  62. bool Create();
  63. /// Render surfaces.
  64. SharedPtr<RenderSurface> renderSurfaces_[MAX_CUBEMAP_FACES];
  65. /// Memory use per face.
  66. unsigned faceMemoryUse_[MAX_CUBEMAP_FACES];
  67. /// Currently locked mip level.
  68. int lockedLevel_;
  69. /// Currently locked face.
  70. CubeMapFace lockedFace_;
  71. };