Skip to content

Commit

Permalink
Merge branch 'its_just_a_render_target' into 'master'
Browse files Browse the repository at this point in the history
Update render targets outside of draw thread

See merge request OpenMW/openmw!4361
  • Loading branch information
psi29a committed Sep 9, 2024
2 parents 090c65c + f849b0c commit fc7c141
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
19 changes: 0 additions & 19 deletions apps/openmw/mwrender/pingpongcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,6 @@ namespace MWRender

if (pass.mRenderTarget)
{
if (mDirtyAttachments.size() > 0)
{
const auto [w, h]
= pass.mSize.get(mTextureScene->getTextureWidth(), mTextureScene->getTextureHeight());

// Custom render targets must be shared between frame ids, so it's impossible to double buffer
// without expensive copies. That means the only thread-safe place to resize is in the draw
// thread.
osg::Texture2D* texture = const_cast<osg::Texture2D*>(dynamic_cast<const osg::Texture2D*>(
pass.mRenderTarget->getAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0)
.getTexture()));

assert(texture != nullptr);

texture->setTextureSize(w, h);
texture->setNumMipmapLevels(pass.mRenderTexture->getNumMipmapLevels());
texture->dirtyTextureObject();
}

pass.mRenderTarget->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);

if (pass.mRenderTexture->getNumMipmapLevels() > 0)
Expand Down
9 changes: 6 additions & 3 deletions apps/openmw/mwrender/postprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,16 @@ namespace MWRender
subPass.mRenderTexture = renderTarget.mTarget;
subPass.mMipMap = renderTarget.mMipMap;

const auto [w, h] = renderTarget.mSize.get(renderWidth(), renderHeight());
subPass.mStateSet->setAttributeAndModes(new osg::Viewport(0, 0, w, h));

subPass.mRenderTexture->setTextureSize(w, h);
subPass.mRenderTexture->dirtyTextureObject();

subPass.mRenderTarget = new osg::FrameBufferObject;
subPass.mRenderTarget->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0,
osg::FrameBufferAttachment(subPass.mRenderTexture));

const auto [w, h] = renderTarget.mSize.get(renderWidth(), renderHeight());
subPass.mStateSet->setAttributeAndModes(new osg::Viewport(0, 0, w, h));

if (std::find_if(attachmentsToDirty.cbegin(), attachmentsToDirty.cend(),
[renderTarget](const auto& rt) { return renderTarget.mTarget == rt.mTarget; })
== attachmentsToDirty.cend())
Expand Down

0 comments on commit fc7c141

Please sign in to comment.