From da598663f7fe98a4bc748b03f5db378b331f370c Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 16 May 2019 21:47:30 +0200 Subject: [PATCH] ui/app: add GL buffer caches Signed-off-by: Elias Naur --- ui/app/egl.go | 1 + ui/app/gl_ios.go | 1 + ui/app/gl_macos.go | 1 + ui/app/internal/gl/functions.go | 42 +++++++++++++------------------- ui/app/internal/gl/gl_windows.go | 31 ++++++++++------------- 5 files changed, 33 insertions(+), 43 deletions(-) diff --git a/ui/app/egl.go b/ui/app/egl.go index 2bb9bd30..5c8b0dae 100644 --- a/ui/app/egl.go +++ b/ui/app/egl.go @@ -105,6 +105,7 @@ func newContext(w *window) (*context, error) { c := &context{ driver: w, eglCtx: eglCtx, + c: new(gl.Functions), } return c, nil } diff --git a/ui/app/gl_ios.go b/ui/app/gl_ios.go index 95fca1e1..dcf872fd 100644 --- a/ui/app/gl_ios.go +++ b/ui/app/gl_ios.go @@ -46,6 +46,7 @@ func newContext(w *window) (*context, error) { ctx: ctx, owner: w, layer: C.CFTypeRef(w.contextLayer()), + c: new(gl.Functions), } return c, nil } diff --git a/ui/app/gl_macos.go b/ui/app/gl_macos.go index 5c36a817..c7348c18 100644 --- a/ui/app/gl_macos.go +++ b/ui/app/gl_macos.go @@ -34,6 +34,7 @@ func newContext(w *window) (*context, error) { ctx := C.gio_contextForView(w.contextView()) c := &context{ ctx: ctx, + c: new(gl.Functions), } return c, nil } diff --git a/ui/app/internal/gl/functions.go b/ui/app/internal/gl/functions.go index 2bc93b5a..92e9254a 100644 --- a/ui/app/internal/gl/functions.go +++ b/ui/app/internal/gl/functions.go @@ -113,7 +113,11 @@ __attribute__((constructor)) static void gio_loadGLFunctions() { */ import "C" -type Functions struct{} +type Functions struct { + // Query caches. + uints [100]C.GLuint + ints [100]C.GLint +} func (f *Functions) ActiveTexture(texture Enum) { C.glActiveTexture(C.GLenum(texture)) @@ -317,31 +321,23 @@ func (f *Functions) GetError() Enum { } func (f *Functions) GetRenderbufferParameteri(target, pname Enum) int { - // Hope this is enough room. - var buf [100]C.GLint - C.glGetRenderbufferParameteriv(C.GLenum(target), C.GLenum(pname), &buf[0]) - return int(buf[0]) + C.glGetRenderbufferParameteriv(C.GLenum(target), C.GLenum(pname), &f.ints[0]) + return int(f.ints[0]) } func (f *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int { - // Hope this is enough room. - var buf [100]C.GLint - C.glGetFramebufferAttachmentParameteriv(C.GLenum(target), C.GLenum(attachment), C.GLenum(pname), &buf[0]) - return int(buf[0]) + C.glGetFramebufferAttachmentParameteriv(C.GLenum(target), C.GLenum(attachment), C.GLenum(pname), &f.ints[0]) + return int(f.ints[0]) } func (f *Functions) GetInteger(pname Enum) int { - // Hope this is enough room. - var buf [100]C.GLint - C.glGetIntegerv(C.GLenum(pname), &buf[0]) - return int(buf[0]) + C.glGetIntegerv(C.GLenum(pname), &f.ints[0]) + return int(f.ints[0]) } func (f *Functions) GetProgrami(p Program, pname Enum) int { - // Hope this is enough room. - var buf [100]C.GLint - C.glGetProgramiv(C.GLuint(p.V), C.GLenum(pname), &buf[0]) - return int(buf[0]) + C.glGetProgramiv(C.GLuint(p.V), C.GLenum(pname), &f.ints[0]) + return int(f.ints[0]) } func (f *Functions) GetProgramInfoLog(p Program) string { @@ -357,17 +353,13 @@ func (f *Functions) GetProgramInfoLog(p Program) string { } func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint { - // Hope this is enough room. - var buf [100]C.GLuint - C.gio_glGetQueryObjectuiv(C.GLuint(query.V), C.GLenum(pname), &buf[0]) - return uint(buf[0]) + C.gio_glGetQueryObjectuiv(C.GLuint(query.V), C.GLenum(pname), &f.uints[0]) + return uint(f.uints[0]) } func (f *Functions) GetShaderi(s Shader, pname Enum) int { - // Hope this is enough room. - var buf [100]C.GLint - C.glGetShaderiv(C.GLuint(s.V), C.GLenum(pname), &buf[0]) - return int(buf[0]) + C.glGetShaderiv(C.GLuint(s.V), C.GLenum(pname), &f.ints[0]) + return int(f.ints[0]) } func (f *Functions) GetShaderInfoLog(s Shader) string { diff --git a/ui/app/internal/gl/gl_windows.go b/ui/app/internal/gl/gl_windows.go index e4b5aa8c..f7c7d3db 100644 --- a/ui/app/internal/gl/gl_windows.go +++ b/ui/app/internal/gl/gl_windows.go @@ -86,7 +86,10 @@ var ( _glViewport = LibGLESv2.NewProc("glViewport") ) -type Functions struct{} +type Functions struct { + // Query caches. + int32s [100]int32 +} func (c *Functions) ActiveTexture(t Enum) { syscall.Syscall(_glActiveTexture.Addr(), 1, uintptr(t), 0, 0) @@ -252,16 +255,12 @@ func (c *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname return int(p) } func (c *Functions) GetInteger(pname Enum) int { - // Hopefully enough room. - var params [100]int32 - syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(¶ms[0])), 0) - return int(params[0]) + syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0) + return int(c.int32s[0]) } func (c *Functions) GetProgrami(p Program, pname Enum) int { - // Hopefully enough space. - var params [100]int32 - syscall.Syscall(_glGetProgramiv.Addr(), 3, uintptr(p.V), uintptr(pname), uintptr(unsafe.Pointer(¶ms[0]))) - return int(params[0]) + syscall.Syscall(_glGetProgramiv.Addr(), 3, uintptr(p.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0]))) + return int(c.int32s[0]) } func (c *Functions) GetProgramInfoLog(p Program) string { var n uintptr @@ -274,17 +273,13 @@ func (c *Functions) GetProgramInfoLog(p Program) string { syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), uintptr(len(buf)), uintptr(unsafe.Pointer(&n)), uintptr(unsafe.Pointer(&buf[0])), 0, 0) return string(buf[:len(buf)-1]) } -func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint { - // Hope this is enough room. - var buf [100]int32 - syscall.Syscall(_glGetQueryObjectuiv.Addr(), 3, uintptr(query.V), uintptr(pname), uintptr(unsafe.Pointer(&buf[0]))) - return uint(buf[0]) +func (c *Functions) GetQueryObjectuiv(query Query, pname Enum) uint { + syscall.Syscall(_glGetQueryObjectuiv.Addr(), 3, uintptr(query.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0]))) + return uint(c.int32s[0]) } func (c *Functions) GetShaderi(s Shader, pname Enum) int { - // Hopefully enough room. - var params [100]int32 - syscall.Syscall(_glGetShaderiv.Addr(), 3, uintptr(s.V), uintptr(pname), uintptr(unsafe.Pointer(¶ms[0]))) - return int(params[0]) + syscall.Syscall(_glGetShaderiv.Addr(), 3, uintptr(s.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0]))) + return int(c.int32s[0]) } func (c *Functions) GetShaderInfoLog(s Shader) string { var n uintptr