gfxCubemap.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GFXCUBEMAP_H_
  23. #define _GFXCUBEMAP_H_
  24. #ifndef _GFXTEXTUREHANDLE_H_
  25. #include "gfx/gfxTextureHandle.h"
  26. #endif
  27. class GFXDevice;
  28. struct DDSFile;
  29. ///
  30. class GFXCubemap : public StrongRefBase, public GFXResource
  31. {
  32. friend class GFXDevice;
  33. friend class GFXTextureManager;
  34. protected:
  35. // should only be called by GFXDevice
  36. virtual void setToTexUnit( U32 tuNum ) = 0;
  37. /// The path to the cubemap file.
  38. String mPath;
  39. /// Sets the cubemap file path.
  40. void _setPath( const String &path ) { mPath = path; }
  41. U32 mMipMapLevels;
  42. bool mInitialized;
  43. public:
  44. /// Create a static cubemap from a list of 6 face textures.
  45. virtual void initStatic( GFXTexHandle *faces ) = 0;
  46. /// Create a static cubemap from a DDS cubemap file.
  47. virtual void initStatic( DDSFile *dds ) = 0;
  48. ///create dynamic cubemap. mipLevels 0 is auto create mips, otherwise the value is how many mip levels you wish the cubemap to have
  49. virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0 ) = 0;
  50. void initNormalize(U32 size);
  51. GFXCubemap();
  52. virtual ~GFXCubemap();
  53. /// Returns the size of the faces.
  54. virtual U32 getSize() const = 0;
  55. /// Returns the face texture format.
  56. virtual GFXFormat getFormat() const = 0;
  57. /// Returns if this cubemap has been initialized
  58. virtual bool isInitialized() { return false; }
  59. /// Returns the cubemap file path set at creation.
  60. const String& getPath() const { return mPath; }
  61. // GFXResource interface
  62. /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
  63. virtual const String describeSelf() const;
  64. /// Get the number of mip maps
  65. const U32 getMipMapLevels() const { return mMipMapLevels; }
  66. /// Get Z up face index of the cubemap. DDS files will be stored Y up
  67. static U32 zUpFaceIndex(const U32 index);
  68. };
  69. /// A reference counted handle to a cubemap resource.
  70. class GFXCubemapHandle : public StrongRefPtr<GFXCubemap>
  71. {
  72. public:
  73. GFXCubemapHandle() {}
  74. GFXCubemapHandle( GFXCubemap *cubemap ) { StrongRefPtr<GFXCubemap>::set( cubemap ); }
  75. GFXCubemapHandle( const String &cubemapDDS ) { set( cubemapDDS ); }
  76. /// Set a cubemap from a DDS cubemap texture file.
  77. bool set( const String &cubemapDDS );
  78. /// Releases the texture handle.
  79. void free() { StrongObjectRef::set( NULL ); }
  80. };
  81. /// Cubemap array - data lives on the GPU only with this class, but the data is not immutable so it can be updated
  82. class GFXCubemapArray : public StrongRefBase, public GFXResource
  83. {
  84. friend class GFXDevice;
  85. friend class GFXTextureManager;
  86. protected:
  87. /// should only be called by GFXDevice
  88. virtual void setToTexUnit( U32 tuNum ) = 0;
  89. /// number of cubemaps in the array
  90. U32 mNumCubemaps;
  91. /// cubemap face size
  92. U32 mSize;
  93. /// number of mip levels
  94. U32 mMipMapLevels;
  95. /// format
  96. GFXFormat mFormat;
  97. public:
  98. GFXCubemapArray() :mNumCubemaps(0), mSize(0), mMipMapLevels(0), mFormat(GFXFormat_FIRST) {}
  99. virtual ~GFXCubemapArray() {};
  100. /// Initialize from an array of cubemaps
  101. void setCubeTexSize(GFXCubemapHandle* cubemaps);
  102. void setCubeTexSize(const U32 cubemapFaceSize);
  103. virtual void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount) = 0;
  104. /// Initialize cubemapCount number of blank cubemaps in the array
  105. virtual void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format) = 0;
  106. /// Update cubemap in the array
  107. virtual void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot) = 0;
  108. /// Copy this cubemap to another - destination must be same format, same face size & at-least the same size(or larger)
  109. virtual void copyTo(GFXCubemapArray *pDstCubemap) = 0;
  110. /// Return number of textures in the array
  111. const U32 getNumCubemaps() const { return mNumCubemaps; }
  112. /// Get the number of mip maps
  113. const U32 getMipMapLevels() const { return mMipMapLevels; }
  114. /// Returns the size of the faces.
  115. const U32 getSize() const { return mSize; }
  116. /// Returns the format
  117. const GFXFormat getFormat() const { return mFormat; }
  118. virtual const String describeSelf() const;
  119. };
  120. /// A reference counted handle to a cubemap array resource.
  121. class GFXCubemapArrayHandle : public StrongRefPtr<GFXCubemapArray>
  122. {
  123. public:
  124. GFXCubemapArrayHandle() {}
  125. GFXCubemapArrayHandle(GFXCubemapArray *cubemapArray) { StrongRefPtr<GFXCubemapArray>::set(cubemapArray); }
  126. /// Releases the texture handle.
  127. void free() { StrongObjectRef::set(NULL); }
  128. };
  129. #endif // GFXCUBEMAP