graphicsdriver/opengl: Unexport Context

This commit is contained in:
Hajime Hoshi 2018-11-11 01:14:26 +09:00
parent 241716d0e6
commit 7e363a6f3b
5 changed files with 119 additions and 120 deletions

View File

@ -55,8 +55,7 @@ func convertOperation(op graphics.Operation) operation {
}
}
// TODO: Unexport this
type Context struct {
type context struct {
locationCache *locationCache
screenFramebuffer framebufferNative // This might not be the default frame buffer '0' (e.g. iOS).
lastFramebuffer framebufferNative
@ -65,12 +64,12 @@ type Context struct {
lastViewportHeight int
lastCompositeMode graphics.CompositeMode
maxTextureSize int
context
contextImpl
}
var theContext Context
var theContext context
func (c *Context) bindTexture(t textureNative) {
func (c *context) bindTexture(t textureNative) {
if c.lastTexture == t {
return
}
@ -78,7 +77,7 @@ func (c *Context) bindTexture(t textureNative) {
c.lastTexture = t
}
func (c *Context) bindFramebuffer(f framebufferNative) {
func (c *context) bindFramebuffer(f framebufferNative) {
if c.lastFramebuffer == f {
return
}
@ -86,7 +85,7 @@ func (c *Context) bindFramebuffer(f framebufferNative) {
c.lastFramebuffer = f
}
func (c *Context) setViewport(f *framebuffer) {
func (c *context) setViewport(f *framebuffer) {
c.bindFramebuffer(f.native)
if c.lastViewportWidth != f.width || c.lastViewportHeight != f.height {
c.setViewportImpl(f.width, f.height)
@ -103,11 +102,11 @@ func (c *Context) setViewport(f *framebuffer) {
}
}
func (c *Context) getScreenFramebuffer() framebufferNative {
func (c *context) getScreenFramebuffer() framebufferNative {
return c.screenFramebuffer
}
func (c *Context) getMaxTextureSize() int {
func (c *context) getMaxTextureSize() int {
if c.maxTextureSize == 0 {
c.maxTextureSize = c.maxTextureSizeImpl()
}

View File

@ -74,11 +74,11 @@ func init() {
initializeArrayBuferLayout()
}
type context struct {
type contextImpl struct {
init bool
}
func (c *Context) reset() error {
func (c *context) reset() error {
if err := mainthread.Run(func() error {
if c.init {
return nil
@ -112,7 +112,7 @@ func (c *Context) reset() error {
return nil
}
func (c *Context) blendFunc(mode graphics.CompositeMode) {
func (c *context) blendFunc(mode graphics.CompositeMode) {
_ = mainthread.Run(func() error {
if c.lastCompositeMode == mode {
return nil
@ -125,7 +125,7 @@ func (c *Context) blendFunc(mode graphics.CompositeMode) {
})
}
func (c *Context) newTexture(width, height int) (textureNative, error) {
func (c *context) newTexture(width, height int) (textureNative, error) {
var texture textureNative
if err := mainthread.Run(func() error {
var t uint32
@ -152,14 +152,14 @@ func (c *Context) newTexture(width, height int) (textureNative, error) {
return texture, nil
}
func (c *Context) bindFramebufferImpl(f framebufferNative) {
func (c *context) bindFramebufferImpl(f framebufferNative) {
_ = mainthread.Run(func() error {
gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f))
return nil
})
}
func (c *Context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
var pixels []byte
_ = mainthread.Run(func() error {
gl.Flush()
@ -180,14 +180,14 @@ func (c *Context) framebufferPixels(f *framebuffer, width, height int) ([]byte,
return pixels, nil
}
func (c *Context) bindTextureImpl(t textureNative) {
func (c *context) bindTextureImpl(t textureNative) {
_ = mainthread.Run(func() error {
gl.BindTexture(gl.TEXTURE_2D, uint32(t))
return nil
})
}
func (c *Context) deleteTexture(t textureNative) {
func (c *context) deleteTexture(t textureNative) {
_ = mainthread.Run(func() error {
tt := uint32(t)
if !gl.IsTexture(tt) {
@ -201,7 +201,7 @@ func (c *Context) deleteTexture(t textureNative) {
})
}
func (c *Context) isTexture(t textureNative) bool {
func (c *context) isTexture(t textureNative) bool {
r := false
_ = mainthread.Run(func() error {
r = gl.IsTexture(uint32(t))
@ -210,7 +210,7 @@ func (c *Context) isTexture(t textureNative) bool {
return r
}
func (c *Context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
func (c *context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
c.bindTexture(t)
_ = mainthread.Run(func() error {
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
@ -218,7 +218,7 @@ func (c *Context) texSubImage2D(t textureNative, p []byte, x, y, width, height i
})
}
func (c *Context) newFramebuffer(texture textureNative) (framebufferNative, error) {
func (c *context) newFramebuffer(texture textureNative) (framebufferNative, error) {
var framebuffer framebufferNative
var f uint32
if err := mainthread.Run(func() error {
@ -252,14 +252,14 @@ func (c *Context) newFramebuffer(texture textureNative) (framebufferNative, erro
return framebuffer, nil
}
func (c *Context) setViewportImpl(width, height int) {
func (c *context) setViewportImpl(width, height int) {
_ = mainthread.Run(func() error {
gl.Viewport(0, 0, int32(width), int32(height))
return nil
})
}
func (c *Context) deleteFramebuffer(f framebufferNative) {
func (c *context) deleteFramebuffer(f framebufferNative) {
_ = mainthread.Run(func() error {
ff := uint32(f)
if !gl.IsFramebufferEXT(ff) {
@ -275,7 +275,7 @@ func (c *Context) deleteFramebuffer(f framebufferNative) {
})
}
func (c *Context) newShader(shaderType shaderType, source string) (shader, error) {
func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
var sh shader
if err := mainthread.Run(func() error {
s := gl.CreateShader(uint32(shaderType))
@ -306,14 +306,14 @@ func (c *Context) newShader(shaderType shaderType, source string) (shader, error
return sh, nil
}
func (c *Context) deleteShader(s shader) {
func (c *context) deleteShader(s shader) {
_ = mainthread.Run(func() error {
gl.DeleteShader(uint32(s))
return nil
})
}
func (c *Context) newProgram(shaders []shader) (program, error) {
func (c *context) newProgram(shaders []shader) (program, error) {
var pr program
if err := mainthread.Run(func() error {
p := gl.CreateProgram()
@ -338,14 +338,14 @@ func (c *Context) newProgram(shaders []shader) (program, error) {
return pr, nil
}
func (c *Context) useProgram(p program) {
func (c *context) useProgram(p program) {
_ = mainthread.Run(func() error {
gl.UseProgram(uint32(p))
return nil
})
}
func (c *Context) deleteProgram(p program) {
func (c *context) deleteProgram(p program) {
_ = mainthread.Run(func() error {
if !gl.IsProgram(uint32(p)) {
return nil
@ -355,7 +355,7 @@ func (c *Context) deleteProgram(p program) {
})
}
func (c *Context) getUniformLocationImpl(p program, location string) uniformLocation {
func (c *context) getUniformLocationImpl(p program, location string) uniformLocation {
l, free := gl.Strs(location + "\x00")
uniform := uniformLocation(gl.GetUniformLocation(uint32(p), *l))
free()
@ -365,7 +365,7 @@ func (c *Context) getUniformLocationImpl(p program, location string) uniformLoca
return uniform
}
func (c *Context) uniformInt(p program, location string, v int) {
func (c *context) uniformInt(p program, location string, v int) {
_ = mainthread.Run(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location))
gl.Uniform1i(l, int32(v))
@ -373,7 +373,7 @@ func (c *Context) uniformInt(p program, location string, v int) {
})
}
func (c *Context) uniformFloat(p program, location string, v float32) {
func (c *context) uniformFloat(p program, location string, v float32) {
_ = mainthread.Run(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location))
gl.Uniform1f(l, v)
@ -381,7 +381,7 @@ func (c *Context) uniformFloat(p program, location string, v float32) {
})
}
func (c *Context) uniformFloats(p program, location string, v []float32) {
func (c *context) uniformFloats(p program, location string, v []float32) {
_ = mainthread.Run(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location))
switch len(v) {
@ -398,7 +398,7 @@ func (c *Context) uniformFloats(p program, location string, v []float32) {
})
}
func (c *Context) getAttribLocationImpl(p program, location string) attribLocation {
func (c *context) getAttribLocationImpl(p program, location string) attribLocation {
l, free := gl.Strs(location + "\x00")
attrib := attribLocation(gl.GetAttribLocation(uint32(p), *l))
free()
@ -408,7 +408,7 @@ func (c *Context) getAttribLocationImpl(p program, location string) attribLocati
return attrib
}
func (c *Context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) {
func (c *context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) {
_ = mainthread.Run(func() error {
l := c.locationCache.GetAttribLocation(c, p, location)
gl.VertexAttribPointer(uint32(l), int32(size), uint32(dataType), false, int32(stride), gl.PtrOffset(offset))
@ -416,7 +416,7 @@ func (c *Context) vertexAttribPointer(p program, location string, size int, data
})
}
func (c *Context) enableVertexAttribArray(p program, location string) {
func (c *context) enableVertexAttribArray(p program, location string) {
_ = mainthread.Run(func() error {
l := c.locationCache.GetAttribLocation(c, p, location)
gl.EnableVertexAttribArray(uint32(l))
@ -424,7 +424,7 @@ func (c *Context) enableVertexAttribArray(p program, location string) {
})
}
func (c *Context) disableVertexAttribArray(p program, location string) {
func (c *context) disableVertexAttribArray(p program, location string) {
_ = mainthread.Run(func() error {
l := c.locationCache.GetAttribLocation(c, p, location)
gl.DisableVertexAttribArray(uint32(l))
@ -432,7 +432,7 @@ func (c *Context) disableVertexAttribArray(p program, location string) {
})
}
func (c *Context) newArrayBuffer(size int) buffer {
func (c *context) newArrayBuffer(size int) buffer {
var bf buffer
_ = mainthread.Run(func() error {
var b uint32
@ -445,7 +445,7 @@ func (c *Context) newArrayBuffer(size int) buffer {
return bf
}
func (c *Context) newElementArrayBuffer(size int) buffer {
func (c *context) newElementArrayBuffer(size int) buffer {
var bf buffer
_ = mainthread.Run(func() error {
var b uint32
@ -458,28 +458,28 @@ func (c *Context) newElementArrayBuffer(size int) buffer {
return bf
}
func (c *Context) bindBuffer(bufferType bufferType, b buffer) {
func (c *context) bindBuffer(bufferType bufferType, b buffer) {
_ = mainthread.Run(func() error {
gl.BindBuffer(uint32(bufferType), uint32(b))
return nil
})
}
func (c *Context) arrayBufferSubData(data []float32) {
func (c *context) arrayBufferSubData(data []float32) {
_ = mainthread.Run(func() error {
gl.BufferSubData(uint32(arrayBuffer), 0, len(data)*4, gl.Ptr(data))
return nil
})
}
func (c *Context) elementArrayBufferSubData(data []uint16) {
func (c *context) elementArrayBufferSubData(data []uint16) {
_ = mainthread.Run(func() error {
gl.BufferSubData(uint32(elementArrayBuffer), 0, len(data)*2, gl.Ptr(data))
return nil
})
}
func (c *Context) deleteBuffer(b buffer) {
func (c *context) deleteBuffer(b buffer) {
_ = mainthread.Run(func() error {
bb := uint32(b)
gl.DeleteBuffers(1, &bb)
@ -487,14 +487,14 @@ func (c *Context) deleteBuffer(b buffer) {
})
}
func (c *Context) drawElements(len int, offsetInBytes int) {
func (c *context) drawElements(len int, offsetInBytes int) {
_ = mainthread.Run(func() error {
gl.DrawElements(gl.TRIANGLES, int32(len), gl.UNSIGNED_SHORT, gl.PtrOffset(offsetInBytes))
return nil
})
}
func (c *Context) maxTextureSizeImpl() int {
func (c *context) maxTextureSizeImpl() int {
size := 0
_ = mainthread.Run(func() error {
s := int32(0)
@ -505,7 +505,7 @@ func (c *Context) maxTextureSizeImpl() int {
return size
}
func (c *Context) flush() {
func (c *context) flush() {
_ = mainthread.Run(func() error {
gl.Flush()
return nil

View File

@ -113,13 +113,13 @@ func init() {
initializeArrayBuferLayout()
}
type context struct {
type contextImpl struct {
gl js.Value
loseContext js.Value
lastProgramID programID
}
func (c *Context) ensureGL() {
func (c *context) ensureGL() {
if c.gl != (js.Value{}) {
return
}
@ -147,7 +147,7 @@ func (c *Context) ensureGL() {
c.loseContext = gl.Call("getExtension", "WEBGL_lose_context")
}
func (c *Context) reset() error {
func (c *context) reset() error {
c.locationCache = newLocationCache()
c.lastTexture = textureNative(js.Null())
c.lastFramebuffer = framebufferNative(js.Null())
@ -164,7 +164,7 @@ func (c *Context) reset() error {
return nil
}
func (c *Context) blendFunc(mode graphics.CompositeMode) {
func (c *context) blendFunc(mode graphics.CompositeMode) {
if c.lastCompositeMode == mode {
return
}
@ -176,7 +176,7 @@ func (c *Context) blendFunc(mode graphics.CompositeMode) {
gl.Call("blendFunc", int(s2), int(d2))
}
func (c *Context) newTexture(width, height int) (textureNative, error) {
func (c *context) newTexture(width, height int) (textureNative, error) {
c.ensureGL()
gl := c.gl
t := gl.Call("createTexture")
@ -203,13 +203,13 @@ func (c *Context) newTexture(width, height int) (textureNative, error) {
return textureNative(t), nil
}
func (c *Context) bindFramebufferImpl(f framebufferNative) {
func (c *context) bindFramebufferImpl(f framebufferNative) {
c.ensureGL()
gl := c.gl
gl.Call("bindFramebuffer", framebuffer_, js.Value(f))
}
func (c *Context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
c.ensureGL()
gl := c.gl
@ -226,13 +226,13 @@ func (c *Context) framebufferPixels(f *framebuffer, width, height int) ([]byte,
return pixels, nil
}
func (c *Context) bindTextureImpl(t textureNative) {
func (c *context) bindTextureImpl(t textureNative) {
c.ensureGL()
gl := c.gl
gl.Call("bindTexture", texture2d, js.Value(t))
}
func (c *Context) deleteTexture(t textureNative) {
func (c *context) deleteTexture(t textureNative) {
c.ensureGL()
gl := c.gl
if !gl.Call("isTexture", js.Value(t)).Bool() {
@ -244,13 +244,13 @@ func (c *Context) deleteTexture(t textureNative) {
gl.Call("deleteTexture", js.Value(t))
}
func (c *Context) isTexture(t textureNative) bool {
func (c *context) isTexture(t textureNative) bool {
c.ensureGL()
gl := c.gl
return gl.Call("isTexture", js.Value(t)).Bool()
}
func (c *Context) texSubImage2D(t textureNative, pixels []byte, x, y, width, height int) {
func (c *context) texSubImage2D(t textureNative, pixels []byte, x, y, width, height int) {
c.bindTexture(t)
c.ensureGL()
gl := c.gl
@ -262,7 +262,7 @@ func (c *Context) texSubImage2D(t textureNative, pixels []byte, x, y, width, hei
p.Release()
}
func (c *Context) newFramebuffer(t textureNative) (framebufferNative, error) {
func (c *context) newFramebuffer(t textureNative) (framebufferNative, error) {
c.ensureGL()
gl := c.gl
f := gl.Call("createFramebuffer")
@ -276,13 +276,13 @@ func (c *Context) newFramebuffer(t textureNative) (framebufferNative, error) {
return framebufferNative(f), nil
}
func (c *Context) setViewportImpl(width, height int) {
func (c *context) setViewportImpl(width, height int) {
c.ensureGL()
gl := c.gl
gl.Call("viewport", 0, 0, width, height)
}
func (c *Context) deleteFramebuffer(f framebufferNative) {
func (c *context) deleteFramebuffer(f framebufferNative) {
c.ensureGL()
gl := c.gl
if !gl.Call("isFramebuffer", js.Value(f)).Bool() {
@ -299,7 +299,7 @@ func (c *Context) deleteFramebuffer(f framebufferNative) {
gl.Call("deleteFramebuffer", js.Value(f))
}
func (c *Context) newShader(shaderType shaderType, source string) (shader, error) {
func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
c.ensureGL()
gl := c.gl
s := gl.Call("createShader", int(shaderType))
@ -317,13 +317,13 @@ func (c *Context) newShader(shaderType shaderType, source string) (shader, error
return shader(s), nil
}
func (c *Context) deleteShader(s shader) {
func (c *context) deleteShader(s shader) {
c.ensureGL()
gl := c.gl
gl.Call("deleteShader", js.Value(s))
}
func (c *Context) newProgram(shaders []shader) (program, error) {
func (c *context) newProgram(shaders []shader) (program, error) {
c.ensureGL()
gl := c.gl
v := gl.Call("createProgram")
@ -347,13 +347,13 @@ func (c *Context) newProgram(shaders []shader) (program, error) {
}, nil
}
func (c *Context) useProgram(p program) {
func (c *context) useProgram(p program) {
c.ensureGL()
gl := c.gl
gl.Call("useProgram", p.value)
}
func (c *Context) deleteProgram(p program) {
func (c *context) deleteProgram(p program) {
c.ensureGL()
gl := c.gl
if !gl.Call("isProgram", p.value).Bool() {
@ -362,20 +362,20 @@ func (c *Context) deleteProgram(p program) {
gl.Call("deleteProgram", p.value)
}
func (c *Context) getUniformLocationImpl(p program, location string) uniformLocation {
func (c *context) getUniformLocationImpl(p program, location string) uniformLocation {
c.ensureGL()
gl := c.gl
return uniformLocation(gl.Call("getUniformLocation", p.value, location))
}
func (c *Context) uniformInt(p program, location string, v int) {
func (c *context) uniformInt(p program, location string, v int) {
c.ensureGL()
gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location)
gl.Call("uniform1i", js.Value(l), v)
}
func (c *Context) uniformFloat(p program, location string, v float32) {
func (c *context) uniformFloat(p program, location string, v float32) {
c.ensureGL()
gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location)
@ -386,7 +386,7 @@ var (
float32Array = js.Global().Get("Float32Array")
)
func (c *Context) uniformFloats(p program, location string, v []float32) {
func (c *context) uniformFloats(p program, location string, v []float32) {
c.ensureGL()
gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location)
@ -404,34 +404,34 @@ func (c *Context) uniformFloats(p program, location string, v []float32) {
}
}
func (c *Context) getAttribLocationImpl(p program, location string) attribLocation {
func (c *context) getAttribLocationImpl(p program, location string) attribLocation {
c.ensureGL()
gl := c.gl
return attribLocation(gl.Call("getAttribLocation", p.value, location).Int())
}
func (c *Context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) {
func (c *context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) {
c.ensureGL()
gl := c.gl
l := c.locationCache.GetAttribLocation(c, p, location)
gl.Call("vertexAttribPointer", int(l), size, int(dataType), false, stride, offset)
}
func (c *Context) enableVertexAttribArray(p program, location string) {
func (c *context) enableVertexAttribArray(p program, location string) {
c.ensureGL()
gl := c.gl
l := c.locationCache.GetAttribLocation(c, p, location)
gl.Call("enableVertexAttribArray", int(l))
}
func (c *Context) disableVertexAttribArray(p program, location string) {
func (c *context) disableVertexAttribArray(p program, location string) {
c.ensureGL()
gl := c.gl
l := c.locationCache.GetAttribLocation(c, p, location)
gl.Call("disableVertexAttribArray", int(l))
}
func (c *Context) newArrayBuffer(size int) buffer {
func (c *context) newArrayBuffer(size int) buffer {
c.ensureGL()
gl := c.gl
b := gl.Call("createBuffer")
@ -440,7 +440,7 @@ func (c *Context) newArrayBuffer(size int) buffer {
return buffer(b)
}
func (c *Context) newElementArrayBuffer(size int) buffer {
func (c *context) newElementArrayBuffer(size int) buffer {
c.ensureGL()
gl := c.gl
b := gl.Call("createBuffer")
@ -449,13 +449,13 @@ func (c *Context) newElementArrayBuffer(size int) buffer {
return buffer(b)
}
func (c *Context) bindBuffer(bufferType bufferType, b buffer) {
func (c *context) bindBuffer(bufferType bufferType, b buffer) {
c.ensureGL()
gl := c.gl
gl.Call("bindBuffer", int(bufferType), js.Value(b))
}
func (c *Context) arrayBufferSubData(data []float32) {
func (c *context) arrayBufferSubData(data []float32) {
c.ensureGL()
gl := c.gl
arr := js.TypedArrayOf(data)
@ -463,7 +463,7 @@ func (c *Context) arrayBufferSubData(data []float32) {
arr.Release()
}
func (c *Context) elementArrayBufferSubData(data []uint16) {
func (c *context) elementArrayBufferSubData(data []uint16) {
c.ensureGL()
gl := c.gl
arr := js.TypedArrayOf(data)
@ -471,37 +471,37 @@ func (c *Context) elementArrayBufferSubData(data []uint16) {
arr.Release()
}
func (c *Context) deleteBuffer(b buffer) {
func (c *context) deleteBuffer(b buffer) {
c.ensureGL()
gl := c.gl
gl.Call("deleteBuffer", js.Value(b))
}
func (c *Context) drawElements(len int, offsetInBytes int) {
func (c *context) drawElements(len int, offsetInBytes int) {
c.ensureGL()
gl := c.gl
gl.Call("drawElements", triangles, len, unsignedShort, offsetInBytes)
}
func (c *Context) maxTextureSizeImpl() int {
func (c *context) maxTextureSizeImpl() int {
c.ensureGL()
gl := c.gl
return gl.Call("getParameter", maxTextureSize).Int()
}
func (c *Context) flush() {
func (c *context) flush() {
c.ensureGL()
gl := c.gl
gl.Call("flush")
}
func (c *Context) isContextLost() bool {
func (c *context) isContextLost() bool {
c.ensureGL()
gl := c.gl
return gl.Call("isContextLost").Bool()
}
func (c *Context) restoreContext() {
func (c *context) restoreContext() {
if c.loseContext != js.Null() {
c.loseContext.Call("restoreContext")
}

View File

@ -70,7 +70,7 @@ func init() {
initializeArrayBuferLayout()
}
type context struct {
type contextImpl struct {
gl mgl.Context
worker mgl.Worker
}
@ -83,7 +83,7 @@ func InitWithContext(context mgl.Context) {
theContext.gl = context
}
func (c *Context) doWork(chError <-chan error, chDone <-chan struct{}) error {
func (c *context) doWork(chError <-chan error, chDone <-chan struct{}) error {
if c.worker == nil {
panic("not reached")
}
@ -103,7 +103,7 @@ loop:
return nil
}
func (c *Context) reset() error {
func (c *context) reset() error {
c.locationCache = newLocationCache()
c.lastTexture = invalidTexture
c.lastFramebuffer = invalidFramebuffer
@ -118,7 +118,7 @@ func (c *Context) reset() error {
return nil
}
func (c *Context) blendFunc(mode graphics.CompositeMode) {
func (c *context) blendFunc(mode graphics.CompositeMode) {
gl := c.gl
if c.lastCompositeMode == mode {
return
@ -129,7 +129,7 @@ func (c *Context) blendFunc(mode graphics.CompositeMode) {
gl.BlendFunc(mgl.Enum(s2), mgl.Enum(d2))
}
func (c *Context) newTexture(width, height int) (textureNative, error) {
func (c *context) newTexture(width, height int) (textureNative, error) {
gl := c.gl
t := gl.CreateTexture()
if t.Value <= 0 {
@ -147,12 +147,12 @@ func (c *Context) newTexture(width, height int) (textureNative, error) {
return textureNative(t), nil
}
func (c *Context) bindFramebufferImpl(f framebufferNative) {
func (c *context) bindFramebufferImpl(f framebufferNative) {
gl := c.gl
gl.BindFramebuffer(mgl.FRAMEBUFFER, mgl.Framebuffer(f))
}
func (c *Context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
gl := c.gl
gl.Flush()
@ -166,12 +166,12 @@ func (c *Context) framebufferPixels(f *framebuffer, width, height int) ([]byte,
return pixels, nil
}
func (c *Context) bindTextureImpl(t textureNative) {
func (c *context) bindTextureImpl(t textureNative) {
gl := c.gl
gl.BindTexture(mgl.TEXTURE_2D, mgl.Texture(t))
}
func (c *Context) deleteTexture(t textureNative) {
func (c *context) deleteTexture(t textureNative) {
gl := c.gl
if !gl.IsTexture(mgl.Texture(t)) {
return
@ -182,18 +182,18 @@ func (c *Context) deleteTexture(t textureNative) {
gl.DeleteTexture(mgl.Texture(t))
}
func (c *Context) isTexture(t textureNative) bool {
func (c *context) isTexture(t textureNative) bool {
gl := c.gl
return gl.IsTexture(mgl.Texture(t))
}
func (c *Context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
func (c *context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
c.bindTexture(t)
gl := c.gl
gl.TexSubImage2D(mgl.TEXTURE_2D, 0, x, y, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
}
func (c *Context) newFramebuffer(texture textureNative) (framebufferNative, error) {
func (c *context) newFramebuffer(texture textureNative) (framebufferNative, error) {
gl := c.gl
f := gl.CreateFramebuffer()
if f.Value <= 0 {
@ -215,12 +215,12 @@ func (c *Context) newFramebuffer(texture textureNative) (framebufferNative, erro
return framebufferNative(f), nil
}
func (c *Context) setViewportImpl(width, height int) {
func (c *context) setViewportImpl(width, height int) {
gl := c.gl
gl.Viewport(0, 0, width, height)
}
func (c *Context) deleteFramebuffer(f framebufferNative) {
func (c *context) deleteFramebuffer(f framebufferNative) {
gl := c.gl
if !gl.IsFramebuffer(mgl.Framebuffer(f)) {
return
@ -236,7 +236,7 @@ func (c *Context) deleteFramebuffer(f framebufferNative) {
gl.DeleteFramebuffer(mgl.Framebuffer(f))
}
func (c *Context) newShader(shaderType shaderType, source string) (shader, error) {
func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
gl := c.gl
s := gl.CreateShader(mgl.Enum(shaderType))
if s.Value == 0 {
@ -253,12 +253,12 @@ func (c *Context) newShader(shaderType shaderType, source string) (shader, error
return shader(s), nil
}
func (c *Context) deleteShader(s shader) {
func (c *context) deleteShader(s shader) {
gl := c.gl
gl.DeleteShader(mgl.Shader(s))
}
func (c *Context) newProgram(shaders []shader) (program, error) {
func (c *context) newProgram(shaders []shader) (program, error) {
gl := c.gl
p := gl.CreateProgram()
if p.Value == 0 {
@ -276,12 +276,12 @@ func (c *Context) newProgram(shaders []shader) (program, error) {
return program(p), nil
}
func (c *Context) useProgram(p program) {
func (c *context) useProgram(p program) {
gl := c.gl
gl.UseProgram(mgl.Program(p))
}
func (c *Context) deleteProgram(p program) {
func (c *context) deleteProgram(p program) {
gl := c.gl
if !gl.IsProgram(mgl.Program(p)) {
return
@ -289,7 +289,7 @@ func (c *Context) deleteProgram(p program) {
gl.DeleteProgram(mgl.Program(p))
}
func (c *Context) getUniformLocationImpl(p program, location string) uniformLocation {
func (c *context) getUniformLocationImpl(p program, location string) uniformLocation {
gl := c.gl
u := uniformLocation(gl.GetUniformLocation(mgl.Program(p), location))
if u.Value == -1 {
@ -298,17 +298,17 @@ func (c *Context) getUniformLocationImpl(p program, location string) uniformLoca
return u
}
func (c *Context) uniformInt(p program, location string, v int) {
func (c *context) uniformInt(p program, location string, v int) {
gl := c.gl
gl.Uniform1i(mgl.Uniform(c.locationCache.GetUniformLocation(c, p, location)), v)
}
func (c *Context) uniformFloat(p program, location string, v float32) {
func (c *context) uniformFloat(p program, location string, v float32) {
gl := c.gl
gl.Uniform1f(mgl.Uniform(c.locationCache.GetUniformLocation(c, p, location)), v)
}
func (c *Context) uniformFloats(p program, location string, v []float32) {
func (c *context) uniformFloats(p program, location string, v []float32) {
gl := c.gl
l := mgl.Uniform(c.locationCache.GetUniformLocation(c, p, location))
switch len(v) {
@ -323,7 +323,7 @@ func (c *Context) uniformFloats(p program, location string, v []float32) {
}
}
func (c *Context) getAttribLocationImpl(p program, location string) attribLocation {
func (c *context) getAttribLocationImpl(p program, location string) attribLocation {
gl := c.gl
a := attribLocation(gl.GetAttribLocation(mgl.Program(p), location))
if a.Value == ^uint(0) {
@ -332,25 +332,25 @@ func (c *Context) getAttribLocationImpl(p program, location string) attribLocati
return a
}
func (c *Context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) {
func (c *context) vertexAttribPointer(p program, location string, size int, dataType dataType, stride int, offset int) {
gl := c.gl
l := c.locationCache.GetAttribLocation(c, p, location)
gl.VertexAttribPointer(mgl.Attrib(l), size, mgl.Enum(dataType), false, stride, offset)
}
func (c *Context) enableVertexAttribArray(p program, location string) {
func (c *context) enableVertexAttribArray(p program, location string) {
gl := c.gl
l := c.locationCache.GetAttribLocation(c, p, location)
gl.EnableVertexAttribArray(mgl.Attrib(l))
}
func (c *Context) disableVertexAttribArray(p program, location string) {
func (c *context) disableVertexAttribArray(p program, location string) {
gl := c.gl
l := c.locationCache.GetAttribLocation(c, p, location)
gl.DisableVertexAttribArray(mgl.Attrib(l))
}
func (c *Context) newArrayBuffer(size int) buffer {
func (c *context) newArrayBuffer(size int) buffer {
gl := c.gl
b := gl.CreateBuffer()
gl.BindBuffer(mgl.Enum(arrayBuffer), b)
@ -358,7 +358,7 @@ func (c *Context) newArrayBuffer(size int) buffer {
return buffer(b)
}
func (c *Context) newElementArrayBuffer(size int) buffer {
func (c *context) newElementArrayBuffer(size int) buffer {
gl := c.gl
b := gl.CreateBuffer()
gl.BindBuffer(mgl.Enum(elementArrayBuffer), b)
@ -366,37 +366,37 @@ func (c *Context) newElementArrayBuffer(size int) buffer {
return buffer(b)
}
func (c *Context) bindBuffer(bufferType bufferType, b buffer) {
func (c *context) bindBuffer(bufferType bufferType, b buffer) {
gl := c.gl
gl.BindBuffer(mgl.Enum(bufferType), mgl.Buffer(b))
}
func (c *Context) arrayBufferSubData(data []float32) {
func (c *context) arrayBufferSubData(data []float32) {
gl := c.gl
gl.BufferSubData(mgl.Enum(arrayBuffer), 0, float32sToBytes(data))
}
func (c *Context) elementArrayBufferSubData(data []uint16) {
func (c *context) elementArrayBufferSubData(data []uint16) {
gl := c.gl
gl.BufferSubData(mgl.Enum(elementArrayBuffer), 0, uint16sToBytes(data))
}
func (c *Context) deleteBuffer(b buffer) {
func (c *context) deleteBuffer(b buffer) {
gl := c.gl
gl.DeleteBuffer(mgl.Buffer(b))
}
func (c *Context) drawElements(len int, offsetInBytes int) {
func (c *context) drawElements(len int, offsetInBytes int) {
gl := c.gl
gl.DrawElements(mgl.TRIANGLES, len, mgl.UNSIGNED_SHORT, offsetInBytes)
}
func (c *Context) maxTextureSizeImpl() int {
func (c *context) maxTextureSizeImpl() int {
gl := c.gl
return gl.GetInteger(mgl.MAX_TEXTURE_SIZE)
}
func (c *Context) flush() {
func (c *context) flush() {
gl := c.gl
gl.Flush()
}

View File

@ -28,7 +28,7 @@ func newLocationCache() *locationCache {
}
}
func (c *locationCache) GetUniformLocation(context *Context, p program, location string) uniformLocation {
func (c *locationCache) GetUniformLocation(context *context, p program, location string) uniformLocation {
id := getProgramID(p)
if _, ok := c.uniformLocationCache[id]; !ok {
c.uniformLocationCache[id] = map[string]uniformLocation{}
@ -41,7 +41,7 @@ func (c *locationCache) GetUniformLocation(context *Context, p program, location
return l
}
func (c *locationCache) GetAttribLocation(context *Context, p program, location string) attribLocation {
func (c *locationCache) GetAttribLocation(context *context, p program, location string) attribLocation {
id := getProgramID(p)
if _, ok := c.attribLocationCache[id]; !ok {
c.attribLocationCache[id] = map[string]attribLocation{}