Class: Hate::Graphics::Shader::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hate/graphics/shader.rb

Direct Known Subclasses

Fragment, Vertex

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Base

Returns a new instance of Base.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hate/graphics/shader.rb', line 31

def initialize(file)
  source = []
  source << MemoryPointer.from_string(File.open(file).read)
  arg = MemoryPointer.new(:pointer, source.length)
  source.each_with_index do |p, i|
    arg[i].put_pointer(0, p)
  end

  if self.class == Hate::Graphics::Shader::Vertex
    @shader = glCreateShader(GL_VERTEX_SHADER)
  elsif self.class == Hate::Graphics::Shader::Fragment
    @shader = glCreateShader(GL_FRAGMENT_SHADER)
  end  
  
  glShaderSource(@shader, source.size, arg, nil)
  glCompileShader(@shader)
end

Instance Attribute Details

#shaderObject (readonly)

Returns the value of attribute shader.



29
30
31
# File 'lib/hate/graphics/shader.rb', line 29

def shader
  @shader
end