struct Gloop::Context

Overview

Provides information about a pre-existing OpenGL context and methods for calling methods within the context.

Gloop does not provide a means of acquiring an OpenGL context. Another mechanism is needed to create an OpenGL context. Some possibilities are GLFW, SFML, and SDL.

Included Modules

Defined in:

gloop/attributes.cr
gloop/buffer.cr
gloop/buffers.cr
gloop/capability.cr
gloop/context.cr
gloop/context/flags.cr
gloop/context/profile.cr
gloop/debug.cr
gloop/extension_list.cr
gloop/loaders.cr
gloop/program.cr
gloop/shader.cr
gloop/shading_language_version_list.cr
gloop/texture.cr
gloop/textures.cr
gloop/uniforms.cr
gloop/vertex_array.cr
gloop/vertex_array/current.cr
gloop/vertex_array/current_bindings.cr

Constructors

Instance Method Summary

Instance methods inherited from module Gloop::RenderCommands

clear(mask : ClearMask = :all) : Nil clear, clear_color : Color clear_color, clear_color=(color : FloatColorTuple)
clear_color=(color : Color)
clear_color=
, clear_depth : Float64 clear_depth, clear_depth=(depth : Float64)
clear_depth=(depth : Float32)
clear_depth=
, clear_stencil : Int32 clear_stencil, clear_stencil=(stencil : Int32) clear_stencil=, finish : Nil finish, flush : Nil flush, viewport : Rect viewport, viewport=(rect : Tuple(Int32, Int32, Int32, Int32))
viewport=(rect : Rect)
viewport=

Instance methods inherited from module Gloop::DrawCommands

disable_primitive_restart disable_primitive_restart, disable_primitive_restart_fixed_index disable_primitive_restart_fixed_index, draw_arrays(mode : Primitive, start : Int32, count : Int32) : Nil
draw_arrays(mode : Primitive, range : Range(Int32, Int32)) : Nil
draw_arrays
, draw_elements(mode : Primitive, count : Int32, type : IndexType, offset : Size) : Nil
draw_elements(mode : Primitive, count : Int32, type : UInt8.class, offset : Size) : Nil
draw_elements(mode : Primitive, count : Int32, type : UInt16.class, offset : Size) : Nil
draw_elements(mode : Primitive, count : Int32, type : UInt32.class, offset : Size) : Nil
draw_elements
, enable_primitive_restart enable_primitive_restart, enable_primitive_restart_fixed_index enable_primitive_restart_fixed_index, primitive_restart=(flag) primitive_restart=, primitive_restart? primitive_restart?, primitive_restart_fixed_index=(flag) primitive_restart_fixed_index=, primitive_restart_fixed_index? primitive_restart_fixed_index?, primitive_restart_index : UInt32 primitive_restart_index, primitive_restart_index=(index : UInt32) primitive_restart_index=

Constructor Detail

def self.from_glfw : self #

Creates a context from GLFW.

This relies on the GLFW shard being available. The context must be current on the calling thread when calling this method.

# Initialization and window creation code.
LibGLFW.init
window = LibGLFW.create_window(640, 480, "Gloop", nil, nil)
LibGLFW.make_context_current(window)

# Create Gloop context from GLFW.
context = Gloop::Context.from_glfw

[View source]
def self.from_sdl : self #

Creates a context from SDL.

This relies on the SDL shard being available. The context must be current on the calling thread when calling this method.

# Initialization and window creation code.
SDL.init(SDL::Init::VIDEO)
window = SDL::Window.new("Gloop", 640, 480, flags: SDL::Window::Flags::OPENGL)
context = LibSDL.gl_create_context(window)
LibSDL.gl_make_current(window, context)

# Create Gloop context from SDL.
context = Gloop::Context.from_sdl

[View source]
def self.new(loader : OpenGL::Loader) #

Constructs a reference to an existing context with pre-loaded functions.

The loader should be setup with OpenGL function addresses.


[View source]
def self.new(&block : String -> Pointer(Void)) #

