Bug fix: gl.EnableClientState should not be called

This commit is contained in:
Hajime Hoshi 2014-12-26 20:13:57 +09:00
parent 8ae96875c9
commit ce81251730

View File

@ -36,6 +36,7 @@ type Matrix interface {
var initialized = false
const size = 10000
// TODO: Use unsafe.SizeOf?
const uint16Size = 2
const short32Size = 4
@ -45,6 +46,11 @@ func DrawTexture(native gl.Texture, projectionMatrix [4][4]float64, quads []Text
if !initialized {
initialize()
vertexBuffer := gl.GenBuffer()
vertexBuffer.Bind(gl.ARRAY_BUFFER)
vertices := make([]float32, stride*size)
gl.BufferData(gl.ARRAY_BUFFER, short32Size*len(vertices), vertices, gl.DYNAMIC_DRAW)
indexBuffer := gl.GenBuffer()
indexBuffer.Bind(gl.ELEMENT_ARRAY_BUFFER)
indices := make([]uint16, 6*size)
@ -58,11 +64,6 @@ func DrawTexture(native gl.Texture, projectionMatrix [4][4]float64, quads []Text
}
gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, uint16Size*len(indices), indices, gl.STATIC_DRAW)
vertexBuffer := gl.GenBuffer()
vertexBuffer.Bind(gl.ARRAY_BUFFER)
vertices := make([]float32, stride*size)
gl.BufferData(gl.ARRAY_BUFFER, short32Size*len(vertices), vertices, gl.DYNAMIC_DRAW)
initialized = true
}
@ -78,15 +79,11 @@ func DrawTexture(native gl.Texture, projectionMatrix [4][4]float64, quads []Text
vertexAttrLocation := getAttributeLocation(program, "vertex")
texCoordAttrLocation := getAttributeLocation(program, "tex_coord")
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
vertexAttrLocation.EnableArray()
texCoordAttrLocation.EnableArray()
defer func() {
texCoordAttrLocation.DisableArray()
vertexAttrLocation.DisableArray()
gl.DisableClientState(gl.TEXTURE_COORD_ARRAY)
gl.DisableClientState(gl.VERTEX_ARRAY)
}()
// TODO: Fix this dirty hack after fixing https://github.com/go-gl/gl/issues/174