From deb2ab1cbf34fd99b354361d15f8c05072eaa88f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 29 May 2016 18:34:30 +0900 Subject: [PATCH] graphics: Refactoring: Reduce array buffer size --- internal/graphics/opengl/context_mobile.go | 1 - internal/graphics/program.go | 3 +-- internal/loop/run.go | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/graphics/opengl/context_mobile.go b/internal/graphics/opengl/context_mobile.go index 1e0782567..6820c2f49 100644 --- a/internal/graphics/opengl/context_mobile.go +++ b/internal/graphics/opengl/context_mobile.go @@ -339,7 +339,6 @@ func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage Bu switch v := v.(type) { case int: gl.BufferInit(mgl.Enum(bufferType), v, mgl.Enum(bufferUsage)) - return Buffer(b) case []uint16: gl.BufferData(mgl.Enum(bufferType), uint16ToBytes(v), mgl.Enum(bufferUsage)) default: diff --git a/internal/graphics/program.go b/internal/graphics/program.go index d85c78fd4..ee0ad06c6 100644 --- a/internal/graphics/program.go +++ b/internal/graphics/program.go @@ -78,8 +78,7 @@ func (s *openGLState) initialize(c *opengl.Context) error { return err } - // 16 [bytes] is an arbitrary number which seems enough to draw anything. Fix this if necessary. - const stride = 16 + const stride = 8 // (2 [vertices] + 2 [texels]) * 2 [sizeof(int16)/bytes] c.NewBuffer(c.ArrayBuffer, 4*stride*MaxQuads, c.DynamicDraw) indices := make([]uint16, 6*MaxQuads) diff --git a/internal/loop/run.go b/internal/loop/run.go index 42bb14056..173b6aa9d 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -163,7 +163,8 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err // Calc the current FPS. if time.Second <= time.Duration(n2-beforeForFPS) { - currentRunContext.updateFPS(float64(frames) * float64(time.Second) / float64(n2-beforeForFPS)) + fps := float64(frames) * float64(time.Second) / float64(n2-beforeForFPS) + currentRunContext.updateFPS(fps) beforeForFPS = n2 frames = 0 }