ruby_rpg 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +21 -21
- data/bin/build.bash +13 -13
- data/bin/import +44 -44
- data/glfw-3.3.9.bin.MACOS/LICENSE.md +23 -23
- data/glfw-3.3.9.bin.MACOS/README.md +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/build_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/build_guide.html +199 -199
- data/glfw-3.3.9.bin.MACOS/docs/html/compat_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/compat_guide.html +153 -153
- data/glfw-3.3.9.bin.MACOS/docs/html/compile_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/compile_guide.html +223 -223
- data/glfw-3.3.9.bin.MACOS/docs/html/context_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/context_guide.html +259 -259
- data/glfw-3.3.9.bin.MACOS/docs/html/deprecated.html +88 -88
- data/glfw-3.3.9.bin.MACOS/docs/html/dir_08423ce7729c4554356a7de7171ba263.html +85 -85
- data/glfw-3.3.9.bin.MACOS/docs/html/dir_2dcebcdf14b42e92a6ed85c61bda6b9d.html +93 -93
- data/glfw-3.3.9.bin.MACOS/docs/html/dir_62ce056722ee97c199075aa1d6eca309.html +95 -95
- data/glfw-3.3.9.bin.MACOS/docs/html/dir_dddf4cf62655095a666cf715de3a31a2.html +91 -91
- data/glfw-3.3.9.bin.MACOS/docs/html/doc.svg +12 -12
- data/glfw-3.3.9.bin.MACOS/docs/html/docd.svg +12 -12
- data/glfw-3.3.9.bin.MACOS/docs/html/doxygen.css +1685 -1685
- data/glfw-3.3.9.bin.MACOS/docs/html/doxygen.svg +28 -28
- data/glfw-3.3.9.bin.MACOS/docs/html/dynsections.js +192 -192
- data/glfw-3.3.9.bin.MACOS/docs/html/extra.css +1 -1
- data/glfw-3.3.9.bin.MACOS/docs/html/files.html +91 -91
- data/glfw-3.3.9.bin.MACOS/docs/html/folderclosed.svg +11 -11
- data/glfw-3.3.9.bin.MACOS/docs/html/folderclosedd.svg +11 -11
- data/glfw-3.3.9.bin.MACOS/docs/html/folderopen.svg +17 -17
- data/glfw-3.3.9.bin.MACOS/docs/html/folderopend.svg +12 -12
- data/glfw-3.3.9.bin.MACOS/docs/html/glfw3_8h.html +1661 -1661
- data/glfw-3.3.9.bin.MACOS/docs/html/glfw3_8h_source.html +1175 -1175
- data/glfw-3.3.9.bin.MACOS/docs/html/glfw3native_8h.html +167 -167
- data/glfw-3.3.9.bin.MACOS/docs/html/glfw3native_8h_source.html +303 -303
- data/glfw-3.3.9.bin.MACOS/docs/html/group__buttons.html +282 -282
- data/glfw-3.3.9.bin.MACOS/docs/html/group__context.html +304 -304
- data/glfw-3.3.9.bin.MACOS/docs/html/group__errors.html +304 -304
- data/glfw-3.3.9.bin.MACOS/docs/html/group__gamepad__axes.html +202 -202
- data/glfw-3.3.9.bin.MACOS/docs/html/group__gamepad__buttons.html +410 -410
- data/glfw-3.3.9.bin.MACOS/docs/html/group__hat__state.html +234 -234
- data/glfw-3.3.9.bin.MACOS/docs/html/group__init.html +570 -570
- data/glfw-3.3.9.bin.MACOS/docs/html/group__input.html +2255 -2255
- data/glfw-3.3.9.bin.MACOS/docs/html/group__joysticks.html +362 -362
- data/glfw-3.3.9.bin.MACOS/docs/html/group__keys.html +2034 -2034
- data/glfw-3.3.9.bin.MACOS/docs/html/group__mods.html +198 -198
- data/glfw-3.3.9.bin.MACOS/docs/html/group__monitor.html +848 -848
- data/glfw-3.3.9.bin.MACOS/docs/html/group__native.html +812 -812
- data/glfw-3.3.9.bin.MACOS/docs/html/group__shapes.html +198 -198
- data/glfw-3.3.9.bin.MACOS/docs/html/group__vulkan.html +359 -359
- data/glfw-3.3.9.bin.MACOS/docs/html/group__window.html +3434 -3434
- data/glfw-3.3.9.bin.MACOS/docs/html/index.html +100 -100
- data/glfw-3.3.9.bin.MACOS/docs/html/input_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/input_guide.html +570 -570
- data/glfw-3.3.9.bin.MACOS/docs/html/internal_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/internals_guide.html +132 -132
- data/glfw-3.3.9.bin.MACOS/docs/html/intro_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/intro_guide.html +351 -351
- data/glfw-3.3.9.bin.MACOS/docs/html/jquery.js +33 -33
- data/glfw-3.3.9.bin.MACOS/docs/html/main_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/menu.js +136 -136
- data/glfw-3.3.9.bin.MACOS/docs/html/menudata.js +29 -29
- data/glfw-3.3.9.bin.MACOS/docs/html/minus.svg +8 -8
- data/glfw-3.3.9.bin.MACOS/docs/html/minusd.svg +8 -8
- data/glfw-3.3.9.bin.MACOS/docs/html/monitor_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/monitor_guide.html +229 -229
- data/glfw-3.3.9.bin.MACOS/docs/html/moving_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/moving_guide.html +374 -374
- data/glfw-3.3.9.bin.MACOS/docs/html/news.html +634 -634
- data/glfw-3.3.9.bin.MACOS/docs/html/news_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/pages.html +99 -99
- data/glfw-3.3.9.bin.MACOS/docs/html/plus.svg +9 -9
- data/glfw-3.3.9.bin.MACOS/docs/html/plusd.svg +9 -9
- data/glfw-3.3.9.bin.MACOS/docs/html/quick_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/quick_guide.html +397 -397
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_0.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_1.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_10.js +65 -65
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_11.js +26 -26
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_12.js +44 -44
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_13.js +34 -34
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_14.js +12 -12
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_15.js +52 -52
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_16.js +69 -69
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_17.js +51 -51
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_18.js +14 -14
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_19.js +36 -36
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_1a.js +98 -98
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_1b.js +12 -12
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_2.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_3.js +9 -9
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_4.js +57 -57
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_5.js +22 -22
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_6.js +103 -103
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_7.js +23 -23
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_8.js +35 -35
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_9.js +63 -63
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_a.js +505 -505
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_b.js +24 -24
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_c.js +50 -50
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_d.js +17 -17
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_e.js +12 -12
- data/glfw-3.3.9.bin.MACOS/docs/html/search/all_f.js +35 -35
- data/glfw-3.3.9.bin.MACOS/docs/html/search/classes_0.js +7 -7
- data/glfw-3.3.9.bin.MACOS/docs/html/search/close.svg +18 -18
- data/glfw-3.3.9.bin.MACOS/docs/html/search/defines_0.js +34 -34
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_0.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_1.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_2.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_3.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_4.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_5.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_6.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_7.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/files_8.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/functions_0.js +146 -146
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_0.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_1.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_10.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_2.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_3.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_4.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_5.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_6.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_7.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_8.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_9.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_a.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_b.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_c.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_d.js +7 -7
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_e.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/groups_f.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/mag.svg +24 -24
- data/glfw-3.3.9.bin.MACOS/docs/html/search/mag_d.svg +24 -24
- data/glfw-3.3.9.bin.MACOS/docs/html/search/mag_sel.svg +31 -31
- data/glfw-3.3.9.bin.MACOS/docs/html/search/mag_seld.svg +31 -31
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_0.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_1.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_10.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_2.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_3.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_4.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_5.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_6.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_7.js +7 -7
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_8.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_9.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_a.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_b.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_c.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_d.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_e.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/pages_f.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/search.css +291 -291
- data/glfw-3.3.9.bin.MACOS/docs/html/search/search.js +840 -840
- data/glfw-3.3.9.bin.MACOS/docs/html/search/searchdata.js +39 -39
- data/glfw-3.3.9.bin.MACOS/docs/html/search/typedefs_0.js +32 -32
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_0.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_1.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_2.js +5 -5
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_3.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_4.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_5.js +6 -6
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_6.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/search/variables_7.js +4 -4
- data/glfw-3.3.9.bin.MACOS/docs/html/spaces.svg +877 -877
- data/glfw-3.3.9.bin.MACOS/docs/html/struct_g_l_f_wgamepadstate.html +134 -134
- data/glfw-3.3.9.bin.MACOS/docs/html/struct_g_l_f_wgammaramp.html +170 -170
- data/glfw-3.3.9.bin.MACOS/docs/html/struct_g_l_f_wimage.html +151 -151
- data/glfw-3.3.9.bin.MACOS/docs/html/struct_g_l_f_wvidmode.html +204 -204
- data/glfw-3.3.9.bin.MACOS/docs/html/vulkan_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/vulkan_guide.html +196 -196
- data/glfw-3.3.9.bin.MACOS/docs/html/window_8dox.html +81 -81
- data/glfw-3.3.9.bin.MACOS/docs/html/window_guide.html +763 -763
- data/glfw-3.3.9.bin.MACOS/include/GLFW/glfw3.h +5932 -5932
- data/glfw-3.3.9.bin.MACOS/include/GLFW/glfw3native.h +634 -634
- data/glfw-3.3.9.bin.MACOS/lib-arm64/libglfw.3.dylib +0 -0
- data/glfw-3.3.9.bin.MACOS/lib-universal/libglfw.3.dylib +0 -0
- data/glfw-3.3.9.bin.MACOS/lib-x86_64/libglfw.3.dylib +0 -0
- data/lib/engine/autoloader.rb +11 -11
- data/lib/engine/camera.rb +12 -12
- data/lib/engine/component.rb +63 -63
- data/lib/engine/components/audio_source.rb +41 -41
- data/lib/engine/components/direction_light.rb +22 -22
- data/lib/engine/components/font_renderer.rb +134 -134
- data/lib/engine/components/mesh_renderer.rb +31 -31
- data/lib/engine/components/orthographic_camera.rb +54 -54
- data/lib/engine/components/perspective_camera.rb +53 -53
- data/lib/engine/components/point_light.rb +23 -23
- data/lib/engine/components/sprite_renderer.rb +141 -141
- data/lib/engine/components/ui_font_renderer.rb +140 -140
- data/lib/engine/components/ui_sprite_clickbox.rb +62 -0
- data/lib/engine/components/ui_sprite_renderer.rb +101 -101
- data/lib/engine/compute_shader.rb +93 -0
- data/lib/engine/cursor.rb +43 -43
- data/lib/engine/debugging.rb +41 -41
- data/lib/engine/engine.rb +131 -131
- data/lib/engine/font.rb +74 -74
- data/lib/engine/game_object.rb +234 -234
- data/lib/engine/importers/font_importer.rb +69 -69
- data/lib/engine/importers/obj_file.rb +244 -244
- data/lib/engine/importers/obj_importer.rb +33 -33
- data/lib/engine/input.rb +105 -104
- data/lib/engine/material.rb +79 -79
- data/lib/engine/mesh.rb +43 -43
- data/lib/engine/path.rb +92 -92
- data/lib/engine/physics/collision.rb +12 -12
- data/lib/engine/physics/components/cube_collider.rb +6 -6
- data/lib/engine/physics/components/rigidbody.rb +103 -103
- data/lib/engine/physics/components/sphere_collider.rb +93 -93
- data/lib/engine/physics/physics_resolver.rb +37 -37
- data/lib/engine/polygon_mesh.rb +45 -45
- data/lib/engine/quaternion.rb +234 -234
- data/lib/engine/rendering/instance_renderer.rb +153 -153
- data/lib/engine/rendering/render_pipeline.rb +35 -35
- data/lib/engine/screenshoter.rb +34 -34
- data/lib/engine/shader.rb +119 -91
- data/lib/engine/shaders/colour_frag.glsl +8 -8
- data/lib/engine/shaders/colour_vertex.glsl +13 -13
- data/lib/engine/shaders/mesh_frag.glsl +102 -102
- data/lib/engine/shaders/mesh_vertex.glsl +25 -25
- data/lib/engine/shaders/skybox_frag.glsl +12 -12
- data/lib/engine/shaders/skybox_vert.glsl +14 -14
- data/lib/engine/shaders/sprite_frag.glsl +17 -17
- data/lib/engine/shaders/sprite_vertex.glsl +15 -15
- data/lib/engine/shaders/text_frag.glsl +15 -15
- data/lib/engine/shaders/text_vertex.glsl +31 -31
- data/lib/engine/shaders/ui_sprite_frag.glsl +15 -15
- data/lib/engine/shaders/ui_sprite_vertex.glsl +15 -15
- data/lib/engine/shaders/vertex_lit_frag.glsl +89 -89
- data/lib/engine/shaders/vertex_lit_vertex.glsl +28 -28
- data/lib/engine/tangent_calculator.rb +42 -42
- data/lib/engine/texture.rb +53 -53
- data/lib/engine/video_mode.rb +37 -37
- data/lib/engine/window.rb +126 -126
- data/lib/ruby_rpg.rb +58 -56
- metadata +5 -6
@@ -1,140 +1,140 @@
|
|
1
|
-
module Engine::Components
|
2
|
-
class UIFontRenderer < Engine::Component
|
3
|
-
attr_reader :mesh, :texture
|
4
|
-
|
5
|
-
def ui_renderer?
|
6
|
-
true
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(font, string)
|
10
|
-
@mesh = Engine::PolygonMesh.new([Vector[-0.5, 0.5], Vector[0.5, 0.5], Vector[0.5, -0.5], Vector[-0.5, -0.5]], [[0, 0], [1, 0], [1, 1], [0, 1]])
|
11
|
-
@texture = font.texture.texture
|
12
|
-
@string = string
|
13
|
-
@font = font
|
14
|
-
end
|
15
|
-
|
16
|
-
def start
|
17
|
-
setup_vertex_attribute_buffer
|
18
|
-
setup_vertex_buffer
|
19
|
-
setup_index_buffer
|
20
|
-
end
|
21
|
-
|
22
|
-
def update_string(string)
|
23
|
-
@string = string
|
24
|
-
update_vbo_buf
|
25
|
-
end
|
26
|
-
|
27
|
-
def update(delta_time)
|
28
|
-
shader.use
|
29
|
-
GL.BindVertexArray(@vao)
|
30
|
-
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
31
|
-
|
32
|
-
set_shader_per_frame_data
|
33
|
-
|
34
|
-
GL.DrawElementsInstanced(GL::TRIANGLES, mesh.index_data.length, GL::UNSIGNED_INT, 0, @string.length)
|
35
|
-
GL.BindVertexArray(0)
|
36
|
-
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def shader
|
42
|
-
@shader ||= Engine::Shader.
|
43
|
-
end
|
44
|
-
|
45
|
-
def set_shader_per_frame_data
|
46
|
-
set_shader_camera_matrix
|
47
|
-
set_shader_model_matrix
|
48
|
-
set_shader_texture
|
49
|
-
end
|
50
|
-
|
51
|
-
def set_shader_model_matrix
|
52
|
-
shader.set_mat4("model", game_object.model_matrix)
|
53
|
-
end
|
54
|
-
|
55
|
-
def set_shader_texture
|
56
|
-
GL.ActiveTexture(GL::TEXTURE0)
|
57
|
-
GL.BindTexture(GL::TEXTURE_2D, texture)
|
58
|
-
shader.set_int("fontTexture", 0)
|
59
|
-
end
|
60
|
-
|
61
|
-
def set_shader_camera_matrix
|
62
|
-
camera_matrix = Matrix[
|
63
|
-
[2.0 / Engine::Window.framebuffer_width, 0, 0, 0],
|
64
|
-
[0, 2.0 / Engine::Window.framebuffer_height, 0, 0],
|
65
|
-
[0, 0, 1, 0],
|
66
|
-
[-1, -1, 0, 1]
|
67
|
-
]
|
68
|
-
shader.set_mat4("camera", camera_matrix)
|
69
|
-
end
|
70
|
-
|
71
|
-
def setup_index_buffer
|
72
|
-
indices = mesh.index_data
|
73
|
-
|
74
|
-
ebo_buf = ' ' * 4
|
75
|
-
GL.GenBuffers(1, ebo_buf)
|
76
|
-
@ebo = ebo_buf.unpack('L')[0]
|
77
|
-
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
78
|
-
GL.BufferData(
|
79
|
-
GL::ELEMENT_ARRAY_BUFFER, indices.length * Fiddle::SIZEOF_INT,
|
80
|
-
indices.pack('I*'), GL::STATIC_DRAW
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
def setup_vertex_attribute_buffer
|
85
|
-
vao_buf = ' ' * 4
|
86
|
-
GL.GenVertexArrays(1, vao_buf)
|
87
|
-
@vao = vao_buf.unpack('L')[0]
|
88
|
-
GL.BindVertexArray(@vao)
|
89
|
-
end
|
90
|
-
|
91
|
-
def setup_vertex_buffer
|
92
|
-
vbo_buf = ' ' * 4
|
93
|
-
GL.GenBuffers(1, vbo_buf)
|
94
|
-
vbo = vbo_buf.unpack('L')[0]
|
95
|
-
points = mesh.vertex_data
|
96
|
-
|
97
|
-
GL.BindBuffer(GL::ARRAY_BUFFER, vbo)
|
98
|
-
GL.BufferData(
|
99
|
-
GL::ARRAY_BUFFER, @mesh.vertex_data.length * Fiddle::SIZEOF_FLOAT,
|
100
|
-
points.pack('F*'), GL::STATIC_DRAW
|
101
|
-
)
|
102
|
-
|
103
|
-
GL.VertexAttribPointer(0, 3, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 0)
|
104
|
-
GL.VertexAttribPointer(1, 2, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 3 * Fiddle::SIZEOF_FLOAT)
|
105
|
-
GL.EnableVertexAttribArray(0)
|
106
|
-
GL.EnableVertexAttribArray(1)
|
107
|
-
|
108
|
-
generate_instance_vbo_buf
|
109
|
-
end
|
110
|
-
|
111
|
-
def generate_instance_vbo_buf
|
112
|
-
@instance_vbo = set_instance_vbo_buf
|
113
|
-
update_vbo_buf
|
114
|
-
end
|
115
|
-
|
116
|
-
def set_instance_vbo_buf
|
117
|
-
instance_vbo_buf = ' ' * 4
|
118
|
-
GL.GenBuffers(1, instance_vbo_buf)
|
119
|
-
instance_vbo_buf.unpack('L')[0]
|
120
|
-
end
|
121
|
-
|
122
|
-
def update_vbo_buf
|
123
|
-
vertex_data = @font.vertex_data(@string)
|
124
|
-
string_length = @string.chars.reject{|c| c == "\n"}.length
|
125
|
-
|
126
|
-
GL.BindBuffer(GL::ARRAY_BUFFER, @instance_vbo)
|
127
|
-
vertex_size = Fiddle::SIZEOF_INT + (Fiddle::SIZEOF_FLOAT * 2)
|
128
|
-
GL.BufferData(
|
129
|
-
GL::ARRAY_BUFFER, string_length * vertex_size,
|
130
|
-
vertex_data.pack('IFF' * string_length), GL::STATIC_DRAW
|
131
|
-
)
|
132
|
-
GL.VertexAttribIPointer(2, 1, GL::INT, vertex_size, 0)
|
133
|
-
GL.VertexAttribPointer(3, 2, GL::FLOAT, GL::FALSE, vertex_size, Fiddle::SIZEOF_INT)
|
134
|
-
GL.EnableVertexAttribArray(2)
|
135
|
-
GL.EnableVertexAttribArray(3)
|
136
|
-
GL.VertexAttribDivisor(2, 1)
|
137
|
-
GL.VertexAttribDivisor(3, 1)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
1
|
+
module Engine::Components
|
2
|
+
class UIFontRenderer < Engine::Component
|
3
|
+
attr_reader :mesh, :texture
|
4
|
+
|
5
|
+
def ui_renderer?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(font, string)
|
10
|
+
@mesh = Engine::PolygonMesh.new([Vector[-0.5, 0.5], Vector[0.5, 0.5], Vector[0.5, -0.5], Vector[-0.5, -0.5]], [[0, 0], [1, 0], [1, 1], [0, 1]])
|
11
|
+
@texture = font.texture.texture
|
12
|
+
@string = string
|
13
|
+
@font = font
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
setup_vertex_attribute_buffer
|
18
|
+
setup_vertex_buffer
|
19
|
+
setup_index_buffer
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_string(string)
|
23
|
+
@string = string
|
24
|
+
update_vbo_buf
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(delta_time)
|
28
|
+
shader.use
|
29
|
+
GL.BindVertexArray(@vao)
|
30
|
+
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
31
|
+
|
32
|
+
set_shader_per_frame_data
|
33
|
+
|
34
|
+
GL.DrawElementsInstanced(GL::TRIANGLES, mesh.index_data.length, GL::UNSIGNED_INT, 0, @string.length)
|
35
|
+
GL.BindVertexArray(0)
|
36
|
+
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def shader
|
42
|
+
@shader ||= Engine::Shader.ui_text
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_shader_per_frame_data
|
46
|
+
set_shader_camera_matrix
|
47
|
+
set_shader_model_matrix
|
48
|
+
set_shader_texture
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_shader_model_matrix
|
52
|
+
shader.set_mat4("model", game_object.model_matrix)
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_shader_texture
|
56
|
+
GL.ActiveTexture(GL::TEXTURE0)
|
57
|
+
GL.BindTexture(GL::TEXTURE_2D, texture)
|
58
|
+
shader.set_int("fontTexture", 0)
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_shader_camera_matrix
|
62
|
+
camera_matrix = Matrix[
|
63
|
+
[2.0 / Engine::Window.framebuffer_width, 0, 0, 0],
|
64
|
+
[0, 2.0 / Engine::Window.framebuffer_height, 0, 0],
|
65
|
+
[0, 0, 1, 0],
|
66
|
+
[-1, -1, 0, 1]
|
67
|
+
]
|
68
|
+
shader.set_mat4("camera", camera_matrix)
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup_index_buffer
|
72
|
+
indices = mesh.index_data
|
73
|
+
|
74
|
+
ebo_buf = ' ' * 4
|
75
|
+
GL.GenBuffers(1, ebo_buf)
|
76
|
+
@ebo = ebo_buf.unpack('L')[0]
|
77
|
+
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
78
|
+
GL.BufferData(
|
79
|
+
GL::ELEMENT_ARRAY_BUFFER, indices.length * Fiddle::SIZEOF_INT,
|
80
|
+
indices.pack('I*'), GL::STATIC_DRAW
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def setup_vertex_attribute_buffer
|
85
|
+
vao_buf = ' ' * 4
|
86
|
+
GL.GenVertexArrays(1, vao_buf)
|
87
|
+
@vao = vao_buf.unpack('L')[0]
|
88
|
+
GL.BindVertexArray(@vao)
|
89
|
+
end
|
90
|
+
|
91
|
+
def setup_vertex_buffer
|
92
|
+
vbo_buf = ' ' * 4
|
93
|
+
GL.GenBuffers(1, vbo_buf)
|
94
|
+
vbo = vbo_buf.unpack('L')[0]
|
95
|
+
points = mesh.vertex_data
|
96
|
+
|
97
|
+
GL.BindBuffer(GL::ARRAY_BUFFER, vbo)
|
98
|
+
GL.BufferData(
|
99
|
+
GL::ARRAY_BUFFER, @mesh.vertex_data.length * Fiddle::SIZEOF_FLOAT,
|
100
|
+
points.pack('F*'), GL::STATIC_DRAW
|
101
|
+
)
|
102
|
+
|
103
|
+
GL.VertexAttribPointer(0, 3, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 0)
|
104
|
+
GL.VertexAttribPointer(1, 2, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 3 * Fiddle::SIZEOF_FLOAT)
|
105
|
+
GL.EnableVertexAttribArray(0)
|
106
|
+
GL.EnableVertexAttribArray(1)
|
107
|
+
|
108
|
+
generate_instance_vbo_buf
|
109
|
+
end
|
110
|
+
|
111
|
+
def generate_instance_vbo_buf
|
112
|
+
@instance_vbo = set_instance_vbo_buf
|
113
|
+
update_vbo_buf
|
114
|
+
end
|
115
|
+
|
116
|
+
def set_instance_vbo_buf
|
117
|
+
instance_vbo_buf = ' ' * 4
|
118
|
+
GL.GenBuffers(1, instance_vbo_buf)
|
119
|
+
instance_vbo_buf.unpack('L')[0]
|
120
|
+
end
|
121
|
+
|
122
|
+
def update_vbo_buf
|
123
|
+
vertex_data = @font.vertex_data(@string)
|
124
|
+
string_length = @string.chars.reject{|c| c == "\n"}.length
|
125
|
+
|
126
|
+
GL.BindBuffer(GL::ARRAY_BUFFER, @instance_vbo)
|
127
|
+
vertex_size = Fiddle::SIZEOF_INT + (Fiddle::SIZEOF_FLOAT * 2)
|
128
|
+
GL.BufferData(
|
129
|
+
GL::ARRAY_BUFFER, string_length * vertex_size,
|
130
|
+
vertex_data.pack('IFF' * string_length), GL::STATIC_DRAW
|
131
|
+
)
|
132
|
+
GL.VertexAttribIPointer(2, 1, GL::INT, vertex_size, 0)
|
133
|
+
GL.VertexAttribPointer(3, 2, GL::FLOAT, GL::FALSE, vertex_size, Fiddle::SIZEOF_INT)
|
134
|
+
GL.EnableVertexAttribArray(2)
|
135
|
+
GL.EnableVertexAttribArray(3)
|
136
|
+
GL.VertexAttribDivisor(2, 1)
|
137
|
+
GL.VertexAttribDivisor(3, 1)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Engine::Components
|
4
|
+
class UISpriteClickbox < Engine::Component
|
5
|
+
attr_reader :mouse_inside, :clicked, :mouse_entered, :mouse_exited
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@mouse_inside = false
|
9
|
+
@clicked = false
|
10
|
+
@mouse_entered = false
|
11
|
+
@mouse_exited = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
@renderer = game_object.ui_renderers.find { |r| r.is_a?(Engine::Components::UISpriteRenderer) }
|
16
|
+
raise "UISpriteClickbox requires a UISpriteRenderer" unless @renderer
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(delta_time)
|
20
|
+
mouse_pos = Engine::Input.mouse_pos
|
21
|
+
return unless mouse_pos
|
22
|
+
|
23
|
+
if point_inside?(mouse_pos)
|
24
|
+
@mouse_entered = !@mouse_inside
|
25
|
+
@mouse_inside = true
|
26
|
+
@clicked = Engine::Input.key_down?(GLFW::MOUSE_BUTTON_LEFT)
|
27
|
+
else
|
28
|
+
@mouse_exited = @mouse_inside
|
29
|
+
@mouse_inside = false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def point_inside?(point)
|
36
|
+
local_point = game_object.world_to_local_coordinate(Vector[point[0], point[1], 0])
|
37
|
+
local_point = Vector[local_point[0], local_point[1]]
|
38
|
+
|
39
|
+
tl = @renderer.v1
|
40
|
+
tr = @renderer.v2
|
41
|
+
br = @renderer.v3
|
42
|
+
bl = @renderer.v4
|
43
|
+
|
44
|
+
point_in_triangle(local_point, tl, tr, br) ||
|
45
|
+
point_in_triangle(local_point, tl, br, bl)
|
46
|
+
end
|
47
|
+
|
48
|
+
def point_in_triangle(point, v1, v2, v3)
|
49
|
+
mapped_point = point - v1
|
50
|
+
mapped_v2 = v2 - v1
|
51
|
+
mapped_v3 = v3 - v1
|
52
|
+
|
53
|
+
matrix = Matrix[
|
54
|
+
[mapped_v2[0], mapped_v3[0]],
|
55
|
+
[mapped_v2[1], mapped_v3[1]]
|
56
|
+
]
|
57
|
+
|
58
|
+
remapped_point = matrix.inverse * mapped_point
|
59
|
+
remapped_point[0] >= 0 && remapped_point[1] >= 0 && remapped_point[0] + remapped_point[1] <= 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,101 +1,101 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Engine::Components
|
4
|
-
class UISpriteRenderer < Engine::Component
|
5
|
-
attr_reader :v1, :v2, :v3, :v4, :material
|
6
|
-
|
7
|
-
def ui_renderer?
|
8
|
-
true
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(tl, tr, br, bl, material)
|
12
|
-
@v1 = tl
|
13
|
-
@v2 = tr
|
14
|
-
@v3 = br
|
15
|
-
@v4 = bl
|
16
|
-
@material = material
|
17
|
-
end
|
18
|
-
|
19
|
-
def start
|
20
|
-
setup_vertex_attribute_buffer
|
21
|
-
setup_vertex_buffer
|
22
|
-
setup_index_buffer
|
23
|
-
end
|
24
|
-
|
25
|
-
def update(delta_time)
|
26
|
-
GL.BindVertexArray(@vao)
|
27
|
-
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
28
|
-
|
29
|
-
set_material_per_frame_data
|
30
|
-
|
31
|
-
GL.DrawElements(GL::TRIANGLES, 6, GL::UNSIGNED_INT, 0)
|
32
|
-
|
33
|
-
GL.BindVertexArray(0)
|
34
|
-
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def set_material_per_frame_data
|
40
|
-
set_camera_matrix
|
41
|
-
material.set_mat4("model", game_object.model_matrix)
|
42
|
-
material.update_shader
|
43
|
-
end
|
44
|
-
|
45
|
-
def set_camera_matrix
|
46
|
-
camera_matrix = Matrix[
|
47
|
-
[2.0 / Engine::Window.framebuffer_width, 0, 0, 0],
|
48
|
-
[0, 2.0 / Engine::Window.framebuffer_height, 0, 0],
|
49
|
-
[0, 0, 1, 0],
|
50
|
-
[-1, -1, 0, 1]
|
51
|
-
]
|
52
|
-
material.set_mat4("camera", camera_matrix)
|
53
|
-
end
|
54
|
-
|
55
|
-
def setup_index_buffer
|
56
|
-
indices = [
|
57
|
-
0, 2, 1,
|
58
|
-
2, 0, 3
|
59
|
-
]
|
60
|
-
|
61
|
-
ebo_buf = ' ' * 4
|
62
|
-
GL.GenBuffers(1, ebo_buf)
|
63
|
-
@ebo = ebo_buf.unpack('L')[0]
|
64
|
-
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
65
|
-
GL.BufferData(
|
66
|
-
GL::ELEMENT_ARRAY_BUFFER, 6 * Fiddle::SIZEOF_INT,
|
67
|
-
indices.pack('I*'), GL::STATIC_DRAW
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
def setup_vertex_attribute_buffer
|
72
|
-
va0_buf = ' ' * 4
|
73
|
-
GL.GenVertexArrays(1, va0_buf)
|
74
|
-
@vao = va0_buf.unpack('L')[0]
|
75
|
-
GL.BindVertexArray(@vao)
|
76
|
-
end
|
77
|
-
|
78
|
-
def setup_vertex_buffer
|
79
|
-
vbo_buf = ' ' * 4
|
80
|
-
GL.GenBuffers(1, vbo_buf)
|
81
|
-
vbo = vbo_buf.unpack('L')[0]
|
82
|
-
points = [
|
83
|
-
v1[0], v1[1], 0, 0, 0,
|
84
|
-
v2[0], v2[1], 0, 1, 0,
|
85
|
-
v3[0], v3[1], 0, 1, 1,
|
86
|
-
v4[0], v4[1], 0, 0, 1
|
87
|
-
]
|
88
|
-
|
89
|
-
GL.BindBuffer(GL::ARRAY_BUFFER, vbo)
|
90
|
-
GL.BufferData(
|
91
|
-
GL::ARRAY_BUFFER, 4 * 5 * Fiddle::SIZEOF_FLOAT,
|
92
|
-
points.pack('F*'), GL::STATIC_DRAW
|
93
|
-
)
|
94
|
-
|
95
|
-
GL.VertexAttribPointer(0, 3, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 0)
|
96
|
-
GL.VertexAttribPointer(1, 2, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 3 * Fiddle::SIZEOF_FLOAT)
|
97
|
-
GL.EnableVertexAttribArray(0)
|
98
|
-
GL.EnableVertexAttribArray(1)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Engine::Components
|
4
|
+
class UISpriteRenderer < Engine::Component
|
5
|
+
attr_reader :v1, :v2, :v3, :v4, :material
|
6
|
+
|
7
|
+
def ui_renderer?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(tl, tr, br, bl, material)
|
12
|
+
@v1 = tl
|
13
|
+
@v2 = tr
|
14
|
+
@v3 = br
|
15
|
+
@v4 = bl
|
16
|
+
@material = material
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
setup_vertex_attribute_buffer
|
21
|
+
setup_vertex_buffer
|
22
|
+
setup_index_buffer
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(delta_time)
|
26
|
+
GL.BindVertexArray(@vao)
|
27
|
+
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
28
|
+
|
29
|
+
set_material_per_frame_data
|
30
|
+
|
31
|
+
GL.DrawElements(GL::TRIANGLES, 6, GL::UNSIGNED_INT, 0)
|
32
|
+
|
33
|
+
GL.BindVertexArray(0)
|
34
|
+
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def set_material_per_frame_data
|
40
|
+
set_camera_matrix
|
41
|
+
material.set_mat4("model", game_object.model_matrix)
|
42
|
+
material.update_shader
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_camera_matrix
|
46
|
+
camera_matrix = Matrix[
|
47
|
+
[2.0 / Engine::Window.framebuffer_width, 0, 0, 0],
|
48
|
+
[0, 2.0 / Engine::Window.framebuffer_height, 0, 0],
|
49
|
+
[0, 0, 1, 0],
|
50
|
+
[-1, -1, 0, 1]
|
51
|
+
]
|
52
|
+
material.set_mat4("camera", camera_matrix)
|
53
|
+
end
|
54
|
+
|
55
|
+
def setup_index_buffer
|
56
|
+
indices = [
|
57
|
+
0, 2, 1,
|
58
|
+
2, 0, 3
|
59
|
+
]
|
60
|
+
|
61
|
+
ebo_buf = ' ' * 4
|
62
|
+
GL.GenBuffers(1, ebo_buf)
|
63
|
+
@ebo = ebo_buf.unpack('L')[0]
|
64
|
+
GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)
|
65
|
+
GL.BufferData(
|
66
|
+
GL::ELEMENT_ARRAY_BUFFER, 6 * Fiddle::SIZEOF_INT,
|
67
|
+
indices.pack('I*'), GL::STATIC_DRAW
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup_vertex_attribute_buffer
|
72
|
+
va0_buf = ' ' * 4
|
73
|
+
GL.GenVertexArrays(1, va0_buf)
|
74
|
+
@vao = va0_buf.unpack('L')[0]
|
75
|
+
GL.BindVertexArray(@vao)
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup_vertex_buffer
|
79
|
+
vbo_buf = ' ' * 4
|
80
|
+
GL.GenBuffers(1, vbo_buf)
|
81
|
+
vbo = vbo_buf.unpack('L')[0]
|
82
|
+
points = [
|
83
|
+
v1[0], v1[1], 0, 0, 0,
|
84
|
+
v2[0], v2[1], 0, 1, 0,
|
85
|
+
v3[0], v3[1], 0, 1, 1,
|
86
|
+
v4[0], v4[1], 0, 0, 1
|
87
|
+
]
|
88
|
+
|
89
|
+
GL.BindBuffer(GL::ARRAY_BUFFER, vbo)
|
90
|
+
GL.BufferData(
|
91
|
+
GL::ARRAY_BUFFER, 4 * 5 * Fiddle::SIZEOF_FLOAT,
|
92
|
+
points.pack('F*'), GL::STATIC_DRAW
|
93
|
+
)
|
94
|
+
|
95
|
+
GL.VertexAttribPointer(0, 3, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 0)
|
96
|
+
GL.VertexAttribPointer(1, 2, GL::FLOAT, GL::FALSE, 5 * Fiddle::SIZEOF_FLOAT, 3 * Fiddle::SIZEOF_FLOAT)
|
97
|
+
GL.EnableVertexAttribArray(0)
|
98
|
+
GL.EnableVertexAttribArray(1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Engine
|
2
|
+
class ComputeShader
|
3
|
+
def initialize(compute_shader)
|
4
|
+
@uniform_locations = {}
|
5
|
+
@compute_shader = compile_shader(compute_shader)
|
6
|
+
@program = GL.CreateProgram
|
7
|
+
GL.AttachShader(@program, @compute_shader)
|
8
|
+
GL.LinkProgram(@program)
|
9
|
+
|
10
|
+
linked_buf = ' ' * 4
|
11
|
+
GL.GetProgramiv(@program, GL::LINK_STATUS, linked_buf)
|
12
|
+
linked = linked_buf.unpack('L')[0]
|
13
|
+
if linked == 0
|
14
|
+
compile_log = ' ' * 1024
|
15
|
+
GL.GetProgramInfoLog(@program, 1023, nil, compile_log)
|
16
|
+
compute_log = ' ' * 1024
|
17
|
+
GL.GetShaderInfoLog(@compute_shader, 1023, nil, compute_log)
|
18
|
+
puts "Shader program failed to link"
|
19
|
+
puts compile_log.strip
|
20
|
+
puts compute_log.strip
|
21
|
+
end
|
22
|
+
@uniform_cache = {}
|
23
|
+
@uniform_locations = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def compile_shader(shader)
|
27
|
+
handle = GL.CreateShader(GL::COMPUTE_SHADER)
|
28
|
+
path = File.expand_path(File.join(GAME_DIR, shader))
|
29
|
+
s_srcs = [File.read(path)].pack('p')
|
30
|
+
s_lens = [File.size(path)].pack('I')
|
31
|
+
GL.ShaderSource(handle, 1, s_srcs, s_lens)
|
32
|
+
GL.CompileShader(handle)
|
33
|
+
handle
|
34
|
+
end
|
35
|
+
|
36
|
+
def dispatch(x, y, z, floats: {}, textures: [], ints: {}, vec3s: {}, vec4s: {}, mat4s: {})
|
37
|
+
textures.each_with_index { |texture, slot| set_texture(slot, texture) }
|
38
|
+
|
39
|
+
GL.UseProgram(@program)
|
40
|
+
|
41
|
+
floats.each { |name, value| set_float(name, value) }
|
42
|
+
ints.each { |name, value| set_int(name, value) }
|
43
|
+
vec3s.each { |name, value| set_vec3(name, value) }
|
44
|
+
vec4s.each { |name, value| set_vec4(name, value) }
|
45
|
+
mat4s.each { |name, value| set_mat4(name, value) }
|
46
|
+
|
47
|
+
GL.DispatchCompute(x, y, z)
|
48
|
+
GL.MemoryBarrier(GL::SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def set_float(name, float)
|
54
|
+
GL.Uniform1f(uniform_location(name), float)
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_texture(slot, texture)
|
58
|
+
#puts "set #{slot}, to #{texture}"
|
59
|
+
GL.ActiveTexture(Object.const_get("GL::TEXTURE#{slot}"))
|
60
|
+
if texture
|
61
|
+
GL.BindImageTexture(slot, texture, 0, GL::FALSE, 0, GL::READ_WRITE, GL::RGBA32F)
|
62
|
+
else
|
63
|
+
GL.BindImageTexture(slot, 0, 0, GL::FALSE, 0, GL::READ_WRITE, GL::RGBA32F)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_vec3(name, vec)
|
68
|
+
GL.Uniform3f(uniform_location(name), vector[0], vector[1], vector[2])
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_vec4(name, vec)
|
72
|
+
GL.Uniform4f(uniform_location(name), vec[0], vec[1], vec[2], vec[3])
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_mat4(name, mat)
|
76
|
+
mat_array = [
|
77
|
+
mat[0, 0], mat[0, 1], mat[0, 2], mat[0, 3],
|
78
|
+
mat[1, 0], mat[1, 1], mat[1, 2], mat[1, 3],
|
79
|
+
mat[2, 0], mat[2, 1], mat[2, 2], mat[2, 3],
|
80
|
+
mat[3, 0], mat[3, 1], mat[3, 2], mat[3, 3]
|
81
|
+
]
|
82
|
+
GL.UniformMatrix4fv(uniform_location(name), 1, GL::FALSE, mat_array.pack('F*'))
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_int(name, int)
|
86
|
+
GL.Uniform1i(uniform_location(name), int)
|
87
|
+
end
|
88
|
+
|
89
|
+
def uniform_location(name)
|
90
|
+
@uniform_locations[name] ||= GL.GetUniformLocation(@program, name)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|