opengl: Remove struct usages to avoid copying (shader)

This commit is contained in:
Hajime Hoshi 2018-02-19 02:06:06 +09:00
parent 9dc68289b8
commit 9400720ddf

View File

@ -37,11 +37,8 @@ type Framebuffer struct {
*js.Object *js.Object
} }
type Shader struct {
*js.Object
}
type ( type (
Shader interface{}
Program interface{} Program interface{}
Buffer interface{} Buffer interface{}
) )
@ -276,7 +273,7 @@ func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error
gl := c.gl gl := c.gl
s := gl.CreateShader(int(shaderType)) s := gl.CreateShader(int(shaderType))
if s == nil { 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) 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) { if !gl.GetShaderParameterb(s, gl.COMPILE_STATUS) {
log := gl.GetShaderInfoLog(s) 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) { func (c *Context) DeleteShader(s Shader) {
gl := c.gl gl := c.gl
gl.DeleteShader(s.Object) gl.DeleteShader(s.(*js.Object))
} }
func (c *Context) NewProgram(shaders []Shader) (Program, error) { func (c *Context) NewProgram(shaders []Shader) (Program, error) {
@ -304,7 +301,7 @@ func (c *Context) NewProgram(shaders []Shader) (Program, error) {
c.lastProgramID++ c.lastProgramID++
for _, shader := range shaders { for _, shader := range shaders {
gl.AttachShader(p, shader.Object) gl.AttachShader(p, shader.(*js.Object))
} }
gl.LinkProgram(p) gl.LinkProgram(p)
if !gl.GetProgramParameterb(p, gl.LINK_STATUS) { if !gl.GetProgramParameterb(p, gl.LINK_STATUS) {