struct Gloop::Context
- Gloop::Context
- Struct
- Value
- Object
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
- Gloop::DrawCommands
- Gloop::Parameters
- Gloop::RenderCommands
Defined in:
gloop/attributes.crgloop/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
-
.from_glfw : self
Creates a context from GLFW.
-
.from_sdl : self
Creates a context from SDL.
-
.new(loader : OpenGL::Loader)
Constructs a reference to an existing context with pre-loaded functions.
-
.new(&block : String -> Pointer(Void))
Constructs a reference to an existing context.
Instance Method Summary
-
#attributes : Attributes
Information for all attributes in the bound vertex array.
-
#bindings : VertexArray::CurrentBindings
Information about vertex buffer and attribute binding slots.
-
#bound_vertex_array : VertexArray::Current
Always references the currently bound vertex array.
-
#buffers : Buffers
Retrieves an interface for the buffer binding targets for this context.
-
#capability(value : Capability::Enum) : Capability
Retrieves a reference to the specified capability for this context.
-
#create_buffer : Buffer
Creates a buffer in this context.
-
#create_buffers(count : Int) : BufferList
Creates multiple buffers in this context.
-
#create_program : Program
Creates an empty program.
-
#create_shader(type : Shader::Type) : Shader
Creates an empty shader of the specified type.
-
#create_texture(type : Texture::Target) : Texture
Creates a new texture of the specified type.
-
#create_texture(type : Symbol) : Texture
Creates a new texture of the specified type.
-
#create_textures(type : Texture::Target, count : Int) : TextureList
Creates multiple textures of the specified type.
-
#create_textures(type : Symbol, count : Int) : TextureList
Creates multiple textures of the specified type.
-
#create_vertex_array : VertexArray
Creates a vertex array in this context.
-
#create_vertex_arrays(count : Int) : VertexArrayList
Creates multiple vertex arrays in this context.
-
#debug : Debug
Provides access to debug functionality for this context.
-
#disable(value : Capability::Enum)
Disables the specified capability for this context.
-
#enable(value : Capability::Enum)
Enables the specified capability for this context.
-
#enabled?(value : Capability::Enum)
Checks if the specified capability for this context is enabled.
-
#extensions : ExtensionList
Retrieves a list of extensions for this context.
-
#flags : Gloop::Context::Flags
Retrieves flags that were set when the context was created (such as debugging functionality).
-
#generate_buffer : Buffer
Generates a buffer in this context.
-
#generate_buffers(count : Int) : BufferList
Generates multiple buffer in this context.
-
#generate_texture : Texture
Generates a new texture.
-
#generate_textures(count : Int) : TextureList
Generates multiple textures.
-
#generate_vertex_array : VertexArray
Generates a vertex array in this context.
-
#generate_vertex_arrays(count : Int) : VertexArrayList
Generates multiple vertex arrays in this context.
-
#gl : Gloop::Context::Proxy
Provides access to OpenGL functions.
-
#major_version : Int32
Retrieves the major version number of the OpenGL API supported by the current context.
-
#minor_version : Int32
Retrieves the minor version number of the OpenGL API supported by the current context.
-
#profile : Gloop::Context::Profile
Retrieves the kinds of contexts supported.
-
#program : Program
Retrieves the current program in use.
-
#program? : Program | Nil
Retrieves the current program in use.
-
#release_shader_compiler : Nil
Releases resources held by the OpenGL implementation shader compiler.
-
#renderer : String
Retrieves a string containing the name of the renderer.
-
#shading_language_version : String
Retrieves a version or release number for the shading language (GLSL).
-
#shading_language_versions : ShadingLanguageVersionList
Retrieves a list of supported GLSL versions for this context.
-
#textures : Textures
Retrieves an interface for the texture binding targets for this context.
-
#unbind_vertex_array : Nil
Unbinds any existing vertex array from the context's rendering state.
-
#uniforms : Uniforms
References uniforms for the active program.
-
#uninstall_program : Nil
Uninstalls any existing program from the context's rendering state.
-
#vendor : String
Retrieves a string containing the name of the company responsible for this GL implementation.
-
#version : String
Retrieves a version or release number.
-
#vertex_array : VertexArray
Retrieves the currently bound vertex array.
-
#vertex_array? : VertexArray | Nil
Retrieves the currently bound vertex array.
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) : Nildraw_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
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
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
Constructs a reference to an existing context with pre-loaded functions.
The loader should be setup with OpenGL function addresses.
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.
Instance Method Detail
Information about vertex buffer and attribute binding slots.
Always references the currently bound vertex array.
See: VertexArray::Current
Retrieves an interface for the buffer binding targets for this context.
Retrieves a reference to the specified capability for this context.
Creates multiple buffers in this context.
See: BufferList.create
Creates an empty shader of the specified type.
See: Shader.create
Creates a new texture of the specified type.
See: Texture.create
Creates a new texture of the specified type.
See: Texture.create
Creates multiple textures of the specified type.
See: Texture.create
Creates multiple textures of the specified type.
See: Texture.create
Creates a vertex array in this context.
See: VertexArray.create
Creates multiple vertex arrays in this context.
Disables the specified capability for this context.
See: Capability#disable
Enables the specified capability for this context.
See: Capability#enable
Checks if the specified capability for this context is enabled.
See: Capability#enabled?
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
Generates a buffer in this context.
See: Buffer.generate
Generates multiple buffer in this context.
See: BufferList.generate
Generates multiple textures.
See: Texture.generate
Generates a vertex array in this context.
See: VertexArray.generate
Generates multiple vertex arrays in this context.
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.
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
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
Retrieves the kinds of contexts supported.
- OpenGL function:
glGetIntegerv
- OpenGL enum:
GL_CONTEXT_PROFILE_MASK
- OpenGL version: 3.2
Retrieves the current program in use.
Returns a null-object (Object.none
) if there isn't a program in use.
See: Program.current
Retrieves the current program in use.
Returns a nil
if there isn't a program in use.
See: Program.current?
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
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
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
Retrieves a list of supported GLSL versions for this context.
Retrieves an interface for the texture binding targets for this context.
Unbinds any existing vertex array from the context's rendering state.
See: VertexArray.unbind
Uninstalls any existing program from the context's rendering state.
See: Program.uninstall
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
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
Retrieves the currently bound vertex array.
Returns a null-object (Object.none
) if there isn't a vertex array bound.
See: VertexArray.current
Retrieves the currently bound vertex array.
Returns a nil
if there isn't a vertex array bound.
See: VertexArray.current?