opengl: Unexport types

This commit is contained in:
Hajime Hoshi 2018-10-30 01:52:59 +09:00
parent e4179aee37
commit ac7bf354a9
8 changed files with 135 additions and 135 deletions

View File

@ -26,14 +26,14 @@ var (
)
var (
VertexShader ShaderType
FragmentShader ShaderType
ArrayBuffer BufferType
ElementArrayBuffer BufferType
DynamicDraw BufferUsage
StaticDraw BufferUsage
Triangles Mode
Lines Mode
VertexShader shaderType
FragmentShader shaderType
ArrayBuffer bufferType
ElementArrayBuffer bufferType
DynamicDraw bufferUsage
StaticDraw bufferUsage
Triangles mode
Lines mode
Short DataType
Float DataType

View File

@ -31,9 +31,9 @@ import (
type (
Texture uint32
Framebuffer uint32
Shader uint32
Program uint32
Buffer uint32
shader uint32
program uint32
buffer uint32
)
var InvalidTexture Texture
@ -50,7 +50,7 @@ const (
invalidFramebuffer = (1 << 32) - 1
)
func getProgramID(p Program) programID {
func getProgramID(p program) programID {
return programID(p)
}
@ -290,8 +290,8 @@ func (c *Context) DeleteFramebuffer(f Framebuffer) {
})
}
func (c *Context) newShader(shaderType ShaderType, source string) (Shader, error) {
var shader Shader
func (c *Context) newShader(shaderType shaderType, source string) (shader, error) {
var sh shader
if err := c.runOnContextThread(func() error {
s := gl.CreateShader(uint32(shaderType))
if s == 0 {
@ -313,23 +313,23 @@ func (c *Context) newShader(shaderType ShaderType, source string) (Shader, error
}
return fmt.Errorf("opengl: shader compile failed: %s", log)
}
shader = Shader(s)
sh = shader(s)
return nil
}); err != nil {
return 0, err
}
return shader, nil
return sh, 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) {
var program Program
func (c *Context) newProgram(shaders []shader) (program, error) {
var pr program
if err := c.runOnContextThread(func() error {
p := gl.CreateProgram()
if p == 0 {
@ -345,22 +345,22 @@ func (c *Context) newProgram(shaders []Shader) (Program, error) {
if v == gl.FALSE {
return errors.New("opengl: program error")
}
program = Program(p)
pr = program(p)
return nil
}); err != nil {
return 0, err
}
return program, nil
return pr, 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
@ -370,7 +370,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()
@ -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) {
@ -413,7 +413,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()
@ -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,33 +447,33 @@ func (c *Context) disableVertexAttribArray(p Program, location string) {
})
}
func (c *Context) newArrayBuffer(size int) Buffer {
var buffer Buffer
func (c *Context) newArrayBuffer(size int) buffer {
var bf buffer
_ = c.runOnContextThread(func() error {
var b uint32
gl.GenBuffers(1, &b)
gl.BindBuffer(uint32(ArrayBuffer), b)
gl.BufferData(uint32(ArrayBuffer), size, nil, uint32(DynamicDraw))
buffer = Buffer(b)
bf = buffer(b)
return nil
})
return buffer
return bf
}
func (c *Context) newElementArrayBuffer(size int) Buffer {
var buffer Buffer
func (c *Context) newElementArrayBuffer(size int) buffer {
var bf buffer
_ = c.runOnContextThread(func() error {
var b uint32
gl.GenBuffers(1, &b)
gl.BindBuffer(uint32(ElementArrayBuffer), b)
gl.BufferData(uint32(ElementArrayBuffer), size, nil, uint32(DynamicDraw))
buffer = Buffer(b)
bf = buffer(b)
return nil
})
return buffer
return bf
}
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
func (c *Context) BindBuffer(bufferType bufferType, b buffer) {
_ = c.runOnContextThread(func() error {
gl.BindBuffer(uint32(bufferType), uint32(b))
return nil
@ -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)
@ -502,7 +502,7 @@ func (c *Context) deleteBuffer(b Buffer) {
})
}
func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
func (c *Context) DrawElements(mode mode, len int, offsetInBytes int) {
_ = c.runOnContextThread(func() error {
gl.DrawElements(uint32(mode), int32(len), gl.UNSIGNED_SHORT, gl.PtrOffset(offsetInBytes))
return nil

View File

@ -28,13 +28,13 @@ import (
type (
Texture js.Value
Framebuffer js.Value
Shader js.Value
Buffer js.Value
shader js.Value
buffer js.Value
uniformLocation js.Value
attribLocation int
programID int
Program struct {
program struct {
value js.Value
id programID
}
@ -42,7 +42,7 @@ type (
var InvalidTexture = Texture(js.Null())
func getProgramID(p Program) programID {
func getProgramID(p program) programID {
return p.id
}
@ -72,13 +72,13 @@ var (
func init() {
// Accessing the prototype is rquired on Safari.
c := js.Global().Get("WebGLRenderingContext").Get("prototype")
VertexShader = ShaderType(c.Get("VERTEX_SHADER").Int())
FragmentShader = ShaderType(c.Get("FRAGMENT_SHADER").Int())
ArrayBuffer = BufferType(c.Get("ARRAY_BUFFER").Int())
ElementArrayBuffer = BufferType(c.Get("ELEMENT_ARRAY_BUFFER").Int())
DynamicDraw = BufferUsage(c.Get("DYNAMIC_DRAW").Int())
Triangles = Mode(c.Get("TRIANGLES").Int())
Lines = Mode(c.Get("LINES").Int())
VertexShader = shaderType(c.Get("VERTEX_SHADER").Int())
FragmentShader = shaderType(c.Get("FRAGMENT_SHADER").Int())
ArrayBuffer = bufferType(c.Get("ARRAY_BUFFER").Int())
ElementArrayBuffer = bufferType(c.Get("ELEMENT_ARRAY_BUFFER").Int())
DynamicDraw = bufferUsage(c.Get("DYNAMIC_DRAW").Int())
Triangles = mode(c.Get("TRIANGLES").Int())
Lines = mode(c.Get("LINES").Int())
Short = DataType(c.Get("SHORT").Int())
Float = DataType(c.Get("FLOAT").Int())
@ -285,11 +285,11 @@ 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() {
return Shader(js.Null()), fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
return shader(js.Null()), fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
}
gl.Call("shaderSource", js.Value(s), source)
@ -297,21 +297,21 @@ func (c *Context) newShader(shaderType ShaderType, source string) (Shader, error
if !gl.Call("getShaderParameter", js.Value(s), compileStatus).Bool() {
log := gl.Call("getShaderInfoLog", js.Value(s))
return Shader(js.Null()), fmt.Errorf("opengl: shader compile failed: %s", log)
return shader(js.Null()), fmt.Errorf("opengl: shader compile failed: %s", log)
}
return Shader(s), nil
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() {
return Program{}, errors.New("opengl: glCreateProgram failed")
return program{}, errors.New("opengl: glCreateProgram failed")
}
for _, shader := range shaders {
@ -319,23 +319,23 @@ func (c *Context) newProgram(shaders []Shader) (Program, error) {
}
gl.Call("linkProgram", v)
if !gl.Call("getProgramParameter", v, linkStatus).Bool() {
return Program{}, errors.New("opengl: program error")
return program{}, errors.New("opengl: program error")
}
id := c.lastProgramID
c.lastProgramID++
return Program{
return program{
value: v,
id: id,
}, 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
@ -343,18 +343,18 @@ 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 {
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) {
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) {
@ -381,46 +381,46 @@ 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
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))
gl.Call("bufferData", int(ArrayBuffer), size, int(DynamicDraw))
return Buffer(b)
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))
gl.Call("bufferData", int(ElementArrayBuffer), size, int(DynamicDraw))
return Buffer(b)
return buffer(b)
}
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
func (c *Context) BindBuffer(bufferType bufferType, b buffer) {
gl := c.gl
gl.Call("bindBuffer", int(bufferType), js.Value(b))
}
@ -439,12 +439,12 @@ 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))
}
func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
func (c *Context) DrawElements(mode mode, len int, offsetInBytes int) {
gl := c.gl
gl.Call("drawElements", int(mode), len, unsignedShort, offsetInBytes)
}

View File

@ -28,9 +28,9 @@ import (
type (
Texture mgl.Texture
Framebuffer mgl.Framebuffer
Shader mgl.Shader
Program mgl.Program
Buffer mgl.Buffer
shader mgl.Shader
program mgl.Program
buffer mgl.Buffer
)
var InvalidTexture Texture
@ -47,7 +47,7 @@ var (
invalidFramebuffer = Framebuffer(mgl.Framebuffer{(1 << 32) - 1})
)
func getProgramID(p Program) programID {
func getProgramID(p program) programID {
return programID(p.Value)
}
@ -241,11 +241,11 @@ 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 {
return Shader{}, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
return shader{}, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
}
gl.ShaderSource(s, source)
gl.CompileShader(s)
@ -253,21 +253,21 @@ func (c *Context) newShader(shaderType ShaderType, source string) (Shader, error
v := gl.GetShaderi(s, mgl.COMPILE_STATUS)
if v == mgl.FALSE {
log := gl.GetShaderInfoLog(s)
return Shader{}, fmt.Errorf("opengl: shader compile failed: %s", log)
return shader{}, fmt.Errorf("opengl: shader compile failed: %s", log)
}
return Shader(s), nil
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 {
return Program{}, errors.New("opengl: glCreateProgram failed")
return program{}, errors.New("opengl: glCreateProgram failed")
}
for _, shader := range shaders {
@ -276,17 +276,17 @@ func (c *Context) newProgram(shaders []Shader) (Program, error) {
gl.LinkProgram(p)
v := gl.GetProgrami(p, mgl.LINK_STATUS)
if v == mgl.FALSE {
return Program{}, errors.New("opengl: program error")
return program{}, errors.New("opengl: program error")
}
return Program(p), nil
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
@ -294,7 +294,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 {
@ -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) {
@ -328,7 +328,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) {
@ -337,41 +337,41 @@ 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)
gl.BufferInit(mgl.Enum(ArrayBuffer), size, mgl.Enum(DynamicDraw))
return Buffer(b)
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)
gl.BufferInit(mgl.Enum(ElementArrayBuffer), size, mgl.Enum(DynamicDraw))
return Buffer(b)
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))
}
@ -386,12 +386,12 @@ 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))
}
func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
func (c *Context) DrawElements(mode mode, len int, offsetInBytes int) {
gl := c.gl
gl.DrawElements(mgl.Enum(mode), len, mgl.UNSIGNED_SHORT, offsetInBytes)
}

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{}

View File

@ -54,12 +54,12 @@ func (a *arrayBufferLayout) totalBytes() int {
}
// newArrayBuffer creates OpenGL's buffer object for the array buffer.
func (a *arrayBufferLayout) newArrayBuffer() Buffer {
func (a *arrayBufferLayout) newArrayBuffer() buffer {
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) {
func (a *arrayBufferLayout) enable(program program) {
for _, p := range a.parts {
GetContext().enableVertexAttribArray(program, p.name)
}
@ -72,7 +72,7 @@ func (a *arrayBufferLayout) enable(program Program) {
}
// disable stops using the array buffer.
func (a *arrayBufferLayout) disable(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)
@ -112,20 +112,20 @@ func ArrayBufferLayoutTotalBytes() int {
// openGLState is a state for
type openGLState struct {
// arrayBuffer is OpenGL's array buffer (vertices data).
arrayBuffer Buffer
arrayBuffer buffer
// elementArrayBuffer is OpenGL's element array buffer (indices data).
elementArrayBuffer Buffer
elementArrayBuffer buffer
// programNearest is OpenGL's program for rendering a texture with nearest filter.
programNearest Program
programNearest program
// programLinear is OpenGL's program for rendering a texture with linear filter.
programLinear Program
programLinear program
programScreen Program
programScreen program
lastProgram Program
lastProgram program
lastProjectionMatrix []float32
lastColorMatrix []float32
lastColorMatrixTranslation []float32
@ -137,8 +137,8 @@ var (
// theOpenGLState is the OpenGL state in the current process.
theOpenGLState openGLState
zeroBuffer Buffer
zeroProgram Program
zeroBuffer buffer
zeroProgram program
)
const (
@ -189,31 +189,31 @@ func (s *openGLState) reset() error {
}
}
shaderVertexModelviewNative, err := GetContext().newShader(VertexShader, shader(shaderVertexModelview))
shaderVertexModelviewNative, err := GetContext().newShader(VertexShader, shaderStr(shaderVertexModelview))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().deleteShader(shaderVertexModelviewNative)
shaderFragmentNearestNative, err := GetContext().newShader(FragmentShader, shader(shaderFragmentNearest))
shaderFragmentNearestNative, err := GetContext().newShader(FragmentShader, shaderStr(shaderFragmentNearest))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().deleteShader(shaderFragmentNearestNative)
shaderFragmentLinearNative, err := GetContext().newShader(FragmentShader, shader(shaderFragmentLinear))
shaderFragmentLinearNative, err := GetContext().newShader(FragmentShader, shaderStr(shaderFragmentLinear))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer GetContext().deleteShader(shaderFragmentLinearNative)
shaderFragmentScreenNative, err := GetContext().newShader(FragmentShader, shader(shaderFragmentScreen))
shaderFragmentScreenNative, err := GetContext().newShader(FragmentShader, shaderStr(shaderFragmentScreen))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
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,
})
@ -268,7 +268,7 @@ func UseProgram(proj []float32, texture Texture, dstW, dstH, srcW, srcH int, col
func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, srcW, srcH int, colorM *affine.ColorM, filter graphics.Filter) {
c := GetContext()
var program Program
var program program
switch filter {
case graphics.FilterNearest:
program = s.programNearest

View File

@ -27,7 +27,7 @@ const (
shaderFragmentScreen
)
func shader(id shaderID) string {
func shaderStr(id shaderID) string {
if id == shaderVertexModelview {
return shaderStrVertex
}

View File

@ -15,10 +15,10 @@
package opengl
type (
ShaderType int
BufferType int
BufferUsage int
Mode int
shaderType int
bufferType int
bufferUsage int
mode int
operation int
)