From cb26342b3d2382476e57fbaa5677d4d8c13e4e3d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 14 Jan 2015 23:29:14 +0900 Subject: [PATCH] Bug fix (#85): The limit of the size of vertices was wrong --- example/sprites/main.go | 2 +- internal/graphics/internal/shader/draw.go | 4 +--- internal/graphics/internal/shader/program.go | 5 +++-- internal/opengl/context_js.go | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/example/sprites/main.go b/example/sprites/main.go index e2b4b6916..450edd09c 100644 --- a/example/sprites/main.go +++ b/example/sprites/main.go @@ -92,7 +92,7 @@ func (s Sprites) Src(i int) (x0, y0, x1, y1 int) { return s[i].Src() } -var sprites = make(Sprites, 2500) +var sprites = make(Sprites, 10000) func update(screen *ebiten.Image) error { sprites.Update() diff --git a/internal/graphics/internal/shader/draw.go b/internal/graphics/internal/shader/draw.go index 9e6a00519..8da5a96d0 100644 --- a/internal/graphics/internal/shader/draw.go +++ b/internal/graphics/internal/shader/draw.go @@ -58,9 +58,7 @@ func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4 if quads.Len() == 0 { return nil } - // TODO: Change this panic if image.DrawImage allows more than quadsMaxNum parts. - // TODO: Kinder message - if quadsMaxNum < 4*quads.Len() { + if quadsMaxNum < quads.Len() { return errors.New(fmt.Sprintf("len(quads) must be equal to or less than %d", quadsMaxNum)) } diff --git a/internal/graphics/internal/shader/program.go b/internal/graphics/internal/shader/program.go index 2fd343895..4e4f7b4e0 100644 --- a/internal/graphics/internal/shader/program.go +++ b/internal/graphics/internal/shader/program.go @@ -23,7 +23,7 @@ var ( programRect opengl.Program ) -const quadsMaxNum = 10000 +const quadsMaxNum = 65536 / 6 func initialize(c *opengl.Context) error { const uint16Size = 2 @@ -63,7 +63,8 @@ func initialize(c *opengl.Context) error { } const stride = 4 * 4 - c.NewBuffer(c.ArrayBuffer, stride*quadsMaxNum, c.DynamicDraw) + const float32Size = 4 + c.NewBuffer(c.ArrayBuffer, float32Size*stride*quadsMaxNum, c.DynamicDraw) indices := make([]uint16, 6*quadsMaxNum) for i := uint16(0); i < quadsMaxNum; i++ { diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index b6ef1a584..6e22b4198 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -267,7 +267,6 @@ func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsageTyp func (c *Context) BufferSubData(bufferType BufferType, data []float32) { gl := c.gl - const float32Size = 4 gl.BufferSubData(int(bufferType), 0, data) }