gl

package
v0.0.0-...-03afc55 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package gl provides a more Go friendly OpenGL API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveTexture

func ActiveTexture(id int)

ActiveTexture sets the texture slot with the passed id as the currently active one.

func BindFragDataLocation

func BindFragDataLocation(p Program, cn int, name string)

func BlendFunc

func BlendFunc(sFactor, dFactor Factor)

BlendFunc sets the factors to be used when blending.

func BlendFuncSeparate

func BlendFuncSeparate(sFactorRGB, dFactorRGB, sFactorA, dFactorA Factor)

BlendFuncSeparate sets the factors to be used when blending.

func BlitFramebuffer

func BlitFramebuffer(sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1 int, mask ClearFlags, filter TextureValue)

func CheckError

func CheckError()

CheckError panics if there has been an error reported to the context. This is normally not a cheap call so shouldn't be used in production.

func Clear

func Clear(flags ClearFlags)

Clear clears the buffers specified by the passed flags.

func ClearBuffer

func ClearBuffer(buffer TargetBuffer, drawBuffer int, values []float32)

func ClearColor

func ClearColor(r, g, b, a float32)

ClearColor sets the color the color buffer should be cleared to when Clear is called with the color flag.

func ClearStencil

func ClearStencil(i int)

ClearStencil clears the stencil buffer will the passed value.

func ColorMask

func ColorMask(r, g, b, a bool)

ColorMask sets whether each color channel be the written too.

func CullFace

func CullFace(face Face)

CullFace sets the face to be culled by the gpu.

func DebugLog

func DebugLog()

DebugLog enables OpenGL's debug messages and logs them to stdout.

func DepthFunc

func DepthFunc(f Func)

DepthFunc sets the function used to decide whether to cull a pixel when depth testing

func DepthMask

func DepthMask(f bool)

DepthMask sets whether the depth buffer can be written too.

func Disable

func Disable(flag Flag)

Disable disables the passed flag.

func DrawArrays

func DrawArrays(ty DrawType, offset, count int)

DrawArrays draws the passed number of triangles starting at the passed offset using data from the currently bound buffer(s). The DrawType specifies how the shapes (triangles, lines etc) will be formed from the data.

func DrawBuffers

func DrawBuffers(bufs []Attachment)

func DrawElements

func DrawElements(ty DrawType, count int, dty Type, offset int)

func Enable

func Enable(flag Flag)

Enable enables the passed flag.

func Flush

func Flush()

Flush flushes all commands in the queue and waits for completion.

func FrontFace

func FrontFace(dir FaceDirection)

FrontFace sets the direction of vertices used to specify the front face (e.g. for culling).

func Init

func Init()

Init inits the gl library. This should be called once a context is ready.

func MultiDrawElements

func MultiDrawElements(ty DrawType, count []int32, dty Type, offset []uintptr)

func StencilFunc

func StencilFunc(f Func, ref, mask int)

StencilFunc sets the function to be used when comparing with the stencil buffer.

func StencilMask

func StencilMask(mask int)

StencilMask sets the value to be written to the stencil buffer on success.

func StencilOp

func StencilOp(op, fail, pass Op)

StencilOp sets the operation to be executed depending on the result of the stencil test.

func UnbindFramebuffer

func UnbindFramebuffer()

func UnbindFramebufferDraw

func UnbindFramebufferDraw()

func UnbindFramebufferRead

func UnbindFramebufferRead()

func Viewport

func Viewport(x, y, width, height int)

Viewport sets the size of the viewport of this context.

Types

type Access

type Access uint32

Access states how a value will be accesed by the program.

const (
	// ReadOnly states that the returned value will only be read.
	ReadOnly Access = gl.READ_ONLY
	// WriteOnly states that the returned value will only be written
	// to.
	WriteOnly Access = gl.WRITE_ONLY
)

type Attachment

type Attachment uint32
const (
	ColorAttachment0 Attachment = gl.COLOR_ATTACHMENT0
	ColorAttachment1 Attachment = gl.COLOR_ATTACHMENT1
	ColorAttachment2 Attachment = gl.COLOR_ATTACHMENT2
	DepthAttachment  Attachment = gl.DEPTH_ATTACHMENT
)

type Attribute

type Attribute int32

Attribute is a per-a-vertex value that can be passed into the program.

func (Attribute) Disable

func (a Attribute) Disable()

Disable disables the attribute for use in rendering.

func (Attribute) Enable

func (a Attribute) Enable()

Enable enables the attribute for use in rendering.

func (Attribute) Pointer

func (a Attribute) Pointer(size int, ty Type, normalized bool, stride, offset int)

Pointer is used to specify the format of the data in the buffer. The data will be uploaded as floats.

func (Attribute) PointerInt

func (a Attribute) PointerInt(size int, ty Type, stride, offset int)

