graphics: Refactoring: Reduce array buffer size

This commit is contained in:
Hajime Hoshi 2016-05-29 18:34:30 +09:00
parent ebac6cbb81
commit deb2ab1cbf
3 changed files with 3 additions and 4 deletions

View File

@ -339,7 +339,6 @@ func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage Bu
switch v := v.(type) { switch v := v.(type) {
case int: case int:
gl.BufferInit(mgl.Enum(bufferType), v, mgl.Enum(bufferUsage)) gl.BufferInit(mgl.Enum(bufferType), v, mgl.Enum(bufferUsage))
return Buffer(b)
case []uint16: case []uint16:
gl.BufferData(mgl.Enum(bufferType), uint16ToBytes(v), mgl.Enum(bufferUsage)) gl.BufferData(mgl.Enum(bufferType), uint16ToBytes(v), mgl.Enum(bufferUsage))
default: default:

View File

@ -78,8 +78,7 @@ func (s *openGLState) initialize(c *opengl.Context) error {
return err return err
} }
// 16 [bytes] is an arbitrary number which seems enough to draw anything. Fix this if necessary. const stride = 8 // (2 [vertices] + 2 [texels]) * 2 [sizeof(int16)/bytes]
const stride = 16
c.NewBuffer(c.ArrayBuffer, 4*stride*MaxQuads, c.DynamicDraw) c.NewBuffer(c.ArrayBuffer, 4*stride*MaxQuads, c.DynamicDraw)
indices := make([]uint16, 6*MaxQuads) indices := make([]uint16, 6*MaxQuads)

View File

@ -163,7 +163,8 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err
// Calc the current FPS. // Calc the current FPS.
if time.Second <= time.Duration(n2-beforeForFPS) { 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 beforeForFPS = n2
frames = 0 frames = 0
} }