tofu

Making something with OpenGL in Go
Log | Files | Refs

commit 6b9ffa027b4ea588e1d24a27108ca97fcb10447c
parent 6cf2d131f5260739729945f616f3cb91838fede6
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 28 Oct 2024 17:17:16 +0900

simplify the process of setting up a texture

Diffstat:
Mcmd/sample/main.go | 2--
Mshader.go | 5++---
Mtexture.go | 5-----
3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/cmd/sample/main.go b/cmd/sample/main.go @@ -125,8 +125,6 @@ func main() { log.Fatalf("set texture: %v", err) } - texture1.Bind() - texture2.Bind() shader.Use() window.SetFramebufferSizeCallback(framebufferSizeCallback) diff --git a/shader.go b/shader.go @@ -59,7 +59,6 @@ func linkShaders(vsID, fsID uint32) (shaderID uint32, err error) { type Shader struct { id uint32 - nextTextureId int32 } // NewShader creates a shader program from a vertex shader source file specified by vpath and @@ -100,11 +99,11 @@ func (s *Shader) SetFloat32(name string, val float32) error { func (s *Shader) SetTexture(t *Texture, name string) error { s.Use() + gl.ActiveTexture(t.unit) l := gl.GetUniformLocation(s.id, gl.Str(name + "\x00")) if l == -1 { return fmt.Errorf("no such uniform: %s", name) } - gl.Uniform1i(l, s.nextTextureId) - s.nextTextureId++ + gl.Uniform1i(l, int32(t.unit - gl.TEXTURE0)) return nil } \ No newline at end of file diff --git a/texture.go b/texture.go @@ -67,11 +67,6 @@ func NewTextureFlip(name string, v bool, h bool) (*Texture, error) { return &Texture{id: id, unit: unit}, nil } -func (t *Texture) Bind() { - gl.ActiveTexture(t.unit) - gl.BindTexture(gl.TEXTURE_2D, t.id) -} - func flipV(img image.Image) image.Image { dst := image.NewRGBA(img.Bounds()) xmin, ymin := dst.Bounds().Min.X, dst.Bounds().Min.Y