gfxD3D11Cubemap.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. virtual void initStatic( GFXTexHandle *faces );
  34. virtual void initStatic( DDSFile *dds );
  35. virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0);
  36. virtual void setToTexUnit( U32 tuNum );
  37. virtual U32 getSize() const { return mTexSize; }
  38. virtual GFXFormat getFormat() const { return mFaceFormat; }
  39. GFXD3D11Cubemap();
  40. virtual ~GFXD3D11Cubemap();
  41. // GFXResource interface
  42. virtual void zombify();
  43. virtual void resurrect();
  44. virtual bool isInitialized() { return mTexture ? true : false; }
  45. // Get functions
  46. ID3D11ShaderResourceView* getSRView();
  47. ID3D11RenderTargetView* getRTView(U32 faceIdx, U32 mipIndex=0);
  48. ID3D11DepthStencilView* getDSView();
  49. ID3D11Texture2D* get2DTex();
  50. private:
  51. friend class GFXD3D11TextureTarget;
  52. friend class GFXD3D11Device;
  53. ID3D11Texture2D* mTexture;
  54. ID3D11ShaderResourceView* mSRView; // for shader resource input
  55. ID3D11RenderTargetView* mRTView[CubeFaces][MaxMipMaps]; // for render targets, 6 faces of the cubemap
  56. ID3D11DepthStencilView* mDSView; //render target view for depth stencil
  57. bool mAutoGenMips;
  58. bool mDynamic;
  59. U32 mTexSize;
  60. GFXFormat mFaceFormat;
  61. void releaseSurfaces();
  62. /// The callback used to get texture events.
  63. /// @see GFXTextureManager::addEventDelegate
  64. void _onTextureEvent(GFXTexCallbackCode code);
  65. };
  66. class GFXD3D11CubemapArray : public GFXCubemapArray
  67. {
  68. public:
  69. GFXD3D11CubemapArray();
  70. virtual ~GFXD3D11CubemapArray();
  71. virtual void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
  72. virtual void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format);
  73. virtual void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot);
  74. virtual void copyTo(GFXCubemapArray *pDstCubemap);
  75. virtual void setToTexUnit(U32 tuNum);
  76. ID3D11ShaderResourceView* getSRView() { return mSRView; }
  77. ID3D11Texture2D* get2DTex() { return mTexture; }
  78. // GFXResource interface
  79. virtual void zombify();
  80. virtual void resurrect();
  81. private:
  82. friend class GFXD3D11TextureTarget;
  83. friend class GFXD3D11Device;
  84. ID3D11Texture2D *mTexture;
  85. ID3D11ShaderResourceView* mSRView; // for shader resource input
  86. };
  87. #endif