From 274245e39ccc198e552ded4b6a0f2d4c735b6983 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 8 May 2020 18:12:30 +0900 Subject: [PATCH] graphicsdriver/metal: Refactoring: Invert the viewport's Y direction --- internal/graphicsdriver/metal/graphics.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/internal/graphicsdriver/metal/graphics.go b/internal/graphicsdriver/metal/graphics.go index 0cace3c80..110821631 100644 --- a/internal/graphicsdriver/metal/graphics.go +++ b/internal/graphicsdriver/metal/graphics.go @@ -82,14 +82,8 @@ vertex VertexOut VertexShader( ); VertexIn in = vertices[vid]; - - // In Metal, the NDC's Y direction (upward) and the framebuffer's Y direction (downward) don't match. - // Then, the Y value must be inverted. - float4 pos = projectionMatrix * float4(in.position, 0, 1); - pos.y = -pos.y; - VertexOut out = { - .position = pos, + .position = projectionMatrix * float4(in.position, 0, 1), .tex = in.tex, .tex_region = in.tex_region, .color = in.color, @@ -613,8 +607,6 @@ func (g *Graphics) Draw(indexLen int, indexOffset int, mode driver.CompositeMode rpd.ColorAttachments[0].Texture = t rpd.ColorAttachments[0].ClearColor = mtl.ClearColor{} - w, h := g.dst.viewportSize() - if g.cb == (mtl.CommandBuffer{}) { g.cb = g.cq.MakeCommandBuffer() } @@ -631,11 +623,14 @@ func (g *Graphics) Draw(indexLen int, indexOffset int, mode driver.CompositeMode compositeMode: mode, }]) } + // In Metal, the NDC's Y direction (upward) and the framebuffer's Y direction (downward) don't + // match. Then, the Y direction must be inverted. + w, h := g.dst.viewportSize() rce.SetViewport(mtl.Viewport{ OriginX: 0, - OriginY: 0, + OriginY: float64(h), Width: float64(w), - Height: float64(h), + Height: -float64(h), ZNear: -1, ZFar: 1, })