remove int support from vertex format

This commit is contained in:
faiface 2016-12-02 18:55:52 +01:00
parent 5f6748f7b8
commit 9546652cc3
2 changed files with 7 additions and 44 deletions

View File

@ -136,18 +136,10 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
size = 4
}
var xtype uint32
switch attr.Type {
case Int:
xtype = gl.INT
case Float, Vec2, Vec3, Vec4:
xtype = gl.FLOAT
}
gl.VertexAttribPointer(
uint32(location),
size,
xtype,
gl.FLOAT,
false,
int32(va.stride),
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
// of the specified vertex.
//

View File

@ -315,14 +315,14 @@ func (w *Window) Do(sub func(pixelgl.Context)) {
}
var defaultVertexFormat = pixelgl.VertexFormat{
"position": {Purpose: pixelgl.Position, Type: pixelgl.Vec2},
"color": {Purpose: pixelgl.Color, Type: pixelgl.Vec4},
"texCoord": {Purpose: pixelgl.TexCoord, Type: pixelgl.Vec2},
"isTexture": {Purpose: pixelgl.IsTexture, Type: pixelgl.Int},
"position": {Purpose: pixelgl.Position, Type: pixelgl.Vec2},
"color": {Purpose: pixelgl.Color, Type: pixelgl.Vec4},
"texCoord": {Purpose: pixelgl.TexCoord, Type: pixelgl.Vec2},
}
var defaultUniformFormat = pixelgl.UniformFormat{
"transform": {Purpose: pixelgl.Transform, Type: pixelgl.Mat3},
"isTexture": {Purpose: pixelgl.IsTexture, Type: pixelgl.Int},
}
var defaultVertexShader = `
@ -331,11 +331,9 @@ var defaultVertexShader = `
in vec2 position;
in vec4 color;
in vec2 texCoord;
in int isTexture;
out vec4 Color;
out vec2 TexCoord;
out int IsTexture;
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);
Color = color;
TexCoord = texCoord;
IsTexture = isTexture;
}
`
@ -352,14 +349,14 @@ var defaultFragmentShader = `
in vec4 Color;
in vec2 TexCoord;
in int IsTexture;
out vec4 color;
uniform int isTexture;
uniform sampler2D tex;
void main() {
if (IsTexture != 0) {
if (isTexture != 0) {
color = Color * texture(tex, vec2(TexCoord.x, 1 - TexCoord.y));
} else {
color = Color;