OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreD3D11RenderWindow.h
Go to the documentation of this file.
1 
2 /*
3 -----------------------------------------------------------------------------
4 This source file is part of OGRE
5 (Object-oriented Graphics Rendering Engine)
6 For the latest info, see http://www.ogre3d.org/
7 
8 Copyright (c) 2000-2014 Torus Knot Software Ltd
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 -----------------------------------------------------------------------------
28 */
29 #ifndef __D3D11RENDERWINDOW_H__
30 #define __D3D11RENDERWINDOW_H__
31 
32 #include "OgreD3D11Prerequisites.h"
33 #include "OgreRenderWindow.h"
34 
35 #if OGRE_PLATFORM == OGRE_PLATFORM_WINRT
36 #pragma warning( disable : 4451 ) // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/314b5826-0a66-4307-abfe-87b8052c3c07/
37 
38 # include <agile.h>
39 # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PC_APP)
40 # include <windows.ui.xaml.media.dxinterop.h>
41 # endif
42 
43 #endif
44 
45 namespace Ogre
46 {
48  : public RenderWindow
49  {
50  public:
51  D3D11RenderWindowBase(D3D11Device& device, IDXGIFactoryN* pDXGIFactory);
53  virtual void create(const String& name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams);
54  virtual void destroy(void);
55 
56  void reposition(int left, int top) {}
57  void resize(unsigned int width, unsigned int height) {}
58 
59  bool isClosed() const { return mClosed; }
60  bool isHidden() const { return mHidden; }
61 
62  void getCustomAttribute( const String& name, void* pData );
65  virtual void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer);
66  bool requiresTextureFlipping() const { return false; }
67 
68  protected:
69  void _createSizeDependedD3DResources(); // assumes mpBackBuffer is already initialized
71 
72  IDXGIDeviceN* _queryDxgiDevice(); // release after use
73 
74  // just check if the multisampling requested is supported by the device
75  bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
76 
78 
79  protected:
80  D3D11Device & mDevice; // D3D11 driver
82  bool mIsExternal; // window not created by Ogre
83  bool mSizing;
84  bool mClosed;
85  bool mHidden;
86 
87  // -------------------------------------------------------
88  // DirectX-specific
89  // -------------------------------------------------------
90  DXGI_SAMPLE_DESC mFSAAType;
92  bool mVSync;
93  unsigned int mVSyncInterval;
94 
95  // Window size depended resources - must be released before swapchain resize and recreated later
96  ID3D11Texture2D* mpBackBuffer;
97  ID3D11RenderTargetView* mRenderTargetView;
98  ID3D11DepthStencilView* mDepthStencilView;
99  };
100 
101 
103  : public D3D11RenderWindowBase
104  {
105  public:
108  virtual void destroy(void);
109 
112 
113  void swapBuffers( );
114 
115  protected:
116  void _createSizeDependedD3DResources(); // obtains mpBackBuffer from mpSwapChain
117  void _createSwapChain();
118  virtual HRESULT _createSwapChainImpl(IDXGIDeviceN* pDXGIDevice) = 0;
119  void _resizeSwapChainBuffers(unsigned width, unsigned height);
120 
121  protected:
122  // Pointer to swap chain
125  };
126 
127 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
128 
131  {
132  public:
133  D3D11RenderWindowHwnd(D3D11Device& device, IDXGIFactoryN* pDXGIFactory);
135  virtual void create(const String& name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams);
136  virtual void destroy(void);
137 
138  bool isVisible() const;
139  void setHidden(bool hidden);
140  void reposition(int left, int top);
141  void resize(unsigned int width, unsigned int height);
142  void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
143 
144  // Method for dealing with resize / move & 3d library
145  void windowMovedOrResized();
146 
147  HWND getWindowHandle() const { return mHWnd; }
148  void getCustomAttribute( const String& name, void* pData );
149 
150  protected:
155 
156  virtual HRESULT _createSwapChainImpl(IDXGIDeviceN* pDXGIDevice);
157  void setActive(bool state);
158  protected:
159  HWND mHWnd; // Win32 window handle
160  bool mSwitchingFullscreen; // Are we switching from fullscreen to windowed or vice versa
161  };
162 
163 #endif
164 
165 #if OGRE_PLATFORM == OGRE_PLATFORM_WINRT
166 
169  {
170  public:
171  D3D11RenderWindowCoreWindow(D3D11Device& device, IDXGIFactoryN* pDXGIFactory);
173  virtual void create(const String& name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams);
174  virtual void destroy(void);
175 
176  Windows::UI::Core::CoreWindow^ getCoreWindow() const { return mCoreWindow.Get(); }
177 
178  bool isVisible() const;
179 
180  // Method for dealing with resize / move & 3d library
181  void windowMovedOrResized();
182 
183  protected:
184  virtual HRESULT _createSwapChainImpl(IDXGIDeviceN* pDXGIDevice);
185 
186  protected:
187  Platform::Agile<Windows::UI::Core::CoreWindow> mCoreWindow;
188  };
189 
190 #if (OGRE_PLATFORM == OGRE_PLATFORM_WINRT) && (OGRE_WINRT_TARGET_TYPE == DESKTOP_APP)
191 
193  : public D3D11RenderWindowBase
194  {
195  public:
198  virtual void create(const String& name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams);
199  virtual void destroy(void);
200 
201  virtual void resize(unsigned int width, unsigned int height);
202  virtual void update();
203  virtual void swapBuffers();
204 
205  virtual bool isVisible() const { return mImageSourceNative != NULL; }
206 
207  Windows::UI::Xaml::Media::ImageBrush^ getImageBrush() const { return mBrush; }
208  virtual void getCustomAttribute( const String& name, void* pData ); // "ImageBrush" -> Windows::UI::Xaml::Media::ImageBrush^
209 
210  protected:
211  void _createSizeDependedD3DResources(); // creates mpBackBuffer
212 
213  protected:
214  Windows::UI::Xaml::Media::ImageBrush^ mBrush; // size independed
215  Windows::UI::Xaml::Media::Imaging::SurfaceImageSource^ mImageSource; // size depended, can be NULL
216  ISurfaceImageSourceNative* mImageSourceNative; // size depended, can be NULL
217  };
218 #endif // (OGRE_PLATFORM == OGRE_PLATFORM_WINRT) && (OGRE_WINRT_TARGET_TYPE == DESKTOP_APP)
219 
220 #endif
221 
222 }
223 #endif
Manages the target rendering window.
bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format)
void resize(unsigned int width, unsigned int height)
Alter the size of the window.
virtual void resize(unsigned int width, unsigned int height)
Alter the size of the window.
bool isVisible() const
Indicates whether the window is visible (not minimized or obscured)
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:580
bool isVisible() const
Indicates whether the window is visible (not minimized or obscured)
Platform::Agile< Windows::UI::Core::CoreWindow > mCoreWindow
virtual void destroy(void)
Destroys the window.
void windowMovedOrResized()
Notify that the window has been resized.
bool isClosed() const
Indicates whether the window has been closed by the user.
bool _getSwitchingFullscreen() const
Are we in the middle of switching between fullscreen and windowed.
void windowMovedOrResized()
Notify that the window has been resized.
void reposition(int left, int top)
Reposition the window.
void setHidden(bool hidden)
Hide (or show) the window.
bool isHidden() const
Indicates whether the window was set to hidden (not displayed)
Windows::UI::Xaml::Media::ImageBrush mBrush
ISurfaceImageSourceNative * mImageSourceNative
virtual void create(const String &name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams)
D3D11RenderWindowHwnd(D3D11Device &device, IDXGIFactoryN *pDXGIFactory)
virtual void destroy(void)
Destroys the window.
virtual HRESULT _createSwapChainImpl(IDXGIDeviceN *pDXGIDevice)=0
virtual void destroy(void)
Destroys the window.
D3D11RenderWindowImageSource(D3D11Device &device, IDXGIFactoryN *pDXGIFactory)
virtual HRESULT _createSwapChainImpl(IDXGIDeviceN *pDXGIDevice)
void _finishSwitchingFullscreen()
Indicate that fullscreen / windowed switching has finished.
IDXGIDevice1 IDXGIDeviceN
void setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
Alter fullscreen mode options.
DXGI_SWAP_CHAIN_DESC DXGI_SWAP_CHAIN_DESC_N
IDXGIDeviceN * _queryDxgiDevice()
Windows::UI::Core::CoreWindow getCoreWindow() const
D3D11RenderWindowSwapChainBased(D3D11Device &device, IDXGIFactoryN *pDXGIFactory)
Windows::UI::Xaml::Media::Imaging::SurfaceImageSource mImageSource
virtual void create(const String &name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams)
virtual void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer)
Overridden - see RenderTarget.
D3D11RenderWindowCoreWindow(D3D11Device &device, IDXGIFactoryN *pDXGIFactory)
virtual HRESULT _createSwapChainImpl(IDXGIDeviceN *pDXGIDevice)
D3D11RenderWindowBase(D3D11Device &device, IDXGIFactoryN *pDXGIFactory)
void swapBuffers()
Swaps the frame buffers to display the next frame.
virtual void swapBuffers()
Swaps the frame buffers to display the next frame.
void resize(unsigned int width, unsigned int height)
Alter the size of the window.
virtual bool isVisible() const
Indicates whether the window is visible (not minimized or obscured)
void setActive(bool state)
Used to set the active state of the render target.
ID3D11DepthStencilView * mDepthStencilView
Windows::UI::Xaml::Media::ImageBrush getImageBrush() const
virtual void create(const String &name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams)
virtual void destroy(void)
Destroys the window.
virtual void destroy(void)
Destroys the window.
IDXGISwapChain IDXGISwapChainN
IDXGIFactory1 IDXGIFactoryN
void _resizeSwapChainBuffers(unsigned width, unsigned height)
_StringBase String
Definition: OgreCommon.h:53
void getCustomAttribute(const String &name, void *pData)
Gets a custom (maybe platform-specific) attribute.
virtual void getCustomAttribute(const String &name, void *pData)
Gets a custom (maybe platform-specific) attribute.
ID3D11RenderTargetView * mRenderTargetView
void getCustomAttribute(const String &name, void *pData)
Gets a custom (maybe platform-specific) attribute.
virtual void create(const String &name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams)
void reposition(int left, int top)
Reposition the window.
DXGI_SWAP_CHAIN_DESC_N * getPresentationParameters(void)
Get the presentation parameters used with this window.