diff --git a/internal/graphics/internal/shader/drawtexture.go b/internal/graphics/internal/shader/drawtexture.go index ca59783e5..1d0307932 100644 --- a/internal/graphics/internal/shader/drawtexture.go +++ b/internal/graphics/internal/shader/drawtexture.go @@ -85,8 +85,8 @@ func DrawTexture(c *opengl.Context, native gl.Texture, projectionMatrix [4][4]fl gl.ActiveTexture(gl.TEXTURE0) native.Bind(gl.TEXTURE_2D) - vertexAttrLocation := getAttributeLocation(program, "vertex") - texCoordAttrLocation := getAttributeLocation(program, "tex_coord") + vertexAttrLocation := program.GetAttributeLocation("vertex") + texCoordAttrLocation := program.GetAttributeLocation("tex_coord") vertexAttrLocation.EnableArray() texCoordAttrLocation.EnableArray() @@ -95,8 +95,8 @@ func DrawTexture(c *opengl.Context, native gl.Texture, projectionMatrix [4][4]fl vertexAttrLocation.DisableArray() }() - vertexAttrLocation.AttribPointer(2, gl.FLOAT, false, stride, uintptr(float32Size*0)) - texCoordAttrLocation.AttribPointer(2, gl.FLOAT, false, stride, uintptr(float32Size*2)) + vertexAttrLocation.AttribPointer(stride, uintptr(float32Size*0)) + texCoordAttrLocation.AttribPointer(stride, uintptr(float32Size*2)) vertices := []float32{} for i := 0; i < quads.Len(); i++ { diff --git a/internal/graphics/internal/shader/program.go b/internal/graphics/internal/shader/program.go index e93b9a26a..ae3770c69 100644 --- a/internal/graphics/internal/shader/program.go +++ b/internal/graphics/internal/shader/program.go @@ -15,7 +15,6 @@ package shader import ( - "github.com/go-gl/gl" "github.com/hajimehoshi/ebiten/internal/opengl" ) @@ -43,13 +42,9 @@ func initialize(c *opengl.Context) error { return err } -func getAttributeLocation(program gl.Program, name string) gl.AttribLocation { - return program.GetAttribLocation(name) -} - var lastProgram opengl.Program = 0 -func useProgramColorMatrix(projectionMatrix [16]float32, geo Matrix, color Matrix) gl.Program { +func useProgramColorMatrix(projectionMatrix [16]float32, geo Matrix, color Matrix) opengl.Program { if lastProgram != programColorMatrix { programColorMatrix.Use() lastProgram = programColorMatrix @@ -94,5 +89,5 @@ func useProgramColorMatrix(projectionMatrix [16]float32, geo Matrix, color Matri } program.GetUniformLocation("color_matrix_translation").Uniform4fv(1, glColorMatrixTranslation[:]) - return gl.Program(program) + return program } diff --git a/internal/opengl/context.go b/internal/opengl/context.go index f313b1a4a..a2e0f177d 100644 --- a/internal/opengl/context.go +++ b/internal/opengl/context.go @@ -90,7 +90,7 @@ func (p Program) Use() { gl.Program(p).Use() } -func (p Program) GetAttribLocation(name string) AttribLocation { +func (p Program) GetAttributeLocation(name string) AttribLocation { return AttribLocation(gl.Program(p).GetAttribLocation(name)) } @@ -100,6 +100,18 @@ func (p Program) GetUniformLocation(name string) UniformLocation { type AttribLocation int +func (a AttribLocation) EnableArray() { + gl.AttribLocation(a).EnableArray() +} + +func (a AttribLocation) DisableArray() { + gl.AttribLocation(a).DisableArray() +} + +func (a AttribLocation) AttribPointer(stride int, x uintptr) { + gl.AttribLocation(a).AttribPointer(2, gl.FLOAT, false, stride, x) +} + type UniformLocation int func (u UniformLocation) UniformMatrix4fv(matrix [16]float32) {