core: refactor renderable size ownership (#4512)
This commit is contained in:
@@ -34,6 +34,7 @@ protected:
|
||||
virtual ~Renderable() = default;
|
||||
|
||||
public:
|
||||
/// Returns the renderable dimensions in physical pixels.
|
||||
Size getSize() const { return size; }
|
||||
|
||||
template <typename T>
|
||||
@@ -50,8 +51,12 @@ public:
|
||||
|
||||
bool operator!=(const Renderable& other) const { return resource.get() != other.resource.get(); }
|
||||
|
||||
protected:
|
||||
private:
|
||||
Size size;
|
||||
|
||||
protected:
|
||||
void setRenderableSize(const Size& size_) noexcept { size = size_; }
|
||||
|
||||
std::unique_ptr<RenderableResource> resource;
|
||||
};
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ protected:
|
||||
~Renderable() override = default;
|
||||
|
||||
public:
|
||||
void setSize(const Size& size_) { size = size_; }
|
||||
void setSize(const Size& size_) { setRenderableSize(size_); }
|
||||
};
|
||||
|
||||
} // namespace vulkan
|
||||
|
||||
@@ -46,21 +46,21 @@ gl::ProcAddress AndroidGLRendererBackend::getExtensionFunctionPointer(const char
|
||||
|
||||
void AndroidGLRendererBackend::updateViewPort() {
|
||||
assert(gfx::BackendScope::exists());
|
||||
setViewport(0, 0, size);
|
||||
setViewport(0, 0, getSize());
|
||||
}
|
||||
|
||||
void AndroidGLRendererBackend::resizeFramebuffer(int width, int height) {
|
||||
size = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||
setRenderableSize({static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
|
||||
}
|
||||
|
||||
PremultipliedImage AndroidGLRendererBackend::readFramebuffer() {
|
||||
assert(gfx::BackendScope::exists());
|
||||
return gl::RendererBackend::readFramebuffer(size);
|
||||
return gl::RendererBackend::readFramebuffer(getSize());
|
||||
}
|
||||
|
||||
void AndroidGLRendererBackend::updateAssumedState() {
|
||||
assumeFramebufferBinding(0);
|
||||
assumeViewport(0, 0, size);
|
||||
assumeViewport(0, 0, getSize());
|
||||
}
|
||||
|
||||
void AndroidGLRendererBackend::markContextLost() {
|
||||
|
||||
@@ -160,8 +160,6 @@ public:
|
||||
WGPUTexture currentTexture = nullptr;
|
||||
WGPUTextureView currentTextureView = nullptr;
|
||||
bool needsPresent = false;
|
||||
|
||||
Size framebufferSize;
|
||||
};
|
||||
|
||||
AndroidWebGPURendererBackend::AndroidWebGPURendererBackend(ANativeWindow* window_)
|
||||
@@ -303,9 +301,8 @@ AndroidWebGPURendererBackend::AndroidWebGPURendererBackend(ANativeWindow* window
|
||||
const int w = ANativeWindow_getWidth(window);
|
||||
const int h = ANativeWindow_getHeight(window);
|
||||
if (w > 0 && h > 0) {
|
||||
impl->framebufferSize = {static_cast<uint32_t>(w), static_cast<uint32_t>(h)};
|
||||
size = impl->framebufferSize;
|
||||
configureSurface(impl->framebufferSize.width, impl->framebufferSize.height);
|
||||
setRenderableSize({static_cast<uint32_t>(w), static_cast<uint32_t>(h)});
|
||||
configureSurface(static_cast<uint32_t>(w), static_cast<uint32_t>(h));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,8 +505,7 @@ void AndroidWebGPURendererBackend::createDepthStencilTexture(uint32_t width, uin
|
||||
void AndroidWebGPURendererBackend::resizeFramebuffer(int width, int height) {
|
||||
if (width <= 0 || height <= 0) return;
|
||||
|
||||
impl->framebufferSize = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||
size = impl->framebufferSize;
|
||||
setRenderableSize({static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
|
||||
|
||||
if (impl->currentTextureView) {
|
||||
wgpuTextureViewRelease(impl->currentTextureView);
|
||||
@@ -520,16 +516,16 @@ void AndroidWebGPURendererBackend::resizeFramebuffer(int width, int height) {
|
||||
impl->currentTexture = nullptr;
|
||||
}
|
||||
|
||||
configureSurface(impl->framebufferSize.width, impl->framebufferSize.height);
|
||||
configureSurface(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
|
||||
}
|
||||
|
||||
PremultipliedImage AndroidWebGPURendererBackend::readFramebuffer() {
|
||||
if (!impl->currentTexture || !impl->device || !impl->queue || impl->framebufferSize.width == 0 ||
|
||||
impl->framebufferSize.height == 0) {
|
||||
return PremultipliedImage(impl->framebufferSize.isEmpty() ? Size(2, 2) : impl->framebufferSize);
|
||||
const auto framebufferSize = getSize();
|
||||
if (!impl->currentTexture || !impl->device || !impl->queue || framebufferSize.isEmpty()) {
|
||||
return PremultipliedImage(framebufferSize.isEmpty() ? Size(2, 2) : framebufferSize);
|
||||
}
|
||||
|
||||
const auto& fbSize = impl->framebufferSize;
|
||||
const auto& fbSize = framebufferSize;
|
||||
constexpr uint32_t bytesPerPixel = 4;
|
||||
constexpr uint32_t bytesPerRowAlignment = 256u;
|
||||
const uint32_t rowStride = fbSize.width * bytesPerPixel;
|
||||
@@ -683,7 +679,8 @@ void* AndroidWebGPURendererBackend::getCurrentTextureView() {
|
||||
auto status = static_cast<WGPUSurfaceGetCurrentTextureStatus>(surfaceTexture.status);
|
||||
if (status == WGPUSurfaceGetCurrentTextureStatus_Outdated || status == WGPUSurfaceGetCurrentTextureStatus_Lost) {
|
||||
wgpuTextureRelease(surfaceTexture.texture);
|
||||
configureSurface(impl->framebufferSize.width, impl->framebufferSize.height);
|
||||
const auto framebufferSize = getSize();
|
||||
configureSurface(framebufferSize.width, framebufferSize.height);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -698,10 +695,9 @@ void* AndroidWebGPURendererBackend::getCurrentTextureView() {
|
||||
// Actual texture size may differ from configured size (Vulkan currentExtent clamping)
|
||||
const uint32_t texW = wgpuTextureGetWidth(surfaceTexture.texture);
|
||||
const uint32_t texH = wgpuTextureGetHeight(surfaceTexture.texture);
|
||||
if (texW != size.width || texH != size.height) {
|
||||
if (const auto framebufferSize = getSize(); texW != framebufferSize.width || texH != framebufferSize.height) {
|
||||
if (texW > 0 && texH > 0) {
|
||||
size = {texW, texH};
|
||||
impl->framebufferSize = size;
|
||||
setRenderableSize({texW, texH});
|
||||
createDepthStencilTexture(texW, texH);
|
||||
}
|
||||
}
|
||||
@@ -759,7 +755,7 @@ void* AndroidWebGPURendererBackend::getDepthStencilView() {
|
||||
}
|
||||
|
||||
mln::Size AndroidWebGPURendererBackend::getFramebufferSize() const {
|
||||
return impl->framebufferSize;
|
||||
return getSize();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
@@ -9,7 +9,7 @@ HeadlessBackend::HeadlessBackend(Size size_)
|
||||
: mln::gfx::Renderable(size_, nullptr) {}
|
||||
|
||||
void HeadlessBackend::setSize(Size size_) {
|
||||
size = size_;
|
||||
setRenderableSize(size_);
|
||||
resource.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ gfx::Renderable& HeadlessBackend::getDefaultRenderable() {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
if (!resource) {
|
||||
resource = std::make_unique<HeadlessRenderableResource>(*this, static_cast<gl::Context&>(getContext()), size);
|
||||
resource = std::make_unique<HeadlessRenderableResource>(
|
||||
*this, static_cast<gl::Context&>(getContext()), getSize());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -115,7 +116,7 @@ void HeadlessBackend::updateAssumedState() {
|
||||
PremultipliedImage HeadlessBackend::readStillImage() {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
return static_cast<gl::Context&>(getContext()).readFramebuffer<PremultipliedImage>(size);
|
||||
return static_cast<gl::Context&>(getContext()).readFramebuffer<PremultipliedImage>(getSize());
|
||||
}
|
||||
|
||||
RendererBackend* HeadlessBackend::getRendererBackend() {
|
||||
|
||||
@@ -83,7 +83,8 @@ gfx::Renderable& HeadlessBackend::getDefaultRenderable() {
|
||||
|
||||
void HeadlessBackend::ensureResource() {
|
||||
if (!resource) {
|
||||
resource = std::make_unique<HeadlessRenderableResource>(*this, static_cast<mtl::Context&>(getContext()), size);
|
||||
resource = std::make_unique<HeadlessRenderableResource>(
|
||||
*this, static_cast<mtl::Context&>(getContext()), getSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,6 @@ public:
|
||||
}
|
||||
|
||||
virtual mln::gfx::RendererBackend& getRendererBackend() = 0;
|
||||
virtual mln::Size getSize() const = 0;
|
||||
virtual void setSize(mln::Size) = 0;
|
||||
virtual mln::Size getFramebufferSize() const = 0;
|
||||
virtual void setFramebufferSize(mln::Size) = 0;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
backend.setFramebufferBinding(0);
|
||||
backend.setViewport(0, 0, backend.getSize());
|
||||
backend.setViewport(0, 0, backend.getFramebufferSize());
|
||||
}
|
||||
|
||||
void swap() override {
|
||||
@@ -72,15 +72,15 @@ void GLFWGLBackend::updateAssumedState() {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
assumeFramebufferBinding(0);
|
||||
setViewport(0, 0, size);
|
||||
setViewport(0, 0, getSize());
|
||||
}
|
||||
|
||||
mln::Size GLFWGLBackend::getSize() const {
|
||||
return size;
|
||||
mln::Size GLFWGLBackend::getFramebufferSize() const {
|
||||
return getSize();
|
||||
}
|
||||
|
||||
void GLFWGLBackend::setSize(const mln::Size newSize) {
|
||||
size = newSize;
|
||||
void GLFWGLBackend::setFramebufferSize(const mln::Size newSize) {
|
||||
setRenderableSize(newSize);
|
||||
}
|
||||
|
||||
void GLFWGLBackend::swap() {
|
||||
|
||||
@@ -17,8 +17,8 @@ public:
|
||||
// GLFWRendererBackend implementation
|
||||
public:
|
||||
mln::gfx::RendererBackend& getRendererBackend() override { return *this; }
|
||||
mln::Size getSize() const override;
|
||||
void setSize(mln::Size) override;
|
||||
mln::Size getFramebufferSize() const override;
|
||||
void setFramebufferSize(mln::Size) override;
|
||||
|
||||
// mln::gfx::RendererBackend implementation
|
||||
public:
|
||||
|
||||
@@ -14,8 +14,8 @@ public:
|
||||
GLFWMetalBackend(GLFWwindow *window_, const bool capFrameRate);
|
||||
~GLFWMetalBackend() = default;
|
||||
mln::gfx::RendererBackend &getRendererBackend() override;
|
||||
void setSize(mln::Size) override;
|
||||
mln::Size getSize() const override;
|
||||
void setFramebufferSize(mln::Size) override;
|
||||
mln::Size getFramebufferSize() const override;
|
||||
|
||||
private:
|
||||
NSWindow *window;
|
||||
|
||||
@@ -11,6 +11,6 @@ GLFWMetalBackend::GLFWMetalBackend(GLFWwindow* window_, [[maybe_unused]] const b
|
||||
|
||||
mln::gfx::RendererBackend& GLFWMetalBackend::getRendererBackend() { return rendererBackend; }
|
||||
|
||||
void GLFWMetalBackend::setSize(mln::Size size) { rendererBackend.setSize(size); }
|
||||
void GLFWMetalBackend::setFramebufferSize(mln::Size size) { rendererBackend.setSize(size); }
|
||||
|
||||
mln::Size GLFWMetalBackend::getSize() const { return rendererBackend.getSize(); }
|
||||
mln::Size GLFWMetalBackend::getFramebufferSize() const { return rendererBackend.getSize(); }
|
||||
|
||||
@@ -312,10 +312,10 @@ GLFWView::GLFWView(bool fullscreen_,
|
||||
#if defined(__APPLE__) && !defined(MLN_RENDER_BACKEND_VULKAN)
|
||||
int fbW, fbH;
|
||||
glfwGetFramebufferSize(window, &fbW, &fbH);
|
||||
backend->setSize({static_cast<uint32_t>(fbW), static_cast<uint32_t>(fbH)});
|
||||
backend->setFramebufferSize({static_cast<uint32_t>(fbW), static_cast<uint32_t>(fbH)});
|
||||
#endif
|
||||
|
||||
pixelRatio = static_cast<float>(backend->getSize().width) / width;
|
||||
pixelRatio = static_cast<float>(backend->getFramebufferSize().width) / width;
|
||||
|
||||
glfwMakeContextCurrent(nullptr);
|
||||
|
||||
@@ -1026,7 +1026,7 @@ void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
|
||||
#ifdef __APPLE__
|
||||
int fbW, fbH;
|
||||
glfwGetFramebufferSize(window, &fbW, &fbH);
|
||||
view->backend->setSize({static_cast<uint32_t>(fbW), static_cast<uint32_t>(fbH)});
|
||||
view->backend->setFramebufferSize({static_cast<uint32_t>(fbW), static_cast<uint32_t>(fbH)});
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1034,7 +1034,7 @@ void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
|
||||
view->backend->setSize({static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
|
||||
view->backend->setFramebufferSize({static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
|
||||
|
||||
// This is only triggered when the framebuffer is resized, but not the
|
||||
// window. It can happen when you move the window between screens with a
|
||||
|
||||
@@ -156,12 +156,12 @@ GLFWVulkanBackend::GLFWVulkanBackend(GLFWwindow* window_, const bool capFrameRat
|
||||
|
||||
GLFWVulkanBackend::~GLFWVulkanBackend() {}
|
||||
|
||||
mln::Size GLFWVulkanBackend::getSize() const {
|
||||
return size;
|
||||
mln::Size GLFWVulkanBackend::getFramebufferSize() const {
|
||||
return getSize();
|
||||
}
|
||||
|
||||
void GLFWVulkanBackend::setSize(const mln::Size newSize) {
|
||||
size = newSize;
|
||||
void GLFWVulkanBackend::setFramebufferSize(const mln::Size newSize) {
|
||||
setRenderableSize(newSize);
|
||||
|
||||
auto& contextImpl = static_cast<mln::vulkan::Context&>(*context);
|
||||
contextImpl.requestSurfaceUpdate();
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
// GLFWRendererBackend implementation
|
||||
public:
|
||||
mln::gfx::RendererBackend& getRendererBackend() override { return *this; }
|
||||
mln::Size getSize() const override;
|
||||
void setSize(mln::Size) override;
|
||||
mln::Size getFramebufferSize() const override;
|
||||
void setFramebufferSize(mln::Size) override;
|
||||
|
||||
// mln::gfx::RendererBackend implementation
|
||||
public:
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
// GLFWBackend implementation
|
||||
public:
|
||||
mln::gfx::RendererBackend& getRendererBackend() override;
|
||||
mln::Size getSize() const override;
|
||||
void setSize(mln::Size) override;
|
||||
mln::Size getFramebufferSize() const override;
|
||||
void setFramebufferSize(mln::Size) override;
|
||||
|
||||
// mln::gfx::RendererBackend implementation
|
||||
public:
|
||||
@@ -50,7 +50,6 @@ public:
|
||||
// Override virtual methods from RendererBackend
|
||||
void* getCurrentTextureView() override;
|
||||
void* getDepthStencilView() override;
|
||||
mln::Size getFramebufferSize() const override;
|
||||
|
||||
private:
|
||||
class SpinLock {
|
||||
|
||||
@@ -896,13 +896,13 @@ void GLFWWebGPUBackend::deactivate() {
|
||||
// WebGPU doesn't need explicit context deactivation like OpenGL
|
||||
}
|
||||
|
||||
mln::Size GLFWWebGPUBackend::getSize() const {
|
||||
return size;
|
||||
mln::Size GLFWWebGPUBackend::getFramebufferSize() const {
|
||||
return getSize();
|
||||
}
|
||||
|
||||
void GLFWWebGPUBackend::setSize(mln::Size newSize) {
|
||||
void GLFWWebGPUBackend::setFramebufferSize(mln::Size newSize) {
|
||||
// Update swap chain size if needed
|
||||
if (size != newSize) {
|
||||
if (getSize() != newSize) {
|
||||
#ifdef __APPLE__
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
@@ -918,7 +918,7 @@ void GLFWWebGPUBackend::setSize(mln::Size newSize) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
size = newSize;
|
||||
setRenderableSize(newSize);
|
||||
surfaceNeedsReconfigure = true;
|
||||
}
|
||||
}
|
||||
@@ -1066,10 +1066,6 @@ void* GLFWWebGPUBackend::getCurrentTextureView() {
|
||||
#endif
|
||||
}
|
||||
|
||||
mln::Size GLFWWebGPUBackend::getFramebufferSize() const {
|
||||
return getSize();
|
||||
}
|
||||
|
||||
void* GLFWWebGPUBackend::getDepthStencilView() {
|
||||
std::lock_guard<SpinLock> guard(textureStateLock);
|
||||
if (!depthStencilView) {
|
||||
@@ -1126,7 +1122,8 @@ void GLFWWebGPUBackend::reconfigureSurface() {
|
||||
return;
|
||||
}
|
||||
|
||||
size = {static_cast<uint32_t>(std::max(width, 0)), static_cast<uint32_t>(std::max(height, 0))};
|
||||
setRenderableSize(
|
||||
{static_cast<uint32_t>(std::max(width, 0)), static_cast<uint32_t>(std::max(height, 0))});
|
||||
|
||||
// Configure surface
|
||||
wgpu::SurfaceConfiguration config = {};
|
||||
|
||||
@@ -15,5 +15,4 @@ public:
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
void setSize(mln::Size size_);
|
||||
mln::Size getSize() const;
|
||||
};
|
||||
|
||||
@@ -19,15 +19,12 @@ public:
|
||||
swapchain->setDevice(backend.getDevice().get());
|
||||
}
|
||||
|
||||
void setBackendSize(mln::Size size_) {
|
||||
size = size_;
|
||||
void setDrawableSize(const mln::Size& drawableSize) {
|
||||
swapchain->setDrawableSize(
|
||||
{static_cast<CGFloat>(size.width), static_cast<CGFloat>(size.height)});
|
||||
{static_cast<CGFloat>(drawableSize.width), static_cast<CGFloat>(drawableSize.height)});
|
||||
buffersInvalid = true;
|
||||
}
|
||||
|
||||
mln::Size getSize() const { return size; }
|
||||
|
||||
void bind() override {
|
||||
surface = NS::TransferPtr(swapchain->nextDrawable());
|
||||
auto texSize = mln::Size{static_cast<uint32_t>(swapchain->drawableSize().width),
|
||||
@@ -107,7 +104,6 @@ private:
|
||||
CAMetalLayerPtr swapchain;
|
||||
gfx::Texture2DPtr depthTexture;
|
||||
gfx::Texture2DPtr stencilTexture;
|
||||
mln::Size size;
|
||||
bool buffersInvalid = true;
|
||||
};
|
||||
|
||||
@@ -129,10 +125,6 @@ void MetalBackend::activate() {}
|
||||
void MetalBackend::deactivate() {}
|
||||
|
||||
void MetalBackend::setSize(mln::Size size_) {
|
||||
size = size_;
|
||||
getResource<mln::MetalRenderableResource>().setBackendSize(size_);
|
||||
}
|
||||
|
||||
mln::Size MetalBackend::getSize() const {
|
||||
return getResource<mln::MetalRenderableResource>().getSize();
|
||||
setRenderableSize(size_);
|
||||
getResource<mln::MetalRenderableResource>().setDrawableSize(size_);
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ void MLNMapViewMetalImpl::layoutChanged() {
|
||||
resource.mtlView.drawableSize = resource.lastAppliedDrawableSize = target;
|
||||
}
|
||||
|
||||
size = {static_cast<uint32_t>(target.width), static_cast<uint32_t>(target.height)};
|
||||
setRenderableSize({static_cast<uint32_t>(target.width), static_cast<uint32_t>(target.height)});
|
||||
}
|
||||
|
||||
MLNBackendResource* MLNMapViewMetalImpl::getObject() {
|
||||
|
||||
@@ -241,8 +241,8 @@ UIImage* MLNMapViewOpenGLImpl::snapshot() {
|
||||
|
||||
void MLNMapViewOpenGLImpl::layoutChanged() {
|
||||
const auto scaleFactor = contentScaleFactor();
|
||||
size = {static_cast<uint32_t>(mapView.bounds.size.width * scaleFactor),
|
||||
static_cast<uint32_t>(mapView.bounds.size.height * scaleFactor)};
|
||||
setRenderableSize({static_cast<uint32_t>(mapView.bounds.size.width * scaleFactor),
|
||||
static_cast<uint32_t>(mapView.bounds.size.height * scaleFactor)});
|
||||
}
|
||||
|
||||
EAGLContext* MLNMapViewOpenGLImpl::getEAGLContext() {
|
||||
|
||||
@@ -94,8 +94,6 @@ public:
|
||||
WGPUTextureView currentTextureView = nullptr;
|
||||
bool needsPresent = false;
|
||||
|
||||
mln::Size framebufferSize;
|
||||
|
||||
MLNWebGPUView* webGPUView = nil;
|
||||
bool presentsWithTransaction = false;
|
||||
NSUInteger activationCount = 0;
|
||||
@@ -316,8 +314,7 @@ void MLNMapViewWebGPUImpl::createView() {
|
||||
uint32_t w = static_cast<uint32_t>(drawableSize.width);
|
||||
uint32_t h = static_cast<uint32_t>(drawableSize.height);
|
||||
if (w > 0 && h > 0) {
|
||||
impl->framebufferSize = {w, h};
|
||||
size = impl->framebufferSize;
|
||||
setRenderableSize({w, h});
|
||||
configureSurface(w, h);
|
||||
}
|
||||
}
|
||||
@@ -497,7 +494,8 @@ void* MLNMapViewWebGPUImpl::getCurrentTextureView() {
|
||||
if (status == WGPUSurfaceGetCurrentTextureStatus_Outdated ||
|
||||
status == WGPUSurfaceGetCurrentTextureStatus_Lost) {
|
||||
wgpuTextureRelease(surfaceTexture.texture);
|
||||
configureSurface(impl->framebufferSize.width, impl->framebufferSize.height);
|
||||
const auto framebufferSize = getSize();
|
||||
configureSurface(framebufferSize.width, framebufferSize.height);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -557,7 +555,7 @@ void MLNMapViewWebGPUImpl::presentSurface() {
|
||||
|
||||
void* MLNMapViewWebGPUImpl::getDepthStencilView() { return impl->depthStencilView; }
|
||||
|
||||
mln::Size MLNMapViewWebGPUImpl::getFramebufferSize() const { return impl->framebufferSize; }
|
||||
mln::Size MLNMapViewWebGPUImpl::getFramebufferSize() const { return getSize(); }
|
||||
|
||||
UIView* MLNMapViewWebGPUImpl::getView() { return impl->webGPUView; }
|
||||
|
||||
@@ -624,8 +622,7 @@ void MLNMapViewWebGPUImpl::layoutChanged() {
|
||||
uint32_t w = static_cast<uint32_t>(drawableSize.width);
|
||||
uint32_t h = static_cast<uint32_t>(drawableSize.height);
|
||||
|
||||
impl->framebufferSize = {w, h};
|
||||
size = impl->framebufferSize;
|
||||
setRenderableSize({w, h});
|
||||
|
||||
if (impl->currentTextureView) {
|
||||
wgpuTextureViewRelease(impl->currentTextureView);
|
||||
@@ -642,12 +639,12 @@ void MLNMapViewWebGPUImpl::layoutChanged() {
|
||||
}
|
||||
|
||||
UIImage* MLNMapViewWebGPUImpl::snapshot() {
|
||||
if (!impl->currentTexture || !impl->device || !impl->queue || impl->framebufferSize.width == 0 ||
|
||||
impl->framebufferSize.height == 0) {
|
||||
const auto framebufferSize = getSize();
|
||||
if (!impl->currentTexture || !impl->device || !impl->queue || framebufferSize.isEmpty()) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
const auto& fbSize = impl->framebufferSize;
|
||||
const auto& fbSize = framebufferSize;
|
||||
constexpr uint32_t bytesPerPixel = 4;
|
||||
constexpr uint32_t bytesPerRowAlignment = 256u;
|
||||
const uint32_t rowStride = fbSize.width * bytesPerPixel;
|
||||
|
||||
@@ -139,7 +139,8 @@ MLNMapViewMetalImpl::MLNMapViewMetalImpl(MLNMapView* nativeView_)
|
||||
}
|
||||
|
||||
void MLNMapViewMetalImpl::drawableSizeChanged(CGSize drawableSize) {
|
||||
size = {static_cast<uint32_t>(drawableSize.width), static_cast<uint32_t>(drawableSize.height)};
|
||||
setRenderableSize(
|
||||
{static_cast<uint32_t>(drawableSize.width), static_cast<uint32_t>(drawableSize.height)});
|
||||
}
|
||||
|
||||
MLNMapViewMetalImpl::~MLNMapViewMetalImpl() = default;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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_),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -21,6 +21,7 @@ add_library(
|
||||
${PROJECT_SOURCE_DIR}/test/plugin/plugin.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/renderer/image_manager.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/renderer/pattern_atlas.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/renderer/renderable.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/renderer/shader_registry.test.cpp
|
||||
$<$<BOOL:${MLN_WITH_WEBGPU}>:${PROJECT_SOURCE_DIR}/test/renderer/wgsl_preprocessor.test.cpp>
|
||||
${PROJECT_SOURCE_DIR}/test/sprite/sprite_loader.test.cpp
|
||||
|
||||
23
test/renderer/renderable.test.cpp
Normal file
23
test/renderer/renderable.test.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <mln/test/util.hpp>
|
||||
|
||||
#include <mln/gfx/renderable.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
class TestRenderable final : public mln::gfx::Renderable {
|
||||
public:
|
||||
explicit TestRenderable(mln::Size size_)
|
||||
: Renderable(size_, nullptr) {}
|
||||
|
||||
void resize(const mln::Size& size_) { setRenderableSize(size_); }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(Renderable, MaintainsCanonicalPhysicalSize) {
|
||||
TestRenderable renderable({256, 128});
|
||||
EXPECT_EQ(renderable.getSize(), (mln::Size{256, 128}));
|
||||
|
||||
renderable.resize({512, 384});
|
||||
EXPECT_EQ(renderable.getSize(), (mln::Size{512, 384}));
|
||||
}
|
||||
Reference in New Issue
Block a user