diff --git a/lib/mittsu/renderers/generic_lib.rb b/lib/mittsu/renderers/generic_lib.rb index 54affd5e..205abccb 100644 --- a/lib/mittsu/renderers/generic_lib.rb +++ b/lib/mittsu/renderers/generic_lib.rb @@ -1,7 +1,7 @@ module Mittsu module GenericLib def discover - case OpenGL.get_platform + case GL.get_platform when :OPENGL_PLATFORM_WINDOWS self::Windows.new when :OPENGL_PLATFORM_MACOSX @@ -9,7 +9,7 @@ def discover when :OPENGL_PLATFORM_LINUX self::Linux.new else - warn "WARNING: Unsupported platform: #{OpenGL.get_platform}" + warn "WARNING: Unsupported platform: #{GL.get_platform}" Base.new end end diff --git a/lib/mittsu/renderers/glfw_window.rb b/lib/mittsu/renderers/glfw_window.rb index c2a5175d..2658f8fe 100644 --- a/lib/mittsu/renderers/glfw_window.rb +++ b/lib/mittsu/renderers/glfw_window.rb @@ -4,9 +4,7 @@ require 'mittsu/utils' require 'mittsu/renderers/glfw_lib' glfw_lib = Mittsu::GLFWLib.discover -GLFW.load_lib(ENV["MITTSU_LIBGLFW_FILE"] || glfw_lib.file, ENV["MITTSU_LIBGLFW_PATH"] || glfw_lib.path) unless Mittsu.test? - -include GLFW +::GLFW.load_lib(ENV["MITTSU_LIBGLFW_FILE"] || glfw_lib.file, ENV["MITTSU_LIBGLFW_PATH"] || glfw_lib.path) unless Mittsu.test? module Mittsu module GLFW @@ -14,88 +12,88 @@ class Window attr_accessor :key_press_handler, :key_release_handler, :key_repeat_handler, :char_input_handler, :cursor_pos_handler, :mouse_button_press_handler, :mouse_button_release_handler, :scroll_handler, :framebuffer_size_handler def initialize(width, height, title, antialias: 0) - glfwInit + ::GLFW.Init - glfwWindowHint GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE - glfwWindowHint GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE - glfwWindowHint GLFW_CONTEXT_VERSION_MAJOR, 3 - glfwWindowHint GLFW_CONTEXT_VERSION_MINOR, 3 - glfwWindowHint GLFW_CONTEXT_REVISION, 0 + ::GLFW.WindowHint ::GLFW::OPENGL_PROFILE, ::GLFW::OPENGL_CORE_PROFILE + ::GLFW.WindowHint ::GLFW::OPENGL_FORWARD_COMPAT, GL::TRUE + ::GLFW.WindowHint ::GLFW::CONTEXT_VERSION_MAJOR, 3 + ::GLFW.WindowHint ::GLFW::CONTEXT_VERSION_MINOR, 3 + ::GLFW.WindowHint ::GLFW::CONTEXT_REVISION, 0 if antialias > 0 - glfwWindowHint GLFW_SAMPLES, antialias + ::GLFW.WindowHint ::GLFW::SAMPLES, antialias end @width, @height, @title = width, height, title - @handle = glfwCreateWindow(@width, @height, @title, nil, nil) + @handle = ::GLFW.CreateWindow(@width, @height, @title, nil, nil) if @handle.null? raise "Unable to create window." end - glfwMakeContextCurrent @handle - glfwSwapInterval 1 + ::GLFW.MakeContextCurrent @handle + ::GLFW.SwapInterval 1 this = self @key_callback = ::GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods| - if action == GLFW_PRESS + if action == ::GLFW::PRESS this.key_press_handler.call(key) unless this.key_press_handler.nil? this.key_repeat_handler.call(key) unless this.key_repeat_handler.nil? - elsif action == GLFW_RELEASE + elsif action == ::GLFW::RELEASE this.key_release_handler.call(key) unless this.key_release_handler.nil? - elsif action == GLFW_REPEAT + elsif action == ::GLFW::REPEAT this.key_repeat_handler.call(key) unless this.key_repeat_handler.nil? end end - glfwSetKeyCallback(@handle, @key_callback) + ::GLFW.SetKeyCallback(@handle, @key_callback) @char_callback = ::GLFW::create_callback(:GLFWcharfun) do |window_handle, codepoint| char = [codepoint].pack('U') this.char_input_handler.call(char) unless this.char_input_handler.nil? end - glfwSetCharCallback(@handle, @char_callback) + ::GLFW.SetCharCallback(@handle, @char_callback) @cursor_pos_callback = ::GLFW::create_callback(:GLFWcursorposfun) do |window_handle, xpos, ypos| this.cursor_pos_handler.call(Vector2.new(xpos, ypos)) unless this.cursor_pos_handler.nil? end - glfwSetCursorPosCallback(@handle, @cursor_pos_callback) + ::GLFW.SetCursorPosCallback(@handle, @cursor_pos_callback) @mouse_button_callback = ::GLFW::create_callback(:GLFWmousebuttonfun) do |window_handle, button, action, mods| mpos = this.mouse_position - if action == GLFW_PRESS + if action == ::GLFW::PRESS this.mouse_button_press_handler.call(button, mpos) unless this.mouse_button_press_handler.nil? - elsif action == GLFW_RELEASE + elsif action == ::GLFW::RELEASE this.mouse_button_release_handler.call(button, mpos) unless this.mouse_button_release_handler.nil? end end - glfwSetMouseButtonCallback(@handle, @mouse_button_callback) + ::GLFW.SetMouseButtonCallback(@handle, @mouse_button_callback) @scroll_callback = ::GLFW::create_callback(:GLFWscrollfun) do |window_handle, xoffset, yoffset| this.scroll_handler.call(Vector2.new(xoffset, yoffset)) unless this.scroll_handler.nil? end - glfwSetScrollCallback(@handle, @scroll_callback) + ::GLFW.SetScrollCallback(@handle, @scroll_callback) @frabuffer_size_callback = ::GLFW::create_callback(:GLFWframebuffersizefun) do |window_handle, new_width, new_height| this.framebuffer_size_handler.call(new_width, new_height) unless this.framebuffer_size_handler.nil? end - glfwSetFramebufferSizeCallback(@handle, @frabuffer_size_callback) + ::GLFW.SetFramebufferSizeCallback(@handle, @frabuffer_size_callback) @joystick_buttons = poll_all_joysticks_buttons end def run - while glfwWindowShouldClose(@handle) == 0 + while ::GLFW.WindowShouldClose(@handle) == 0 yield - glfwSwapBuffers @handle - glfwPollEvents + ::GLFW.SwapBuffers @handle + ::GLFW.PollEvents poll_joystick_events end - glfwDestroyWindow @handle - glfwTerminate + ::GLFW.DestroyWindow @handle + ::GLFW.Terminate end def framebuffer_size width, height = ' '*8, ' '*8 - glfwGetFramebufferSize(@handle, width, height) + ::GLFW.GetFramebufferSize(@handle, width, height) [width.unpack('L')[0], height.unpack('L')[0]] end @@ -112,7 +110,7 @@ def on_key_typed &block end def key_down?(key) - glfwGetKey(@handle, key) == GLFW_PRESS + ::GLFW.GetKey(@handle, key) == ::GLFW::PRESS end def on_character_input &block @@ -133,12 +131,12 @@ def on_mouse_button_released &block def mouse_position xpos, ypos = ' '*8, ' '*8 - glfwGetCursorPos(@handle, xpos, ypos); + ::GLFW.GetCursorPos(@handle, xpos, ypos); Vector2.new(xpos.unpack('D')[0], ypos.unpack('D')[0]) end def mouse_button_down?(button) - glfwGetMouseButton(@handle, button) == GLFW_PRESS + ::GLFW.GetMouseButton(@handle, button) == ::GLFW::PRESS end def on_scroll &block @@ -149,15 +147,15 @@ def on_resize &block @framebuffer_size_handler = block end - def joystick_buttons(joystick = GLFW_JOYSTICK_1) + def joystick_buttons(joystick = ::GLFW::JOYSTICK_1) @joystick_buttons = poll_all_joysticks_buttons @joystick_buttons[joystick] end - def joystick_axes(joystick = GLFW_JOYSTICK_1) + def joystick_axes(joystick = ::GLFW::JOYSTICK_1) return [] unless joystick_present?(joystick) count = ' ' * 4 - array = glfwGetJoystickAxes(joystick, count) + array = ::GLFW.GetJoystickAxes(joystick, count) count = count.unpack('l')[0] array[0, count * 4].unpack('f' * count) end @@ -170,30 +168,30 @@ def on_joystick_button_released &block @joystick_button_release_handler = block end - def joystick_present?(joystick = GLFW_JOYSTICK_1) - glfwJoystickPresent(joystick).nonzero? + def joystick_present?(joystick = ::GLFW::JOYSTICK_1) + ::GLFW.JoystickPresent(joystick).nonzero? end - def joystick_button_down?(button, joystick = GLFW_JOYSTICK_1) + def joystick_button_down?(button, joystick = ::GLFW::JOYSTICK_1) @joystick_buttons[joystick][button] end - def joystick_name(joystick = GLFW_JOYSTICK_1) - glfwGetJoystickName(joystick) + def joystick_name(joystick = ::GLFW::JOYSTICK_1) + ::GLFW.GetJoystickName(joystick) end def set_mouselock(value) if value - glfwSetInputMode(@handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED) + ::GLFW.SetInputMode(@handle, ::GLFW::CURSOR, ::GLFW::CURSOR_DISABLED) else - glfwSetInputMode(@handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL) + ::GLFW.SetInputMode(@handle, ::GLFW::CURSOR, ::GLFW::CURSOR_NORMAL) end end private def poll_all_joysticks_buttons - (GLFW_JOYSTICK_1..GLFW_JOYSTICK_LAST).map do |joystick| + (::GLFW::JOYSTICK_1..::GLFW::JOYSTICK_LAST).map do |joystick| poll_joystick_buttons(joystick) end end @@ -201,7 +199,7 @@ def poll_all_joysticks_buttons def poll_joystick_buttons(joystick) return nil unless joystick_present?(joystick) count = ' ' * 4 - array = glfwGetJoystickButtons(joystick, count) + array = ::GLFW.GetJoystickButtons(joystick, count) count = count.unpack('l')[0] array[0, count].unpack('c' * count).map(&:nonzero?) end diff --git a/lib/mittsu/renderers/opengl/core/geometry.rb b/lib/mittsu/renderers/opengl/core/geometry.rb index f73da69e..36ddac76 100644 --- a/lib/mittsu/renderers/opengl/core/geometry.rb +++ b/lib/mittsu/renderers/opengl/core/geometry.rb @@ -71,20 +71,20 @@ def init_particle_buffers(object) end def create_line_buffers - @vertex_array_object = glCreateVertexArray + @vertex_array_object = GL.CreateVertexArray - @vertex_buffer = glCreateBuffer - @color_buffer = glCreateBuffer - @line_distance_buffer = glCreateBuffer + @vertex_buffer = GL.CreateBuffer + @color_buffer = GL.CreateBuffer + @line_distance_buffer = GL.CreateBuffer @renderer.info[:memory][:geometries] += 1 end def create_particle_buffers - @vertex_array_object = glCreateVertexArray + @vertex_array_object = GL.CreateVertexArray - @vertex_buffer = glCreateBuffer - @color_buffer = glCreateBuffer + @vertex_buffer = GL.CreateBuffer + @color_buffer = GL.CreateBuffer @renderer.info[:memory][:geometries] += 1 end @@ -99,8 +99,8 @@ def set_line_buffers(hint) @vertex_array[offset + 2] = vertex.z end - glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @vertex_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @vertex_array, hint) end if @colors_need_update @@ -112,8 +112,8 @@ def set_line_buffers(hint) @color_array[offset + 2] = color.b end - glBindBuffer(GL_ARRAY_BUFFER, @color_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @color_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @color_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @color_array, hint) end if @line_distances_need_update @@ -121,8 +121,8 @@ def set_line_buffers(hint) @line_distance_array[d] = l end - glBindBuffer(GL_ARRAY_BUFFER, @line_distance_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @line_distance_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @line_distance_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @line_distance_array, hint) end if @custom_attributes @@ -172,8 +172,8 @@ def set_line_buffers(hint) end end - glBindBuffer(GL_ARRAY_BUFFER, custom_attribute.buffer) - glBufferData_easy(GL_ARRAY_BUFFER, custom_attribute.array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, custom_attribute.buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, custom_attribute.array, hint) custom_attribute.needs_update = false end @@ -191,8 +191,8 @@ def set_particle_buffers(hint) end - glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @vertex_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @vertex_array, hint) end if @colors_need_update @@ -204,8 +204,8 @@ def set_particle_buffers(hint) @color_array[offset + 2] = color.b end - glBindBuffer(GL_ARRAY_BUFFER, @color_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @color_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @color_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @color_array, hint) end if @custom_attribute @@ -254,8 +254,8 @@ def set_particle_buffers(hint) end end - glBindBuffer(GL_ARRAY_BUFFER, customAttribute.buffer) - glBufferData(GL_ARRAY_BUFFER, customAttribute.array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, customAttribute.buffer) + GL.BufferData(GL::ARRAY_BUFFER, customAttribute.array, hint) custom_attribute.needs_update = false end @@ -332,7 +332,7 @@ def init_custom_attributes(object) attribute.array = Array.new(nvertices * size) # Float32Array - attribute.buffer = glCreateBuffer + attribute.buffer = GL.CreateBuffer attribute.buffer.belongs_to_attribute = name attribute.needs_update = true diff --git a/lib/mittsu/renderers/opengl/core/object_3d.rb b/lib/mittsu/renderers/opengl/core/object_3d.rb index 092c5ea2..4320f878 100644 --- a/lib/mittsu/renderers/opengl/core/object_3d.rb +++ b/lib/mittsu/renderers/opengl/core/object_3d.rb @@ -89,13 +89,13 @@ def setup_matrices(camera) end def load_uniforms_matrices(uniforms) - glUniformMatrix4fv(uniforms['modelViewMatrix'], - 1, GL_FALSE, + GL.UniformMatrix4fv(uniforms['modelViewMatrix'], + 1, GL::FALSE, array_to_ptr_easy(@model_view_matrix.elements)) if uniforms['normalMatrix'] - glUniformMatrix3fv(uniforms['normalMatrix'], - 1, GL_FALSE, + GL.UniformMatrix3fv(uniforms['normalMatrix'], + 1, GL::FALSE, array_to_ptr_easy(@normal_matrix.elements)) end end diff --git a/lib/mittsu/renderers/opengl/materials/material.rb b/lib/mittsu/renderers/opengl/materials/material.rb index 2fe0a1da..5d05948e 100644 --- a/lib/mittsu/renderers/opengl/materials/material.rb +++ b/lib/mittsu/renderers/opengl/materials/material.rb @@ -123,7 +123,7 @@ def allocate_bones(object = nil) # - limit here is ANGLE's 254 max uniform vectors # (up to 54 should be safe) - n_vertex_uniforms = (glGetParameter(GL_MAX_VERTEX_UNIFORM_COMPONENTS) / 4.0).floor + n_vertex_uniforms = (GL.GetParameter(GL::MAX_VERTEX_UNIFORM_COMPONENTS) / 4.0).floor n_vertex_matrices = ((n_vertex_uniforms - 20) / 4.0).floor max_bones = n_vertex_matrices diff --git a/lib/mittsu/renderers/opengl/objects/line.rb b/lib/mittsu/renderers/opengl/objects/line.rb index dc7cc4ad..7122e792 100644 --- a/lib/mittsu/renderers/opengl/objects/line.rb +++ b/lib/mittsu/renderers/opengl/objects/line.rb @@ -1,22 +1,22 @@ module Mittsu class Line def render_buffer(camera, lights, fog, material, geometry_group, update_buffers) - opengl_mode = mode == LineStrip ? GL_LINE_STRIP : GL_LINES + opengl_mode = mode == LineStrip ? GL::LINE_STRIP : GL::LINES @renderer.state.set_line_width(material.line_width * @renderer.pixel_ratio) - glDrawArrays(opengl_mode, 0, geometry_group.line_count) + GL.DrawArrays(opengl_mode, 0, geometry_group.line_count) @renderer.info[:render][:calls] += 1 end def update - # TODO: glBindVertexArray ??? + # TODO: GL.BindVertexArray ??? material = buffer_material(geometry) custom_attributes_dirty = material.attributes && material.custom_attributes_dirty? if geometry.vertices_need_update || geometry.colors_need_update || geometry.line_distances_need_update || custom_attributes_dirty - geometry.set_line_buffers(GL_DYNAMIC_DRAW) + geometry.set_line_buffers(GL::DYNAMIC_DRAW) end geometry.vertices_need_update = false diff --git a/lib/mittsu/renderers/opengl/objects/mesh.rb b/lib/mittsu/renderers/opengl/objects/mesh.rb index 470a2b1a..42d02cdb 100644 --- a/lib/mittsu/renderers/opengl/objects/mesh.rb +++ b/lib/mittsu/renderers/opengl/objects/mesh.rb @@ -3,19 +3,19 @@ class Mesh attr_accessor :renderer def render_buffer(camera, lights, fog, material, geometry_group, update_buffers) - type = GL_UNSIGNED_INT # geometry_group.type_array == Uint32Array ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT + type = GL::UNSIGNED_INT # geometry_group.type_array == Uint32Array ? GL::UNSIGNED_INT : GL::UNSIGNED_SHORT # wireframe if material.wireframe @renderer.state.set_line_width(material.wireframe_linewidth * @renderer.pixel_ratio) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry_group.line_buffer) if update_buffers - glDrawElements(GL_LINES, geometry_group.line_count, type, 0) + GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, geometry_group.line_buffer) if update_buffers + GL.DrawElements(GL::LINES, geometry_group.line_count, type, 0) # triangles else - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry_group.face_buffer) if update_buffers - glDrawElements(GL_TRIANGLES, geometry_group.face_count, type, 0) + GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, geometry_group.face_buffer) if update_buffers + GL.DrawElements(GL::TRIANGLES, geometry_group.face_count, type, 0) end @renderer.info[:render][:calls] += 1 @@ -28,13 +28,13 @@ def update mat = nil geometry.groups.each do |geometry_group| # TODO: place to put this??? - # glBindVertexArray(geometry_group.vertex_array_object) + # GL.BindVertexArray(geometry_group.vertex_array_object) mat = buffer_material(geometry_group) custom_attributes_dirty = mat.attributes && mat.custom_attributes_dirty? if geometry.vertices_need_update || geometry.morph_targets_need_update || geometry.elements_need_update || geometry.uvs_need_update || geometry.normals_need_update || geometry.colors_need_update || geometry.tangents_need_update || custom_attributes_dirty - geometry_group.set_mesh_buffers(self, GL_DYNAMIC_DRAW, !geometry.dynamic, mat) + geometry_group.set_mesh_buffers(self, GL::DYNAMIC_DRAW, !geometry.dynamic, mat) end end diff --git a/lib/mittsu/renderers/opengl/objects/point_cloud.rb b/lib/mittsu/renderers/opengl/objects/point_cloud.rb index 6f7dbd61..e95058e6 100644 --- a/lib/mittsu/renderers/opengl/objects/point_cloud.rb +++ b/lib/mittsu/renderers/opengl/objects/point_cloud.rb @@ -1,7 +1,7 @@ module Mittsu class PointCloud def render_buffer(camera, lights, fog, material, geometry_group, update_buffers) - glDrawArrays(GL_POINTS, 0, geometry_group.particle_count) + GL.DrawArrays(GL::POINTS, 0, geometry_group.particle_count) @renderer.info[:render][:calls] += 1 @renderer.info[:render][:points] += geometry_group.particle_count @@ -12,7 +12,7 @@ def update custom_attributes_dirty = material.attributes && material.custom_attributes_dirty? if geometry.vertices_need_update || geometry.colors_need_update || custom_attributes_dirty - geometry.set_particle_buffers(GL_DYNAMIC_DRAW) + geometry.set_particle_buffers(GL::DYNAMIC_DRAW) end geometry.vertices_need_update = false diff --git a/lib/mittsu/renderers/opengl/opengl_debug.rb b/lib/mittsu/renderers/opengl/opengl_debug.rb index 73fd4806..f65f30b7 100644 --- a/lib/mittsu/renderers/opengl/opengl_debug.rb +++ b/lib/mittsu/renderers/opengl/opengl_debug.rb @@ -1,16 +1,18 @@ require 'opengl' ERROR_STRINGS = { - OpenGL::GL_NO_ERROR => 'NO_ERROR', - OpenGL::GL_INVALID_ENUM => 'INVALID_ENUM', - OpenGL::GL_INVALID_VALUE => 'INVALID_VALUE', - OpenGL::GL_INVALID_OPERATION => 'INVALID_OPERATION', - OpenGL::GL_STACK_OVERFLOW => 'STACK_OVERFLOW', - OpenGL::GL_STACK_UNDERFLOW => 'STACK_UNDERFLOW', - OpenGL::GL_OUT_OF_MEMORY => 'OUT_OF_MEMORY', - # OpenGL::GL_TABLE_TOO_LARGE => 'TABLE_TOO_LARGE' + GL::NO_ERROR => 'NO_ERROR', + GL::INVALID_ENUM => 'INVALID_ENUM', + GL::INVALID_VALUE => 'INVALID_VALUE', + GL::INVALID_OPERATION => 'INVALID_OPERATION', + GL::STACK_OVERFLOW => 'STACK_OVERFLOW', + GL::STACK_UNDERFLOW => 'STACK_UNDERFLOW', + GL::OUT_OF_MEMORY => 'OUT_OF_MEMORY', + # GL::TABLE_TOO_LARGE => 'TABLE_TOO_LARGE' } +OriginalGL = GL + module OpenGLDebug class DebugShader def initialize(handle) @@ -27,55 +29,57 @@ def get_uniform_name(handle) end end - module OpenGLProxy - extend OpenGL - end - def self.load_lib(*args) - OpenGL.load_lib(*args) + OriginalGL.load_lib(*args) end - OpenGL.constants.each do |c| - const_set c, OpenGL.const_get(c) + OriginalGL.constants.each do |c| + const_set c, OriginalGL.const_get(c) end - 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 + class << self + OriginalGL::GL_FUNCTION_SYMBOLS + .map { |m| m.to_s.gsub(/^gl/, '').to_sym } + .each do |m| + define_method(m) do |*args| + call_debug_method(m, caller[0], *args) + end + end - OpenGL.instance_methods.each do |m| - define_method m do |*args| - self.call_debug_method(m, caller[0], *args) + def call_debug_method m, called_from = caller[0], *args + if m.to_s.start_with?('Uniform') + 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 = OriginalGL.send(m, *args) + ret = r.nil? ? '' : " => #{r}" + puts "#{ret} (#{called_from})" + e = OriginalGL.GetError + raise "ERROR: #{m} => #{ERROR_STRINGS[e]}" unless e == GL::NO_ERROR + r end - end - def glCreateProgram - call_debug_method(:glCreateProgram, caller[0]).tap do |handle| - @@shaders ||= {} - @@shaders[handle] = DebugShader.new(handle) + def CreateProgram + call_debug_method(:CreateProgram, caller[0]).tap do |handle| + @@shaders ||= {} + @@shaders[handle] = DebugShader.new(handle) + end end - end - def glUseProgram(handle) - @@current_shader = @@shaders[handle] - call_debug_method(:glUseProgram, caller[0], handle) - end + def UseProgram(handle) + @@current_shader = @@shaders[handle] + call_debug_method(:UseProgram, caller[0], handle) + end - def glGetUniformLocation(program, name) - call_debug_method(:glGetUniformLocation, caller[0], program, name).tap do |handle| - @@shaders[program].set_uniform(handle, name) + def GetUniformLocation(program, name) + call_debug_method(:GetUniformLocation, caller[0], program, name).tap do |handle| + @@shaders[program].set_uniform(handle, name) + end end end end + +GL = OpenGLDebug diff --git a/lib/mittsu/renderers/opengl/opengl_default_target.rb b/lib/mittsu/renderers/opengl/opengl_default_target.rb index 28064291..ae48c60d 100644 --- a/lib/mittsu/renderers/opengl/opengl_default_target.rb +++ b/lib/mittsu/renderers/opengl/opengl_default_target.rb @@ -25,12 +25,12 @@ def setup_buffers end def use - glBindFramebuffer(GL_FRAMEBUFFER, 0) + GL.BindFramebuffer(GL::FRAMEBUFFER, 0) use_viewport end def use_viewport - glViewport(@viewport_x, @viewport_y, @viewport_width, @viewport_height) + GL.Viewport(@viewport_x, @viewport_y, @viewport_width, @viewport_height) end def set_and_use_viewport(x, y, width, height) diff --git a/lib/mittsu/renderers/opengl/opengl_extensions.rb b/lib/mittsu/renderers/opengl/opengl_extensions.rb new file mode 100644 index 00000000..41922712 --- /dev/null +++ b/lib/mittsu/renderers/opengl/opengl_extensions.rb @@ -0,0 +1,42 @@ +module GL + def self.CreateBuffer + @_b ||= ' '*8 + ::GL.GenBuffers(1, @_b) + @_b.unpack('L')[0] + end + + def self.CreateTexture + @_b ||= ' '*8 + ::GL.GenTextures(1, @_b) + @_b.unpack('L')[0] + end + + def self.CreateVertexArray + @_b ||= ' '*8 + ::GL.GenVertexArrays(1, @_b) + @_b.unpack('L')[0] + end + + def self.CreateFramebuffer + @_b ||= ' '*8 + ::GL.GenFramebuffers(1, @_b) + @_b.unpack('L')[0] + end + + def self.CreateRenderbuffer + @_b ||= ' '*8 + ::GL.GenRenderbuffers(1, @_b) + @_b.unpack('L')[0] + end + + def self.BufferData_easy(target, data, usage) + ptr = array_to_ptr_easy(data) + ::GL.BufferData(target, ptr.size, ptr, usage) + end + + def self.GetParameter(pname) + @_b ||= ' '*8 + ::GL.GetIntegerv(pname, @_b) + @_b.unpack('L')[0] + end +end diff --git a/lib/mittsu/renderers/opengl/opengl_geometry_group.rb b/lib/mittsu/renderers/opengl/opengl_geometry_group.rb index 4aae1343..8b5e5456 100644 --- a/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +++ b/lib/mittsu/renderers/opengl/opengl_geometry_group.rb @@ -24,26 +24,26 @@ def initialize material_index, num_morph_targets, num_morph_normals, renderer end def create_mesh_buffers - @vertex_array_object = glCreateVertexArray + @vertex_array_object = GL.CreateVertexArray - @vertex_buffer = glCreateBuffer - @normal_buffer = glCreateBuffer - @tangent_buffer = glCreateBuffer - @color_buffer = glCreateBuffer - @uv_buffer = glCreateBuffer - @uv2_buffer = glCreateBuffer + @vertex_buffer = GL.CreateBuffer + @normal_buffer = GL.CreateBuffer + @tangent_buffer = GL.CreateBuffer + @color_buffer = GL.CreateBuffer + @uv_buffer = GL.CreateBuffer + @uv2_buffer = GL.CreateBuffer - @skin_indices_buffer = glCreateBuffer - @skin_weights_buffer = glCreateBuffer + @skin_indices_buffer = GL.CreateBuffer + @skin_weights_buffer = GL.CreateBuffer - @face_buffer = glCreateBuffer - @line_buffer = glCreateBuffer + @face_buffer = GL.CreateBuffer + @line_buffer = GL.CreateBuffer if !@num_morph_targets.nil? @morph_targets_buffers = [] @num_morph_targets.times do |m| - @morph_targets_buffers << glCreateBuffer + @morph_targets_buffers << GL.CreateBuffer end end @@ -51,7 +51,7 @@ def create_mesh_buffers @morph_normals_buffers = [] @num_morph_normals.times do |m| - @morph_normals_buffers << glCreateBuffer + @morph_normals_buffers << GL.CreateBuffer end end end @@ -141,7 +141,7 @@ def init_mesh_buffers(object) attribute[:size] = size attribute[:array] = Array.new(nvertices * size) # Float32Array - attribute[:buffer] = glCreateBuffer + attribute[:buffer] = GL.CreateBuffer attribute[:buffer_belongs_to_attribute] = name original_attribute[:needs_update] = true @@ -211,8 +211,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) offset += 9 end - glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @vertex_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @vertex_array, hint) end if geometry.morph_targets_need_update @@ -275,12 +275,12 @@ def set_mesh_buffers(object, hint, should_dispose, material) offset_morph_target += 9 end - glBindBuffer(GL_ARRAY_BUFFER, @morph_targets_buffers[vk]) - glBufferData_easy(GL_ARRAY_BUFFER, @morph_targets_arrays[vk], hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @morph_targets_buffers[vk]) + GL.BufferData_easy(GL::ARRAY_BUFFER, @morph_targets_arrays[vk], hint) if material.morph_normals - glBindBuffer(GL_ARRAY_BUFFER, @morph_normals_buffers[vk]) - glBufferData_easy(GL_ARRAY_BUFFER, @morph_normals_arrays[vk], hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @morph_normals_buffers[vk]) + GL.BufferData_easy(GL::ARRAY_BUFFER, @morph_normals_arrays[vk], hint) end end end @@ -335,11 +335,11 @@ def set_mesh_buffers(object, hint, should_dispose, material) end if offset_skin > 0 - glBindBuffer(GL_ARRAY_BUFFER, @skin_indices_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @skin_indices_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @skin_indices_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @skin_indices_array, hint) - glBindBuffer(GL_ARRAY_BUFFER, @skin_weights_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @skin_weight_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @skin_weights_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @skin_weight_array, hint) end end @@ -376,8 +376,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) end if offset_color > 0 - glBindBuffer(GL_ARRAY_BUFFER, @color_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @color_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @color_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @color_array, hint) end end @@ -409,8 +409,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) offset_tangent += 12 end - glBindBuffer(GL_ARRAY_BUFFER, @angent_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @tangent_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @angent_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @tangent_array, hint) end if geometry.normals_need_update @@ -441,8 +441,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) end end - glBindBuffer(GL_ARRAY_BUFFER, @normal_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @normal_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @normal_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @normal_array, hint) end if geometry.uvs_need_update && obj_uvs @@ -462,8 +462,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) end if offset_uv > 0 - glBindBuffer(GL_ARRAY_BUFFER, @uv_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @uv_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @uv_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @uv_array, hint) end end @@ -484,8 +484,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) end if offset_uv2 > 0 - glBindBuffer(GL_ARRAY_BUFFER, @uv2_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, @uv2_array, hint) + GL.BindBuffer(GL::ARRAY_BUFFER, @uv2_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, @uv2_array, hint) end end @@ -511,11 +511,11 @@ def set_mesh_buffers(object, hint, should_dispose, material) vertex_index += 3 end - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @face_buffer) - glBufferData_easy(GL_ELEMENT_ARRAY_BUFFER, @face_array, hint) + GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @face_buffer) + GL.BufferData_easy(GL::ELEMENT_ARRAY_BUFFER, @face_array, hint) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @line_buffer) - glBufferData_easy(GL_ELEMENT_ARRAY_BUFFER, @line_array, hint) + GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @line_buffer) + GL.BufferData_easy(GL::ELEMENT_ARRAY_BUFFER, @line_array, hint) end if @custom_attributes_list @@ -731,8 +731,8 @@ def set_mesh_buffers(object, hint, should_dispose, material) end end - glBindBuffer(GL_ARRAY_BUFFER, custom_attribute[:buffer]) - glBufferData_easy(GL_ARRAY_BUFFER, custom_attribute[:array], hint) + GL.BindBuffer(GL::ARRAY_BUFFER, custom_attribute[:buffer]) + GL.BufferData_easy(GL::ARRAY_BUFFER, custom_attribute[:array], hint) end end diff --git a/lib/mittsu/renderers/opengl/opengl_geometry_like.rb b/lib/mittsu/renderers/opengl/opengl_geometry_like.rb index 51a3675a..d205fc53 100644 --- a/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +++ b/lib/mittsu/renderers/opengl/opengl_geometry_like.rb @@ -34,13 +34,13 @@ module OpenGLGeometryLike :renderer def bind_vertex_array_object - glBindVertexArray(@vertex_array_object) if @vertex_array_object + GL.BindVertexArray(@vertex_array_object) if @vertex_array_object end def update_vertex_buffer(attribute) - glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer) + GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer) @renderer.state.enable_attribute(attribute) - glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, 0, 0) + GL.VertexAttribPointer(attribute, 3, GL::FLOAT, GL::FALSE, 0, 0) end def update_other_buffers(object, material, attributes) @@ -69,7 +69,7 @@ def update_color_buffer(attribute, object, material) if object.geometry.colors.length > 0 || object.geometry.faces.length > 0 update_attribute(attribute, @color_buffer, 3) elsif material.default_attribute_values - glVertexAttrib3fv(attribute, material.default_attribute_values.color) + GL.VertexAttrib3fv(attribute, material.default_attribute_values.color) end end @@ -94,7 +94,7 @@ def update_uv_buffer(attribute, buffer, object, index) update_attribute(attribute, buffer, 2) else # TODO default_attribute_value ??? - # glVertexAttrib2fv(attribute, default_attribute_value) + # GL.VertexAttrib2fv(attribute, default_attribute_value) end end @@ -124,9 +124,9 @@ def update_custom_attribute(custom_attribute, belongs_to_attribute) end def update_attribute(attribute, buffer, size) - glBindBuffer(GL_ARRAY_BUFFER, buffer) + GL.BindBuffer(GL::ARRAY_BUFFER, buffer) @renderer.state.enable_attribute(attribute) - glVertexAttribPointer(attribute, size, GL_FLOAT, GL_FALSE, 0, 0) + GL.VertexAttribPointer(attribute, size, GL::FLOAT, GL::FALSE, 0, 0) end end end diff --git a/lib/mittsu/renderers/opengl/opengl_helper.rb b/lib/mittsu/renderers/opengl/opengl_helper.rb index 2908194f..d846827d 100644 --- a/lib/mittsu/renderers/opengl/opengl_helper.rb +++ b/lib/mittsu/renderers/opengl/opengl_helper.rb @@ -1,35 +1,5 @@ module Mittsu module OpenGLHelper - def glCreateBuffer - @_b ||= ' '*8 - glGenBuffers(1, @_b) - @_b.unpack('L')[0] - end - - def glCreateTexture - @_b ||= ' '*8 - glGenTextures(1, @_b) - @_b.unpack('L')[0] - end - - def glCreateVertexArray - @_b ||= ' '*8 - glGenVertexArrays(1, @_b) - @_b.unpack('L')[0] - end - - def glCreateFramebuffer - @_b ||= ' '*8 - glGenFramebuffers(1, @_b) - @_b.unpack('L')[0] - end - - def glCreateRenderbuffer - @_b ||= ' '*8 - glGenRenderbuffers(1, @_b) - @_b.unpack('L')[0] - end - def array_to_ptr_easy(data) if data.first.is_a?(Float) size_of_element = Fiddle::SIZEOF_FLOAT @@ -50,17 +20,6 @@ def array_to_ptr(data, size, format) ptr end - def glBufferData_easy(target, data, usage) - ptr = array_to_ptr_easy(data) - glBufferData(target, ptr.size, ptr, usage) - end - - def glGetParameter(pname) - @_b ||= ' '*8 - glGetIntegerv(pname, @_b) - @_b.unpack('L')[0] - end - class << self def mark_uniforms_lights_needs_update(uniforms, value) uniforms['ambientLightColor'].needs_update = value diff --git a/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb b/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb index b8760219..5c04824b 100644 --- a/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +++ b/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb @@ -1,53 +1,53 @@ module Mittsu - GL_MITTSU_PARAMS = { - RepeatWrapping => GL_REPEAT, - ClampToEdgeWrapping => GL_CLAMP_TO_EDGE, - MirroredRepeatWrapping => GL_MIRRORED_REPEAT, - - NearestFilter => GL_NEAREST, - NearestMipMapNearestFilter => GL_NEAREST_MIPMAP_NEAREST, - NearestMipMapLinearFilter => GL_NEAREST_MIPMAP_LINEAR, - - LinearFilter => GL_LINEAR, - LinearMipMapNearestFilter => GL_LINEAR_MIPMAP_NEAREST, - LinearMipMapLinearFilter => GL_LINEAR_MIPMAP_LINEAR, - - UnsignedByteType => GL_UNSIGNED_BYTE, - UnsignedShort4444Type => GL_UNSIGNED_SHORT_4_4_4_4, - UnsignedShort5551Type => GL_UNSIGNED_SHORT_5_5_5_1, - UnsignedShort565Type => GL_UNSIGNED_SHORT_5_6_5, - - ByteType => GL_BYTE, - ShortType => GL_SHORT, - UnsignedShortType => GL_UNSIGNED_SHORT, - IntType => GL_INT, - UnsignedIntType => GL_UNSIGNED_INT, - FloatType => GL_FLOAT, - - AlphaFormat => GL_ALPHA, - RGBFormat => GL_RGB, - RGBAFormat => GL_RGBA, - LuminanceFormat => GL_LUMINANCE, - LuminanceAlphaFormat => GL_LUMINANCE_ALPHA, - - AddEquation => GL_FUNC_ADD, - SubtractEquation => GL_FUNC_SUBTRACT, - ReverseSubtractEquation => GL_FUNC_REVERSE_SUBTRACT, - - ZeroFactor => GL_ZERO, - OneFactor => GL_ONE, - SrcColorFactor => GL_SRC_COLOR, - OneMinusSrcColorFactor => GL_ONE_MINUS_SRC_COLOR, - SrcAlphaFactor => GL_SRC_ALPHA, - OneMinusSrcAlphaFactor => GL_ONE_MINUS_SRC_ALPHA, - DstAlphaFactor => GL_DST_ALPHA, - OneMinusDstAlphaFactor => GL_ONE_MINUS_DST_ALPHA, - - DstColorFactor => GL_DST_COLOR, - OneMinusDstColorFactor => GL_ONE_MINUS_DST_COLOR, - SrcAlphaSaturateFactor => GL_SRC_ALPHA_SATURATE + GL::MITTSU_PARAMS = { + RepeatWrapping => GL::REPEAT, + ClampToEdgeWrapping => GL::CLAMP_TO_EDGE, + MirroredRepeatWrapping => GL::MIRRORED_REPEAT, + + NearestFilter => GL::NEAREST, + NearestMipMapNearestFilter => GL::NEAREST_MIPMAP_NEAREST, + NearestMipMapLinearFilter => GL::NEAREST_MIPMAP_LINEAR, + + LinearFilter => GL::LINEAR, + LinearMipMapNearestFilter => GL::LINEAR_MIPMAP_NEAREST, + LinearMipMapLinearFilter => GL::LINEAR_MIPMAP_LINEAR, + + UnsignedByteType => GL::UNSIGNED_BYTE, + UnsignedShort4444Type => GL::UNSIGNED_SHORT_4_4_4_4, + UnsignedShort5551Type => GL::UNSIGNED_SHORT_5_5_5_1, + UnsignedShort565Type => GL::UNSIGNED_SHORT_5_6_5, + + ByteType => GL::BYTE, + ShortType => GL::SHORT, + UnsignedShortType => GL::UNSIGNED_SHORT, + IntType => GL::INT, + UnsignedIntType => GL::UNSIGNED_INT, + FloatType => GL::FLOAT, + + AlphaFormat => GL::ALPHA, + RGBFormat => GL::RGB, + RGBAFormat => GL::RGBA, + LuminanceFormat => GL::LUMINANCE, + LuminanceAlphaFormat => GL::LUMINANCE_ALPHA, + + AddEquation => GL::FUNC_ADD, + SubtractEquation => GL::FUNC_SUBTRACT, + ReverseSubtractEquation => GL::FUNC_REVERSE_SUBTRACT, + + ZeroFactor => GL::ZERO, + OneFactor => GL::ONE, + SrcColorFactor => GL::SRC_COLOR, + OneMinusSrcColorFactor => GL::ONE_MINUS_SRC_COLOR, + SrcAlphaFactor => GL::SRC_ALPHA, + OneMinusSrcAlphaFactor => GL::ONE_MINUS_SRC_ALPHA, + DstAlphaFactor => GL::DST_ALPHA, + OneMinusDstAlphaFactor => GL::ONE_MINUS_DST_ALPHA, + + DstColorFactor => GL::DST_COLOR, + OneMinusDstColorFactor => GL::ONE_MINUS_DST_COLOR, + SrcAlphaSaturateFactor => GL::SRC_ALPHA_SATURATE # TODO: populate with extension parameters? } - GL_MITTSU_PARAMS.default = 0 + GL::MITTSU_PARAMS.default = 0 end diff --git a/lib/mittsu/renderers/opengl/opengl_program.rb b/lib/mittsu/renderers/opengl/opengl_program.rb index 488c67c8..20b323df 100644 --- a/lib/mittsu/renderers/opengl/opengl_program.rb +++ b/lib/mittsu/renderers/opengl/opengl_program.rb @@ -22,7 +22,7 @@ def initialize(renderer, code, material, parameters) private def compile_and_link_program(material, parameters) - @program = glCreateProgram + @program = GL.CreateProgram # TODO: necessary for OpenGL? # index0_attribute_name = material.index0_attribute_name @@ -41,10 +41,10 @@ def compile_and_link_program(material, parameters) # because potentially expensive emulation is done by __browser__ if attribute 0 is disabled. (no browser here!) # And, color, for example is often automatically bound to index 0 so disabling it - # glBindAttributeLocation(program, 0, index0_attribute_name) + # GL.BindAttributeLocation(program, 0, index0_attribute_name) # end - glLinkProgram(@program) + GL.LinkProgram(@program) check_for_link_errors post_link_clean_up end @@ -64,18 +64,18 @@ def generate_defines(defines) def link_status ptr = ' '*8 - glGetProgramiv @program, GL_LINK_STATUS, ptr + GL.GetProgramiv @program, GL::LINK_STATUS, ptr ptr.unpack('L')[0] end def program_info_log ptr = ' '*8 - glGetProgramiv @program, GL_INFO_LOG_LENGTH, ptr + GL.GetProgramiv @program, GL::INFO_LOG_LENGTH, ptr length = ptr.unpack('L')[0] if length > 0 log = ' '*length - glGetProgramInfoLog @program, length, ptr, log + GL.GetProgramInfoLog @program, length, ptr, log log.unpack("A#{length}")[0] else '' @@ -86,14 +86,14 @@ def check_for_link_errors log_info = program_info_log if !link_status - puts "ERROR: Mittsu::OpenGLProgram: shader error: #{glGetError}, GL_INVALID_STATUS, #{glGetProgramParameter(program, GL_VALIDATE_STATUS)}, glGetProgramParameterInfoLog, #{log_info}" + puts "ERROR: Mittsu::OpenGLProgram: shader error: #{GL.GetError}, GL::INVALID_STATUS, #{GL.GetProgramParameter(program, GL::VALIDATE_STATUS)}, GL.GetProgramParameterInfoLog, #{log_info}" end if !log_info.empty? - puts "WARNING: Mittsu::OpenGLProgram: glGetProgramInfoLog, #{log_info}" + puts "WARNING: Mittsu::OpenGLProgram: GL.GetProgramInfoLog, #{log_info}" # TODO: useless in OpenGL ??? - # puts "WARNING: #{glGetExtension( 'OPENGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader )}" - # puts "WARNING: #{glGetExtension( 'OPENGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader )}" + # puts "WARNING: #{GL.GetExtension( 'OPENGL_debug_shaders' ).getTranslatedShaderSource( GL.VertexShader )}" + # puts "WARNING: #{GL.GetExtension( 'OPENGL_debug_shaders' ).getTranslatedShaderSource( GL.FragmentShader )}" end end @@ -165,11 +165,11 @@ def compile_shaders(material, parameters) prefix_fragment = File.read(File.expand_path('../../shaders/shader_templates/fragment.glsl.erb', __FILE__)) end - @vertex_shader = OpenGLShader.new(GL_VERTEX_SHADER, compile_shader_template(prefix_vertex + material.shader[:vertex_shader], binding)) - @fragment_shader = OpenGLShader.new(GL_FRAGMENT_SHADER, compile_shader_template(prefix_fragment + material.shader[:fragment_shader], binding)) + @vertex_shader = OpenGLShader.new(GL::VERTEX_SHADER, compile_shader_template(prefix_vertex + material.shader[:vertex_shader], binding)) + @fragment_shader = OpenGLShader.new(GL::FRAGMENT_SHADER, compile_shader_template(prefix_fragment + material.shader[:fragment_shader], binding)) - glAttachShader(@program, @vertex_shader.shader) - glAttachShader(@program, @fragment_shader.shader) + GL.AttachShader(@program, @vertex_shader.shader) + GL.AttachShader(@program, @fragment_shader.shader) end def compile_shader_template(template, b) @@ -177,8 +177,8 @@ def compile_shader_template(template, b) end def post_link_clean_up - glDeleteShader(@vertex_shader.shader) - glDeleteShader(@fragment_shader.shader) + GL.DeleteShader(@vertex_shader.shader) + GL.DeleteShader(@fragment_shader.shader) end def cache_uniform_locations(uniforms, parameters) @@ -212,7 +212,7 @@ def cache_uniform_locations(uniforms, parameters) @uniforms = {} identifiers.each do |id| - @uniforms[id] = glGetUniformLocation(program, id) + @uniforms[id] = GL.GetUniformLocation(program, id) end end @@ -243,7 +243,7 @@ def cache_attribute_locations(attributes, parameters) @attributes = {} identifiers.each do |id| - @attributes[id] = glGetAttribLocation(program, id) + @attributes[id] = GL.GetAttribLocation(program, id) end end end diff --git a/lib/mittsu/renderers/opengl/opengl_shader.rb b/lib/mittsu/renderers/opengl/opengl_shader.rb index 4e822c18..d6b90ba8 100644 --- a/lib/mittsu/renderers/opengl/opengl_shader.rb +++ b/lib/mittsu/renderers/opengl/opengl_shader.rb @@ -5,15 +5,15 @@ class OpenGLShader attr_reader :shader def initialize(type, string) - @shader = glCreateShader(type) - # filename = type == GL_VERTEX_SHADER ? 'vertex.glsl' : 'fragment.glsl' + @shader = GL.CreateShader(type) + # filename = type == GL::VERTEX_SHADER ? 'vertex.glsl' : 'fragment.glsl' # File.write filename, string string_pointer = Fiddle::Pointer[string] string_length = Fiddle::Pointer[string.length] - glShaderSource(@shader, 1, string_pointer.ref, string_length.ref) - glCompileShader(@shader) + GL.ShaderSource(@shader, 1, string_pointer.ref, string_length.ref) + GL.CompileShader(@shader) if !compile_status puts "ERROR: Mittsu::OpenGLShader: Shader couldn't compile" @@ -21,7 +21,7 @@ def initialize(type, string) log_info = shader_info_log if !log_info.empty? - puts "WARNING: Mittsu::OpenGLShader: glGetShaderInfoLog, #{log_info}" + puts "WARNING: Mittsu::OpenGLShader: GL.GetShaderInfoLog, #{log_info}" puts add_line_numbers(string) end end @@ -30,18 +30,18 @@ def initialize(type, string) def compile_status ptr = ' '*8 - glGetShaderiv @shader, GL_COMPILE_STATUS, ptr + GL.GetShaderiv @shader, GL::COMPILE_STATUS, ptr ptr.unpack('L')[0] end def shader_info_log ptr = ' '*8 - glGetShaderiv @shader, GL_INFO_LOG_LENGTH, ptr + GL.GetShaderiv @shader, GL::INFO_LOG_LENGTH, ptr length = ptr.unpack('L')[0] if length > 0 log = ' '*length - glGetShaderInfoLog @shader, length, ptr, log + GL.GetShaderInfoLog @shader, length, ptr, log log.unpack("A#{length}")[0] else '' diff --git a/lib/mittsu/renderers/opengl/opengl_state.rb b/lib/mittsu/renderers/opengl/opengl_state.rb index 9fa8e791..0f93edab 100644 --- a/lib/mittsu/renderers/opengl/opengl_state.rb +++ b/lib/mittsu/renderers/opengl/opengl_state.rb @@ -34,11 +34,11 @@ def init_attributes end def enable_attribute(attribute) - glEnableVertexAttribArray(attribute) + GL.EnableVertexAttribArray(attribute) @new_attributes[attribute] = true if !@enabled_attributes[attribute] - # glEnableVertexAttribArray(attribute) + # GL.EnableVertexAttribArray(attribute) @enabled_attributes[attribute] = true end end @@ -46,7 +46,7 @@ def enable_attribute(attribute) def disable_unused_attributes @enabled_attributes.length.times do |i| if @enabled_attributes[i] && !@new_attributes[i] - glDisableVertexAttribArray(i) + GL.DisableVertexAttribArray(i) @enabled_attributes[i] = false end end @@ -56,27 +56,27 @@ def set_blending(blending, blend_equation = nil, blend_src = nil, blend_dst = ni if blending != @current_blending case blending when NoBlending - glDisable(GL_BLEND) + GL.Disable(GL::BLEND) when AdditiveBlending - glEnable(GL_BLEND) - glBlendEquation(GL_FUNC_ADD) - glBlendFunc(GL_SRC_ALPHA, GL_ONE) + GL.Enable(GL::BLEND) + GL.BlendEquation(GL::FUNC_ADD) + GL.BlendFunc(GL::SRC_ALPHA, GL::ONE) when SubtractiveBlending # TODO: Find blendFuncSeparate() combination ??? - glEnable(GL_BLEND) - glBlendEquation(GL_FUNC_ADD) - glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR) + GL.Enable(GL::BLEND) + GL.BlendEquation(GL::FUNC_ADD) + GL.BlendFunc(GL::ZERO, GL::ONE_MINUS_SRC_COLOR) when MultiplyBlending # TODO: Find blendFuncSeparate() combination ??? - glEnable(GL_BLEND) - glBlendEquation(GL_FUNC_ADD) - glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR) + GL.Enable(GL::BLEND) + GL.BlendEquation(GL::FUNC_ADD) + GL.BlendFunc(GL::ZERO, GL::ONE_MINUS_SRC_COLOR) when CustomBlending - glEnable(GL_BLEND) + GL.Enable(GL::BLEND) else - glEnable(GL_BLEND) - glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD) - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA) + GL.Enable(GL::BLEND) + GL.BlendEquationSeparate(GL::FUNC_ADD, GL::FUNC_ADD) + GL.BlendFuncSeparate(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA, GL::ONE, GL::ONE_MINUS_SRC_ALPHA) end @current_blending = blending @@ -88,14 +88,14 @@ def set_blending(blending, blend_equation = nil, blend_src = nil, blend_dst = ni blend_dst_alpha ||= blend_dst if blend_equation != @current_blend_equation || blend_equation_alpha != @current_blend_equation_alpha - glBlendEquationSeparate(GL_MITTSU_PARAMS[blend_equation], GL_MITTSU_PARAMS[blend_equation_alpha]) + GL.BlendEquationSeparate(GL::MITTSU_PARAMS[blend_equation], GL::MITTSU_PARAMS[blend_equation_alpha]) @current_blend_equation = blend_equation @current_blend_equation_alpha = blend_equation_alpha end if blend_src != @current_blend_src || blend_dst != @current_blend_dst || blend_src_alpha != @current_blend_src_alpha || blend_dst_alpha != @current_blend_dst_alpha - glBlendFuncSeparate(GL_MITTSU_PARAMS[blend_src], GL_MITTSU_PARAMS[blend_dst], GL_MITTSU_PARAMS[blend_src_alpha], GL_MITTSU_PARAMS[blend_dst_alpha]) + GL.BlendFuncSeparate(GL::MITTSU_PARAMS[blend_src], GL::MITTSU_PARAMS[blend_dst], GL::MITTSU_PARAMS[blend_src_alpha], GL::MITTSU_PARAMS[blend_dst_alpha]) @current_blend_src = nil @current_blend_dst = nil @@ -115,9 +115,9 @@ def set_blending(blending, blend_equation = nil, blend_src = nil, blend_dst = ni def set_depth_test(depth_test) if @current_depth_test != depth_test if depth_test - glEnable(GL_DEPTH_TEST) + GL.Enable(GL::DEPTH_TEST) else - glDisable(GL_DEPTH_TEST) + GL.Disable(GL::DEPTH_TEST) end @current_depth_test = depth_test @@ -126,15 +126,15 @@ def set_depth_test(depth_test) def set_depth_write(depth_write) if @current_depth_write != depth_write - glDepthMask(depth_write ? GL_TRUE : GL_FALSE) + GL.DepthMask(depth_write ? GL::TRUE : GL::FALSE) @current_depth_write = depth_write end end def set_color_write(color_write) if @current_color_write != color_write - gl_color_write = color_write ? GL_TRUE : GL_FALSE - glColorMask(gl_color_write, gl_color_write, gl_color_write, gl_color_write) + gl_color_write = color_write ? GL::TRUE : GL::FALSE + GL.ColorMask(gl_color_write, gl_color_write, gl_color_write, gl_color_write) @current_color_write = color_write end end @@ -142,9 +142,9 @@ def set_color_write(color_write) def set_double_sided(double_sided) if @current_double_sided != double_sided if double_sided - glDisable(GL_CULL_FACE) + GL.Disable(GL::CULL_FACE) else - glEnable(GL_CULL_FACE) + GL.Enable(GL::CULL_FACE) end @current_double_sided = double_sided @@ -154,9 +154,9 @@ def set_double_sided(double_sided) def set_flip_sided(flip_sided) if @current_flip_sided != flip_sided if flip_sided - glFrontFace(GL_CW) + GL.FrontFace(GL::CW) else - glFrontFace(GL_CCW) + GL.FrontFace(GL::CCW) end @current_flip_sided = flip_sided @@ -165,7 +165,7 @@ def set_flip_sided(flip_sided) def set_line_width(width) if width != @current_line_width - glLineWidth(width) + GL.LineWidth(width) @current_line_width = width end end @@ -173,16 +173,16 @@ def set_line_width(width) def set_polygon_offset(polygon_offset, factor, units) if @current_polygon_offset != polygon_offset if polygon_offset - glEnable(GL_POLYGON_OFFSET_FILL) + GL.Enable(GL::POLYGON_OFFSET_FILL) else - glDisable(GL_POLYGON_OFFSET_FILL) + GL.Disable(GL::POLYGON_OFFSET_FILL) end @current_polygon_offset = polygon_offset end if polygon_offset && (@current_polygon_offset_factor != factor || @current_polygon_offset_units != units) - glPolygonOffset(factor, units) + GL.PolygonOffset(factor, units) @current_polygon_offset_factor = factor @current_polygon_offset_units = units diff --git a/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb b/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb index 0c7a462d..688fb539 100644 --- a/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +++ b/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb @@ -63,16 +63,16 @@ def render(scene, camera) # set GL state for depth map - glClearColor(1.0, 1.0, 1.0, 1.0) - glDisable(GL_BLEND) + GL.ClearColor(1.0, 1.0, 1.0, 1.0) + GL.Disable(GL::BLEND) - glEnable(GL_CULL_FACE) - glFrontFace(GL_CCW) + GL.Enable(GL::CULL_FACE) + GL.FrontFace(GL::CCW) if @renderer.shadow_map_cull_face = CullFaceFront - glCullFace(GL_FRONT) + GL.CullFace(GL::FRONT) else - glCullFace(GL_BACK) + GL.CullFace(GL::BACK) end @renderer.state.set_depth_test(true) @@ -258,11 +258,11 @@ def render(scene, camera) clear_color = @renderer.get_clear_color clear_alpha = @renderer.get_clear_alpha - glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_alpha) - glEnable(GL_BLEND) + GL.ClearColor(clear_color.r, clear_color.g, clear_color.b, clear_alpha) + GL.Enable(GL::BLEND) if @renderer.shadow_map_cull_face == CullFaceFront - glCullFace(GL_BACK) + GL.CullFace(GL::BACK) end @renderer.reset_gl_state diff --git a/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb b/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb index 704841b3..93dcb92d 100644 --- a/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +++ b/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb @@ -36,7 +36,7 @@ def render(scene, camera) render_all_sprites(scene) - glEnable(GL_CULL_FACE) + GL.Enable(GL::CULL_FACE) @renderer.reset_gl_state end @@ -53,60 +53,60 @@ def init end def create_vertex_array_object - @vertex_array_object = glCreateVertexArray - glBindVertexArray(@vertex_array_object) + @vertex_array_object = GL.CreateVertexArray + GL.BindVertexArray(@vertex_array_object) - @vertex_buffer = glCreateBuffer - @element_buffer = glCreateBuffer + @vertex_buffer = GL.CreateBuffer + @element_buffer = GL.CreateBuffer - glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer) - glBufferData_easy(GL_ARRAY_BUFFER, VERTICES, GL_STATIC_DRAW) + GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer) + GL.BufferData_easy(GL::ARRAY_BUFFER, VERTICES, GL::STATIC_DRAW) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @element_buffer) - glBufferData_easy(GL_ELEMENT_ARRAY_BUFFER, FACES, GL_STATIC_DRAW) + GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @element_buffer) + GL.BufferData_easy(GL::ELEMENT_ARRAY_BUFFER, FACES, GL::STATIC_DRAW) end def create_program - @program = glCreateProgram + @program = GL.CreateProgram - vertex_shader = OpenGLShader.new(GL_VERTEX_SHADER, File.read(File.join(__dir__, 'sprite_vertex.glsl'))) - fragment_shader = OpenGLShader.new(GL_FRAGMENT_SHADER, File.read(File.join(__dir__, 'sprite_fragment.glsl'))) + vertex_shader = OpenGLShader.new(GL::VERTEX_SHADER, File.read(File.join(__dir__, 'sprite_vertex.glsl'))) + fragment_shader = OpenGLShader.new(GL::FRAGMENT_SHADER, File.read(File.join(__dir__, 'sprite_fragment.glsl'))) - glAttachShader(@program, vertex_shader.shader) - glAttachShader(@program, fragment_shader.shader) + GL.AttachShader(@program, vertex_shader.shader) + GL.AttachShader(@program, fragment_shader.shader) - glLinkProgram(@program) + GL.LinkProgram(@program) end def init_attributes @attributes = { - position: glGetAttribLocation(@program, 'position'), - uv: glGetAttribLocation(@program, 'uv') + position: GL.GetAttribLocation(@program, 'position'), + uv: GL.GetAttribLocation(@program, 'uv') } end def init_uniforms @uniforms = { - uvOffset: glGetUniformLocation(@program, 'uvOffset'), - uvScale: glGetUniformLocation(@program, 'uvScale'), + uvOffset: GL.GetUniformLocation(@program, 'uvOffset'), + uvScale: GL.GetUniformLocation(@program, 'uvScale'), - rotation: glGetUniformLocation(@program, 'rotation'), - scale: glGetUniformLocation(@program, 'scale'), + rotation: GL.GetUniformLocation(@program, 'rotation'), + scale: GL.GetUniformLocation(@program, 'scale'), - color: glGetUniformLocation(@program, 'color'), - map: glGetUniformLocation(@program, 'map'), - opacity: glGetUniformLocation(@program, 'opacity'), + color: GL.GetUniformLocation(@program, 'color'), + map: GL.GetUniformLocation(@program, 'map'), + opacity: GL.GetUniformLocation(@program, 'opacity'), - modelViewMatrix: glGetUniformLocation(@program, 'modelViewMatrix'), - projectionMatrix: glGetUniformLocation(@program, 'projectionMatrix'), + modelViewMatrix: GL.GetUniformLocation(@program, 'modelViewMatrix'), + projectionMatrix: GL.GetUniformLocation(@program, 'projectionMatrix'), - fogType: glGetUniformLocation(@program, 'fogType'), - fogDensity: glGetUniformLocation(@program, 'fogDensity'), - fogNear: glGetUniformLocation(@program, 'fogNear'), - fogFar: glGetUniformLocation(@program, 'fogFar'), - fogColor: glGetUniformLocation(@program, 'fogColor'), + fogType: GL.GetUniformLocation(@program, 'fogType'), + fogDensity: GL.GetUniformLocation(@program, 'fogDensity'), + fogNear: GL.GetUniformLocation(@program, 'fogNear'), + fogFar: GL.GetUniformLocation(@program, 'fogFar'), + fogColor: GL.GetUniformLocation(@program, 'fogColor'), - alphaTest: glGetUniformLocation(@program, 'alphaTest') + alphaTest: GL.GetUniformLocation(@program, 'alphaTest') } end @@ -119,27 +119,27 @@ def painter_sort_stable(a, b) end def setup_gl_for_render(camera) - glUseProgram(@program) + GL.UseProgram(@program) - glDisable(GL_CULL_FACE) - glEnable(GL_BLEND) + GL.Disable(GL::CULL_FACE) + GL.Enable(GL::BLEND) - glBindVertexArray(@vertex_array_object) + GL.BindVertexArray(@vertex_array_object) - glEnableVertexAttribArray(@attributes[:position]) - glEnableVertexAttribArray(@attributes[:uv]) + GL.EnableVertexAttribArray(@attributes[:position]) + GL.EnableVertexAttribArray(@attributes[:uv]) - glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer) + GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer) - glVertexAttribPointer(@attributes[:position], 2, GL_FLOAT, GL_FALSE, 2 * 8, 0) - glVertexAttribPointer(@attributes[:uv], 2, GL_FLOAT, GL_FALSE, 2 * 8, 8) + GL.VertexAttribPointer(@attributes[:position], 2, GL::FLOAT, GL::FALSE, 2 * 8, 0) + GL.VertexAttribPointer(@attributes[:uv], 2, GL::FLOAT, GL::FALSE, 2 * 8, 8) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @element_buffer) + GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @element_buffer) - glUniformMatrix4fv(@uniforms[:projectionMatrix], 1, GL_FALSE, array_to_ptr_easy(camera.projection_matrix.elements)) + GL.UniformMatrix4fv(@uniforms[:projectionMatrix], 1, GL::FALSE, array_to_ptr_easy(camera.projection_matrix.elements)) - glActiveTexture(GL_TEXTURE0) - glUniform1i(@uniforms[:map], 0) + GL.ActiveTexture(GL::TEXTURE0) + GL.Uniform1i(@uniforms[:map], 0) end def setup_fog(scene) @@ -148,24 +148,24 @@ def setup_fog(scene) fog = scene.fog if fog - glUniform3f(@uniforms[:fogColor], fog.color.r, fog.color.g, fog.color.b) + GL.Uniform3f(@uniforms[:fogColor], fog.color.r, fog.color.g, fog.color.b) if fog.is_a?(Fog) - glUniform1f(@uniforms[:fogNear], fog.near) - glUniform1f(@uniforms[:fogFar], fog.far) + GL.Uniform1f(@uniforms[:fogNear], fog.near) + GL.Uniform1f(@uniforms[:fogFar], fog.far) - glUniform1i(@uniforms[:fogType], 1) + GL.Uniform1i(@uniforms[:fogType], 1) @old_fog_type = 1 @scene_fog_type = 1 elsif fog.is_a?(FogExp2) - glUniform1f(@uniforms[:fogDensity], fog.density) + GL.Uniform1f(@uniforms[:fogDensity], fog.density) - glUniform1i(@uniforms[:fogType], 2) + GL.Uniform1i(@uniforms[:fogType], 2) @old_fog_type = 2 @scene_fog_type = 2 end else - glUniform1i(@uniforms[:fogType], 0) + GL.Uniform1i(@uniforms[:fogType], 0) @old_fog_type = 0 @scene_fog_type = 0 end @@ -199,7 +199,7 @@ def render_all_sprites(scene) end # draw elements - glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) # GL_UNSIGNED_SHORT + GL.DrawElements(GL::TRIANGLES, 6, GL::UNSIGNED_INT, 0) # GL::UNSIGNED_SHORT end end @@ -211,34 +211,34 @@ def set_fog_uniforms(material, scene) end if @old_fog_type != fog_type - glUniform1(@uniforms[:fogType], fog_type) + GL.Uniform1(@uniforms[:fogType], fog_type) @old_fog_type = fog_type end end def set_uv_uniforms(material) if !material.map.nil? - glUniform2f(@uniforms[:uvOffset], material.map.offset.x, material.map.offset.y) - glUniform2f(@uniforms[:uvScale], material.map.repeat.x, material.map.repeat.y) + GL.Uniform2f(@uniforms[:uvOffset], material.map.offset.x, material.map.offset.y) + GL.Uniform2f(@uniforms[:uvScale], material.map.repeat.x, material.map.repeat.y) else - glUniform2f(@uniforms[:uvOffset], 0.0, 0.0) - glUniform2f(@uniforms[:uvScale], 1.0, 1.0) + GL.Uniform2f(@uniforms[:uvOffset], 0.0, 0.0) + GL.Uniform2f(@uniforms[:uvScale], 1.0, 1.0) end end def set_color_uniforms(material) - glUniform1f(@uniforms[:opacity], material.opacity) - glUniform3f(@uniforms[:color], material.color.r, material.color.g, material.color.b) - glUniform1f(@uniforms[:alphaTest], material.alpha_test) + GL.Uniform1f(@uniforms[:opacity], material.opacity) + GL.Uniform3f(@uniforms[:color], material.color.r, material.color.g, material.color.b) + GL.Uniform1f(@uniforms[:alphaTest], material.alpha_test) end def set_transform_uniforms(sprite) - glUniformMatrix4fv(@uniforms[:modelViewMatrix], 1, GL_FALSE, array_to_ptr_easy(sprite.model_view_matrix.elements)) + GL.UniformMatrix4fv(@uniforms[:modelViewMatrix], 1, GL::FALSE, array_to_ptr_easy(sprite.model_view_matrix.elements)) sprite.matrix_world.decompose(@sprite_position, @sprite_rotation, @sprite_scale) - glUniform1f(@uniforms[:rotation], sprite.material.rotation) - glUniform2fv(@uniforms[:scale], 1, array_to_ptr_easy([@sprite_scale.x, @sprite_scale.y])) + GL.Uniform1f(@uniforms[:rotation], sprite.material.rotation) + GL.Uniform2fv(@uniforms[:scale], 1, array_to_ptr_easy([@sprite_scale.x, @sprite_scale.y])) end def set_blend_mode(material) diff --git a/lib/mittsu/renderers/opengl/textures/compressed_texture.rb b/lib/mittsu/renderers/opengl/textures/compressed_texture.rb index e35ef664..e0387dc1 100644 --- a/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +++ b/lib/mittsu/renderers/opengl/textures/compressed_texture.rb @@ -1,18 +1,18 @@ module Mittsu class CompressedTexture def update_specific - gl_format = GL_MITTSU_PARAMS[format] - gl_type = GL_MITTSU_PARAMS[type] + gl_format = GL::MITTSU_PARAMS[format] + gl_type = GL::MITTSU_PARAMS[type] mipmaps.each_with_index do |mipmap, i| if format != RGBAFormat && format != RGBFormat if @renderer.compressed_texture_formats.include?(gl_format) - glCompressedTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, mipmap.data) + GL.CompressedTexImage2D(GL::TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, mipmap.data) else puts 'WARNING: Mittsu::Texture: Attempt to load unsupported compressed texture format in #update_texture' end else - glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) + GL.TexImage2D(GL::TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) end end end diff --git a/lib/mittsu/renderers/opengl/textures/cube_texture.rb b/lib/mittsu/renderers/opengl/textures/cube_texture.rb index c6005c05..df9eb246 100644 --- a/lib/mittsu/renderers/opengl/textures/cube_texture.rb +++ b/lib/mittsu/renderers/opengl/textures/cube_texture.rb @@ -7,14 +7,14 @@ def set(slot, renderer) if needs_update? if !image[:_opengl_texture_cube] add_event_listener(:dispose, @renderer.method(:on_texture_dispose)) - image[:_opengl_texture_cube] = glCreateTexture + image[:_opengl_texture_cube] = GL.CreateTexture @renderer.info[:memory][:textures] += 1 end - glActiveTexture(GL_TEXTURE0 + slot) - glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube]) + GL.ActiveTexture(GL::TEXTURE0 + slot) + GL.BindTexture(GL::TEXTURE_CUBE_MAP, image[:_opengl_texture_cube]) - # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, texture.flip_y) + # GL.PixelStorei(GL::UNPACK_FLIP_Y_WEBGL, texture.flip_y) is_compressed = is_a?(CompressedTexture) is_data_texture = image[0].is_a?(DataTexture) @@ -31,17 +31,17 @@ def set(slot, renderer) img = cube_image[0] is_image_power_of_two = Math.power_of_two?(img.width) && Math.power_of_two?(img.height) - gl_format = GL_MITTSU_PARAMS[format] - gl_type = GL_MITTSU_PARAMS[type] + gl_format = GL::MITTSU_PARAMS[format] + gl_type = GL::MITTSU_PARAMS[type] - set_parameters(GL_TEXTURE_CUBE_MAP, is_image_power_of_two) + set_parameters(GL::TEXTURE_CUBE_MAP, is_image_power_of_two) 6.times do |i| if !is_compressed if is_data_texture - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data) + GL.TexImage2D(GL::TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data) else - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data) + GL.TexImage2D(GL::TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data) end else mipmaps = cube_image[i].mipmaps @@ -49,27 +49,27 @@ def set(slot, renderer) mipmaps.each_with_index do |mipmap, j| if format != RGBAFormat && format != RGBFormat if @renderer.compressed_texture_formats.include?(gl_format) - glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, mipmap.data) + GL.CompressedTexImage2D(GL::TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, mipmap.data) else puts "WARNING: Mittsu::OpenGLCubeTexture: Attempt to load unsupported compressed texture format in #set" end else - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) + GL.TexImage2D(GL::TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) end end end end if generate_mipmaps && is_image_power_of_two - glGenerateMipmap(GL_TEXTURE_CUBE_MAP) + GL.GenerateMipmap(GL::TEXTURE_CUBE_MAP) end self.needs_update = false on_update.call if on_update else - glActiveTexture(GL_TEXTURE0 + slot) - glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube]) + GL.ActiveTexture(GL::TEXTURE0 + slot) + GL.BindTexture(GL::TEXTURE_CUBE_MAP, image[:_opengl_texture_cube]) end end end diff --git a/lib/mittsu/renderers/opengl/textures/data_texture.rb b/lib/mittsu/renderers/opengl/textures/data_texture.rb index 0e8a4d2d..1abaab9a 100644 --- a/lib/mittsu/renderers/opengl/textures/data_texture.rb +++ b/lib/mittsu/renderers/opengl/textures/data_texture.rb @@ -1,8 +1,8 @@ module Mittsu class DataTexture def update_specific - gl_format = GL_MITTSU_PARAMS[format] - gl_type = GL_MITTSU_PARAMS[type] + gl_format = GL::MITTSU_PARAMS[format] + gl_type = GL::MITTSU_PARAMS[type] is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height) # use manually created mipmaps if available @@ -11,10 +11,10 @@ def update_specific if !mipmaps.empty? && is_image_power_of_two mipmaps.each_with_index do |mipmap, i| - glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) + GL.TexImage2D(GL::TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) end else - glTexImage2D(GL_TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data) + GL.TexImage2D(GL::TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data) end end end diff --git a/lib/mittsu/renderers/opengl/textures/texture.rb b/lib/mittsu/renderers/opengl/textures/texture.rb index 84ca5f68..4a0e0c43 100644 --- a/lib/mittsu/renderers/opengl/textures/texture.rb +++ b/lib/mittsu/renderers/opengl/textures/texture.rb @@ -5,12 +5,12 @@ class Texture def set(slot, renderer) @renderer = renderer - glActiveTexture(GL_TEXTURE0 + slot) + GL.ActiveTexture(GL::TEXTURE0 + slot) if needs_update? update_opengl(@renderer) else - glBindTexture(GL_TEXTURE_2D, @opengl_texture) + GL.BindTexture(GL::TEXTURE_2D, @opengl_texture) end end @@ -20,26 +20,26 @@ def update_opengl(renderer) if !@initted @initted = true add_event_listener(:dispose, @renderer.method(:on_texture_dispose)) - @opengl_texture = glCreateTexture + @opengl_texture = GL.CreateTexture @renderer.info[:memory][:textures] += 1 end - glBindTexture(GL_TEXTURE_2D, @opengl_texture) + GL.BindTexture(GL::TEXTURE_2D, @opengl_texture) - # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, flip_y) ??? - # glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiply_alpha) ??? - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment) + # GL.PixelStorei(GL::UNPACK_FLIP_Y_WEBGL, flip_y) ??? + # GL.PixelStorei(GL::UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiply_alpha) ??? + GL.PixelStorei(GL::UNPACK_ALIGNMENT, unpack_alignment) self.image = @renderer.clamp_to_max_size(image) is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height) - set_parameters(GL_TEXTURE_2D, is_image_power_of_two) + set_parameters(GL::TEXTURE_2D, is_image_power_of_two) update_specific if generate_mipmaps && is_image_power_of_two - glGenerateMipmap(GL_TEXTURE_2D) + GL.GenerateMipmap(GL::TEXTURE_2D) end self.needs_update = false @@ -51,21 +51,21 @@ def update_opengl(renderer) def set_parameters(texture_type, is_image_power_of_two) if is_image_power_of_two - glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_MITTSU_PARAMS[wrap_s]) - glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_MITTSU_PARAMS[wrap_t]) + GL.TexParameteri(texture_type, GL::TEXTURE_WRAP_S, GL::MITTSU_PARAMS[wrap_s]) + GL.TexParameteri(texture_type, GL::TEXTURE_WRAP_T, GL::MITTSU_PARAMS[wrap_t]) - glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, GL_MITTSU_PARAMS[mag_filter]) - glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_MITTSU_PARAMS[min_filter]) + GL.TexParameteri(texture_type, GL::TEXTURE_MAG_FILTER, GL::MITTSU_PARAMS[mag_filter]) + GL.TexParameteri(texture_type, GL::TEXTURE_MIN_FILTER, GL::MITTSU_PARAMS[min_filter]) else - glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) - glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) + GL.TexParameteri(texture_type, GL::TEXTURE_WRAP_S, GL::CLAMP_TO_EDGE) + GL.TexParameteri(texture_type, GL::TEXTURE_WRAP_T, GL::CLAMP_TO_EDGE) if wrap_s != ClampToEdgeWrapping || wrap_t != ClampToEdgeWrapping puts "WARNING: Mittsu::Texture: Texture is not power of two. Texture.wrap_s and Texture.wrap_t should be set to Mittsu::ClampToEdgeWrapping. (#{source_file})" end - glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, filter_fallback(mag_filter)) - glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter_fallback(min_filter)) + GL.TexParameteri(texture_type, GL::TEXTURE_MAG_FILTER, filter_fallback(mag_filter)) + GL.TexParameteri(texture_type, GL::TEXTURE_MIN_FILTER, filter_fallback(min_filter)) if min_filter != NearestFilter && min_filter != LinearFilter puts "WARNING: Mittsu::Texture: Texture is not a power of two. Texture.min_filter should be set to Mittsu::NearestFilter or Mittsu::LinearFilter. (#{source_file})" @@ -78,15 +78,15 @@ def set_parameters(texture_type, is_image_power_of_two) # Fallback filters for non-power-of-2 textures def filter_fallback(filter) if filter == NearestFilter || filter == NearestMipMapNearestFilter || filter == NearestMipMapLinearFilter - GL_NEAREST + GL::NEAREST end - GL_LINEAR + GL::LINEAR end def update_specific - gl_format = GL_MITTSU_PARAMS[format] - gl_type = GL_MITTSU_PARAMS[type] + gl_format = GL::MITTSU_PARAMS[format] + gl_type = GL::MITTSU_PARAMS[type] is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height) # use manually created mipmaps if available @@ -95,12 +95,12 @@ def update_specific if !mipmaps.empty? && is_image_power_of_two mipmaps.each_with_index do |mipmap, i| - glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) + GL.TexImage2D(GL::TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) end self.generate_mipmaps = false else - glTexImage2D(GL_TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data) + GL.TexImage2D(GL::TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data) end end end diff --git a/lib/mittsu/renderers/opengl_render_target.rb b/lib/mittsu/renderers/opengl_render_target.rb index c64cd92a..b241ecee 100644 --- a/lib/mittsu/renderers/opengl_render_target.rb +++ b/lib/mittsu/renderers/opengl_render_target.rb @@ -97,45 +97,45 @@ def setup_buffers add_event_listener(:dispose, @renderer.method(:on_render_target_dispose)) - @opengl_texture = glCreateTexture + @opengl_texture = GL.CreateTexture @renderer.info[:memory][:textures] += 1 # Setup texture, create render and frame buffers is_target_power_of_two = Math.power_of_two?(@width) && Math.power_of_two?(@height) - gl_format = GL_MITTSU_PARAMS[@format] - gl_type = GL_MITTSU_PARAMS[@type] + gl_format = GL::MITTSU_PARAMS[@format] + gl_type = GL::MITTSU_PARAMS[@type] if is_cube # TODO else - @framebuffer = glCreateFramebuffer + @framebuffer = GL.CreateFramebuffer if @share_depth_from @renderbuffer = share_depth_from.renderbuffer else - @renderbuffer = glCreateRenderbuffer + @renderbuffer = GL.CreateRenderbuffer end - glBindTexture(GL_TEXTURE_2D, @opengl_texture) - set_parameters(GL_TEXTURE_2D, is_target_power_of_two) + GL.BindTexture(GL::TEXTURE_2D, @opengl_texture) + set_parameters(GL::TEXTURE_2D, is_target_power_of_two) - glTexImage2D(GL_TEXTURE_2D, 0, gl_format, @width, @height, 0, gl_format, gl_type, nil) + GL.TexImage2D(GL::TEXTURE_2D, 0, gl_format, @width, @height, 0, gl_format, gl_type, nil) - setup_framebuffer(GL_TEXTURE_2D) + setup_framebuffer(GL::TEXTURE_2D) if @share_depth_from if @depth_buffer && !@stencil_buffer - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, @renderbuffer) + GL.FramebufferRenderbuffer(GL::FRAMEBUFFER, GL::DEPTH_ATTACHMENT, GL::RENDERBUFFER, @renderbuffer) elsif @depth_buffer && @stencil_buffer - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, @renderbuffer) + GL.FramebufferRenderbuffer(GL::FRAMEBUFFER, GL::DEPTH_STENCIL_ATTACHMENT, GL::RENDERBUFFER, @renderbuffer) end else setup_renderbuffer end - glGenerateMipmap(GL_TEXTURE_2D) if is_target_power_of_two + GL.GenerateMipmap(GL::TEXTURE_2D) if is_target_power_of_two end # Release everything @@ -143,16 +143,16 @@ def setup_buffers if is_cube # TODO else - glBindTexture(GL_TEXTURE_2D, 0) + GL.BindTexture(GL::TEXTURE_2D, 0) end - glBindRenderbuffer(GL_RENDERBUFFER, 0) - glBindFramebuffer(GL_FRAMEBUFFER, 0) + GL.BindRenderbuffer(GL::RENDERBUFFER, 0) + GL.BindFramebuffer(GL::FRAMEBUFFER, 0) end def use - glBindFramebuffer(GL_FRAMEBUFFER, @framebuffer) - glViewport(0, 0, @width, @height) + GL.BindFramebuffer(GL::FRAMEBUFFER, @framebuffer) + GL.Viewport(0, 0, @width, @height) end def dispose @@ -162,27 +162,27 @@ def dispose def update_mipmap return if !@generate_mipmaps || @min_filter == NearestFilter || @min_filter == LinearFilter # TODO: when OpenGLRenderTargetCube exists - # glBindTexture(GL_TEXTURE_CUBE_MAP, @opengl_texture) - # glGenerateMipmap(GL_TEXTURE_CUBE_MAP) - # glBindTexture(GL_TEXTURE_CUBE_MAP, nil) - glBindTexture(GL_TEXTURE_2D, @opengl_texture) - glGenerateMipmap(GL_TEXTURE_2D) - glBindTexture(GL_TEXTURE_2D, nil) + # GL.BindTexture(GL::TEXTURE_CUBE_MAP, @opengl_texture) + # GL.GenerateMipmap(GL::TEXTURE_CUBE_MAP) + # GL.BindTexture(GL::TEXTURE_CUBE_MAP, nil) + GL.BindTexture(GL::TEXTURE_2D, @opengl_texture) + GL.GenerateMipmap(GL::TEXTURE_2D) + GL.BindTexture(GL::TEXTURE_2D, nil) end private def setup_framebuffer(texture_target) - glBindFramebuffer(GL_FRAMEBUFFER, @framebuffer) - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture_target, @opengl_texture, 0) + GL.BindFramebuffer(GL::FRAMEBUFFER, @framebuffer) + GL.FramebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, texture_target, @opengl_texture, 0) end def setup_renderbuffer - glBindRenderbuffer(GL_RENDERBUFFER, @renderbuffer) + GL.BindRenderbuffer(GL::RENDERBUFFER, @renderbuffer) if @depth_buffer && !@stencil_buffer - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, @width, @height) - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, @renderbuffer) + GL.RenderbufferStorage(GL::RENDERBUFFER, GL::DEPTH_COMPONENT16, @width, @height) + GL.FramebufferRenderbuffer(GL::FRAMEBUFFER, GL::DEPTH_ATTACHMENT, GL::RENDERBUFFER, @renderbuffer) # TODO: investigate this (?): # THREE.js - For some reason this is not working. Defaulting to RGBA4. @@ -191,10 +191,10 @@ def setup_renderbuffer # _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height ); # _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer ); elsif @depth_buffer && @stencil_buffer - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, @width, @height) - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, @renderbuffer) + GL.RenderbufferStorage(GL::RENDERBUFFER, GL::DEPTH_STENCIL, @width, @height) + GL.FramebufferRenderbuffer(GL::FRAMEBUFFER, GL::DEPTH_STENCIL_ATTACHMENT, GL::RENDERBUFFER, @renderbuffer) else - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, @width, @height) + GL.RenderbufferStorage(GL::RENDERBUFFER, GL::RGBA4, @width, @height) end end end diff --git a/lib/mittsu/renderers/opengl_renderer.rb b/lib/mittsu/renderers/opengl_renderer.rb index 21083608..fd96ecd8 100644 --- a/lib/mittsu/renderers/opengl_renderer.rb +++ b/lib/mittsu/renderers/opengl_renderer.rb @@ -4,11 +4,12 @@ require 'mittsu/renderers/opengl/opengl_lib' opengl_lib = Mittsu::OpenGLLib.discover -OpenGL.load_lib(ENV["MITTSU_LIBGL_FILE"] || opengl_lib.file, ENV["MITTSU_LIBGL_PATH"] || opengl_lib.path) +GL.load_lib(ENV["MITTSU_LIBGL_FILE"] || opengl_lib.file, ENV["MITTSU_LIBGL_PATH"] || opengl_lib.path) require 'mittsu/renderers/glfw_window' +require 'mittsu/renderers/opengl/opengl_debug' if ENV['DEBUG'] require 'mittsu/renderers/opengl/opengl_implementations' -require 'mittsu/renderers/opengl/opengl_debug' +require 'mittsu/renderers/opengl/opengl_extensions' require 'mittsu/renderers/opengl/opengl_helper' require 'mittsu/renderers/opengl/opengl_program' require 'mittsu/renderers/opengl/opengl_state' @@ -20,8 +21,6 @@ require 'mittsu/renderers/opengl/plugins/sprite_plugin' require 'mittsu/renderers/shaders/shader_lib' require 'mittsu/renderers/shaders/uniforms_utils' - -include ENV['DEBUG'] ? OpenGLDebug : OpenGL include Mittsu::OpenGLHelper require 'mittsu/renderers/opengl/opengl_mittsu_params' @@ -104,7 +103,7 @@ def set_viewport(x, y, width, height) end def set_scissor(x, y, width, height) - glScissor( + GL.Scissor( x * pixel_ratio, y * pixel_ratio, width * pixel_ratio, @@ -113,7 +112,7 @@ def set_scissor(x, y, width, height) end def enable_scissor_test(enable) - enable ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST) + enable ? GL.Enable(GL::SCISSOR_TEST) : GL.Disable(GL::SCISSOR_TEST) end def object_in_frustum?(object) @@ -148,19 +147,19 @@ def set_clear_alpha(alpha) def clear(color = true, depth = true, stencil = true) bits = 0 - bits |= GL_COLOR_BUFFER_BIT if color - bits |= GL_DEPTH_BUFFER_BIT if depth - bits |= GL_STENCIL_BUFFER_BIT if stencil + bits |= GL::COLOR_BUFFER_BIT if color + bits |= GL::DEPTH_BUFFER_BIT if depth + bits |= GL::STENCIL_BUFFER_BIT if stencil - glClear(bits) + GL.Clear(bits) end def clear_depth - glClear(GL_DEPTH_BUFFER_BIT) + GL.Clear(GL::DEPTH_BUFFER_BIT) end def clear_stencil - glClear(GL_STENCIL_BUFFER_BIT) + GL.Clear(GL::STENCIL_BUFFER_BIT) end def clear_target(render_target, color, depth, stencil) @@ -325,24 +324,24 @@ def clear_color(r, g, b, a) r *= a; g *= a; b *= a end - glClearColor(r, g, b, a) + GL.ClearColor(r, g, b, a) end def set_default_gl_state - glClearColor(0.0, 0.0, 0.0, 1.0) - glClearDepth(1) - glClearStencil(0) + GL.ClearColor(0.0, 0.0, 0.0, 1.0) + GL.ClearDepth(1) + GL.ClearStencil(0) - glEnable(GL_DEPTH_TEST) - glDepthFunc(GL_LEQUAL) + GL.Enable(GL::DEPTH_TEST) + GL.DepthFunc(GL::LEQUAL) - glFrontFace(GL_CCW) - glCullFace(GL_BACK) - glEnable(GL_CULL_FACE) + GL.FrontFace(GL::CCW) + GL.CullFace(GL::BACK) + GL.Enable(GL::CULL_FACE) - glEnable(GL_BLEND) - glBlendEquation(GL_FUNC_ADD) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + GL.Enable(GL::BLEND) + GL.BlendEquation(GL::FUNC_ADD) + GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA) default_target.use_viewport @@ -448,26 +447,26 @@ def update_object(object) if geometry.is_a? BufferGeometry # TODO: geometry vertex array ????? - # glBindVertexArray geometry.vertex_array + # GL.BindVertexArray geometry.vertex_array geometry.attributes.each do |(key, attribute)| - buffer_type = (key == 'index') ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER + buffer_type = (key == 'index') ? GL::ELEMENT_ARRAY_BUFFER : GL::ARRAY_BUFFER if attribute.buffer.nil? - attribute.buffer = glCreateBuffer - glBindBuffer(buffer_type, attribute.buffer) - glBufferData_easy(buffer_type, attribute.array, (attribute.is_a? DynamicBufferAttribute) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW) + attribute.buffer = GL.CreateBuffer + GL.BindBuffer(buffer_type, attribute.buffer) + GL.BufferData_easy(buffer_type, attribute.array, (attribute.is_a? DynamicBufferAttribute) ? GL::DYNAMIC_DRAW : GL::STATIC_DRAW) attribute.needs_update = false elsif attribute.needs_update - glBindBuffer(buffer_type, attribute.buffer) + GL.BindBuffer(buffer_type, attribute.buffer) if attribute.update_range.nil? || attribute.update_range.count == -1 # Not using update ranged - glBufferSubData(buffer_type, 0, attribute.array) + GL.BufferSubData(buffer_type, 0, attribute.array) elsif attribute.udpate_range.count.zero? puts 'ERROR: Mittsu::OpenGLRenderer#update_object: using update_range for Mittsu::DynamicBufferAttribute and marked as needs_update but count is 0, ensure you are using set methods or updating manually.' else - # TODO: make a glBufferSubData_easy method - glBufferSubData(buffer_type, attribute.update_range.offset * attribute.array.BYTES_PER_ELEMENT, attribute.array.subarray(attribute.update_range.offset, attribute.update_range.offset + attribute.update_range.count)) + # TODO: make a GL.BufferSubData_easy method + GL.BufferSubData(buffer_type, attribute.update_range.offset * attribute.array.BYTES_PER_ELEMENT, attribute.array.subarray(attribute.update_range.offset, attribute.update_range.offset + attribute.update_range.count)) attribute.update_range.count = 0 # reset range end @@ -504,7 +503,7 @@ def set_program(camera, lights, fog, material, object) material_uniforms = material.shader[:uniforms] if program.id != @_current_program - glUseProgram(program.program) + GL.UseProgram(program.program) @_current_program = program.id refresh_program = true @@ -527,31 +526,31 @@ def set_program(camera, lights, fog, material, object) if material.skinning # TODO: when skinning is implemented. Then also refactor # if object.bind_matrix && !program_uniforms['bindMatrix'].nil? - # glUniformMatrix4fv(program_uniforms['bindMatrix'], GL_FALSE, object.bind_matrix.elements) + # GL.UniformMatrix4fv(program_uniforms['bindMatrix'], GL::FALSE, object.bind_matrix.elements) # end # # if object.bind_matrix_inverse && !program_uniforms['bindMatrixInverse'].nil? - # glUniformMatrix4fv(program_uniforms['bindMatrixInverse'], GL_FALSE, object.bind_matrix_inverse.elements) + # GL.UniformMatrix4fv(program_uniforms['bindMatrixInverse'], GL::FALSE, object.bind_matrix_inverse.elements) # end # # if @_supports_bone_textures && object.skeleton && object.skeleton.use_vertex_texture # if !program_uniforms['boneTexture'].nil? # texture_unit = get_texture_unit # - # glUniform1i(program_uniforms['boneTexture'], texture_unit) + # GL.Uniform1i(program_uniforms['boneTexture'], texture_unit) # object.skeleton.bone_texture.set(texture_unit, self) # end # # if !program_uniforms['boneTextureWidth'].nil? - # glUniform1i(program_uniforms['boneTextureWidth'], object.skeleton.bone_texture_width) + # GL.Uniform1i(program_uniforms['boneTextureWidth'], object.skeleton.bone_texture_width) # end # # if !program_uniforms['boneTextureHeight'].nil? - # glUniform1i(program_uniforms['boneTextureHeight'], object.skeleton.bone_texture_height) + # GL.Uniform1i(program_uniforms['boneTextureHeight'], object.skeleton.bone_texture_height) # end # elsif object.skeleton && object.skeleton.bone_matrices # if !program_uniforms['boneGlobalMatrices'].nil? - # glUniformMatrix4fv(program_uniforms['boneGlobalMatrices'], GL_FALSE, object.skeleton.bone_matrices) + # GL.UniformMatrix4fv(program_uniforms['boneGlobalMatrices'], GL::FALSE, object.skeleton.bone_matrices) # end # end end @@ -596,7 +595,7 @@ def set_program(camera, lights, fog, material, object) object.load_uniforms_matrices(program_uniforms) if !program_uniforms['modelMatrix'].nil? - glUniformMatrix4fv(program_uniforms['modelMatrix'], 1, GL_FALSE, array_to_ptr_easy(object.matrix_world.elements)) + GL.UniformMatrix4fv(program_uniforms['modelMatrix'], 1, GL::FALSE, array_to_ptr_easy(object.matrix_world.elements)) end program @@ -615,56 +614,56 @@ def load_uniforms_generic(uniforms) # AAAAAHHHHH!!!!! \o/ *flips table* case type when :int - glUniform1i(location, value) + GL.Uniform1i(location, value) when :ivec2 - glUniform2i(location, value[0], value[1]) + GL.Uniform2i(location, value[0], value[1]) when :ivec3 - glUniform3i(location, value[0], value[1], value[2]) + GL.Uniform3i(location, value[0], value[1], value[2]) when :ivec4 - glUniform4i(location, value[0], value[1], value[2], value[3]) + GL.Uniform4i(location, value[0], value[1], value[2], value[3]) when :float - glUniform1f(location, value) + GL.Uniform1f(location, value) when :vec2 - glUniform2f(location, value[0], value[1]) + GL.Uniform2f(location, value[0], value[1]) when :vec3, :color - glUniform3f(location, value[0], value[1], value[2]) + GL.Uniform3f(location, value[0], value[1], value[2]) when :vec4 - glUniform4f(location, value[0], value[1], value[2], value[3]) + GL.Uniform4f(location, value[0], value[1], value[2], value[3]) when :'int[]' - glUniform1iv(location, value.length, array_to_ptr_easy(value)) + GL.Uniform1iv(location, value.length, array_to_ptr_easy(value)) when :'ivec2[]' - glUniform2iv(location, value.length / 2, array_to_ptr_easy(value)) + GL.Uniform2iv(location, value.length / 2, array_to_ptr_easy(value)) when :'ivec3[]' - glUniform3iv(location, value.length / 3, array_to_ptr_easy(value)) + GL.Uniform3iv(location, value.length / 3, array_to_ptr_easy(value)) when :'ivec4[]' - glUniform4iv(location, value.length / 4, array_to_ptr_easy(value)) + GL.Uniform4iv(location, value.length / 4, array_to_ptr_easy(value)) when :'float[]' - glUniform1fv(location, value.length, array_to_ptr_easy(value)) + GL.Uniform1fv(location, value.length, array_to_ptr_easy(value)) when :'vec2[]' if value[0].is_a? Vector2 uniform.array ||= value.flat_map(&:to_a) # TODO: Float32Array - glUniform2fv(location, value.length, array_to_ptr_easy(uniform.array)) + GL.Uniform2fv(location, value.length, array_to_ptr_easy(uniform.array)) else - glUniform2fv(location, value.length / 2, array_to_ptr_easy(value)) + GL.Uniform2fv(location, value.length / 2, array_to_ptr_easy(value)) end when :'vec3[]', :'color[]' if value.first.is_a?(Vector3) || value.first.is_a?(Color) uniform.array ||= value.flat_map(&:to_a) # TODO: Float32Array - glUniform3fv(location, value.length, array_to_ptr_easy(uniform.array)) + GL.Uniform3fv(location, value.length, array_to_ptr_easy(uniform.array)) else - glUniform3fv(location, value.length / 3, array_to_ptr_easy(value)) + GL.Uniform3fv(location, value.length / 3, array_to_ptr_easy(value)) end when :'vec4[]' if value.first.is_a? Vector4 uniform.array ||= value.flat_map(&:to_a) # TODO: Float32Array - glUniform4fv(location, value.length, array_to_ptr_easy(uniform.array)) + GL.Uniform4fv(location, value.length, array_to_ptr_easy(uniform.array)) else - glUniform4fv(location, value.length / 4, array_to_ptr_easy(value)) + GL.Uniform4fv(location, value.length / 4, array_to_ptr_easy(value)) end when :mat3 - glUniformMatrix3fv(location, 1, GL_FALSE, array_to_ptr_easy(value.to_a)) + GL.UniformMatrix3fv(location, 1, GL::FALSE, array_to_ptr_easy(value.to_a)) when :mat4 - glUniformMatrix4fv(location, 1, GL_FALSE, array_to_ptr_easy(value.to_a)) + GL.UniformMatrix4fv(location, 1, GL::FALSE, array_to_ptr_easy(value.to_a)) when :'mat3[]' if value.first.is_a? Matrix3 uniform.array ||= Array.new(9 * value.length) # Float32Array @@ -673,9 +672,9 @@ def load_uniforms_generic(uniforms) value[i].flatten_to_array_offset(uniform.array, i * 9) end - glUniformMatrix3fv(location, value.length, GL_FALSE, array_to_ptr_easy(uniform.array)) + GL.UniformMatrix3fv(location, value.length, GL::FALSE, array_to_ptr_easy(uniform.array)) else - glUniformMatrix3fv(location, value.length / 9, GL_FALSE, array_to_ptr_easy(value)) + GL.UniformMatrix3fv(location, value.length / 9, GL::FALSE, array_to_ptr_easy(value)) end when :'mat4[]' if value.first.is_a? Matrix4 @@ -685,16 +684,16 @@ def load_uniforms_generic(uniforms) value[i].flatten_to_array_offset(uniform.array, i * 16) end - glUniformMatrix4fv(location, value.length, GL_FALSE, array_to_ptr_easy(uniform.array)) + GL.UniformMatrix4fv(location, value.length, GL::FALSE, array_to_ptr_easy(uniform.array)) else - glUniformMatrix4fv(location, value.length / 16, GL_FALSE, array_to_ptr_easy(value)) + GL.UniformMatrix4fv(location, value.length / 16, GL::FALSE, array_to_ptr_easy(value)) end when :texture # single Mittsu::Texture (2d or cube) texture = value texture_unit = get_texture_unit - glUniform1i(location, texture_unit) + GL.Uniform1i(location, texture_unit) next unless texture @@ -710,7 +709,7 @@ def load_uniforms_generic(uniforms) uniform.array[i] = get_texture_unit end - glUniform1iv(location, uniform.array.length, array_to_ptr_easy(uniform.array)) + GL.Uniform1iv(location, uniform.array.length, array_to_ptr_easy(uniform.array)) uniform.value.each_with_index do |tex, i| tex_unit = uniform.array[i] @@ -946,10 +945,10 @@ def fetch_parameters(parameters) end def get_gpu_capabilities - @_max_textures = glGetParameter(GL_MAX_TEXTURE_IMAGE_UNITS) - @_max_vertex_textures = glGetParameter(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS) - @_max_texture_size = glGetParameter(GL_MAX_TEXTURE_SIZE) - @_max_cubemap_size = glGetParameter(GL_MAX_CUBE_MAP_TEXTURE_SIZE) + @_max_textures = GL.GetParameter(GL::MAX_TEXTURE_IMAGE_UNITS) + @_max_vertex_textures = GL.GetParameter(GL::MAX_VERTEX_TEXTURE_IMAGE_UNITS) + @_max_texture_size = GL.GetParameter(GL::MAX_TEXTURE_SIZE) + @_max_cubemap_size = GL.GetParameter(GL::MAX_CUBE_MAP_TEXTURE_SIZE) @_supports_vertex_textures = @_max_vertex_textures > 0 @_supports_bone_textures = @_supports_vertex_textures && false # TODO: extensions.get('OES_texture_float') ???? @@ -998,19 +997,19 @@ def default_target end def update_camera_uniforms(uniforms, camera, material) - glUniformMatrix4fv(uniforms['projectionMatrix'], 1, GL_FALSE, array_to_ptr_easy(camera.projection_matrix.elements)) + GL.UniformMatrix4fv(uniforms['projectionMatrix'], 1, GL::FALSE, array_to_ptr_easy(camera.projection_matrix.elements)) if @logarithmic_depth_buffer - glUniform1f(uniforms['logDepthBuffFC'], 2.0 / ::Math.log(camera.far + 1.0) / Math::LN2) + GL.Uniform1f(uniforms['logDepthBuffFC'], 2.0 / ::Math.log(camera.far + 1.0) / Math::LN2) end if material.needs_camera_position_uniform? && !uniforms['cameraPosition'].nil? @_vector3.set_from_matrix_position(camera.matrix_world) - glUniform3f(uniforms['cameraPosition'], @_vector3.x, @_vector3.y, @_vector3.z) + GL.Uniform3f(uniforms['cameraPosition'], @_vector3.x, @_vector3.y, @_vector3.z) end if material.needs_view_matrix_uniform? && !uniforms['viewMatrix'].nil? - glUniformMatrix4fv(uniforms['viewMatrix'], 1, GL_FALSE, array_to_ptr_easy(camera.matrix_world_inverse.elements)) + GL.UniformMatrix4fv(uniforms['viewMatrix'], 1, GL::FALSE, array_to_ptr_easy(camera.matrix_world_inverse.elements)) end end @@ -1019,7 +1018,7 @@ def remove_child(object) @_opengl_objects.delete(object.id) # elsif object.is_a?(ImmediateRenderObject) || object.immediate_render_callback - # removeInstances( _webglObjectsImmediate, object ); + # removeInstances( _webGL.ObjectsImmediate, object ); end object.deinit diff --git a/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb b/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb index 657ba803..f75fa7a4 100644 --- a/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +++ b/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb @@ -97,7 +97,7 @@ <% if parameters[:logarithmic_depth_buffer] %> #define USE_LOGDEPTHBUF <% end %> -// @renderer._glExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', +// @renderer._GL.ExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', uniform mat4 viewMatrix; uniform vec3 cameraPosition; diff --git a/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb b/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb index 2e351b90..e2d76cfb 100644 --- a/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +++ b/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb @@ -98,7 +98,7 @@ <% if parameters[:logarithmic_depth_buffer] %> #define USE_LOGDEPTHBUF <% end %> -// @renderer._glExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', +// @renderer._GL.ExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', uniform mat4 modelMatrix; diff --git a/lib/mittsu/textures/texture.rb b/lib/mittsu/textures/texture.rb index 260653fd..da652031 100644 --- a/lib/mittsu/textures/texture.rb +++ b/lib/mittsu/textures/texture.rb @@ -39,7 +39,7 @@ def initialize(image = DEFAULT_IMAGE, mapping = DEFAULT_MAPPING, wrap_s = ClampT @generate_mipmaps = true @premultiply_alpha = false @filp_y = true - @unpack_alignment = 4 # valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml) + @unpack_alignment = 4 # valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/GL.PixelStorei.xml) @_needs_update = false @on_update = nil diff --git a/mittsu.gemspec b/mittsu.gemspec index ea66e7bd..323566a5 100644 --- a/mittsu.gemspec +++ b/mittsu.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.0.0' spec.requirements << 'OpenGL 3.3+ capable hardware and drivers' - spec.add_runtime_dependency 'opengl-bindings' + spec.add_runtime_dependency 'opengl-bindings2' spec.add_runtime_dependency 'ffi' spec.add_runtime_dependency 'chunky_png' diff --git a/test/support/opengl_stub.rb b/test/support/opengl_stub.rb index 8d876b43..925f0a23 100644 --- a/test/support/opengl_stub.rb +++ b/test/support/opengl_stub.rb @@ -11,266 +11,263 @@ def self.discover module OpenGLStub def self.load_lib(*args) + # stub end - def self.get_command(command) - OpenGLInstance.method(command) + GL.constants.each do |c| + const_set c, GL.const_get(c) end - OpenGL.constants.each do |c| - const_set c, OpenGL.const_get(c) - end + class << self + GL::GL_FUNCTION_SYMBOLS.each do |m| + define_method(m.to_s.gsub(/^gl/, '').to_sym) do |*args| + nil + end + end - OpenGL.instance_methods.each do |m| - define_method m do |*args| + def GenVertexArrays(n, arrays) + next_va = (@@_GenVertexArrays ||= 1) + @@_GenVertexArrays += n + arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) nil end - end - - def glGenVertexArrays(n, arrays) - next_va = (@@_glGenVertexArrays ||= 1) - @@_glGenVertexArrays += n - arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) - nil - end - def glGenBuffers(n, arrays) - next_va = (@@_glGenBuffers ||= 1) - @@_glGenBuffers += n - arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) - nil - end + def GenBuffers(n, arrays) + next_va = (@@_GenBuffers ||= 1) + @@_GenBuffers += n + arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) + nil + end - def glGenTextures(n, arrays) - next_va = (@@_glGenTextures ||= 1) - @@_glGenTextures += n - arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) - nil - end + def GenTextures(n, arrays) + next_va = (@@_GenTextures ||= 1) + @@_GenTextures += n + arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) + nil + end - def glGenFramebuffers(n, arrays) - next_va = (@@_glGenFramebuffers ||= 1) - @@_glGenFramebuffers += n - arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) - nil - end + def GenFramebuffers(n, arrays) + next_va = (@@_GenFramebuffers ||= 1) + @@_GenFramebuffers += n + arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) + nil + end - def glGenRenderbuffers(n, arrays) - next_va = (@@_glGenRenderbuffers ||= 1) - @@_glGenRenderbuffers += n - arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) - nil - end + def GenRenderbuffers(n, arrays) + next_va = (@@_GenRenderbuffers ||= 1) + @@_GenRenderbuffers += n + arrays[0...n*4] = n.times.map { |i| i + next_va }.pack('L'*n) + nil + end - def glGetBooleanv(_, params) - params[0] = [1].pack('C') - nil - end + def GetBooleanv(_, params) + params[0] = [1].pack('C') + nil + end - def glGetDoublev(_, params) - params[0..-1] = [rand].pack('D') - nil - end + def GetDoublev(_, params) + params[0..-1] = [rand].pack('D') + nil + end - def glGetFloatv(_, params) - params[0..-1] = [rand].pack('F') - nil - end + def GetFloatv(_, params) + params[0..-1] = [rand].pack('F') + nil + end - def glGetIntegerv(_, params) - params[0..-1] = [4096].pack('L') - nil - end + def GetIntegerv(_, params) + params[0..-1] = [4096].pack('L') + nil + end - def glGetShaderiv(_, _, params) - params[0..-1] = [4096].pack('L') - nil - end - alias :glGetProgramiv :glGetShaderiv + def GetShaderiv(_, _, params) + params[0..-1] = [4096].pack('L') + nil + end + alias :GetProgramiv :GetShaderiv - def glGetShaderInfoLog(_, _, length, infoLog) - length[0...4] = [0].pack('L') - nil - end - alias :glGetProgramInfoLog :glGetShaderInfoLog + def GetShaderInfoLog(_, _, length, infoLog) + length[0...4] = [0].pack('L') + nil + end + alias :GetProgramInfoLog :GetShaderInfoLog - def glGetError() - OpenGL::GL_NO_ERROR - end + def GetError() + GL::NO_ERROR + end - def glFrontFace(mode) - @@_glFrontFace = mode - end + def FrontFace(mode) + @@_FrontFace = mode + end - def glCullFace(mode) - @@_glCullFace = mode - end + def CullFace(mode) + @@_CullFace = mode + end - def glEnable(cap) - (@@_glEnable ||= {}).tap { |e| e[cap] = true } - end + def Enable(cap) + (@@_Enable ||= {}).tap { |e| e[cap] = true } + end - def glDisable(cap) - (@@_glEnable ||= {}).tap { |e| e[cap] = false } - end + def Disable(cap) + (@@_Enable ||= {}).tap { |e| e[cap] = false } + end - def glIsEnabled(cap) - (@@_glEnable ||= {})[cap] - end + def IsEnabled(cap) + (@@_Enable ||= {})[cap] + end - def glGenLists(_range_) - _range_ - end + def GenLists(_range_) + _range_ + end - def glRenderMode(_mode_) - 0 - end + def RenderMode(_mode_) + 0 + end - def glIsList(_list_) - true - end + def IsList(_list_) + true + end - def glIsTexture(_texture_) - true - end + def IsTexture(_texture_) + true + end - def glAreTexturesResident(_n_, _textures_, _residences_) - true - end + def AreTexturesResident(_n_, _textures_, _residences_) + true + end - def glIsQuery(_id_) - true - end + def IsQuery(_id_) + true + end - def glIsBuffer(_buffer_) - true - end + def IsBuffer(_buffer_) + true + end - def glUnmapBuffer(_target_) - true - end + def UnmapBuffer(_target_) + true + end - def glCreateProgram() - (@@_glCreateProgram ||= 1).tap { @@_glCreateProgram += 1 } - end + def CreateProgram() + (@@_CreateProgram ||= 1).tap { @@_CreateProgram += 1 } + end - def glCreateShader(_type_) - (@@_glCreateShader ||= 1).tap { @@_glCreateShader += 1 } - end + def CreateShader(_type_) + (@@_CreateShader ||= 1).tap { @@_CreateShader += 1 } + end - def glGetAttribLocation(_program_, _name_) - (@@_glGetAttribLocation ||= 1).tap { @@_glGetAttribLocation += 1 } - end + def GetAttribLocation(_program_, _name_) + (@@_GetAttribLocation ||= 1).tap { @@_GetAttribLocation += 1 } + end - def glGetUniformLocation(_program_, _name_) - (@@_glGetUniformLocation ||= 1).tap { @@_glGetUniformLocation += 1 } - end + def GetUniformLocation(_program_, _name_) + (@@_GetUniformLocation ||= 1).tap { @@_GetUniformLocation += 1 } + end - def glIsProgram(_program_) - true - end + def IsProgram(_program_) + true + end - def glIsShader(_shader_) - true - end + def IsShader(_shader_) + true + end - def glIsEnabledi(_target_, _index_) - true - end + def IsEnabledi(_target_, _index_) + true + end - def glGetFragDataLocation(_program_, _name_) - (@@_glGetFragDataLocation ||= 1).tap { @@_glGetFragDataLocation += 1 } - end + def GetFragDataLocation(_program_, _name_) + (@@_GetFragDataLocation ||= 1).tap { @@_GetFragDataLocation += 1 } + end - def glIsRenderbuffer(_renderbuffer_) - true - end + def IsRenderbuffer(_renderbuffer_) + true + end - def glIsFramebuffer(_framebuffer_) - true - end + def IsFramebuffer(_framebuffer_) + true + end - def glCheckFramebufferStatus(_target_) - OpenGL::GL_FRAMEBUFFER_COMPLETE - end + def CheckFramebufferStatus(_target_) + GL::FRAMEBUFFER_COMPLETE + end - def glIsVertexArray(_array_) - true - end + def IsVertexArray(_array_) + true + end - def glGetUniformBlockIndex(_program_, _uniformBlockName_) - (@@_glGetUniformBlockIndex ||= 1).tap { @@_glGetUniformBlockIndex += 1 } - end + def GetUniformBlockIndex(_program_, _uniformBlockName_) + (@@_GetUniformBlockIndex ||= 1).tap { @@_GetUniformBlockIndex += 1 } + end - def glIsSync(_sync_) - true - end + def IsSync(_sync_) + true + end - def glClientWaitSync(_sync_, _flags_, _timeout_) - OpenGL::GL_ALREADY_SIGNALED - end + def ClientWaitSync(_sync_, _flags_, _timeout_) + GL::ALREADY_SIGNALED + end - def glGetFragDataIndex(_program_, _name_) - (@@_glGetFragDataIndex ||= 1).tap { @@_glGetFragDataIndex += 1 } - end + def GetFragDataIndex(_program_, _name_) + (@@_GetFragDataIndex ||= 1).tap { @@_GetFragDataIndex += 1 } + end - def glIsSampler(_sampler_) - true - end + def IsSampler(_sampler_) + true + end - def glGetSubroutineUniformLocation(_program_, _shadertype_, _name_) - (@@_glGetSubroutineUniformLocation ||= 1).tap { @@_glGetSubroutineUniformLocation += 1 } - end + def GetSubroutineUniformLocation(_program_, _shadertype_, _name_) + (@@_GetSubroutineUniformLocation ||= 1).tap { @@_GetSubroutineUniformLocation += 1 } + end - def glGetSubroutineIndex(_program_, _shadertype_, _name_) - (@@_glGetSubroutineIndex ||= 1).tap { @@_glGetSubroutineIndex += 1 } - end + def GetSubroutineIndex(_program_, _shadertype_, _name_) + (@@_GetSubroutineIndex ||= 1).tap { @@_GetSubroutineIndex += 1 } + end - def glIsTransformFeedback(_id_) - true - end + def IsTransformFeedback(_id_) + true + end - def glCreateShaderProgramv(_type_, _count_, _strings_) - (@@_glCreateShaderProgramv ||= 1).tap { @@_glCreateShaderProgramv += 1 } - end + def CreateShaderProgramv(_type_, _count_, _strings_) + (@@_CreateShaderProgramv ||= 1).tap { @@_CreateShaderProgramv += 1 } + end - def glIsProgramPipeline(_pipeline_) - true - end + def IsProgramPipeline(_pipeline_) + true + end - def glGetProgramResourceIndex(_program_, _programInterface_, _name_) - (@@_glGetProgramResourceIndex ||= 1).tap { @@_glGetProgramResourceIndex += 1 } - end + def GetProgramResourceIndex(_program_, _programInterface_, _name_) + (@@_GetProgramResourceIndex ||= 1).tap { @@_GetProgramResourceIndex += 1 } + end - def glGetProgramResourceLocation(_program_, _programInterface_, _name_) - (@@_glGetProgramResourceLocation ||= 1).tap { @@_glGetProgramResourceLocation += 1 } - end + def GetProgramResourceLocation(_program_, _programInterface_, _name_) + (@@_GetProgramResourceLocation ||= 1).tap { @@_GetProgramResourceLocation += 1 } + end - def glGetProgramResourceLocationIndex(_program_, _programInterface_, _name_) - (@@_glGetProgramResourceLocationIndex ||= 1).tap { @@_glGetProgramResourceLocationIndex += 1 } - end + def GetProgramResourceLocationIndex(_program_, _programInterface_, _name_) + (@@_GetProgramResourceLocationIndex ||= 1).tap { @@_GetProgramResourceLocationIndex += 1 } + end - def glGetDebugMessageLog(_count_, _bufSize_, _sources_, _types_, _ids_, _severities_, _lengths_, _messageLog_) - 0 - end + def GetDebugMessageLog(_count_, _bufSize_, _sources_, _types_, _ids_, _severities_, _lengths_, _messageLog_) + 0 + end - def glUnmapNamedBuffer(_buffer_) - true - end + def UnmapNamedBuffer(_buffer_) + true + end - def glCheckNamedFramebufferStatus(_framebuffer_, _target_) - OpenGL::GL_FRAMEBUFFER_COMPLETE - end + def CheckNamedFramebufferStatus(_framebuffer_, _target_) + GL::FRAMEBUFFER_COMPLETE + end - def glGetGraphicsResetStatus() - OpenGL::GL_NO_ERROR - end + def GetGraphicsResetStatus() + GL::NO_ERROR + end - def self.get_platform - :OPENGL_PLATFORM_TEST + def get_platform + :OPENGL_PLATFORM_TEST + end end end -OpenGLInstance = Object.new.extend(OpenGLStub) - -OpenGL = OpenGLStub +GL = OpenGLStub