1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __D3D11DEVICE_H__
29 #define __D3D11DEVICE_H__
30 
31 
32 #include "OgreD3D11Prerequisites.h"
33 
34 namespace Ogre
35 {
36     class _OgreD3D11Export D3D11Device
37     {
38     private:
39         ComPtr<ID3D11DeviceN>           mD3D11Device;
40         ComPtr<ID3D11DeviceContextN>    mImmediateContext;
41         ComPtr<ID3D11ClassLinkage>      mClassLinkage;
42         ComPtr<ID3D11InfoQueue>         mInfoQueue;
43         LARGE_INTEGER                   mDriverVersion;
44         ComPtr<IDXGIFactoryN>           mDXGIFactory;
45 #if OGRE_D3D11_PROFILING
46         ComPtr<ID3DUserDefinedAnnotation> mPerf;
47 #endif
48 
49         D3D11Device(const D3D11Device& device); /* intentionally not implemented */
50         const D3D11Device& operator=(D3D11Device& device); /* intentionally not implemented */
51 
52     public:
53         D3D11Device();
54         ~D3D11Device();
55 
56         void ReleaseAll();
57         void TransferOwnership(ID3D11DeviceN* device);
58         bool IsDeviceLost();
59 
isNull()60         bool isNull()                                { return !mD3D11Device; }
get()61         ID3D11DeviceN* get()                         { return mD3D11Device.Get(); }
GetImmediateContext()62         ID3D11DeviceContextN* GetImmediateContext()  { return mImmediateContext.Get(); }
GetClassLinkage()63         ID3D11ClassLinkage* GetClassLinkage()        { return mClassLinkage.Get(); }
GetDXGIFactory()64         IDXGIFactoryN* GetDXGIFactory()              { return mDXGIFactory.Get(); }
GetDriverVersion()65         LARGE_INTEGER GetDriverVersion()             { return mDriverVersion; }
66 #if OGRE_D3D11_PROFILING
GetProfiler()67         ID3DUserDefinedAnnotation* GetProfiler()     { return mPerf.Get(); }
68 #endif
69 
70         ID3D11DeviceN* operator->() const
71         {
72             assert(mD3D11Device);
73             if (D3D_NO_EXCEPTION != mExceptionsErrorLevel)
74             {
75                 clearStoredErrorMessages();
76             }
77             return mD3D11Device.Get();
78         }
79 
80         void throwIfFailed(HRESULT hr, const char* desc, const char* src);
throwIfFailed(const char * desc,const char * src)81         void throwIfFailed(const char* desc, const char* src) { throwIfFailed(NO_ERROR, desc, src); }
82 
83         String getErrorDescription(const HRESULT hr = NO_ERROR) const;
84         void clearStoredErrorMessages() const;
85         bool _getErrorsFromQueue() const;
86 
isError()87         bool isError() const                         { return (D3D_NO_EXCEPTION == mExceptionsErrorLevel) ? false : _getErrorsFromQueue(); }
88 
89         enum eExceptionsErrorLevel
90         {
91             D3D_NO_EXCEPTION,
92             D3D_CORRUPTION,
93             D3D_ERROR,
94             D3D_WARNING,
95             D3D_INFO,
96         };
97 
98         static eExceptionsErrorLevel mExceptionsErrorLevel;
99         static const eExceptionsErrorLevel getExceptionsErrorLevel();
100         static void setExceptionsErrorLevel(const eExceptionsErrorLevel exceptionsErrorLevel);
101         static void setExceptionsErrorLevel(const Ogre::String& exceptionsErrorLevel);
102 
103         static D3D_FEATURE_LEVEL parseFeatureLevel(const Ogre::String& value, D3D_FEATURE_LEVEL fallback);
104         static D3D_DRIVER_TYPE parseDriverType(const Ogre::String& value, D3D_DRIVER_TYPE fallback = D3D_DRIVER_TYPE_HARDWARE);
105     };
106 }
107 #endif
108