diff --git a/.gitignore b/.gitignore index 7dc7ce8..ec0a7a4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ inter/ ## Files *.user *.filters -**/imgui\.ini +**\.ini ## VisualStudio Specific *.vcxproj diff --git a/README.md b/README.md index 9dce5ee..9546586 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ -# Ember Editor [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build status](https://ci.appveyor.com/api/projects/status/r3k87jbaegd8v3fc/branch/procedural_generation?svg=true)](https://ci.appveyor.com/project/L4ZZA/pyro-procedural-gen/branch/procedural_generation) -================== - +# Ember Editor [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build status](https://ci.appveyor.com/api/projects/status/47kvcru66wge4vas/branch/develop?svg=true)](https://ci.appveyor.com/project/L4ZZA/pyro/branch/develop) > A small piece of burning or glowing coal or wood in a dying fire. @@ -21,7 +19,8 @@ Real-time 2D level editor using Pyro engine. > **Requirements** > - Install [NSIS: Nullsoft Scriptable Install System](https://sourceforge.net/projects/nsis/) to its default location `C:\Program Files (x86)\NSIS` -> - Add the install directory to your system path like so:![image](https://i.imgur.com/cTZquD7.png) +> - Add the install directory to your system path like so: + ![image](https://i.imgur.com/cTZquD7.png) - Run the `create_installer.bat`, thie will generate the installer in the bin directory. - go to `bin\Release-windows-x86_64\installers` and run `LevelEditorSetup.exe`. diff --git a/appveyor.yml b/appveyor.yml index 539e9bc..ea27549 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,15 +1,13 @@ # # Reference list # - https://raw.githubusercontent.com/malaterre/GDCM/master/appveyor.yml -# +# - https://github.com/KhronosGroup/SPIRV-Tools/blob/master/.appveyor.yml +# - https://gitlab.com/eyeo/adblockplus/libadblockplus/blob/master/appveyor.yml # # http://www.appveyor.com/docs/build-cache#caching-chocolatey-packages # https://github.com/kvirc/KVIrc/blob/master/.appveyor.yml cache: - - C:\Tools\vcpkg\installed -> appveyor.yml -# caching binries and intermediates to allow incremental build - - C:\dev\source\bin -> appveyor.yml - - C:\dev\source\inter -> appveyor.yml + - C:\Tools\vcpkg\installed # - 'C:\Program Files (x86)\NSIS' # - C:\ProgramData\chocolatey\bin -> appveyor.yml # - C:\ProgramData\chocolatey\lib -> appveyor.yml @@ -35,11 +33,16 @@ environment: image: - Visual Studio 2019 +# stop infinite cycle of tag creation and build on tag +skip_tags: true + +clone_depth: 1 + # branches to build branches: # whitelist only: - - procedural_generation + - develop #---------------------------------# # scripts that are called at # @@ -146,7 +149,6 @@ deploy: artifact: installer draft: false prerelease: true - appveyor_repo_tag: false # deploy on tag push only on: - branch: procedural_generation # release from master branch only + branch: develop # release from master branch only configuration: Release \ No newline at end of file diff --git a/installer/Ember.nsi b/installer/Ember.nsi index 0c1c313..234370a 100644 --- a/installer/Ember.nsi +++ b/installer/Ember.nsi @@ -31,7 +31,7 @@ !system '${CMD_PATH} /C ${ScriptPath} ${LinkName} ${LinkDest} ${LinkTarget}' !macroend - !insertmacro WebShortucts "${SCRIPTS_DIR}\create_shortcut.cmd" "Readme" "." "https://github.com/L4ZZA/pyro/blob/procedural_generation/README.md" + !insertmacro WebShortucts "${SCRIPTS_DIR}\create_shortcut.cmd" "Readme" "." "https://github.com/L4ZZA/pyro/blob/develop/README.md" ;General diff --git a/pyro/external/GLFW b/pyro/external/GLFW index ad087f5..0156dfc 160000 --- a/pyro/external/GLFW +++ b/pyro/external/GLFW @@ -1 +1 @@ -Subproject commit ad087f56842d00304f3849ecfe0096ebe63ac810 +Subproject commit 0156dfcc8de511c7710eb20f427b3f82f98963ab diff --git a/sandbox/assets/shaders/color.glsl b/sandbox/assets/shaders/color.glsl new file mode 100644 index 0000000..43f2507 --- /dev/null +++ b/sandbox/assets/shaders/color.glsl @@ -0,0 +1,36 @@ +/* +* Simple color shader, taking position and vec4 color as input. +*/ + +#type vertex +#version 430 + +layout(location = 0) in vec3 a_position; +layout(location = 1) in vec4 a_color; + +uniform mat4 u_view_projection; +uniform mat4 u_transform; + +out vec3 v_position; +out vec4 v_color; + +void main() +{ + v_position = a_position; + v_color = a_color; + gl_Position = u_view_projection * u_transform * vec4(a_position, 1.0); +} + +#type fragment +#version 430 + +layout(location = 0) out vec4 o_color; + +in vec3 v_position; +in vec4 v_color; + +void main() +{ + o_color = v_color; +} + diff --git a/sandbox/assets/shaders/dynamic_flat_color.glsl b/sandbox/assets/shaders/dynamic_flat_color.glsl new file mode 100644 index 0000000..6a55c3b --- /dev/null +++ b/sandbox/assets/shaders/dynamic_flat_color.glsl @@ -0,0 +1,33 @@ +/* +* Simple flat color shader, with dynamic update of the color. +*/ + +#type vertex +#version 430 + +layout(location = 0) in vec3 a_position; + +uniform mat4 u_view_projection; +uniform mat4 u_transform; + +out vec3 v_position; + +void main() +{ + v_position = a_position; + gl_Position = u_view_projection * u_transform * vec4(a_position, 1.0); +} + +#type fragment +#version 430 + +layout(location = 0) out vec4 o_color; + +in vec3 v_position; + +uniform vec4 u_color; + +void main() +{ + o_color = u_color; +} diff --git a/sandbox/assets/shaders/texture.glsl b/sandbox/assets/shaders/texture.glsl new file mode 100644 index 0000000..f45e7cf --- /dev/null +++ b/sandbox/assets/shaders/texture.glsl @@ -0,0 +1,34 @@ +/* +* Simple texture shader. +*/ + +#type vertex +#version 430 + +layout(location = 0) in vec3 a_position; +layout(location = 1) in vec2 a_tex_coord; + +uniform mat4 u_view_projection; +uniform mat4 u_transform; + +out vec2 v_tex_coord; + +void main() +{ + v_tex_coord = a_tex_coord; + gl_Position = u_view_projection * u_transform * vec4(a_position, 1.0); +} + +#type fragment +#version 430 + +layout(location = 0) out vec4 o_color; + +in vec2 v_tex_coord; + +uniform sampler2D u_sampler; + +void main() +{ + o_color = texture(u_sampler, v_tex_coord); +} diff --git a/sandbox/assets/textures/checkerboard.png b/sandbox/assets/textures/checkerboard.png new file mode 100644 index 0000000..a384354 Binary files /dev/null and b/sandbox/assets/textures/checkerboard.png differ diff --git a/sandbox/assets/textures/face.png b/sandbox/assets/textures/face.png new file mode 100644 index 0000000..80531e0 Binary files /dev/null and b/sandbox/assets/textures/face.png differ diff --git a/sandbox/src/layer_2d.cpp b/sandbox/src/layer_2d.cpp new file mode 100644 index 0000000..bea5d87 --- /dev/null +++ b/sandbox/src/layer_2d.cpp @@ -0,0 +1,124 @@ +#include "layer_2d.h" +#include "imgui/imgui.h" + + +layer_2d::layer_2d() : imgui_layer("Sandbox2D"), +m_2d_camera_controller(1280.0f / 720.0f, true) +{ +} + +layer_2d::~layer_2d() +{ +} + +void layer_2d::on_attach() +{ + PYRO_PROFILE_FUNCTION(); + imgui_layer::on_attach(); + + pyro::texture::wrap(pyro::e_texture_wrap::repeat); + m_checkerboard_texture = pyro::texture_2d::create_from_file("assets/textures/checkerboard.png"); +} + +void layer_2d::on_detach() +{ + PYRO_PROFILE_FUNCTION(); +} + +static float rotation = 0.0f; +void layer_2d::on_update(const pyro::timestep &ts) +{ + // Update + PYRO_PROFILE_FUNCTION(); + m_2d_camera_controller.on_update(ts); + rotation += ts * 0.5f; +} + +void layer_2d::on_imgui_render() +{ + pyro::renderer_2d::reset_stats(); + { + // Pre Render + PYRO_PROFILE_SCOPE("layer_2d::pre_render"); + pyro::render_command::clear_color({0.1f, 0.1f, 0.1f, 1}); + pyro::render_command::clear(); + } + { + // Render + PYRO_PROFILE_SCOPE("layer_2d::render"); + pyro::renderer_2d::begin_scene(m_2d_camera_controller.camera()); + pyro::quad_properties props; + + props.position = {1.f, 0.0f, 0.f}; + props.size = {0.8f, 0.85f}; + props.rotation = -45.f; + props.color = { 0.8f, 0.2f, 0.3f, 1.0f }; + pyro::renderer_2d::draw_quad(props); + + props.position = {-1.0f, 0.0f, 0.f}; + props.size = {0.8f, 0.8f}; + props.rotation = 0.f; + props.color = {0.8f, 0.3f, 0.2f, 1.0f}; + pyro::renderer_2d::draw_quad(props); + + props.position = {0.5f, -0.5f, 0.f}; + props.size = {0.5f, 0.75f}; + props.color = {m_rect_color, 1.f}; + pyro::renderer_2d::draw_quad(props); + + props.position = { 0.f, 0.f, -0.1f }; + props.size = {20.f, 20.f}; + props.color = glm::vec4(1.f); + props.tiling_factor = 10.f; + props.texture = m_checkerboard_texture; + pyro::renderer_2d::draw_quad(props); + + props.color = glm::vec4(1); + props.position = { -2.f, 0.f, 0.0f }; + props.size = {1.f, 1.f}; + props.rotation = rotation; + props.tiling_factor = 20.f; + props.color = { .8f, 1.f, .8f, 1.f }; + pyro::renderer_2d::draw_quad(props); + + for (float y = -5.0f; y < 5.0f; y += 0.5f) + { + for (float x = -5.0f; x < 5.0f; x += 0.5f) + { + pyro::quad_properties props; + props.color = { (x + 5.0f) / 10.0f, 0.4f, (y + 5.0f) / 10.0f, 0.7f }; + props.size = { 0.45f, 0.45f }; + props.position = { x, y, 0.f }; + pyro::renderer_2d::draw_quad(props); + } + } + pyro::renderer_2d::end_scene(); + } + + ImGui::Begin("Settings"); + + ImGui::ColorEdit3("Squares color", glm::value_ptr(m_rect_color)); + for (auto& result : m_profile_results) + { + char label[50]; + strcpy_s(label, "%.3fms "); + strcat_s(label, result.name); + ImGui::Text(label, result.time); + } + m_profile_results.clear(); + + auto stats = pyro::renderer_2d::stats(); + ImGui::Text("-- 2D Renderer stats:"); + ImGui::Text("- Draw calls: %d", stats.draw_calls); + ImGui::Text("- Quads: %d", stats.quad_count); + ImGui::Text("- Vertices: %d", stats.total_vertex_count()); + ImGui::Text("- Indices: %d", stats.total_index_count()); + ImGui::Text("---------------------"); + + ImGui::End(); +} + +void layer_2d::on_event(pyro::event &e) +{ + m_2d_camera_controller.on_event(e); +} diff --git a/sandbox/src/layer_3d.cpp b/sandbox/src/layer_3d.cpp new file mode 100644 index 0000000..add8956 --- /dev/null +++ b/sandbox/src/layer_3d.cpp @@ -0,0 +1,169 @@ +#include "layer_3d.h" +#include + +layer_3d::layer_3d() + :m_3d_camera_controller(pyro::perspective_camera_controller::e_control_type::first_person, + static_cast(pyro::application::window().width()), + static_cast(pyro::application::window().height())) +{ + m_color_shader = m_shader_library.load("assets/shaders/color.glsl"); + m_textured_shader = m_shader_library.load("assets/shaders/texture.glsl"); + + //======= triangle ========= + float vertices[3 * 7] + { + -.5f, -.5f, .0f, .8f, .2f, .8f, 1.0f, + .5f, -.5f, .0f, .2f, .3f, .8f, 1.0f, + .0f, .5f, .0f, .8f, .8f, .2f, 1.0f, + }; + + pyro::ref triangle_vb(pyro::vertex_buffer::create(vertices, sizeof(vertices))); + + const pyro::buffer_layout layout + { + {pyro::e_shader_data_type::float3, "a_position"}, + {pyro::e_shader_data_type::float2, "a_tex_coord"}, + }; + triangle_vb->layout(layout); + + uint32_t indices[3]{0,1,2}; + const pyro::ref triangle_ib(pyro::index_buffer::create(indices, sizeof(indices) / sizeof(uint32_t))); + + m_triangle_va = pyro::vertex_array::create(); + m_triangle_va->add_buffer(triangle_vb); + m_triangle_va->add_buffer(triangle_ib); + + //======== rectangle ========= + + float rect_vertices[] + { + -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, + -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + }; + + const pyro::ref rect_vb = pyro::vertex_buffer::create(rect_vertices, sizeof(rect_vertices)); + + uint32_t rect_indices[]{0,1,2, 2,3,0}; + const pyro::ref rect_ib = pyro::index_buffer::create(rect_indices, sizeof(rect_indices) / sizeof(uint32_t)); + + rect_vb->layout({ + {pyro::e_shader_data_type::float3, "a_position"}, + {pyro::e_shader_data_type::float2, "a_tex_coord"}, + }); + + m_rect_va = pyro::vertex_array::create(); + m_rect_va->add_buffer(rect_vb); + m_rect_va->add_buffer(rect_ib); + + //======== cube ========= + + float cube_vertices[] + { + // FRONT + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // A + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // B + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // C + -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // D + + // BACK + -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // E + 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // F + 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // G + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // H + + // LEFT + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // E = 8 + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // H = 9 + -0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // D = 10 + -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // A = 11 + + // RIGHT + 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // F = 12 + 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // G = 13 + 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // C = 14 + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // B = 15 + + // BOTTOM + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // E = 16 + 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // F = 17 + 0.5f, -0.5f, 0.5f, 1.0f, 1.0f, // B = 18 + -0.5f, -0.5f, 0.5f, 0.0f, 1.0f, // A = 19 + + // TOP + -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, // G = 20 + 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, // H = 21 + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // D = 22 + -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // C = 23 + }; + + const pyro::ref cube_vb = pyro::vertex_buffer::create(cube_vertices, sizeof(cube_vertices)); + + uint32_t cube_indices[] + { + 0, 1, 2, 2, 3, 0, // FRONT + 5, 4, 7, 7, 6, 5, // BACK + 8,11,10, 10, 9, 8, // LEFT + 15,12,13, 13,14,15, // RIGHT + 16,17,18, 18,19,16, // BOTTOM + 21,20,23, 23,22,21 // TOP + + }; + const pyro::ref cube_ib = pyro::index_buffer::create(cube_indices, sizeof(cube_indices) / sizeof(uint32_t)); + + cube_vb->layout({ + {pyro::e_shader_data_type::float3, "a_position"}, + {pyro::e_shader_data_type::float2, "a_tex_coord"}, + }); + + m_cube_va = pyro::vertex_array::create(); + m_cube_va->add_buffer(cube_vb); + m_cube_va->add_buffer(cube_ib); + + m_textured_shader->bind(); + m_textured_shader->set_int("u_sampler", 0); + + m_texture = pyro::texture_2d::create_from_file("assets/textures/checkerboard.png"); + m_face_texture = pyro::texture_2d::create_from_file("assets/textures/face.png"); +} + +void layer_3d::on_update(const pyro::timestep ×tep) +{ + m_3d_camera_controller.on_update(timestep); + //m_3d_camera.on_update(timestep); +} + +void layer_3d::on_imgui_render() +{ + + pyro::render_command::clear_color({0.2f, 0.3f, 0.3f, 1.0f}); + pyro::render_command::clear(); + + pyro::renderer::begin_scene(m_3d_camera_controller.camera(), m_textured_shader); + + glm::mat4 transform(1.0f); + // big square + m_texture->bind(); + pyro::renderer::submit(m_textured_shader, m_rect_va, transform); + m_face_texture->bind(); + pyro::renderer::submit(m_textured_shader, m_rect_va, transform); + + pyro::renderer::end_scene(); + +} + +void layer_3d::on_event(pyro::event &event) +{ + if(event.event_type() == pyro::event_type_e::key_pressed) + { + auto &e = dynamic_cast(event); + if(e.key_code() == pyro::key_codes::KEY_TAB) + { + pyro::render_command::toggle_wireframe(); + } + //PYRO_TRACE("{0}", static_cast(e.key_code())); + } + m_3d_camera_controller.on_event(event); + +} diff --git a/sandbox/src/layer_3d.h b/sandbox/src/layer_3d.h new file mode 100644 index 0000000..6b7c68c --- /dev/null +++ b/sandbox/src/layer_3d.h @@ -0,0 +1,27 @@ +#pragma once +#include + +class layer_3d : public pyro::imgui_layer +{ +public: + layer_3d(); + + void on_update(const pyro::timestep& timestep) override; + void on_imgui_render() override; + void on_event(pyro::event& event) override; + +private: + pyro::ref m_color_shader{}; + pyro::ref m_triangle_va{}; + + //pyro::ref m_flat_color_shader{}; + pyro::ref m_textured_shader{}; + pyro::ref m_rect_va{}; + pyro::ref m_cube_va{}; + pyro::ref m_texture{}; + pyro::ref m_face_texture{}; + pyro::shader_library m_shader_library; + //pyro::orthographic_camera_controller m_2d_camera_controller; + pyro::perspective_camera_controller m_3d_camera_controller; + +}; diff --git a/scripts/delete_all_tags.bat b/scripts/delete_all_tags.bat new file mode 100644 index 0000000..dc704e5 --- /dev/null +++ b/scripts/delete_all_tags.bat @@ -0,0 +1,12 @@ +@echo off +@rem this script was created to clear the repository from all the wrongly +@rem generated release tags. + +@rem remove all local tags +for /f "tokens=* delims=" %%a in ('git tag -l') do ( git tag -d %%a ) + +@rem fetch a reference to the remote ones +git fetch + +@rem delete all remote tags +for /f "tokens=* delims=" %%a in ('git tag -l') do ( git push --delete origin %%a )