Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/cinder/CaptureImplDirectShow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class CaptureImplDirectShow {

static const std::vector<Capture::DeviceRef>& getDevices( bool forceRefresh = false );

// Public method to update dimensions (used by DirectShow setup)
void updateDimensions( int width, int height );
// Public method to update dimensions with stride awareness (used by DirectShow setup)
void updateDimensions( int width, int height, int rowStride, int imageSizeBytes );

class Device : public Capture::Device {
public:
Expand All @@ -83,6 +83,8 @@ class CaptureImplDirectShow {
std::unique_ptr<class SurfaceCache> mSurfaceCache;

int32_t mWidth, mHeight;
int32_t mRowStride; // Actual bytes per row (may include padding)
int32_t mImageSize; // Total buffer size in bytes
mutable Surface8uRef mCurrentFrame;
Capture::DeviceRef mDevice;

Expand Down
90 changes: 90 additions & 0 deletions include/cinder/app/RendererD3d11.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
Copyright (c) 2025, The Cinder Project

This code is intended to be used with the Cinder C++ library, http://libcinder.org

Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "cinder/app/Renderer.h"

namespace cinder { namespace app {

typedef std::shared_ptr<class RendererD3d11> RendererD3d11Ref;

//! Direct3D 11 renderer for Windows Desktop applications
class RendererD3d11 : public Renderer {
public:
RendererD3d11();
~RendererD3d11();

static RendererD3d11Ref create() { return RendererD3d11Ref( new RendererD3d11() ); }
virtual RendererRef clone() const override { return RendererD3d11Ref( new RendererD3d11( *this ) ); }

//! Initializes the renderer with a WindowImplMsw
virtual void setup( WindowImplMsw *windowImpl, RendererRef sharedRenderer ) override;

//! Returns the HWND associated with this renderer
virtual HWND getHwnd() const override { return mWnd; }

//! Returns the HDC (not used for D3D11, returns nullptr)
virtual HDC getDc() const override { return nullptr; }

//! Cleans up D3D11 resources
virtual void kill() override;

//! Called before toggling fullscreen
virtual void prepareToggleFullScreen() override;

//! Called after toggling fullscreen
virtual void finishToggleFullScreen() override;

//! Called at the start of each frame
virtual void startDraw() override;

//! Called at the end of each frame (presents the back buffer)
virtual void finishDraw() override;

//! Called when the window is resized
virtual void defaultResize() override;

//! Copies the current window surface to a Cinder Surface
virtual Surface8u copyWindowSurface( const Area &area, int32_t windowHeightPixels ) override;

//! Makes this context current (for D3D11, sets render targets)
virtual void makeCurrentContext( bool force = false ) override;

//! Clears the back buffer to the specified color
void clear( const ColorA &color );

//! Returns the D3D11 device (for advanced users)
void* getDevice();

//! Returns the D3D11 device context (for advanced users)
void* getDeviceContext();

protected:
RendererD3d11( const RendererD3d11 &renderer );

class RendererImplD3d11 *mImpl;
HWND mWnd;
};

} } // namespace cinder::app
110 changes: 110 additions & 0 deletions include/cinder/app/msw/RendererImplD3d11.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright (c) 2025, The Cinder Project

This code is intended to be used with the Cinder C++ library, http://libcinder.org

Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "cinder/app/AppBase.h"
#include "cinder/app/msw/RendererImplMsw.h"
#include "cinder/app/RendererD3d11.h"
#include "cinder/msw/CinderMsw.h"
#include <d3d11_1.h>
#include <dxgi1_2.h>

namespace cinder { namespace app {

//! Forward declaration
class WindowImplMsw;

//! Implementation details for RendererD3d11
class RendererImplD3d11 : public RendererImplMsw {
public:
RendererImplD3d11( WindowImplMsw *windowImpl, RendererD3d11 *renderer );
~RendererImplD3d11();

//! Initializes the D3D11 device, swap chain, and render targets
virtual bool initialize( WindowImplMsw *windowImpl, RendererRef sharedRenderer );

//! Cleans up D3D11 resources
virtual void kill() override;

//! Prepares for fullscreen toggle
virtual void prepareToggleFullScreen() override;

//! Finishes fullscreen toggle
virtual void finishToggleFullScreen() override;

//! Called when window is resized
virtual void defaultResize() const override;

//! Presents the back buffer
virtual void swapBuffers() const override;

//! Sets the render target
virtual void makeCurrentContext( bool force = false ) override;

//! Clears the back buffer to a color
void clear( const ColorA &color );

//! Copies window surface to a Cinder Surface
Surface8u copyWindowSurface( const Area &area );

//! D3D11 device
msw::ComPtr<ID3D11Device1> mDevice;

//! D3D11 device context
msw::ComPtr<ID3D11DeviceContext1> mDeviceContext;

//! DXGI swap chain
msw::ComPtr<IDXGISwapChain1> mSwapChain;

//! Render target view for the back buffer
msw::ComPtr<ID3D11RenderTargetView> mRenderTargetView;

//! Depth stencil texture
msw::ComPtr<ID3D11Texture2D> mDepthStencilTexture;

//! Depth stencil view
msw::ComPtr<ID3D11DepthStencilView> mDepthStencilView;

protected:
RendererD3d11 *mRenderer;
HWND mWnd;
bool mFullScreen;

//! Creates the D3D11 device
bool createDevice();

//! Creates the swap chain
bool createSwapChain();

//! Creates the render target view
bool createRenderTarget();

//! Creates the depth stencil
bool createDepthStencil();

//! Releases framebuffer resources (render target, depth stencil)
void releaseFramebufferResources();
};

} } // namespace cinder::app
Loading