changed openglinterface a bit to be less specific to the go-gl implementation
This commit is contained in:
parent
7042a59cdb
commit
06267645f6
8 changed files with 604 additions and 697 deletions
|
@ -1,6 +1,7 @@
|
|||
package goglimpl
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/go-gl/gl/v3.2-core/gl"
|
||||
|
@ -14,15 +15,6 @@ var _ canvas.GL = GLImpl{}
|
|||
func (_ GLImpl) Ptr(data interface{}) unsafe.Pointer {
|
||||
return gl.Ptr(data)
|
||||
}
|
||||
func (_ GLImpl) PtrOffset(offset int) unsafe.Pointer {
|
||||
return gl.PtrOffset(offset)
|
||||
}
|
||||
func (_ GLImpl) Str(str string) *uint8 {
|
||||
return gl.Str(str)
|
||||
}
|
||||
func (_ GLImpl) Strs(strs ...string) (cstrs **uint8, free func()) {
|
||||
return gl.Strs(strs...)
|
||||
}
|
||||
func (_ GLImpl) ActiveTexture(texture uint32) {
|
||||
gl.ActiveTexture(texture)
|
||||
}
|
||||
|
@ -83,26 +75,30 @@ func (_ GLImpl) GenTextures(n int32, textures *uint32) {
|
|||
func (_ GLImpl) GenerateMipmap(target uint32) {
|
||||
gl.GenerateMipmap(target)
|
||||
}
|
||||
func (_ GLImpl) GetAttribLocation(program uint32, name *uint8) int32 {
|
||||
return gl.GetAttribLocation(program, name)
|
||||
func (_ GLImpl) GetAttribLocation(program uint32, name string) int32 {
|
||||
return gl.GetAttribLocation(program, gl.Str(name+"\x00"))
|
||||
}
|
||||
func (_ GLImpl) GetError() uint32 {
|
||||
return gl.GetError()
|
||||
}
|
||||
func (_ GLImpl) GetProgramInfoLog(program uint32, bufSize int32, length *int32, infoLog *uint8) {
|
||||
gl.GetProgramInfoLog(program, bufSize, length, infoLog)
|
||||
func (_ GLImpl) GetProgramInfoLog(program uint32, bufSize int32) string {
|
||||
log := strings.Repeat("\x00", int(bufSize+1))
|
||||
gl.GetProgramInfoLog(program, bufSize, nil, gl.Str(log))
|
||||
return log
|
||||
}
|
||||
func (_ GLImpl) GetProgramiv(program uint32, pname uint32, params *int32) {
|
||||
gl.GetProgramiv(program, pname, params)
|
||||
}
|
||||
func (_ GLImpl) GetShaderInfoLog(shader uint32, bufSize int32, length *int32, infoLog *uint8) {
|
||||
gl.GetShaderInfoLog(shader, bufSize, length, infoLog)
|
||||
func (_ GLImpl) GetShaderInfoLog(program uint32, bufSize int32) string {
|
||||
log := strings.Repeat("\x00", int(bufSize+1))
|
||||
gl.GetShaderInfoLog(program, bufSize, nil, gl.Str(log))
|
||||
return log
|
||||
}
|
||||
func (_ GLImpl) GetShaderiv(shader uint32, pname uint32, params *int32) {
|
||||
gl.GetShaderiv(shader, pname, params)
|
||||
}
|
||||
func (_ GLImpl) GetUniformLocation(program uint32, name *uint8) int32 {
|
||||
return gl.GetUniformLocation(program, name)
|
||||
func (_ GLImpl) GetUniformLocation(program uint32, name string) int32 {
|
||||
return gl.GetUniformLocation(program, gl.Str(name+"\x00"))
|
||||
}
|
||||
func (_ GLImpl) LinkProgram(program uint32) {
|
||||
gl.LinkProgram(program)
|
||||
|
@ -113,8 +109,10 @@ func (_ GLImpl) ReadPixels(x int32, y int32, width int32, height int32, format u
|
|||
func (_ GLImpl) Scissor(x int32, y int32, width int32, height int32) {
|
||||
gl.Scissor(x, y, width, height)
|
||||
}
|
||||
func (_ GLImpl) ShaderSource(shader uint32, count int32, xstring **uint8, length *int32) {
|
||||
gl.ShaderSource(shader, count, xstring, length)
|
||||
func (_ GLImpl) ShaderSource(shader uint32, source string) {
|
||||
csource, freeFunc := gl.Strs(source + "\x00")
|
||||
gl.ShaderSource(shader, 1, csource, nil)
|
||||
freeFunc()
|
||||
}
|
||||
func (_ GLImpl) StencilFunc(xfunc uint32, ref int32, mask uint32) {
|
||||
gl.StencilFunc(xfunc, ref, mask)
|
||||
|
@ -155,8 +153,8 @@ func (_ GLImpl) UniformMatrix3fv(location int32, count int32, transpose bool, va
|
|||
func (_ GLImpl) UseProgram(program uint32) {
|
||||
gl.UseProgram(program)
|
||||
}
|
||||
func (_ GLImpl) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, pointer unsafe.Pointer) {
|
||||
gl.VertexAttribPointer(index, size, xtype, normalized, stride, pointer)
|
||||
func (_ GLImpl) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset uint32) {
|
||||
gl.VertexAttribPointer(index, size, xtype, normalized, stride, gl.PtrOffset(int(offset)))
|
||||
}
|
||||
func (_ GLImpl) Viewport(x int32, y int32, width int32, height int32) {
|
||||
gl.Viewport(x, y, width, height)
|
||||
|
|
|
@ -86,8 +86,8 @@ func (cv *Canvas) PutImageData(img *image.RGBA, x, y int) {
|
|||
gli.Uniform1i(ir.image, 0)
|
||||
gli.Uniform2f(ir.canvasSize, float32(cv.fw), float32(cv.fh))
|
||||
gli.Uniform1f(ir.globalAlpha, 1)
|
||||
gli.VertexAttribPointer(ir.vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(ir.texCoord, 2, gl_FLOAT, false, 0, gli.PtrOffset(8*4))
|
||||
gli.VertexAttribPointer(ir.vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.VertexAttribPointer(ir.texCoord, 2, gl_FLOAT, false, 0, 8*4)
|
||||
gli.EnableVertexAttribArray(ir.vertex)
|
||||
gli.EnableVertexAttribArray(ir.texCoord)
|
||||
gli.DrawArrays(gl_TRIANGLE_FAN, 0, 4)
|
||||
|
|
|
@ -263,8 +263,8 @@ func (cv *Canvas) DrawImage(image interface{}, coords ...float64) {
|
|||
gli.Uniform1i(ir.image, 0)
|
||||
gli.Uniform2f(ir.canvasSize, float32(cv.fw), float32(cv.fh))
|
||||
gli.Uniform1f(ir.globalAlpha, float32(cv.state.globalAlpha))
|
||||
gli.VertexAttribPointer(ir.vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(ir.texCoord, 2, gl_FLOAT, false, 0, gli.PtrOffset(8*4))
|
||||
gli.VertexAttribPointer(ir.vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.VertexAttribPointer(ir.texCoord, 2, gl_FLOAT, false, 0, 8*4)
|
||||
gli.EnableVertexAttribArray(ir.vertex)
|
||||
gli.EnableVertexAttribArray(ir.texCoord)
|
||||
gli.DrawArrays(gl_TRIANGLE_FAN, 0, 4)
|
||||
|
|
1206
made_shaders.go
1206
made_shaders.go
File diff suppressed because it is too large
Load diff
|
@ -200,18 +200,14 @@ func shaderGetTopLevelLines(source string) []string {
|
|||
|
||||
const compilePart = `
|
||||
{
|
||||
csource, freeFunc := gli.Strs(SHADER_SRC + "\x00")
|
||||
defer freeFunc()
|
||||
|
||||
SHADER_VAR = gli.CreateShader(gl_SHADER_TYPE)
|
||||
gli.ShaderSource(SHADER_VAR, 1, csource, nil)
|
||||
gli.ShaderSource(SHADER_VAR, SHADER_SRC)
|
||||
gli.CompileShader(SHADER_VAR)
|
||||
|
||||
var logLength int32
|
||||
gli.GetShaderiv(SHADER_VAR, gl_INFO_LOG_LENGTH, &logLength)
|
||||
if logLength > 0 {
|
||||
shLog := strings.Repeat("\x00", int(logLength+1))
|
||||
gli.GetShaderInfoLog(SHADER_VAR, logLength, nil, gli.Str(shLog))
|
||||
shLog := gli.GetShaderInfoLog(SHADER_VAR, logLength)
|
||||
fmt.Printf("SHADER_TYPE compilation log for SHADER_SRC:\n\n%s\n", shLog)
|
||||
}
|
||||
|
||||
|
@ -236,8 +232,7 @@ const linkPart = `
|
|||
var logLength int32
|
||||
gli.GetProgramiv(program, gl_INFO_LOG_LENGTH, &logLength)
|
||||
if logLength > 0 {
|
||||
shLog := strings.Repeat("\x00", int(logLength+1))
|
||||
gli.GetProgramInfoLog(program, logLength, nil, gli.Str(shLog))
|
||||
shLog := gli.GetProgramInfoLog(program, logLength)
|
||||
fmt.Printf("Shader link log for SHADER_SRC:\n\n%s\n", shLog)
|
||||
}
|
||||
|
||||
|
@ -263,7 +258,6 @@ func buildCodeHeader(buf *bytes.Buffer) {
|
|||
fmt.Fprint(buf, "import (\n")
|
||||
fmt.Fprint(buf, "\t\"errors\"\n")
|
||||
fmt.Fprint(buf, "\t\"fmt\"\n")
|
||||
fmt.Fprint(buf, "\t\"strings\"\n")
|
||||
fmt.Fprint(buf, ")\n\n")
|
||||
}
|
||||
|
||||
|
@ -306,9 +300,9 @@ func buildCode(buf *bytes.Buffer, baseName string, inputs []ShaderInput) {
|
|||
|
||||
for _, input := range inputs {
|
||||
if input.IsAttrib {
|
||||
fmt.Fprintf(buf, "\tresult.%s = uint32(gli.GetAttribLocation(program, gli.Str(\"%s\\x00\")))\n", input.Name, input.Name)
|
||||
fmt.Fprintf(buf, "\tresult.%s = uint32(gli.GetAttribLocation(program, \"%s\"))\n", input.Name, input.Name)
|
||||
} else if input.IsUniform {
|
||||
fmt.Fprintf(buf, "\tresult.%s = gli.GetUniformLocation(program, gli.Str(\"%s\\x00\"))\n", input.Name, input.Name)
|
||||
fmt.Fprintf(buf, "\tresult.%s = gli.GetUniformLocation(program, \"%s\")\n", input.Name, input.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -794,9 +794,6 @@ const (
|
|||
// this interface based on Go-GL v3.2
|
||||
type GL interface {
|
||||
Ptr(data interface{}) unsafe.Pointer
|
||||
PtrOffset(offset int) unsafe.Pointer
|
||||
Str(str string) *uint8
|
||||
Strs(strs ...string) (cstrs **uint8, free func())
|
||||
ActiveTexture(texture uint32)
|
||||
AttachShader(program uint32, shader uint32)
|
||||
BindBuffer(target uint32, buffer uint32)
|
||||
|
@ -817,17 +814,17 @@ type GL interface {
|
|||
GenBuffers(n int32, buffers *uint32)
|
||||
GenTextures(n int32, textures *uint32)
|
||||
GenerateMipmap(target uint32)
|
||||
GetAttribLocation(program uint32, name *uint8) int32
|
||||
GetAttribLocation(program uint32, name string) int32
|
||||
GetError() uint32
|
||||
GetProgramInfoLog(program uint32, bufSize int32, length *int32, infoLog *uint8)
|
||||
GetProgramInfoLog(program uint32, bufSize int32) string
|
||||
GetProgramiv(program uint32, pname uint32, params *int32)
|
||||
GetShaderInfoLog(shader uint32, bufSize int32, length *int32, infoLog *uint8)
|
||||
GetShaderInfoLog(shader uint32, bufSize int32) string
|
||||
GetShaderiv(shader uint32, pname uint32, params *int32)
|
||||
GetUniformLocation(program uint32, name *uint8) int32
|
||||
GetUniformLocation(program uint32, name string) int32
|
||||
LinkProgram(program uint32)
|
||||
ReadPixels(x int32, y int32, width int32, height int32, format uint32, xtype uint32, pixels unsafe.Pointer)
|
||||
Scissor(x int32, y int32, width int32, height int32)
|
||||
ShaderSource(shader uint32, count int32, xstring **uint8, length *int32)
|
||||
ShaderSource(shader uint32, source string)
|
||||
StencilFunc(xfunc uint32, ref int32, mask uint32)
|
||||
StencilMask(mask uint32)
|
||||
StencilOp(fail uint32, zfail uint32, zpass uint32)
|
||||
|
@ -841,6 +838,6 @@ type GL interface {
|
|||
Uniform4f(location int32, v0 float32, v1 float32, v2 float32, v3 float32)
|
||||
UniformMatrix3fv(location int32, count int32, transpose bool, value *float32)
|
||||
UseProgram(program uint32)
|
||||
VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, pointer unsafe.Pointer)
|
||||
VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset uint32)
|
||||
Viewport(x int32, y int32, width int32, height int32)
|
||||
}
|
||||
|
|
12
paths.go
12
paths.go
|
@ -370,7 +370,7 @@ func (cv *Canvas) stroke(path []pathPoint) {
|
|||
gli.Uniform2f(sr.canvasSize, float32(cv.fw), float32(cv.fh))
|
||||
|
||||
gli.EnableVertexAttribArray(sr.vertex)
|
||||
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.DrawArrays(gl_TRIANGLES, 6, int32(len(tris)/2-6))
|
||||
gli.DisableVertexAttribArray(sr.vertex)
|
||||
|
||||
|
@ -380,7 +380,7 @@ func (cv *Canvas) stroke(path []pathPoint) {
|
|||
|
||||
vertex := cv.useShader(&cv.state.stroke)
|
||||
gli.EnableVertexAttribArray(vertex)
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.DrawArrays(gl_TRIANGLES, 0, 6)
|
||||
gli.DisableVertexAttribArray(vertex)
|
||||
|
||||
|
@ -517,7 +517,7 @@ func (cv *Canvas) Fill() {
|
|||
gli.Uniform2f(sr.canvasSize, float32(cv.fw), float32(cv.fh))
|
||||
|
||||
gli.EnableVertexAttribArray(sr.vertex)
|
||||
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.DrawArrays(gl_TRIANGLES, 6, int32(len(tris)/2-6))
|
||||
gli.DisableVertexAttribArray(sr.vertex)
|
||||
|
||||
|
@ -527,7 +527,7 @@ func (cv *Canvas) Fill() {
|
|||
|
||||
vertex := cv.useShader(&cv.state.fill)
|
||||
gli.EnableVertexAttribArray(vertex)
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.DrawArrays(gl_TRIANGLES, 0, 6)
|
||||
gli.DisableVertexAttribArray(vertex)
|
||||
|
||||
|
@ -594,7 +594,7 @@ func (cv *Canvas) clip(path []pathPoint) {
|
|||
|
||||
gli.BindBuffer(gl_ARRAY_BUFFER, buf)
|
||||
gli.BufferData(gl_ARRAY_BUFFER, len(tris)*4, unsafe.Pointer(&tris[0]), gl_STREAM_DRAW)
|
||||
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
|
||||
gli.UseProgram(sr.id)
|
||||
gli.Uniform4f(sr.color, 1, 1, 1, 1)
|
||||
|
@ -701,7 +701,7 @@ func (cv *Canvas) FillRect(x, y, w, h float64) {
|
|||
gli.StencilFunc(gl_EQUAL, 0, 0xFF)
|
||||
|
||||
vertex := cv.useShader(&cv.state.fill)
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.EnableVertexAttribArray(vertex)
|
||||
gli.DrawArrays(gl_TRIANGLE_FAN, 0, 4)
|
||||
gli.DisableVertexAttribArray(vertex)
|
||||
|
|
4
text.go
4
text.go
|
@ -215,8 +215,8 @@ func (cv *Canvas) FillText(str string, x, y float64) {
|
|||
0, 1, 0, float32(1 - th), float32(tw), float32(1 - th), float32(tw), 1}
|
||||
gli.BufferData(gl_ARRAY_BUFFER, len(data)*4, unsafe.Pointer(&data[0]), gl_STREAM_DRAW)
|
||||
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, nil)
|
||||
gli.VertexAttribPointer(alphaTexCoord, 2, gl_FLOAT, false, 0, gli.PtrOffset(8*4))
|
||||
gli.VertexAttribPointer(vertex, 2, gl_FLOAT, false, 0, 0)
|
||||
gli.VertexAttribPointer(alphaTexCoord, 2, gl_FLOAT, false, 0, 8*4)
|
||||
gli.DrawArrays(gl_TRIANGLE_FAN, 0, 4)
|
||||
|
||||
for y := 0; y < strHeight; y++ {
|
||||
|
|
Loading…
Reference in a new issue