Torque3D Documentation / _generateds / gfxD3D11Device.h

gfxD3D11Device.h

Engine/source/gfx/D3D11/gfxD3D11Device.h

More...

Classes:

Public Defines

define
D3D11() static_cast<*>()
define
D3D11DEVICE() ->getDevice()
define
D3D11DEVICECONTEXT() ->getDeviceContext()

Detailed Description

Public Defines

D3D11() static_cast<*>()
D3D11DEVICE() ->getDevice()
D3D11DEVICECONTEXT() ->getDeviceContext()
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2015 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _GFXD3D11DEVICE_H_
 25#define _GFXD3D11DEVICE_H_
 26
 27#include <d3d11.h>
 28
 29#include "platform/tmm_off.h"
 30#include "platformWin32/platformWin32.h"
 31#include "gfx/D3D11/gfxD3D11Shader.h"
 32#include "gfx/D3D11/gfxD3D11StateBlock.h"
 33#include "gfx/D3D11/gfxD3D11TextureManager.h"
 34#include "gfx/D3D11/gfxD3D11Cubemap.h"
 35#include "gfx/D3D11/gfxD3D11PrimitiveBuffer.h"
 36#include "gfx/gfxInit.h"
 37#include "gfx/gfxResource.h"
 38#include "platform/tmm_on.h"
 39
 40#define D3D11 static_cast<GFXD3D11Device*>(GFX)
 41#define D3D11DEVICE D3D11->getDevice()
 42#define D3D11DEVICECONTEXT D3D11->getDeviceContext()
 43
 44class PlatformWindow;
 45class GFXD3D11ShaderConstBuffer;
 46class OculusVRHMDDevice;
 47class D3D11OculusTexture;
 48
 49//------------------------------------------------------------------------------
 50
 51class GFXD3D11Device : public GFXDevice
 52{
 53   friend class GFXResource;
 54   friend class GFXD3D11PrimitiveBuffer;
 55   friend class GFXD3D11VertexBuffer;
 56   friend class GFXD3D11TextureObject;
 57   friend class GFXD3D11TextureTarget;
 58   friend class GFXD3D11WindowTarget;
 59   friend class OculusVRHMDDevice;
 60   friend class D3D11OculusTexture;
 61
 62   virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile,
 63   const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter);
 64
 65   virtual void enumerateVideoModes();
 66
 67   virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window);
 68   virtual GFXTextureTarget *allocRenderToTextureTarget();
 69
 70   virtual void enterDebugEvent(ColorI color, const char *name){};
 71   virtual void leaveDebugEvent(){};
 72   virtual void setDebugMarker(ColorI color, const char *name){};
 73
 74protected:
 75
 76   class D3D11VertexDecl : public GFXVertexDecl
 77   {
 78   public:
 79      virtual ~D3D11VertexDecl()
 80      {
 81         SAFE_RELEASE( decl );
 82      }
 83
 84      ID3D11InputLayout *decl;
 85   };
 86
 87   virtual void initStates() { };
 88
 89   static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
 90
 91   MatrixF mTempMatrix;    ///< Temporary matrix, no assurances on value at all
 92   RectI mClipRect;
 93
 94   typedef StrongRefPtr<GFXD3D11VertexBuffer> RPGDVB;
 95   Vector<RPGDVB> mVolatileVBList;
 96
 97   /// Used to lookup a vertex declaration for the vertex format.
 98   /// @see allocVertexDecl
 99   typedef Map<String,D3D11VertexDecl*> VertexDeclMap;