PointerInt is used to specify the format of the data in the buffer. The data will be uploaded as integers.

type Buffer

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

Buffer is a storage for vertex data.

func CreateBuffer

func CreateBuffer() Buffer

CreateBuffer allocates a new Buffer. If the allocation fails IsValid will return false.

func (Buffer) Bind

func (b Buffer) Bind(target BufferTarget)

Bind makes the buffer the currently active one for the given target. This will allow it to be the source of operations that act on a buffer (Data, Map etc). If the buffer is already bound then this does nothing.

func (Buffer) Data

func (b Buffer) Data(data []byte, usage BufferUsage)

Data uploads the passed data to the gpu to be placed in this buffer. The usage specifies how the program plans to use this buffer.

func (*Buffer) Delete

func (b *Buffer) Delete()

Delete deallocates the buffer and any stored data. IsValid will return false after this call.

func (Buffer) IsValid

func (b Buffer) IsValid() bool

IsValid returns whether this Buffer is still valid. A Buffer will become invalid after Delete is called.

func (Buffer) Map

func (b Buffer) Map(access Access, length int) []byte

Map maps the memory in the buffer on the gpu to memory which the program can access. The access flag will specify how the program plans to use the returned data. Unmapped must be called to return the data to the gpu.

Warning: the passed length value is not checked in anyway so it is possible to overrun the memory. It is up to the program to ensure this length is valid.

func (Buffer) Unmap

func (b Buffer) Unmap()

Unmap returns mapped memory for the buffer, as returned by Map, to the gpu so that it can be used in draw operations.

type BufferTarget

type BufferTarget uint32

BufferTarget is a target for a buffer to be bound to.

const (
	// ArrayBuffer is a buffer target intended for vertex data.
	ArrayBuffer        BufferTarget = gl.ARRAY_BUFFER
	ElementArrayBuffer BufferTarget = gl.ELEMENT_ARRAY_BUFFER
)

type BufferUsage

type BufferUsage uint32

BufferUsage states how a buffer is going to be used by the program.

const (
	// StaticDraw marks the buffer as 'not going to change' after the
	// initial data upload to be rendered by the gpu.
	StaticDraw BufferUsage = gl.STATIC_DRAW
	// DynamicDraw marks the buffer as 'changed frequently' during the
	// course of the program whilst being rendered by the gpu.
	DynamicDraw BufferUsage = gl.DYNAMIC_DRAW
	// StreamDraw marks the buffer as 'changed every frame' whilst being
	// rendered by the gpu.
	StreamDraw BufferUsage = gl.STREAM_DRAW
)

type ClearFlags

type ClearFlags uint32

ClearFlags is a set of flags to mark what should be cleared during a Clear call.

const (
	// ColorBufferBit marks the color buffer to be cleared
	ColorBufferBit ClearFlags = gl.COLOR_BUFFER_BIT
	// DepthBufferBit marks the depth buffer to be cleared
	DepthBufferBit ClearFlags = gl.DEPTH_BUFFER_BIT
	// StencilBufferBit marks the stencil buffer to be cleared
	StencilBufferBit ClearFlags = gl.STENCIL_BUFFER_BIT
)

type DrawType

type DrawType uint32

DrawType is used to specify how the vertices will be handled to draw.

const (
	// Triangles treats each set of 3 vertices as a triangle
	Triangles DrawType = gl.TRIANGLES
	// LineStrip means the previous vertex connects to the next
	// one in a continuous strip.
	LineStrip DrawType = gl.LINE_STRIP
	// Lines treats each set of 2 vertices as a line
	Lines DrawType = gl.LINES
	// Points treats each vertex as a point
	Points DrawType = gl.POINTS
)

type Face

type Face uint32

Face specifies a face to act on.

const (
	Back  Face = gl.BACK
	Front Face = gl.FRONT
)

Valid faces

type FaceDirection

type FaceDirection uint32

FaceDirection is used to specify an order of vertices, normally used to set which is considered to be the front face.

const (
	ClockWise        FaceDirection = gl.CW
	CounterClockWise FaceDirection = gl.CCW
)

Valid directions for vertices for faces.

type Factor

type Factor uint32

Factor is used in blending

const (
	SrcAlpha         Factor = gl.SRC_ALPHA
	OneMinusSrcAlpha Factor = gl.ONE_MINUS_SRC_ALPHA
	OneFactor        Factor = gl.ONE
	ZeroFactor       Factor = gl.ZERO
)

Valid factors

type Flag

type Flag uint32

Flag is a setting that can be enabled or disabled on the context.

const (
	DepthTest    Flag = gl.DEPTH_TEST
	CullFaceFlag Flag = gl.CULL_FACE
	StencilTest  Flag = gl.STENCIL_TEST
	Blend        Flag = gl.BLEND
	DebugOutput  Flag = gl.DEBUG_OUTPUT
	Multisample  Flag = gl.MULTISAMPLE
)

Valid flags

type Framebuffer

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

func NewFramebuffer

func NewFramebuffer() Framebuffer

func (Framebuffer) Bind

func (f Framebuffer) Bind()

func (Framebuffer) BindDraw

func (f Framebuffer) BindDraw()

func (Framebuffer) BindRead

func (f Framebuffer) BindRead()

func (Framebuffer) Check

func (f Framebuffer) Check()

func (Framebuffer) Delete

func (f Framebuffer) Delete()

func (Framebuffer) ReadBuffer

func (f Framebuffer) ReadBuffer(a Attachment)

func (Framebuffer) Texture2D

func (f Framebuffer) Texture2D(attachment Attachment, texTarget TextureTarget, tex Texture, level int)

type Func

type Func uint32

Func is a function to be preformed on two values.

const (
	Never       Func = gl.NEVER
	Less        Func = gl.LESS
	LessOrEqual Func = gl.LEQUAL
	Greater     Func = gl.GREATER
	Always      Func = gl.ALWAYS
	Equal       Func = gl.EQUAL
)

Functions

type Op

type Op uint32

Op is an operation to be applied (depending on the method used)

const (
	Replace Op = gl.REPLACE
	Keep    Op = gl.KEEP
	Zero    Op = gl.ZERO
)

Valid operations

type Program

type Program uint32

Program is a collection of shaders which will be run on draw operations.

func CreateProgram

func CreateProgram() Program

CreateProgram allocates a new program.

func (Program) AttachShader

func (p Program) AttachShader(s Shader)

AttachShader attaches the passed shader to the program.

func (Program) AttributeLocation

func (p Program) AttributeLocation(name string) Attribute

AttributeLocation returns the attribute with the given name in the program.

func (p Program) Link()

Link links the program's shaders.

func (Program) UniformLocation

func (p Program) UniformLocation(name string) Uniform

UniformLocation returns the uniform with the given name in the program.

func (Program) Use

func (p Program) Use()

Use sets this shader as the active shader. If this shader is already active this does nothing.

type Shader

type Shader uint32

Shader is code to be run on the gpu at a specific stage in the pipeline.

func CreateShader

func CreateShader(t ShaderType) Shader

CreateShader creates a new shader of the specifed type.

func (Shader) Compile

func (s Shader) Compile()

Compile compiles the shader.

func (Shader) InfoLog

func (s Shader) InfoLog() string

InfoLog returns the log from compiling the shader.

func (Shader) Parameter

func (s Shader) Parameter(param ShaderParameter) int

Parameter returns the integer value of the parameter for this shader.

func (Shader) Source

func (s Shader) Source(src string)

Source sets the source of the shader.

type ShaderParameter

type ShaderParameter uint32

ShaderParameter is a parameter that can set or read from a shader.

const (
	CompileStatus ShaderParameter = gl.COMPILE_STATUS
	InfoLogLength ShaderParameter = gl.INFO_LOG_LENGTH
)

Valid shader parameters.

type ShaderType

type ShaderType uint32

ShaderType is type of shader to be used, different types run at different stages in the pipeline.

const (
	VertexShader   ShaderType = gl.VERTEX_SHADER
	FragmentShader ShaderType = gl.FRAGMENT_SHADER
	GeometryShader ShaderType = gl.GEOMETRY_SHADER
)

Valid shader types.

type TargetBuffer

type TargetBuffer uint32
const (
	Color TargetBuffer = gl.COLOR
)

type Texture

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

Texture is a buffer of data used by fragment shaders to produce color.

func CreateTexture

func CreateTexture() Texture

CreateTexture allocates a new texture.

func (Texture) Bind

func (t Texture) Bind(target TextureTarget)

Bind binds the texture to the passed target, if the texture is already bound then this does nothing.

func (Texture) Delete

func (t Texture) Delete()

func (Texture) Get

func (t Texture) Get(level int, format TextureFormat, ty Type, pixels []byte)

func (Texture) Image2D

func (t Texture) Image2D(level, width, height int, format TextureFormat, ty Type, pix []byte)

Image2D uploads a 2D texture to the GPU.

func (Texture) Image2DEx

func (t Texture) Image2DEx(level, width, height int, internalFormat, format TextureFormat, ty Type, pix []byte)

Image2DEx uploads a 2D texture to the GPU.

func (Texture) Image2DSample

func (t Texture) Image2DSample(samples, width, height int, format TextureFormat, fixed bool)

Image2DEx uploads a 2D texture to the GPU.

func (Texture) Image3D

func (t Texture) Image3D(level, width, height, depth int, format TextureFormat, ty Type, pix []byte)

Image3D uploads a 3D texture to the GPU.