Constructs a reference to an existing context.

Uses a generic loader to retrieve addresses of OpenGL functions. A block must be provided that retrieves OpenGL functions. It takes a function name as an argument and returns a pointer (address) to the function. The address must correspond to the currently bound context. If the function is unavailable, a null pointer should be returned by the block.


[View source]

Instance Method Detail

def attributes : Attributes #

Information for all attributes in the bound vertex array.


[View source]

Information about vertex buffer and attribute binding slots.


[View source]
def bound_vertex_array : VertexArray::Current #

Always references the currently bound vertex array.

See: VertexArray::Current


[View source]
def buffers : Buffers #

Retrieves an interface for the buffer binding targets for this context.


[View source]
def capability(value : Capability::Enum) : Capability #

Retrieves a reference to the specified capability for this context.


[View source]
def create_buffer : Buffer #

Creates a buffer in this context.

See: Buffer.create


[View source]
def create_buffers(count : Int) : BufferList #

Creates multiple buffers in this context.

See: BufferList.create


[View source]
def create_program : Program #

Creates an empty program.

See: Program.create


[View source]
def create_shader(type : Shader::Type) : Shader #

Creates an empty shader of the specified type.

See: Shader.create


[View source]
def create_texture(type : Texture::Target) : Texture #

Creates a new texture of the specified type.

See: Texture.create


[View source]
def create_texture(type : Symbol) : Texture #

Creates a new texture of the specified type.

See: Texture.create


[View source]
def create_textures(type : Texture::Target, count : Int) : TextureList #

Creates multiple textures of the specified type.

See: Texture.create


[View source]
def create_textures(type : Symbol, count : Int) : TextureList #

Creates multiple textures of the specified type.

See: Texture.create


[View source]
def create_vertex_array : VertexArray #

Creates a vertex array in this context.

See: VertexArray.create


[View source]
def create_vertex_arrays(count : Int) : VertexArrayList #

Creates multiple vertex arrays in this context.

See: VertexArrayList.create


[View source]
def debug : Debug #

Provides access to debug functionality for this context.


[View source]
def disable(value : Capability::Enum) #

Disables the specified capability for this context.

See: Capability#disable


[View source]
def enable(value : Capability::Enum) #

Enables the specified capability for this context.

See: Capability#enable


[View source]
def enabled?(value : Capability::Enum) #

Checks if the specified capability for this context is enabled.

See: Capability#enabled?


[View source]
def extensions : ExtensionList #

Retrieves a list of extensions for this context.


[View source]
def flags : Gloop::Context::Flags #

Retrieves flags that were set when the context was created (such as debugging functionality).

  • OpenGL function: glGetIntegerv
  • OpenGL enum: GL_CONTEXT_FLAGS
  • OpenGL version: 2.0

[View source]
def generate_buffer : Buffer #

Generates a buffer in this context.

See: Buffer.generate


[View source]
def generate_buffers(count : Int) : BufferList #

Generates multiple buffer in this context.

See: BufferList.generate


[View source]
def generate_texture : Texture #

Generates a new texture.

See: Texture.generate


[View source]
def generate_textures(count : Int) : TextureList #

Generates multiple textures.

See: Texture.generate


[View source]
def generate_vertex_array : VertexArray #

Generates a vertex array in this context.

See: VertexArray.generate


[View source]
def generate_vertex_arrays(count : Int) : VertexArrayList #

Generates multiple vertex arrays in this context.

See: VertexArrayList.generate


[View source]
def gl : Gloop::Context::Proxy #

Provides access to OpenGL functions.

OpenGL functions can be called by using their "Crystalized" name.

context.gl.bind_buffer(target, buffer)

See: https://gitlab.com/arctic-fox/opengl.cr/-/blob/master/README.md#libgl

When compiling in debug mode or with error checking explicitly enabled (-Derror_checking), function pointers are checked prior to calling them. An error is raised if an unloaded or unavailable function is called. Additionally, glGetError is called after each method. An error is raised if the function produced an error.

