opengl: Unexport functions

This commit is contained in:
Hajime Hoshi 2018-10-30 01:31:09 +09:00
parent 6b95a5140c
commit e4179aee37
4 changed files with 71 additions and 71 deletions

View File

@ -290,7 +290,7 @@ func (c *Context) DeleteFramebuffer(f Framebuffer) {
})
}
func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error) {
func (c *Context) newShader(shaderType ShaderType, source string) (Shader, error) {
var shader Shader
if err := c.runOnContextThread(func() error {
s := gl.CreateShader(uint32(shaderType))
@ -321,14 +321,14 @@ func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error
return shader, nil
}
func (c *Context) DeleteShader(s Shader) {
func (c *Context) deleteShader(s Shader) {
_ = c.runOnContextThread(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 program Program
if err := c.runOnContextThread(func() error {
p := gl.CreateProgram()
@ -353,14 +353,14 @@ func (c *Context) NewProgram(shaders []Shader) (Program, error) {
return program, nil
}
func (c *Context) UseProgram(p Program) {
func (c *Context) useProgram(p Program) {
_ = c.runOnContextThread(func() error {
gl.UseProgram(uint32(p))
return nil
})
}
func (c *Context) DeleteProgram(p Program) {
func (c *Context) deleteProgram(p Program) {
_ = c.runOnContextThread(func() error {
if !gl.IsProgram(uint32(p)) {
return nil
@ -380,7 +380,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) {
_ = c.runOnContextThread(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location))
gl.Uniform1i(l, int32(v))
@ -388,7 +388,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) {
_ = c.runOnContextThread(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location))
gl.Uniform1f(l, v)
@ -396,7 +396,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) {
_ = c.runOnContextThread(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location))
switch len(v) {
@ -423,7 +423,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) {
_ = c.runOnContextThread(func() error {
l := c.locationCache.GetAttribLocation(c, p, location)
gl.VertexAttribPointer(uint32(l), int32(size), uint32(dataType), false, int32(stride), gl.PtrOffset(offset))
@ -431,7 +431,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) {
_ = c.runOnContextThread(func() error {
l := c.locationCache.GetAttribLocation(c, p, location)
gl.EnableVertexAttribArray(uint32(l))
@ -439,7 +439,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) {
_ = c.runOnContextThread(func() error {
l := c.locationCache.GetAttribLocation(c, p, location)
gl.DisableVertexAttribArray(uint32(l))
@ -447,7 +447,7 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
})
}
func (c *Context) NewArrayBuffer(size int) Buffer {
func (c *Context) newArrayBuffer(size int) Buffer {
var buffer Buffer
_ = c.runOnContextThread(func() error {
var b uint32
@ -460,7 +460,7 @@ func (c *Context) NewArrayBuffer(size int) Buffer {
return buffer
}
func (c *Context) NewElementArrayBuffer(size int) Buffer {
func (c *Context) newElementArrayBuffer(size int) Buffer {
var buffer Buffer
_ = c.runOnContextThread(func() error {
var b uint32
@ -494,7 +494,7 @@ func (c *Context) ElementArrayBufferSubData(data []uint16) {
})
}
func (c *Context) DeleteBuffer(b Buffer) {
func (c *Context) deleteBuffer(b Buffer) {
_ = c.runOnContextThread(func() error {
bb := uint32(b)
gl.DeleteBuffers(1, &bb)

View File

@ -285,7 +285,7 @@ func (c *Context) DeleteFramebuffer(f Framebuffer) {
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) {
gl := c.gl
s := gl.Call("createShader", int(shaderType))
if s == js.Null() {
@ -302,12 +302,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.Call("deleteShader", js.Value(s))
}
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
func (c *Context) newProgram(shaders []Shader) (Program, error) {
gl := c.gl
v := gl.Call("createProgram")
if v == js.Null() {
@ -330,12 +330,12 @@ func (c *Context) NewProgram(shaders []Shader) (Program, error) {
}, nil
}
func (c *Context) UseProgram(p Program) {
func (c *Context) useProgram(p Program) {
gl := c.gl
gl.Call("useProgram", p.value)
}
func (c *Context) DeleteProgram(p Program) {
func (c *Context) deleteProgram(p Program) {
gl := c.gl
if !gl.Call("isProgram", p.value).Bool() {
return
@ -348,13 +348,13 @@ func (c *Context) getUniformLocationImpl(p Program, location string) uniformLoca
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) {
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) {
gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location)
gl.Call("uniform1f", js.Value(l), v)
@ -364,7 +364,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) {
gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location)
switch len(v) {
@ -386,25 +386,25 @@ func (c *Context) getAttribLocationImpl(p Program, location string) attribLocati
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) {
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) {
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) {
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 {
gl := c.gl
b := gl.Call("createBuffer")
gl.Call("bindBuffer", int(ArrayBuffer), js.Value(b))
@ -412,7 +412,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.Call("createBuffer")
gl.Call("bindBuffer", int(ElementArrayBuffer), js.Value(b))
@ -439,7 +439,7 @@ func (c *Context) ElementArrayBufferSubData(data []uint16) {
arr.Release()
}
func (c *Context) DeleteBuffer(b Buffer) {
func (c *Context) deleteBuffer(b Buffer) {
gl := c.gl
gl.Call("deleteBuffer", js.Value(b))
}

View File

@ -241,7 +241,7 @@ func (c *Context) DeleteFramebuffer(f Framebuffer) {
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 {
@ -258,12 +258,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 {
@ -281,12 +281,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
@ -303,17 +303,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) {
@ -337,25 +337,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)
@ -363,7 +363,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)
@ -386,7 +386,7 @@ func (c *Context) ElementArrayBufferSubData(data []uint16) {
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))
}

View File

@ -55,18 +55,18 @@ func (a *arrayBufferLayout) totalBytes() int {
// newArrayBuffer creates OpenGL's buffer object for the array buffer.
func (a *arrayBufferLayout) newArrayBuffer() Buffer {
return GetContext().NewArrayBuffer(a.totalBytes() * IndicesNum)
return GetContext().newArrayBuffer(a.totalBytes() * IndicesNum)
}
// enable binds the array buffer the given program to use the array buffer.
func (a *arrayBufferLayout) enable(program Program) {
for _, p := range a.parts {
GetContext().EnableVertexAttribArray(program, p.name)
GetContext().enableVertexAttribArray(program, p.name)
}
total := a.totalBytes()
offset := 0
for _, p := range a.parts {
GetContext().VertexAttribPointer(program, p.name, p.num, p.dataType, total, offset)
GetContext().vertexAttribPointer(program, p.name, p.num, p.dataType, total, offset)
offset += p.dataType.SizeInBytes() * p.num
}
}
@ -75,7 +75,7 @@ func (a *arrayBufferLayout) enable(program Program) {
func (a *arrayBufferLayout) disable(program Program) {
// TODO: Disabling should be done in reversed order?
for _, p := range a.parts {
GetContext().DisableVertexAttribArray(program, p.name)
GetContext().disableVertexAttribArray(program, p.name)
}
}
@ -109,7 +109,7 @@ func ArrayBufferLayoutTotalBytes() int {
return theArrayBufferLayout.totalBytes()
}
// openGLState is a state for
// openGLState is a state for
type openGLState struct {
// arrayBuffer is OpenGL's array buffer (vertices data).
arrayBuffer Buffer
@ -169,51 +169,51 @@ func (s *openGLState) reset() error {
// However, it is not assumed that reset is called only when context lost happens.
// Let's delete them explicitly.
if s.programNearest != zeroProgram {
GetContext().DeleteProgram(s.programNearest)
GetContext().deleteProgram(s.programNearest)
}
if s.programLinear != zeroProgram {
GetContext().DeleteProgram(s.programLinear)
GetContext().deleteProgram(s.programLinear)
}
if s.programScreen != zeroProgram {
GetContext().DeleteProgram(s.programScreen)
GetContext().deleteProgram(s.programScreen)
}
// On browsers (at least Chrome), buffers are already detached from the context
// and must not be deleted by DeleteBuffer.
if !web.IsBrowser() {
if s.arrayBuffer != zeroBuffer {
GetContext().DeleteBuffer(s.arrayBuffer)
GetContext().deleteBuffer(s.arrayBuffer)
}
if s.elementArrayBuffer != zeroBuffer {
GetContext().DeleteBuffer(s.elementArrayBuffer)
GetContext().deleteBuffer(s.elementArrayBuffer)
}
}
shaderVertexModelviewNative, err := GetContext().NewShader(VertexShader, shader(shaderVertexModelview))
shaderVertexModelviewNative, err := GetContext().newShader(VertexShader, shader(shaderVertexModelview))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().DeleteShader(shaderVertexModelviewNative)
defer GetContext().deleteShader(shaderVertexModelviewNative)
shaderFragmentNearestNative, err := GetContext().NewShader(FragmentShader, shader(shaderFragmentNearest))
shaderFragmentNearestNative, err := GetContext().newShader(FragmentShader, shader(shaderFragmentNearest))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().DeleteShader(shaderFragmentNearestNative)
defer GetContext().deleteShader(shaderFragmentNearestNative)
shaderFragmentLinearNative, err := GetContext().NewShader(FragmentShader, shader(shaderFragmentLinear))
shaderFragmentLinearNative, err := GetContext().newShader(FragmentShader, shader(shaderFragmentLinear))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().DeleteShader(shaderFragmentLinearNative)
defer GetContext().deleteShader(shaderFragmentLinearNative)
shaderFragmentScreenNative, err := GetContext().NewShader(FragmentShader, shader(shaderFragmentScreen))
shaderFragmentScreenNative, err := GetContext().newShader(FragmentShader, shader(shaderFragmentScreen))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().DeleteShader(shaderFragmentScreenNative)
defer GetContext().deleteShader(shaderFragmentScreenNative)
s.programNearest, err = GetContext().NewProgram([]Shader{
s.programNearest, err = GetContext().newProgram([]Shader{
shaderVertexModelviewNative,
shaderFragmentNearestNative,
})
@ -221,7 +221,7 @@ func (s *openGLState) reset() error {
return err
}
s.programLinear, err = GetContext().NewProgram([]Shader{
s.programLinear, err = GetContext().newProgram([]Shader{
shaderVertexModelviewNative,
shaderFragmentLinearNative,
})
@ -229,7 +229,7 @@ func (s *openGLState) reset() error {
return err
}
s.programScreen, err = GetContext().NewProgram([]Shader{
s.programScreen, err = GetContext().newProgram([]Shader{
shaderVertexModelviewNative,
shaderFragmentScreenNative,
})
@ -242,7 +242,7 @@ func (s *openGLState) reset() error {
// Note that the indices passed to NewElementArrayBuffer is not under GC management
// in opengl package due to unsafe-way.
// See NewElementArrayBuffer in context_mobile.go.
s.elementArrayBuffer = GetContext().NewElementArrayBuffer(IndicesNum * 2)
s.elementArrayBuffer = GetContext().newElementArrayBuffer(IndicesNum * 2)
return nil
}
@ -281,7 +281,7 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr
}
if s.lastProgram != program {
c.UseProgram(program)
c.useProgram(program)
if s.lastProgram != zeroProgram {
theArrayBufferLayout.disable(s.lastProgram)
}
@ -290,7 +290,7 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr
if s.lastProgram == zeroProgram {
c.BindBuffer(ArrayBuffer, s.arrayBuffer)
c.BindBuffer(ElementArrayBuffer, s.elementArrayBuffer)
c.UniformInt(program, "texture", 0)
c.uniformInt(program, "texture", 0)
}
s.lastProgram = program
@ -302,7 +302,7 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr
}
if !areSameFloat32Array(s.lastProjectionMatrix, proj) {
c.UniformFloats(program, "projection_matrix", proj)
c.uniformFloats(program, "projection_matrix", proj)
if s.lastProjectionMatrix == nil {
s.lastProjectionMatrix = make([]float32, 16)
}
@ -314,7 +314,7 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr
esBody, esTranslate := colorM.UnsafeElements()
if !areSameFloat32Array(s.lastColorMatrix, esBody) {
c.UniformFloats(program, "color_matrix_body", esBody)
c.uniformFloats(program, "color_matrix_body", esBody)
if s.lastColorMatrix == nil {
s.lastColorMatrix = make([]float32, 16)
}
@ -322,7 +322,7 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr
s.lastColorMatrix = esBody
}
if !areSameFloat32Array(s.lastColorMatrixTranslation, esTranslate) {
c.UniformFloats(program, "color_matrix_translation", esTranslate)
c.uniformFloats(program, "color_matrix_translation", esTranslate)
if s.lastColorMatrixTranslation == nil {
s.lastColorMatrixTranslation = make([]float32, 4)
}
@ -334,14 +334,14 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr
sh := emath.NextPowerOf2Int(srcH)
if s.lastSourceWidth != sw || s.lastSourceHeight != sh {
c.UniformFloats(program, "source_size", []float32{float32(sw), float32(sh)})
c.uniformFloats(program, "source_size", []float32{float32(sw), float32(sh)})
s.lastSourceWidth = sw
s.lastSourceHeight = sh
}
if program == s.programScreen {
scale := float32(dstW) / float32(srcW)
c.UniformFloat(program, "scale", scale)
c.uniformFloat(program, "scale", scale)
}
// We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture