remove int support from vertex format
This commit is contained in:
parent
5f6748f7b8
commit
9546652cc3
|
@ -136,18 +136,10 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
|
||||||
size = 4
|
size = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
var xtype uint32
|
|
||||||
switch attr.Type {
|
|
||||||
case Int:
|
|
||||||
xtype = gl.INT
|
|
||||||
case Float, Vec2, Vec3, Vec4:
|
|
||||||
xtype = gl.FLOAT
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.VertexAttribPointer(
|
gl.VertexAttribPointer(
|
||||||
uint32(location),
|
uint32(location),
|
||||||
size,
|
size,
|
||||||
xtype,
|
gl.FLOAT,
|
||||||
false,
|
false,
|
||||||
int32(va.stride),
|
int32(va.stride),
|
||||||
gl.PtrOffset(offset),
|
gl.PtrOffset(offset),
|
||||||
|
@ -248,32 +240,6 @@ func (va *VertexArray) checkVertex(vertex int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVertexAttributeInt sets the value of a specified vertex attribute Attr{Purpose: purpose, Type: Int} of type Int
|
|
||||||
// of the specified vertex.
|
|
||||||
//
|
|
||||||
// This function returns false if the specified vertex attribute does not exist. Note that the function panics if
|
|
||||||
// the vertex if out of range.
|
|
||||||
func (va *VertexArray) SetVertexAttributeInt(vertex int, purpose AttrPurpose, value int32) (ok bool) {
|
|
||||||
va.checkVertex(vertex)
|
|
||||||
attr := Attr{Purpose: purpose, Type: Int}
|
|
||||||
if _, ok := va.attrs[attr]; !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
DoNoBlock(func() {
|
|
||||||
gl.BindBuffer(gl.ARRAY_BUFFER, va.vbo)
|
|
||||||
|
|
||||||
offset := va.stride*vertex + va.attrs[attr]
|
|
||||||
gl.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
|
|
||||||
|
|
||||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
|
||||||
|
|
||||||
if err := getLastGLErr(); err != nil {
|
|
||||||
panic(errors.Wrap(err, "set attribute vertex"))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetVertexAttributeFloat sets the value of a specified vertex attribute Attr{Purpose: purpose, Type: Float} of type Float
|
// SetVertexAttributeFloat sets the value of a specified vertex attribute Attr{Purpose: purpose, Type: Float} of type Float
|
||||||
// of the specified vertex.
|
// of the specified vertex.
|
||||||
//
|
//
|
||||||
|
|
15
window.go
15
window.go
|
@ -315,14 +315,14 @@ func (w *Window) Do(sub func(pixelgl.Context)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultVertexFormat = pixelgl.VertexFormat{
|
var defaultVertexFormat = pixelgl.VertexFormat{
|
||||||
"position": {Purpose: pixelgl.Position, Type: pixelgl.Vec2},
|
"position": {Purpose: pixelgl.Position, Type: pixelgl.Vec2},
|
||||||
"color": {Purpose: pixelgl.Color, Type: pixelgl.Vec4},
|
"color": {Purpose: pixelgl.Color, Type: pixelgl.Vec4},
|
||||||
"texCoord": {Purpose: pixelgl.TexCoord, Type: pixelgl.Vec2},
|
"texCoord": {Purpose: pixelgl.TexCoord, Type: pixelgl.Vec2},
|
||||||
"isTexture": {Purpose: pixelgl.IsTexture, Type: pixelgl.Int},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultUniformFormat = pixelgl.UniformFormat{
|
var defaultUniformFormat = pixelgl.UniformFormat{
|
||||||
"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 = `
|
||||||
|
@ -331,11 +331,9 @@ var defaultVertexShader = `
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
in vec4 color;
|
in vec4 color;
|
||||||
in vec2 texCoord;
|
in vec2 texCoord;
|
||||||
in int isTexture;
|
|
||||||
|
|
||||||
out vec4 Color;
|
out vec4 Color;
|
||||||
out vec2 TexCoord;
|
out vec2 TexCoord;
|
||||||
out int IsTexture;
|
|
||||||
|
|
||||||
uniform mat3 transform;
|
uniform mat3 transform;
|
||||||
|
|
||||||
|
@ -343,7 +341,6 @@ void main() {
|
||||||
gl_Position = vec4((transform * vec3(position.x, position.y, 1.0)).xy, 0.0, 1.0);
|
gl_Position = vec4((transform * vec3(position.x, position.y, 1.0)).xy, 0.0, 1.0);
|
||||||
Color = color;
|
Color = color;
|
||||||
TexCoord = texCoord;
|
TexCoord = texCoord;
|
||||||
IsTexture = isTexture;
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -352,14 +349,14 @@ var defaultFragmentShader = `
|
||||||
|
|
||||||
in vec4 Color;
|
in vec4 Color;
|
||||||
in vec2 TexCoord;
|
in vec2 TexCoord;
|
||||||
in int IsTexture;
|
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
|
uniform int isTexture;
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
if (IsTexture != 0) {
|
if (isTexture != 0) {
|
||||||
color = Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y));
|
color = Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y));
|
||||||
} else {
|
} else {
|
||||||
color = Color;
|
color = Color;
|
||||||
|
|
Loading…
Reference in New Issue