Hajime Hoshi 2024-07-04 21:46:45 +09:00
parent ed73f028c7
commit 4997e7e254
2 changed files with 12 additions and 10 deletions

View File

@ -398,10 +398,6 @@ func (c *context) newShader(shaderType uint32, source string) (shader, error) {
c.ctx.ShaderSource(s, source)
c.ctx.CompileShader(s)
if c.ctx.GetShaderi(s, gl.COMPILE_STATUS) == gl.FALSE {
log := c.ctx.GetShaderInfoLog(s)
return 0, fmt.Errorf("opengl: shader compile failed: %s", log)
}
return shader(s), nil
}
@ -420,10 +416,6 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er
}
c.ctx.LinkProgram(p)
if c.ctx.GetProgrami(p, gl.LINK_STATUS) == gl.FALSE {
info := c.ctx.GetProgramInfoLog(p)
return 0, fmt.Errorf("opengl: program error: %s", info)
}
return program(p), nil
}

View File

@ -59,13 +59,13 @@ func (s *Shader) compile() error {
vs, err := s.graphics.context.newShader(gl.VERTEX_SHADER, vssrc)
if err != nil {
return fmt.Errorf("opengl: vertex shader compile error: %v, source:\n%s", err, vssrc)
return err
}
defer s.graphics.context.ctx.DeleteShader(uint32(vs))
fs, err := s.graphics.context.newShader(gl.FRAGMENT_SHADER, fssrc)
if err != nil {
return fmt.Errorf("opengl: fragment shader compile error: %v, source:\n%s", err, fssrc)
return err
}
defer s.graphics.context.ctx.DeleteShader(uint32(fs))
@ -74,6 +74,16 @@ func (s *Shader) compile() error {
return err
}
// Check errors only after linking fails.
// See https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#dont_check_shader_compile_status_unless_linking_fails
if s.graphics.context.ctx.GetProgrami(uint32(p), gl.LINK_STATUS) == gl.FALSE {
programInfo := s.graphics.context.ctx.GetProgramInfoLog(uint32(p))
vertexShaderInfo := s.graphics.context.ctx.GetShaderInfoLog(uint32(vs))
fragmentShaderInfo := s.graphics.context.ctx.GetShaderInfoLog(uint32(fs))
return fmt.Errorf("opengl: program error: %s\nvertex shader error: %s\nvertex shader source: %s\nfragment shader error: %s\nfragment shader source: %s",
programInfo, vertexShaderInfo, vssrc, fragmentShaderInfo, fssrc)
}
s.p = p
return nil
}