diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 8f8decf30..b1a6161b9 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -126,7 +126,7 @@ func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float q.appendVertices(vertices) q.appendIndices(indices, uint16(q.nextIndex)) - q.nextIndex += len(vertices) * opengl.Float.SizeInBytes() / opengl.ArrayBufferLayoutTotalBytes() + q.nextIndex += len(vertices) / opengl.ArrayBufferLayoutFloatNum() q.tmpNumIndices += len(indices) q.doEnqueueDrawImageCommand(dst, src, len(vertices), len(indices), color, mode, filter, split) diff --git a/internal/opengl/context.go b/internal/opengl/context.go index e846225bd..e335f9e6f 100644 --- a/internal/opengl/context.go +++ b/internal/opengl/context.go @@ -25,8 +25,8 @@ var ( elementArrayBuffer bufferType dynamicDraw bufferUsage staticDraw bufferUsage - Short DataType - Float DataType + short dataType + float dataType zero operation one operation diff --git a/internal/opengl/context_desktop.go b/internal/opengl/context_desktop.go index e36a6fbdc..9199e4f2c 100644 --- a/internal/opengl/context_desktop.go +++ b/internal/opengl/context_desktop.go @@ -61,8 +61,8 @@ func init() { arrayBuffer = gl.ARRAY_BUFFER elementArrayBuffer = gl.ELEMENT_ARRAY_BUFFER dynamicDraw = gl.DYNAMIC_DRAW - Short = gl.SHORT - Float = gl.FLOAT + short = gl.SHORT + float = gl.FLOAT zero = gl.ZERO one = gl.ONE @@ -408,7 +408,7 @@ func (c *Context) getAttribLocationImpl(p program, location string) attribLocati return attrib } -func (c *Context) vertexAttribPointer(p program, location string, size int, dataType DataType, stride int, offset int) { +func (c *Context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) { _ = mainthread.Run(func() error { l := c.locationCache.GetAttribLocation(c, p, location) gl.VertexAttribPointer(uint32(l), int32(size), uint32(dataType), false, int32(stride), gl.PtrOffset(offset)) diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index 6794ddfb8..a891b1f6f 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -78,8 +78,8 @@ func init() { arrayBuffer = bufferType(c.Get("ARRAY_BUFFER").Int()) elementArrayBuffer = bufferType(c.Get("ELEMENT_ARRAY_BUFFER").Int()) dynamicDraw = bufferUsage(c.Get("DYNAMIC_DRAW").Int()) - Short = DataType(c.Get("SHORT").Int()) - Float = DataType(c.Get("FLOAT").Int()) + short = dataType(c.Get("SHORT").Int()) + float = dataType(c.Get("FLOAT").Int()) zero = operation(c.Get("ZERO").Int()) one = operation(c.Get("ONE").Int()) @@ -410,7 +410,7 @@ func (c *Context) getAttribLocationImpl(p program, location string) attribLocati return attribLocation(gl.Call("getAttribLocation", p.value, location).Int()) } -func (c *Context) vertexAttribPointer(p program, location string, size int, dataType DataType, stride int, offset int) { +func (c *Context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) { c.ensureGL() gl := c.gl l := c.locationCache.GetAttribLocation(c, p, location) diff --git a/internal/opengl/context_mobile.go b/internal/opengl/context_mobile.go index 88d1a0c9d..b49246f4d 100644 --- a/internal/opengl/context_mobile.go +++ b/internal/opengl/context_mobile.go @@ -57,8 +57,8 @@ func init() { arrayBuffer = mgl.ARRAY_BUFFER elementArrayBuffer = mgl.ELEMENT_ARRAY_BUFFER dynamicDraw = mgl.DYNAMIC_DRAW - Short = mgl.SHORT - Float = mgl.FLOAT + short = mgl.SHORT + float = mgl.FLOAT zero = mgl.ZERO one = mgl.ONE @@ -332,7 +332,7 @@ func (c *Context) getAttribLocationImpl(p program, location string) attribLocati return a } -func (c *Context) vertexAttribPointer(p program, location string, size int, dataType DataType, stride int, offset int) { +func (c *Context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) { gl := c.gl l := c.locationCache.GetAttribLocation(c, p, location) gl.VertexAttribPointer(mgl.Attrib(l), size, mgl.Enum(dataType), false, stride, offset) diff --git a/internal/opengl/program.go b/internal/opengl/program.go index e813010b0..3adabb121 100644 --- a/internal/opengl/program.go +++ b/internal/opengl/program.go @@ -46,7 +46,7 @@ func (a *arrayBufferLayout) totalBytes() int { } t := 0 for _, p := range a.parts { - t += Float.SizeInBytes() * p.num + t += float.SizeInBytes() * p.num } a.total = t return a.total @@ -65,8 +65,8 @@ func (a *arrayBufferLayout) enable(program program) { total := a.totalBytes() offset := 0 for _, p := range a.parts { - GetContext().vertexAttribPointer(program, p.name, p.num, Float, total, offset) - offset += Float.SizeInBytes() * p.num + GetContext().vertexAttribPointer(program, p.name, p.num, float, total, offset) + offset += float.SizeInBytes() * p.num } } @@ -101,8 +101,8 @@ func initializeArrayBuferLayout() { } } -func ArrayBufferLayoutTotalBytes() int { - return theArrayBufferLayout.totalBytes() +func ArrayBufferLayoutFloatNum() int { + return theArrayBufferLayout.totalBytes() / float.SizeInBytes() } // openGLState is a state for diff --git a/internal/opengl/types.go b/internal/opengl/types.go index 0453a1c8c..8ca2d01f5 100644 --- a/internal/opengl/types.go +++ b/internal/opengl/types.go @@ -21,13 +21,13 @@ type ( operation int ) -type DataType int +type dataType int -func (d DataType) SizeInBytes() int { +func (d dataType) SizeInBytes() int { switch d { - case Short: + case short: return 2 - case Float: + case float: return 4 default: panic("not reached")