gfxD3D11Cubemap.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2015 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 _GFXD3D11CUBEMAP_H_
  23. #define _GFXD3D11CUBEMAP_H_
  24. #include "gfx/D3D11/gfxD3D11Device.h"
  25. #include "gfx/gfxCubemap.h"
  26. #include "gfx/gfxResource.h"
  27. #include "gfx/gfxTarget.h"
  28. const U32 CubeFaces = 6;
  29. const U32 MaxMipMaps = 13; //todo this needs a proper static value somewhere to sync up with other classes like GBitmap
  30. class GFXD3D11Cubemap : public GFXCubemap
  31. {
  32. public:
  33. void initStatic( GFXTexHandle *faces ) override;
  34. void initStatic( DDSFile *dds ) override;
  35. void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0) override;
  36. void generateMipMaps() override;
  37. void setToTexUnit( U32 tuNum ) override;
  38. U32 getSize() const override { return mTexSize; }
  39. GFXFormat getFormat() const override { return mFaceFormat; }
  40. GFXD3D11Cubemap();
  41. virtual ~GFXD3D11Cubemap();
  42. // GFXResource interface
  43. void zombify() override;
  44. void resurrect() override;
  45. bool isInitialized() override { return mTexture ? true : false; }
  46. // Get functions
  47. ID3D11ShaderResourceView* getSRView();
  48. ID3D11RenderTargetView* getRTView(U32 faceIdx);
  49. ID3D11DepthStencilView* getDSView();
  50. ID3D11Texture2D* get2DTex();
  51. private:
  52. friend class GFXD3D11TextureTarget;
  53. friend class GFXD3D11Device;
  54. ID3D11Texture2D* mTexture;
  55. ID3D11ShaderResourceView* mSRView; // for shader resource input
  56. ID3D11RenderTargetView* mRTView[CubeFaces]; // for render targets, 6 faces of the cubemap
  57. ID3D11DepthStencilView* mDSView; //render target view for depth stencil
  58. bool mAutoGenMips;
  59. bool mDynamic;
  60. U32 mTexSize;
  61. GFXFormat mFaceFormat;
  62. void releaseSurfaces();
  63. /// The callback used to get texture events.
  64. /// @see GFXTextureManager::addEventDelegate
  65. void _onTextureEvent(GFXTexCallbackCode code);
  66. void _init(U32 size, GFXFormat format, U32 mipLevels, bool isDynamic, DDSFile* dds = nullptr, GFXTexHandle* faces = nullptr);
  67. };
  68. class GFXD3D11CubemapArray : public GFXCubemapArray
  69. {
  70. public:
  71. GFXD3D11CubemapArray();
  72. virtual ~GFXD3D11CubemapArray();
  73. void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount) override;
  74. void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format) override;
  75. void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot) override;
  76. void copyTo(GFXCubemapArray *pDstCubemap) override;
  77. void setToTexUnit(U32 tuNum) override;
  78. ID3D11ShaderResourceView* getSRView() { return mSRView; }
  79. ID3D11Texture2D* get2DTex() { return mTexture; }
  80. // GFXResource interface
  81. void zombify() override;
  82. void resurrect() override;
  83. private:
  84. friend class GFXD3D11TextureTarget;
  85. friend class GFXD3D11Device;
  86. void _init(U32 cubemapCount, U32 size, GFXFormat format);
  87. ID3D11Texture2D *mTexture;
  88. ID3D11ShaderResourceView* mSRView; // for shader resource input
  89. };
  90. #endif