Ran rubocop -a

This commit is contained in:
2020-12-14 16:04:31 -06:00
parent 2447dde1af
commit 26dd688124
59 changed files with 770 additions and 741 deletions

View File

@@ -1,6 +1,7 @@
module CyberarmEngine
class BoundingBoxRenderer
attr_reader :bounding_boxes, :vertex_count
def initialize
@bounding_boxes = {}
@vertex_count = 0
@@ -8,7 +9,7 @@ module CyberarmEngine
def render(entities)
entities.each do |entity|
create_bounding_box(entity,color = nil)
create_bounding_box(entity, color = nil)
draw_bounding_boxes
end
@@ -43,7 +44,7 @@ module CyberarmEngine
colors = mesh_colors(color)
vertices = mesh_vertices(box)
@vertex_count+=vertices.size
@vertex_count += vertices.size
@bounding_boxes[entity_id][:vertices_size] = vertices.size
@bounding_boxes[entity_id][:vertices] = vertices.pack("f*")
@@ -58,7 +59,7 @@ module CyberarmEngine
colors = mesh_colors(mesh.debug_color)
vertices = mesh_vertices(box)
@vertex_count+=vertices.size
@vertex_count += vertices.size
data[:vertices_size] = vertices.size
data[:vertices] = vertices.pack("f*")
@@ -71,48 +72,48 @@ module CyberarmEngine
def mesh_normals
[
0,1,0,
0,1,0,
0,1,0,
0,1,0,
0,1,0,
0,1,0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0,0,1,
0,0,1,
0,0,1,
0,0,1,
0,0,1,
0,0,1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
1,0,0,
1,0,0,
1,0,0,
1,0,0,
1,0,0,
1,0,0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
-1,0,0,
-1,0,0,
-1,0,0,
-1,0,0,
-1,0,0,
-1,0,0,
-1, 0, 0,
-1, 0, 0,
-1, 0, 0,
-1, 0, 0,
-1, 0, 0,
-1, 0, 0,
-1,0,0,
-1,0,0,
-1,0,0,
-1, 0, 0,
-1, 0, 0,
-1, 0, 0,
-1,0,0,
-1,0,0,
-1,0,0
-1, 0, 0,
-1, 0, 0,
-1, 0, 0
]
end
@@ -219,7 +220,7 @@ module CyberarmEngine
bounding_box[:entity].position.z
)
draw_bounding_box(bounding_box)
@bounding_boxes[key][:objects].each {|o| draw_bounding_box(o)}
@bounding_boxes[key][:objects].each { |o| draw_bounding_box(o) }
glPopMatrix
end

View File

