cyberarm_engine 0.19.0 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +39 -39
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +179 -179
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +113 -113
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +248 -248
- data/lib/cyberarm_engine/game_state.rb +97 -97
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/model_object.rb +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +212 -212
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/opengl/light.rb +50 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
- data/lib/cyberarm_engine/opengl/shader.rb +406 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +28 -28
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +21 -21
- data/lib/cyberarm_engine/text.rb +197 -197
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +139 -139
- data/lib/cyberarm_engine/ui/element.rb +488 -488
- data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
- data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
- data/lib/cyberarm_engine/ui/style.rb +49 -49
- data/lib/cyberarm_engine/ui/theme.rb +207 -207
- data/lib/cyberarm_engine/vector.rb +293 -293
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +120 -120
- data/lib/cyberarm_engine.rb +71 -71
- metadata +3 -3
@@ -1,164 +1,164 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class GBuffer
|
3
|
-
attr_reader :screen_vbo, :vertices, :uvs
|
4
|
-
|
5
|
-
def initialize(width:, height:)
|
6
|
-
@width = width
|
7
|
-
@height = height
|
8
|
-
|
9
|
-
@framebuffer = nil
|
10
|
-
@buffers = %i[position diffuse normal texcoord]
|
11
|
-
@textures = {}
|
12
|
-
@screen_vbo = nil
|
13
|
-
@ready = false
|
14
|
-
|
15
|
-
@vertices = [
|
16
|
-
-1.0, -1.0, 0,
|
17
|
-
1.0, -1.0, 0,
|
18
|
-
-1.0, 1.0, 0,
|
19
|
-
|
20
|
-
-1.0, 1.0, 0,
|
21
|
-
1.0, -1.0, 0,
|
22
|
-
1.0, 1.0, 0
|
23
|
-
].freeze
|
24
|
-
|
25
|
-
@uvs = [
|
26
|
-
0, 0,
|
27
|
-
1, 0,
|
28
|
-
0, 1,
|
29
|
-
|
30
|
-
0, 1,
|
31
|
-
1, 0,
|
32
|
-
1, 1
|
33
|
-
].freeze
|
34
|
-
|
35
|
-
create_framebuffer
|
36
|
-
create_screen_vbo
|
37
|
-
end
|
38
|
-
|
39
|
-
def create_framebuffer
|
40
|
-
buffer = " " * 4
|
41
|
-
glGenFramebuffers(1, buffer)
|
42
|
-
@framebuffer = buffer.unpack1("L2")
|
43
|
-
|
44
|
-
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, @framebuffer)
|
45
|
-
|
46
|
-
create_textures
|
47
|
-
|
48
|
-
status = glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
49
|
-
|
50
|
-
if status != GL_FRAMEBUFFER_COMPLETE
|
51
|
-
message = ""
|
52
|
-
|
53
|
-
message = case status
|
54
|
-
when GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
55
|
-
"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"
|
56
|
-
when GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
57
|
-
"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"
|
58
|
-
when GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
|
59
|
-
"GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"
|
60
|
-
when GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
|
61
|
-
"GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"
|
62
|
-
when GL_FRAMEBUFFER_UNSUPPORTED
|
63
|
-
"GL_FRAMEBUFFER_UNSUPPORTED"
|
64
|
-
else
|
65
|
-
"Unknown error!"
|
66
|
-
end
|
67
|
-
puts "Incomplete framebuffer: #{status}\nError: #{message}"
|
68
|
-
else
|
69
|
-
@ready = true
|
70
|
-
end
|
71
|
-
|
72
|
-
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
|
73
|
-
end
|
74
|
-
|
75
|
-
def create_textures
|
76
|
-
@buffers.size.times do |i|
|
77
|
-
buffer = " " * 4
|
78
|
-
glGenTextures(1, buffer)
|
79
|
-
texture_id = buffer.unpack1("L2")
|
80
|
-
@textures[@buffers[i]] = texture_id
|
81
|
-
|
82
|
-
glBindTexture(GL_TEXTURE_2D, texture_id)
|
83
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, @width, @height, 0, GL_RGBA, GL_FLOAT, nil)
|
84
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
85
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
86
|
-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
|
87
|
-
end
|
88
|
-
|
89
|
-
buffer = " " * 4
|
90
|
-
glGenTextures(1, buffer)
|
91
|
-
texture_id = buffer.unpack1("L2")
|
92
|
-
@textures[:depth] = texture_id
|
93
|
-
|
94
|
-
glBindTexture(GL_TEXTURE_2D, texture_id)
|
95
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, @width, @height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nil)
|
96
|
-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0)
|
97
|
-
|
98
|
-
draw_buffers = [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3]
|
99
|
-
glDrawBuffers(draw_buffers.size, draw_buffers.pack("I*"))
|
100
|
-
end
|
101
|
-
|
102
|
-
def create_screen_vbo
|
103
|
-
buffer = " " * 4
|
104
|
-
glGenVertexArrays(1, buffer)
|
105
|
-
@screen_vbo = buffer.unpack1("L2")
|
106
|
-
|
107
|
-
buffer = " " * 4
|
108
|
-
glGenBuffers(1, buffer)
|
109
|
-
@positions_buffer_id = buffer.unpack1("L2")
|
110
|
-
|
111
|
-
buffer = " " * 4
|
112
|
-
glGenBuffers(1, buffer)
|
113
|
-
@uvs_buffer_id = buffer.unpack1("L2")
|
114
|
-
|
115
|
-
glBindVertexArray(@screen_vbo)
|
116
|
-
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
117
|
-
glBufferData(GL_ARRAY_BUFFER, @vertices.size * Fiddle::SIZEOF_FLOAT, @vertices.pack("f*"), GL_STATIC_DRAW)
|
118
|
-
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
119
|
-
|
120
|
-
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
121
|
-
glBufferData(GL_ARRAY_BUFFER, @uvs.size * Fiddle::SIZEOF_FLOAT, @uvs.pack("f*"), GL_STATIC_DRAW)
|
122
|
-
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nil)
|
123
|
-
|
124
|
-
glEnableVertexAttribArray(0)
|
125
|
-
glEnableVertexAttribArray(1)
|
126
|
-
|
127
|
-
glBindVertexArray(0)
|
128
|
-
end
|
129
|
-
|
130
|
-
def bind_for_writing
|
131
|
-
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, @framebuffer)
|
132
|
-
end
|
133
|
-
|
134
|
-
def bind_for_reading
|
135
|
-
glBindFramebuffer(GL_READ_FRAMEBUFFER, @framebuffer)
|
136
|
-
end
|
137
|
-
|
138
|
-
def set_read_buffer(buffer)
|
139
|
-
glReadBuffer(GL_COLOR_ATTACHMENT0 + @textures.keys.index(buffer))
|
140
|
-
end
|
141
|
-
|
142
|
-
def set_read_buffer_depth
|
143
|
-
glReadBuffer(GL_DEPTH_ATTACHMENT)
|
144
|
-
end
|
145
|
-
|
146
|
-
def unbind_framebuffer
|
147
|
-
glBindFramebuffer(GL_FRAMEBUFFER, 0)
|
148
|
-
end
|
149
|
-
|
150
|
-
def texture(type)
|
151
|
-
@textures[type]
|
152
|
-
end
|
153
|
-
|
154
|
-
def clean_up
|
155
|
-
glDeleteFramebuffers(1, [@framebuffer].pack("L"))
|
156
|
-
|
157
|
-
glDeleteTextures(@textures.values.size, @textures.values.pack("L*"))
|
158
|
-
|
159
|
-
glDeleteBuffers(2, [@positions_buffer_id, @uvs_buffer_id].pack("L*"))
|
160
|
-
glDeleteVertexArrays(1, [@screen_vbo].pack("L"))
|
161
|
-
gl_error?
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class GBuffer
|
3
|
+
attr_reader :screen_vbo, :vertices, :uvs
|
4
|
+
|
5
|
+
def initialize(width:, height:)
|
6
|
+
@width = width
|
7
|
+
@height = height
|
8
|
+
|
9
|
+
@framebuffer = nil
|
10
|
+
@buffers = %i[position diffuse normal texcoord]
|
11
|
+
@textures = {}
|
12
|
+
@screen_vbo = nil
|
13
|
+
@ready = false
|
14
|
+
|
15
|
+
@vertices = [
|
16
|
+
-1.0, -1.0, 0,
|
17
|
+
1.0, -1.0, 0,
|
18
|
+
-1.0, 1.0, 0,
|
19
|
+
|
20
|
+
-1.0, 1.0, 0,
|
21
|
+
1.0, -1.0, 0,
|
22
|
+
1.0, 1.0, 0
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
@uvs = [
|
26
|
+
0, 0,
|
27
|
+
1, 0,
|
28
|
+
0, 1,
|
29
|
+
|
30
|
+
0, 1,
|
31
|
+
1, 0,
|
32
|
+
1, 1
|
33
|
+
].freeze
|
34
|
+
|
35
|
+
create_framebuffer
|
36
|
+
create_screen_vbo
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_framebuffer
|
40
|
+
buffer = " " * 4
|
41
|
+
glGenFramebuffers(1, buffer)
|
42
|
+
@framebuffer = buffer.unpack1("L2")
|
43
|
+
|
44
|
+
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, @framebuffer)
|
45
|
+
|
46
|
+
create_textures
|
47
|
+
|
48
|
+
status = glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
49
|
+
|
50
|
+
if status != GL_FRAMEBUFFER_COMPLETE
|
51
|
+
message = ""
|
52
|
+
|
53
|
+
message = case status
|
54
|
+
when GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
55
|
+
"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"
|
56
|
+
when GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
57
|
+
"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"
|
58
|
+
when GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
|
59
|
+
"GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"
|
60
|
+
when GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
|
61
|
+
"GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"
|
62
|
+
when GL_FRAMEBUFFER_UNSUPPORTED
|
63
|
+
"GL_FRAMEBUFFER_UNSUPPORTED"
|
64
|
+
else
|
65
|
+
"Unknown error!"
|
66
|
+
end
|
67
|
+
puts "Incomplete framebuffer: #{status}\nError: #{message}"
|
68
|
+
else
|
69
|
+
@ready = true
|
70
|
+
end
|
71
|
+
|
72
|
+
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_textures
|
76
|
+
@buffers.size.times do |i|
|
77
|
+
buffer = " " * 4
|
78
|
+
glGenTextures(1, buffer)
|
79
|
+
texture_id = buffer.unpack1("L2")
|
80
|
+
@textures[@buffers[i]] = texture_id
|
81
|
+
|
82
|
+
glBindTexture(GL_TEXTURE_2D, texture_id)
|
83
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, @width, @height, 0, GL_RGBA, GL_FLOAT, nil)
|
84
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
85
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
86
|
+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
|
87
|
+
end
|
88
|
+
|
89
|
+
buffer = " " * 4
|
90
|
+
glGenTextures(1, buffer)
|
91
|
+
texture_id = buffer.unpack1("L2")
|
92
|
+
@textures[:depth] = texture_id
|
93
|
+
|
94
|
+
glBindTexture(GL_TEXTURE_2D, texture_id)
|
95
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, @width, @height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nil)
|
96
|
+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0)
|
97
|
+
|
98
|
+
draw_buffers = [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3]
|
99
|
+
glDrawBuffers(draw_buffers.size, draw_buffers.pack("I*"))
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_screen_vbo
|
103
|
+
buffer = " " * 4
|
104
|
+
glGenVertexArrays(1, buffer)
|
105
|
+
@screen_vbo = buffer.unpack1("L2")
|
106
|
+
|
107
|
+
buffer = " " * 4
|
108
|
+
glGenBuffers(1, buffer)
|
109
|
+
@positions_buffer_id = buffer.unpack1("L2")
|
110
|
+
|
111
|
+
buffer = " " * 4
|
112
|
+
glGenBuffers(1, buffer)
|
113
|
+
@uvs_buffer_id = buffer.unpack1("L2")
|
114
|
+
|
115
|
+
glBindVertexArray(@screen_vbo)
|
116
|
+
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
117
|
+
glBufferData(GL_ARRAY_BUFFER, @vertices.size * Fiddle::SIZEOF_FLOAT, @vertices.pack("f*"), GL_STATIC_DRAW)
|
118
|
+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
119
|
+
|
120
|
+
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
121
|
+
glBufferData(GL_ARRAY_BUFFER, @uvs.size * Fiddle::SIZEOF_FLOAT, @uvs.pack("f*"), GL_STATIC_DRAW)
|
122
|
+
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nil)
|
123
|
+
|
124
|
+
glEnableVertexAttribArray(0)
|
125
|
+
glEnableVertexAttribArray(1)
|
126
|
+
|
127
|
+
glBindVertexArray(0)
|
128
|
+
end
|
129
|
+
|
130
|
+
def bind_for_writing
|
131
|
+
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, @framebuffer)
|
132
|
+
end
|
133
|
+
|
134
|
+
def bind_for_reading
|
135
|
+
glBindFramebuffer(GL_READ_FRAMEBUFFER, @framebuffer)
|
136
|
+
end
|
137
|
+
|
138
|
+
def set_read_buffer(buffer)
|
139
|
+
glReadBuffer(GL_COLOR_ATTACHMENT0 + @textures.keys.index(buffer))
|
140
|
+
end
|
141
|
+
|
142
|
+
def set_read_buffer_depth
|
143
|
+
glReadBuffer(GL_DEPTH_ATTACHMENT)
|
144
|
+
end
|
145
|
+
|
146
|
+
def unbind_framebuffer
|
147
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0)
|
148
|
+
end
|
149
|
+
|
150
|
+
def texture(type)
|
151
|
+
@textures[type]
|
152
|
+
end
|
153
|
+
|
154
|
+
def clean_up
|
155
|
+
glDeleteFramebuffers(1, [@framebuffer].pack("L"))
|
156
|
+
|
157
|
+
glDeleteTextures(@textures.values.size, @textures.values.pack("L*"))
|
158
|
+
|
159
|
+
glDeleteBuffers(2, [@positions_buffer_id, @uvs_buffer_id].pack("L*"))
|
160
|
+
glDeleteVertexArrays(1, [@screen_vbo].pack("L"))
|
161
|
+
gl_error?
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|