func (Texture) Parameter

func (t Texture) Parameter(param TextureParameter, val TextureValue)

Parameter sets a parameter on the texture to passed value.

func (Texture) SubImage2D

func (t Texture) SubImage2D(level int, x, y, width, height int, format TextureFormat, ty Type, pix []byte)

SubImage2D updates a region of a 2D texture.

func (Texture) SubImage3D

func (t Texture) SubImage3D(level, x, y, z, width, height, depth int, format TextureFormat, ty Type, pix []byte)

SubImage3D updates a region of a 3D texture.

type TextureFormat

type TextureFormat uint32

TextureFormat is the format of a texture either internally or to be uploaded.

Valid texture formats.

type TextureParameter

type TextureParameter uint32

TextureParameter is a parameter that can be read or set on a texture.

Valid texture parameters.

type TextureTarget

type TextureTarget uint32

TextureTarget is a target were a texture can be bound to.

const (
	Texture2D            TextureTarget = gl.TEXTURE_2D
	Texture2DMultisample TextureTarget = gl.TEXTURE_2D_MULTISAMPLE
	Texture2DArray       TextureTarget = gl.TEXTURE_2D_ARRAY
	Texture3D            TextureTarget = gl.TEXTURE_3D
)

Valid texture targets.

type TextureValue

type TextureValue int32

TextureValue is a value that be set on a texture's parameter.

const (
	Nearest              TextureValue = gl.NEAREST
	Linear               TextureValue = gl.LINEAR
	LinearMipmapLinear   TextureValue = gl.LINEAR_MIPMAP_LINEAR
	LinearMipmapNearest  TextureValue = gl.LINEAR_MIPMAP_NEAREST
	NearestMipmapNearest TextureValue = gl.NEAREST_MIPMAP_NEAREST
	NearestMipmapLinear  TextureValue = gl.NEAREST_MIPMAP_LINEAR
	ClampToEdge          TextureValue = gl.CLAMP_TO_EDGE
)

Valid texture values.

type Type

type Type uint32

Type is a type of data used by various operations.

const (
	UnsignedByte  Type = gl.UNSIGNED_BYTE
	UnsignedShort Type = gl.UNSIGNED_SHORT
	UnsignedInt   Type = gl.UNSIGNED_INT
	Short         Type = gl.SHORT
	Float         Type = gl.FLOAT
)

Valid types.

type Uniform

type Uniform int32

Uniform is a per-a-draw value that can be passed into the program.

func (Uniform) Float

func (u Uniform) Float(val float32)

Float sets the value of the uniform to the passed float.

func (Uniform) Float2

func (u Uniform) Float2(x, y float32)

Float2 sets the value of the uniform to the passed floats.

func (Uniform) Float3

func (u Uniform) Float3(x, y, z float32)

Float3 sets the value of the uniform to the passed floats.

func (Uniform) Float4

func (u Uniform) Float4(x, y, z, w float32)

Float3 sets the value of the uniform to the passed floats.

func (Uniform) FloatMutli

func (u Uniform) FloatMutli(a []float32)

func (Uniform) FloatMutliRaw

func (u Uniform) FloatMutliRaw(a interface{}, l int)

func (Uniform) Int

func (u Uniform) Int(val int)

Int sets the value of the uniform to the passed integer.

func (Uniform) Int3

func (u Uniform) Int3(x, y, z int)

Int3 sets the value of the uniform to the passed integers.

func (Uniform) IntV

func (u Uniform) IntV(v ...int)

IntV sets the value of the uniform to the passed integer array.

func (Uniform) Matrix4

func (u Uniform) Matrix4(matrix *mgl32.Mat4)

Matrix4 sets the value of the uniform to the passed matrix.

func (Uniform) Matrix4Multi

func (u Uniform) Matrix4Multi(matrix []mgl32.Mat4)

Matrix4 sets the value of the uniform to the passed matrix.

type VertexArray

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

VertexArray is used to store state needed to render vertices. This includes buffers, the format of the buffers and enabled attributes.

func CreateVertexArray

func CreateVertexArray() VertexArray

CreateVertexArray allocates a new VertexArray. If the allocation fails then IsValid will return false.

func (VertexArray) Bind

func (va VertexArray) Bind()

Bind marks the VertexArray as the currently active one, this means buffers/the format of the buffers etc will be bound to this VertexArray. If this vertex array is already bound then this will do nothing.

func (*VertexArray) Delete

func (va *VertexArray) Delete()

Delete deallocates the VertexArray. This does not free any attached buffers. IsValid will return false after this call.

func (VertexArray) IsValid

func (va VertexArray) IsValid() bool

IsValid returns whether this VertexArray is still valid. A VertexArray will become invalid after Delete is called.

Jump to

Keyboard shortcuts

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