change internal default shader to use -1,-1 texCoords as no texture
This commit is contained in:
parent
2f402dd9a8
commit
db2d6be751
27
graphics.go
27
graphics.go
|
@ -200,7 +200,6 @@ func (s *Sprite) Draw(t ...Transform) {
|
||||||
r, g, b, a := colorToRGBA(s.color)
|
r, g, b, a := colorToRGBA(s.color)
|
||||||
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
||||||
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
||||||
ctx.Shader().SetUniformInt(pixelgl.IsTexture, 1)
|
|
||||||
|
|
||||||
s.va.Draw()
|
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})
|
for i := 0; i < 4; i++ {
|
||||||
lc.va.SetVertexAttributeVec4(1, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1})
|
lc.va.SetVertexAttributeVec4(i, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1})
|
||||||
lc.va.SetVertexAttributeVec4(2, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1})
|
lc.va.SetVertexAttributeVec2(i, pixelgl.TexCoord, mgl32.Vec2{-1, -1})
|
||||||
lc.va.SetVertexAttributeVec4(3, pixelgl.Color, mgl32.Vec4{1, 1, 1, 1})
|
}
|
||||||
|
|
||||||
lc.setPoints()
|
lc.setPoints()
|
||||||
|
|
||||||
|
@ -312,7 +311,6 @@ func (lc *LineColor) Draw(t ...Transform) {
|
||||||
r, g, b, a := colorToRGBA(lc.color)
|
r, g, b, a := colorToRGBA(lc.color)
|
||||||
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
||||||
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
||||||
ctx.Shader().SetUniformInt(pixelgl.IsTexture, 0)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
lc.va.Draw()
|
lc.va.Draw()
|
||||||
|
@ -373,6 +371,11 @@ func NewPolygonColor(parent pixelgl.Doer, c color.Color, points ...Vec) *Polygon
|
||||||
pixelgl.Color,
|
pixelgl.Color,
|
||||||
mgl32.Vec4{1, 1, 1, 1},
|
mgl32.Vec4{1, 1, 1, 1},
|
||||||
)
|
)
|
||||||
|
pc.va.SetVertexAttributeVec2(
|
||||||
|
i,
|
||||||
|
pixelgl.TexCoord,
|
||||||
|
mgl32.Vec2{-1, -1},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pc
|
return pc
|
||||||
|
@ -419,7 +422,6 @@ func (pc *PolygonColor) Draw(t ...Transform) {
|
||||||
r, g, b, a := colorToRGBA(pc.color)
|
r, g, b, a := colorToRGBA(pc.color)
|
||||||
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
||||||
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
||||||
ctx.Shader().SetUniformInt(pixelgl.IsTexture, 0)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
pc.va.Draw()
|
pc.va.Draw()
|
||||||
|
@ -488,6 +490,11 @@ func NewEllipseColor(parent pixelgl.Doer, c color.Color, radius Vec, fill float6
|
||||||
pixelgl.Color,
|
pixelgl.Color,
|
||||||
mgl32.Vec4{1, 1, 1, 1},
|
mgl32.Vec4{1, 1, 1, 1},
|
||||||
)
|
)
|
||||||
|
ec.va.SetVertexAttributeVec2(
|
||||||
|
i,
|
||||||
|
pixelgl.TexCoord,
|
||||||
|
mgl32.Vec2{-1, -1},
|
||||||
|
)
|
||||||
ec.va.SetVertexAttributeVec2(
|
ec.va.SetVertexAttributeVec2(
|
||||||
j,
|
j,
|
||||||
pixelgl.Position,
|
pixelgl.Position,
|
||||||
|
@ -501,6 +508,11 @@ func NewEllipseColor(parent pixelgl.Doer, c color.Color, radius Vec, fill float6
|
||||||
pixelgl.Color,
|
pixelgl.Color,
|
||||||
mgl32.Vec4{1, 1, 1, 1},
|
mgl32.Vec4{1, 1, 1, 1},
|
||||||
)
|
)
|
||||||
|
ec.va.SetVertexAttributeVec2(
|
||||||
|
j,
|
||||||
|
pixelgl.TexCoord,
|
||||||
|
mgl32.Vec2{-1, -1},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ec
|
return ec
|
||||||
|
@ -538,7 +550,6 @@ func (ec *EllipseColor) Draw(t ...Transform) {
|
||||||
r, g, b, a := colorToRGBA(ec.color)
|
r, g, b, a := colorToRGBA(ec.color)
|
||||||
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
ctx.Shader().SetUniformVec4(pixelgl.MaskColor, mgl32.Vec4{r, g, b, a})
|
||||||
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
ctx.Shader().SetUniformMat3(pixelgl.Transform, mat)
|
||||||
ctx.Shader().SetUniformInt(pixelgl.IsTexture, 0)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ec.va.Draw()
|
ec.va.Draw()
|
||||||
|
|
|
@ -20,8 +20,6 @@ const (
|
||||||
Transform
|
Transform
|
||||||
// MaskColor is a masking color. When drawing, each color gets multiplied by this color.
|
// MaskColor is a masking color. When drawing, each color gets multiplied by this color.
|
||||||
MaskColor
|
MaskColor
|
||||||
// IsTexture signals, whether a texture is present.
|
|
||||||
IsTexture
|
|
||||||
// NumStandardAttrPurposes is the number of standard attribute purposes
|
// NumStandardAttrPurposes is the number of standard attribute purposes
|
||||||
NumStandardAttrPurposes
|
NumStandardAttrPurposes
|
||||||
)
|
)
|
||||||
|
|
|
@ -346,7 +346,6 @@ var defaultVertexFormat = pixelgl.VertexFormat{
|
||||||
var defaultUniformFormat = pixelgl.UniformFormat{
|
var defaultUniformFormat = pixelgl.UniformFormat{
|
||||||
"maskColor": {Purpose: pixelgl.MaskColor, Type: pixelgl.Vec4},
|
"maskColor": {Purpose: pixelgl.MaskColor, Type: pixelgl.Vec4},
|
||||||
"transform": {Purpose: pixelgl.Transform, Type: pixelgl.Mat3},
|
"transform": {Purpose: pixelgl.Transform, Type: pixelgl.Mat3},
|
||||||
"isTexture": {Purpose: pixelgl.IsTexture, Type: pixelgl.Int},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultVertexShader = `
|
var defaultVertexShader = `
|
||||||
|
@ -377,14 +376,13 @@ in vec2 TexCoord;
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
uniform vec4 maskColor;
|
uniform vec4 maskColor;
|
||||||
uniform int isTexture;
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
if (isTexture != 0) {
|
if (TexCoord == vec2(-1, -1)) {
|
||||||
color = maskColor * Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y));
|
|
||||||
} else {
|
|
||||||
color = maskColor * Color;
|
color = maskColor * Color;
|
||||||
|
} else {
|
||||||
|
color = maskColor * Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue