opengl

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEPTH_BUFFER_BIT   uint32 = 0x00000100
	STENCIL_BUFFER_BIT        = 0x00000400
	COLOR_BUFFER_BIT          = 0x00004000
)

Buffer Bits nolint: golint,megacheck

View Source
const (
	POINTS         uint32 = 0x0000
	LINES                 = 0x0001
	LINE_LOOP             = 0x0002
	LINE_STRIP            = 0x0003
	TRIANGLES             = 0x0004
	TRIANGLE_STRIP        = 0x0005
	TRIANGLE_FAN          = 0x0006
)

Draw Types nolint: golint,megacheck

View Source
const (
	FRAGMENT_SHADER uint32 = 0x8B30
	VERTEX_SHADER          = 0x8B31
)

Shader Types nolint: golint,megacheck

View Source
const (
	COMPILE_STATUS uint32 = 0x8B81
	LINK_STATUS           = 0x8B82
)

Status Values nolint: golint,megacheck

View Source
const (
	ARRAY_BUFFER         uint32 = 0x8892
	ELEMENT_ARRAY_BUFFER        = 0x8893
)

Buffer Types nolint: golint,megacheck

View Source
const (
	FRAMEBUFFER  = 0x8D40
	RENDERBUFFER = 0x8D41

	DEPTH_COMPONENT24 = 0x81A6

	COLOR_ATTACHMENT0 = 0x8CE0
	DEPTH_ATTACHMENT  = 0x8D00
)

Framebuffer Types nolint: golint,megacheck

View Source
const (
	STREAM_DRAW  uint32 = 0x88E0
	STATIC_DRAW         = 0x88E4
	DYNAMIC_DRAW        = 0x88E8
)

Draw Types nolint: golint,megacheck

View Source
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
)

Features nolint: golint,megacheck

View Source
const (
	SRC_ALPHA           uint32 = 0x0302
	ONE_MINUS_SRC_ALPHA        = 0x0303
	ONE_MINUS_SRC_COLOR        = 0x0301

	FUNC_ADD = 0x8006
)

Alpha constants nolint: golint,megacheck

View Source
const (
	BYTE           uint32 = 0x1400
	UNSIGNED_BYTE         = 0x1401
	SHORT                 = 0x1402
	UNSIGNED_SHORT        = 0x1403
	INT                   = 0x1404
	UNSIGNED_INT          = 0x1405
	FLOAT                 = 0x1406
)

Data Types nolint: golint,megacheck

View Source
const (
	TEXTURE_2D uint32 = 0x0DE1

	TEXTURE0 = 0x84C0

	NEAREST            = 0x2600
	TEXTURE_MAG_FILTER = 0x2800
	TEXTURE_MIN_FILTER = 0x2801

	UNPACK_ROW_LENGTH = 0x0CF2

	LINEAR = 0x2601
)

Texture Constants nolint: golint,megacheck

View Source
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
)

Errors nolint: golint,megacheck

View Source
const (
	ALPHA uint32 = 0x1906
	RGBA         = 0x1908
	RED          = 0x1903

	RGBA8 = 0x8058
	R8    = 0x8229
)

Color Types nolint: golint,megacheck

Variables

This section is empty.

Functions

func CompileNewShader

func CompileNewShader(gl OpenGL, shaderType uint32, source string) (shader uint32, err error)

CompileNewShader creates a shader of given type and compiles the provided source.

func ErrorString

func ErrorString(errorCode uint32) string

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 LinkNewProgram

func LinkNewProgram(gl OpenGL, shaders ...uint32) (program uint32, err error)

LinkNewProgram creates a new shader program based on the provided shaders.

func LinkNewStandardProgram

func LinkNewStandardProgram(gl OpenGL, vertexShaderSource, fragmentShaderSource string) (program uint32, err error)

LinkNewStandardProgram creates a new shader based on two shader sources.

Types

type AttributeSetter

type AttributeSetter func(OpenGL)

AttributeSetter is a callback function for a VertexArrayObject.

type CharCallback

type CharCallback func(char rune)

CharCallback is called for typing a character.

type ClosedCallback

type ClosedCallback func()

ClosedCallback is the function to clean up resources when the window is being closed.

type ClosingCallback

type ClosingCallback func()

ClosingCallback is the function to handle close requests by the user.

type DebugBuilder

type DebugBuilder struct {
	// contains filtered or unexported fields
}

DebugBuilder is a builder for an OpenGL implementation for debugging.

func NewDebugBuilder

func NewDebugBuilder(wrapped OpenGL) *DebugBuilder

NewDebugBuilder wraps the provided OpenGL instance and returns a new builder instance.

func (*DebugBuilder) Build

func (builder *DebugBuilder) Build() OpenGL

Build creates a new instance of the debugging OpenGL implementation. The builder can be reused to create another instance with different parameters.

func (*DebugBuilder) OnEntry

func (builder *DebugBuilder) OnEntry(callback DebuggingEntryFunc) *DebugBuilder

OnEntry registers a callback function to be called before an OpenGL function is called.

func (*DebugBuilder) OnError

func (builder *DebugBuilder) OnError(callback DebuggingErrorFunc) *DebugBuilder

OnError registers a callback function to be called when an OpenGL function set an error state.

func (*DebugBuilder) OnExit

func (builder *DebugBuilder) OnExit(callback DebuggingExitFunc) *DebugBuilder

OnExit registers a callback function to be called after an OpenGL function returned.

type DebuggingEntryFunc

type DebuggingEntryFunc func(name string, param ...interface{})

DebuggingEntryFunc is a function to be called on function entry.

type DebuggingErrorFunc

type DebuggingErrorFunc func(name string, errorCodes []uint32)

DebuggingErrorFunc is a function which is called if a previous OpenGL call caused an error state.

type DebuggingExitFunc

type DebuggingExitFunc func(name string, result ...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 FileDropCallback added in v0.2.0

type FileDropCallback func(filePaths []string)

FileDropCallback is called when one or more files were dropped into the window.

type KeyCallback

type KeyCallback func(key input.Key, modifier input.Modifier)

KeyCallback is called for pressing or releasing a key on the keyboard.

type Matrix4Uniform

type Matrix4Uniform UniformLocation

Matrix4Uniform represents one uniform parameter for a 4x4 matrix.

func (Matrix4Uniform) Set

func (location Matrix4Uniform) Set(gl OpenGL, matrix *mgl.Mat4)

Set stores the provided matrix as the current uniform value.

type ModifierCallback

type ModifierCallback func(modifier input.Modifier)

ModifierCallback is called when the currently active modifier changed.

type MouseButtonCallback

type MouseButtonCallback func(buttonMask uint32, modifier input.Modifier)

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 MouseMoveCallback

type MouseMoveCallback func(x float32, y float32)

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 MouseScrollCallback

type MouseScrollCallback func(dx float32, dy float32)

MouseScrollCallback is the function to receive scroll events. Delta values are right-hand oriented: positive values go right/down/far.

type NamedShaderError added in v1.8.0

type NamedShaderError struct {
	Name   string
	Nested error
}

NamedShaderError is an error with a name.

func (NamedShaderError) Error added in v1.8.0

func (err NamedShaderError) Error() string

Error returns the name with the nested error information.

func (NamedShaderError) Unwrap added in v1.8.0

func (err NamedShaderError) Unwrap() error

Unwrap returns the nested error.

type OpenGL

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

OpenGL describes an Open GL interface usable for all environments of this application.

type RenderCallback

type RenderCallback func()

RenderCallback is the function to receive render events. When the callback returns, the window will swap the internal buffer.

type ResizeCallback

type ResizeCallback func(width int, height int)

ResizeCallback is called for a change of window dimensions.

type ShaderError added in v1.8.0

type ShaderError struct {
	Log string
}

ShaderError describes a problem with a log.

func (ShaderError) Error added in v1.8.0

func (err ShaderError) Error() string

Error returns the log.

type UniformLocation

type UniformLocation int32

UniformLocation represents a uniform parameter for a shader program.

type Vector4Uniform

type Vector4Uniform UniformLocation

Vector4Uniform represents one uniform parameter for a 4-dimensional vector.

func (Vector4Uniform) Set

func (location Vector4Uniform) Set(gl OpenGL, value *[4]float32)

Set stores the provided 4-dimensional vector as the current uniform value.

type VertexArrayObject

type VertexArrayObject struct {
	// contains filtered or unexported fields
}

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.

func NewVertexArrayObject

func NewVertexArrayObject(gl OpenGL, program uint32) *VertexArrayObject

NewVertexArrayObject returns a new instance.

func (*VertexArrayObject) Dispose

func (vao *VertexArrayObject) Dispose()

Dispose drops any associated resources.

func (*VertexArrayObject) OnShader

func (vao *VertexArrayObject) OnShader(task func())

OnShader executes the provided task with an activated shader program and the vertex array object initialized.

func (*VertexArrayObject) WithSetter

func (vao *VertexArrayObject) WithSetter(setter AttributeSetter)

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.

type Window

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

Window represents an OpenGL render surface.

type WindowEventDispatcher

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
}

