From db2d6be7510fbd591b7e48e60de6f1fe985676ec Mon Sep 17 00:00:00 2001 From: faiface Date: Fri, 9 Dec 2016 20:13:32 +0100 Subject: [PATCH] change internal default shader to use -1,-1 texCoords as no texture --- graphics.go | 27 +++++++++++++++++++-------- pixelgl/attr.go | 2 -- window.go | 8 +++----- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/graphics.go b/graphics.go index 6094159..886a507 100644 --- a/graphics.go +++ b/graphics.go @@ -200,7 +200,6 @@ func (s *Sprite) Draw(t ...Transform) { r, g, b, a := colorToRGBA(s.color) ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a}) ctx.Shader().SetUniformMat3(pixelgl.Transform, mat) - ctx.Shader().SetUniformInt(pixelgl.IsTexture, 1) s.va.Draw() }) @@ -240,10 +239,10 @@ func NewLineColor(parent pixelgl.Doer, c color.Color, a, b Vec, width float64) * } }) - lc.va.SetVertexAttributeVec4(0, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}) - lc.va.SetVertexAttributeVec4(1, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}) - lc.va.SetVertexAttributeVec4(2, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}) - lc.va.SetVertexAttributeVec4(3, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}) + for i := 0; i < 4; i++ { + lc.va.SetVertexAttributeVec4(i, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}) + lc.va.SetVertexAttributeVec2(i, pixelgl.TexCoord, mgl32.Vec2{-1, -1}) + } lc.setPoints() @@ -312,7 +311,6 @@ func (lc *LineColor) Draw(t ...Transform) { r, g, b, a := colorToRGBA(lc.color) ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a}) ctx.Shader().SetUniformMat3(pixelgl.Transform, mat) - ctx.Shader().SetUniformInt(pixelgl.IsTexture, 0) }) lc.va.Draw() @@ -373,6 +371,11 @@ func NewPolygonColor(parent pixelgl.Doer, c color.Color, points ...Vec) *Polygon pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}, ) + pc.va.SetVertexAttributeVec2( + i, + pixelgl.TexCoord, + mgl32.Vec2{-1, -1}, + ) } return pc @@ -419,7 +422,6 @@ func (pc *PolygonColor) Draw(t ...Transform) { r, g, b, a := colorToRGBA(pc.color) ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a}) ctx.Shader().SetUniformMat3(pixelgl.Transform, mat) - ctx.Shader().SetUniformInt(pixelgl.IsTexture, 0) }) pc.va.Draw() @@ -488,6 +490,11 @@ func NewEllipseColor(parent pixelgl.Doer, c color.Color, radius Vec, fill float6 pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}, ) + ec.va.SetVertexAttributeVec2( + i, + pixelgl.TexCoord, + mgl32.Vec2{-1, -1}, + ) ec.va.SetVertexAttributeVec2( j, pixelgl.Position, @@ -501,6 +508,11 @@ func NewEllipseColor(parent pixelgl.Doer, c color.Color, radius Vec, fill float6 pixelgl.Color, mgl32.Vec4{1, 1, 1, 1}, ) + ec.va.SetVertexAttributeVec2( + j, + pixelgl.TexCoord, + mgl32.Vec2{-1, -1}, + ) } return ec @@ -538,7 +550,6 @@ func (ec *EllipseColor) Draw(t ...Transform) { r, g, b, a := colorToRGBA(ec.color) ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a}) ctx.Shader().SetUniformMat3(pixelgl.Transform, mat) - ctx.Shader().SetUniformInt(pixelgl.IsTexture, 0) }) ec.va.Draw() diff --git a/pixelgl/attr.go b/pixelgl/attr.go index 5757d20..b7f6b8c 100644 --- a/pixelgl/attr.go +++ b/pixelgl/attr.go @@ -20,8 +20,6 @@ const ( Transform // MaskColor is a masking color. When drawing, each color gets multiplied by this color. MaskColor - // IsTexture signals, whether a texture is present. - IsTexture // NumStandardAttrPurposes is the number of standard attribute purposes NumStandardAttrPurposes ) diff --git a/window.go b/window.go index 5ad5d0e..065d92b 100644 --- a/window.go +++ b/window.go @@ -346,7 +346,6 @@ var defaultVertexFormat = pixelgl.VertexFormat{ var defaultUniformFormat = pixelgl.UniformFormat{ "maskColor": {Purpose: pixelgl.MaskColor, Type: pixelgl.Vec4}, "transform": {Purpose: pixelgl.Transform, Type: pixelgl.Mat3}, - "isTexture": {Purpose: pixelgl.IsTexture, Type: pixelgl.Int}, } var defaultVertexShader = ` @@ -377,14 +376,13 @@ in vec2 TexCoord; out vec4 color; uniform vec4 maskColor; -uniform int isTexture; uniform sampler2D tex; void main() { - if (isTexture != 0) { - color = maskColor * Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y)); - } else { + if (TexCoord == vec2(-1, -1)) { color = maskColor * Color; + } else { + color = maskColor * Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y)); } } `