In release mode or with error checking disabled, these checks are skipped. Calls to unloaded and unavailable functions can crash the program. Errors are not raised after invalid OpenGL function calls.


[View source]
def major_version : Int32 #

Retrieves the major version number of the OpenGL API supported by the current context.

For instance, if the OpenGL version is 4.6, 4 is returned.

  • OpenGL function: glGetIntegerv
  • OpenGL enum: GL_MAJOR_VERSION
  • OpenGL version: 2.0

[View source]
def minor_version : Int32 #

Retrieves the minor version number of the OpenGL API supported by the current context.

For instance, if the OpenGL version is 4.6, 6 is returned.

  • OpenGL function: glGetIntegerv
  • OpenGL enum: GL_MINOR_VERSION
  • OpenGL version: 2.0

[View source]
def profile : Gloop::Context::Profile #

Retrieves the kinds of contexts supported.

  • OpenGL function: glGetIntegerv
  • OpenGL enum: GL_CONTEXT_PROFILE_MASK
  • OpenGL version: 3.2

[View source]
def program : Program #

Retrieves the current program in use.

Returns a null-object (Object.none) if there isn't a program in use.

See: Program.current


[View source]
def program? : Program | Nil #

Retrieves the current program in use.

Returns a nil if there isn't a program in use.

See: Program.current?


[View source]
def release_shader_compiler : Nil #

Releases resources held by the OpenGL implementation shader compiler.

This method hints that resources held by the compiler can be released. Additional shaders can be compiled after calling this method, and the resources will be reallocated first.

  • OpenGL function: glReleaseShaderCompiler
  • OpenGL version: 4.1

[View source]
def renderer : String #

Retrieves a string containing the name of the renderer.

This name is typically specific to a particular configuration of a hardware platform. It does not change from release to release.

  • OpenGL function: glGetString
  • OpenGL enum: GL_RENDERER
  • OpenGL version: 2.0

[View source]
def shading_language_version : String #

Retrieves a version or release number for the shading language (GLSL).

This usually takes the form:

MAJOR.MINOR[.RELEASE][ VENDOR]

Vendor-specific information may follow the version string. Its format depends on the implementation, but a space always separates the version number and the vendor-specific information.

  • OpenGL function: glGetString
  • OpenGL enum: GL_SHADING_LANGUAGE_VERSION
  • OpenGL version: 2.0

[View source]
def shading_language_versions : ShadingLanguageVersionList #

Retrieves a list of supported GLSL versions for this context.


[View source]
def textures : Textures #

Retrieves an interface for the texture binding targets for this context.


[View source]
def unbind_vertex_array : Nil #

Unbinds any existing vertex array from the context's rendering state.

See: VertexArray.unbind


[View source]
def uniforms : Uniforms #

References uniforms for the active program.


[View source]
def uninstall_program : Nil #

Uninstalls any existing program from the context's rendering state.

See: Program.uninstall


[View source]
def vendor : String #

Retrieves a string containing the name of the company responsible for this GL implementation.

This name does not change from release to release.

  • OpenGL function: glGetString
  • OpenGL enum: GL_VENDOR
  • OpenGL version: 2.0

[View source]
def version : String #

Retrieves a version or release number.

This usually takes the form:

MAJOR.MINOR[.RELEASE][ VENDOR]

Vendor-specific information may follow the version string. Its format depends on the implementation, but a space always separates the version number and the vendor-specific information.

  • OpenGL function: glGetString
  • OpenGL enum: GL_VERSION
  • OpenGL version: 2.0

[View source]
def vertex_array : VertexArray #

Retrieves the currently bound vertex array.

Returns a null-object (Object.none) if there isn't a vertex array bound.

See: VertexArray.current


[View source]
def vertex_array? : VertexArray | Nil #

Retrieves the currently bound vertex array.

Returns a nil if there isn't a vertex array bound.

See: VertexArray.current?


[View source]