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