Module: GL_VERSION_2_0::RenderContext

Includes:
Roglew::RenderContextExtension
Defined in:
lib/roglew/extensions/GL_VERSION_2_0.rb

Instance Method Summary collapse

Methods included from Roglew::RenderContextExtension

included

Instance Method Details

#create_program(shaders = nil) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 195

def create_program(shaders = nil)
  program = Roglew::ShaderProgram.new(@rh)
  return program unless shaders
  shaders = case shaders
    when Hash
      shaders.map do |type, source|
        type = type.is_a?(Integer) ? type : Roglew::GL.const_get("#{type.to_s.upcase}_SHADER")
        create_shader(type, source)
      end
    when Array
      shaders
    else
      raise ArgumentError, "It must be Hash or Array. Given: #{shaders.class}"
  end
  program.attach(*shaders)
  program.link
  program
end

#create_shader(*args) ⇒ Object



214
215
216
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 214

def create_shader(*args)
  Roglew::Shader.new(@rh, *args)
end

#get_program(program, pname) ⇒ Object



218
219
220
221
222
223
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 218

def get_program(program, pname)
  p = FFI::MemoryPointer.new(:int)
  @rh.glGetProgramiv(program, pname, p)
  result = p.read_int
  [Roglew::GL::DELETE_STATUS, Roglew::GL::COMPILE_STATUS].include?(pname) ? result == Roglew::GL::TRUE : result
end

#get_program_info_log(program) ⇒ Object



225
226
227
228
229
230
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 225

def get_program_info_log(program)
  length = get_program(program, Roglew::GL::INFO_LOG_LENGTH)
  p = FFI::MemoryPointer.new(:char, length)
  @rh.glGetProgramInfoLog(program, length, nil, p)
  p.read_string
end

#get_shader(shader, pname) ⇒ Object



232
233
234
235
236
237
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 232

def get_shader(shader, pname)
  p = FFI::MemoryPointer.new(:int)
  @rh.glGetShaderiv(shader, pname, p)
  result = p.read_int
  [Roglew::GL::DELETE_STATUS, Roglew::GL::COMPILE_STATUS].include?(pname) ? result == Roglew::GL::TRUE : result
end

#get_shader_info_log(shader) ⇒ Object



239
240
241
242
243
244
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 239

def get_shader_info_log(shader)
  length = get_shader(shader, Roglew::GL::INFO_LOG_LENGTH)
  p = FFI::MemoryPointer.new(:char, length)
  @rh.glGetShaderInfoLog(shader, length, nil, p)
  p.read_string
end

#shader_sources(shader, *srcs) ⇒ Object



246
247
248
249
250
251
252
# File 'lib/roglew/extensions/GL_VERSION_2_0.rb', line 246

def shader_sources(shader, *srcs)
  ps = FFI::MemoryPointer.new(:string, srcs.length)
  ps.write_array_of_pointer(srcs.map { |src| FFI::MemoryPointer.from_string(src) })
  pl = FFI::MemoryPointer.new(:int, srcs.length)
  pl.write_array_of_int(srcs.map { |src| src.length })
  @rh.glShaderSource(shader, srcs.length, ps, pl)
end