Class: Gl::Program

Inherits:
GlInternalMarked show all
Defined in:
lib/opengl-core/aux/program.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GlInternalMarked

#==, #__mark__, __marked_allocated__, #__unmark__, allocated, clear_all, delete_all, inherited, #marked?

Constructor Details

#initialize(name = nil) ⇒ Program

Returns a new instance of Program.



11
12
13
14
15
16
17
18
19
# File 'lib/opengl-core/aux/program.rb', line 11

def initialize(name = nil)
  super()
  @name = (name != 0 && name) || Gl.glCreateProgram()

  @validate_status   = nil
  @link_status       = nil
  @uniform_locations = {}
  __mark__
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/opengl-core/aux/program.rb', line 9

def name
  @name
end

Instance Method Details

#__reload_uniforms__Object



41
42
43
44
45
46
# File 'lib/opengl-core/aux/program.rb', line 41

def __reload_uniforms__
  @uniform_locations.keys.each {
    |key|
    @uniform_locations[key] = Gl.glGetUniformLocation(@name, key.to_s)
  }
end

#attach_shader(shader) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/opengl-core/aux/program.rb', line 80

def attach_shader(shader)
  case shader
  when ::Gl::Shader then Gl.glAttachShader(@name, shader.name)
  else Gl.glAttachShader(@name, shader)
  end
  self
end

#binaryObject



28
29
30
# File 'lib/opengl-core/aux/program.rb', line 28

def binary
  Gl.glGetProgramBinary(@name)
end

#bind_attrib_location(attrib_index, attrib_name) ⇒ Object



112
113
114
115
# File 'lib/opengl-core/aux/program.rb', line 112

def bind_attrib_location(attrib_index, attrib_name)
  Gl.glBindAttribLocation(@name, attrib_index, attrib_name.to_s)
  self
end

#bind_frag_data_location(color_number, frag_data_name) ⇒ Object



117
118
119
120
# File 'lib/opengl-core/aux/program.rb', line 117

def bind_frag_data_location(color_number, frag_data_name)
  Gl.glBindFragDataLocation(@name, color_number, frag_data_name.to_s)
  self
end

#deleteObject



32
33
34
35
36
37
38
39
# File 'lib/opengl-core/aux/program.rb', line 32

def delete
  if @name != 0
    Gl.glDeleteProgram(@name)
    @name = 0
    super
  end
  self
end

#each_hinted_uniform(&block) ⇒ Object



102
103
104
105
106
# File 'lib/opengl-core/aux/program.rb', line 102

def each_hinted_uniform(&block)
  return @uniform_locations.each_key unless block_given?
  @uniform_locations.each_key(&block)
  self
end

#hint_uniform(uniform_name) ⇒ Object



88
89
90
91
92
# File 'lib/opengl-core/aux/program.rb', line 88

def hint_uniform(uniform_name)
  uniform_name = uniform_name.to_sym
  @uniform_locations[uniform_name] ||= -1
  self
end

#info_logObject



71
72
73
# File 'lib/opengl-core/aux/program.rb', line 71

def info_log
  Gl.glGetProgramInfoLog(@name)
end


48
49
50
51
52
53
# File 'lib/opengl-core/aux/program.rb', line 48

def link
  Gl.glLinkProgram(@name)
  @link_status = nil
  __reload_uniforms__ if (link_successful = linked?)
  link_successful
end

#linked?Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/opengl-core/aux/program.rb', line 55

def linked?
  @link_status = (!@link_status.nil? && @link_status) ||
    Gl.glGetProgram(@name, Gl::GL_LINK_STATUS) == GL_TRUE
end

#load_binary(binary_format, binary_string) ⇒ Object



21
22
23
24
25
26
# File 'lib/opengl-core/aux/program.rb', line 21

def load_binary(binary_format, binary_string)
  Gl.glProgramBinary(@name, binary_format, binary_string, binary_string.bytesize)
  @link_status = nil
  __reload_uniforms__  if (link_successful = linked?)
  link_successful
end

#subroutine_uniform_location(shader_kind, uniform_name) ⇒ Object



108
109
110
# File 'lib/opengl-core/aux/program.rb', line 108

def subroutine_uniform_location(shader_kind, uniform_name)
  Gl.glGetSubroutineUniformLocation(@name, shader_kind, uniform_name)
end

#uniform_location(uniform_name) ⇒ Object Also known as: []

Implicitly hints that a uniform exists.



95
96
97
98
99
# File 'lib/opengl-core/aux/program.rb', line 95

def uniform_location(uniform_name)
  uniform_sym = uniform_name.to_sym
  @uniform_locations[uniform_sym] ||=
    Gl.glGetUniformLocation(@name, uniform_name.to_s)
end

#useObject



75
76
77
78
# File 'lib/opengl-core/aux/program.rb', line 75

def use
  Gl.glUseProgram(@name)
  self
end

#valid?Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/opengl-core/aux/program.rb', line 66

def valid?
  @validate_status = (!@validate_status.nil? && @validate_status) ||
    Gl.glGetProgram(@name, Gl::GL_VALIDATE_STATUS) == GL_TRUE
end

#validateObject



60
61
62
63
64
# File 'lib/opengl-core/aux/program.rb', line 60

def validate
  Gl.glValidateProgram(@name)
  @validate_status = nil
  valid?
end