1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Merge branch 'its_just_a_render_target' into 'master'

Update render targets outside of draw thread

See merge request OpenMW/openmw!4361
This commit is contained in:
psi29a 2024-09-09 07:15:18 +00:00
commit fc7c141f3b
2 changed files with 6 additions and 22 deletions

View file

@ -278,25 +278,6 @@ namespace MWRender
if (pass.mRenderTarget) 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); pass.mRenderTarget->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);
if (pass.mRenderTexture->getNumMipmapLevels() > 0) if (pass.mRenderTexture->getNumMipmapLevels() > 0)

View file

@ -650,13 +650,16 @@ namespace MWRender
subPass.mRenderTexture = renderTarget.mTarget; subPass.mRenderTexture = renderTarget.mTarget;
subPass.mMipMap = renderTarget.mMipMap; 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 = new osg::FrameBufferObject;
subPass.mRenderTarget->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0, subPass.mRenderTarget->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0,
osg::FrameBufferAttachment(subPass.mRenderTexture)); 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(), if (std::find_if(attachmentsToDirty.cbegin(), attachmentsToDirty.cend(),
[renderTarget](const auto& rt) { return renderTarget.mTarget == rt.mTarget; }) [renderTarget](const auto& rt) { return renderTarget.mTarget == rt.mTarget; })
== attachmentsToDirty.cend()) == attachmentsToDirty.cend())