core: refactor renderable size ownership (#4512)

This commit is contained in:
Bart Louwers
2026-09-01 17:35:29 +02:00
committed by GitHub
parent be3f03b86e
commit e5d0fce32a
35 changed files with 131 additions and 122 deletions

View File

@@ -57,7 +57,7 @@ private:
};
OffscreenTexture::OffscreenTexture(gl::Context& context, const Size size_, const gfx::TextureChannelDataType type)
: gfx::OffscreenTexture(size, std::make_unique<OffscreenTextureResource>(context, size_, type)) {}
: gfx::OffscreenTexture(size_, std::make_unique<OffscreenTextureResource>(context, size_, type)) {}
bool OffscreenTexture::isRenderable() {
try {

View File

@@ -134,7 +134,7 @@ private:
OffscreenTexture::OffscreenTexture(
Context& context, const Size size_, const gfx::TextureChannelDataType type, bool depth, bool stencil)
: gfx::OffscreenTexture(size, std::make_unique<OffscreenTextureResource>(context, size_, type, depth, stencil)) {}
: gfx::OffscreenTexture(size_, std::make_unique<OffscreenTextureResource>(context, size_, type, depth, stencil)) {}
bool OffscreenTexture::isRenderable() {
assert(false);

View File

@@ -4,7 +4,6 @@
#include <mln/gfx/drawable.hpp>
#include <mln/renderer/layer_group.hpp>
#include <mln/renderer/paint_parameters.hpp>
#include <mln/renderer/render_static_data.hpp>
#include <mln/renderer/render_tree.hpp>
#include <mln/shaders/heatmap_texture_layer_ubo.hpp>
#include <mln/style/layers/heatmap_layer_properties.hpp>
@@ -30,7 +29,7 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint
propertiesUpdated = false;
mat4 matrix;
const auto& size = parameters.staticData.backendSize;
const auto& size = parameters.renderableSize;
matrix::ortho(matrix, 0, size.width, size.height, 0, -1, 1);
const HeatmapTexturePropsUBO propsUBO = {.matrix = util::cast<float>(matrix),

View File

@@ -66,6 +66,7 @@ PaintParameters::PaintParameters(gfx::Context& context_,
double tileLodScale_,
double tileLodPitchThreshold_,
TileLodMode tileLodMode_,
Size renderableSize_,
const gfx::ScissorRect& scissorRect_)
: context(context_),
backend(backend_),
@@ -80,6 +81,7 @@ PaintParameters::PaintParameters(gfx::Context& context_,
debugOptions(debugOptions_),
timePoint(timePoint_),
pixelRatio(pixelRatio_),
renderableSize(renderableSize_),
shaders(*staticData_.shaders),
frameCount(frameCount_),
tileLodMinRadius(tileLodMinRadius_),

View File

@@ -63,6 +63,7 @@ public:
double tileLodScale,
double tileLodPitchThreshold,
TileLodMode tileLodMode,
Size renderableSize,
const gfx::ScissorRect&);
~PaintParameters();
@@ -85,6 +86,7 @@ public:
TimePoint timePoint;
float pixelRatio;
const Size renderableSize;
std::array<float, 2> pixelsToGLUnits;
gfx::ShaderRegistry& shaders;

View File

@@ -48,7 +48,6 @@ public:
std::optional<gfx::Renderbuffer<gfx::RenderbufferPixelType::Depth>> depthRenderbuffer;
bool has3D = false;
bool uploaded = false;
Size backendSize;
std::unique_ptr<gfx::ShaderRegistry> shaders;

View File

@@ -181,7 +181,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
const auto& renderTreeParameters = renderTree.getParameters();
staticData->has3D = renderTreeParameters.has3D;
staticData->backendSize = backend.getDefaultRenderable().getSize();
const Size renderableSize = backend.getDefaultRenderable().getSize();
if (renderState == RenderState::Never) {
observer->onWillStartRenderingMap();
@@ -190,7 +190,6 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
observer->onWillStartRenderingFrame();
const TransformState& state = renderTreeParameters.transformParams.state;
const Size& size = staticData->backendSize;
const EdgeInsets& frustumOffset = state.getFrustumOffset();
const gfx::ScissorRect scissorRect = {
.x = static_cast<int32_t>(frustumOffset.left() * pixelRatio),
@@ -199,8 +198,10 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
#else
.y = static_cast<int32_t>(frustumOffset.top() * pixelRatio),
#endif
.width = size.width - static_cast<uint32_t>((frustumOffset.left() + frustumOffset.right()) * pixelRatio),
.height = size.height - static_cast<uint32_t>((frustumOffset.top() + frustumOffset.bottom()) * pixelRatio),
.width = renderableSize.width -
static_cast<uint32_t>((frustumOffset.left() + frustumOffset.right()) * pixelRatio),
.height = renderableSize.height -
static_cast<uint32_t>((frustumOffset.top() + frustumOffset.bottom()) * pixelRatio),
};
PaintParameters parameters{
@@ -220,6 +221,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
updateParameters->tileLodScale,
updateParameters->tileLodPitchThreshold,
updateParameters->tileLodMode,
renderableSize,
scissorRect,
};
@@ -297,7 +299,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
}
const Size atlasSize = parameters.patternAtlas.getPixelSize();
const auto& worldSize = parameters.staticData.backendSize;
const auto& worldSize = parameters.renderableSize;
const shaders::GlobalPaintParamsUBO globalPaintParamsUBO = {
.pattern_atlas_texsize = {static_cast<float>(atlasSize.width), static_cast<float>(atlasSize.height)},
.units_to_pixels = {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]},
@@ -318,8 +320,6 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
// attachments, but share the same depth rbo between them.
const auto common3DPass = [&] {
if (parameters.staticData.has3D) {
parameters.staticData.backendSize = parameters.backend.getDefaultRenderable().getSize();
const auto debugGroup(parameters.encoder->createDebugGroup("common-3d"));
parameters.pass = RenderPass::Pass3D;
#if MLN_RENDER_BACKEND_OPENGL
@@ -328,10 +328,10 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
// TODO is this needed?
// if (!parameters.staticData.depthRenderbuffer ||
// parameters.staticData.depthRenderbuffer->getSize() != parameters.staticData.backendSize) {
// parameters.staticData.depthRenderbuffer->getSize() != parameters.renderableSize) {
// parameters.staticData.depthRenderbuffer =
// parameters.context.createRenderbuffer<gfx::RenderbufferPixelType::Depth>(
// parameters.staticData.backendSize);
// parameters.renderableSize);
//}
// parameters.staticData.depthRenderbuffer->setShouldClear(true);
}

View File

@@ -133,7 +133,7 @@ OffscreenTexture::OffscreenTexture(Context& context,
const gfx::TextureChannelDataType type,
[[maybe_unused]] bool depth,
[[maybe_unused]] bool stencil)
: gfx::OffscreenTexture(size, std::make_unique<OffscreenTextureResource>(context.getBackend(), size_, type)) {
: gfx::OffscreenTexture(size_, std::make_unique<OffscreenTextureResource>(context.getBackend(), size_, type)) {
assert(!depth);
assert(!stencil);
}

View File

@@ -107,7 +107,7 @@ public:
wgpu::TextureView offscreenTextureView;
wgpu::Texture depthTexture;
wgpu::TextureView depthTextureView;
Size framebufferSize;
Size offscreenTextureSize;
};
HeadlessBackend::HeadlessBackend(Size size_, SwapBehaviour swapBehaviour_, gfx::ContextMode mode)
@@ -116,8 +116,6 @@ HeadlessBackend::HeadlessBackend(Size size_, SwapBehaviour swapBehaviour_, gfx::
impl(std::make_unique<Impl>()) {
static_cast<void>(swapBehaviour_);
impl->framebufferSize = size_;
#if MLN_WEBGPU_IMPL_DAWN
// Initialize Dawn instance with TimedWaitAny feature enabled
wgpu::InstanceFeatureName timedWaitAnyFeature = wgpu::InstanceFeatureName::TimedWaitAny;
@@ -221,6 +219,9 @@ HeadlessBackend::~HeadlessBackend() {
void HeadlessBackend::createOffscreenTextures() {
if (!impl->device) return;
const auto renderableSize = getSize();
impl->offscreenTextureSize = renderableSize;
// Release old textures if they exist
impl->offscreenTextureView = nullptr;
impl->offscreenTexture = nullptr;
@@ -236,8 +237,7 @@ void HeadlessBackend::createOffscreenTextures() {
#elif MLN_WEBGPU_IMPL_WGPU
colorDesc.dimension = wgpu::TextureDimension::_2D;
#endif
colorDesc.size = {
static_cast<uint32_t>(impl->framebufferSize.width), static_cast<uint32_t>(impl->framebufferSize.height), 1};
colorDesc.size = {renderableSize.width, renderableSize.height, 1};
colorDesc.format = wgpu::TextureFormat::RGBA8Unorm;
colorDesc.mipLevelCount = 1;
colorDesc.sampleCount = 1;
@@ -282,8 +282,7 @@ void HeadlessBackend::createOffscreenTextures() {
#elif MLN_WEBGPU_IMPL_WGPU
depthDesc.dimension = wgpu::TextureDimension::_2D;
#endif
depthDesc.size = {
static_cast<uint32_t>(impl->framebufferSize.width), static_cast<uint32_t>(impl->framebufferSize.height), 1};
depthDesc.size = {renderableSize.width, renderableSize.height, 1};
depthDesc.format = wgpu::TextureFormat::Depth24PlusStencil8;
depthDesc.mipLevelCount = 1;
depthDesc.sampleCount = 1;
@@ -323,8 +322,8 @@ void HeadlessBackend::createOffscreenTextures() {
gfx::Renderable& HeadlessBackend::getDefaultRenderable() {
if (!hasResource()) {
setResource(
std::make_unique<HeadlessRenderableResource>(*this, static_cast<webgpu::Context&>(getContext()), size));
setResource(std::make_unique<HeadlessRenderableResource>(
*this, static_cast<webgpu::Context&>(getContext()), getSize()));
}
return *this;
}
@@ -350,8 +349,7 @@ RendererBackend* HeadlessBackend::getRendererBackend() {
void HeadlessBackend::activate() {
active = true;
// Ensure textures are created if size changed
if (impl && impl->framebufferSize != getSize()) {
impl->framebufferSize = getSize();
if (impl && impl->offscreenTextureSize != getSize()) {
createOffscreenTextures();
}
}
@@ -375,9 +373,6 @@ void* HeadlessBackend::getDepthStencilView() {
}
mln::Size HeadlessBackend::getFramebufferSize() const {
if (impl) {
return impl->framebufferSize;
}
return getSize();
}

View File

@@ -354,7 +354,7 @@ OffscreenTexture::OffscreenTexture(
Context& context, const Size size_, const gfx::TextureChannelDataType type, bool depth, bool stencil)
: gfx::OffscreenTexture(size_, std::make_unique<OffscreenTextureResource>(context, size_, type, depth, stencil)) {
auto& offscreenResource = getResource<OffscreenTextureResource>();
offscreenResource.setSizeListener([this](const Size& newSize) { size = newSize; });
offscreenResource.setSizeListener([this](const Size& newSize) { setRenderableSize(newSize); });
}
bool OffscreenTexture::isRenderable() {