Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Canvas rendertarget emulation #380

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion source/examples/demo-stages-plugins/ShapeDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ ShapeDemo::ShapeDemo(Environment * environment, const std::string & name)

// Colorize rasterization stage
addStage(m_colorizeRasterization.get());
m_colorizeRasterization->createInput("ColorAttachment") << *createInput<gloperate::ColorRenderTarget *>("Color");
m_colorizeRasterization->createInput("Color") << *createInput<gloperate::ColorRenderTarget *>("Color");
//m_colorizeRasterization->createInput("Depth") << *createInput<gloperate::DepthRenderTarget *>("Depth"); // This example doesn't need a depth buffer for postprocessing
m_colorizeRasterization->renderInterface.viewport << canvasInterface.viewport;
m_colorizeRasterization->drawable << m_colorizeRenderPass->renderPass;

Expand Down
77 changes: 55 additions & 22 deletions source/gloperate/include/gloperate/base/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DepthRenderTarget;
class DepthStencilRenderTarget;
class StencilRenderTarget;
class BlitStage;
class RenderbufferRenderTargetStage;


/**
Expand Down Expand Up @@ -313,30 +314,62 @@ class GLOPERATE_API Canvas : public cppexpose::Object
cppexpose::Variant getSlotStatus(const std::string & path, const std::string & slot);
//@}

/**
* @brief
* Detect framebuffer and render stage compatability and determine render targets
* for render stage inputs
*
* @param[in] targetFBO
* The target framebuffer whose attachments are used when compatible
* @param[out] colorRenderTarget
* The resulting color render target for render stage input
* @param[out] depthRenderTarget
* The resulting depth render target for render stage input
* @param[out] stencilRenderTarget
* The resulting stencil render target for render stage input
* @param[out] depthStencilRenderTarget
* The resulting combined depth-stencil render target for render stage input
*
* @remarks
* The output paarameters are filled with usable render targets as render stage input.
* These may be the attachments from the target framebuffer or emulated ones
*/
void determineRenderTargets(
globjects::Framebuffer * targetFBO,
ColorRenderTarget * & colorRenderTarget,
DepthRenderTarget * & depthRenderTarget,
StencilRenderTarget * & stencilRenderTarget,
DepthStencilRenderTarget * & depthStencilRenderTarget
);

protected:
Environment * m_environment; ///< Gloperate environment to which the canvas belongs
AbstractGLContext * m_openGLContext; ///< OpenGL context used for rendering onto the canvas
bool m_initialized; ///< 'true' if the context has been initialized and the viewport has been set, else 'false'
gloperate::ChronoTimer m_clock; ///< Time measurement
glm::vec4 m_viewport; ///< Viewport (in real device coordinates)
float m_timeDelta; ///< Time delta since the last update (in seconds)
std::unique_ptr<Stage> m_renderStage; ///< Render stage that renders into the canvas
std::unique_ptr<Stage> m_oldStage; ///< Old render stage, will be destroyed on the next render call
std::unique_ptr<BlitStage> m_blitStage; ///< Blit stage that is used to blit to target color attachment if render stage uses own targets
std::unique_ptr<MouseDevice> m_mouseDevice; ///< Device for Mouse Events
std::unique_ptr<KeyboardDevice> m_keyboardDevice; ///< Device for Keyboard Events
bool m_replaceStage; ///< 'true' if the stage has just been replaced, else 'false'
std::mutex m_mutex; ///< Mutex for separating main and render thread
cppexpose::ScopedConnection m_inputChangedConnection; ///< Connection for the inputChanged-signal of the current stage
cppexpose::Function m_inputChangedCallback; ///< Script function that is called on inputChanged (slot, status)
std::vector<AbstractSlot *> m_changedInputs; ///< List of changed input slots
std::mutex m_changedInputMutex; ///< Mutex to access m_changedInputs

