mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Removed redundant glError? from Map class and renamed CommonMethods#glError? to #gl_error?, added debug settings for disabling shaders and whether to exit on opengl error
This commit is contained in:
@@ -43,12 +43,12 @@ class IMICFPS
|
||||
draw_rect(0, 0, window.width, window.height, color)
|
||||
end
|
||||
|
||||
def handleGlError
|
||||
def gl_error?
|
||||
e = glGetError()
|
||||
if e != GL_NO_ERROR
|
||||
$stderr.puts "OpenGL error detected by handler at: #{caller[0]}"
|
||||
$stderr.puts " #{gluErrorString(e)} (#{e})\n"
|
||||
exit
|
||||
exit if $debug && $debug.get(:opengl_error_panic)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ class IMICFPS
|
||||
class Manifest
|
||||
attr_reader :name, :model, :collision, :collision_mesh, :collision_resolution, :physics, :scripts, :uses
|
||||
def initialize(manifest_file: nil, package: nil, name: nil)
|
||||
|
||||
unless manifest_file
|
||||
raise "Entity package not specified!" unless package
|
||||
raise "Entity name not specified!" unless name
|
||||
@@ -10,6 +11,7 @@ class IMICFPS
|
||||
|
||||
raise "No manifest found at: #{manifest_file}" unless File.exist?(manifest_file)
|
||||
|
||||
|
||||
@file = manifest_file
|
||||
parse(manifest_file)
|
||||
end
|
||||
@@ -55,4 +57,4 @@ class IMICFPS
|
||||
Script = Struct.new(:name, :source)
|
||||
Dependency = Struct.new(:package, :name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
19
lib/map.rb
19
lib/map.rb
@@ -2,6 +2,7 @@ class IMICFPS
|
||||
class Map
|
||||
include EntityManager
|
||||
include LightManager
|
||||
include CommonMethods
|
||||
|
||||
attr_reader :collision_manager
|
||||
attr_reader :gravity
|
||||
@@ -37,23 +38,15 @@ class IMICFPS
|
||||
@map_loader
|
||||
end
|
||||
|
||||
def glError?
|
||||
e = glGetError()
|
||||
if e != GL_NO_ERROR
|
||||
$stderr.puts "OpenGL error in: #{gluErrorString(e)} (#{e})\n"
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
def render(camera)
|
||||
glError?
|
||||
gl_error?
|
||||
|
||||
Gosu.gl do
|
||||
glError?
|
||||
gl_error?
|
||||
glClearColor(0,0.2,0.5,1) # skyish blue
|
||||
glError?
|
||||
gl_error?
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||
glError?
|
||||
gl_error?
|
||||
|
||||
@renderer.draw(camera, @lights, @entities)
|
||||
end
|
||||
@@ -66,4 +59,4 @@ class IMICFPS
|
||||
# @lights.each(&:update)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
10
lib/model.rb
10
lib/model.rb
@@ -167,25 +167,25 @@ class IMICFPS
|
||||
# vertices (positions)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
||||
glVertexAttribPointer(glGetAttribLocation(program, "inPosition"), 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
handleGlError
|
||||
gl_error?
|
||||
# colors
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
||||
glVertexAttribPointer(glGetAttribLocation(program, "inColor"), 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
handleGlError
|
||||
gl_error?
|
||||
# normals
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
||||
glVertexAttribPointer(glGetAttribLocation(program, "inNormal"), 4, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
handleGlError
|
||||
gl_error?
|
||||
|
||||
if has_texture?
|
||||
# uvs
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
||||
glVertexAttribPointer(glGetAttribLocation(program, "inUV"), 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
handleGlError
|
||||
gl_error?
|
||||
# texture ids
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @textures_buffer_id)
|
||||
glVertexAttribPointer(glGetAttribLocation(program, "inTextureID"), 1, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
handleGlError
|
||||
gl_error?
|
||||
end
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
||||
|
||||
@@ -27,7 +27,7 @@ class IMICFPS
|
||||
|
||||
shader.uniform_float("totalLights", lights.size)
|
||||
|
||||
handleGlError
|
||||
gl_error?
|
||||
draw_model(object.model)
|
||||
object.draw
|
||||
end
|
||||
@@ -35,7 +35,7 @@ class IMICFPS
|
||||
puts "Shader 'default' failed to compile, using immediate mode for rendering..." unless @immediate_mode_warning
|
||||
@immediate_mode_warning = true
|
||||
|
||||
handleGlError
|
||||
gl_error?
|
||||
lights.each(&:draw)
|
||||
camera.draw
|
||||
|
||||
@@ -48,13 +48,13 @@ class IMICFPS
|
||||
glRotatef(object.orientation.y, 0, 1.0, 0)
|
||||
glRotatef(object.orientation.z, 0, 0, 1.0)
|
||||
|
||||
handleGlError
|
||||
gl_error?
|
||||
draw_mesh(object.model)
|
||||
object.draw
|
||||
glPopMatrix
|
||||
end
|
||||
|
||||
handleGlError
|
||||
gl_error?
|
||||
end
|
||||
|
||||
def draw_model(model)
|
||||
@@ -137,4 +137,4 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,10 +43,10 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def update
|
||||
@percentage.text = "#{((@asset_index.to_f/@assets.count)*100.0).round}%"
|
||||
@percentage.text = "#{((@asset_index.to_f / @assets.count) * 100.0).round}%"
|
||||
@act = true if @cycled
|
||||
|
||||
if @act && (@asset_index+1 <= @assets.count)
|
||||
if @act && (@asset_index + 1 <= @assets.count)
|
||||
@act = false
|
||||
@cycled = false
|
||||
|
||||
@@ -55,13 +55,17 @@ class IMICFPS
|
||||
when :model
|
||||
ModelLoader.new(manifest: hash[:manifest], entity: @dummy_entity)
|
||||
when :shader
|
||||
if $debug.get(:use_shaders)
|
||||
shader = Shader.new(name: hash[:name], vertex: "shaders/vertex/#{hash[:name]}.glsl", fragment: "shaders/fragment/#{hash[:name]}.glsl")
|
||||
Shader.add(hash[:name], shader) if shader.compiled?
|
||||
else
|
||||
warn "Skipping shader: #{hash[:name]}..."
|
||||
end
|
||||
else
|
||||
warn "Unknown asset: #{hash}"
|
||||
end
|
||||
|
||||
@asset_index+=1
|
||||
@asset_index += 1
|
||||
end
|
||||
|
||||
unless @asset_index < @assets.count
|
||||
|
||||
@@ -17,11 +17,15 @@ class IMICFPS
|
||||
set(:stats, false)
|
||||
set(:fps, false)
|
||||
set(:skydome, true)
|
||||
set(:use_shaders, true)
|
||||
set(:opengl_error_panic, false)
|
||||
|
||||
subcommand(:boundingboxes, :boolean)
|
||||
subcommand(:wireframe, :boolean)
|
||||
subcommand(:stats, :boolean)
|
||||
subcommand(:skydome, :boolean)
|
||||
subcommand(:use_shaders, :boolean)
|
||||
subcommand(:opengl_error_panic, :boolean)
|
||||
end
|
||||
|
||||
def handle(arguments, console)
|
||||
@@ -33,4 +37,4 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user