Module: OpenGLDebug

Defined in:
lib/mittsu/renderers/opengl/opengl_debug.rb

Defined Under Namespace

Modules: OpenGLProxy Classes: DebugShader

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_lib(*args) ⇒ Object



34
35
36
# File 'lib/mittsu/renderers/opengl/opengl_debug.rb', line 34

def self.load_lib(*args)
  OpenGL.load_lib(*args)
end

Instance Method Details

#call_debug_method(m, called_from = , *args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mittsu/renderers/opengl/opengl_debug.rb', line 42

def call_debug_method m, called_from = caller[0], *args
  if m.to_s.start_with?('glUniform')
    uniform_name = @@current_shader.get_uniform_name(args.first)
    call = "#{m}('#{uniform_name}',#{args[1..-1].map { |s| s.to_s[0..20] }.join(', ')})"
  else
    call = "#{m}(#{args.map { |s| s.to_s[0..20] }.join(', ')})"
  end
  print call
  r = OpenGLProxy.send(m, *args)
  ret = r.nil? ? '' : " => #{r}"
  puts "#{ret} (#{called_from})"
  e = OpenGLProxy.glGetError
  raise "ERROR: #{m} => #{ERROR_STRINGS[e]}" unless e == OpenGL::GL_NO_ERROR
  r
end

#glCreateProgramObject



64
65
66
67
68
69
# File 'lib/mittsu/renderers/opengl/opengl_debug.rb', line 64

def glCreateProgram
  call_debug_method(:glCreateProgram, caller[0]).tap do |handle|
    @@shaders ||= {}
    @@shaders[handle] = DebugShader.new(handle)
  end
end

#glGetUniformLocation(program, name) ⇒ Object



76
77
78
79
80
# File 'lib/mittsu/renderers/opengl/opengl_debug.rb', line 76

def glGetUniformLocation(program, name)
  call_debug_method(:glGetUniformLocation, caller[0], program, name).tap do |handle|
    @@shaders[program].set_uniform(handle, name)
  end
end

#glUseProgram(handle) ⇒ Object



71
72
73
74
# File 'lib/mittsu/renderers/opengl/opengl_debug.rb', line 71

def glUseProgram(handle)
  @@current_shader = @@shaders[handle]
  call_debug_method(:glUseProgram, caller[0], handle)
end