graphicsdriver/opengl: Refactoring

This commit is contained in:
Hajime Hoshi 2020-11-29 23:02:22 +09:00
parent 9a49501957
commit 912e13071f
4 changed files with 16 additions and 16 deletions

View File

@ -374,15 +374,15 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
return true
}
func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
func (c *context) vertexAttribPointer(index int, size int, stride int, offset int) {
gl.VertexAttribPointer(uint32(index), int32(size), gl.FLOAT, false, int32(stride), uintptr(offset))
}
func (c *context) enableVertexAttribArray(p program, index int) {
func (c *context) enableVertexAttribArray(index int) {
gl.EnableVertexAttribArray(uint32(index))
}
func (c *context) disableVertexAttribArray(p program, index int) {
func (c *context) disableVertexAttribArray(index int) {
gl.DisableVertexAttribArray(uint32(index))
}

View File

@ -410,17 +410,17 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
return true
}
func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
func (c *context) vertexAttribPointer(index int, size int, stride int, offset int) {
gl := c.gl
gl.Call("vertexAttribPointer", index, size, gles.FLOAT, false, stride, offset)
}
func (c *context) enableVertexAttribArray(p program, index int) {
func (c *context) enableVertexAttribArray(index int) {
gl := c.gl
gl.Call("enableVertexAttribArray", index)
}
func (c *context) disableVertexAttribArray(p program, index int) {
func (c *context) disableVertexAttribArray(index int) {
gl := c.gl
gl.Call("disableVertexAttribArray", index)
}

View File

@ -343,15 +343,15 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
return true
}
func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
func (c *context) vertexAttribPointer(index int, size int, stride int, offset int) {
c.ctx.VertexAttribPointer(uint32(index), int32(size), gles.FLOAT, false, int32(stride), offset)
}
func (c *context) enableVertexAttribArray(p program, index int) {
func (c *context) enableVertexAttribArray(index int) {
c.ctx.EnableVertexAttribArray(uint32(index))
}
func (c *context) disableVertexAttribArray(p program, index int) {
func (c *context) disableVertexAttribArray(index int) {
c.ctx.DisableVertexAttribArray(uint32(index))
}

View File

@ -67,24 +67,24 @@ func (a *arrayBufferLayout) newArrayBuffer(context *context) buffer {
return context.newArrayBuffer(a.totalBytes() * graphics.IndicesNum)
}
// enable binds the array buffer the given program to use the array buffer.
func (a *arrayBufferLayout) enable(context *context, program program) {
// enable starts using the array buffer.
func (a *arrayBufferLayout) enable(context *context) {
for i := range a.parts {
context.enableVertexAttribArray(program, i)
context.enableVertexAttribArray(i)
}
total := a.totalBytes()
offset := 0
for i, p := range a.parts {
context.vertexAttribPointer(program, i, p.num, total, offset)
context.vertexAttribPointer(i, p.num, total, offset)
offset += floatSizeInBytes * p.num
}
}
// disable stops using the array buffer.
func (a *arrayBufferLayout) disable(context *context, program program) {
func (a *arrayBufferLayout) disable(context *context) {
// TODO: Disabling should be done in reversed order?
for i := range a.parts {
context.disableVertexAttribArray(program, i)
context.disableVertexAttribArray(i)
}
}
@ -253,7 +253,7 @@ func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textu
if !g.state.lastProgram.equal(program) {
g.context.useProgram(program)
if g.state.lastProgram.equal(zeroProgram) {
theArrayBufferLayout.enable(&g.context, program)
theArrayBufferLayout.enable(&g.context)
g.context.bindArrayBuffer(g.state.arrayBuffer)
g.context.bindElementArrayBuffer(g.state.elementArrayBuffer)
}