Adding modding folder with a hacked build.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package opengl
|
||||
|
||||
// CompileNewShader creates a shader of given type and compiles the provided source.
|
||||
func CompileNewShader(gl OpenGL, shaderType uint32, source string) (shader uint32, err error) {
|
||||
shader = gl.CreateShader(shaderType)
|
||||
|
||||
gl.ShaderSource(shader, source)
|
||||
gl.CompileShader(shader)
|
||||
|
||||
compileStatus := gl.GetShaderParameter(shader, COMPILE_STATUS)
|
||||
if compileStatus == 0 {
|
||||
err = ShaderError{Log: gl.GetShaderInfoLog(shader)}
|
||||
gl.DeleteShader(shader)
|
||||
shader = 0
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package opengl
|
||||
|
||||
// DebuggingEntryFunc is a function to be called on function entry.
|
||||
type DebuggingEntryFunc func(name string, param ...interface{})
|
||||
|
||||
// DebuggingExitFunc is a function to be called after an OpenGL function has returned.
|
||||
// result may be several parameters for functions with multiple return values.
|
||||
type DebuggingExitFunc func(name string, result ...interface{})
|
||||
|
||||
// DebuggingErrorFunc is a function which is called if a previous OpenGL call caused an error state.
|
||||
type DebuggingErrorFunc func(name string, errorCodes []uint32)
|
||||
|
||||
// DebugBuilder is a builder for an OpenGL implementation for debugging.
|
||||
type DebugBuilder struct {
|
||||
wrapped OpenGL
|
||||
|
||||
onEntry DebuggingEntryFunc
|
||||
onExit DebuggingExitFunc
|
||||
onError DebuggingErrorFunc
|
||||
}
|
||||
|
||||
// NewDebugBuilder wraps the provided OpenGL instance and returns a new builder
|
||||
// instance.
|
||||
func NewDebugBuilder(wrapped OpenGL) *DebugBuilder {
|
||||
builder := &DebugBuilder{
|
||||
wrapped: wrapped,
|
||||
onEntry: func(string, ...interface{}) {},
|
||||
onExit: func(string, ...interface{}) {},
|
||||
onError: func(string, []uint32) {}}
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
// Build creates a new instance of the debugging OpenGL implementation.
|
||||
// The builder can be reused to create another instance with different parameters.
|
||||
func (builder *DebugBuilder) Build() OpenGL {
|
||||
opengl := &debuggingOpenGL{
|
||||
gl: builder.wrapped,
|
||||
|
||||
onEntry: builder.onEntry,
|
||||
onExit: builder.onExit,
|
||||
onError: builder.onError}
|
||||
|
||||
return opengl
|
||||
}
|
||||
|
||||
// OnEntry registers a callback function to be called before an OpenGL function is called.
|
||||
func (builder *DebugBuilder) OnEntry(callback DebuggingEntryFunc) *DebugBuilder {
|
||||
builder.onEntry = callback
|
||||
return builder
|
||||
}
|
||||
|
||||
// OnExit registers a callback function to be called after an OpenGL function returned.
|
||||
func (builder *DebugBuilder) OnExit(callback DebuggingExitFunc) *DebugBuilder {
|
||||
builder.onExit = callback
|
||||
return builder
|
||||
}
|
||||
|
||||
// OnError registers a callback function to be called when an OpenGL function set an error state.
|
||||
func (builder *DebugBuilder) OnError(callback DebuggingErrorFunc) *DebugBuilder {
|
||||
builder.onError = callback
|
||||
return builder
|
||||
}
|
||||
@@ -0,0 +1,490 @@
|
||||
package opengl
|
||||
|
||||
type debuggingOpenGL struct {
|
||||
gl OpenGL
|
||||
|
||||
onEntry DebuggingEntryFunc
|
||||
onExit DebuggingExitFunc
|
||||
onError DebuggingErrorFunc
|
||||
}
|
||||
|
||||
func (debugging *debuggingOpenGL) recordEntry(name string, param ...interface{}) {
|
||||
debugging.onEntry(name, param...)
|
||||
}
|
||||
|
||||
func (debugging *debuggingOpenGL) recordExit(name string, result ...interface{}) {
|
||||
var errorCodes []uint32
|
||||
|
||||
for errorCode := debugging.gl.GetError(); errorCode != NO_ERROR; errorCode = debugging.gl.GetError() {
|
||||
errorCodes = append(errorCodes, errorCode)
|
||||
}
|
||||
debugging.onExit(name, result...)
|
||||
if len(errorCodes) > 0 {
|
||||
debugging.onError(name, errorCodes)
|
||||
}
|
||||
}
|
||||
|
||||
// ActiveTexture implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) ActiveTexture(texture uint32) {
|
||||
debugging.recordEntry("ActiveTexture", texture)
|
||||
debugging.gl.ActiveTexture(texture)
|
||||
debugging.recordExit("ActiveTexture")
|
||||
}
|
||||
|
||||
// AttachShader implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) AttachShader(program uint32, shader uint32) {
|
||||
debugging.recordEntry("AttachShader", program, shader)
|
||||
debugging.gl.AttachShader(program, shader)
|
||||
debugging.recordExit("AttachShader")
|
||||
}
|
||||
|
||||
// BindAttribLocation implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindAttribLocation(program uint32, index uint32, name string) {
|
||||
debugging.recordEntry("BindAttribLocation", program, index, name)
|
||||
debugging.gl.BindAttribLocation(program, index, name)
|
||||
debugging.recordExit("BindAttribLocation")
|
||||
}
|
||||
|
||||
// BindBuffer implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindBuffer(target uint32, buffer uint32) {
|
||||
debugging.recordEntry("BindBuffer", target, buffer)
|
||||
debugging.gl.BindBuffer(target, buffer)
|
||||
debugging.recordExit("BindBuffer")
|
||||
}
|
||||
|
||||
// BindFramebuffer implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindFramebuffer(target uint32, buffer uint32) {
|
||||
debugging.recordEntry("BindFramebuffer", target, buffer)
|
||||
debugging.gl.BindFramebuffer(target, buffer)
|
||||
debugging.recordExit("BindFramebuffer")
|
||||
}
|
||||
|
||||
// BindRenderbuffer implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindRenderbuffer(target uint32, buffer uint32) {
|
||||
debugging.recordEntry("BindRenderbuffer", target, buffer)
|
||||
debugging.gl.BindRenderbuffer(target, buffer)
|
||||
debugging.recordExit("BindRenderbuffer")
|
||||
}
|
||||
|
||||
// BindSampler implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindSampler(unit uint32, sampler uint32) {
|
||||
debugging.recordEntry("BindSampler", unit, sampler)
|
||||
debugging.gl.BindSampler(unit, sampler)
|
||||
debugging.recordExit("BindSampler")
|
||||
}
|
||||
|
||||
// BindTexture implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindTexture(target uint32, texture uint32) {
|
||||
debugging.recordEntry("BindTexture", target, texture)
|
||||
debugging.gl.BindTexture(target, texture)
|
||||
debugging.recordExit("BindTexture")
|
||||
}
|
||||
|
||||
// BindVertexArray implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BindVertexArray(array uint32) {
|
||||
debugging.recordEntry("BindVertexArray", array)
|
||||
debugging.gl.BindVertexArray(array)
|
||||
debugging.recordExit("BindVertexArray")
|
||||
}
|
||||
|
||||
// BlendEquation implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BlendEquation(mode uint32) {
|
||||
debugging.recordEntry("BlendEquation", mode)
|
||||
debugging.gl.BlendEquation(mode)
|
||||
debugging.recordExit("BlendEquation")
|
||||
}
|
||||
|
||||
// BlendEquationSeparate implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
|
||||
debugging.recordEntry("BlendEquationSeparate", modeRGB, modeAlpha)
|
||||
debugging.gl.BlendEquationSeparate(modeRGB, modeAlpha)
|
||||
debugging.recordExit("BlendEquationSeparate")
|
||||
}
|
||||
|
||||
// BlendFunc implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BlendFunc(sfactor uint32, dfactor uint32) {
|
||||
debugging.recordEntry("BlendFunc", sfactor, dfactor)
|
||||
debugging.gl.BlendFunc(sfactor, dfactor)
|
||||
debugging.recordExit("BlendFunc")
|
||||
}
|
||||
|
||||
// BlendFuncSeparate implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
|
||||
debugging.recordEntry("BlendFuncSeparate", srcRGB, dstRGB, srcAlpha, dstAlpha)
|
||||
debugging.gl.BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha)
|
||||
debugging.recordExit("BlendFuncSeparate")
|
||||
}
|
||||
|
||||
// BufferData implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) BufferData(target uint32, size int, data interface{}, usage uint32) {
|
||||
debugging.recordEntry("BufferData", target, size, data, usage)
|
||||
debugging.gl.BufferData(target, size, data, usage)
|
||||
debugging.recordExit("BufferData")
|
||||
}
|
||||
|
||||
// CheckFramebufferStatus implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) CheckFramebufferStatus(target uint32) uint32 {
|
||||
debugging.recordEntry("CheckFramebufferStatus", target)
|
||||
result := debugging.gl.CheckFramebufferStatus(target)
|
||||
debugging.recordExit("CheckFramebufferStatus")
|
||||
return result
|
||||
}
|
||||
|
||||
// Clear implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Clear(mask uint32) {
|
||||
debugging.recordEntry("Clear", mask)
|
||||
debugging.gl.Clear(mask)
|
||||
debugging.recordExit("Clear")
|
||||
}
|
||||
|
||||
// ClearColor implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) ClearColor(red float32, green float32, blue float32, alpha float32) {
|
||||
debugging.recordEntry("ClearColor", red, green, blue, alpha)
|
||||
debugging.gl.ClearColor(red, green, blue, alpha)
|
||||
debugging.recordExit("ClearColor")
|
||||
}
|
||||
|
||||
// CompileShader implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) CompileShader(shader uint32) {
|
||||
debugging.recordEntry("CompileShader", shader)
|
||||
debugging.gl.CompileShader(shader)
|
||||
debugging.recordExit("CompileShader")
|
||||
}
|
||||
|
||||
// CreateProgram implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) CreateProgram() uint32 {
|
||||
debugging.recordEntry("CreateProgram")
|
||||
result := debugging.gl.CreateProgram()
|
||||
debugging.recordExit("CreateProgram", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// CreateShader implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) CreateShader(shaderType uint32) uint32 {
|
||||
debugging.recordEntry("CreateShader", shaderType)
|
||||
result := debugging.gl.CreateShader(shaderType)
|
||||
debugging.recordExit("CreateShader", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// DeleteBuffers implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DeleteBuffers(buffers []uint32) {
|
||||
debugging.recordEntry("DeleteBuffers", buffers)
|
||||
debugging.gl.DeleteBuffers(buffers)
|
||||
debugging.recordExit("DeleteBuffers")
|
||||
}
|
||||
|
||||
// DeleteFramebuffers implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DeleteFramebuffers(buffers []uint32) {
|
||||
debugging.recordEntry("DeleteFramebuffers", buffers)
|
||||
debugging.gl.DeleteFramebuffers(buffers)
|
||||
debugging.recordExit("DeleteFramebuffers")
|
||||
}
|
||||
|
||||
// DeleteProgram implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DeleteProgram(program uint32) {
|
||||
debugging.recordEntry("DeleteProgram", program)
|
||||
debugging.gl.DeleteProgram(program)
|
||||
debugging.recordExit("DeleteProgram")
|
||||
}
|
||||
|
||||
// DeleteShader implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DeleteShader(shader uint32) {
|
||||
debugging.recordEntry("DeleteShader", shader)
|
||||
debugging.gl.DeleteShader(shader)
|
||||
debugging.recordExit("DeleteShader")
|
||||
}
|
||||
|
||||
// DeleteTextures implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DeleteTextures(textures []uint32) {
|
||||
debugging.recordEntry("DeleteTextures", textures)
|
||||
debugging.gl.DeleteTextures(textures)
|
||||
debugging.recordExit("DeleteTextures")
|
||||
}
|
||||
|
||||
// DeleteVertexArrays implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DeleteVertexArrays(arrays []uint32) {
|
||||
debugging.recordEntry("DeleteVertexArrays", arrays)
|
||||
debugging.gl.DeleteVertexArrays(arrays)
|
||||
debugging.recordExit("DeleteVertexArrays")
|
||||
}
|
||||
|
||||
// Disable implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Disable(capability uint32) {
|
||||
debugging.recordEntry("Disable", capability)
|
||||
debugging.gl.Disable(capability)
|
||||
debugging.recordExit("Disable")
|
||||
}
|
||||
|
||||
// DrawArrays implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DrawArrays(mode uint32, first int32, count int32) {
|
||||
debugging.recordEntry("DrawArrays", first, count)
|
||||
debugging.gl.DrawArrays(mode, first, count)
|
||||
debugging.recordExit("DrawArrays")
|
||||
}
|
||||
|
||||
// DrawBuffers implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DrawBuffers(buffers []uint32) {
|
||||
debugging.recordEntry("DrawBuffers", buffers)
|
||||
debugging.gl.DrawBuffers(buffers)
|
||||
debugging.recordExit("DrawBuffers")
|
||||
}
|
||||
|
||||
// DrawElements implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) DrawElements(mode uint32, count int32, elementType uint32, indices uintptr) {
|
||||
debugging.recordEntry("DrawElements", mode, count, elementType, indices)
|
||||
debugging.gl.DrawElements(mode, count, elementType, indices)
|
||||
debugging.recordExit("DrawElements")
|
||||
}
|
||||
|
||||
// Enable implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Enable(capability uint32) {
|
||||
debugging.recordEntry("Enable", capability)
|
||||
debugging.gl.Enable(capability)
|
||||
debugging.recordExit("Enable")
|
||||
}
|
||||
|
||||
// EnableVertexAttribArray implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) EnableVertexAttribArray(index uint32) {
|
||||
debugging.recordEntry("EnableVertexAttribArray", index)
|
||||
debugging.gl.EnableVertexAttribArray(index)
|
||||
debugging.recordExit("EnableVertexAttribArray")
|
||||
}
|
||||
|
||||
// FramebufferRenderbuffer implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
|
||||
debugging.recordEntry("FramebufferRenderbuffer", target, attachment, renderbuffertarget, renderbuffer)
|
||||
debugging.gl.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer)
|
||||
debugging.recordExit("FramebufferRenderbuffer")
|
||||
}
|
||||
|
||||
// FramebufferTexture implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) FramebufferTexture(target uint32, attachment uint32, texture uint32, level int32) {
|
||||
debugging.recordEntry("FramebufferTexture", target, attachment, texture, level)
|
||||
debugging.gl.FramebufferTexture(target, attachment, texture, level)
|
||||
debugging.recordExit("FramebufferTexture")
|
||||
}
|
||||
|
||||
// GenerateMipmap implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GenerateMipmap(target uint32) {
|
||||
debugging.recordEntry("GenerateMipmap", target)
|
||||
debugging.gl.GenerateMipmap(target)
|
||||
debugging.recordExit("GenerateMipmap")
|
||||
}
|
||||
|
||||
// GenBuffers implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GenBuffers(n int32) []uint32 {
|
||||
debugging.recordEntry("GenBuffers", n)
|
||||
result := debugging.gl.GenBuffers(n)
|
||||
debugging.recordExit("GenBuffers", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GenFramebuffers implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GenFramebuffers(n int32) []uint32 {
|
||||
debugging.recordEntry("GenFramebuffers", n)
|
||||
result := debugging.gl.GenFramebuffers(n)
|
||||
debugging.recordExit("GenFramebuffers", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GenRenderbuffers implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GenRenderbuffers(n int32) []uint32 {
|
||||
debugging.recordEntry("GenRenderbuffers", n)
|
||||
result := debugging.gl.GenRenderbuffers(n)
|
||||
debugging.recordExit("GenRenderbuffers", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GenTextures implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GenTextures(n int32) []uint32 {
|
||||
debugging.recordEntry("GenTextures", n)
|
||||
result := debugging.gl.GenTextures(n)
|
||||
debugging.recordExit("GenTextures", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GenVertexArrays implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GenVertexArrays(n int32) []uint32 {
|
||||
debugging.recordEntry("GenVertexArrays", n)
|
||||
result := debugging.gl.GenVertexArrays(n)
|
||||
debugging.recordExit("GenVertexArrays", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetAttribLocation implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetAttribLocation(program uint32, name string) int32 {
|
||||
debugging.recordEntry("GetAttribLocation", program, name)
|
||||
result := debugging.gl.GetAttribLocation(program, name)
|
||||
debugging.recordExit("GetAttribLocation", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetError implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetError() uint32 {
|
||||
debugging.recordEntry("GetError")
|
||||
result := debugging.gl.GetError()
|
||||
debugging.recordExit("GetError", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetIntegerv implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetIntegerv(name uint32, data *int32) {
|
||||
debugging.recordEntry("GetIntegerv", name, data)
|
||||
debugging.gl.GetIntegerv(name, data)
|
||||
debugging.recordExit("GetIntegerv")
|
||||
}
|
||||
|
||||
// GetProgramInfoLog implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetProgramInfoLog(program uint32) string {
|
||||
debugging.recordEntry("GetProgramInfoLog", program)
|
||||
result := debugging.gl.GetProgramInfoLog(program)
|
||||
debugging.recordExit("GetProgramInfoLog", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetProgramParameter implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetProgramParameter(program uint32, param uint32) int32 {
|
||||
debugging.recordEntry("GetProgramParameter", program, param)
|
||||
result := debugging.gl.GetProgramParameter(program, param)
|
||||
debugging.recordExit("GetProgramParameter", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetShaderInfoLog implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetShaderInfoLog(shader uint32) string {
|
||||
debugging.recordEntry("GetShaderInfoLog", shader)
|
||||
result := debugging.gl.GetShaderInfoLog(shader)
|
||||
debugging.recordExit("GetShaderInfoLog", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetShaderParameter implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetShaderParameter(shader uint32, param uint32) int32 {
|
||||
debugging.recordEntry("GetShaderParameter", shader, param)
|
||||
result := debugging.gl.GetShaderParameter(shader, param)
|
||||
debugging.recordExit("GetShaderParameter", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetUniformLocation implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) GetUniformLocation(program uint32, name string) int32 {
|
||||
debugging.recordEntry("GetUniformLocation", program, name)
|
||||
result := debugging.gl.GetUniformLocation(program, name)
|
||||
debugging.recordExit("GetUniformLocation", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// IsEnabled implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) IsEnabled(capability uint32) bool {
|
||||
debugging.recordEntry("IsEnabled", capability)
|
||||
result := debugging.gl.IsEnabled(capability)
|
||||
debugging.recordExit("IsEnabled", result)
|
||||
return result
|
||||
}
|
||||
|
||||
// LinkProgram implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) LinkProgram(program uint32) {
|
||||
debugging.recordEntry("LinkProgram", program)
|
||||
debugging.gl.LinkProgram(program)
|
||||
debugging.recordExit("LinkProgram")
|
||||
}
|
||||
|
||||
// PixelStorei implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) PixelStorei(name uint32, param int32) {
|
||||
debugging.recordEntry("PixelStorei", name, param)
|
||||
debugging.gl.PixelStorei(name, param)
|
||||
debugging.recordExit("PixelStorei")
|
||||
}
|
||||
|
||||
// PolygonMode implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) PolygonMode(face uint32, mode uint32) {
|
||||
debugging.recordEntry("PolygonMode", face, mode)
|
||||
debugging.gl.PolygonMode(face, mode)
|
||||
debugging.recordExit("PolygonMode")
|
||||
}
|
||||
|
||||
// ReadPixels implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) ReadPixels(x int32, y int32, width int32, height int32, format uint32, pixelType uint32, pixels interface{}) {
|
||||
debugging.recordEntry("ReadPixels", x, y, width, height, format, pixelType, pixels)
|
||||
debugging.gl.ReadPixels(x, y, width, height, format, pixelType, pixels)
|
||||
debugging.recordExit("ReadPixels")
|
||||
}
|
||||
|
||||
// RenderbufferStorage implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32) {
|
||||
debugging.recordEntry("RenderbufferStorage", target, internalFormat, width, height)
|
||||
debugging.gl.RenderbufferStorage(target, internalFormat, width, height)
|
||||
debugging.recordExit("RenderbufferStorage")
|
||||
}
|
||||
|
||||
// Scissor implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Scissor(x, y int32, width, height int32) {
|
||||
debugging.recordEntry("Scissor", x, y, width, height)
|
||||
debugging.gl.Scissor(x, y, width, height)
|
||||
debugging.recordExit("Scissor")
|
||||
}
|
||||
|
||||
// ShaderSource implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) ShaderSource(shader uint32, source string) {
|
||||
debugging.recordEntry("ShaderSource", shader, source)
|
||||
debugging.gl.ShaderSource(shader, source)
|
||||
debugging.recordExit("ShaderSource")
|
||||
}
|
||||
|
||||
// TexImage2D implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) TexImage2D(target uint32, level int32, internalFormat uint32, width int32, height int32,
|
||||
border int32, format uint32, xtype uint32, pixels interface{}) {
|
||||
debugging.recordEntry("TexImage2D", target, level, internalFormat, width, height, border, format, xtype, pixels)
|
||||
debugging.gl.TexImage2D(target, level, internalFormat, width, height, border, format, xtype, pixels)
|
||||
debugging.recordExit("TexImage2D")
|
||||
}
|
||||
|
||||
// TexParameteri implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) TexParameteri(target uint32, pname uint32, param int32) {
|
||||
debugging.recordEntry("TexParameteri", target, pname, param)
|
||||
debugging.gl.TexParameteri(target, pname, param)
|
||||
debugging.recordExit("TexParameteri")
|
||||
}
|
||||
|
||||
// Uniform1i implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Uniform1i(location int32, value int32) {
|
||||
debugging.recordEntry("Uniform1i", location, value)
|
||||
debugging.gl.Uniform1i(location, value)
|
||||
debugging.recordExit("Uniform1i")
|
||||
}
|
||||
|
||||
// Uniform4fv implements the opengl.OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Uniform4fv(location int32, value *[4]float32) {
|
||||
debugging.recordEntry("Uniform4fv", location, value)
|
||||
debugging.gl.Uniform4fv(location, value)
|
||||
debugging.recordExit("Uniform4fv")
|
||||
}
|
||||
|
||||
// UniformMatrix4fv implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) UniformMatrix4fv(location int32, transpose bool, value *[16]float32) {
|
||||
debugging.recordEntry("UniformMatrix4fv", location, transpose, value)
|
||||
debugging.gl.UniformMatrix4fv(location, transpose, value)
|
||||
debugging.recordExit("UniformMatrix4fv")
|
||||
}
|
||||
|
||||
// UseProgram implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) UseProgram(program uint32) {
|
||||
debugging.recordEntry("UseProgram", program)
|
||||
debugging.gl.UseProgram(program)
|
||||
debugging.recordExit("UseProgram")
|
||||
}
|
||||
|
||||
// VertexAttribOffset implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) VertexAttribOffset(index uint32, size int32, attribType uint32, normalized bool, stride int32, offset int) {
|
||||
debugging.recordEntry("VertexAttribOffset", index, size, attribType, normalized, stride, offset)
|
||||
debugging.gl.VertexAttribOffset(index, size, attribType, normalized, stride, offset)
|
||||
debugging.recordExit("VertexAttribOffset")
|
||||
}
|
||||
|
||||
// Viewport implements the OpenGL interface.
|
||||
func (debugging *debuggingOpenGL) Viewport(x int32, y int32, width int32, height int32) {
|
||||
debugging.recordEntry("Viewport", x, y, width, height)
|
||||
debugging.gl.Viewport(x, y, width, height)
|
||||
debugging.recordExit("Viewport")
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var errorStrings = map[uint32]string{
|
||||
NO_ERROR: "NO_ERROR",
|
||||
INVALID_ENUM: "INVALID_ENUM",
|
||||
INVALID_VALUE: "INVALID_VALUE",
|
||||
INVALID_OPERATION: "INVALID_OPERATION",
|
||||
STACK_OVERFLOW: "STACK_OVERFLOW",
|
||||
STACK_UNDERFLOW: "STACK_UNDERFLOW",
|
||||
OUT_OF_MEMORY: "OUT_OF_MEMORY",
|
||||
INVALID_FRAMEBUFFER_OPERATION: "INVALID_FRAMEBUFFER_OPERATION"}
|
||||
|
||||
// ErrorString returns a readable version of the provided error code. If the
|
||||
// code is unknown, the textual representation of the hexadecimal value is
|
||||
// returned.
|
||||
func ErrorString(errorCode uint32) string {
|
||||
value, exists := errorStrings[errorCode]
|
||||
|
||||
if !exists {
|
||||
value = fmt.Sprintf("0x%04X", errorCode)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// ShaderError describes a problem with a log.
|
||||
type ShaderError struct {
|
||||
Log string
|
||||
}
|
||||
|
||||
// Error returns the log.
|
||||
func (err ShaderError) Error() string {
|
||||
return err.Log
|
||||
}
|
||||
|
||||
// NamedShaderError is an error with a name.
|
||||
type NamedShaderError struct {
|
||||
Name string
|
||||
Nested error
|
||||
}
|
||||
|
||||
// Error returns the name with the nested error information.
|
||||
func (err NamedShaderError) Error() string {
|
||||
return fmt.Sprintf("%s failed: %v", err.Name, err.Nested)
|
||||
}
|
||||
|
||||
// Unwrap returns the nested error.
|
||||
func (err NamedShaderError) Unwrap() error {
|
||||
return err.Nested
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package opengl
|
||||
|
||||
// OpenGL describes an Open GL interface usable for all environments of this
|
||||
// application.
|
||||
type OpenGL interface {
|
||||
ActiveTexture(texture uint32)
|
||||
AttachShader(program uint32, shader uint32)
|
||||
|
||||
BindAttribLocation(program uint32, index uint32, name string)
|
||||
BindBuffer(target uint32, buffer uint32)
|
||||
BindFramebuffer(target uint32, buffer uint32)
|
||||
BindRenderbuffer(target uint32, buffer uint32)
|
||||
BindSampler(unit uint32, sampler uint32)
|
||||
BindTexture(target uint32, texture uint32)
|
||||
BindVertexArray(array uint32)
|
||||
BlendEquation(mode uint32)
|
||||
BlendEquationSeparate(modeRGB uint32, modeAlpha uint32)
|
||||
BlendFunc(sfactor uint32, dfactor uint32)
|
||||
BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32)
|
||||
BufferData(target uint32, size int, data interface{}, usage uint32)
|
||||
|
||||
CheckFramebufferStatus(target uint32) uint32
|
||||
|
||||
Clear(mask uint32)
|
||||
ClearColor(red float32, green float32, blue float32, alpha float32)
|
||||
|
||||
CompileShader(shader uint32)
|
||||
|
||||
CreateProgram() uint32
|
||||
CreateShader(shaderType uint32) uint32
|
||||
|
||||
DeleteBuffers(buffers []uint32)
|
||||
DeleteFramebuffers(buffers []uint32)
|
||||
DeleteProgram(program uint32)
|
||||
DeleteShader(shader uint32)
|
||||
DeleteTextures(textures []uint32)
|
||||
DeleteVertexArrays(arrays []uint32)
|
||||
Disable(capability uint32)
|
||||
|
||||
DrawArrays(mode uint32, first int32, count int32)
|
||||
DrawBuffers(buffers []uint32)
|
||||
DrawElements(mode uint32, count int32, elementType uint32, indices uintptr)
|
||||
|
||||
Enable(capability uint32)
|
||||
EnableVertexAttribArray(index uint32)
|
||||
|
||||
FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32)
|
||||
FramebufferTexture(target uint32, attachment uint32, texture uint32, level int32)
|
||||
|
||||
GenerateMipmap(target uint32)
|
||||
GenBuffers(n int32) []uint32
|
||||
GenFramebuffers(n int32) []uint32
|
||||
GenRenderbuffers(n int32) []uint32
|
||||
GenTextures(n int32) []uint32
|
||||
GenVertexArrays(n int32) []uint32
|
||||
|
||||
GetAttribLocation(program uint32, name string) int32
|
||||
GetError() uint32
|
||||
GetIntegerv(name uint32, data *int32)
|
||||
GetShaderInfoLog(shader uint32) string
|
||||
GetShaderParameter(shader uint32, param uint32) int32
|
||||
GetProgramInfoLog(program uint32) string
|
||||
GetProgramParameter(program uint32, param uint32) int32
|
||||
GetUniformLocation(program uint32, name string) int32
|
||||
|
||||
IsEnabled(capability uint32) bool
|
||||
|
||||
LinkProgram(program uint32)
|
||||
|
||||
PixelStorei(name uint32, param int32)
|
||||
PolygonMode(face uint32, mode uint32)
|
||||
|
||||
ReadPixels(x int32, y int32, width int32, height int32, format uint32, pixelType uint32, pixels interface{})
|
||||
RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32)
|
||||
|
||||
Scissor(x, y int32, width, height int32)
|
||||
ShaderSource(shader uint32, source string)
|
||||
|
||||
TexImage2D(target uint32, level int32, internalFormat uint32, width int32, height int32,
|
||||
border int32, format uint32, xtype uint32, pixels interface{})
|
||||
TexParameteri(target uint32, pname uint32, param int32)
|
||||
|
||||
Uniform1i(location int32, value int32)
|
||||
Uniform4fv(location int32, value *[4]float32)
|
||||
UniformMatrix4fv(location int32, transpose bool, value *[16]float32)
|
||||
UseProgram(program uint32)
|
||||
|
||||
VertexAttribOffset(index uint32, size int32, attribType uint32, normalized bool, stride int32, offset int)
|
||||
Viewport(x int32, y int32, width int32, height int32)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package opengl
|
||||
|
||||
// LinkNewProgram creates a new shader program based on the provided shaders.
|
||||
func LinkNewProgram(gl OpenGL, shaders ...uint32) (program uint32, err error) {
|
||||
program = gl.CreateProgram()
|
||||
|
||||
for _, shader := range shaders {
|
||||
gl.AttachShader(program, shader)
|
||||
}
|
||||
gl.LinkProgram(program)
|
||||
|
||||
if gl.GetProgramParameter(program, LINK_STATUS) == 0 {
|
||||
err = ShaderError{Log: gl.GetProgramInfoLog(program)}
|
||||
gl.DeleteProgram(program)
|
||||
program = 0
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// LinkNewStandardProgram creates a new shader based on two shader sources.
|
||||
func LinkNewStandardProgram(gl OpenGL, vertexShaderSource, fragmentShaderSource string) (program uint32, err error) {
|
||||
vertexShader, vertexErr := CompileNewShader(gl, VERTEX_SHADER, vertexShaderSource)
|
||||
if vertexErr != nil {
|
||||
return 0, NamedShaderError{Name: "vertexShader", Nested: vertexErr}
|
||||
}
|
||||
defer gl.DeleteShader(vertexShader)
|
||||
fragmentShader, fragmentErr := CompileNewShader(gl, FRAGMENT_SHADER, fragmentShaderSource)
|
||||
if fragmentErr != nil {
|
||||
return 0, NamedShaderError{Name: "fragmentShader", Nested: fragmentErr}
|
||||
}
|
||||
defer gl.DeleteShader(fragmentShader)
|
||||
|
||||
return LinkNewProgram(gl, vertexShader, fragmentShader)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
mgl "github.com/go-gl/mathgl/mgl32"
|
||||
)
|
||||
|
||||
// UniformLocation represents a uniform parameter for a shader program.
|
||||
type UniformLocation int32
|
||||
|
||||
// Matrix4Uniform represents one uniform parameter for a 4x4 matrix.
|
||||
type Matrix4Uniform UniformLocation
|
||||
|
||||
// Set stores the provided matrix as the current uniform value.
|
||||
func (location Matrix4Uniform) Set(gl OpenGL, matrix *mgl.Mat4) {
|
||||
matrixArray := (*[16]float32)(matrix)
|
||||
gl.UniformMatrix4fv(int32(location), false, matrixArray)
|
||||
}
|
||||
|
||||
// Vector4Uniform represents one uniform parameter for a 4-dimensional vector.
|
||||
type Vector4Uniform UniformLocation
|
||||
|
||||
// Set stores the provided 4-dimensional vector as the current uniform value.
|
||||
func (location Vector4Uniform) Set(gl OpenGL, value *[4]float32) {
|
||||
gl.Uniform4fv(int32(location), value)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package opengl
|
||||
|
||||
// AttributeSetter is a callback function for a VertexArrayObject.
|
||||
type AttributeSetter func(OpenGL)
|
||||
|
||||
// VertexArrayObject registers common vertex properties which are pre-set
|
||||
// before regular rendering loops.
|
||||
// Depending on the supported level of the Open GL API, these settings are
|
||||
// either buffered (using a VAO - vertex array object), or replayed for
|
||||
// every render call.
|
||||
type VertexArrayObject struct {
|
||||
gl OpenGL
|
||||
program uint32
|
||||
handle uint32
|
||||
setter AttributeSetter
|
||||
}
|
||||
|
||||
// NewVertexArrayObject returns a new instance.
|
||||
func NewVertexArrayObject(gl OpenGL, program uint32) *VertexArrayObject {
|
||||
vao := &VertexArrayObject{
|
||||
gl: gl,
|
||||
program: program,
|
||||
handle: gl.GenVertexArrays(1)[0],
|
||||
setter: func(OpenGL) {}}
|
||||
|
||||
return vao
|
||||
}
|
||||
|
||||
// Dispose drops any associated resources.
|
||||
func (vao *VertexArrayObject) Dispose() {
|
||||
vao.gl.DeleteVertexArrays([]uint32{vao.handle})
|
||||
vao.handle = 0
|
||||
}
|
||||
|
||||
// WithSetter registers the setter function for this object.
|
||||
// Depending on the support of the OpenGL API, this setter may be called
|
||||
// once immediately, or for each render call.
|
||||
func (vao *VertexArrayObject) WithSetter(setter AttributeSetter) {
|
||||
if vao.handle != 0 {
|
||||
vao.OnShader(func() { setter(vao.gl) })
|
||||
}
|
||||
vao.setter = setter
|
||||
}
|
||||
|
||||
// OnShader executes the provided task with an activated shader program
|
||||
// and the vertex array object initialized.
|
||||
func (vao *VertexArrayObject) OnShader(task func()) {
|
||||
gl := vao.gl
|
||||
|
||||
gl.UseProgram(vao.program)
|
||||
gl.BindVertexArray(vao.handle)
|
||||
|
||||
defer func() {
|
||||
gl.BindVertexArray(0)
|
||||
gl.UseProgram(0)
|
||||
}()
|
||||
|
||||
if vao.handle == 0 {
|
||||
vao.setter(gl)
|
||||
}
|
||||
task()
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/inkyblackness/hacked/ui/input"
|
||||
)
|
||||
|
||||
// ClosingCallback is the function to handle close requests by the user.
|
||||
type ClosingCallback func()
|
||||
|
||||
// ClosedCallback is the function to clean up resources when the window is being closed.
|
||||
type ClosedCallback func()
|
||||
|
||||
// RenderCallback is the function to receive render events. When the callback
|
||||
// returns, the window will swap the internal buffer.
|
||||
type RenderCallback func()
|
||||
|
||||
// MouseMoveCallback is the function to receive the current mouse coordinate while moving.
|
||||
// Movement is reported while the cursor is within the client area of the window, and
|
||||
// beyond the window as long as at least one captured button is pressed.
|
||||
// Reported values are with sub-pixel precision, if possible.
|
||||
type MouseMoveCallback func(x float32, y float32)
|
||||
|
||||
// MouseButtonCallback is the function to receive button up/down events.
|
||||
// An Up event is sent for every reported Down event, even if the mouse cursor is outside
|
||||
// the client area.
|
||||
type MouseButtonCallback func(buttonMask uint32, modifier input.Modifier)
|
||||
|
||||
// MouseScrollCallback is the function to receive scroll events.
|
||||
// Delta values are right-hand oriented: positive values go right/down/far.
|
||||
type MouseScrollCallback func(dx float32, dy float32)
|
||||
|
||||
// ResizeCallback is called for a change of window dimensions.
|
||||
type ResizeCallback func(width int, height int)
|
||||
|
||||
// CharCallback is called for typing a character.
|
||||
type CharCallback func(char rune)
|
||||
|
||||
// KeyCallback is called for pressing or releasing a key on the keyboard.
|
||||
type KeyCallback func(key input.Key, modifier input.Modifier)
|
||||
|
||||
// ModifierCallback is called when the currently active modifier changed.
|
||||
type ModifierCallback func(modifier input.Modifier)
|
||||
|
||||
// FileDropCallback is called when one or more files were dropped into the window.
|
||||
type FileDropCallback func(filePaths []string)
|
||||
|
||||
// WindowState describes how the window is currently presented to the user.
|
||||
type WindowState struct {
|
||||
// Maximized is set to true if the window is currently resized to fill the screen.
|
||||
Maximized bool
|
||||
// Top marks the screen position of the upper border of the window.
|
||||
Top int
|
||||
// Left marks the screen position of the left border of the window.
|
||||
Left int
|
||||
// Width marks the width of the non-maximized window.
|
||||
Width int
|
||||
// Height marks the height of the non-maximized window.
|
||||
Height int
|
||||
}
|
||||
|
||||
// WindowStateFromFile attempts to load the state from a file with given name.
|
||||
// If this does not work, the given default state will be returned.
|
||||
func WindowStateFromFile(filename string, defaultState WindowState) WindowState {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return defaultState
|
||||
}
|
||||
var state WindowState
|
||||
err = json.Unmarshal(data, &state)
|
||||
if err != nil {
|
||||
return defaultState
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
// SaveTo stores the state in a file with given filename.
|
||||
func (state WindowState) SaveTo(filename string) error {
|
||||
bytes, err := json.MarshalIndent(state, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(filename, bytes, 0640)
|
||||
}
|
||||
|
||||
// Window represents an OpenGL render surface.
|
||||
type Window interface {
|
||||
// StateSnapshot returns the current state of the window.
|
||||
StateSnapshot() WindowState
|
||||
// RestoreState puts the window into the same state when StateSnapshot() was called.
|
||||
RestoreState(state WindowState)
|
||||
|
||||
// ClipboardString returns the current value of the clipboard, if it is compatible with UTF-8.
|
||||
ClipboardString() (string, error)
|
||||
// SetClipboardString sets the current value of the clipboard as UTF-8 string.
|
||||
SetClipboardString(value string)
|
||||
|
||||
// OnClosing registers a callback function which shall be called when the user requests to close the window.
|
||||
OnClosing(callback ClosingCallback)
|
||||
// OnClosed registers a callback function which shall be called when the window is being closed.
|
||||
OnClosed(callback ClosedCallback)
|
||||
// SetCloseRequest notifies the window system whether the window shall be closed.
|
||||
// It can be called during the callback of OnClosing() to abort a close request by the user.
|
||||
SetCloseRequest(shouldClose bool)
|
||||
|
||||
// OpenGL returns the OpenGL API wrapper for this window.
|
||||
OpenGL() OpenGL
|
||||
// OnRender registers a callback function which shall be called to update the scene.
|
||||
OnRender(callback RenderCallback)
|
||||
|
||||
// OnResize registers a callback function for sizing events.
|
||||
OnResize(callback ResizeCallback)
|
||||
// Size returns the dimensions of the window display area in pixel.
|
||||
Size() (width int, height int)
|
||||
// SetFullScreen sets the full screen state of the window.
|
||||
SetFullScreen(on bool)
|
||||
// SetTitleSuffix appends a text to the current window title.
|
||||
SetTitleSuffix(value string)
|
||||
// SetProjectModified sets an indicator in the window frame that the project has not been saved.
|
||||
SetProjectModified(modified bool)
|
||||
|
||||
// SetCursorVisible controls whether the mouse cursor is currently visible.
|
||||
SetCursorVisible(visible bool)
|
||||
|
||||
// OnMouseMove registers a callback function for mouse move events.
|
||||
OnMouseMove(callback MouseMoveCallback)
|
||||
// OnMouseButtonDown registers a callback function for mouse button down events.
|
||||
OnMouseButtonDown(callback MouseButtonCallback)
|
||||
// OnMouseButtonUp registers a callback function for mouse button up events.
|
||||
OnMouseButtonUp(callback MouseButtonCallback)
|
||||
// OnMouseScroll registers a callback function for mouse scroll events.
|
||||
OnMouseScroll(callback MouseScrollCallback)
|
||||
|
||||
// OnKeyPress registers a callback function for key events.
|
||||
OnKeyPress(callback KeyCallback)
|
||||
// OnKeyRelease registers a callback function for key events.
|
||||
OnKeyRelease(callback KeyCallback)
|
||||
// OnModifier registers a callback function for change of modifier events.
|
||||
OnModifier(callback ModifierCallback)
|
||||
// OnCharCallback registers a callback function for typed characters.
|
||||
OnCharCallback(callback CharCallback)
|
||||
|
||||
// OnFileDropCallback registers a callback function for dropped files.
|
||||
OnFileDropCallback(callback FileDropCallback)
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"github.com/inkyblackness/hacked/ui/input"
|
||||
)
|
||||
|
||||
type keyDeferrer struct {
|
||||
window *WindowEventDispatcher
|
||||
}
|
||||
|
||||
func (def *keyDeferrer) KeyPress(key input.Key, modifier input.Modifier) {
|
||||
def.window.CallKeyPress(key, modifier)
|
||||
}
|
||||
|
||||
func (def *keyDeferrer) KeyRelease(key input.Key, modifier input.Modifier) {
|
||||
def.window.CallKeyRelease(key, modifier)
|
||||
}
|
||||
|
||||
func (def *keyDeferrer) Modifier(modifier input.Modifier) {
|
||||
def.window.CallModifier(modifier)
|
||||
}
|
||||
|
||||
// WindowEventDispatcher implements the common, basic functionality of Window.
|
||||
type WindowEventDispatcher struct {
|
||||
CallClosing ClosingCallback
|
||||
CallClosed ClosedCallback
|
||||
CallRender RenderCallback
|
||||
CallResize ResizeCallback
|
||||
CallOnMouseMove MouseMoveCallback
|
||||
CallOnMouseButtonUp MouseButtonCallback
|
||||
CallOnMouseButtonDown MouseButtonCallback
|
||||
CallOnMouseScroll MouseScrollCallback
|
||||
CallModifier ModifierCallback
|
||||
CallKeyPress KeyCallback
|
||||
CallKeyRelease KeyCallback
|
||||
CallCharCallback CharCallback
|
||||
CallFileDropCallback FileDropCallback
|
||||
}
|
||||
|
||||
// NullWindowEventDispatcher returns an initialized instance with empty callbacks.
|
||||
func NullWindowEventDispatcher() WindowEventDispatcher {
|
||||
return WindowEventDispatcher{
|
||||
CallClosing: func() {},
|
||||
CallClosed: func() {},
|
||||
CallRender: func() {},
|
||||
CallResize: func(int, int) {},
|
||||
CallOnMouseMove: func(float32, float32) {},
|
||||
CallOnMouseButtonUp: func(uint32, input.Modifier) {},
|
||||
CallOnMouseButtonDown: func(uint32, input.Modifier) {},
|
||||
CallOnMouseScroll: func(float32, float32) {},
|
||||
CallKeyPress: func(input.Key, input.Modifier) {},
|
||||
CallKeyRelease: func(input.Key, input.Modifier) {},
|
||||
CallModifier: func(input.Modifier) {},
|
||||
CallCharCallback: func(rune) {},
|
||||
CallFileDropCallback: func([]string) {},
|
||||
}
|
||||
}
|
||||
|
||||
// StickyKeyListener returns an instance of a listener acting as an adapter
|
||||
// for the key-down/-up callbacks.
|
||||
func (window *WindowEventDispatcher) StickyKeyListener() input.StickyKeyListener {
|
||||
return &keyDeferrer{window: window}
|
||||
}
|
||||
|
||||
// OnClosing implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnClosing(callback ClosingCallback) {
|
||||
window.CallClosing = callback
|
||||
}
|
||||
|
||||
// OnClosed implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnClosed(callback ClosedCallback) {
|
||||
window.CallClosed = callback
|
||||
}
|
||||
|
||||
// OnRender implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnRender(callback RenderCallback) {
|
||||
window.CallRender = callback
|
||||
}
|
||||
|
||||
// OnResize implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnResize(callback ResizeCallback) {
|
||||
window.CallResize = callback
|
||||
}
|
||||
|
||||
// OnMouseMove implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnMouseMove(callback MouseMoveCallback) {
|
||||
window.CallOnMouseMove = callback
|
||||
}
|
||||
|
||||
// OnMouseButtonDown implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnMouseButtonDown(callback MouseButtonCallback) {
|
||||
window.CallOnMouseButtonDown = callback
|
||||
}
|
||||
|
||||
// OnMouseButtonUp implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnMouseButtonUp(callback MouseButtonCallback) {
|
||||
window.CallOnMouseButtonUp = callback
|
||||
}
|
||||
|
||||
// OnMouseScroll implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnMouseScroll(callback MouseScrollCallback) {
|
||||
window.CallOnMouseScroll = callback
|
||||
}
|
||||
|
||||
// OnKeyPress implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnKeyPress(callback KeyCallback) {
|
||||
window.CallKeyPress = callback
|
||||
}
|
||||
|
||||
// OnKeyRelease implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnKeyRelease(callback KeyCallback) {
|
||||
window.CallKeyRelease = callback
|
||||
}
|
||||
|
||||
// OnModifier implements the WindowEventDispatcher interface.
|
||||
func (window *WindowEventDispatcher) OnModifier(callback ModifierCallback) {
|
||||
window.CallModifier = callback
|
||||
}
|
||||
|
||||
// OnCharCallback implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnCharCallback(callback CharCallback) {
|
||||
window.CallCharCallback = callback
|
||||
}
|
||||
|
||||
// OnFileDropCallback implements the Window interface.
|
||||
func (window *WindowEventDispatcher) OnFileDropCallback(callback FileDropCallback) {
|
||||
window.CallFileDropCallback = callback
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package opengl
|
||||
|
||||
// Buffer Bits
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
DEPTH_BUFFER_BIT uint32 = 0x00000100
|
||||
STENCIL_BUFFER_BIT = 0x00000400
|
||||
COLOR_BUFFER_BIT = 0x00004000
|
||||
)
|
||||
|
||||
// Draw Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
POINTS uint32 = 0x0000
|
||||
LINES = 0x0001
|
||||
LINE_LOOP = 0x0002
|
||||
LINE_STRIP = 0x0003
|
||||
TRIANGLES = 0x0004
|
||||
TRIANGLE_STRIP = 0x0005
|
||||
TRIANGLE_FAN = 0x0006
|
||||
)
|
||||
|
||||
// Shader Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
FRAGMENT_SHADER uint32 = 0x8B30
|
||||
VERTEX_SHADER = 0x8B31
|
||||
)
|
||||
|
||||
// Status Values
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
COMPILE_STATUS uint32 = 0x8B81
|
||||
LINK_STATUS = 0x8B82
|
||||
)
|
||||
|
||||
// Buffer Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
ARRAY_BUFFER uint32 = 0x8892
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893
|
||||
)
|
||||
|
||||
// Framebuffer Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
FRAMEBUFFER = 0x8D40
|
||||
RENDERBUFFER = 0x8D41
|
||||
|
||||
DEPTH_COMPONENT24 = 0x81A6
|
||||
|
||||
COLOR_ATTACHMENT0 = 0x8CE0
|
||||
DEPTH_ATTACHMENT = 0x8D00
|
||||
)
|
||||
|
||||
// Draw Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
STREAM_DRAW uint32 = 0x88E0
|
||||
STATIC_DRAW = 0x88E4
|
||||
DYNAMIC_DRAW = 0x88E8
|
||||
)
|
||||
|
||||
// Features
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
BLEND uint32 = 0x0BE2
|
||||
DEPTH_TEST = 0x0B71
|
||||
CULL_FACE = 0x0B44
|
||||
SCISSOR_TEST = 0x0C11
|
||||
|
||||
NICEST = 0x1102
|
||||
LINE_SMOOTH = 0x0B20
|
||||
LINE_SMOOTH_HINT = 0x0C52
|
||||
|
||||
ACTIVE_TEXTURE = 0x84E0
|
||||
CURRENT_PROGRAM = 0x8B8D
|
||||
TEXTURE_BINDING_2D = 0x8069
|
||||
SAMPLER_BINDING = 0x8919
|
||||
ARRAY_BUFFER_BINDING = 0x8894
|
||||
ELEMENT_ARRAY_BUFFER_BINDING = 0x8895
|
||||
VERTEX_ARRAY_BINDING = 0x85B5
|
||||
POLYGON_MODE = 0x0B40
|
||||
VIEWPORT = 0x0BA2
|
||||
SCISSOR_BOX = 0x0C10
|
||||
BLEND_SRC_RGB = 0x80C9
|
||||
BLEND_DST_RGB = 0x80C8
|
||||
BLEND_SRC_ALPHA = 0x80CB
|
||||
BLEND_DST_ALPHA = 0x80CA
|
||||
BLEND_EQUATION_RGB = 0x8009
|
||||
BLEND_EQUATION_ALPHA = 0x883D
|
||||
FRONT_AND_BACK = 0x0408
|
||||
FILL = 0x1B02
|
||||
)
|
||||
|
||||
// Alpha constants
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
SRC_ALPHA uint32 = 0x0302
|
||||
ONE_MINUS_SRC_ALPHA = 0x0303
|
||||
ONE_MINUS_SRC_COLOR = 0x0301
|
||||
|
||||
FUNC_ADD = 0x8006
|
||||
)
|
||||
|
||||
// Data Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
BYTE uint32 = 0x1400
|
||||
UNSIGNED_BYTE = 0x1401
|
||||
SHORT = 0x1402
|
||||
UNSIGNED_SHORT = 0x1403
|
||||
INT = 0x1404
|
||||
UNSIGNED_INT = 0x1405
|
||||
FLOAT = 0x1406
|
||||
)
|
||||
|
||||
// Texture Constants
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
TEXTURE_2D uint32 = 0x0DE1
|
||||
|
||||
TEXTURE0 = 0x84C0
|
||||
|
||||
NEAREST = 0x2600
|
||||
TEXTURE_MAG_FILTER = 0x2800
|
||||
TEXTURE_MIN_FILTER = 0x2801
|
||||
|
||||
UNPACK_ROW_LENGTH = 0x0CF2
|
||||
|
||||
LINEAR = 0x2601
|
||||
)
|
||||
|
||||
// Errors
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
NO_ERROR uint32 = 0
|
||||
INVALID_ENUM = 0x0500
|
||||
INVALID_VALUE = 0x0501
|
||||
INVALID_OPERATION = 0x0502
|
||||
STACK_OVERFLOW = 0x0503
|
||||
STACK_UNDERFLOW = 0x0504
|
||||
OUT_OF_MEMORY = 0x0505
|
||||
INVALID_FRAMEBUFFER_OPERATION = 0x0506
|
||||
)
|
||||
|
||||
// Color Types
|
||||
// nolint: golint,megacheck
|
||||
const (
|
||||
ALPHA uint32 = 0x1906
|
||||
RGBA = 0x1908
|
||||
RED = 0x1903
|
||||
|
||||
RGBA8 = 0x8058
|
||||
R8 = 0x8229
|
||||
)
|
||||
Reference in New Issue
Block a user