gl: use better spec-defined func names, fix bug, increase consistency

Change func names and parameter order to more closely follow OpenGL
ES/WebGL spec.
    BufferData(target, usage, src) -> BufferData(target, src, usage)
    GenBuffer -> CreateBuffer
    GenFramebuffer -> CreateFramebuffer
    GenRenderbuffer -> CreateRenderbuffer
    GenTexture -> CreateTexture
Fix issue where glBoolean helper was returning inverted result.
Make Attrib.String() logic consistent with others (print value, not
struct).
Make internal code of GetUniformLocation the same as GetAttribLocation
and BindAttribLocation for consistency.
Resolves golang/go#10218.

Change-Id: Ib33dfff7c22c4d178b2e6b8d228f80f3c17308a8
Reviewed-on: https://go-review.googlesource.com/8000
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Dmitri Shuralyov 2015-03-23 20:18:30 -07:00 коммит произвёл David Crawshaw
Родитель 6ed9b243b1
Коммит eaba00bca5
7 изменённых файлов: 100 добавлений и 100 удалений

Просмотреть файл

@ -46,9 +46,9 @@ func start() {
return
}
buf = gl.GenBuffer()
buf = gl.CreateBuffer()
gl.BindBuffer(gl.ARRAY_BUFFER, buf)
gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, triangleData)
gl.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)
position = gl.GetAttribLocation(program, "position")
color = gl.GetUniformLocation(program, "color")

Просмотреть файл

