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{
 53public:
 54   typedef Map<U32, ID3D11SamplerState*> SamplerMap;
 55private:
 56
 57   friend class GFXResource;
 58   friend class GFXD3D11PrimitiveBuffer;
 59   friend class GFXD3D11VertexBuffer;
 60   friend class GFXD3D11TextureObject;
 61   friend class GFXD3D11TextureTarget;
 62   friend class GFXD3D11WindowTarget;
 63   friend class OculusVRHMDDevice;
 64   friend class D3D11OculusTexture;
 65
 66   virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile,
 67   const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter);
 68
 69   virtual void enumerateVideoModes();
 70
 71   virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window);
 72   virtual GFXTextureTarget *allocRenderToTextureTarget();
 73
 74   virtual void enterDebugEvent(ColorI color, const char *name);
 75   virtual void leaveDebugEvent();
 76   virtual void setDebugMarker(ColorI color, const char *name);
 77
 78protected:
 79
 80   class D3D11VertexDecl : public GFXVertexDecl
 81   {
 82   public:
 83      virtual ~D3D11VertexDecl()
 84      {
 85         SAFE_RELEASE( decl );
 86      }
 87
 88      ID3D11InputLayout *decl;
 89   };
 90
 91   virtual void initStates() { };
 92
 93   static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
 94
 95   MatrixF mTempMatrix;    ///< Temporary matrix, no assurances on value at all
 96   RectI mClipRect;
 97
 98   typedef StrongRefPtr<GFXD3D11VertexBuffer> RPGDVB;
 99   Vector<RPGDVB> mVolatileVBList;
