From 5c3f3911364f3a2b51cbef235e33579280e86d95 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 12 Jan 2022 18:31:32 -0400 Subject: [PATCH] update metal backend for projection changes. --- src/modules/graphics/metal/Graphics.h | 2 ++ src/modules/graphics/metal/Graphics.mm | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/graphics/metal/Graphics.h b/src/modules/graphics/metal/Graphics.h index 83e11e26a..7b833d63b 100644 --- a/src/modules/graphics/metal/Graphics.h +++ b/src/modules/graphics/metal/Graphics.h @@ -65,6 +65,8 @@ public: love::graphics::Texture *newTexture(const Texture::Settings &settings, const Texture::Slices *data = nullptr) override; love::graphics::Buffer *newBuffer(const Buffer::Settings &settings, const std::vector &format, const void *data, size_t size, size_t arraylength) override; + Matrix4 computeDeviceProjection(const Matrix4 &projection, bool rendertotexture) const override; + void setViewportSize(int width, int height, int pixelwidth, int pixelheight) override; bool setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool windowhasstencil, int msaa) override; void unSetMode() override; diff --git a/src/modules/graphics/metal/Graphics.mm b/src/modules/graphics/metal/Graphics.mm index 546a264b3..099ece420 100644 --- a/src/modules/graphics/metal/Graphics.mm +++ b/src/modules/graphics/metal/Graphics.mm @@ -418,6 +418,12 @@ love::graphics::Buffer *Graphics::newBuffer(const Buffer::Settings &settings, co return new Buffer(this, device, settings, format, data, size, arraylength); } +Matrix4 Graphics::computeDeviceProjection(const Matrix4 &projection, bool /*rendertotexture*/) const +{ + uint32 flags = DEVICE_PROJECTION_FLIP_Y; + return calculateDeviceProjection(projection, flags); +} + void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelheight) { this->width = width; @@ -428,9 +434,7 @@ void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelh if (!isRenderTargetActive()) { dirtyRenderState |= STATEBIT_VIEWPORT | STATEBIT_SCISSOR; - - // Set up the projection matrix - projectionMatrix = Matrix4::ortho(0.0, (float) width, (float) height, 0.0, -10.0f, 10.0f); + resetProjection(); } Texture::Settings settings; @@ -1009,7 +1013,7 @@ void Graphics::applyShaderUniforms(id renderEncoder, lo auto builtins = (Shader::BuiltinUniformData *) (bufferdata + s->getBuiltinUniformDataOffset()); builtins->transformMatrix = getTransform(); - builtins->projectionMatrix = getProjection(); + builtins->projectionMatrix = getDeviceProjection(); // The normal matrix is the transpose of the inverse of the rotation portion // (top-left 3x3) of the transform matrix. @@ -1299,7 +1303,7 @@ bool Graphics::dispatch(int x, int y, int z) return true; }} -void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int /*pixelw*/, int /*pixelh*/, bool /*hasSRGBtexture*/) +void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int /*w*/, int /*h*/, int /*pixelw*/, int /*pixelh*/, bool /*hasSRGBtexture*/) { @autoreleasepool { endPass(); @@ -1336,7 +1340,6 @@ void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int w, int h, setAttachment(rt, passDesc.stencilAttachment, attachmentStoreActions.stencil); } - projectionMatrix = Matrix4::ortho(0.0, (float) w, (float) h, 0.0, -10.0f, 10.0f); dirtyRenderState = STATEBIT_ALL; lastVertexAttributes = VertexAttributes(); }}