tofu

Making something with OpenGL in Go
Log | Files | Refs

commit 9c5ed4a4abbb7bdcc8a11b363aacb456a5122b7b
parent 235a82b16717a311840e0086b9e16b22f9756269
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 21 Oct 2024 10:27:47 +0900

add comments

Diffstat:
Mshader.go | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/shader.go b/shader.go @@ -8,6 +8,8 @@ import ( "github.com/go-gl/gl/v3.3-core/gl" ) +// CompileShader compiles shaders of type xtype using the source file specified by path. +// It returns the resulting shader ID. func compileShader(path string, xtype uint32) (shaderID uint32, err error) { src, err := os.ReadFile(path) if err != nil { @@ -35,6 +37,8 @@ func compileShader(path string, xtype uint32) (shaderID uint32, err error) { return shaderID, nil } +// LinkShaders links vertex shader vsID and fragment shader fsID and returns the +// resulting shader program. func linkShaders(vsID, fsID uint32) (shaderID uint32, err error) { shaderID = gl.CreateProgram() gl.AttachShader(shaderID, vsID) @@ -57,6 +61,8 @@ type Shader struct { id uint32 } +// NewShader creates a shader program from a vertex shader source file specified by vpath and +// a fragment shader source file specified by fpath, and returns the resulting Shader object. func NewShader(vpath, fpath string) (*Shader, error) { vid, err := compileShader(vpath, gl.VERTEX_SHADER) if err != nil { @@ -75,6 +81,7 @@ func NewShader(vpath, fpath string) (*Shader, error) { return &Shader{id: sid}, nil } +// Use activates the shader. func (s *Shader) Use() { gl.UseProgram(s.id) }