gfxCubemap.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /// Get Z up face index of the cubemap. DDS files will be stored Y up
  42. U32 _zUpFaceIndex(const U32 index);
  43. U32 mMipMapLevels;
  44. public:
  45. /// Create a static cubemap from a list of 6 face textures.
  46. virtual void initStatic( GFXTexHandle *faces ) = 0;
  47. /// Create a static cubemap from a DDS cubemap file.
  48. virtual void initStatic( DDSFile *dds ) = 0;
  49. ///create dynamic cubemap. mipLevels 0 is auto create mips, otherwise the value is how many mip levels you wish the cubemap to have
  50. virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0 ) = 0;
  51. void initNormalize(U32 size);
  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 the cubemap file path set at creation.
  58. const String& getPath() const { return mPath; }
  59. // GFXResource interface
  60. /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
  61. virtual const String describeSelf() const;
  62. /// Get the number of mip maps
  63. const U32 getMipMapLevels() const { return mMipMapLevels; }
  64. };
  65. /// A reference counted handle to a cubemap resource.
  66. class GFXCubemapHandle : public StrongRefPtr<GFXCubemap>
  67. {
  68. public:
  69. GFXCubemapHandle() {}
  70. GFXCubemapHandle( GFXCubemap *cubemap ) { StrongRefPtr<GFXCubemap>::set( cubemap ); }
  71. GFXCubemapHandle( const String &cubemapDDS ) { set( cubemapDDS ); }
  72. /// Set a cubemap from a DDS cubemap texture file.
  73. bool set( const String &cubemapDDS );
  74. /// Releases the texture handle.
  75. void free() { StrongObjectRef::set( NULL ); }
  76. };
  77. /// Cubemap array
  78. class GFXCubemapArray : public StrongRefBase, public GFXResource
  79. {
  80. friend class GFXDevice;
  81. friend class GFXTextureManager;
  82. protected:
  83. // should only be called by GFXDevice
  84. virtual void setToTexUnit( U32 tuNum ) = 0;
  85. /// number of cubemaps in the array
  86. U32 mNumCubemaps;
  87. U32 mSize;
  88. U32 mMipMapLevels;
  89. GFXFormat mFormat;
  90. public:
  91. virtual ~GFXCubemapArray() {};
  92. virtual void initStatic(GFXCubemapHandle *cubemaps, const U32 cubemapCount) = 0;
  93. /// Return number of textures in the array
  94. const U32 getNumCubemaps() const { return mNumCubemaps; }
  95. /// Get the number of mip maps
  96. const U32 getMipMapLevels() const { return mMipMapLevels; }
  97. /// Returns the size of the faces.
  98. const U32 getSize() const { return mSize; }
  99. virtual const String describeSelf() const;
  100. };
  101. /// A reference counted handle to a cubemap array resource.
  102. class GFXCubemapArrayHandle : public StrongRefPtr<GFXCubemapArray>
  103. {
  104. public:
  105. GFXCubemapArrayHandle() {}
  106. GFXCubemapArrayHandle(GFXCubemapArray *cubemapArray) { StrongRefPtr<GFXCubemapArray>::set(cubemapArray); }
  107. /// Releases the texture handle.
  108. void free() { StrongObjectRef::set(NULL); }
  109. };
  110. #endif // GFXCUBEMAP