100   VertexDeclMap mVertexDecls;
101
102   ID3D11RenderTargetView* mDeviceBackBufferView;
103   ID3D11DepthStencilView* mDeviceDepthStencilView;
104
105   ID3D11Texture2D *mDeviceBackbuffer;
106   ID3D11Texture2D *mDeviceDepthStencil;
107
108   /// The stream 0 vertex buffer used for volatile VB offseting.
109   GFXD3D11VertexBuffer *mVolatileVB;
110
111   //-----------------------------------------------------------------------
112   StrongRefPtr<GFXD3D11PrimitiveBuffer> mDynamicPB;
113   GFXD3D11PrimitiveBuffer *mCurrentPB;
114
115   ID3D11VertexShader *mLastVertShader;
116   ID3D11PixelShader *mLastPixShader;
117
118   S32 mCreateFenceType;
119
120   IDXGISwapChain *mSwapChain;
121   ID3D11Device* mD3DDevice;
122   ID3D11DeviceContext* mD3DDeviceContext;
123
124   GFXShader* mCurrentShader;
125   GFXShaderRef mGenericShader[GS_COUNT];
126   GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT];
127   GFXShaderConstHandle *mModelViewProjSC[GS_COUNT];
128
129   U32  mAdapterIndex;
130
131   F32 mPixVersion;
132
133   bool mDebugLayers;
134
135   DXGI_SAMPLE_DESC mMultisampleDesc;
136
137   bool mOcclusionQuerySupported;
138
139   U32 mDrawInstancesCount;   
140
141   /// To manage creating and re-creating of these when device is aquired
142   void reacquireDefaultPoolResources();
143
144   /// To release all resources we control from D3DPOOL_DEFAULT
145   void releaseDefaultPoolResources();
146
147   virtual GFXD3D11VertexBuffer* findVBPool( const GFXVertexFormat *vertexFormat, U32 numVertsNeeded );
148   virtual GFXD3D11VertexBuffer* createVBPool( const GFXVertexFormat *vertexFormat, U32 vertSize );
149
150   IDXGISwapChain* getSwapChain();
151   // State overrides
152   // {
153
154   ///
155   virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject* texture);
156
157   /// Called by GFXDevice to create a device specific stateblock
158   virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc);
159   /// Called by GFXDevice to actually set a stateblock.
160   virtual void setStateBlockInternal(GFXStateBlock* block, bool force);
161
162   /// Track the last const buffer we've used.  Used to notify new constant buffers that
163   /// they should send all of their constants up
164   StrongRefPtr<GFXD3D11ShaderConstBuffer> mCurrentConstBuffer;
165   /// Called by base GFXDevice to actually set a const buffer
166   virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer);
167
168   virtual void setMatrix( GFXMatrixType /*mtype*/, const MatrixF &/*mat*/ ) { };
169   virtual void setLightInternal(U32 /*lightStage*/, const GFXLightInfo /*light*/, bool /*lightEnable*/) { };
170   virtual void setLightMaterialInternal(const GFXLightMaterial /*mat*/) { };
171   virtual void setGlobalAmbientInternal(ColorF /*color*/) { };
172
173   // }
174
175   // Index buffer management
176   // {
177   virtual void _setPrimitiveBuffer( GFXPrimitiveBuffer *buffer );
178   virtual void drawIndexedPrimitive(  GFXPrimitiveType primType, 
179                                       U32 startVertex, 
180                                       U32 minIndex, 
181                                       U32 numVerts, 
182                                       U32 startIndex, 
183                                       U32 primitiveCount );
184   // }
185
186   virtual GFXShader* createShader();
187
188   /// Device helper function
189   virtual DXGI_SWAP_CHAIN_DESC setupPresentParams( const GFXVideoMode &mode, const HWND &hwnd );
190
191   String _createTempShaderInternal(const GFXVertexFormat *vertexFormat);
192   // Supress any debug layer messages we don't want to see
193   void _suppressDebugMessages();
194   
195public:
196
197   static GFXDevice *createInstance( U32 adapterIndex );
198
199   static void enumerateAdapters( Vector<GFXAdapter*> &adapterList );
200
201   GFXTextureObject* createRenderSurface( U32 width, U32 height, GFXFormat format, U32 mipLevel );
202
203   ID3D11DepthStencilView* getDepthStencilView() { return mDeviceDepthStencilView; }
204   ID3D11RenderTargetView* getRenderTargetView() { return mDeviceBackBufferView; }
205   ID3D11Texture2D* getBackBufferTexture() { return mDeviceBackbuffer; }
206
207   /// Constructor
208   /// @param   d3d   Direct3D object to instantiate this device with
209   /// @param   index   Adapter index since D3D can use multiple graphics adapters
210   GFXD3D11Device( U32 index );
211   virtual ~GFXD3D11Device();
212
213   // Activate/deactivate
214   // {
215   virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL );
216
217   virtual void preDestroy() { GFXDevice::preDestroy(); if(mTextureManager) mTextureManager->kill(); }
218
219   GFXAdapterType getAdapterType(){ return Direct3D11; }
220
221   U32 getAdaterIndex() const { return mAdapterIndex; }
222
223   virtual GFXCubemap *createCubemap();
224
225   virtual F32  getPixelShaderVersion() const { return mPixVersion; }
226   virtual void setPixelShaderVersion( F32 version ){ mPixVersion = version;} 
227
228   virtual void setShader(GFXShader *shader, bool force = false);
229   virtual U32  getNumSamplers() const { return 16; }
230   virtual U32  getNumRenderTargets() const { return 8; }
231   // }
232
233   // Misc rendering control
234   // {
235   virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil );
236   virtual bool beginSceneInternal();
237   virtual void endSceneInternal();
238
239   virtual void setClipRect( const RectI &rect );
240   virtual const RectI& getClipRect() const { return mClipRect; }
241
242   // }
243
244
245   
246   /// @name Render Targets
247   /// @{
248   virtual void _updateRenderTargets();
249   /// @}
250
251   // Vertex/Index buffer management
252   // {
253   virtual GFXVertexBuffer* allocVertexBuffer(  U32 numVerts, 
254                                                const GFXVertexFormat *vertexFormat,
255                                                U32 vertSize,
256                                                GFXBufferType bufferType,
257                                                void* data = NULL);
258
259   virtual GFXPrimitiveBuffer *allocPrimitiveBuffer(  U32 numIndices, 
260                                                      U32 numPrimitives, 
261                                                      GFXBufferType bufferType,
262                                                      void* data = NULL);
263
264   virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat );
265   virtual void setVertexDecl( const GFXVertexDecl *decl );
266
267   virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer );
268   virtual void setVertexStreamFrequency( U32 stream, U32 frequency );
269   // }
270
271   virtual U32 getMaxDynamicVerts() { return MAX_DYNAMIC_VERTS; }
272   virtual U32 getMaxDynamicIndices() { return MAX_DYNAMIC_INDICES; }
273
274   inline U32 primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount);
275
276   // Rendering
277   // {
278   virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount );
279   // }
280
281   ID3D11DeviceContext* getDeviceContext(){ return mD3DDeviceContext; }
282   ID3D11Device* getDevice(){ return mD3DDevice; }
283
284   /// Reset
285   void reset( DXGI_SWAP_CHAIN_DESC &d3dpp );
286
287   virtual void setupGenericShaders( GenericShaderType type  = GSColor );
288
289   inline virtual F32 getFillConventionOffset() const { return 0.0f; }
290   virtual void doParanoidStateCheck() {};
291
292   GFXFence *createFence();
293
294   GFXOcclusionQuery* createOcclusionQuery();   
295
296   // Default multisample parameters
297   DXGI_SAMPLE_DESC getMultisampleType() const { return mMultisampleDesc; }
298};
299
300#endif
301