gfxD3D11Target.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 _GFX_D3D_GFXD3D11TARGET_H_
  23. #define _GFX_D3D_GFXD3D11TARGET_H_
  24. #include "gfx/D3D11/gfxD3D11Device.h"
  25. #include "gfx/D3D11/gfxD3D11TextureObject.h"
  26. #include "gfx/gfxTarget.h"
  27. #include "math/mPoint3.h"
  28. #include "math/mPoint2.h"
  29. class GFXD3D11TextureTarget : public GFXTextureTarget
  30. {
  31. friend class GFXD3D11Device;
  32. // Array of target surfaces, this is given to us by attachTexture
  33. ID3D11Texture2D* mTargets[MaxRenderSlotId];
  34. // Array of shader resource views
  35. ID3D11ShaderResourceView* mTargetSRViews[MaxRenderSlotId];
  36. //ID3D11DepthStencilView* mDepthTargetView;
  37. ID3D11View* mTargetViews[MaxRenderSlotId];
  38. // Array of texture objects which correspond to the target surfaces above,
  39. // needed for copy from RenderTarget to texture situations. Current only valid in those situations
  40. GFXD3D11TextureObject* mResolveTargets[MaxRenderSlotId];
  41. Point2I mTargetSize;
  42. GFXFormat mTargetFormat;
  43. public:
  44. GFXD3D11TextureTarget(bool genMips);
  45. ~GFXD3D11TextureTarget();
  46. // Public interface.
  47. virtual const Point2I getSize() { return mTargetSize; }
  48. virtual GFXFormat getFormat() { return mTargetFormat; }
  49. virtual void attachTexture(RenderSlot slot, GFXTextureObject *tex, U32 mipLevel=0, U32 zOffset = 0);
  50. virtual void attachTexture(RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel=0);
  51. virtual void resolve();
  52. /// Note we always copy the Color0 RenderSlot.
  53. virtual void resolveTo( GFXTextureObject *tex );
  54. virtual void activate();
  55. virtual void deactivate();
  56. void zombify();
  57. void resurrect();
  58. };
  59. class GFXD3D11WindowTarget : public GFXWindowTarget
  60. {
  61. friend class GFXD3D11Device;
  62. /// Our backbuffer
  63. ID3D11Texture2D* mBackBuffer;
  64. ID3D11Texture2D* mDepthStencil;
  65. ID3D11RenderTargetView* mBackBufferView;
  66. ID3D11DepthStencilView* mDepthStencilView;
  67. IDXGISwapChain* mSwapChain;
  68. /// Maximum size we can render to.
  69. Point2I mSize;
  70. /// D3D presentation info.
  71. DXGI_SWAP_CHAIN_DESC mPresentationParams;
  72. /// Internal interface that notifies us we need to reset our video mode.
  73. void resetMode();
  74. /// Is this a secondary window
  75. bool mSecondaryWindow;
  76. public:
  77. GFXD3D11WindowTarget();
  78. ~GFXD3D11WindowTarget();
  79. virtual const Point2I getSize();
  80. virtual GFXFormat getFormat();
  81. virtual bool present();
  82. void initPresentationParams();
  83. void createSwapChain();
  84. void createBuffersAndViews();
  85. void setBackBuffer();
  86. virtual void activate();
  87. void zombify();
  88. void resurrect();
  89. virtual void resolveTo( GFXTextureObject *tex );
  90. // These are all reference counted and must be released by whomever uses the get* function
  91. IDXGISwapChain* getSwapChain();
  92. ID3D11Texture2D* getBackBuffer();
  93. ID3D11Texture2D* getDepthStencil();
  94. ID3D11RenderTargetView* getBackBufferView();
  95. ID3D11DepthStencilView* getDepthStencilView();
  96. };
  97. #endif