Class: Roglew::Shader

Inherits:
Object
  • Object
show all
Defined in:
lib/roglew/extensions/GL_VERSION_2_0/shader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle, type, src = nil) ⇒ Shader

Returns a new instance of Shader.

Raises:



5
6
7
8
9
10
11
12
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 5

def initialize(handle, type, src = nil)
  @handle, @type = handle, type
  @id = handle.bind { handle.glCreateShader(type) }
  raise OpenGLError, "couldn't create a shader of type #{type.to_s(16)}" if @id == 0
  compile(File.file?(src) ? File.read(src) : src) if src

  ObjectSpace.define_finalizer(self, self.class.finalize(@id, @handle))
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



3
4
5
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 3

def handle
  @handle
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 3

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 3

def type
  @type
end

Class Method Details

.finalize(id, handle) ⇒ Object



14
15
16
17
18
19
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 14

def self.finalize(id, handle)
  proc do
    #puts "releasing shader #{id}"
    handle.bind { handle.glDeleteShader(id) }
  end
end

Instance Method Details

#compile(src) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 21

def compile(src)
  @handle.bind do |context|
    context.shader_sources(@id, src)
    @handle.glCompileShader(@id)
    raise CompileError, info_log unless compile_status
  end
end

#compile_statusObject Also known as: compiled?



29
30
31
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 29

def compile_status
  @handle.bind { |context| context.get_shader(@id, GL::COMPILE_STATUS) }
end

#delete_statusObject



33
34
35
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 33

def delete_status
  @handle.bind { |context| context.get_shader(@id, GL::DELETE_STATUS) }
end

#info_logObject



41
42
43
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 41

def info_log
  @handle.bind { |context| context.get_shader_info_log(@id) }
end

#info_log_lengthObject



37
38
39
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 37

def info_log_length
  @handle.bind { |context| context.get_shader(@id, GL::INFO_LOG_LENGTH) }
end

#source_lengthObject



45
46
47
# File 'lib/roglew/extensions/GL_VERSION_2_0/shader.rb', line 45

def source_length
  @handle.bind { |context| context.get_shader(@id, GL::SHADER_SOURCE_LENGTH) }
end