-- import "github.com/metaleap/go-opengl/util"
OpenGL utilities and a few sane slim wrappers (without going full-on "OO"-overboard) for Go (using the GL Core Profile 3.3+ [ http://github.com/metaleap/go-opengl/core/ ] bindings).
const (
// The size of a gl.Float in bytes
SizeOfGlFloat gl.Sizeiptr = 4
// The size of a gl.Uint in bytes
SizeOfGlUint gl.Sizeiptr = 4
)
var (
Cache GlCache
// Provides access to miscellaneous GL functionality.
Util GlUtil
// Provides access to miscellaneous type-specific GL functionality.
Typed TypeUtils
// Provides methods that each wrap a GL function call and immediately check for GL errors to be returned as Go errors.
Try GlTry
)
var (
// All the known possible OpenGL core context versions that this package supports.
KnownVersions = [5]float64{3.3, 4.0, 4.1, 4.2, 4.3}
// Contains the well-known extension prefixes that can be omitted
// when querying the current OpenGL context via Util.Extension().
KnownExtensionPrefixes = [...]string{"GL_3DFX_", "GL_3DL_", "GL_AMD_", "GL_APPLE_", "GL_ARB_", "GL_ATI_", "GL_EXT_", "GL_GREMEDY_", "GL_HP_", "GL_I3D_", "GL_IBM_", "GL_INGR_", "GL_INTEL_", "GL_KHR_", "GL_KTX_", "GL_MESA_", "GL_MESAX_", "GL_NV_", "GL_NVX_", "GL_OES_", "GL_OML_", "GL_PGI_", "GL_REND__", "GL_S3_", "GL_SGI_", "GL_SGIS_", "GL_SGIX_", "GL_SUN_", "GL_SUNX_", "GL_WIN_", "WGL_EXT_"}
// After you have called ugl.Init() upon successful OpenGL context creation and GL binding initialization,
// contains information on what the currently active OpenGL profile supports.
Support struct {
// Informs on whether certain buffer types are supported by the current OpenGL context.
Buffers struct {
// True if OpenGL version is 4.2 or higher.
AtomicCounter bool
// True if OpenGL version is 4.3 or higher.
DispatchIndirect bool
// True if OpenGL version is 4.3 or higher.
ShaderStorage bool
}
// All extensions supported by the current OpenGL context.
// Useful for casual inspection, but to query for the presence of a specific extension, always use Util.Extension(name)
Extensions []string
// Information on the OpenGL version of the current OpenGL context.
GlVersion struct {
// Will be either 0 or any one of the values in KnownVersions.
Num float64
// The major and minor parts of the version in Num.
MajorMinor [2]int
// True if OpenGL version is 3.3 or higher.
Is33 bool
// True if OpenGL version is 4.0 or higher.
Is40 bool
// True if OpenGL version is 4.1 or higher.
Is41 bool
// True if OpenGL version is 4.2 or higher.
Is42 bool
// True if OpenGL version is 4.3 or higher.
Is43 bool
}
// Information on the GL Shading Language supported by the current OpenGL context.
Glsl struct {
// Info on support for certain shader stages.
Shaders struct {
// True if Support.GlSl.Version.Num is 430 or higher.
ComputeStage bool
// True if Support.GlSl.Version.Num is 400 or higher.
TessellationStages bool
}
// Information on the GLSL version supported by the current OpenGL context.
Version struct {
// Will be either 0, 330, 400, 410, 420 or 430.
Num int
// True if OpenGL version is 3.3 or higher.
Is330 bool
// True if OpenGL version is 4.0 or higher.
Is400 bool
// True if OpenGL version is 4.1 or higher.
Is410 bool
// True if OpenGL version is 4.2 or higher.
Is420 bool
// True if OpenGL version is 4.3 or higher.
Is430 bool
}
}
// Informs on texturing/sampling-related support by the current OpenGL context.
Textures struct {
// True if OpenGL version is 4.2 or higher.
Immutable bool
// The maximum supported texture filtering anisotropy.
// If the current OpenGL context does not support anisotropic texture filtering, the
// value will be 0; else the value is guaranteed to be at least 1, and is typically 16.
MaxFilterAnisotropy gl.Float
// The maximum supported texture MIP-map LOD bias.
// (The minimum would be the negative equivalent of this value.)
MaxMipLoadBias gl.Float
ImageUnits struct {
MaxCombined gl.Int
MaxCompute gl.Int
MaxFragment gl.Int
MaxGeometry gl.Int
MaxVertex gl.Int
}
// Experimental.
StreamUpdatesViaPixelBuffer bool
}
}
)
var (
PtrNil = gl.Ptr(nil)
)
func Init()
DO call this immediately upon successful OpenGL context initialization to prepare this package for use. Fully populates all fields and sub-fields in the Support package global.
func LogLastError(stepFmt string, stepFmtArgs ...interface{})
log.Println()s the error returned by Util.Error(), if any.
func VersionMajorMinor(v float64) (major, minor int)
Returns the major and minor parts of the specified version number.
func VersionMatch(v float64) bool
Returns true if GlVersion is greater than or equal to v.
type Buffer struct {
// The OpenGL handle to this buffer object.
// This is 0 before calling Recreate() and after calling Dispose().
GlHandle gl.Uint
// The current binding target for this buffer object
// (such as for example gl.ARRAY_BUFFER, gl.ELEMENT_ARRAY_BUFFER etc.).
GlTarget gl.Enum
}
Represents an OpenGL buffer object.
func NewArrayBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.ARRAY_BUFFER.
func NewAtomicCounterBuffer() (me *Buffer)
If Support.Buffers.AtomicCounter is true, initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.ATOMIC_COUNTER_BUFFER.
func NewBuffer(glTarget gl.Enum) (me *Buffer)
Initializes and returns --but does not Recreate()-- a new Buffer not yet initialized with any valid GlTarget.
func NewCopyReadBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.COPY_READ_BUFFER.
func NewCopyWriteBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.COPY_WRITE_BUFFER.
func NewDispatchIndirectBuffer() (me *Buffer)
If Support.Buffers.DispatchIndirect is true, initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.DISPATCH_INDIRECT_BUFFER.
func NewDrawIndirectBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.DRAW_INDIRECT_BUFFER.
func NewElementArrayBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.ELEMENT_ARRAY_BUFFER.
func NewPixelPackBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.PIXEL_PACK_BUFFER.
func NewPixelUnpackBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.PIXEL_UNPACK_BUFFER.
func NewShaderStorageBuffer() (me *Buffer)
If Support.Buffers.ShaderStorage is true, initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.SHADER_STORAGE_BUFFER.
func NewTextureBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.TEXTURE_BUFFER.
func NewTransformFeedbackBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.TRANSFORM_FEEDBACK_BUFFER.
func NewUniformBuffer() *Buffer
Initializes and returns --but does not Recreate()-- a new Buffer initialized with a GlTarget of gl.UNIFORM_BUFFER.
func (me *Buffer) Bind()
Binds this buffer object to its current GlTarget.
func (me *Buffer) BindBase(index gl.Uint)
Convenience short-hand for gl.BindBufferBase(). Only permissible if me.GlTarget is gl.TRANSFORM_FEEDBACK_BUFFER or gl.UNIFORM_BUFFER.
func (me *Buffer) BindRange(index gl.Uint, offset gl.Intptr, size gl.Sizeiptr)
Convenience short-hand for gl.BindBufferRange(). Only permissible if me.GlTarget is gl.TRANSFORM_FEEDBACK_BUFFER or gl.UNIFORM_BUFFER.
func (me *Buffer) Dispose()
Deletes this buffer object.
func (me *Buffer) Map(read, write bool) *gl.Ptr
Maps to the client's address space the entire data store of whatever buffer object is currently bound to me.GlTarget.
func (me *Buffer) Recreate(newGlTarget gl.Enum, sizeInBytes gl.Sizeiptr, initialData gl.Ptr, usageHint gl.Enum) (err error)
Deletes this buffer object if applicable, generates it anew, and allocates its data store as specified, populating it with the specified initialData if any. GlTarget is changed to newGlTarget unless 0 is specified.
func (me *Buffer) SubData(offset gl.Intptr, size gl.Sizeiptr, data gl.Ptr) (err error)
Buffers the specified data into this buffer object's data store at the specified offset.
func (me *Buffer) Unbind()
Unbinds whatever buffer object is currently bound to me.GlTarget.
func (me *Buffer) Unmap() gl.Boolean
Convenience short-hand for gl.UnmapBuffer(me.GlTarget)
type Framebuffer struct {
// Set in Create(), this is either gl.READ_FRAMEBUFFER or gl.FRAMEBUFFER
GlTarget gl.Enum
// The OpenGL handle to this framebuffer object.
// This is 0 before calling Create() and after calling Dispose().
GlHandle gl.Uint
}
Encapsulates an OpenGL framebuffer object.
func (me *Framebuffer) AttachRenderbuffer() (rb *FramebufferRenderbuffer)
Attaches the specified renderbuffer to this Framebuffer.
func (me *Framebuffer) AttachRendertexture() (tex *FramebufferRendertexture)
Attaches the specified render texture to this Framebuffer.
func (me *Framebuffer) Bind()
Binds this framebuffer object.
func (me *Framebuffer) Create(width, height gl.Sizei, read bool)
Creates this Framebuffer in OpenGL sized as specified.
func (me *Framebuffer) Dispose()
Deletes this Framebuffer and all attached render textures and render buffers from OpenGL.
func (me *Framebuffer) RenderTextureHandle(index int) gl.Uint
Returns the FramebufferRendertexture attached to me at the specified index.
func (me *Framebuffer) Resize(width, height gl.Sizei) (resized bool)
Resizes this Framebuffer and all attached render textures and render buffers.
func (me *Framebuffer) Status() gl.Enum
The current status of this Framebuffer as returned by gl.CheckFramebufferStatus().
func (me *Framebuffer) Unbind()
Unbinds whatever Framebuffer is currently bound, and binds the "default" framebuffer (typically, the window's drawing surface).
type FramebufferRenderbuffer struct {
// The attachment point of this render buffer.
// Defaults to gl.DEPTH_STENCIL_ATTACHMENT.
Attachment gl.Enum
// Defaults to gl.RENDERBUFFER.
GlTarget gl.Enum
// The OpenGL handle to this render buffer object.
GlHandle gl.Uint
// Defaults to gl.DEPTH24_STENCIL8.
InternalFormat gl.Enum
}
Represents a Renderbuffer that can be attached to a Framebuffer.
func (me *FramebufferRenderbuffer) Bind()
Binds this render buffer object.
func (me *FramebufferRenderbuffer) Init()
func (me *FramebufferRenderbuffer) Unbind()
Unbinds whatever render buffer object is currently bound, if any.
type FramebufferRendertexture struct {
// The texture object being rendered to.
Texture2D
// The attachment point for this render texture object.
// Defaults to gl.COLOR_ATTACHMENT0.
Attachment gl.Enum
}
Represents a render-to-texture object that can be attached to a Framebuffer.
func (me *FramebufferRendertexture) Init()
type GlCache struct {
}
func (_ *GlCache) ActiveTexture(texture gl.Enum)
func (_ *GlCache) BindSampler(textureUnit, glHandle gl.Uint)
func (_ *GlCache) BindTextureTo(textureUnit, glHandle gl.Uint, glTarget gl.Enum)
func (_ *GlCache) BindVertexArray(glHandle gl.Uint)
func (_ *GlCache) UseProgram(glHandle gl.Uint)
type GlMat3 [9]gl.Float
Represents a 3x3 matrix of 9 32-bit gl.Float values
func NewGlMat3(mat *unum.Mat3) (glMat *GlMat3)
Instantiates and returns a new 3x3 matrix (32-bit) from the specified 3x3 matrix (64-bit).
func (me *GlMat3) Load(mat *unum.Mat3)
Sets all values in this 3x3 matrix (32-bit) from the specified 3x3 matrix (64-bit).
type GlMat4 [16]gl.Float
Represents a 3x3 matrix of 16 32-bit gl.Float values
func NewGlMat4(mat *unum.Mat4) (glMat *GlMat4)
Instantiates and returns a new 4x4 matrix (32-bit) from the specified 4x4 matrix (64-bit).
func (me *GlMat4) Load(mat *unum.Mat4)
Sets all values in this 4x4 matrix (32-bit) from the specified 4x4 matrix (64-bit).
type GlTry struct {
}
A singleton type, only used for the package-global ugl.Try variable. (Methods generated with github.com/metaleap/go-opengl/cmd/gen-opengl-bindings.)
func (_ GlTry) AttachShader(program gl.Uint, shader gl.Uint) (err error)
Calls gl.AttachShader() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) BufferData(target gl.Enum, size gl.Sizeiptr, data gl.Ptr, usage gl.Enum) (err error)
Calls gl.BufferData() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) BufferSubData(target gl.Enum, offset gl.Intptr, size gl.Sizeiptr, data gl.Ptr) (err error)
Calls gl.BufferSubData() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) CreateProgram() (err error, tryRetVal__ gl.Uint)
Calls gl.CreateProgram() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) CreateShader(type_ gl.Enum) (err error, tryRetVal__ gl.Uint)
Calls gl.CreateShader() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) GenBuffers(n gl.Sizei, buffers *gl.Uint) (err error)
Calls gl.GenBuffers() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) GenTextures(n gl.Sizei, textures *gl.Uint) (err error)
Calls gl.GenTextures() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) GenVertexArrays(n gl.Sizei, arrays *gl.Uint) (err error)
Calls gl.GenVertexArrays() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) GenerateMipmap(target gl.Enum) (err error)
Calls gl.GenerateMipmap() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) ShaderSource(shader gl.Uint, count gl.Sizei, string_ **gl.Char, length *gl.Int) (err error)
Calls gl.ShaderSource() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) TexImage2D(target gl.Enum, level gl.Int, internalformat gl.Int, width gl.Sizei, height gl.Sizei, border gl.Int, format gl.Enum, type_ gl.Enum, pixels gl.Ptr) (err error)
Calls gl.TexImage2D() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) TexStorage2D(target gl.Enum, levels gl.Sizei, internalformat gl.Enum, width gl.Sizei, height gl.Sizei) (err error)
Calls gl.TexStorage2D() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) TexSubImage2D(target gl.Enum, level gl.Int, xoffset gl.Int, yoffset gl.Int, width gl.Sizei, height gl.Sizei, format gl.Enum, type_ gl.Enum, pixels gl.Ptr) (err error)
Calls gl.TexSubImage2D() and yields the err returned by Util.LastError(), if any.
type GlUtil struct {
}
A singleton type, only used for the package-global ugl.Util variable.
func (_ GlUtil) ConnInfo() string
Returns an OpenGL connection-info string of the format "OpenGL {version} @ {vendor} {renderer} (GLSL: {version})" Example: "OpenGL 4.2.0 @ NVIDIA Corporation Quadro 5010M/PCIe/SSE2 (GLSL: 4.20 NVIDIA via Cg compiler)"
func (_ GlUtil) EnumName(enum gl.Enum) (name string)
Returns the name of the specified enum. Out of the over 1290 possible enum values, currently only supports error codes and shader stages.
func (_ GlUtil) Extension(name string) bool
Returns true if the specified extension (ignoring upper/lower-case) is supported by the current OpenGL context, as per the global Support.Extensions variable. If the extension uses a well-known prefix contained in KnownExtensionPrefixes, it can be omitted, ie. you can just specify "texture_filter_anisotropic" instead of "GL_EXT_texture_filter_anisotropic".
func (_ GlUtil) LastError(msgFmt string, fmtArgs ...interface{}) (err error)
If the GL error flag is currently set, returns an error with the specified message and the GL error flag(s).
func (_ GlUtil) Str(name gl.Enum) string
Returns the specified OpenGL string. Example: GlStr(gl.VENDOR) = "NVIDIA Corporation"
func (_ GlUtil) Stri(name gl.Enum, i gl.Uint) string
Returns the specified OpenGL string at the specified index. For example, GlStri(gl.EXTENSIONS, 0) returns the name of the "first" of all supported extensions.
func (_ GlUtil) Val(name gl.Enum) (val gl.Int)
Returns the specified integer as returned by gl.GetIntegerv(). Example: numExts := GlVal(gl.NUM_EXTENSIONS)
func (_ GlUtil) Vals(name gl.Enum, n uint) (vals []gl.Int)
Returns the specified n integers as returned by gl.GetIntegerv().
type GlVec3 [3]gl.Float
Represents a 3-dimensional vector (32-bit per component)
func (me *GlVec3) Set(vals ...gl.Float)
Sets me to the first 3-or-less vals.
type GlVec4 [4]gl.Float
Represents a quaternion or 4-dimensional vector (32-bit per component)
func (me *GlVec4) Set(vals ...gl.Float)
Sets me to the first 4-or-less vals.
type Program struct {
// The OpenGL handle to the underlying program object.
// This is 0 before calling Create() and after calling Dispose().
GlHandle gl.Uint
// An arbitrary numeric identifier that is of no use to OpenGL.
// This is set by the parent ProgramManager, if any.
Index int
// An arbitrary application-defined name that is of no use to OpenGL, but may aid client-side diagnostics.
Name string
Sources struct {
In ShaderSources
Out ShaderSources
}
Tag interface{}
// All vertex-attributes and their locations mapped for this program object (after the SetAttrLocations() method has been called).
AttrLocs map[string]gl.Uint
// All uniforms and their locations mapped for this program object (after the SetUnifLocations() method has been called).
UnifLocs map[string]gl.Int
}
Represents an OpenGL program object.
func NewProgram(index int, name string) (me *Program)
func (me *Program) CompileAndLinkShaders(defines map[string]interface{}) (err error)
Creates and compiles Shader stages for the specified sources (and defines) and links them together in this Program. All sources are string pointers and WILL be modified by this method to contain the final real GLSL source string sent to GL as returned by Shader.SetSource(). This may aid diagnostics or be discarded, but a source string should not be re-sent to a subsequent compilation in that modified form.
func (me *Program) Create() (err error)
Creates this program object in OpenGL.
func (me *Program) Dispose()
Deletes this program object from OpenGL.
func (me *Program) HasAttr(name string) (ok bool)
Returns true if the specified attribute name is present as a key in me.AttrLocs.
func (me *Program) HasUnif(name string) (ok bool)
Returns true if the specified uniform name is present as a key in me.UnifLocs.
func (me *Program) InfoLog() string
Retrieves and returns the content of the current OpenGL info-log for this shader object.
func (me *Program) Init(index int, name string)
func (me *Program) Link() (err error)
Links this program object. This is a convenience short-hand for calling gl.LinkProgram(), checking gl.LINK_STATUS and obtaining gl.GetProgramInfoLog().
func (me *Program) ParamInt(pname gl.Enum) (iv gl.Int)
Convenience short-hand for gl.GetProgramiv.
func (me *Program) SetAttrLocations(attrNames ...string) (err error)
Stores the locations for the specified vertex-attributes in the AttrLocs field. If an attribute in attrNames isn't found, it will not be added to AttrLocs but this may not result in an error. err is the result of LastError() after each call to gl.GetAttribLocation(), the method immediately returns on the first error encountered.
func (me *Program) SetUnifLocations(unifNames ...string) (err error)
Stores the locations for the specified uniforms in the UnifLocs field. If a uniform in unifNames isn't found, it will not be added to UnifLocs but this may not result in an error. err is the result of LastError() after each call to gl.GetUniformLocation(), the method immediately returns on the first error encountered.
func (me *Program) Uniform1f(name string, v0 gl.Float)
Convenience short-hand for gl.Uniform1f, if this Program contains the specified uniform and v0 differs from its current value.
func (me *Program) Uniform1i(name string, v0 gl.Int)
Convenience short-hand for gl.Uniform1i, if this Program contains the specified uniform and v0 differs from its current value.
func (me *Program) Uniform3fv(name string, count gl.Sizei, value *gl.Float)
Convenience short-hand for gl.Uniform3fv, if this Program contains the specified uniform.
func (me *Program) UniformMat4(name string, mat4 *GlMat4)
func (me *Program) UniformMatrix4fv(name string, count gl.Sizei, transpose gl.Boolean, value *gl.Float)
Convenience short-hand for gl.UniformMatrix4fv, if this Program contains the specified uniform.
func (me *Program) UniformVec3(name string, vec *GlVec3)
func (me *Program) Use()
Installs this program object as part of current rendering state.
func (me *Program) Validate() (err error)
Validates this program object. This is a convenience short-hand for calling gl.ValidateProgram(), checking gl.VALIDATE_STATUS and obtaining gl.GetProgramInfoLog().
type ProgramManager struct {
All []Program
}
func (me *ProgramManager) AddNew(name string) (prog *Program)
func (me *ProgramManager) Dispose()
func (me *ProgramManager) Get(name string) (prog *Program)
func (me *ProgramManager) Index(name string) (index int)
func (me *ProgramManager) Init()
func (me *ProgramManager) MakeProgramsFromRawSources(defines map[string]interface{}, forceAll bool, forceSome ...string) (dur time.Duration, progsMade []bool, err error)
type RenderStates struct {
}
Encapsulates various states in the OpenGL state machine, also providing toggles for some.
RenderStates is designed to facilitate lazy state changes by caching all render states: so unless you call any of the ForceFoo() methods, state changes are only propagated to OpenGL if there is an actual change from the last time that state was set (via any RenderStates instance -- being 'singleton' in design, they all utilize the same backing cache).
func (me RenderStates) Apply(bag *RenderStatesBag)
Calls the applicable me.SetFoo() methods for all render states in bag (except those in bag.Other).
func (me RenderStates) DisableBlending()
Disables blending only if it is currently enabled.
func (me RenderStates) DisableDepthTest()
Disables depth-testing only if it is currently enabled.
func (me RenderStates) DisableFaceCulling()
Disables face-culling only if it is currently enabled.
func (me RenderStates) DisableFramebufferSrgb()
Disables SRGB-framebuffer only if it is currently enabled.
func (me RenderStates) DisableScissorTest()
Disables scissor-testing only if it is currently enabled.
func (me RenderStates) DisableStencilTest()
Disables stencil-testing only if it is currently enabled.
func (me RenderStates) EnableBlending()
Enables blending only if it is currently disabled.
func (me RenderStates) EnableDepthTest()
Enables depth-testing only if it is currently disabled.
func (me RenderStates) EnableFaceCulling()
Enables face-culling only if it is currently disabled.
func (me RenderStates) EnableFramebufferSrgb()
Enables SRGB-framebuffer only if it is currently disabled.
func (me RenderStates) EnableScissorTest()
Enables scissor-testing only if it is currently disabled.
func (me RenderStates) EnableStencilTest()
Enables stencil-testing only if it is currently disabled.
func (_ RenderStates) ForceClearColor(rgba GlVec4)
Sets the OpenGL clear-color to the specified rgba.
func (_ RenderStates) ForceDisableBlending()
Deactivates blending.
func (_ RenderStates) ForceDisableDepthTest()
Deactivates depth-testing.
func (_ RenderStates) ForceDisableFaceCulling()
Deactivates face-culling.
func (_ RenderStates) ForceDisableFramebufferSrgb()
Deactivates SRGB-framebuffer.
func (_ RenderStates) ForceDisableScissorTest()
Deactivates scissor-testing.
func (_ RenderStates) ForceDisableStencilTest()
Deactivates stencil-testing.
func (_ RenderStates) ForceEnableBlending()
Activates blending.
func (_ RenderStates) ForceEnableDepthTest()
Activates depth-testing.
func (_ RenderStates) ForceEnableFaceCulling()
Activates face-culling.
func (_ RenderStates) ForceEnableFramebufferSrgb()
Activates SRGB-framebuffer.
func (_ RenderStates) ForceEnableScissorTest()
Activates scissor-testing.
func (_ RenderStates) ForceEnableStencilTest()
Activates stencil-testing.
func (me RenderStates) SetBlending(newBlending bool)
Activates or deactivates blending.
func (me RenderStates) SetClearColor(rgba GlVec4)
Sets the OpenGL clear-color if rgba differs from the currently cached value.
func (me RenderStates) SetDepthTest(newDepthTest bool)
Activates or deactivates depth-testing.
func (me RenderStates) SetFaceCulling(newFaceCulling bool)
Activates or deactivates face-culling.
func (me RenderStates) SetFramebufferSrgb(newFramebufferSrgb bool)
Activates or deactivates SRGB-framebuffer.
func (me RenderStates) SetScissorTest(newScissorTest bool)
Activates or deactivates scissor-testing.
func (me RenderStates) SetStencilTest(newStencilTest bool)
Activates or deactivates stencil-testing.
func (me RenderStates) ToggleBlending()
Toggles blending.
func (me RenderStates) ToggleDepthTest()
Toggles depth-testing.
func (me RenderStates) ToggleFaceCulling()
Toggles face-culling.
func (me RenderStates) ToggleFramebufferSrgb()
Toggles SRGB-framebuffer.
func (me RenderStates) ToggleScissorTest()
Toggles scissor-testing.
func (me RenderStates) ToggleStencilTest()
Toggles stencil-testing.
type RenderStatesBag struct {
Blending bool
DepthTest bool
FaceCulling bool
StencilTest bool
ClearColor GlVec4
Other struct {
FramebufferSrgb bool
ClearBits gl.Bitfield
}
}
Encapsulates a particular combination of render-states that RenderStates can Apply().
type Sampler struct {
// The OpenGL handle to this sampler object.
// This is 0 before calling Create() and after calling Dispose().
GlHandle gl.Uint
}
Stores sampling parameters for texture accesses.
func (me Sampler) Bind(textureUnit gl.Uint)
Binds this sampler object to the specified textureUnit.
func (me *Sampler) Create() *Sampler
Creates this sampler object.
func (me Sampler) DepthCompareFunc() gl.Int
Returns a single-valued texture comparison function, a symbolic constant. The initial value is GL_LEQUAL.
func (me Sampler) DepthCompareMode() gl.Int
Returns a single-valued texture comparison mode, a symbolic constant. The initial value is gl.NONE.
func (me *Sampler) DisableAllFiltering(allowMip bool) *Sampler
Disables linear and anisotropic filtering on this sampler. If allowMip is true, minified sampling still blends between MIP map levels (just without linear filtering).
func (me *Sampler) Dispose()
Deletes this sampler object.
func (me *Sampler) EnableFullFiltering(allowMip bool, maxAniso gl.Float) *Sampler
Enables linear and anisotropic filtering on this sampler. If allowMip is true, minified sampling blends between MIP map levels linearly filtered.
func (me Sampler) FilterMag() gl.Int
Returns the single-valued texture magnification filter, a symbolic constant. The initial value is GL_LINEAR.
func (me Sampler) FilterMaxAnisotropy() (val gl.Float)
Returns filtering anisotropy. 0 if anisotropic filtering isn't supported, 1 if anisotropic filtering isn't activated for this Sampler, else a value between 1 and Support.Textures.MaxFilterAnisotropy.
func (me Sampler) FilterMin() gl.Int
Returns the single-valued texture minification filter, a symbolic constant. The initial value is GL_NEAREST_MIPMAP_LINEAR.
func (me Sampler) MipLodBias() gl.Float
The mipmap image selection process can be adjusted coarsely by using this sampling parameter.
func (me Sampler) MipLodMax() gl.Float
Returns the single-valued texture maximum level-of-detail value. The initial value is 1000.
func (me Sampler) MipLodMin() gl.Float
Returns the single-valued texture minimum level-of-detail value. The initial value is -1000.
func (me Sampler) ParamFloat(param gl.Enum) (val gl.Float)
A convenience short-hand to invoke gl.GetSamplerParameterfv for this sampler object.
func (me Sampler) ParamInt(param gl.Enum) (val gl.Int)
A convenience short-hand to invoke gl.GetSamplerParameteriv for this sampler object.
func (me Sampler) SetDepthCompareFunc(val gl.Int)
Specifies the comparison operator used when DepthCompareMode() is set to gl.COMPARE_REF_TO_TEXTURE. val may be one of: gl.LEQUAL, gl.GEQUAL, gl.LESS, gl.GREATER, gl.EQUAL, gl.NOTEQUAL, gl.ALWAYS, gl.NEVER.
func (me Sampler) SetDepthCompareMode(val gl.Int)
Specifies the texture comparison mode for currently bound textures whose internal format is gl.DEPTH_COMPONENT_*. val may be either gl.NONE or gl.COMPARE_REF_TO_TEXTURE.
func (me Sampler) SetFilterMag(val gl.Int)
Sets the texture magnification function to either GL_NEAREST or GL_LINEAR.
func (me Sampler) SetFilterMaxAnisotropy(val gl.Float)
Sets filtering anisotropy, if supported. val will be clamped between 1 and Support.Textures.MaxFilterAnisotropy. Only a val greater than 1 will activate anisotropic filtering.
func (me Sampler) SetFilterMin(val gl.Int)
Sets the texture magnification function. val may be one of: GL_NEAREST, GL_LINEAR, gl.NEAREST_MIPMAP_NEAREST, gl.LINEAR_MIPMAP_NEAREST, gl.NEAREST_MIPMAP_LINEAR, gl.LINEAR_MIPMAP_LINEAR.
func (me Sampler) SetMipLodBias(val gl.Float)
This bias will be added to the mipmap LOD calculation (as well as added to the bias specified in one of the texture accessing functions in GLSL), which is used to select the image.
func (me Sampler) SetMipLodMax(val gl.Float)
Sets the maximum level-of-detail parameter. This limits the selection of the lowest resolution mipmap (highest mipmap level).
func (me Sampler) SetMipLodMin(val gl.Float)
Sets the minimum level-of-detail parameter. This limits the selection of highest resolution mipmap (lowest mipmap level).
func (me Sampler) SetParamFloat(param gl.Enum, val gl.Float)
A convenience short-hand to invoke gl.SamplerParameterf for this sampler object.
func (me Sampler) SetParamInt(param gl.Enum, val gl.Int)
A convenience short-hand to invoke gl.SamplerParameteri for this sampler object.
func (me *Sampler) SetWrap(wrapVal gl.Int) *Sampler
A convenience short-hand that calls SetWrapR(), SetWrapS() and SetWrapT() with the specified wrapVal.
func (me Sampler) SetWrapClampBorderColor(val *GlVec4)
Specifies four values that define the border values that should be used for border texels.
func (me Sampler) SetWrapR(val gl.Int)
Sets the wrap parameter for texture coordinate r to gl.CLAMP_TO_EDGE, gl.CLAMP_TO_BORDER, gl.MIRRORED_REPEAT, or gl.REPEAT.
func (me Sampler) SetWrapS(val gl.Int)
Sets the wrap parameter for texture coordinate s to gl.CLAMP_TO_EDGE, gl.CLAMP_TO_BORDER, gl.MIRRORED_REPEAT, or gl.REPEAT.
func (me Sampler) SetWrapT(val gl.Int)
Sets the wrap parameter for texture coordinate t to gl.CLAMP_TO_EDGE, gl.CLAMP_TO_BORDER, gl.MIRRORED_REPEAT, or gl.REPEAT.
func (_ Sampler) Unbind(textureUnit gl.Uint)
Unbinds whatever sampler object is currently bound to the specified textureUnit.
func (me Sampler) WrapClampBorderColor() (val *GlVec4)
Returns four floating-point numbers that comprise the RGBA color of the texture border. The initial value is (0, 0, 0, 0).
func (me Sampler) WrapR() gl.Int
Returns the single-valued wrapping function for texture coordinate r, a symbolic constant. The initial value is gl.REPEAT.
func (me Sampler) WrapS() gl.Int
Returns the single-valued wrapping function for texture coordinate s, a symbolic constant. The initial value is gl.REPEAT.
func (me Sampler) WrapT() gl.Int
Returns the single-valued wrapping function for texture coordinate t, a symbolic constant. The initial value is gl.REPEAT.
type Shader struct {
// The OpenGL handle to the underlying shader object.
// This is 0 before calling Create() and after calling Dispose().
GlHandle gl.Uint
// The shader stage provided by this shader,
// such as for example gl.FRAGMENT_SHADER, gl.VERTEX_SHADER, etc.
Stage gl.Enum
}
Represents an OpenGL shader object.
func NewComputeShader() (me *Shader)
If Support.Glsl.Shaders.ComputeStage is true, initializes and returns --but does not Create()-- a new Shader for the gl.COMPUTE_SHADER Stage with the specified name.
func NewFragmentShader() *Shader
Initializes and returns --but does not Create()-- a new Shader for the gl.FRAGMENT_SHADER Stage with the specified name.
func NewGeometryShader() *Shader
Initializes and returns --but does not Create()-- a new Shader for the gl.GEOMETRY_SHADER Stage with the specified name.
func NewShader(glStage gl.Enum) (me *Shader)
Initializes and returns --but does not Create()-- a new Shader with the specified name and shader stage.
func NewTessCtlShader() (me *Shader)
If Support.Glsl.Shaders.TessellationStages is true, initializes and returns --but does not Create()-- a new Shader for the gl.TESS_CONTROL_SHADER ("Hull") Stage with the specified name.
func NewTessEvalShader() (me *Shader)
If Support.Glsl.Shaders.TessellationStages is true, initializes and returns --but does not Create()-- a new Shader for the gl.TESS_EVALUATION_SHADER ("Domain") Stage with the specified name.
func NewVertexShader() *Shader
Initializes and returns --but does not Create()-- a new Shader for the gl.VERTEX_SHADER Stage with the specified name.
func (me *Shader) AttachTo(prog *Program) error
Attaches this shader object to the specified program object.
func (me *Shader) Compile(name string) (err error)
Compiles this shader object. This is a convenience short-hand for calling gl.CompileShader(), checking gl.COMPILE_STATUS and obtaining gl.GetShaderInfoLog().
func (me *Shader) Create() (err error)
Creates this shader object in OpenGL.
func (me *Shader) DetachFrom(prog *Program)
Detaches this shader object from the specified program object.
func (me *Shader) Dispose()
Deletes this shader object from OpenGL.
func (me *Shader) InfoLog(name string) string
Retrieves and returns the content of the current OpenGL info-log for this shader object.
func (me *Shader) ParamInt(pname gl.Enum) (iv gl.Int)
Convenience short-hand for gl.GetShaderiv.
func (me *Shader) SetSource(source string, defines map[string]interface{}) (finalRealSrc string, err error)
Replaces the GLSL source code in this shader object with source, prepending a #version (core) directive with the current Support.Glsl.Version.Num and #define directives for all specified name-value pairs in defines.
func (me *Shader) StageName() (sn string)
Returns the name of this shader's stage, for example "GL_VERTEX_SHADER", "GL_COMPUTE_SHADER", etc.
type ShaderSources struct {
Compute string
Fragment string
Geometry string
TessCtl string
TessEval string
Vertex string
}
type Texture interface {
Dispose()
// Deletes and (re)creates the texture object based on its current params.
Recreate() error
}
Implemented by specialized texture types such as Texture2D.
type Texture2D struct {
// Common texture params
TextureBase
// Width and height of mip-level 0 for this 2-dimensional texture object.
Width, Height gl.Sizei
}
Represents a 2-dimensional texture image.
func NewTexture2D() (me *Texture2D)
Initializes --but does not Recreate()-- a new Texture2D, calls its Init() method and returns it.
func (me *Texture2D) Init()
Sets GlTarget to gl.TEXTURE_2D and initializes TextureBase with defaults.
func (me *Texture2D) MaxNumMipLevels() gl.Sizei
Returns the maximum number of possible MIP map levels for this 2-dimensional texture image according to its current Width and Height.
func (me *Texture2D) PrepFromImage(bgra, uintRev bool, img image.Image) (err error)
Prepares this Texture2D for uploading the specified Image via Recreate(). This sets all of the following fields to applicable values: me.PixelData.Type, me.PixelData.Format, me.PixelData.Ptrs[0], me.Width, me.Height, me.MipMap.NumLevels, me.SizedInternalFormat
func (me *Texture2D) Recreate() error
Deletes and (re)creates the texture object based on its current params. Uploads the image data at me.PixelData.Ptrs[0], if any. Generates the MIP map if me.MipMap.AutoGen is true and me.MipMap.NumLevels isn't 1. If me.MipMap.NumLevels is 0 (or just smaller than 1), then me.MaxNumMipLevels() is used.
func (me *Texture2D) SubImage(x, y gl.Int, width, height gl.Sizei, ptr gl.Ptr) error
Updates the specified portion of this texture image with the specified pixel data.
type TextureBase struct {
// The OpenGL handle for this texture object.
// This is 0 before calling Recreate() and after calling Dispose().
GlHandle gl.Uint
// The type of texture, such as for example gl.TEXTURE_2D.
GlTarget gl.Enum
// Specifies the sized internal format to be used to store texture image data,
// as per gl.TexStorageNN(). Defaults to gl.RGBA8.
SizedInternalFormat gl.Enum
// If true, then (if Support.Textures.Immutable is also true) whenever this Texture
// is Recreate()d it is declared immutable in OpenGL, meaning its dimensions are
// locked at creation time and cannot be changed subsequently.
// Defaults to Support.Textures.Immutable.
Immutable bool
// Settings for this texture's MIP map, if any.
MipMap struct {
// If true (the default) and NumLevels isn't 1, all MIP map
// levels are automatically generated by Recreate()
AutoGen bool
// The maximum number of MIP map levels for this texture object.
// Set to 0 (the default) to have Recreate() determine this
// automatically, set to 1 for a texture object with no MIP map.
NumLevels gl.Sizei
}
// Information regarding the pixel data stored by this texture object.
PixelData struct {
// Specifies the format of the pixel data, as per
// gl.TexSubImageNN(). Defaults to gl.RGBA.
Format gl.Enum
// Specifies the data type of the pixel data, as per
// gl.TexSubImageNN(). Defaults to gl.UNSIGNED_BYTE.
Type gl.Enum
// Pointers (one per sub-image) to the first pixel
// of the data stream to be uploaded by Recreate().
// Initially defaults to []gl.Ptr { PtrNil }
Ptrs [6]gl.Ptr
}
}
Embedded by specialized texture types such as Texture2D.
func (me *TextureBase) Dispose()
Deletes this texture object from OpenGL.
func (me *TextureBase) ParamBaseLevel() gl.Int
Returns the index of the lowest defined mipmap level. Defaults to 0.
func (me *TextureBase) ParamFloat(param gl.Enum) (val gl.Float)
A convenience short-hand to invoke gl.GetTexParameterfv for the texture object currently bound to me.GlTarget.
func (me *TextureBase) ParamInt(param gl.Enum) (val gl.Int)
A convenience short-hand to invoke gl.GetTexParameteriv for the texture object currently bound to me.GlTarget.
func (me *TextureBase) ParamMaxLevel() gl.Int
Returns the index of the highest defined mipmap level. Defaults to 1000.
func (me *TextureBase) ParamSwizzleA() gl.Int
Returns the swizzle that will be applied to the A component of a texel before it is returned to the shader. Defaults to gl.ALPHA.
func (me *TextureBase) ParamSwizzleB() gl.Int
Returns the swizzle that will be applied to the B component of a texel before it is returned to the shader. Defaults to gl.BLUE.
func (me *TextureBase) ParamSwizzleG() gl.Int
Returns the swizzle that will be applied to the G component of a texel before it is returned to the shader. Defaults to gl.GREEN.
func (me *TextureBase) ParamSwizzleR() gl.Int
Returns the swizzle that will be applied to the R component of a texel before it is returned to the shader. Defaults to gl.RED.
func (me *TextureBase) ParamSwizzleRgba() gl.Int
Returns the swizzle that will be applied to the R, G, B and A components of a texel before it is returned to the shader.
func (me *TextureBase) SetParamBaseLevel(val gl.Int)
Sets the index of the lowest defined mipmap level.
func (me *TextureBase) SetParamFloat(param gl.Enum, val gl.Float)
A convenience short-hand to invoke gl.TexParameterf for the texture object currently bound to me.GlTarget.
func (me *TextureBase) SetParamInt(param gl.Enum, val gl.Int)
A convenience short-hand to invoke gl.TexParameteri for the texture object currently bound to me.GlTarget.
func (me *TextureBase) SetParamMaxLevel(val gl.Int)
Sets the index of the highest defined mipmap level.
func (me *TextureBase) SetParamSwizzleA(val gl.Int)
Sets the swizzle that will be applied to the A component of a texel before it is returned to the shader.
func (me *TextureBase) SetParamSwizzleB(val gl.Int)
Sets the swizzle that will be applied to the B component of a texel before it is returned to the shader.
func (me *TextureBase) SetParamSwizzleG(val gl.Int)
Sets the swizzle that will be applied to the G component of a texel before it is returned to the shader.
func (me *TextureBase) SetParamSwizzleR(val gl.Int)
Sets the swizzle that will be applied to the R component of a texel before it is returned to the shader.
func (me *TextureBase) SetParamSwizzleRgba(val gl.Int)
Sets the swizzle that will be applied to the R, G, B and A components of a texel before it is returned to the shader.
type TextureCube struct {
// Common texture params
TextureBase
// Width and height of mip-level 0 for all 6 cube-faces.
Width, Height gl.Sizei
}
Represents six 2-dimensional texture images of equal dimensions.
func NewTextureCube() (me *TextureCube)
Initializes --but does not Recreate()-- a new TextureCube, calls its Init() method and returns it.
func (me *TextureCube) Init()
Sets GlTarget to gl.TEXTURE_CUBE_MAP and initializes TextureBase with defaults.
func (me *TextureCube) MaxNumMipLevels() gl.Sizei
Returns the maximum number of possible MIP map levels for any of this cube-map's 6 faces according to its current Width and Height.
func (me *TextureCube) PrepFromImages(bgra, uintRev bool, images ...image.Image) (err error)
Prepares this TextureCube for uploading the specified Images via Recreate(). This sets all of the following fields to applicable values: me.PixelData.Type, me.PixelData.Format, me.PixelData.Ptrs, me.Width, me.Height, me.MipMap.NumLevels, me.SizedInternalFormat
func (me *TextureCube) Recreate() error
Deletes and (re)creates the texture object based on its current params. Uploads the image data pointed to in me.PixelData.Ptrs, if any. Generates the MIP map if me.MipMap.AutoGen is true and me.MipMap.NumLevels isn't 1. If me.MipMap.NumLevels is 0 (or just smaller than 1), then me.MaxNumMipLevels() is used.
func (me *TextureCube) SubImage(glTargetFace gl.Enum, x, y gl.Int, width, height gl.Sizei, ptr gl.Ptr) error
Updates the specified portion of the specified cube-face image with the specified pixel data.
type TypeUtils struct {
}
A singleton type, only used for the package-global ugl.Typed variable.
func (_ TypeUtils) Clamp(val, min, max gl.Float) gl.Float
Clamps the specified val between min and max.
func (_ TypeUtils) Ifb(one, two bool, ifOne, ifTwo, ifBoth gl.Enum) (val gl.Enum)
If one but not two, return ifOne. If two but not one, return ifTwo. Else, return ifBoth.
func (_ TypeUtils) Ife(cond bool, ifTrue, ifFalse gl.Enum) gl.Enum
Returns ifTrue if cond is true, otherwise returns ifFalse.
func (_ TypeUtils) Ifi(cond bool, ifTrue, ifFalse gl.Int) gl.Int
Returns ifTrue if cond is true, otherwise returns ifFalse.
type UniformBlock struct {
Buffer Buffer
Name string
}
func NewUniformBlock(name string) (me *UniformBlock)
func (me *UniformBlock) Create()
func (me *UniformBlock) Dispose()
type VertexArray struct {
// The OpenGL handle to this vertex array object.
// This is 0 before calling Create() and after calling Dispose().
GlHandle gl.Uint
}
Represents an OpenGL vertex array object (NOT the legacy OpenGL "vertex arrays", but what is commonly abbreviated as VAO).
func (me *VertexArray) Bind()
Binds this vertex array object.
func (me *VertexArray) Create() (err error)
Creates this vertex-array object.
func (me *VertexArray) Dispose()
Deletes this vertex array object.
func (me *VertexArray) Setup(prog *Program, atts []VertexAttribPointer, bufs ...*Buffer) (err error)
Sets up this vertex array object. Unless atts are specified, prog can be be nil. To specify element/index buffer and vertex/attribute buffers (if applicable), pass them via bufs.
func (_ VertexArray) Unbind()
Unbinds whatever vertex array object is currently bound.
type VertexAttribPointer struct {
// The name of the vertex attribute in a Program.AttrLocs hash-table.
Name string
// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.
// Additionally, the symbolic constant GL_BGRA is accepted.
Size gl.Int
// Defaults to gl.FLOAT
Type gl.Enum
// Defaults to gl.FALSE
Normalized gl.Boolean
// Specifies the byte offset between consecutive generic vertex attributes.
// If Stride is 0, the generic vertex attributes are understood to be tightly packed in the array.
Stride gl.Sizei
// Specifies an offset of the first component of the first generic vertex attribute in the array
// in the data store of the Buffer currently bound to the gl.ARRAY_BUFFER target.
Offset gl.Ptr
}
Encapsulates vertex attribute information used by VertexArray.Setup() to enable that vertex attribute.
func NewVertexAttribPointer(name string, size gl.Int, stride gl.Sizei, offset gl.Ptr) (me *VertexAttribPointer)
Initializes and returns a new VertexAttribPointer with the specified values.
func (me *VertexAttribPointer) Init(name string, size gl.Int, stride gl.Sizei, offset gl.Ptr)
-- godocdown http://github.com/robertkrimen/godocdown