WindowEventDispatcher implements the common, basic functionality of Window.

func NullWindowEventDispatcher

func NullWindowEventDispatcher() WindowEventDispatcher

NullWindowEventDispatcher returns an initialized instance with empty callbacks.

func (*WindowEventDispatcher) OnCharCallback

func (window *WindowEventDispatcher) OnCharCallback(callback CharCallback)

OnCharCallback implements the Window interface.

func (*WindowEventDispatcher) OnClosed

func (window *WindowEventDispatcher) OnClosed(callback ClosedCallback)

OnClosed implements the Window interface.

func (*WindowEventDispatcher) OnClosing

func (window *WindowEventDispatcher) OnClosing(callback ClosingCallback)

OnClosing implements the Window interface.

func (*WindowEventDispatcher) OnFileDropCallback added in v0.2.0

func (window *WindowEventDispatcher) OnFileDropCallback(callback FileDropCallback)

OnFileDropCallback implements the Window interface.

func (*WindowEventDispatcher) OnKeyPress added in v1.7.0

func (window *WindowEventDispatcher) OnKeyPress(callback KeyCallback)

OnKeyPress implements the Window interface.

func (*WindowEventDispatcher) OnKeyRelease added in v1.7.0

func (window *WindowEventDispatcher) OnKeyRelease(callback KeyCallback)

OnKeyRelease implements the Window interface.

func (*WindowEventDispatcher) OnModifier

func (window *WindowEventDispatcher) OnModifier(callback ModifierCallback)

OnModifier implements the WindowEventDispatcher interface.

func (*WindowEventDispatcher) OnMouseButtonDown

func (window *WindowEventDispatcher) OnMouseButtonDown(callback MouseButtonCallback)

OnMouseButtonDown implements the Window interface.

func (*WindowEventDispatcher) OnMouseButtonUp

func (window *WindowEventDispatcher) OnMouseButtonUp(callback MouseButtonCallback)

OnMouseButtonUp implements the Window interface.

func (*WindowEventDispatcher) OnMouseMove

func (window *WindowEventDispatcher) OnMouseMove(callback MouseMoveCallback)

OnMouseMove implements the Window interface.

func (*WindowEventDispatcher) OnMouseScroll

func (window *WindowEventDispatcher) OnMouseScroll(callback MouseScrollCallback)

OnMouseScroll implements the Window interface.

func (*WindowEventDispatcher) OnRender

func (window *WindowEventDispatcher) OnRender(callback RenderCallback)

OnRender implements the Window interface.

func (*WindowEventDispatcher) OnResize

func (window *WindowEventDispatcher) OnResize(callback ResizeCallback)

OnResize implements the Window interface.

func (*WindowEventDispatcher) StickyKeyListener

func (window *WindowEventDispatcher) StickyKeyListener() input.StickyKeyListener

StickyKeyListener returns an instance of a listener acting as an adapter for the key-down/-up callbacks.

type WindowState added in v1.6.0

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
}

WindowState describes how the window is currently presented to the user.

func WindowStateFromFile added in v1.6.0

func WindowStateFromFile(filename string, defaultState WindowState) WindowState

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 (WindowState) SaveTo added in v1.6.0

func (state WindowState) SaveTo(filename string) error

SaveTo stores the state in a file with given filename.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL