diff --git a/internal/graphics/vertices.go b/internal/graphics/vertices.go index 68791585a..f0bcb6765 100644 --- a/internal/graphics/vertices.go +++ b/internal/graphics/vertices.go @@ -23,7 +23,10 @@ type verticesBackend struct { head int } -const VertexFloatNum = 10 +const ( + IndicesNum = (1 << 16) / 3 * 3 // Adjust num for triangles. + VertexFloatNum = 10 +) func (v *verticesBackend) slice(n int) []float32 { const num = 1024 diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index e627ed9db..bdbeae337 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -89,7 +89,7 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) { } func (q *commandQueue) doEnqueueDrawImageCommand(dst, src *Image, nvertices, nindices int, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, forceNewCommand bool) { - if nindices > opengl.IndicesNum { + if nindices > graphics.IndicesNum { panic("not implemented for too many indices") } if !forceNewCommand && 0 < len(q.commands) { @@ -113,12 +113,12 @@ func (q *commandQueue) doEnqueueDrawImageCommand(dst, src *Image, nvertices, nin // EnqueueDrawImageCommand enqueues a drawing-image command. func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) { - if len(indices) > opengl.IndicesNum { + if len(indices) > graphics.IndicesNum { panic("not reached") } split := false - if q.tmpNumIndices+len(indices) > opengl.IndicesNum { + if q.tmpNumIndices+len(indices) > graphics.IndicesNum { q.tmpNumIndices = 0 q.nextIndex = 0 split = true @@ -155,10 +155,10 @@ func (q *commandQueue) Flush() { ne := 0 nc := 0 for _, c := range q.commands { - if c.NumIndices() > opengl.IndicesNum { + if c.NumIndices() > graphics.IndicesNum { panic("not reached") } - if ne+c.NumIndices() > opengl.IndicesNum { + if ne+c.NumIndices() > graphics.IndicesNum { break } nv += c.NumVertices() diff --git a/internal/opengl/program.go b/internal/opengl/program.go index 14056b6b8..ced02d436 100644 --- a/internal/opengl/program.go +++ b/internal/opengl/program.go @@ -54,7 +54,7 @@ func (a *arrayBufferLayout) totalBytes() int { // newArrayBuffer creates OpenGL's buffer object for the array buffer. func (a *arrayBufferLayout) newArrayBuffer() buffer { - return theContext.newArrayBuffer(a.totalBytes() * IndicesNum) + return theContext.newArrayBuffer(a.totalBytes() * graphics.IndicesNum) } // enable binds the array buffer the given program to use the array buffer. @@ -144,8 +144,7 @@ var ( ) const ( - IndicesNum = (1 << 16) / 3 * 3 // Adjust num for triangles. - maxTriangles = IndicesNum / 3 + maxTriangles = graphics.IndicesNum / 3 maxQuads = maxTriangles / 2 ) @@ -239,7 +238,7 @@ func (s *openGLState) reset() error { // Note that the indices passed to NewElementArrayBuffer is not under GC management // in opengl package due to unsafe-way. // See NewElementArrayBuffer in context_mobile.go. - s.elementArrayBuffer = theContext.newElementArrayBuffer(IndicesNum * 2) + s.elementArrayBuffer = theContext.newElementArrayBuffer(graphics.IndicesNum * 2) return nil }