From fe308f1971f6dcbb59fd9e2a6ccf7c1565c69caa Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 5 Jun 2020 04:36:09 +0900 Subject: [PATCH] Revert "shader: Add a predefined uniform variable: Internal_ViewportSize" This reverts commit 6f411842f0e898673b12b7aa9b3c9545936646d1. Reason: Test failures on internal/restorable --- examples/shader/main.go | 9 +++------ image.go | 4 ---- internal/graphicscommand/command.go | 7 ------- shader.go | 11 +---------- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/examples/shader/main.go b/examples/shader/main.go index 15b5003b1..00ad3625d 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -29,20 +29,17 @@ const ( const shaderSrc = `package main -// Internal_ViewportSize is a predefined uniform variable. -// TODO: Hide this and create a function for the projection matrix? - func Vertex(position vec2, texCoord vec2, color vec4) vec4 { return mat4( - 2.0/Internal_ViewportSize.x, 0, 0, 0, - 0, 2.0/Internal_ViewportSize.y, 0, 0, + 2.0/640, 0, 0, 0, + 0, 2.0/480, 0, 0, 0, 0, 1, 0, -1, -1, 0, 1, ) * vec4(position, 0, 1) } func Fragment(position vec4) vec4 { - return vec4(position.x/Internal_ViewportSize.x, position.y/Internal_ViewportSize.y, 0, 1) + return vec4(position.x/640, position.y/480, 0, 1) }` type Game struct { diff --git a/image.go b/image.go index 2ff60589c..4a359a10f 100644 --- a/image.go +++ b/image.go @@ -384,10 +384,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha } } - // The last uniform variable is Internal_ViewportSize. - // The actual value is set at graphicscommand package. - us = append(us, []float32{0, 0}) - var bx0, by0, bx1, by1 float32 if firstImage != nil { b := firstImage.Bounds() diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 6bba313d2..60c834193 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -453,13 +453,6 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error { us[i] = v } } - - // The last uniform variables are added at /shader.go and represents a viewport size. - w, h := c.dst.InternalSize() - viewport := us[len(us)-1].([]float32) - viewport[0] = float32(w) - viewport[1] = float32(h) - return theGraphicsDriver.DrawShader(c.dst.image.ID(), c.shader.shader.ID(), c.nindices, indexOffset, c.mode, us) } return theGraphicsDriver.Draw(c.dst.image.ID(), c.src.image.ID(), c.nindices, indexOffset, c.mode, c.color, c.filter, c.address) diff --git a/shader.go b/shader.go index cacd631d7..d9d1fa724 100644 --- a/shader.go +++ b/shader.go @@ -15,25 +15,16 @@ package ebiten import ( - "bytes" - "github.com/hajimehoshi/ebiten/internal/buffered" "github.com/hajimehoshi/ebiten/internal/shader" ) -const shaderSuffix = ` -var Internal_ViewportSize vec2` - type Shader struct { shader *buffered.Shader } func NewShader(src []byte) (*Shader, error) { - var b bytes.Buffer - b.Write(src) - b.Write([]byte(shaderSuffix)) - - s, err := shader.Compile(b.Bytes(), "Vertex", "Fragment") + s, err := shader.Compile(src, "Vertex", "Fragment") if err != nil { return nil, err }