internal/graphicsdriver/opengl/gl: make Context closer to gomobile's Context

This commit is contained in:
Hajime Hoshi 2022-11-17 00:55:16 +09:00
parent 49fc1cfdc0
commit 9df4770d20
5 changed files with 135 additions and 191 deletions

View File

@ -132,7 +132,7 @@ func (c *context) scissor(x, y, width, height int) {
} }
func (c *context) newTexture(width, height int) (textureNative, error) { func (c *context) newTexture(width, height int) (textureNative, error) {
t := c.ctx.GenTextures(1)[0] t := c.ctx.CreateTexture()
if t <= 0 { if t <= 0 {
return 0, errors.New("opengl: creating texture failed") return 0, errors.New("opengl: creating texture failed")
} }
@ -185,7 +185,7 @@ func (c *context) deleteTexture(t textureNative) {
if c.lastTexture == t { if c.lastTexture == t {
c.lastTexture = invalidTexture c.lastTexture = invalidTexture
} }
c.ctx.DeleteTextures([]uint32{uint32(t)}) c.ctx.DeleteTexture(uint32(t))
} }
func (c *context) isTexture(t textureNative) bool { func (c *context) isTexture(t textureNative) bool {
@ -193,7 +193,7 @@ func (c *context) isTexture(t textureNative) bool {
} }
func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error) { func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error) {
r := c.ctx.GenRenderbuffers(1)[0] r := c.ctx.CreateRenderbuffer()
if r <= 0 { if r <= 0 {
return 0, errors.New("opengl: creating renderbuffer failed") return 0, errors.New("opengl: creating renderbuffer failed")
} }
@ -219,11 +219,11 @@ func (c *context) deleteRenderbuffer(r renderbufferNative) {
if c.lastRenderbuffer.equal(r) { if c.lastRenderbuffer.equal(r) {
c.lastRenderbuffer = 0 c.lastRenderbuffer = 0
} }
c.ctx.DeleteRenderbuffers([]uint32{uint32(r)}) c.ctx.DeleteRenderbuffer(uint32(r))
} }
func (c *context) newFramebuffer(texture textureNative) (framebufferNative, error) { func (c *context) newFramebuffer(texture textureNative) (framebufferNative, error) {
f := c.ctx.GenFramebuffers(1)[0] f := c.ctx.CreateFramebuffer()
if f <= 0 { if f <= 0 {
return 0, fmt.Errorf("opengl: creating framebuffer failed: the returned value is not positive but %d", f) return 0, fmt.Errorf("opengl: creating framebuffer failed: the returned value is not positive but %d", f)
} }
@ -269,7 +269,7 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
c.lastViewportWidth = 0 c.lastViewportWidth = 0
c.lastViewportHeight = 0 c.lastViewportHeight = 0
} }
c.ctx.DeleteFramebuffers([]uint32{uint32(f)}) c.ctx.DeleteFramebuffer(uint32(f))
} }
func (c *context) newVertexShader(source string) (shader, error) { func (c *context) newVertexShader(source string) (shader, error) {
@ -371,11 +371,11 @@ func (c *context) uniforms(p program, location string, v []uint32, typ shaderir.
case shaderir.Vec4: case shaderir.Vec4:
c.ctx.Uniform4fv(int32(l), uint32sToFloat32s(v)) c.ctx.Uniform4fv(int32(l), uint32sToFloat32s(v))
case shaderir.Mat2: case shaderir.Mat2:
c.ctx.UniformMatrix2fv(int32(l), false, uint32sToFloat32s(v)) c.ctx.UniformMatrix2fv(int32(l), uint32sToFloat32s(v))
case shaderir.Mat3: case shaderir.Mat3:
c.ctx.UniformMatrix3fv(int32(l), false, uint32sToFloat32s(v)) c.ctx.UniformMatrix3fv(int32(l), uint32sToFloat32s(v))
case shaderir.Mat4: case shaderir.Mat4:
c.ctx.UniformMatrix4fv(int32(l), false, uint32sToFloat32s(v)) c.ctx.UniformMatrix4fv(int32(l), uint32sToFloat32s(v))
default: default:
panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String())) panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String()))
} }
@ -395,16 +395,16 @@ func (c *context) disableVertexAttribArray(index int) {
} }
func (c *context) newArrayBuffer(size int) buffer { func (c *context) newArrayBuffer(size int) buffer {
b := c.ctx.GenBuffers(1)[0] b := c.ctx.CreateBuffer()
c.ctx.BindBuffer(gl.ARRAY_BUFFER, b) c.ctx.BindBuffer(gl.ARRAY_BUFFER, b)
c.ctx.BufferData(gl.ARRAY_BUFFER, size, nil, gl.DYNAMIC_DRAW) c.ctx.BufferInit(gl.ARRAY_BUFFER, size, gl.DYNAMIC_DRAW)
return buffer(b) return buffer(b)
} }
func (c *context) newElementArrayBuffer(size int) buffer { func (c *context) newElementArrayBuffer(size int) buffer {
b := c.ctx.GenBuffers(1)[0] b := c.ctx.CreateBuffer()
c.ctx.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, b) c.ctx.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, b)
c.ctx.BufferData(gl.ELEMENT_ARRAY_BUFFER, size, nil, gl.DYNAMIC_DRAW) c.ctx.BufferInit(gl.ELEMENT_ARRAY_BUFFER, size, gl.DYNAMIC_DRAW)
return buffer(b) return buffer(b)
} }
@ -427,7 +427,7 @@ func (c *context) elementArrayBufferSubData(data []uint16) {
} }
func (c *context) deleteBuffer(b buffer) { func (c *context) deleteBuffer(b buffer) {
c.ctx.DeleteBuffers([]uint32{uint32(b)}) c.ctx.DeleteBuffer(uint32(b))
} }
func (c *context) drawElements(len int, offsetInBytes int) { func (c *context) drawElements(len int, offsetInBytes int) {

View File

@ -454,13 +454,8 @@ func (c *defaultContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlph
C.glowBlendFuncSeparate(c.gpBlendFuncSeparate, (C.GLenum)(srcRGB), (C.GLenum)(dstRGB), (C.GLenum)(srcAlpha), (C.GLenum)(dstAlpha)) C.glowBlendFuncSeparate(c.gpBlendFuncSeparate, (C.GLenum)(srcRGB), (C.GLenum)(dstRGB), (C.GLenum)(srcAlpha), (C.GLenum)(dstAlpha))
} }
func (c *defaultContext) BufferData(target uint32, size int, data []byte, usage uint32) { func (c *defaultContext) BufferInit(target uint32, size int, usage uint32) {
var ptr *byte C.glowBufferData(c.gpBufferData, (C.GLenum)(target), (C.GLsizeiptr)(size), nil, (C.GLenum)(usage))
if len(data) > 0 {
ptr = &data[0]
}
C.glowBufferData(c.gpBufferData, (C.GLenum)(target), (C.GLsizeiptr)(size), unsafe.Pointer(ptr), (C.GLenum)(usage))
runtime.KeepAlive(data)
} }
func (c *defaultContext) BufferSubData(target uint32, offset int, data []byte) { func (c *defaultContext) BufferSubData(target uint32, offset int, data []byte) {
@ -485,42 +480,62 @@ func (c *defaultContext) CompileShader(shader uint32) {
C.glowCompileShader(c.gpCompileShader, (C.GLuint)(shader)) C.glowCompileShader(c.gpCompileShader, (C.GLuint)(shader))
} }
func (c *defaultContext) CreateBuffer() uint32 {
var buffer uint32
C.glowGenBuffers(c.gpGenBuffers, 1, (*C.GLuint)(unsafe.Pointer(&buffer)))
return buffer
}
func (c *defaultContext) CreateFramebuffer() uint32 {
var framebuffer uint32
C.glowGenFramebuffersEXT(c.gpGenFramebuffersEXT, 1, (*C.GLuint)(unsafe.Pointer(&framebuffer)))
return framebuffer
}
func (c *defaultContext) CreateProgram() uint32 { func (c *defaultContext) CreateProgram() uint32 {
ret := C.glowCreateProgram(c.gpCreateProgram) ret := C.glowCreateProgram(c.gpCreateProgram)
return uint32(ret) return uint32(ret)
} }
func (c *defaultContext) CreateRenderbuffer() uint32 {
var renderbuffer uint32
C.glowGenRenderbuffersEXT(c.gpGenRenderbuffersEXT, 1, (*C.GLuint)(unsafe.Pointer(&renderbuffer)))
return renderbuffer
}
func (c *defaultContext) CreateShader(xtype uint32) uint32 { func (c *defaultContext) CreateShader(xtype uint32) uint32 {
ret := C.glowCreateShader(c.gpCreateShader, (C.GLenum)(xtype)) ret := C.glowCreateShader(c.gpCreateShader, (C.GLenum)(xtype))
return uint32(ret) return uint32(ret)
} }
func (c *defaultContext) DeleteBuffers(buffers []uint32) { func (c *defaultContext) CreateTexture() uint32 {
C.glowDeleteBuffers(c.gpDeleteBuffers, (C.GLsizei)(len(buffers)), (*C.GLuint)(unsafe.Pointer(&buffers[0]))) var texture uint32
runtime.KeepAlive(buffers) C.glowGenTextures(c.gpGenTextures, 1, (*C.GLuint)(unsafe.Pointer(&texture)))
return texture
} }
func (c *defaultContext) DeleteFramebuffers(framebuffers []uint32) { func (c *defaultContext) DeleteBuffer(buffer uint32) {
C.glowDeleteFramebuffersEXT(c.gpDeleteFramebuffersEXT, (C.GLsizei)(len(framebuffers)), (*C.GLuint)(unsafe.Pointer(&framebuffers[0]))) C.glowDeleteBuffers(c.gpDeleteBuffers, 1, (*C.GLuint)(unsafe.Pointer(&buffer)))
runtime.KeepAlive(framebuffers) }
func (c *defaultContext) DeleteFramebuffer(framebuffer uint32) {
C.glowDeleteFramebuffersEXT(c.gpDeleteFramebuffersEXT, 1, (*C.GLuint)(unsafe.Pointer(&framebuffer)))
} }
func (c *defaultContext) DeleteProgram(program uint32) { func (c *defaultContext) DeleteProgram(program uint32) {
C.glowDeleteProgram(c.gpDeleteProgram, (C.GLuint)(program)) C.glowDeleteProgram(c.gpDeleteProgram, (C.GLuint)(program))
} }
func (c *defaultContext) DeleteRenderbuffers(renderbuffers []uint32) { func (c *defaultContext) DeleteRenderbuffer(renderbuffer uint32) {
C.glowDeleteRenderbuffersEXT(c.gpDeleteRenderbuffersEXT, (C.GLsizei)(len(renderbuffers)), (*C.GLuint)(unsafe.Pointer(&renderbuffers[0]))) C.glowDeleteRenderbuffersEXT(c.gpDeleteRenderbuffersEXT, 1, (*C.GLuint)(unsafe.Pointer(&renderbuffer)))
runtime.KeepAlive(renderbuffers)
} }
func (c *defaultContext) DeleteShader(shader uint32) { func (c *defaultContext) DeleteShader(shader uint32) {
C.glowDeleteShader(c.gpDeleteShader, (C.GLuint)(shader)) C.glowDeleteShader(c.gpDeleteShader, (C.GLuint)(shader))
} }
func (c *defaultContext) DeleteTextures(textures []uint32) { func (c *defaultContext) DeleteTexture(texture uint32) {
C.glowDeleteTextures(c.gpDeleteTextures, (C.GLsizei)(len(textures)), (*C.GLuint)(unsafe.Pointer(&textures[0]))) C.glowDeleteTextures(c.gpDeleteTextures, 1, (*C.GLuint)(unsafe.Pointer(&texture)))
runtime.KeepAlive(textures)
} }
func (c *defaultContext) Disable(cap uint32) { func (c *defaultContext) Disable(cap uint32) {
@ -555,30 +570,6 @@ func (c *defaultContext) FramebufferTexture2D(target uint32, attachment uint32,
C.glowFramebufferTexture2DEXT(c.gpFramebufferTexture2DEXT, (C.GLenum)(target), (C.GLenum)(attachment), (C.GLenum)(textarget), (C.GLuint)(texture), (C.GLint)(level)) C.glowFramebufferTexture2DEXT(c.gpFramebufferTexture2DEXT, (C.GLenum)(target), (C.GLenum)(attachment), (C.GLenum)(textarget), (C.GLuint)(texture), (C.GLint)(level))
} }
func (c *defaultContext) GenBuffers(n int32) []uint32 {
buffers := make([]uint32, n)
C.glowGenBuffers(c.gpGenBuffers, (C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(&buffers[0])))
return buffers
}
func (c *defaultContext) GenFramebuffers(n int32) []uint32 {
framebuffers := make([]uint32, n)
C.glowGenFramebuffersEXT(c.gpGenFramebuffersEXT, (C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(&framebuffers[0])))
return framebuffers
}
func (c *defaultContext) GenRenderbuffers(n int32) []uint32 {
renderbuffers := make([]uint32, n)
C.glowGenRenderbuffersEXT(c.gpGenRenderbuffersEXT, (C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(&renderbuffers[0])))
return renderbuffers
}
func (c *defaultContext) GenTextures(n int32) []uint32 {
textures := make([]uint32, n)
C.glowGenTextures(c.gpGenTextures, (C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(&textures[0])))
return textures
}
func (c *defaultContext) GetError() uint32 { func (c *defaultContext) GetError() uint32 {
ret := C.glowGetError(c.gpGetError) ret := C.glowGetError(c.gpGetError)
return uint32(ret) return uint32(ret)
@ -724,18 +715,18 @@ func (c *defaultContext) Uniform4fv(location int32, value []float32) {
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }
func (c *defaultContext) UniformMatrix2fv(location int32, transpose bool, value []float32) { func (c *defaultContext) UniformMatrix2fv(location int32, value []float32) {
C.glowUniformMatrix2fv(c.gpUniformMatrix2fv, (C.GLint)(location), (C.GLsizei)(len(value)/4), (C.GLboolean)(boolToInt(transpose)), (*C.GLfloat)(unsafe.Pointer(&value[0]))) C.glowUniformMatrix2fv(c.gpUniformMatrix2fv, (C.GLint)(location), (C.GLsizei)(len(value)/4), 0, (*C.GLfloat)(unsafe.Pointer(&value[0])))
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }
func (c *defaultContext) UniformMatrix3fv(location int32, transpose bool, value []float32) { func (c *defaultContext) UniformMatrix3fv(location int32, value []float32) {
C.glowUniformMatrix3fv(c.gpUniformMatrix3fv, (C.GLint)(location), (C.GLsizei)(len(value)/9), (C.GLboolean)(boolToInt(transpose)), (*C.GLfloat)(unsafe.Pointer(&value[0]))) C.glowUniformMatrix3fv(c.gpUniformMatrix3fv, (C.GLint)(location), (C.GLsizei)(len(value)/9), 0, (*C.GLfloat)(unsafe.Pointer(&value[0])))
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }
func (c *defaultContext) UniformMatrix4fv(location int32, transpose bool, value []float32) { func (c *defaultContext) UniformMatrix4fv(location int32, value []float32) {
C.glowUniformMatrix4fv(c.gpUniformMatrix4fv, (C.GLint)(location), (C.GLsizei)(len(value)/16), (C.GLboolean)(boolToInt(transpose)), (*C.GLfloat)(unsafe.Pointer(&value[0]))) C.glowUniformMatrix4fv(c.gpUniformMatrix4fv, (C.GLint)(location), (C.GLsizei)(len(value)/16), 0, (*C.GLfloat)(unsafe.Pointer(&value[0])))
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }

View File

@ -155,13 +155,8 @@ func (c *defaultContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlph
purego.SyscallN(c.gpBlendFuncSeparate, uintptr(srcRGB), uintptr(dstRGB), uintptr(srcAlpha), uintptr(dstAlpha)) purego.SyscallN(c.gpBlendFuncSeparate, uintptr(srcRGB), uintptr(dstRGB), uintptr(srcAlpha), uintptr(dstAlpha))
} }
func (c *defaultContext) BufferData(target uint32, size int, data []byte, usage uint32) { func (c *defaultContext) BufferInit(target uint32, size int, usage uint32) {
var ptr *byte purego.SyscallN(c.gpBufferData, uintptr(target), uintptr(size), 0, uintptr(usage))
if len(data) > 0 {
ptr = &data[0]
}
purego.SyscallN(c.gpBufferData, uintptr(target), uintptr(size), uintptr(unsafe.Pointer(ptr)), uintptr(usage))
runtime.KeepAlive(data)
} }
func (c *defaultContext) BufferSubData(target uint32, offset int, data []byte) { func (c *defaultContext) BufferSubData(target uint32, offset int, data []byte) {
@ -186,40 +181,62 @@ func (c *defaultContext) CompileShader(shader uint32) {
purego.SyscallN(c.gpCompileShader, uintptr(shader)) purego.SyscallN(c.gpCompileShader, uintptr(shader))
} }
func (c *defaultContext) CreateBuffer() uint32 {
var buffer uint32
purego.SyscallN(c.gpGenBuffers, 1, uintptr(unsafe.Pointer(&buffer)))
return buffer
}
func (c *defaultContext) CreateFramebuffer() uint32 {
var framebuffer uint32
purego.SyscallN(c.gpGenFramebuffersEXT, 1, uintptr(unsafe.Pointer(&framebuffer)))
return framebuffer
}
func (c *defaultContext) CreateProgram() uint32 { func (c *defaultContext) CreateProgram() uint32 {
ret, _, _ := purego.SyscallN(c.gpCreateProgram) ret, _, _ := purego.SyscallN(c.gpCreateProgram)
return uint32(ret) return uint32(ret)
} }
func (c *defaultContext) CreateRenderbuffer() uint32 {
var renderbuffer uint32
purego.SyscallN(c.gpGenRenderbuffersEXT, 1, uintptr(unsafe.Pointer(&renderbuffer)))
return renderbuffer
}
func (c *defaultContext) CreateShader(xtype uint32) uint32 { func (c *defaultContext) CreateShader(xtype uint32) uint32 {
ret, _, _ := purego.SyscallN(c.gpCreateShader, uintptr(xtype)) ret, _, _ := purego.SyscallN(c.gpCreateShader, uintptr(xtype))
return uint32(ret) return uint32(ret)
} }
func (c *defaultContext) DeleteBuffers(buffers []uint32) { func (c *defaultContext) CreateTexture() uint32 {
purego.SyscallN(c.gpDeleteBuffers, uintptr(len(buffers)), uintptr(unsafe.Pointer(&buffers[0]))) var texture uint32
runtime.KeepAlive(buffers) purego.SyscallN(c.gpGenTextures, 1, uintptr(unsafe.Pointer(&texture)))
return texture
} }
func (c *defaultContext) DeleteFramebuffers(framebuffers []uint32) { func (c *defaultContext) DeleteBuffer(buffer uint32) {
purego.SyscallN(c.gpDeleteFramebuffersEXT, uintptr(len(framebuffers)), uintptr(unsafe.Pointer(&framebuffers[0]))) purego.SyscallN(c.gpDeleteBuffers, 1, uintptr(unsafe.Pointer(&buffer)))
runtime.KeepAlive(framebuffers) }
func (c *defaultContext) DeleteFramebuffer(framebuffer uint32) {
purego.SyscallN(c.gpDeleteFramebuffersEXT, 1, uintptr(unsafe.Pointer(&framebuffer)))
} }
func (c *defaultContext) DeleteProgram(program uint32) { func (c *defaultContext) DeleteProgram(program uint32) {
purego.SyscallN(c.gpDeleteProgram, uintptr(program)) purego.SyscallN(c.gpDeleteProgram, uintptr(program))
} }
func (c *defaultContext) DeleteRenderbuffers(renderbuffers []uint32) { func (c *defaultContext) DeleteRenderbuffer(renderbuffer uint32) {
purego.SyscallN(c.gpDeleteRenderbuffersEXT, uintptr(len(renderbuffers)), uintptr(unsafe.Pointer(&renderbuffers[0]))) purego.SyscallN(c.gpDeleteRenderbuffersEXT, 1, uintptr(unsafe.Pointer(&renderbuffer)))
} }
func (c *defaultContext) DeleteShader(shader uint32) { func (c *defaultContext) DeleteShader(shader uint32) {
purego.SyscallN(c.gpDeleteShader, uintptr(shader)) purego.SyscallN(c.gpDeleteShader, uintptr(shader))
} }
func (c *defaultContext) DeleteTextures(textures []uint32) { func (c *defaultContext) DeleteTexture(texture uint32) {
purego.SyscallN(c.gpDeleteTextures, uintptr(len(textures)), uintptr(unsafe.Pointer(&textures[0]))) purego.SyscallN(c.gpDeleteTextures, 1, uintptr(unsafe.Pointer(&texture)))
} }
func (c *defaultContext) Disable(cap uint32) { func (c *defaultContext) Disable(cap uint32) {
@ -254,30 +271,6 @@ func (c *defaultContext) FramebufferTexture2D(target uint32, attachment uint32,
purego.SyscallN(c.gpFramebufferTexture2DEXT, uintptr(target), uintptr(attachment), uintptr(textarget), uintptr(texture), uintptr(level)) purego.SyscallN(c.gpFramebufferTexture2DEXT, uintptr(target), uintptr(attachment), uintptr(textarget), uintptr(texture), uintptr(level))
} }
func (c *defaultContext) GenBuffers(n int32) []uint32 {
buffers := make([]uint32, n)
purego.SyscallN(c.gpGenBuffers, uintptr(n), uintptr(unsafe.Pointer(&buffers[0])))
return buffers
}
func (c *defaultContext) GenFramebuffers(n int32) []uint32 {
framebuffers := make([]uint32, n)
purego.SyscallN(c.gpGenFramebuffersEXT, uintptr(n), uintptr(unsafe.Pointer(&framebuffers[0])))
return framebuffers
}
func (c *defaultContext) GenRenderbuffers(n int32) []uint32 {
renderbuffers := make([]uint32, n)
purego.SyscallN(c.gpGenRenderbuffersEXT, uintptr(n), uintptr(unsafe.Pointer(&renderbuffers[0])))
return renderbuffers
}
func (c *defaultContext) GenTextures(n int32) []uint32 {
textures := make([]uint32, n)
purego.SyscallN(c.gpGenTextures, uintptr(n), uintptr(unsafe.Pointer(&textures[0])))
return textures
}
func (c *defaultContext) GetError() uint32 { func (c *defaultContext) GetError() uint32 {
ret, _, _ := purego.SyscallN(c.gpGetError) ret, _, _ := purego.SyscallN(c.gpGetError)
return uint32(ret) return uint32(ret)
@ -423,18 +416,18 @@ func (c *defaultContext) Uniform4fv(location int32, value []float32) {
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }
func (c *defaultContext) UniformMatrix2fv(location int32, transpose bool, value []float32) { func (c *defaultContext) UniformMatrix2fv(location int32, value []float32) {
purego.SyscallN(c.gpUniformMatrix2fv, uintptr(location), uintptr(len(value)/4), uintptr(boolToInt(transpose)), uintptr(unsafe.Pointer(&value[0]))) purego.SyscallN(c.gpUniformMatrix2fv, uintptr(location), uintptr(len(value)/4), 0, uintptr(unsafe.Pointer(&value[0])))
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }
func (c *defaultContext) UniformMatrix3fv(location int32, transpose bool, value []float32) { func (c *defaultContext) UniformMatrix3fv(location int32, value []float32) {
purego.SyscallN(c.gpUniformMatrix3fv, uintptr(location), uintptr(len(value)/9), uintptr(boolToInt(transpose)), uintptr(unsafe.Pointer(&value[0]))) purego.SyscallN(c.gpUniformMatrix3fv, uintptr(location), uintptr(len(value)/9), 0, uintptr(unsafe.Pointer(&value[0])))
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }
func (c *defaultContext) UniformMatrix4fv(location int32, transpose bool, value []float32) { func (c *defaultContext) UniformMatrix4fv(location int32, value []float32) {
purego.SyscallN(c.gpUniformMatrix4fv, uintptr(location), uintptr(len(value)/16), uintptr(boolToInt(transpose)), uintptr(unsafe.Pointer(&value[0]))) purego.SyscallN(c.gpUniformMatrix4fv, uintptr(location), uintptr(len(value)/16), 0, uintptr(unsafe.Pointer(&value[0])))
runtime.KeepAlive(value) runtime.KeepAlive(value)
} }

View File

@ -79,15 +79,8 @@ func (g *gomobileContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlp
g.ctx.BlendFuncSeparate(gl.Enum(srcRGB), gl.Enum(dstRGB), gl.Enum(srcAlpha), gl.Enum(dstAlpha)) 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) BufferInit(target uint32, size int, usage uint32) {
if data == nil { g.ctx.BufferInit(gl.Enum(target), size, gl.Enum(usage))
g.ctx.BufferInit(gl.Enum(target), size, gl.Enum(usage))
} else {
if size != len(data) {
panic("gl: size and len(data) must be same at BufferData")
}
g.ctx.BufferData(gl.Enum(target), data, gl.Enum(usage))
}
} }
func (g *gomobileContext) BufferSubData(target uint32, offset int, data []byte) { func (g *gomobileContext) BufferSubData(target uint32, offset int, data []byte) {
@ -110,44 +103,52 @@ func (g *gomobileContext) CompileShader(shader uint32) {
g.ctx.CompileShader(gl.Shader{Value: shader}) g.ctx.CompileShader(gl.Shader{Value: shader})
} }
func (g *gomobileContext) CreateBuffer() uint32 {
return g.ctx.CreateBuffer().Value
}
func (g *gomobileContext) CreateFramebuffer() uint32 {
return g.ctx.CreateFramebuffer().Value
}
func (g *gomobileContext) CreateProgram() uint32 { func (g *gomobileContext) CreateProgram() uint32 {
return g.ctx.CreateProgram().Value return g.ctx.CreateProgram().Value
} }
func (g *gomobileContext) CreateRenderbuffer() uint32 {
return g.ctx.CreateRenderbuffer().Value
}
func (g *gomobileContext) CreateShader(xtype uint32) uint32 { func (g *gomobileContext) CreateShader(xtype uint32) uint32 {
return g.ctx.CreateShader(gl.Enum(xtype)).Value return g.ctx.CreateShader(gl.Enum(xtype)).Value
} }
func (g *gomobileContext) DeleteBuffers(buffers []uint32) { func (g *gomobileContext) CreateTexture() uint32 {
for _, b := range buffers { return g.ctx.CreateTexture().Value
g.ctx.DeleteBuffer(gl.Buffer{Value: b})
}
} }
func (g *gomobileContext) DeleteFramebuffers(framebuffers []uint32) { func (g *gomobileContext) DeleteBuffer(buffer uint32) {
for _, b := range framebuffers { g.ctx.DeleteBuffer(gl.Buffer{Value: buffer})
g.ctx.DeleteFramebuffer(gl.Framebuffer{Value: b}) }
}
func (g *gomobileContext) DeleteFramebuffer(framebuffer uint32) {
g.ctx.DeleteFramebuffer(gl.Framebuffer{Value: framebuffer})
} }
func (g *gomobileContext) DeleteProgram(program uint32) { func (g *gomobileContext) DeleteProgram(program uint32) {
g.ctx.DeleteProgram(gmProgram(program)) g.ctx.DeleteProgram(gmProgram(program))
} }
func (g *gomobileContext) DeleteRenderbuffers(renderbuffers []uint32) { func (g *gomobileContext) DeleteRenderbuffer(renderbuffer uint32) {
for _, r := range renderbuffers { g.ctx.DeleteRenderbuffer(gl.Renderbuffer{Value: renderbuffer})
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}) g.ctx.DeleteShader(gl.Shader{Value: shader})
} }
func (g *gomobileContext) DeleteTextures(textures []uint32) { func (g *gomobileContext) DeleteTexture(texture uint32) {
for _, t := range textures { g.ctx.DeleteTexture(gl.Texture{Value: texture})
g.ctx.DeleteTexture(gl.Texture{Value: t})
}
} }
func (g *gomobileContext) Disable(cap uint32) { func (g *gomobileContext) Disable(cap uint32) {
@ -182,38 +183,6 @@ func (g *gomobileContext) FramebufferTexture2D(target uint32, attachment uint32,
g.ctx.FramebufferTexture2D(gl.Enum(target), gl.Enum(attachment), gl.Enum(textarget), gl.Texture{Value: texture}, int(level)) 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 {
buffers := make([]uint32, n)
for i := range buffers {
buffers[i] = g.ctx.CreateBuffer().Value
}
return buffers
}
func (g *gomobileContext) GenFramebuffers(n int32) []uint32 {
framebuffers := make([]uint32, n)
for i := range framebuffers {
framebuffers[i] = g.ctx.CreateFramebuffer().Value
}
return framebuffers
}
func (g *gomobileContext) GenRenderbuffers(n int32) []uint32 {
renderbuffers := make([]uint32, n)
for i := range renderbuffers {
renderbuffers[i] = g.ctx.CreateRenderbuffer().Value
}
return renderbuffers
}
func (g *gomobileContext) GenTextures(n int32) []uint32 {
textures := make([]uint32, n)
for i := range textures {
textures[i] = g.ctx.CreateTexture().Value
}
return textures
}
func (g *gomobileContext) GetError() uint32 { func (g *gomobileContext) GetError() uint32 {
return uint32(g.ctx.GetError()) return uint32(g.ctx.GetError())
} }
@ -326,24 +295,15 @@ func (g *gomobileContext) Uniform4fv(location int32, value []float32) {
g.ctx.Uniform4fv(gl.Uniform{Value: location}, value) g.ctx.Uniform4fv(gl.Uniform{Value: location}, value)
} }
func (g *gomobileContext) UniformMatrix2fv(location int32, transpose bool, value []float32) { func (g *gomobileContext) UniformMatrix2fv(location int32, value []float32) {
if transpose {
panic("gl: UniformMatrix2fv with transpose is not implemented")
}
g.ctx.UniformMatrix2fv(gl.Uniform{Value: location}, value) g.ctx.UniformMatrix2fv(gl.Uniform{Value: location}, value)
} }
func (g *gomobileContext) UniformMatrix3fv(location int32, transpose bool, value []float32) { func (g *gomobileContext) UniformMatrix3fv(location int32, value []float32) {
if transpose {
panic("gl: UniformMatrix3fv with transpose is not implemented")
}
g.ctx.UniformMatrix3fv(gl.Uniform{Value: location}, value) g.ctx.UniformMatrix3fv(gl.Uniform{Value: location}, value)
} }
func (g *gomobileContext) UniformMatrix4fv(location int32, transpose bool, value []float32) { func (g *gomobileContext) UniformMatrix4fv(location int32, value []float32) {
if transpose {
panic("gl: UniformMatrix4fv with transpose is not implemented")
}
g.ctx.UniformMatrix4fv(gl.Uniform{Value: location}, value) g.ctx.UniformMatrix4fv(gl.Uniform{Value: location}, value)
} }

View File

@ -31,20 +31,24 @@ type Context interface {
BindTexture(target uint32, texture uint32) BindTexture(target uint32, texture uint32)
BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32)
BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32)
BufferData(target uint32, size int, data []byte, usage uint32) BufferInit(target uint32, size int, usage uint32)
BufferSubData(target uint32, offset int, data []byte) BufferSubData(target uint32, offset int, data []byte)
CheckFramebufferStatus(target uint32) uint32 CheckFramebufferStatus(target uint32) uint32
Clear(mask uint32) Clear(mask uint32)
ColorMask(red, green, blue, alpha bool) ColorMask(red, green, blue, alpha bool)
CompileShader(shader uint32) CompileShader(shader uint32)
CreateBuffer() uint32
CreateFramebuffer() uint32
CreateProgram() uint32 CreateProgram() uint32
CreateRenderbuffer() uint32
CreateShader(xtype uint32) uint32 CreateShader(xtype uint32) uint32
DeleteBuffers(buffers []uint32) CreateTexture() uint32
DeleteFramebuffers(framebuffers []uint32) DeleteBuffer(buffer uint32)
DeleteFramebuffer(framebuffer uint32)
DeleteProgram(program uint32) DeleteProgram(program uint32)
DeleteRenderbuffers(renderbuffer []uint32) DeleteRenderbuffer(renderbuffer uint32)
DeleteShader(shader uint32) DeleteShader(shader uint32)
DeleteTextures(textures []uint32) DeleteTexture(textures uint32)
Disable(cap uint32) Disable(cap uint32)
DisableVertexAttribArray(index uint32) DisableVertexAttribArray(index uint32)
DrawElements(mode uint32, count int32, xtype uint32, offset int) DrawElements(mode uint32, count int32, xtype uint32, offset int)
@ -53,10 +57,6 @@ type Context interface {
Flush() Flush()
FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32)
FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32)
GenBuffers(n int32) []uint32
GenFramebuffers(n int32) []uint32
GenRenderbuffers(n int32) []uint32
GenTextures(n int32) []uint32
GetError() uint32 GetError() uint32
GetInteger(pname uint32) int GetInteger(pname uint32) int
GetProgramInfoLog(program uint32) string GetProgramInfoLog(program uint32) string
@ -85,9 +85,9 @@ type Context interface {
Uniform2fv(location int32, value []float32) Uniform2fv(location int32, value []float32)
Uniform3fv(location int32, value []float32) Uniform3fv(location int32, value []float32)
Uniform4fv(location int32, value []float32) Uniform4fv(location int32, value []float32)
UniformMatrix2fv(location int32, transpose bool, value []float32) UniformMatrix2fv(location int32, value []float32)
UniformMatrix3fv(location int32, transpose bool, value []float32) UniformMatrix3fv(location int32, value []float32)
UniformMatrix4fv(location int32, transpose bool, value []float32) UniformMatrix4fv(location int32, value []float32)
UseProgram(program uint32) UseProgram(program uint32)
VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int)
Viewport(x int32, y int32, width int32, height int32) Viewport(x int32, y int32, width int32, height int32)