opengl: Add BindBuffer accepting both element-array-buffer and array-buffer

This change is a pure refactoring to clarify that array buffer is
binded before its usage.
This commit is contained in:
Hajime Hoshi 2018-05-28 00:33:58 +09:00
parent 311788dfe2
commit 399f965729
4 changed files with 8 additions and 7 deletions

View File

@ -288,7 +288,8 @@ func (s *openGLState) useProgram(proj []float32, texture opengl.Texture, dst, sr
s.lastColorMatrixTranslation = nil
s.lastSourceWidth = 0
s.lastSourceHeight = 0
c.BindElementArrayBuffer(s.elementArrayBuffer)
c.BindBuffer(opengl.ArrayBuffer, s.arrayBuffer)
c.BindBuffer(opengl.ElementArrayBuffer, s.elementArrayBuffer)
c.UniformInt(program, "texture", 0)
}

View File

@ -465,9 +465,9 @@ func (c *Context) NewElementArrayBuffer(indices []uint16) Buffer {
return buffer
}
func (c *Context) BindElementArrayBuffer(b Buffer) {
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
_ = c.runOnContextThread(func() error {
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, uint32(b))
gl.BindBuffer(uint32(bufferType), uint32(b))
return nil
})
}

View File

@ -366,9 +366,9 @@ func (c *Context) NewElementArrayBuffer(indices []uint16) Buffer {
return b
}
func (c *Context) BindElementArrayBuffer(b Buffer) {
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
gl := c.gl
gl.Call("bindBuffer", gl.Get("ELEMENT_ARRAY_BUFFER"), b)
gl.Call("bindBuffer", int(bufferType), b)
}
func (c *Context) BufferSubData(bufferType BufferType, data []float32) {

View File

@ -380,9 +380,9 @@ func (c *Context) NewElementArrayBuffer(indices []uint16) Buffer {
return Buffer(b)
}
func (c *Context) BindElementArrayBuffer(b Buffer) {
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
gl := c.gl
gl.BindBuffer(mgl.ELEMENT_ARRAY_BUFFER, mgl.Buffer(b))
gl.BindBuffer(mgl.Enum(bufferType), mgl.Buffer(b))
}
func float32ToBytes(v []float32) []byte {