@ -121,7 +121,7 @@ func BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha Enum)
// BufferData creates a new data store for the bound buffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml
func BufferData(target Enum, usage Enum, src []byte) {
func BufferData(target Enum, src []byte, usage Enum) {
C.glBufferData(target.c(), C.GLsizeiptr(len(src)), unsafe.Pointer(&src[0]), usage.c())
}
@ -222,6 +222,24 @@ func CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height
C.glCopyTexSubImage2D(target.c(), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
}
// CreateBuffer creates a buffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml
func CreateBuffer() Buffer {
var b Buffer
C.glGenBuffers(1, (*C.GLuint)(&b.Value))
return b
}
// CreateFramebuffer creates a framebuffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenFramebuffers.xhtml
func CreateFramebuffer() Framebuffer {
var b Framebuffer
C.glGenFramebuffers(1, (*C.GLuint)(&b.Value))
return b
}
// CreateProgram creates a new empty program object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateProgram.xhtml
@ -229,6 +247,15 @@ func CreateProgram() Program {
return Program{Value: uint32(C.glCreateProgram())}
}
// CreateRenderbuffer create a renderbuffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenRenderbuffers.xhtml
func CreateRenderbuffer() Renderbuffer {
var b Renderbuffer
C.glGenRenderbuffers(1, (*C.GLuint)(&b.Value))
return b
}
// CreateShader creates a new empty shader object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateShader.xhtml
@ -236,6 +263,15 @@ func CreateShader(ty Enum) Shader {
return Shader{Value: uint32(C.glCreateShader(ty.c()))}
}
// CreateTexture creates a texture object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml
func CreateTexture() Texture {
var t Texture
C.glGenTextures(1, (*C.GLuint)(&t.Value))
return t
}
// CullFace specifies which polygons are candidates for culling.
//
// Valid modes: FRONT, BACK, FRONT_AND_BACK.
@ -409,15 +445,6 @@ func FrontFace(mode Enum) {
C.glFrontFace(mode.c())
}
// GenBuffer creates a buffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml
func GenBuffer() Buffer {
var b Buffer
C.glGenBuffers(1, (*C.GLuint)(&b.Value))
return b
}
// GenerateMipmap generates mipmaps for the current texture.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenerateMipmap.xhtml
@ -425,33 +452,6 @@ func GenerateMipmap(target Enum) {
C.glGenerateMipmap(target.c())
}
// GenFramebuffer creates a framebuffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenFramebuffers.xhtml
func GenFramebuffer() Framebuffer {
var b Framebuffer
C.glGenFramebuffers(1, (*C.GLuint)(&b.Value))
return b
}
// GenRenderbuffer create a renderbuffer object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenRenderbuffers.xhtml
func GenRenderbuffer() Renderbuffer {
var b Renderbuffer
C.glGenRenderbuffers(1, (*C.GLuint)(&b.Value))
return b
}
// GenTexture creates a texture object.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml
func GenTexture() Texture {
var t Texture
C.glGenTextures(1, (*C.GLuint)(&t.Value))
return t
}
// GetActiveAttrib returns details about an attribute variable.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveAttrib.xhtml
@ -660,10 +660,10 @@ func GetShaderSource(s Shader) string {
// VERSION
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGetString.xhtml
func GetString(name Enum) string {
func GetString(pname Enum) string {
// Bounce through unsafe.Pointer, because on some platforms
// GetString returns an *unsigned char which doesn't convert.
return C.GoString((*C.char)((unsafe.Pointer)(C.glGetString(name.c()))))
return C.GoString((*C.char)((unsafe.Pointer)(C.glGetString(pname.c()))))
}
// GetTexParameterfv returns the float values of a texture parameter.
@ -698,8 +698,8 @@ func GetUniformiv(dst []int32, src Uniform, p Program) {
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniformLocation.xhtml
func GetUniformLocation(p Program, name string) Uniform {
str := C.CString(name)
defer C.free((unsafe.Pointer)(str))
str := unsafe.Pointer(C.CString(name))
defer C.free(str)
return Uniform{Value: int32(C.glGetUniformLocation(p.c(), (*C.GLchar)(str)))}
}

Просмотреть файл

@ -739,10 +739,10 @@ func BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha Enum)
C.glBlendFuncSeparate(sfactorRGB.c(), dfactorRGB.c(), sfactorAlpha.c(), dfactorAlpha.c())
}
func BufferData(target Enum, usage Enum, src []byte) {
func BufferData(target Enum, src []byte, usage Enum) {
defer func() {
errstr := errDrain()
log.Printf("gl.BufferData(%v, %v, len(%d)) %v", target, usage, len(src), errstr)
log.Printf("gl.BufferData(%v, len(%d), %v) %v", target, len(src), usage, errstr)
}()
C.glBufferData(target.c(), C.GLsizeiptr(len(src)), unsafe.Pointer(&src[0]), usage.c())
}
@ -851,6 +851,26 @@ func CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height
C.glCopyTexSubImage2D(target.c(), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
}
func CreateBuffer() (r0 Buffer) {
defer func() {
errstr := errDrain()
log.Printf("gl.CreateBuffer() %v%v", r0, errstr)
}()
var b Buffer
C.glGenBuffers(1, (*C.GLuint)(&b.Value))
return b
}
func CreateFramebuffer() (r0 Framebuffer) {
defer func() {
errstr := errDrain()
log.Printf("gl.CreateFramebuffer() %v%v", r0, errstr)
}()
var b Framebuffer
C.glGenFramebuffers(1, (*C.GLuint)(&b.Value))
return b
}
func CreateProgram() (r0 Program) {
defer func() {
errstr := errDrain()
@ -859,6 +879,16 @@ func CreateProgram() (r0 Program) {
return Program{Value: uint32(C.glCreateProgram())}
}
func CreateRenderbuffer() (r0 Renderbuffer) {
defer func() {
errstr := errDrain()
log.Printf("gl.CreateRenderbuffer() %v%v", r0, errstr)
}()
var b Renderbuffer
C.glGenRenderbuffers(1, (*C.GLuint)(&b.Value))
return b
}
func CreateShader(ty Enum) (r0 Shader) {
defer func() {
errstr := errDrain()
@ -867,6 +897,16 @@ func CreateShader(ty Enum) (r0 Shader) {
return Shader{Value: uint32(C.glCreateShader(ty.c()))}
}
func CreateTexture() (r0 Texture) {
defer func() {
errstr := errDrain()
log.Printf("gl.CreateTexture() %v%v", r0, errstr)
}()
var t Texture
C.glGenTextures(1, (*C.GLuint)(&t.Value))
return t
}
func CullFace(mode Enum) {
defer func() {
errstr := errDrain()
@ -1043,16 +1083,6 @@ func FrontFace(mode Enum) {
C.glFrontFace(mode.c())
}
func GenBuffer() (r0 Buffer) {
defer func() {
errstr := errDrain()
log.Printf("gl.GenBuffer() %v%v", r0, errstr)
}()
var b Buffer
C.glGenBuffers(1, (*C.GLuint)(&b.Value))
return b
}
func GenerateMipmap(target Enum) {
defer func() {
errstr := errDrain()
@ -1061,36 +1091,6 @@ func GenerateMipmap(target Enum) {
C.glGenerateMipmap(target.c())
}
func GenFramebuffer() (r0 Framebuffer) {
defer func() {
errstr := errDrain()
log.Printf("gl.GenFramebuffer() %v%v", r0, errstr)
}()
var b Framebuffer
C.glGenFramebuffers(1, (*C.GLuint)(&b.Value))
return b
}
func GenRenderbuffer() (r0 Renderbuffer) {
defer func() {
errstr := errDrain()
log.Printf("gl.GenRenderbuffer() %v%v", r0, errstr)
}()
var b Renderbuffer
C.glGenRenderbuffers(1, (*C.GLuint)(&b.Value))
return b
}
func GenTexture() (r0 Texture) {
defer func() {
errstr := errDrain()
log.Printf("gl.GenTexture() %v%v", r0, errstr)
}()
var t Texture
C.glGenTextures(1, (*C.GLuint)(&t.Value))
return t
}
func GetActiveAttrib(p Program, a Attrib) (name string, size int, ty Enum) {
defer func() {
errstr := errDrain()
@ -1298,12 +1298,12 @@ func GetShaderSource(s Shader) (r0 string) {
return C.GoString((*C.char)(buf))
}
func GetString(name Enum) (r0 string) {
func GetString(pname Enum) (r0 string) {
defer func() {
errstr := errDrain()
log.Printf("gl.GetString(%v) %v%v", name, r0, errstr)
log.Printf("gl.GetString(%v) %v%v", pname, r0, errstr)
}()
return C.GoString((*C.char)((unsafe.Pointer)(C.glGetString(name.c()))))
return C.GoString((*C.char)((unsafe.Pointer)(C.glGetString(pname.c()))))
}
func GetTexParameterfv(dst []float32, target, pname Enum) {
@ -1344,8 +1344,8 @@ func GetUniformLocation(p Program, name string) (r0 Uniform) {
r0.name = name
log.Printf("gl.GetUniformLocation(%v, %v) %v%v", p, name, r0, errstr)
}()
str := C.CString(name)
defer C.free((unsafe.Pointer)(str))
str := unsafe.Pointer(C.CString(name))
defer C.free(str)
return Uniform{Value: int32(C.glGetUniformLocation(p.c(), (*C.GLchar)(str)))}
}

Просмотреть файл

@ -35,13 +35,13 @@ func glInit() {
panic(err)
}
glimage.quadXY = gl.GenBuffer()
glimage.quadUV = gl.GenBuffer()
glimage.quadXY = gl.CreateBuffer()
glimage.quadUV = gl.CreateBuffer()
gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadXY)
gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, quadXYCoords)
gl.BufferData(gl.ARRAY_BUFFER, quadXYCoords, gl.STATIC_DRAW)
gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV)
gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, quadUVCoords)
gl.BufferData(gl.ARRAY_BUFFER, quadUVCoords, gl.STATIC_DRAW)
glimage.pos = gl.GetAttribLocation(glimage.program, "pos")
glimage.mvp = gl.GetUniformLocation(glimage.program, "mvp")
@ -81,7 +81,7 @@ func NewImage(w, h int) *Image {
img := &Image{
RGBA: m.SubImage(image.Rect(0, 0, w, h)).(*image.RGBA),
Texture: gl.GenTexture(),
Texture: gl.CreateTexture(),
texWidth: dx,
texHeight: dy,
}

Просмотреть файл

@ -52,9 +52,9 @@ func TestImage(t *testing.T) {
geom.Width = ptW
geom.Height = ptH
fBuf := gl.GenFramebuffer()
fBuf := gl.CreateFramebuffer()
gl.BindFramebuffer(gl.FRAMEBUFFER, fBuf)
colorBuf := gl.GenRenderbuffer()
colorBuf := gl.CreateRenderbuffer()
gl.BindRenderbuffer(gl.RENDERBUFFER, colorBuf)
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glRenderbufferStorage.xml
// says that the internalFormat "must be one of the following symbolic constants:

Просмотреть файл

@ -81,9 +81,9 @@ func (u Uniform) WriteVec4(v *f32.Vec4) {
func glBoolean(b bool) C.GLboolean {
if b {
return 0
return TRUE
}
return 1
return FALSE
}
// Desktop OpenGL and the ES 2/3 APIs have a very slight difference

Просмотреть файл

@ -78,7 +78,7 @@ func (v Renderbuffer) c() C.GLuint { return C.GLuint(v.Value) }
func (v Texture) c() C.GLuint { return C.GLuint(v.Value) }
func (v Uniform) c() C.GLint { return C.GLint(v.Value) }
func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d)", v) }
func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d)", v.Value) }
func (v Program) String() string { return fmt.Sprintf("Program(%d)", v.Value) }
func (v Shader) String() string { return fmt.Sprintf("Shader(%d)", v.Value) }
func (v Buffer) String() string { return fmt.Sprintf("Buffer(%d)", v.Value) }