Class: Roglew::Shader
- Inherits:
-
Object
- Object
- Roglew::Shader
- Defined in:
- lib/roglew/extensions/GL_VERSION_2_0/shader.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #compile(src) ⇒ Object
- #compile_status ⇒ Object (also: #compiled?)
- #delete_status ⇒ Object
- #info_log ⇒ Object
- #info_log_length ⇒ Object
-
#initialize(handle, type, src = nil) ⇒ Shader
constructor
A new instance of Shader.
- #source_length ⇒ Object
Constructor Details
#initialize(handle, type, src = nil) ⇒ Shader
Returns a new instance of Shader.
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
#handle ⇒ Object (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 |
#id ⇒ Object (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 |
#type ⇒ Object (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_status ⇒ Object 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_status ⇒ Object
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_log ⇒ Object
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_length ⇒ Object
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_length ⇒ Object
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 |