graphcis: Move IndicesNum from opengl to graphics

This commit is contained in:
Hajime Hoshi 2018-11-07 01:49:45 +09:00
parent 07ae1db0dd
commit 09c8516545
3 changed files with 12 additions and 10 deletions

View File

@ -23,7 +23,10 @@ type verticesBackend struct {
head int head int
} }
const VertexFloatNum = 10 const (
IndicesNum = (1 << 16) / 3 * 3 // Adjust num for triangles.
VertexFloatNum = 10
)
func (v *verticesBackend) slice(n int) []float32 { func (v *verticesBackend) slice(n int) []float32 {
const num = 1024 const num = 1024

View File

@ -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) { 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") panic("not implemented for too many indices")
} }
if !forceNewCommand && 0 < len(q.commands) { 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. // 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) { 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") panic("not reached")
} }
split := false split := false
if q.tmpNumIndices+len(indices) > opengl.IndicesNum { if q.tmpNumIndices+len(indices) > graphics.IndicesNum {
q.tmpNumIndices = 0 q.tmpNumIndices = 0
q.nextIndex = 0 q.nextIndex = 0
split = true split = true
@ -155,10 +155,10 @@ func (q *commandQueue) Flush() {
ne := 0 ne := 0
nc := 0 nc := 0
for _, c := range q.commands { for _, c := range q.commands {
if c.NumIndices() > opengl.IndicesNum { if c.NumIndices() > graphics.IndicesNum {
panic("not reached") panic("not reached")
} }
if ne+c.NumIndices() > opengl.IndicesNum { if ne+c.NumIndices() > graphics.IndicesNum {
break break
} }
nv += c.NumVertices() nv += c.NumVertices()

View File

@ -54,7 +54,7 @@ func (a *arrayBufferLayout) totalBytes() int {
// newArrayBuffer creates OpenGL's buffer object for the array buffer. // newArrayBuffer creates OpenGL's buffer object for the array buffer.
func (a *arrayBufferLayout) newArrayBuffer() 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. // enable binds the array buffer the given program to use the array buffer.
@ -144,8 +144,7 @@ var (
) )
const ( const (
IndicesNum = (1 << 16) / 3 * 3 // Adjust num for triangles. maxTriangles = graphics.IndicesNum / 3
maxTriangles = IndicesNum / 3
maxQuads = maxTriangles / 2 maxQuads = maxTriangles / 2
) )
@ -239,7 +238,7 @@ func (s *openGLState) reset() error {
// Note that the indices passed to NewElementArrayBuffer is not under GC management // Note that the indices passed to NewElementArrayBuffer is not under GC management
// in opengl package due to unsafe-way. // in opengl package due to unsafe-way.
// See NewElementArrayBuffer in context_mobile.go. // See NewElementArrayBuffer in context_mobile.go.
s.elementArrayBuffer = theContext.newElementArrayBuffer(IndicesNum * 2) s.elementArrayBuffer = theContext.newElementArrayBuffer(graphics.IndicesNum * 2)
return nil return nil
} }