internal/graphicsdriver/opengl/gl: hide concrete context types

This commit is contained in:
Hajime Hoshi 2022-11-13 17:13:52 +09:00
parent b66cf74c99
commit b536b82109
4 changed files with 148 additions and 144 deletions

View File

@ -45,47 +45,51 @@ func glBool(x bool) C.GLboolean {
return FALSE
}
type DefaultContext struct{}
type defaultContext struct{}
func (DefaultContext) ActiveTexture(texture uint32) {
func NewDefaultContext() Context {
return defaultContext{}
}
func (defaultContext) ActiveTexture(texture uint32) {
C.glActiveTexture(C.GLenum(texture))
}
func (DefaultContext) AttachShader(program uint32, shader uint32) {
func (defaultContext) AttachShader(program uint32, shader uint32) {
C.glAttachShader(C.GLuint(program), C.GLuint(shader))
}
func (DefaultContext) BindAttribLocation(program uint32, index uint32, name string) {
func (defaultContext) BindAttribLocation(program uint32, index uint32, name string) {
s := C.CString(name)
defer C.free(unsafe.Pointer(s))
C.glBindAttribLocation(C.GLuint(program), C.GLuint(index), (*C.GLchar)(unsafe.Pointer(s)))
}
func (DefaultContext) BindBuffer(target uint32, buffer uint32) {
func (defaultContext) BindBuffer(target uint32, buffer uint32) {
C.glBindBuffer(C.GLenum(target), C.GLuint(buffer))
}
func (DefaultContext) BindFramebuffer(target uint32, framebuffer uint32) {
func (defaultContext) BindFramebuffer(target uint32, framebuffer uint32) {
C.glBindFramebuffer(C.GLenum(target), C.GLuint(framebuffer))
}
func (DefaultContext) BindRenderbuffer(target uint32, renderbuffer uint32) {
func (defaultContext) BindRenderbuffer(target uint32, renderbuffer uint32) {
C.glBindRenderbuffer(C.GLenum(target), C.GLuint(renderbuffer))
}
func (DefaultContext) BindTexture(target uint32, texture uint32) {
func (defaultContext) BindTexture(target uint32, texture uint32) {
C.glBindTexture(C.GLenum(target), C.GLuint(texture))
}
func (DefaultContext) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
func (defaultContext) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
C.glBlendEquationSeparate(C.GLenum(modeRGB), C.GLenum(modeAlpha))
}
func (DefaultContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
func (defaultContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
C.glBlendFuncSeparate(C.GLenum(srcRGB), C.GLenum(dstRGB), C.GLenum(srcAlpha), C.GLenum(dstAlpha))
}
func (DefaultContext) BufferData(target uint32, size int, data []byte, usage uint32) {
func (defaultContext) BufferData(target uint32, size int, data []byte, usage uint32) {
var p *byte
if data != nil {
p = &data[0]
@ -93,123 +97,123 @@ func (DefaultContext) BufferData(target uint32, size int, data []byte, usage uin
C.glBufferData(C.GLenum(target), C.GLsizeiptr(size), unsafe.Pointer(p), C.GLenum(usage))
}
func (DefaultContext) BufferSubData(target uint32, offset int, data []byte) {
func (defaultContext) BufferSubData(target uint32, offset int, data []byte) {
C.glBufferSubData(C.GLenum(target), C.GLintptr(offset), C.GLsizeiptr(len(data)), unsafe.Pointer(&data[0]))
}
func (DefaultContext) CheckFramebufferStatus(target uint32) uint32 {
func (defaultContext) CheckFramebufferStatus(target uint32) uint32 {
return uint32(C.glCheckFramebufferStatus(C.GLenum(target)))
}
func (DefaultContext) Clear(mask uint32) {
func (defaultContext) Clear(mask uint32) {
C.glClear(C.GLbitfield(mask))
}
func (DefaultContext) ColorMask(red, green, blue, alpha bool) {
func (defaultContext) ColorMask(red, green, blue, alpha bool) {
C.glColorMask(glBool(red), glBool(green), glBool(blue), glBool(alpha))
}
func (DefaultContext) CompileShader(shader uint32) {
func (defaultContext) CompileShader(shader uint32) {
C.glCompileShader(C.GLuint(shader))
}
func (DefaultContext) CreateProgram() uint32 {
func (defaultContext) CreateProgram() uint32 {
return uint32(C.glCreateProgram())
}
func (DefaultContext) CreateShader(xtype uint32) uint32 {
func (defaultContext) CreateShader(xtype uint32) uint32 {
return uint32(C.glCreateShader(C.GLenum(xtype)))
}
func (DefaultContext) DeleteBuffers(buffers []uint32) {
func (defaultContext) DeleteBuffers(buffers []uint32) {
C.glDeleteBuffers(C.GLsizei(len(buffers)), (*C.GLuint)(unsafe.Pointer(&buffers[0])))
}
func (DefaultContext) DeleteFramebuffers(framebuffers []uint32) {
func (defaultContext) DeleteFramebuffers(framebuffers []uint32) {
C.glDeleteFramebuffers(C.GLsizei(len(framebuffers)), (*C.GLuint)(unsafe.Pointer(&framebuffers[0])))
}
func (DefaultContext) DeleteProgram(program uint32) {
func (defaultContext) DeleteProgram(program uint32) {
C.glDeleteProgram(C.GLuint(program))
}
func (DefaultContext) DeleteRenderbuffers(renderbuffers []uint32) {
func (defaultContext) DeleteRenderbuffers(renderbuffers []uint32) {
C.glDeleteRenderbuffers(C.GLsizei(len(renderbuffers)), (*C.GLuint)(unsafe.Pointer(&renderbuffers[0])))
}
func (DefaultContext) DeleteShader(shader uint32) {
func (defaultContext) DeleteShader(shader uint32) {
C.glDeleteShader(C.GLuint(shader))
}
func (DefaultContext) DeleteTextures(textures []uint32) {
func (defaultContext) DeleteTextures(textures []uint32) {
C.glDeleteTextures(C.GLsizei(len(textures)), (*C.GLuint)(unsafe.Pointer(&textures[0])))
}
func (DefaultContext) Disable(cap uint32) {
func (defaultContext) Disable(cap uint32) {
C.glDisable(C.GLenum(cap))
}
func (DefaultContext) DisableVertexAttribArray(index uint32) {
func (defaultContext) DisableVertexAttribArray(index uint32) {
C.glDisableVertexAttribArray(C.GLuint(index))
}
func (DefaultContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
func (defaultContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
C.glDrawElements(C.GLenum(mode), C.GLsizei(count), C.GLenum(xtype), unsafe.Pointer(uintptr(offset)))
}
func (DefaultContext) Enable(cap uint32) {
func (defaultContext) Enable(cap uint32) {
C.glEnable(C.GLenum(cap))
}
func (DefaultContext) EnableVertexAttribArray(index uint32) {
func (defaultContext) EnableVertexAttribArray(index uint32) {
C.glEnableVertexAttribArray(C.GLuint(index))
}
func (DefaultContext) Flush() {
func (defaultContext) Flush() {
C.glFlush()
}
func (DefaultContext) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
func (defaultContext) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
C.glFramebufferRenderbuffer(C.GLenum(target), C.GLenum(attachment), C.GLenum(renderbuffertarget), C.GLuint(renderbuffer))
}
func (DefaultContext) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) {
func (defaultContext) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) {
C.glFramebufferTexture2D(C.GLenum(target), C.GLenum(attachment), C.GLenum(textarget), C.GLuint(texture), C.GLint(level))
}
func (DefaultContext) GenBuffers(n int32) []uint32 {
func (defaultContext) GenBuffers(n int32) []uint32 {
buffers := make([]uint32, n)
C.glGenBuffers(C.GLsizei(n), (*C.GLuint)(unsafe.Pointer(&buffers[0])))
return buffers
}
func (DefaultContext) GenFramebuffers(n int32) []uint32 {
func (defaultContext) GenFramebuffers(n int32) []uint32 {
framebuffers := make([]uint32, n)
C.glGenFramebuffers(C.GLsizei(n), (*C.GLuint)(unsafe.Pointer(&framebuffers[0])))
return framebuffers
}
func (DefaultContext) GenRenderbuffers(n int32) []uint32 {
func (defaultContext) GenRenderbuffers(n int32) []uint32 {
renderbuffers := make([]uint32, n)
C.glGenRenderbuffers(C.GLsizei(n), (*C.GLuint)(unsafe.Pointer(&renderbuffers[0])))
return renderbuffers
}
func (DefaultContext) GenTextures(n int32) []uint32 {
func (defaultContext) GenTextures(n int32) []uint32 {
textures := make([]uint32, n)
C.glGenTextures(C.GLsizei(n), (*C.GLuint)(unsafe.Pointer(&textures[0])))
return textures
}
func (DefaultContext) GetError() uint32 {
func (defaultContext) GetError() uint32 {
return uint32(C.glGetError())
}
func (DefaultContext) GetIntegerv(dst []int32, pname uint32) {
func (defaultContext) GetIntegerv(dst []int32, pname uint32) {
C.glGetIntegerv(C.GLenum(pname), (*C.GLint)(unsafe.Pointer(&dst[0])))
}
func (d DefaultContext) GetProgramInfoLog(program uint32) string {
func (d defaultContext) GetProgramInfoLog(program uint32) string {
buflens := make([]int32, 1)
d.GetProgramiv(buflens, program, INFO_LOG_LENGTH)
buflen := buflens[0]
@ -222,11 +226,11 @@ func (d DefaultContext) GetProgramInfoLog(program uint32) string {
return string(buf[:length])
}
func (DefaultContext) GetProgramiv(dst []int32, program uint32, pname uint32) {
func (defaultContext) GetProgramiv(dst []int32, program uint32, pname uint32) {
C.glGetProgramiv(C.GLuint(program), C.GLenum(pname), (*C.GLint)(unsafe.Pointer(&dst[0])))
}
func (d DefaultContext) GetShaderInfoLog(shader uint32) string {
func (d defaultContext) GetShaderInfoLog(shader uint32) string {
buflens := make([]int32, 1)
d.GetShaderiv(buflens, shader, INFO_LOG_LENGTH)
buflen := buflens[0]
@ -239,67 +243,67 @@ func (d DefaultContext) GetShaderInfoLog(shader uint32) string {
return string(buf[:length])
}
func (DefaultContext) GetShaderiv(dst []int32, shader uint32, pname uint32) {
func (defaultContext) GetShaderiv(dst []int32, shader uint32, pname uint32) {
C.glGetShaderiv(C.GLuint(shader), C.GLenum(pname), (*C.GLint)(unsafe.Pointer(&dst[0])))
}
func (DefaultContext) GetUniformLocation(program uint32, name string) int32 {
func (defaultContext) GetUniformLocation(program uint32, name string) int32 {
s := C.CString(name)
defer C.free(unsafe.Pointer(s))
return int32(C.glGetUniformLocation(C.GLuint(program), (*C.GLchar)(unsafe.Pointer(s))))
}
func (DefaultContext) IsFramebuffer(framebuffer uint32) bool {
func (defaultContext) IsFramebuffer(framebuffer uint32) bool {
return C.glIsFramebuffer(C.GLuint(framebuffer)) != FALSE
}
func (DefaultContext) IsProgram(program uint32) bool {
func (defaultContext) IsProgram(program uint32) bool {
return C.glIsProgram(C.GLuint(program)) != FALSE
}
func (DefaultContext) IsRenderbuffer(renderbuffer uint32) bool {
func (defaultContext) IsRenderbuffer(renderbuffer uint32) bool {
return C.glIsRenderbuffer(C.GLuint(renderbuffer)) != FALSE
}
func (DefaultContext) IsTexture(texture uint32) bool {
func (defaultContext) IsTexture(texture uint32) bool {
return C.glIsTexture(C.GLuint(texture)) != FALSE
}
func (DefaultContext) LinkProgram(program uint32) {
func (defaultContext) LinkProgram(program uint32) {
C.glLinkProgram(C.GLuint(program))
}
func (DefaultContext) PixelStorei(pname uint32, param int32) {
func (defaultContext) PixelStorei(pname uint32, param int32) {
C.glPixelStorei(C.GLenum(pname), C.GLint(param))
}
func (DefaultContext) ReadPixels(dst []byte, x int32, y int32, width int32, height int32, format uint32, xtype uint32) {
func (defaultContext) ReadPixels(dst []byte, x int32, y int32, width int32, height int32, format uint32, xtype uint32) {
C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(xtype), unsafe.Pointer(&dst[0]))
}
func (DefaultContext) RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32) {
func (defaultContext) RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32) {
C.glRenderbufferStorage(C.GLenum(target), C.GLenum(internalFormat), C.GLsizei(width), C.GLsizei(height))
}
func (DefaultContext) Scissor(x, y, width, height int32) {
func (defaultContext) Scissor(x, y, width, height int32) {
C.glScissor(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
}
func (DefaultContext) ShaderSource(shader uint32, xstring string) {
func (defaultContext) ShaderSource(shader uint32, xstring string) {
s, free := cStringPtr(xstring)
defer free()
C.glShaderSource(C.GLuint(shader), 1, (**C.GLchar)(s), nil)
}
func (DefaultContext) StencilFunc(func_ uint32, ref int32, mask uint32) {
func (defaultContext) StencilFunc(func_ uint32, ref int32, mask uint32) {
C.glStencilFunc(C.GLenum(func_), C.GLint(ref), C.GLuint(mask))
}
func (DefaultContext) StencilOp(sfail, dpfail, dppass uint32) {
func (defaultContext) StencilOp(sfail, dpfail, dppass uint32) {
C.glStencilOp(C.GLenum(sfail), C.GLenum(dpfail), C.GLenum(dppass))
}
func (DefaultContext) TexImage2D(target uint32, level int32, internalformat int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
func (defaultContext) TexImage2D(target uint32, level int32, internalformat int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
var p *byte
if pixels != nil {
p = &pixels[0]
@ -307,58 +311,58 @@ func (DefaultContext) TexImage2D(target uint32, level int32, internalformat int3
C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), C.GLsizei(width), C.GLsizei(height), 0 /* border */, C.GLenum(format), C.GLenum(xtype), unsafe.Pointer(p))
}
func (DefaultContext) TexParameteri(target uint32, pname uint32, param int32) {
func (defaultContext) TexParameteri(target uint32, pname uint32, param int32) {
C.glTexParameteri(C.GLenum(target), C.GLenum(pname), C.GLint(param))
}
func (DefaultContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
func (defaultContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
C.glTexSubImage2D(C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(xtype), unsafe.Pointer(&pixels[0]))
}
func (DefaultContext) Uniform1fv(location int32, value []float32) {
func (defaultContext) Uniform1fv(location int32, value []float32) {
C.glUniform1fv(C.GLint(location), C.GLsizei(len(value)), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) Uniform1i(location int32, v0 int32) {
func (defaultContext) Uniform1i(location int32, v0 int32) {
C.glUniform1i(C.GLint(location), C.GLint(v0))
}
func (DefaultContext) Uniform1iv(location int32, value []int32) {
func (defaultContext) Uniform1iv(location int32, value []int32) {
C.glUniform1iv(C.GLint(location), C.GLsizei(len(value)), (*C.GLint)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) Uniform2fv(location int32, value []float32) {
func (defaultContext) Uniform2fv(location int32, value []float32) {
C.glUniform2fv(C.GLint(location), C.GLsizei(len(value)/2), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) Uniform3fv(location int32, value []float32) {
func (defaultContext) Uniform3fv(location int32, value []float32) {
C.glUniform3fv(C.GLint(location), C.GLsizei(len(value)/3), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) Uniform4fv(location int32, value []float32) {
func (defaultContext) Uniform4fv(location int32, value []float32) {
C.glUniform4fv(C.GLint(location), C.GLsizei(len(value)/4), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) UniformMatrix2fv(location int32, transpose bool, value []float32) {
func (defaultContext) UniformMatrix2fv(location int32, transpose bool, value []float32) {
C.glUniformMatrix2fv(C.GLint(location), C.GLsizei(len(value)/4), glBool(transpose), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) UniformMatrix3fv(location int32, transpose bool, value []float32) {
func (defaultContext) UniformMatrix3fv(location int32, transpose bool, value []float32) {
C.glUniformMatrix3fv(C.GLint(location), C.GLsizei(len(value)/9), glBool(transpose), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) UniformMatrix4fv(location int32, transpose bool, value []float32) {
func (defaultContext) UniformMatrix4fv(location int32, transpose bool, value []float32) {
C.glUniformMatrix4fv(C.GLint(location), C.GLsizei(len(value)/16), glBool(transpose), (*C.GLfloat)(unsafe.Pointer(&value[0])))
}
func (DefaultContext) UseProgram(program uint32) {
func (defaultContext) UseProgram(program uint32) {
C.glUseProgram(C.GLuint(program))
}
func (DefaultContext) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) {
func (defaultContext) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) {
C.glVertexAttribPointer(C.GLuint(index), C.GLint(size), C.GLenum(xtype), glBool(normalized), C.GLsizei(stride), unsafe.Pointer(uintptr(offset)))
}
func (DefaultContext) Viewport(x int32, y int32, width int32, height int32) {
func (defaultContext) Viewport(x int32, y int32, width int32, height int32) {
C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
}

View File

@ -20,7 +20,7 @@ import (
"golang.org/x/mobile/gl"
)
type GomobileContext struct {
type gomobileContext struct {
ctx gl.Context
}
@ -31,47 +31,47 @@ func gmProgram(program uint32) gl.Program {
}
}
func NewGomobileContext(ctx gl.Context) *GomobileContext {
return &GomobileContext{ctx}
func NewGomobileContext(ctx gl.Context) Context {
return &gomobileContext{ctx}
}
func (g *GomobileContext) ActiveTexture(texture uint32) {
func (g *gomobileContext) ActiveTexture(texture uint32) {
g.ctx.ActiveTexture(gl.Enum(texture))
}
func (g *GomobileContext) AttachShader(program uint32, shader uint32) {
func (g *gomobileContext) AttachShader(program uint32, shader uint32) {
g.ctx.AttachShader(gmProgram(program), gl.Shader{Value: shader})
}
func (g *GomobileContext) BindAttribLocation(program uint32, index uint32, name string) {
func (g *gomobileContext) BindAttribLocation(program uint32, index uint32, name string) {
g.ctx.BindAttribLocation(gmProgram(program), gl.Attrib{Value: uint(index)}, name)
}
func (g *GomobileContext) BindBuffer(target uint32, buffer uint32) {
func (g *gomobileContext) BindBuffer(target uint32, buffer uint32) {
g.ctx.BindBuffer(gl.Enum(target), gl.Buffer{Value: buffer})
}
func (g *GomobileContext) BindFramebuffer(target uint32, framebuffer uint32) {
func (g *gomobileContext) BindFramebuffer(target uint32, framebuffer uint32) {
g.ctx.BindFramebuffer(gl.Enum(target), gl.Framebuffer{Value: framebuffer})
}
func (g *GomobileContext) BindRenderbuffer(target uint32, renderbuffer uint32) {
func (g *gomobileContext) BindRenderbuffer(target uint32, renderbuffer uint32) {
g.ctx.BindRenderbuffer(gl.Enum(target), gl.Renderbuffer{Value: renderbuffer})
}
func (g *GomobileContext) BindTexture(target uint32, texture uint32) {
func (g *gomobileContext) BindTexture(target uint32, texture uint32) {
g.ctx.BindTexture(gl.Enum(target), gl.Texture{Value: texture})
}
func (g *GomobileContext) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
func (g *gomobileContext) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
g.ctx.BlendEquationSeparate(gl.Enum(modeRGB), gl.Enum(modeAlpha))
}
func (g *GomobileContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
func (g *gomobileContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
g.ctx.BlendFuncSeparate(gl.Enum(srcRGB), gl.Enum(dstRGB), gl.Enum(srcAlpha), gl.Enum(dstAlpha))
}
func (g *GomobileContext) BufferData(target uint32, size int, data []byte, usage uint32) {
func (g *gomobileContext) BufferData(target uint32, size int, data []byte, usage uint32) {
if data == nil {
g.ctx.BufferInit(gl.Enum(target), size, gl.Enum(usage))
} else {
@ -82,99 +82,99 @@ func (g *GomobileContext) BufferData(target uint32, size int, data []byte, usage
}
}
func (g *GomobileContext) BufferSubData(target uint32, offset int, data []byte) {
func (g *gomobileContext) BufferSubData(target uint32, offset int, data []byte) {
g.ctx.BufferSubData(gl.Enum(target), offset, data)
}
func (g *GomobileContext) CheckFramebufferStatus(target uint32) uint32 {
func (g *gomobileContext) CheckFramebufferStatus(target uint32) uint32 {
return uint32(g.ctx.CheckFramebufferStatus(gl.Enum(target)))
}
func (g *GomobileContext) Clear(mask uint32) {
func (g *gomobileContext) Clear(mask uint32) {
g.ctx.Clear(gl.Enum(mask))
}
func (g *GomobileContext) ColorMask(red, green, blue, alpha bool) {
func (g *gomobileContext) ColorMask(red, green, blue, alpha bool) {
g.ctx.ColorMask(red, green, blue, alpha)
}
func (g *GomobileContext) CompileShader(shader uint32) {
func (g *gomobileContext) CompileShader(shader uint32) {
g.ctx.CompileShader(gl.Shader{Value: shader})
}
func (g *GomobileContext) CreateProgram() uint32 {
func (g *gomobileContext) CreateProgram() uint32 {
return g.ctx.CreateProgram().Value
}
func (g *GomobileContext) CreateShader(xtype uint32) uint32 {
func (g *gomobileContext) CreateShader(xtype uint32) uint32 {
return g.ctx.CreateShader(gl.Enum(xtype)).Value
}
func (g *GomobileContext) DeleteBuffers(buffers []uint32) {
func (g *gomobileContext) DeleteBuffers(buffers []uint32) {
for _, b := range buffers {
g.ctx.DeleteBuffer(gl.Buffer{Value: b})
}
}
func (g *GomobileContext) DeleteFramebuffers(framebuffers []uint32) {
func (g *gomobileContext) DeleteFramebuffers(framebuffers []uint32) {
for _, b := range framebuffers {
g.ctx.DeleteFramebuffer(gl.Framebuffer{Value: b})
}
}
func (g *GomobileContext) DeleteProgram(program uint32) {
func (g *gomobileContext) DeleteProgram(program uint32) {
g.ctx.DeleteProgram(gmProgram(program))
}
func (g *GomobileContext) DeleteRenderbuffers(renderbuffers []uint32) {
func (g *gomobileContext) DeleteRenderbuffers(renderbuffers []uint32) {
for _, r := range renderbuffers {
g.ctx.DeleteRenderbuffer(gl.Renderbuffer{Value: r})
}
}
func (g *GomobileContext) DeleteShader(shader uint32) {
func (g *gomobileContext) DeleteShader(shader uint32) {
g.ctx.DeleteShader(gl.Shader{Value: shader})
}
func (g *GomobileContext) DeleteTextures(textures []uint32) {
func (g *gomobileContext) DeleteTextures(textures []uint32) {
for _, t := range textures {
g.ctx.DeleteTexture(gl.Texture{Value: t})
}
}
func (g *GomobileContext) Disable(cap uint32) {
func (g *gomobileContext) Disable(cap uint32) {
g.ctx.Disable(gl.Enum(cap))
}
func (g *GomobileContext) DisableVertexAttribArray(index uint32) {
func (g *gomobileContext) DisableVertexAttribArray(index uint32) {
g.ctx.DisableVertexAttribArray(gl.Attrib{Value: uint(index)})
}
func (g *GomobileContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
func (g *gomobileContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
g.ctx.DrawElements(gl.Enum(mode), int(count), gl.Enum(xtype), offset)
}
func (g *GomobileContext) Enable(cap uint32) {
func (g *gomobileContext) Enable(cap uint32) {
g.ctx.Enable(gl.Enum(cap))
}
func (g *GomobileContext) EnableVertexAttribArray(index uint32) {
func (g *gomobileContext) EnableVertexAttribArray(index uint32) {
g.ctx.EnableVertexAttribArray(gl.Attrib{Value: uint(index)})
}
func (g *GomobileContext) Flush() {
func (g *gomobileContext) Flush() {
g.ctx.Flush()
}
func (g *GomobileContext) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
func (g *gomobileContext) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
g.ctx.FramebufferRenderbuffer(gl.Enum(target), gl.Enum(attachment), gl.Enum(renderbuffertarget), gl.Renderbuffer{Value: renderbuffer})
}
func (g *GomobileContext) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) {
func (g *gomobileContext) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) {
g.ctx.FramebufferTexture2D(gl.Enum(target), gl.Enum(attachment), gl.Enum(textarget), gl.Texture{Value: texture}, int(level))
}
func (g *GomobileContext) GenBuffers(n int32) []uint32 {
func (g *gomobileContext) GenBuffers(n int32) []uint32 {
buffers := make([]uint32, n)
for i := range buffers {
buffers[i] = g.ctx.CreateBuffer().Value
@ -182,7 +182,7 @@ func (g *GomobileContext) GenBuffers(n int32) []uint32 {
return buffers
}
func (g *GomobileContext) GenFramebuffers(n int32) []uint32 {
func (g *gomobileContext) GenFramebuffers(n int32) []uint32 {
framebuffers := make([]uint32, n)
for i := range framebuffers {
framebuffers[i] = g.ctx.CreateFramebuffer().Value
@ -190,7 +190,7 @@ func (g *GomobileContext) GenFramebuffers(n int32) []uint32 {
return framebuffers
}
func (g *GomobileContext) GenRenderbuffers(n int32) []uint32 {
func (g *gomobileContext) GenRenderbuffers(n int32) []uint32 {
renderbuffers := make([]uint32, n)
for i := range renderbuffers {
renderbuffers[i] = g.ctx.CreateRenderbuffer().Value
@ -198,7 +198,7 @@ func (g *GomobileContext) GenRenderbuffers(n int32) []uint32 {
return renderbuffers
}
func (g *GomobileContext) GenTextures(n int32) []uint32 {
func (g *gomobileContext) GenTextures(n int32) []uint32 {
textures := make([]uint32, n)
for i := range textures {
textures[i] = g.ctx.CreateTexture().Value
@ -206,147 +206,147 @@ func (g *GomobileContext) GenTextures(n int32) []uint32 {
return textures
}
func (g *GomobileContext) GetError() uint32 {
func (g *gomobileContext) GetError() uint32 {
return uint32(g.ctx.GetError())
}
func (g *GomobileContext) GetIntegerv(dst []int32, pname uint32) {
func (g *gomobileContext) GetIntegerv(dst []int32, pname uint32) {
g.ctx.GetIntegerv(dst, gl.Enum(pname))
}
func (g *GomobileContext) GetProgramInfoLog(program uint32) string {
func (g *gomobileContext) GetProgramInfoLog(program uint32) string {
return g.ctx.GetProgramInfoLog(gmProgram(program))
}
func (g *GomobileContext) GetProgramiv(dst []int32, program uint32, pname uint32) {
func (g *gomobileContext) GetProgramiv(dst []int32, program uint32, pname uint32) {
dst[0] = int32(g.ctx.GetProgrami(gmProgram(program), gl.Enum(pname)))
}
func (g *GomobileContext) GetShaderInfoLog(shader uint32) string {
func (g *gomobileContext) GetShaderInfoLog(shader uint32) string {
return g.ctx.GetShaderInfoLog(gl.Shader{Value: shader})
}
func (g *GomobileContext) GetShaderiv(dst []int32, shader uint32, pname uint32) {
func (g *gomobileContext) GetShaderiv(dst []int32, shader uint32, pname uint32) {
dst[0] = int32(g.ctx.GetShaderi(gl.Shader{Value: shader}, gl.Enum(pname)))
}
func (g *GomobileContext) GetUniformLocation(program uint32, name string) int32 {
func (g *gomobileContext) GetUniformLocation(program uint32, name string) int32 {
return g.ctx.GetUniformLocation(gmProgram(program), name).Value
}
func (g *GomobileContext) IsFramebuffer(framebuffer uint32) bool {
func (g *gomobileContext) IsFramebuffer(framebuffer uint32) bool {
return g.ctx.IsFramebuffer(gl.Framebuffer{Value: framebuffer})
}
func (g *GomobileContext) IsProgram(program uint32) bool {
func (g *gomobileContext) IsProgram(program uint32) bool {
return g.ctx.IsProgram(gmProgram(program))
}
func (g *GomobileContext) IsRenderbuffer(renderbuffer uint32) bool {
func (g *gomobileContext) IsRenderbuffer(renderbuffer uint32) bool {
return g.ctx.IsRenderbuffer(gl.Renderbuffer{Value: renderbuffer})
}
func (g *GomobileContext) IsTexture(texture uint32) bool {
func (g *gomobileContext) IsTexture(texture uint32) bool {
return g.ctx.IsTexture(gl.Texture{Value: texture})
}
func (g *GomobileContext) LinkProgram(program uint32) {
func (g *gomobileContext) LinkProgram(program uint32) {
g.ctx.LinkProgram(gmProgram(program))
}
func (g *GomobileContext) PixelStorei(pname uint32, param int32) {
func (g *gomobileContext) PixelStorei(pname uint32, param int32) {
g.ctx.PixelStorei(gl.Enum(pname), param)
}
func (g *GomobileContext) ReadPixels(dst []byte, x int32, y int32, width int32, height int32, format uint32, xtype uint32) {
func (g *gomobileContext) ReadPixels(dst []byte, x int32, y int32, width int32, height int32, format uint32, xtype uint32) {
g.ctx.ReadPixels(dst, int(x), int(y), int(width), int(height), gl.Enum(format), gl.Enum(xtype))
}
func (g *GomobileContext) RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32) {
func (g *gomobileContext) RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32) {
g.ctx.RenderbufferStorage(gl.Enum(target), gl.Enum(internalFormat), int(width), int(height))
}
func (g *GomobileContext) Scissor(x, y, width, height int32) {
func (g *gomobileContext) Scissor(x, y, width, height int32) {
g.ctx.Scissor(x, y, width, height)
}
func (g *GomobileContext) ShaderSource(shader uint32, xstring string) {
func (g *gomobileContext) ShaderSource(shader uint32, xstring string) {
g.ctx.ShaderSource(gl.Shader{Value: shader}, xstring)
}
func (g *GomobileContext) StencilFunc(func_ uint32, ref int32, mask uint32) {
func (g *gomobileContext) StencilFunc(func_ uint32, ref int32, mask uint32) {
g.ctx.StencilFunc(gl.Enum(func_), int(ref), mask)
}
func (g *GomobileContext) StencilOp(sfail, dpfail, dppass uint32) {
func (g *gomobileContext) StencilOp(sfail, dpfail, dppass uint32) {
g.ctx.StencilOp(gl.Enum(sfail), gl.Enum(dpfail), gl.Enum(dppass))
}
func (g *GomobileContext) TexImage2D(target uint32, level int32, internalformat int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
func (g *gomobileContext) TexImage2D(target uint32, level int32, internalformat int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
g.ctx.TexImage2D(gl.Enum(target), int(level), int(internalformat), int(width), int(height), gl.Enum(format), gl.Enum(xtype), pixels)
}
func (g *GomobileContext) TexParameteri(target uint32, pname uint32, param int32) {
func (g *gomobileContext) TexParameteri(target uint32, pname uint32, param int32) {
g.ctx.TexParameteri(gl.Enum(target), gl.Enum(pname), int(param))
}
func (g *GomobileContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
func (g *gomobileContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
g.ctx.TexSubImage2D(gl.Enum(target), int(level), int(xoffset), int(yoffset), int(width), int(height), gl.Enum(format), gl.Enum(xtype), pixels)
}
func (g *GomobileContext) Uniform1fv(location int32, value []float32) {
func (g *gomobileContext) Uniform1fv(location int32, value []float32) {
g.ctx.Uniform1fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) Uniform1i(location int32, v0 int32) {
func (g *gomobileContext) Uniform1i(location int32, v0 int32) {
g.ctx.Uniform1i(gl.Uniform{Value: location}, int(v0))
}
func (g *GomobileContext) Uniform1iv(location int32, value []int32) {
func (g *gomobileContext) Uniform1iv(location int32, value []int32) {
g.ctx.Uniform1iv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) Uniform2fv(location int32, value []float32) {
func (g *gomobileContext) Uniform2fv(location int32, value []float32) {
g.ctx.Uniform2fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) Uniform3fv(location int32, value []float32) {
func (g *gomobileContext) Uniform3fv(location int32, value []float32) {
g.ctx.Uniform3fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) Uniform4fv(location int32, value []float32) {
func (g *gomobileContext) Uniform4fv(location int32, value []float32) {
g.ctx.Uniform4fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) UniformMatrix2fv(location int32, transpose bool, value []float32) {
func (g *gomobileContext) UniformMatrix2fv(location int32, transpose bool, value []float32) {
if transpose {
panic("gl: UniformMatrix2fv with transpose is not implemented")
}
g.ctx.UniformMatrix2fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) UniformMatrix3fv(location int32, transpose bool, value []float32) {
func (g *gomobileContext) UniformMatrix3fv(location int32, transpose bool, value []float32) {
if transpose {
panic("gl: UniformMatrix3fv with transpose is not implemented")
}
g.ctx.UniformMatrix3fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) UniformMatrix4fv(location int32, transpose bool, value []float32) {
func (g *gomobileContext) UniformMatrix4fv(location int32, transpose bool, value []float32) {
if transpose {
panic("gl: UniformMatrix4fv with transpose is not implemented")
}
g.ctx.UniformMatrix4fv(gl.Uniform{Value: location}, value)
}
func (g *GomobileContext) UseProgram(program uint32) {
func (g *gomobileContext) UseProgram(program uint32) {
g.ctx.UseProgram(gmProgram(program))
}
func (g *GomobileContext) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) {
func (g *gomobileContext) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) {
g.ctx.VertexAttribPointer(gl.Attrib{Value: uint(index)}, int(size), gl.Enum(xtype), normalized, int(stride), int(offset))
}
func (g *GomobileContext) Viewport(x int32, y int32, width int32, height int32) {
func (g *gomobileContext) Viewport(x int32, y int32, width int32, height int32) {
g.ctx.Viewport(int(x), int(y), int(width), int(height))
}

View File

@ -25,6 +25,6 @@ import (
// The returned graphics value is nil iff the error is not nil.
func NewGraphics() (graphicsdriver.Graphics, error) {
g := &Graphics{}
g.context.ctx = gl.DefaultContext{}
g.context.ctx = gl.NewDefaultContext()
return g, nil
}

View File

@ -30,7 +30,7 @@ func NewGraphics(context mgl.Context) (graphicsdriver.Graphics, error) {
if context != nil {
g.context.ctx = gl.NewGomobileContext(context.(mgl.Context))
} else {
g.context.ctx = gl.DefaultContext{}
g.context.ctx = gl.NewDefaultContext()
}
return g, nil
}