Documentation ¶
Overview ¶
Package gl provides a more Go friendly OpenGL API
Index ¶
- func ActiveTexture(id int)
- func BindFragDataLocation(p Program, cn int, name string)
- func BlendFunc(sFactor, dFactor Factor)
- func BlendFuncSeparate(sFactorRGB, dFactorRGB, sFactorA, dFactorA Factor)
- func BlitFramebuffer(sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1 int, mask ClearFlags, ...)
- func CheckError()
- func Clear(flags ClearFlags)
- func ClearBuffer(buffer TargetBuffer, drawBuffer int, values []float32)
- func ClearColor(r, g, b, a float32)
- func ClearStencil(i int)
- func ColorMask(r, g, b, a bool)
- func CullFace(face Face)
- func DebugLog()
- func DepthFunc(f Func)
- func DepthMask(f bool)
- func Disable(flag Flag)
- func DrawArrays(ty DrawType, offset, count int)
- func DrawBuffers(bufs []Attachment)
- func DrawElements(ty DrawType, count int, dty Type, offset int)
- func Enable(flag Flag)
- func Flush()
- func FrontFace(dir FaceDirection)
- func Init()
- func MultiDrawElements(ty DrawType, count []int32, dty Type, offset []uintptr)
- func StencilFunc(f Func, ref, mask int)
- func StencilMask(mask int)
- func StencilOp(op, fail, pass Op)
- func UnbindFramebuffer()
- func UnbindFramebufferDraw()
- func UnbindFramebufferRead()
- func Viewport(x, y, width, height int)
- type Access
- type Attachment
- type Attribute
- type Buffer
- type BufferTarget
- type BufferUsage
- type ClearFlags
- type DrawType
- type Face
- type FaceDirection
- type Factor
- type Flag
- type Framebuffer
- type Func
- type Op
- type Program
- type Shader
- type ShaderParameter
- type ShaderType
- type TargetBuffer
- type Texture
- func (t Texture) Bind(target TextureTarget)
- func (t Texture) Delete()
- func (t Texture) Get(level int, format TextureFormat, ty Type, pixels []byte)
- func (t Texture) Image2D(level, width, height int, format TextureFormat, ty Type, pix []byte)
- func (t Texture) Image2DEx(level, width, height int, internalFormat, format TextureFormat, ty Type, ...)
- func (t Texture) Image2DSample(samples, width, height int, format TextureFormat, fixed bool)
- func (t Texture) Image3D(level, width, height, depth int, format TextureFormat, ty Type, pix []byte)
- func (t Texture) Parameter(param TextureParameter, val TextureValue)
- func (t Texture) SubImage2D(level int, x, y, width, height int, format TextureFormat, ty Type, pix []byte)
- func (t Texture) SubImage3D(level, x, y, z, width, height, depth int, format TextureFormat, ty Type, ...)
- type TextureFormat
- type TextureParameter
- type TextureTarget
- type TextureValue
- type Type
- type Uniform
- func (u Uniform) Float(val float32)
- func (u Uniform) Float2(x, y float32)
- func (u Uniform) Float3(x, y, z float32)
- func (u Uniform) Float4(x, y, z, w float32)
- func (u Uniform) FloatMutli(a []float32)
- func (u Uniform) FloatMutliRaw(a interface{}, l int)
- func (u Uniform) Int(val int)
- func (u Uniform) Int3(x, y, z int)
- func (u Uniform) IntV(v ...int)
- func (u Uniform) Matrix4(matrix *mgl32.Mat4)
- func (u Uniform) Matrix4Multi(matrix []mgl32.Mat4)
- type VertexArray
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 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 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 DepthFunc ¶
func DepthFunc(f Func)
DepthFunc sets the function used to decide whether to cull a pixel when depth testing
func DrawArrays ¶
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 FrontFace ¶
func FrontFace(dir FaceDirection)
FrontFace sets the direction of vertices used to specify the front face (e.g. for culling).
func MultiDrawElements ¶
func StencilFunc ¶
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()
Types ¶
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.
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 ¶
IsValid returns whether this Buffer is still valid. A Buffer will become invalid after Delete is called.
func (Buffer) Map ¶
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.
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 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 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 Program ¶
type Program uint32
Program is a collection of shaders which will be run on draw operations.
func (Program) AttachShader ¶
AttachShader attaches the passed shader to the program.
func (Program) AttributeLocation ¶
AttributeLocation returns the attribute with the given name in the program.
func (Program) UniformLocation ¶
UniformLocation returns the uniform with the given name in the program.
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) Parameter ¶
func (s Shader) Parameter(param ShaderParameter) int
Parameter returns the integer value of the parameter for this 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 Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture is a buffer of data used by fragment shaders to produce color.
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) 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.
const ( Red TextureFormat = gl.RED RGB TextureFormat = gl.RGB RGBA TextureFormat = gl.RGBA RGBA8 TextureFormat = gl.RGBA8 RGBA16F TextureFormat = gl.RGBA16F R16F TextureFormat = gl.R16F DepthComponent24 TextureFormat = gl.DEPTH_COMPONENT24 DepthComponent TextureFormat = gl.DEPTH_COMPONENT )
Valid texture formats.
type TextureParameter ¶
type TextureParameter uint32
TextureParameter is a parameter that can be read or set on a texture.
const ( TextureMinFilter TextureParameter = gl.TEXTURE_MIN_FILTER TextureMagFilter TextureParameter = gl.TEXTURE_MAG_FILTER TextureWrapS TextureParameter = gl.TEXTURE_WRAP_S TextureWrapT TextureParameter = gl.TEXTURE_WRAP_T TextureMaxLevel TextureParameter = gl.TEXTURE_MAX_LEVEL )
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) FloatMutli ¶
func (Uniform) FloatMutliRaw ¶
func (Uniform) Matrix4Multi ¶
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.