Add opengl.AttribLocation

This commit is contained in:
Hajime Hoshi 2014-12-31 17:01:08 +09:00
parent b8dde70b03
commit 37828c452f
3 changed files with 19 additions and 12 deletions

View File

@ -85,8 +85,8 @@ func DrawTexture(c *opengl.Context, native gl.Texture, projectionMatrix [4][4]fl
gl.ActiveTexture(gl.TEXTURE0) gl.ActiveTexture(gl.TEXTURE0)
native.Bind(gl.TEXTURE_2D) native.Bind(gl.TEXTURE_2D)
vertexAttrLocation := getAttributeLocation(program, "vertex") vertexAttrLocation := program.GetAttributeLocation("vertex")
texCoordAttrLocation := getAttributeLocation(program, "tex_coord") texCoordAttrLocation := program.GetAttributeLocation("tex_coord")
vertexAttrLocation.EnableArray() vertexAttrLocation.EnableArray()
texCoordAttrLocation.EnableArray() texCoordAttrLocation.EnableArray()
@ -95,8 +95,8 @@ func DrawTexture(c *opengl.Context, native gl.Texture, projectionMatrix [4][4]fl
vertexAttrLocation.DisableArray() vertexAttrLocation.DisableArray()
}() }()
vertexAttrLocation.AttribPointer(2, gl.FLOAT, false, stride, uintptr(float32Size*0)) vertexAttrLocation.AttribPointer(stride, uintptr(float32Size*0))
texCoordAttrLocation.AttribPointer(2, gl.FLOAT, false, stride, uintptr(float32Size*2)) texCoordAttrLocation.AttribPointer(stride, uintptr(float32Size*2))
vertices := []float32{} vertices := []float32{}
for i := 0; i < quads.Len(); i++ { for i := 0; i < quads.Len(); i++ {

View File

@ -15,7 +15,6 @@
package shader package shader
import ( import (
"github.com/go-gl/gl"
"github.com/hajimehoshi/ebiten/internal/opengl" "github.com/hajimehoshi/ebiten/internal/opengl"
) )
@ -43,13 +42,9 @@ func initialize(c *opengl.Context) error {
return err return err
} }
func getAttributeLocation(program gl.Program, name string) gl.AttribLocation {
return program.GetAttribLocation(name)
}
var lastProgram opengl.Program = 0 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 { if lastProgram != programColorMatrix {
programColorMatrix.Use() programColorMatrix.Use()
lastProgram = programColorMatrix lastProgram = programColorMatrix
@ -94,5 +89,5 @@ func useProgramColorMatrix(projectionMatrix [16]float32, geo Matrix, color Matri
} }
program.GetUniformLocation("color_matrix_translation").Uniform4fv(1, glColorMatrixTranslation[:]) program.GetUniformLocation("color_matrix_translation").Uniform4fv(1, glColorMatrixTranslation[:])
return gl.Program(program) return program
} }

View File

@ -90,7 +90,7 @@ func (p Program) Use() {
gl.Program(p).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)) return AttribLocation(gl.Program(p).GetAttribLocation(name))
} }
@ -100,6 +100,18 @@ func (p Program) GetUniformLocation(name string) UniformLocation {
type AttribLocation int 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 type UniformLocation int
func (u UniformLocation) UniformMatrix4fv(matrix [16]float32) { func (u UniformLocation) UniformMatrix4fv(matrix [16]float32) {