100
101   /// Used to lookup a vertex declaration for the vertex format.
102   /// @see allocVertexDecl
103   typedef Map<String,D3D11VertexDecl*> VertexDeclMap;
104   VertexDeclMap mVertexDecls;
105
106   /// Used to lookup sampler state for a given hash key
107   SamplerMap mSamplersMap;
108
109   ID3D11RenderTargetView* mDeviceBackBufferView;
110   ID3D11DepthStencilView* mDeviceDepthStencilView;
111
112   ID3D11Texture2D *mDeviceBackbuffer;
113   ID3D11Texture2D *mDeviceDepthStencil;
114
115   /// The stream 0 vertex buffer used for volatile VB offseting.
116   GFXD3D11VertexBuffer *mVolatileVB;
117
118   //-----------------------------------------------------------------------
119   StrongRefPtr<GFXD3D11PrimitiveBuffer> mDynamicPB;
120   GFXD3D11PrimitiveBuffer *mCurrentPB;
121
122   ID3D11VertexShader *mLastVertShader;
123   ID3D11PixelShader *mLastPixShader;
124
125   S32 mCreateFenceType;
126
127   IDXGISwapChain *mSwapChain;
128   ID3D11Device* mD3DDevice;
129   ID3D11DeviceContext* mD3DDeviceContext;
130
131   GFXShader* mCurrentShader;
132   GFXShaderRef mGenericShader[GS_COUNT];
133   GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT];
134   GFXShaderConstHandle *mModelViewProjSC[GS_COUNT];
135
136   U32  mAdapterIndex;
137
138   F32 mPixVersion;
139
140   D3D_FEATURE_LEVEL mFeatureLevel;
141   // Shader Model targers
142   String mVertexShaderTarget;
143   String mPixelShaderTarget;
144   // String for use with shader macros in the form of shader model version * 10
145   String mShaderModel;
146
147   bool mDebugLayers;
148
149   DXGI_SAMPLE_DESC mMultisampleDesc;
150
151   bool mOcclusionQuerySupported;
152
153   U32 mDrawInstancesCount;   
154
155   /// To manage creating and re-creating of these when device is aquired
156   void reacquireDefaultPoolResources();
157
158   /// To release all resources we control from D3DPOOL_DEFAULT
159   void releaseDefaultPoolResources();
160
161   virtual GFXD3D11VertexBuffer* findVBPool( const GFXVertexFormat *vertexFormat, U32 numVertsNeeded );
162   virtual GFXD3D11VertexBuffer* createVBPool( const GFXVertexFormat *vertexFormat, U32 vertSize );
163
164   // State overrides
165   // {
166
167   ///
168   virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject* texture);
169
170   /// Called by GFXDevice to create a device specific stateblock
171   virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc);
172   /// Called by GFXDevice to actually set a stateblock.
173   virtual void setStateBlockInternal(GFXStateBlock* block, bool force);
174
175   /// Track the last const buffer we've used.  Used to notify new constant buffers that
176   /// they should send all of their constants up
177   StrongRefPtr<GFXD3D11ShaderConstBuffer> mCurrentConstBuffer;
178   /// Called by base GFXDevice to actually set a const buffer
179   virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer);
180
181   virtual void setMatrix( GFXMatrixType /*mtype*/, const MatrixF &/*mat*/ ) { };
182   virtual void setLightInternal(U32 /*lightStage*/, const GFXLightInfo /*light*/, bool /*lightEnable*/) { };
183   virtual void setLightMaterialInternal(const GFXLightMaterial /*mat*/) { };
184   virtual void setGlobalAmbientInternal(ColorF /*color*/) { };
185
186   // }
187
188   // Index buffer management
189   // {
190   virtual void _setPrimitiveBuffer( GFXPrimitiveBuffer *buffer );
191   virtual void drawIndexedPrimitive(  GFXPrimitiveType primType, 
192                                       U32 startVertex, 
193                                       U32 minIndex, 
194                                       U32 numVerts, 
195                                       U32 startIndex, 
196                                       U32 primitiveCount );
197   // }
198
199   virtual GFXShader* createShader();
200
201   /// Device helper function
202   virtual DXGI_SWAP_CHAIN_DESC setupPresentParams( const GFXVideoMode &mode, const HWND &hwnd );
203
204   String _createTempShaderInternal(const GFXVertexFormat *vertexFormat);
205   // Supress any debug layer messages we don't want to see
206   void _suppressDebugMessages();
207   
208public:
209
210   static GFXDevice *createInstance( U32 adapterIndex );
211
212   static void enumerateAdapters( Vector<GFXAdapter*> &adapterList );
213
214   ID3D11DepthStencilView* getDepthStencilView() { return mDeviceDepthStencilView; }
215   ID3D11RenderTargetView* getRenderTargetView() { return mDeviceBackBufferView; }
216   ID3D11Texture2D* getBackBufferTexture() { return mDeviceBackbuffer; }
217
218   /// Constructor
219   /// @param   d3d   Direct3D object to instantiate this device with
220   /// @param   index   Adapter index since D3D can use multiple graphics adapters
221   GFXD3D11Device( U32 index );
222   virtual ~GFXD3D11Device();
223
224   // Activate/deactivate
225   // {
226   virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL );
227
228   virtual void preDestroy() { GFXDevice::preDestroy(); if(mTextureManager) mTextureManager->kill(); }
229
230   GFXAdapterType getAdapterType(){ return Direct3D11; }
231
232   U32 getAdaterIndex() const { return mAdapterIndex; }
233
234   virtual GFXCubemap *createCubemap();
235
236   virtual F32  getPixelShaderVersion() const { return mPixVersion; }
237   virtual void setPixelShaderVersion( F32 version ){ mPixVersion = version;} 
238
239   virtual void setShader(GFXShader *shader, bool force = false);
240   virtual U32  getNumSamplers() const { return 16; }
241   virtual U32  getNumRenderTargets() const { return 8; }
242   // }
243
244   // Misc rendering control
245   // {
246   virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil );
247   virtual bool beginSceneInternal();
248   virtual void endSceneInternal();
249
250   virtual void setClipRect( const RectI &rect );
251   virtual const RectI& getClipRect() const { return mClipRect; }
252
253   // }
254
255
256   
257   /// @name Render Targets
258   /// @{
259   virtual void _updateRenderTargets();
260   /// @}
261
262   // Vertex/Index buffer management
263   // {
264   virtual GFXVertexBuffer* allocVertexBuffer(  U32 numVerts, 
265                                                const GFXVertexFormat *vertexFormat,
266                                                U32 vertSize,
267                                                GFXBufferType bufferType,
268                                                void* data = NULL);
269
270   virtual GFXPrimitiveBuffer *allocPrimitiveBuffer(  U32 numIndices, 
271                                                      U32 numPrimitives, 
272                                                      GFXBufferType bufferType,
273                                                      void* data = NULL);
274
275   virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat );
276   virtual void setVertexDecl( const GFXVertexDecl *decl );
277
278   virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer );
279   virtual void setVertexStreamFrequency( U32 stream, U32 frequency );
280   // }
281
282   virtual U32 getMaxDynamicVerts() { return MAX_DYNAMIC_VERTS; }
283   virtual U32 getMaxDynamicIndices() { return MAX_DYNAMIC_INDICES; }
284
285   inline U32 primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount);
286
287   // Rendering
288   // {
289   virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount );
290   // }
291
292   ID3D11DeviceContext* getDeviceContext(){ return mD3DDeviceContext; }
293   ID3D11Device* getDevice(){ return mD3DDevice; }
294
295   /// Reset
296   void beginReset();
297   void endReset(GFXD3D11WindowTarget *windowTarget);
298
299   virtual void setupGenericShaders( GenericShaderType type  = GSColor );
300
301   inline virtual F32 getFillConventionOffset() const { return 0.0f; }
302   virtual void doParanoidStateCheck() {};
303
304   GFXFence *createFence();
305
306   GFXOcclusionQuery* createOcclusionQuery();   
307
308   // Default multisample parameters
309   DXGI_SAMPLE_DESC getMultisampleType() const { return mMultisampleDesc; }
310
311   // Get feature level this gfx device supports
312   D3D_FEATURE_LEVEL getFeatureLevel() const { return mFeatureLevel; }
313   // Shader Model targers
314   const String &getVertexShaderTarget() const { return mVertexShaderTarget; }
315   const String &getPixelShaderTarget() const { return mPixelShaderTarget; }
316   const String &getShaderModel() const { return mShaderModel; }
317
318   // grab the sampler map
319   const SamplerMap &getSamplersMap() const { return mSamplersMap; }
320   SamplerMap &getSamplersMap() { return mSamplersMap; }
321};
322
323#endif
324