|
| 1 | +/* |
| 2 | + Copyright (c) 2025, The Cinder Project |
| 3 | +
|
| 4 | + This code is intended to be used with the Cinder C++ library, http://libcinder.org |
| 5 | +
|
| 6 | + Redistribution and use in source and binary forms, with or without modification, are permitted provided that |
| 7 | + the following conditions are met: |
| 8 | +
|
| 9 | + * Redistributions of source code must retain the above copyright notice, this list of conditions and |
| 10 | + the following disclaimer. |
| 11 | + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
| 12 | + the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 13 | +
|
| 14 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| 15 | + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 16 | + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 17 | + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 18 | + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 19 | + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 20 | + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 21 | + POSSIBILITY OF SUCH DAMAGE. |
| 22 | +*/ |
| 23 | + |
| 24 | +#pragma once |
| 25 | + |
| 26 | +#include "cinder/app/AppBase.h" |
| 27 | +#include "cinder/app/msw/RendererImplMsw.h" |
| 28 | +#include "cinder/app/RendererD3d11.h" |
| 29 | +#include <d3d11_1.h> |
| 30 | +#include <dxgi1_2.h> |
| 31 | + |
| 32 | +namespace cinder { namespace app { |
| 33 | + |
| 34 | +//! Forward declaration |
| 35 | +class WindowImplMsw; |
| 36 | + |
| 37 | +//! Implementation details for RendererD3d11 |
| 38 | +class RendererImplD3d11 : public RendererImplMsw { |
| 39 | + public: |
| 40 | + RendererImplD3d11( WindowImplMsw *windowImpl, RendererD3d11 *renderer ); |
| 41 | + ~RendererImplD3d11(); |
| 42 | + |
| 43 | + //! Initializes the D3D11 device, swap chain, and render targets |
| 44 | + virtual bool initialize( WindowImplMsw *windowImpl, RendererRef sharedRenderer ); |
| 45 | + |
| 46 | + //! Cleans up D3D11 resources |
| 47 | + virtual void kill() override; |
| 48 | + |
| 49 | + //! Prepares for fullscreen toggle |
| 50 | + virtual void prepareToggleFullScreen() override; |
| 51 | + |
| 52 | + //! Finishes fullscreen toggle |
| 53 | + virtual void finishToggleFullScreen() override; |
| 54 | + |
| 55 | + //! Called when window is resized |
| 56 | + virtual void defaultResize() const override; |
| 57 | + |
| 58 | + //! Presents the back buffer |
| 59 | + virtual void swapBuffers() const override; |
| 60 | + |
| 61 | + //! Sets the render target |
| 62 | + virtual void makeCurrentContext( bool force = false ) override; |
| 63 | + |
| 64 | + //! Clears the back buffer to a color |
| 65 | + void clear( const ColorA &color ); |
| 66 | + |
| 67 | + //! Copies window surface to a Cinder Surface |
| 68 | + Surface8u copyWindowSurface( const Area &area ); |
| 69 | + |
| 70 | + //! D3D11 device |
| 71 | + ID3D11Device1 *mDevice; |
| 72 | + |
| 73 | + //! D3D11 device context |
| 74 | + ID3D11DeviceContext1 *mDeviceContext; |
| 75 | + |
| 76 | + //! DXGI swap chain |
| 77 | + IDXGISwapChain1 *mSwapChain; |
| 78 | + |
| 79 | + //! Render target view for the back buffer |
| 80 | + ID3D11RenderTargetView *mRenderTargetView; |
| 81 | + |
| 82 | + //! Depth stencil texture |
| 83 | + ID3D11Texture2D *mDepthStencilTexture; |
| 84 | + |
| 85 | + //! Depth stencil view |
| 86 | + ID3D11DepthStencilView *mDepthStencilView; |
| 87 | + |
| 88 | + protected: |
| 89 | + RendererD3d11 *mRenderer; |
| 90 | + HWND mWnd; |
| 91 | + bool mFullScreen; |
| 92 | + |
| 93 | + //! Creates the D3D11 device |
| 94 | + bool createDevice(); |
| 95 | + |
| 96 | + //! Creates the swap chain |
| 97 | + bool createSwapChain(); |
| 98 | + |
| 99 | + //! Creates the render target view |
| 100 | + bool createRenderTarget(); |
| 101 | + |
| 102 | + //! Creates the depth stencil |
| 103 | + bool createDepthStencil(); |
| 104 | + |
| 105 | + //! Releases framebuffer resources (render target, depth stencil) |
| 106 | + void releaseFramebufferResources(); |
| 107 | +}; |
| 108 | + |
| 109 | +} } // namespace cinder::app |
0 commit comments