@@ -1,11 +1,13 @@
module CyberarmEngine
class GBuffer
attr_reader :screen_vbo, :vertices, :uvs
def initialize(width:, height:)
@width, @height = width, height
@width = width
@height = height
@framebuffer = nil
@buffers = [:position, :diffuse, :normal, :texcoord]
@buffers = %i[position diffuse normal texcoord]
@textures = {}
@screen_vbo = nil
@ready = false
@@ -16,9 +18,9 @@ module CyberarmEngine
-1.0, 1.0, 0,
-1.0, 1.0, 0,
1.0, -1.0, 0,
1.0, 1.0, 0,
].freeze
1.0, -1.0, 0,
1.0, 1.0, 0
].freeze
@uvs = [
0, 0,
@@ -35,9 +37,9 @@ module CyberarmEngine
end
def create_framebuffer
buffer = ' ' * 4
buffer = " " * 4
glGenFramebuffers(1, buffer)
@framebuffer = buffer.unpack('L2').first
@framebuffer = buffer.unpack1("L2")
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, @framebuffer)
@@ -48,20 +50,20 @@ module CyberarmEngine
if status != GL_FRAMEBUFFER_COMPLETE
message = ""
case status
when GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
message = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"
when GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
message = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"
when GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
message = "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"
when GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
message = "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"
when GL_FRAMEBUFFER_UNSUPPORTED
message = "GL_FRAMEBUFFER_UNSUPPORTED"
else
message = "Unknown error!"
end
message = case status
when GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"
when GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"
when GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
"GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"
when GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
"GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"
when GL_FRAMEBUFFER_UNSUPPORTED
"GL_FRAMEBUFFER_UNSUPPORTED"
else
"Unknown error!"
end
puts "Incomplete framebuffer: #{status}\nError: #{message}"
else
@ready = true
@@ -72,9 +74,9 @@ module CyberarmEngine
def create_textures
@buffers.size.times do |i|
buffer = ' ' * 4
buffer = " " * 4
glGenTextures(1, buffer)
texture_id = buffer.unpack('L2').first
texture_id = buffer.unpack1("L2")
@textures[@buffers[i]] = texture_id
glBindTexture(GL_TEXTURE_2D, texture_id)
@@ -84,39 +86,39 @@ module CyberarmEngine
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
end
buffer = ' ' * 4
buffer = " " * 4
glGenTextures(1, buffer)
texture_id = buffer.unpack('L2').first
texture_id = buffer.unpack1("L2")
@textures[:depth] = texture_id
glBindTexture(GL_TEXTURE_2D, texture_id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, @width, @height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nil)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0)
draw_buffers = [ GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 ]
draw_buffers = [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3]
glDrawBuffers(draw_buffers.size, draw_buffers.pack("I*"))
end
def create_screen_vbo
buffer = ' ' * 4
buffer = " " * 4
glGenVertexArrays(1, buffer)
@screen_vbo = buffer.unpack('L2').first
@screen_vbo = buffer.unpack1("L2")
buffer = " " * 4
glGenBuffers(1, buffer)
@positions_buffer_id = buffer.unpack('L2').first
@positions_buffer_id = buffer.unpack1("L2")
buffer = " " * 4
glGenBuffers(1, buffer)
@uvs_buffer_id = buffer.unpack('L2').first
@uvs_buffer_id = buffer.unpack1("L2")
glBindVertexArray(@screen_vbo)
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
glBufferData(GL_ARRAY_BUFFER, @vertices.size * Fiddle::SIZEOF_FLOAT, @vertices.pack("f*"), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, @vertices.size * Fiddle::SIZEOF_FLOAT, @vertices.pack("f*"), GL_STATIC_DRAW)
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
glBufferData(GL_ARRAY_BUFFER, @uvs.size * Fiddle::SIZEOF_FLOAT, @uvs.pack("f*"), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, @uvs.size * Fiddle::SIZEOF_FLOAT, @uvs.pack("f*"), GL_STATIC_DRAW)
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nil)
glEnableVertexAttribArray(0)
@@ -159,4 +161,4 @@ module CyberarmEngine
gl_error?
end
end
end
end

View File

@@ -3,8 +3,10 @@ module CyberarmEngine
@@immediate_mode_warning = false
attr_accessor :show_wireframe
def initialize(width:, height:, show_wireframe: false)
@width, @height = width, height
@width = width
@height = height
@show_wireframe = show_wireframe
@g_buffer = GBuffer.new(width: @width, height: @height)
@@ -63,7 +65,9 @@ module CyberarmEngine
@g_buffer.unbind_framebuffer
gl_error?
else
puts "Shaders are disabled or failed to compile, using immediate mode for rendering..." unless @@immediate_mode_warning
unless @@immediate_mode_warning
puts "Shaders are disabled or failed to compile, using immediate mode for rendering..."
end
@@immediate_mode_warning = true
gl_error?
@@ -141,8 +145,8 @@ module CyberarmEngine
glBindTexture(GL_TEXTURE_2D, @g_buffer.texture(:depth))
shader.uniform_integer("depth", 4)
lights.each_with_index do |light, i|
shader.uniform_integer("light[0].type", light.type);
lights.each_with_index do |light, _i|
shader.uniform_integer("light[0].type", light.type)
shader.uniform_vec3("light[0].direction", light.direction)
shader.uniform_vec3("light[0].position", light.position)
shader.uniform_vec3("light[0].diffuse", light.diffuse)
@@ -229,7 +233,7 @@ module CyberarmEngine
end
def draw_mesh(model)
model.objects.each_with_index do |o, i|
model.objects.each_with_index do |o, _i|
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
glShadeModel(GL_FLAT) unless o.faces.first[4]
@@ -255,16 +259,16 @@ module CyberarmEngine
glPolygonOffset(2, 0.5)
glLineWidth(3)
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size / 4)
glLineWidth(1)
glPolygonOffset(0, 0)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glEnable(GL_LIGHTING)
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size / 4)
else
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size / 4)
end
# glBindBuffer(GL_ARRAY_BUFFER, 0)