struct Gloop::Shader

Overview

Base type for all shaders. Encapsulates functionality for working with a stage of the graphics processing pipeline.

See: https://www.khronos.org/opengl/wiki/Shader

Included Modules

Defined in:

gloop/shader.cr
gloop/shader/compilation_error.cr
gloop/shader/type.cr

Constructors

Instance Method Summary

Instance methods inherited from struct Gloop::Object

context : Context context, name : Name name, none? none?, object_type object_type, to_s(io) to_s, to_unsafe : UInt32 to_unsafe

Constructor methods inherited from struct Gloop::Object

new(context : Context, name : Name) new, none(context) : self none

Instance methods inherited from module Gloop::Labelable

label : String label, label=(label : Nil)
label=(label)
label=
, max_label_size : Int32 max_label_size, name name, object_type object_type

Constructor Detail

def self.create(context : Context, type : Type) : self #

Creates an empty shader of the specified type.

  • OpenGL function: glCreateShader
  • OpenGL version: 2.0
  • OpenGL enum GL_COMPUTE_SHADER available in version 4.3 or higher

[View source]

Instance Method Detail

def compile : Bool #

Attempts to compile the shader.

Returns true if the compilation was successful, false otherwise.

The source of the shader must be previously set by calling #source= or #sources=. The result of the compilation can be checked with #compiled?. Additional information from the compilation may be available from #info_log.

See: #compile!

  • OpenGL function: glCompileShader
  • OpenGL version: 2.0

[View source]
def compile! : Nil #

Attempts to compile the shader.

Raises CompilationError if the compilation fails.

The source of the shader must be previously set by calling #source= or #sources=. Additional information from the compilation may be available from #info_log.

See: #compile

  • OpenGL function: glCompileShader
  • OpenGL version: 2.0

[View source]
def compiled? : Bool #

Checks if this shader was compiled successfully.

See: #compile

  • OpenGL function: glGetShaderiv
  • OpenGL enum: GL_COMPILE_STATUS
  • OpenGL version: 2.0

[View source]
def delete : Nil #

Deletes this shader object.

Frees memory and invalidates the name associated with this shader object. This method effectively undoes the effects of a call to .create.

If this shader object is attached to a Program object, it will be flagged for deletion, but it will not be deleted until it is no longer attached to any Program object, for any rendering context.

See: #deleted?

  • OpenGL function: glDeleteShader
  • OpenGL version: 2.0

[View source]
def deleted? : Bool #

Checks if this shader is flagged for deletion.

See: #delete

  • OpenGL function: glGetShaderiv
  • OpenGL enum: GL_DELETE_STATUS
  • OpenGL version: 2.0

[View source]
def exists? #

Determines if this shader is known to the context.

Returns true if this shader was previously created with .create and not yet deleted with #delete.

  • OpenGL function: glIsShader
  • OpenGL version: 2.0

[View source]
def info_log : String | Nil #

Retrieves information about the shader's compilation.

Nil will be returned if there's no log available.

The information log is OpenGL's mechanism for conveying information about the compilation to application developers. Even if the compilation was successful, some useful information may be in it.

  • OpenGL function: glGetShaderInfoLog
  • OpenGL version: 2.0

[View source]
def info_log_size #

Retrieves the size of the information log for this shader.

If the log is unavailable, nil is returned.

See: #info_log

  • OpenGL function: glGetShaderiv
  • OpenGL enum: GL_INFO_LOG_LENGTH
  • OpenGL version: 2.0

[View source]
def object_type #

Indicates that this is a shader object.


[View source]
def source : String | Nil #

Retrieves the shader's source code.

This will be the concatenation if multiple sources were provided (see #sources=). Nil is returned if the source is not available.

  • OpenGL function: glGetShaderSource
  • OpenGL version: 2.0

[View source]
def source=(source) #

Updates the source code for the shader.

This does not compile the shader, it merely stores the source code. Any existing source code will be replaced. If source is not already a string, it will be stringified by calling #to_s on it.

  • OpenGL function: glShaderSource
  • OpenGL version: 2.0

[View source]
def source_size #

Retrieves the size of this shadaer's source code.

If the source is unavailable, nil is returned.

See: #source

  • OpenGL function: glGetShaderiv
  • OpenGL enum: GL_SHADER_SOURCE_LENGTH
  • OpenGL version: 2.0

[View source]
def sources=(sources : Enumerable) #

Updates the source code for the shader.

This does not compile the shader, it merely stores the source code. Any existing source code will be replaced. The sources must be a collection of items that can be stringified (or already strings).

  • OpenGL function: glShaderSource
  • OpenGL version: 2.0

[View source]
def type : Gloop::Shader::Type #

Retrieves the type of this shader.

  • OpenGL function: glGetShaderiv
  • OpenGL enum: GL_SHADER_TYPE
  • OpenGL version: 2.0

[View source]