std::unique_ptr<ColorRenderTarget> m_colorTarget; ///< Input render target for color attachment
std::unique_ptr<DepthRenderTarget> m_depthTarget; ///< Input render target for depth attachment
std::unique_ptr<DepthStencilRenderTarget> m_depthStencilTarget; ///< Input render target for combined depth stencil attachment
std::unique_ptr<StencilRenderTarget> m_stencilTarget; ///< Input render target for stencil attachment
Environment * m_environment; ///< Gloperate environment to which the canvas belongs
AbstractGLContext * m_openGLContext; ///< OpenGL context used for rendering onto the canvas
bool m_initialized; ///< 'true' if the context has been initialized and the viewport has been set, else 'false'
gloperate::ChronoTimer m_clock; ///< Time measurement
glm::vec4 m_viewport; ///< Viewport (in real device coordinates)
float m_timeDelta; ///< Time delta since the last update (in seconds)
std::unique_ptr<Stage> m_renderStage; ///< Render stage that renders into the canvas
std::unique_ptr<Stage> m_oldStage; ///< Old render stage, will be destroyed on the next render call
std::unique_ptr<RenderbufferRenderTargetStage> m_colorRenderTargetStage; ///< Color render target stage for rendertarget emulation
std::unique_ptr<RenderbufferRenderTargetStage> m_depthRenderTargetStage; ///< Depth render target stage for rendertarget emulation
std::unique_ptr<RenderbufferRenderTargetStage> m_stencilRenderTargetStage; ///< Stencil render target stage for rendertarget emulation
std::unique_ptr<RenderbufferRenderTargetStage> m_depthStencilRenderTargetStage; ///< Combined depth stencil render target stage for rendertarget emulation
std::unique_ptr<BlitStage> m_blitStage; ///< Blit stage that is used to blit to target color attachment if render stage uses own targets
std::unique_ptr<MouseDevice> m_mouseDevice; ///< Device for Mouse Events
std::unique_ptr<KeyboardDevice> m_keyboardDevice; ///< Device for Keyboard Events
bool m_replaceStage; ///< 'true' if the stage has just been replaced, else 'false'
std::mutex m_mutex; ///< Mutex for separating main and render thread
cppexpose::ScopedConnection m_inputChangedConnection; ///< Connection for the inputChanged-signal of the current stage
cppexpose::Function m_inputChangedCallback; ///< Script function that is called on inputChanged (slot, status)
std::vector<AbstractSlot *> m_changedInputs; ///< List of changed input slots
std::mutex m_changedInputMutex; ///< Mutex to access m_changedInputs

std::unique_ptr<ColorRenderTarget> m_targetFBOColorTarget; ///< Input target FBO render target for color attachment
std::unique_ptr<ColorRenderTarget> m_colorTarget; ///< Input render target for color attachment
std::unique_ptr<DepthRenderTarget> m_depthTarget; ///< Input render target for depth attachment
std::unique_ptr<DepthStencilRenderTarget> m_depthStencilTarget; ///< Input render target for combined depth stencil attachment
std::unique_ptr<StencilRenderTarget> m_stencilTarget; ///< Input render target for stencil attachment
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ class GLOPERATE_API AbstractRenderTarget
*/
virtual ~AbstractRenderTarget();

/**
* @brief
* Checks if this and another AbstractRenderTarget points to the same render underlying framebuffer memory segment
*
* @param[in] other
* The other render target
*
* @return
* 'true' if both render targets points to the same framebuffer attachment, else 'false'
*/
bool matchesAttachment(const AbstractRenderTarget * other) const;

/**
* @brief
* Release the current target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace gloperate
class ColorRenderTarget;
class DepthRenderTarget;
class StencilRenderTarget;
class DepthStencilRenderTarget;


/**
Expand All @@ -53,10 +54,11 @@ class GLOPERATE_API RenderbufferRenderTargetStage : public gloperate::Stage
Input<glm::vec4> size; ///< Viewport size (only z and w component is used as width and height)

// Outputs
Output<globjects::Renderbuffer *> renderbuffer; ///< Renderbuffer
Output<gloperate::ColorRenderTarget *> colorRenderTarget; ///< Color RenderTarget
Output<gloperate::DepthRenderTarget *> depthRenderTarget; ///< Depth RenderTarget
Output<gloperate::StencilRenderTarget *> stencilRenderTarget; ///< Stencil RenderTarget
Output<globjects::Renderbuffer *> renderbuffer; ///< Renderbuffer
Output<gloperate::ColorRenderTarget *> colorRenderTarget; ///< Color RenderTarget
Output<gloperate::DepthRenderTarget *> depthRenderTarget; ///< Depth RenderTarget
Output<gloperate::StencilRenderTarget *> stencilRenderTarget; ///< Stencil RenderTarget
Output<gloperate::DepthStencilRenderTarget *> depthStencilRenderTarget; ///< Depth-stencil RenderTarget


public:
Expand Down Expand Up @@ -86,10 +88,11 @@ class GLOPERATE_API RenderbufferRenderTargetStage : public gloperate::Stage


protected:
std::unique_ptr<globjects::Renderbuffer> m_renderbuffer; ///< The created renderbuffer
std::unique_ptr<gloperate::ColorRenderTarget> m_colorRenderTarget; ///< The color render target
std::unique_ptr<gloperate::DepthRenderTarget> m_depthRenderTarget; ///< The depth render target
std::unique_ptr<gloperate::StencilRenderTarget> m_stencilRenderTarget; ///< The stencil render target
std::unique_ptr<globjects::Renderbuffer> m_renderbuffer; ///< The created renderbuffer
std::unique_ptr<gloperate::ColorRenderTarget> m_colorRenderTarget; ///< The color render target
std::unique_ptr<gloperate::DepthRenderTarget> m_depthRenderTarget; ///< The depth render target
std::unique_ptr<gloperate::StencilRenderTarget> m_stencilRenderTarget; ///< The stencil render target
std::unique_ptr<gloperate::DepthStencilRenderTarget> m_depthStencilRenderTarget; ///< The depth-stencil render target
};


Expand Down
Loading