From 9400720ddf3a47eaebe1f516791af3bf78d9f6e1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 19 Feb 2018 02:06:06 +0900 Subject: [PATCH] opengl: Remove struct usages to avoid copying (shader) --- internal/opengl/context_js.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index b97055341..e43729982 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -37,11 +37,8 @@ type Framebuffer struct { *js.Object } -type Shader struct { - *js.Object -} - type ( + Shader interface{} Program interface{} Buffer interface{} ) @@ -276,7 +273,7 @@ func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error gl := c.gl s := gl.CreateShader(int(shaderType)) if s == nil { - return Shader{nil}, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType) + return nil, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType) } gl.ShaderSource(s, source) @@ -284,14 +281,14 @@ func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error if !gl.GetShaderParameterb(s, gl.COMPILE_STATUS) { log := gl.GetShaderInfoLog(s) - return Shader{nil}, fmt.Errorf("opengl: shader compile failed: %s", log) + return nil, fmt.Errorf("opengl: shader compile failed: %s", log) } - return Shader{s}, nil + return Shader(s), nil } func (c *Context) DeleteShader(s Shader) { gl := c.gl - gl.DeleteShader(s.Object) + gl.DeleteShader(s.(*js.Object)) } func (c *Context) NewProgram(shaders []Shader) (Program, error) { @@ -304,7 +301,7 @@ func (c *Context) NewProgram(shaders []Shader) (Program, error) { c.lastProgramID++ for _, shader := range shaders { - gl.AttachShader(p, shader.Object) + gl.AttachShader(p, shader.(*js.Object)) } gl.LinkProgram(p) if !gl.GetProgramParameterb(p, gl.LINK_STATUS) {