From 912e13071f801ccfd1415cd42aa196bef7591b38 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 29 Nov 2020 23:02:22 +0900 Subject: [PATCH] graphicsdriver/opengl: Refactoring --- internal/graphicsdriver/opengl/context_desktop.go | 6 +++--- internal/graphicsdriver/opengl/context_js.go | 6 +++--- internal/graphicsdriver/opengl/context_mobile.go | 6 +++--- internal/graphicsdriver/opengl/program.go | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_desktop.go b/internal/graphicsdriver/opengl/context_desktop.go index 1e81fa8ac..c07b99d74 100644 --- a/internal/graphicsdriver/opengl/context_desktop.go +++ b/internal/graphicsdriver/opengl/context_desktop.go @@ -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)) } diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index 49c592c3c..3b42ee01d 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -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) } diff --git a/internal/graphicsdriver/opengl/context_mobile.go b/internal/graphicsdriver/opengl/context_mobile.go index 63ec81260..d0d9d5153 100644 --- a/internal/graphicsdriver/opengl/context_mobile.go +++ b/internal/graphicsdriver/opengl/context_mobile.go @@ -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)) } diff --git a/internal/graphicsdriver/opengl/program.go b/internal/graphicsdriver/opengl/program.go index ba227d014..70c160494 100644 --- a/internal/graphicsdriver/opengl/program.go +++ b/internal/graphicsdriver/opengl/program.go @@ -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) }