change internal default shader to use -1,-1 texCoords as no texture

This commit is contained in:
faiface 2016-12-09 20:13:32 +01:00
parent 2f402dd9a8
commit db2d6be751
3 changed files with 22 additions and 15 deletions

View File

@ -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()

View File

@ -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
)

View File

@ -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));
}
}
`