From 54d9c199f59be2b4f0f4d69e7d158c76f15bd5e2 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sat, 23 Oct 2021 01:16:13 +0800 Subject: [PATCH] Put classes related to high-level rendering into render namespace --- CMakeLists.txt | 1 + src/animation/screen-transition.cpp | 2 +- src/animation/screen-transition.hpp | 12 +- src/entity/components/model.hpp | 6 +- src/entity/components/terrain.hpp | 4 +- src/entity/systems/astronomy.cpp | 2 +- src/entity/systems/astronomy.hpp | 6 +- src/entity/systems/painting.cpp | 6 +- src/entity/systems/painting.hpp | 8 +- src/entity/systems/render.cpp | 3 +- src/entity/systems/render.hpp | 7 +- src/entity/systems/subterrain.cpp | 22 +- src/entity/systems/subterrain.hpp | 14 +- src/entity/systems/terrain.cpp | 20 +- src/entity/systems/terrain.hpp | 8 +- src/entity/systems/ui.cpp | 192 ------------------ src/entity/systems/ui.hpp | 89 -------- src/entity/systems/vegetation.cpp | 2 +- src/game/bootloader.cpp | 82 ++++---- src/game/context.hpp | 76 ++++--- src/game/states/brood.cpp | 2 +- src/game/states/forage.cpp | 2 +- src/game/states/loading.cpp | 161 +++++++++------ src/game/states/nuptial-flight.cpp | 3 +- src/game/tools.cpp | 4 +- src/input/control-set.hpp | 2 - src/input/gamepad.hpp | 2 - src/input/mapping.hpp | 2 - src/{renderer => render}/compositor.cpp | 13 +- src/{renderer => render}/compositor.hpp | 25 ++- src/{renderer => render}/context.hpp | 0 src/{renderer => render}/material-flags.hpp | 0 .../material-property.cpp | 5 +- .../material-property.hpp | 9 +- src/{renderer => render}/material.cpp | 6 +- src/{renderer => render}/material.hpp | 15 +- src/{renderer => render}/model.cpp | 6 +- src/{renderer => render}/model.hpp | 18 +- src/{renderer => render}/operation.hpp | 3 +- .../render-pass.cpp => render/pass.cpp} | 11 +- .../render-pass.hpp => render/pass.hpp} | 18 +- .../passes/bloom-pass.cpp | 11 +- .../passes/bloom-pass.hpp | 14 +- .../passes/clear-pass.cpp | 8 +- .../passes/clear-pass.hpp | 38 +++- .../passes/final-pass.cpp | 13 +- .../passes/final-pass.hpp | 16 +- .../passes/material-pass.cpp | 22 +- .../passes/material-pass.hpp | 23 ++- .../passes/outline-pass.cpp | 21 +- .../passes/outline-pass.hpp | 13 +- .../passes/shadow-map-pass.cpp | 16 +- .../passes/shadow-map-pass.hpp | 14 +- .../passes/simple-pass.cpp} | 25 ++- .../passes/simple-pass.hpp} | 27 +-- src/{renderer => render}/passes/sky-pass.cpp | 17 +- src/{renderer => render}/passes/sky-pass.hpp | 17 +- src/{renderer => render}/passes/ui-pass.cpp | 15 +- src/{renderer => render}/passes/ui-pass.hpp | 15 +- src/{renderer => render}/queue.hpp | 2 +- src/render/render.hpp | 28 +++ src/{renderer => render}/renderer.cpp | 12 +- src/{renderer => render}/renderer.hpp | 25 +-- src/{renderer => render}/shader-template.cpp | 6 +- src/{renderer => render}/shader-template.hpp | 10 +- src/{renderer => render}/vertex-attribute.hpp | 38 +--- src/resources/entity-archetype-loader.cpp | 4 +- src/resources/material-loader.cpp | 34 ++-- src/resources/model-loader.cpp | 14 +- src/resources/shader-program-loader.cpp | 6 +- src/scene/billboard.cpp | 3 +- src/scene/billboard.hpp | 11 +- src/scene/camera.cpp | 2 +- src/scene/camera.hpp | 16 +- src/scene/model-instance.cpp | 16 +- src/scene/model-instance.hpp | 25 ++- src/scene/object.hpp | 7 +- src/scene/text.cpp | 5 +- src/scene/text.hpp | 10 +- src/ui/ui.hpp | 2 + 80 files changed, 666 insertions(+), 804 deletions(-) delete mode 100644 src/entity/systems/ui.cpp delete mode 100644 src/entity/systems/ui.hpp rename src/{renderer => render}/compositor.cpp (83%) rename src/{renderer => render}/compositor.hpp (69%) rename src/{renderer => render}/context.hpp (100%) rename src/{renderer => render}/material-flags.hpp (100%) rename src/{renderer => render}/material-property.cpp (93%) rename src/{renderer => render}/material-property.hpp (98%) rename src/{renderer => render}/material.cpp (97%) rename src/{renderer => render}/material.hpp (93%) rename src/{renderer => render}/model.cpp (97%) rename src/{renderer => render}/model.hpp (92%) rename src/{renderer => render}/operation.hpp (99%) rename src/{renderer/render-pass.cpp => render/pass.cpp} (81%) rename src/{renderer/render-pass.hpp => render/pass.hpp} (82%) rename src/{renderer => render}/passes/bloom-pass.cpp (97%) rename src/{renderer => render}/passes/bloom-pass.hpp (90%) rename src/{renderer => render}/passes/clear-pass.cpp (95%) rename src/{renderer => render}/passes/clear-pass.hpp (68%) rename src/{renderer => render}/passes/final-pass.cpp (95%) rename src/{renderer => render}/passes/final-pass.hpp (89%) rename src/{renderer => render}/passes/material-pass.cpp (98%) rename src/{renderer => render}/passes/material-pass.hpp (93%) rename src/{renderer => render}/passes/outline-pass.cpp (92%) rename src/{renderer => render}/passes/outline-pass.hpp (87%) rename src/{renderer => render}/passes/shadow-map-pass.cpp (97%) rename src/{renderer => render}/passes/shadow-map-pass.hpp (92%) rename src/{renderer/simple-render-pass.cpp => render/passes/simple-pass.cpp} (84%) rename src/{renderer/simple-render-pass.hpp => render/passes/simple-pass.hpp} (71%) rename src/{renderer => render}/passes/sky-pass.cpp (98%) rename src/{renderer => render}/passes/sky-pass.hpp (96%) rename src/{renderer => render}/passes/ui-pass.cpp (92%) rename src/{renderer => render}/passes/ui-pass.hpp (87%) rename src/{renderer => render}/queue.hpp (96%) create mode 100644 src/render/render.hpp rename src/{renderer => render}/renderer.cpp (98%) rename src/{renderer => render}/renderer.hpp (76%) rename src/{renderer => render}/shader-template.cpp (98%) rename src/{renderer => render}/shader-template.hpp (96%) rename src/{renderer => render}/vertex-attribute.hpp (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00b9acf..3bc5ed2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.7) + option(VERSION_STRING "Project version string" "0.0.0") project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX) diff --git a/src/animation/screen-transition.cpp b/src/animation/screen-transition.cpp index fd2ed7c..c1984cf 100644 --- a/src/animation/screen-transition.cpp +++ b/src/animation/screen-transition.cpp @@ -18,7 +18,7 @@ */ #include "screen-transition.hpp" -#include "renderer/material-flags.hpp" +#include "render/material-flags.hpp" #include screen_transition::screen_transition() diff --git a/src/animation/screen-transition.hpp b/src/animation/screen-transition.hpp index 75b150a..52d1d42 100644 --- a/src/animation/screen-transition.hpp +++ b/src/animation/screen-transition.hpp @@ -21,8 +21,8 @@ #define ANTKEEPER_SCREEN_TRANSITION_HPP #include "animation/animation.hpp" -#include "renderer/material.hpp" -#include "renderer/material-property.hpp" +#include "render/material.hpp" +#include "render/material-property.hpp" #include "scene/billboard.hpp" /** @@ -36,13 +36,13 @@ public: void transition(float duration, bool reverse, animation::interpolator_type interpolator); scene::billboard* get_billboard(); - ::material* get_material(); + render::material* get_material(); ::animation* get_animation(); private: scene::billboard billboard; - ::material material; - material_property* progress; + render::material material; + render::material_property* progress; ::animation animation; ::animation::channel* channel; }; @@ -52,7 +52,7 @@ inline scene::billboard* screen_transition::get_billboard() return &billboard; } -inline material* screen_transition::get_material() +inline render::material* screen_transition::get_material() { return &material; } diff --git a/src/entity/components/model.hpp b/src/entity/components/model.hpp index eb40f02..3aac87a 100644 --- a/src/entity/components/model.hpp +++ b/src/entity/components/model.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP #define ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP -#include "renderer/model.hpp" +#include "render/model.hpp" #include namespace entity { @@ -28,8 +28,8 @@ namespace component { struct model { - ::model* render_model; - std::unordered_map materials; + render::model* render_model; + std::unordered_map materials; int instance_count; unsigned int layers; }; diff --git a/src/entity/components/terrain.hpp b/src/entity/components/terrain.hpp index 6e5a7bd..0ae6dfd 100644 --- a/src/entity/components/terrain.hpp +++ b/src/entity/components/terrain.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP #define ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP -#include "renderer/material.hpp" +#include "render/material.hpp" #include namespace entity { @@ -35,7 +35,7 @@ struct terrain std::size_t max_lod; /// Material for terrain patches; - material* patch_material; + render::material* patch_material; }; } // namespace component diff --git a/src/entity/systems/astronomy.cpp b/src/entity/systems/astronomy.cpp index f8753bc..cf2fd05 100644 --- a/src/entity/systems/astronomy.cpp +++ b/src/entity/systems/astronomy.cpp @@ -261,7 +261,7 @@ void astronomy::set_sun_light(scene::directional_light* light) sun_light = light; } -void astronomy::set_sky_pass(::sky_pass* pass) +void astronomy::set_sky_pass(::render::sky_pass* pass) { this->sky_pass = pass; } diff --git a/src/entity/systems/astronomy.hpp b/src/entity/systems/astronomy.hpp index a032795..445137f 100644 --- a/src/entity/systems/astronomy.hpp +++ b/src/entity/systems/astronomy.hpp @@ -25,7 +25,7 @@ #include "scene/directional-light.hpp" #include "utility/fundamental-types.hpp" #include "physics/frame.hpp" -#include "renderer/passes/sky-pass.hpp" +#include "render/passes/sky-pass.hpp" #include "entity/components/atmosphere.hpp" #include "entity/components/celestial-body.hpp" #include "entity/components/orbit.hpp" @@ -80,7 +80,7 @@ public: void set_sun_light(scene::directional_light* light); - void set_sky_pass(sky_pass* pass); + void set_sky_pass(::render::sky_pass* pass); private: void on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body); @@ -102,7 +102,7 @@ private: physics::frame ezs_to_sez; scene::directional_light* sun_light; - sky_pass* sky_pass; + ::render::sky_pass* sky_pass; }; } // namespace system diff --git a/src/entity/systems/painting.cpp b/src/entity/systems/painting.cpp index 9c6807b..5db2291 100644 --- a/src/entity/systems/painting.cpp +++ b/src/entity/systems/painting.cpp @@ -24,14 +24,14 @@ #include "event/event-dispatcher.hpp" #include "resources/resource-manager.hpp" #include "math/math.hpp" -#include "renderer/material.hpp" -#include "renderer/model.hpp" +#include "render/material.hpp" +#include "render/model.hpp" #include "utility/fundamental-types.hpp" #include "entity/commands.hpp" #include "entity/components/collision.hpp" #include "entity/components/transform.hpp" #include "gl/vertex-buffer.hpp" -#include "renderer/vertex-attribute.hpp" +#include "render/vertex-attribute.hpp" #include "geom/mesh-functions.hpp" #include diff --git a/src/entity/systems/painting.hpp b/src/entity/systems/painting.hpp index 9c58b28..20c822c 100644 --- a/src/entity/systems/painting.hpp +++ b/src/entity/systems/painting.hpp @@ -28,14 +28,12 @@ #include "scene/collection.hpp" #include "scene/model-instance.hpp" #include "gl/vertex-buffer.hpp" +#include "render/model.hpp" #include #include -class material; class event_dispatcher; class resource_manager; -class model; -class model_group; namespace entity { namespace system { @@ -82,8 +80,8 @@ private: std::size_t vertex_stride; std::size_t vertex_count; - model* stroke_model; - model_group* stroke_model_group; + ::render::model* stroke_model; + ::render::model_group* stroke_model_group; gl::vertex_buffer* stroke_vbo; bool midstroke; diff --git a/src/entity/systems/render.cpp b/src/entity/systems/render.cpp index 05ed2d0..77ae5ac 100644 --- a/src/entity/systems/render.cpp +++ b/src/entity/systems/render.cpp @@ -20,7 +20,6 @@ #include "render.hpp" #include "entity/components/transform.hpp" #include "entity/components/camera.hpp" -#include "renderer/renderer.hpp" #include "scene/point-light.hpp" #include "scene/directional-light.hpp" #include "scene/ambient-light.hpp" @@ -121,7 +120,7 @@ void render::remove_layers() layers.clear(); } -void render::set_renderer(::renderer* renderer) +void render::set_renderer(::render::renderer* renderer) { this->renderer = renderer; } diff --git a/src/entity/systems/render.hpp b/src/entity/systems/render.hpp index eb4a352..b777e92 100644 --- a/src/entity/systems/render.hpp +++ b/src/entity/systems/render.hpp @@ -27,11 +27,10 @@ #include "entity/components/model.hpp" #include "entity/components/light.hpp" #include "entity/id.hpp" +#include "render/renderer.hpp" #include #include -class renderer; - namespace entity { namespace system { @@ -47,7 +46,7 @@ public: void add_layer(scene::collection* layer); void remove_layers(); - void set_renderer(::renderer* renderer); + void set_renderer(::render::renderer* renderer); scene::model_instance* get_model_instance(entity::id entity_id); scene::light* get_light(entity::id entity_id); @@ -66,7 +65,7 @@ private: double t; double dt; - renderer* renderer; + ::render::renderer* renderer; std::vector layers; std::unordered_map model_instances; std::unordered_map lights; diff --git a/src/entity/systems/subterrain.cpp b/src/entity/systems/subterrain.cpp index b931f08..aa5cab7 100644 --- a/src/entity/systems/subterrain.cpp +++ b/src/entity/systems/subterrain.cpp @@ -21,10 +21,10 @@ #include "entity/components/model.hpp" #include "entity/components/cavity.hpp" #include "entity/id.hpp" -#include "renderer/model.hpp" -#include "renderer/material.hpp" +#include "render/model.hpp" +#include "render/material.hpp" #include "geom/mesh-functions.hpp" -#include "renderer/vertex-attribute.hpp" +#include "render/vertex-attribute.hpp" #include "gl/vertex-attribute.hpp" #include "gl/drawing-mode.hpp" #include "gl/vertex-buffer.hpp" @@ -195,22 +195,22 @@ subterrain::subterrain(entity::registry& registry, ::resource_manager* resource_ { // Load subterrain materials - subterrain_inside_material = resource_manager->load("subterrain-inside.mtl"); - subterrain_inside_material = resource_manager->load("subterrain-outside.mtl"); + subterrain_inside_material = resource_manager->load<::render::material>("subterrain-inside.mtl"); + subterrain_inside_material = resource_manager->load<::render::material>("subterrain-outside.mtl"); // Allocate subterrain model - subterrain_model = new model(); + subterrain_model = new ::render::model(); // Create inside model group subterrain_inside_group = subterrain_model->add_group("inside"); - subterrain_inside_group->set_material(resource_manager->load("subterrain-inside.mtl")); + subterrain_inside_group->set_material(resource_manager->load<::render::material>("subterrain-inside.mtl")); subterrain_inside_group->set_drawing_mode(gl::drawing_mode::triangles); subterrain_inside_group->set_start_index(0); subterrain_inside_group->set_index_count(0); // Create outside model group subterrain_outside_group = subterrain_model->add_group("outside"); - subterrain_outside_group->set_material(resource_manager->load("subterrain-outside.mtl")); + subterrain_outside_group->set_material(resource_manager->load<::render::material>("subterrain-outside.mtl")); subterrain_outside_group->set_drawing_mode(gl::drawing_mode::triangles); subterrain_outside_group->set_start_index(0); subterrain_outside_group->set_index_count(0); @@ -253,9 +253,9 @@ subterrain::subterrain(entity::registry& registry, ::resource_manager* resource_ attribute_offset += barycentric_attribute.components * sizeof(float); // Bind vertex attributes to VAO - vao->bind(render::vertex_attribute::position, position_attribute); - vao->bind(render::vertex_attribute::normal, normal_attribute); - vao->bind(render::vertex_attribute::barycentric, barycentric_attribute); + vao->bind(::render::vertex_attribute::position, position_attribute); + vao->bind(::render::vertex_attribute::normal, normal_attribute); + vao->bind(::render::vertex_attribute::barycentric, barycentric_attribute); // Calculate adjusted bounds to fit isosurface resolution //isosurface_resolution = 0.325f; diff --git a/src/entity/systems/subterrain.hpp b/src/entity/systems/subterrain.hpp index 0278d95..a32c1f3 100644 --- a/src/entity/systems/subterrain.hpp +++ b/src/entity/systems/subterrain.hpp @@ -25,13 +25,11 @@ #include "geom/aabb.hpp" #include "scene/collection.hpp" #include "scene/model-instance.hpp" +#include "render/model.hpp" #include "utility/fundamental-types.hpp" #include class resource_manager; -class model; -class model_group; -class material; namespace entity { namespace system { @@ -104,11 +102,11 @@ private: resource_manager* resource_manager; geom::mesh* subterrain_mesh; - model* subterrain_model; - material* subterrain_inside_material; - material* subterrain_outside_material; - model_group* subterrain_inside_group; - model_group* subterrain_outside_group; + ::render::model* subterrain_model; + ::render::material* subterrain_inside_material; + ::render::material* subterrain_outside_material; + ::render::model_group* subterrain_inside_group; + ::render::model_group* subterrain_outside_group; int subterrain_model_vertex_size; int subterrain_model_vertex_stride; geom::aabb subterrain_bounds; diff --git a/src/entity/systems/terrain.cpp b/src/entity/systems/terrain.cpp index 03faad6..27220c2 100644 --- a/src/entity/systems/terrain.cpp +++ b/src/entity/systems/terrain.cpp @@ -29,7 +29,7 @@ #include "gl/vertex-attribute.hpp" #include "math/constants.hpp" #include "math/quaternion-operators.hpp" -#include "renderer/vertex-attribute.hpp" +#include "render/vertex-attribute.hpp" #include "utility/fundamental-types.hpp" #include #include @@ -405,7 +405,7 @@ geom::mesh* terrain::generate_patch_mesh(std::uint8_t face_index, quadtree_node_ return patch_mesh; } -model* terrain::generate_patch_model(const geom::mesh& patch_mesh, material* patch_material) const +::render::model* terrain::generate_patch_model(const geom::mesh& patch_mesh, ::render::material* patch_material) const { // Barycentric coordinates static const float3 barycentric[3] = @@ -470,7 +470,7 @@ model* terrain::generate_patch_model(const geom::mesh& patch_mesh, material* pat std::size_t patch_triangle_count = patch_mesh.get_faces().size(); // Allocate patch model - model* patch_model = new model(); + ::render::model* patch_model = new ::render::model(); // Get model VBO and VAO gl::vertex_buffer* vbo = patch_model->get_vertex_buffer(); @@ -536,15 +536,15 @@ model* terrain::generate_patch_model(const geom::mesh& patch_mesh, material* pat attribute_offset += target_attribute.components * sizeof(float); // Bind vertex attributes to VAO - vao->bind(render::vertex_attribute::position, position_attribute); - vao->bind(render::vertex_attribute::uv, uv_attribute); - vao->bind(render::vertex_attribute::normal, normal_attribute); - vao->bind(render::vertex_attribute::tangent, tangent_attribute); - vao->bind(render::vertex_attribute::barycentric, barycentric_attribute); - vao->bind(render::vertex_attribute::target, target_attribute); + vao->bind(::render::vertex_attribute::position, position_attribute); + vao->bind(::render::vertex_attribute::uv, uv_attribute); + vao->bind(::render::vertex_attribute::normal, normal_attribute); + vao->bind(::render::vertex_attribute::tangent, tangent_attribute); + vao->bind(::render::vertex_attribute::barycentric, barycentric_attribute); + vao->bind(::render::vertex_attribute::target, target_attribute); // Create model group - model_group* patch_model_group = patch_model->add_group("terrain"); + ::render::model_group* patch_model_group = patch_model->add_group("terrain"); patch_model_group->set_material(patch_material); patch_model_group->set_drawing_mode(gl::drawing_mode::triangles); patch_model_group->set_start_index(0); diff --git a/src/entity/systems/terrain.hpp b/src/entity/systems/terrain.hpp index 062fd1a..8d89631 100644 --- a/src/entity/systems/terrain.hpp +++ b/src/entity/systems/terrain.hpp @@ -27,8 +27,8 @@ #include "geom/quadtree.hpp" #include "geom/mesh.hpp" #include "utility/fundamental-types.hpp" -#include "renderer/model.hpp" -#include "renderer/material.hpp" +#include "render/model.hpp" +#include "render/material.hpp" #include "scene/model-instance.hpp" #include "scene/collection.hpp" #include @@ -75,7 +75,7 @@ private: struct terrain_patch { geom::mesh* mesh; - model* model; + ::render::model* model; scene::model_instance* model_instance; float error; float morph; @@ -112,7 +112,7 @@ private: /** * Generates a model for a terrain patch given the patch's mesh. */ - model* generate_patch_model(const geom::mesh& patch_mesh, material* patch_material) const; + ::render::model* generate_patch_model(const geom::mesh& patch_mesh, ::render::material* patch_material) const; diff --git a/src/entity/systems/ui.cpp b/src/entity/systems/ui.cpp deleted file mode 100644 index c78ee51..0000000 --- a/src/entity/systems/ui.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "ui.hpp" -#include "resources/resource-manager.hpp" - -namespace entity { -namespace system { - -ui::ui(::resource_manager* resource_manager): - resource_manager(resource_manager), - tool_menu_control(nullptr), - camera(nullptr), - scene_collection(nullptr) -{ - // Setup lighting - indirect_light.set_intensity(0.25f); - indirect_light.update_tweens(); - direct_light.look_at({-0.1f, 0.0f, 1.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}); - direct_light.set_intensity(1.0f); - direct_light.update_tweens(); - - // Setup modal background - modal_bg_material.set_shader_program(resource_manager->load("ui-element-untextured.glsl")); - modal_bg_material.set_flags(1); - modal_bg_material.add_property("tint")->set_value({0, 0, 0, 0.25f}); - modal_bg.set_material(&modal_bg_material); - modal_bg.set_translation({0, 0, -10.0f}); - - // Setup tool selector background - tool_selector_bg.set_material(resource_manager->load("tool-selector.mtl")); - tool_selector_bg.set_translation({0, 0, -4.0f}); - tool_selector_bg.set_scale({270, 270, 270}); - - // Setup scene - //scene.add_object(&camera); - //scene.add_object(&indirect_light); - //scene.add_object(&direct_light); -} - -void ui::update(float dt) -{} - -void ui::set_viewport(const float4& viewport) -{ - this->viewport = viewport; - - // Calculate viewport center - viewport_center[0] = (viewport[2] - viewport[0]) * 0.5f; - viewport_center[1] = (viewport[3] - viewport[1]) * 0.5f; - - - // Resize modal BG - modal_bg.set_scale({viewport[2] * 0.5f, viewport[3] * 0.5f, 1.0f}); - modal_bg.update_tweens(); - - update_projection(); -} - -void ui::set_tool_menu_control(input::control* control) -{ - tool_menu_control = control; - - if (tool_menu_control) - { - tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this)); - tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this)); - } -} - -void ui::set_camera(scene::camera* camera) -{ - this->camera = camera; - - if (camera) - { - camera->look_at({0.0f, 0.0f, 500.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}); - update_projection(); - } -} - -void ui::set_scene(scene::collection* collection) -{ - this->scene_collection = collection; -} - -void ui::handle_event(const mouse_moved_event& event) -{ - if (tool_menu_control && tool_menu_control->is_active()) - { - tool_selection_vector.x += event.dx; - tool_selection_vector.y += event.dy; - - float max_length = 200.0f; - float selection_threshold = 20.0f; - int sector_count = 6; - float sector_angle = math::two_pi / static_cast(sector_count); - - float length_squared = math::length_squared(tool_selection_vector); - - // Select tool if length of selection vector within threshold - if (length_squared >= selection_threshold * selection_threshold) - { - // Limit length of tool selection vector - if (length_squared > max_length * max_length) - { - tool_selection_vector = (tool_selection_vector / std::sqrt(length_squared)) * max_length; - } - - float2 selection_direction = tool_selection_vector / std::sqrt(length_squared); - float selection_angle = std::atan2(-selection_direction.y, selection_direction.x) - math::radians(90.0f); - selection_angle = (selection_angle >= 0.0f ? selection_angle : (math::two_pi + selection_angle)); - - int sector = static_cast((selection_angle + sector_angle * 0.5f) / sector_angle) % sector_count; - - float rotation_angle = static_cast(sector) * sector_angle; - tool_selector_bg.set_rotation(math::angle_axis(rotation_angle, {0, 0, 1})); - tool_selector_bg.update_tweens(); - - } - } - - mouse_position[0] = event.x; - mouse_position[1] = event.y; -} - -void ui::handle_event(const window_resized_event& event) -{ - set_viewport({0.0f, 0.0f, static_cast(event.w), static_cast(event.h)}); -} - -void ui::update_projection() -{ - if (camera) - { - float clip_left = -viewport[2] * 0.5f; - float clip_right = viewport[2] * 0.5f; - float clip_top = -viewport[3] * 0.5f; - float clip_bottom = viewport[3] * 0.5f; - float clip_near = 0.0f; - float clip_far = 1000.0f; - camera->set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far); - } -} - -void ui::open_tool_menu() -{ - if (scene_collection) - { - scene_collection->add_object(&modal_bg); - scene_collection->add_object(&tool_selector_bg); - } - tool_selection_vector = {0, 0}; -} - -void ui::close_tool_menu() -{ - if (scene_collection) - { - scene_collection->remove_object(&modal_bg); - scene_collection->remove_object(&tool_selector_bg); - } -} - -void ui::open_elevator_menu() -{ - -} - -void ui::close_elevator_menu() -{ - -} - -} // namespace system -} // namespace entity diff --git a/src/entity/systems/ui.hpp b/src/entity/systems/ui.hpp deleted file mode 100644 index 2a96ff5..0000000 --- a/src/entity/systems/ui.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_ENTITY_SYSTEM_UI_HPP -#define ANTKEEPER_ENTITY_SYSTEM_UI_HPP - -#include "event/event-handler.hpp" -#include "event/input-events.hpp" -#include "event/window-events.hpp" -#include "scene/collection.hpp" -#include "scene/camera.hpp" -#include "scene/directional-light.hpp" -#include "scene/ambient-light.hpp" -#include "scene/model-instance.hpp" -#include "scene/billboard.hpp" -#include "renderer/material.hpp" -#include "math/math.hpp" -#include "input/control.hpp" - -class resource_manager; - -namespace entity { -namespace system { - -class ui: - public event_handler, - public event_handler -{ -public: - ui(::resource_manager* resource_manager); - - void update(float dt); - - void set_viewport(const float4& viewport); - void set_tool_menu_control(input::control* control); - - void set_camera(scene::camera* camera); - void set_scene(scene::collection* collection); - -private: - virtual void handle_event(const mouse_moved_event& event); - virtual void handle_event(const window_resized_event& event); - - void update_projection(); - - void open_tool_menu(); - void close_tool_menu(); - - void open_elevator_menu(); - void close_elevator_menu(); - - resource_manager* resource_manager; - scene::collection* scene_collection; - scene::camera* camera; - scene::ambient_light indirect_light; - scene::directional_light direct_light; - scene::billboard tool_selector_bg; - material modal_bg_material; - scene::billboard modal_bg; - - scene::billboard underground_bg; - - float2 mouse_position; - float4 viewport; - float2 viewport_center; - float2 tool_selection_vector; - input::control* tool_menu_control; -}; - -} // namespace system -} // namespace entity - -#endif // ANTKEEPER_ENTITY_SYSTEM_UI_HPP diff --git a/src/entity/systems/vegetation.cpp b/src/entity/systems/vegetation.cpp index cacb96e..c3c7ae9 100644 --- a/src/entity/systems/vegetation.cpp +++ b/src/entity/systems/vegetation.cpp @@ -23,7 +23,7 @@ #include "scene/model-instance.hpp" #include "scene/lod-group.hpp" #include "scene/collection.hpp" -#include "renderer/material.hpp" +#include "render/material.hpp" #include "geom/aabb.hpp" #include "utility/fundamental-types.hpp" #include diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index ba10f52..1135405 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -37,19 +37,19 @@ #include "gl/vertex-array.hpp" #include "gl/vertex-attribute.hpp" #include "gl/vertex-buffer.hpp" -#include "renderer/material-flags.hpp" -#include "renderer/material-property.hpp" -#include "renderer/passes/bloom-pass.hpp" -#include "renderer/passes/clear-pass.hpp" -#include "renderer/passes/final-pass.hpp" -#include "renderer/passes/material-pass.hpp" -#include "renderer/passes/outline-pass.hpp" -#include "renderer/passes/shadow-map-pass.hpp" -#include "renderer/passes/sky-pass.hpp" -#include "renderer/simple-render-pass.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/compositor.hpp" -#include "renderer/renderer.hpp" +#include "render/material-flags.hpp" +#include "render/material-property.hpp" +#include "render/passes/bloom-pass.hpp" +#include "render/passes/clear-pass.hpp" +#include "render/passes/final-pass.hpp" +#include "render/passes/material-pass.hpp" +#include "render/passes/outline-pass.hpp" +#include "render/passes/shadow-map-pass.hpp" +#include "render/passes/sky-pass.hpp" +#include "render/passes/simple-pass.hpp" +#include "render/vertex-attribute.hpp" +#include "render/compositor.hpp" +#include "render/renderer.hpp" #include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp" #include "scene/scene.hpp" @@ -64,7 +64,6 @@ #include "entity/systems/samara.hpp" #include "entity/systems/subterrain.hpp" #include "entity/systems/terrain.hpp" -#include "entity/systems/ui.hpp" #include "entity/systems/vegetation.hpp" #include "entity/systems/spatial.hpp" #include "entity/systems/painting.hpp" @@ -498,16 +497,16 @@ void setup_rendering(game::context* ctx) gl::texture_2d* blue_noise_map = ctx->resource_manager->load("blue-noise.tex"); // Load fallback material - ctx->fallback_material = ctx->resource_manager->load("fallback.mtl"); + ctx->fallback_material = ctx->resource_manager->load("fallback.mtl"); // Setup common render passes { - ctx->common_bloom_pass = new bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager); + ctx->common_bloom_pass = new render::bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager); ctx->common_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color); ctx->common_bloom_pass->set_brightness_threshold(1.0f); ctx->common_bloom_pass->set_blur_iterations(5); - ctx->common_final_pass = new ::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); + ctx->common_final_pass = new render::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); ctx->common_final_pass->set_color_texture(ctx->framebuffer_hdr_color); ctx->common_final_pass->set_bloom_texture(ctx->bloom_texture); ctx->common_final_pass->set_blue_noise_texture(blue_noise_map); @@ -515,30 +514,30 @@ void setup_rendering(game::context* ctx) // Setup UI compositor { - ctx->ui_clear_pass = new clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer()); + ctx->ui_clear_pass = new render::clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer()); ctx->ui_clear_pass->set_cleared_buffers(false, true, false); ctx->ui_clear_pass->set_clear_depth(0.0f); - ctx->ui_material_pass = new material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); + ctx->ui_material_pass = new render::material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); ctx->ui_material_pass->set_fallback_material(ctx->fallback_material); - ctx->ui_compositor = new compositor(); + ctx->ui_compositor = new render::compositor(); ctx->ui_compositor->add_pass(ctx->ui_clear_pass); ctx->ui_compositor->add_pass(ctx->ui_material_pass); } // Setup underground compositor { - ctx->underground_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr); + ctx->underground_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->framebuffer_hdr); ctx->underground_clear_pass->set_cleared_buffers(true, true, false); ctx->underground_clear_pass->set_clear_color({1, 0, 1, 0}); ctx->underground_clear_pass->set_clear_depth(0.0f); - ctx->underground_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); + ctx->underground_material_pass = new render::material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->underground_material_pass->set_fallback_material(ctx->fallback_material); ctx->app->get_event_dispatcher()->subscribe(ctx->underground_material_pass); - ctx->underground_compositor = new compositor(); + ctx->underground_compositor = new render::compositor(); ctx->underground_compositor->add_pass(ctx->underground_clear_pass); ctx->underground_compositor->add_pass(ctx->underground_material_pass); ctx->underground_compositor->add_pass(ctx->common_bloom_pass); @@ -547,31 +546,31 @@ void setup_rendering(game::context* ctx) // Setup surface compositor { - ctx->surface_shadow_map_clear_pass = new clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer); + ctx->surface_shadow_map_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer); ctx->surface_shadow_map_clear_pass->set_cleared_buffers(false, true, false); ctx->surface_shadow_map_clear_pass->set_clear_depth(1.0f); - ctx->surface_shadow_map_pass = new shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager); + ctx->surface_shadow_map_pass = new render::shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager); ctx->surface_shadow_map_pass->set_split_scheme_weight(0.75f); - ctx->surface_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr); + ctx->surface_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->framebuffer_hdr); ctx->surface_clear_pass->set_cleared_buffers(true, true, true); ctx->surface_clear_pass->set_clear_depth(0.0f); - ctx->surface_sky_pass = new sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); + ctx->surface_sky_pass = new render::sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->app->get_event_dispatcher()->subscribe(ctx->surface_sky_pass); - ctx->surface_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); + ctx->surface_material_pass = new render::material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->surface_material_pass->set_fallback_material(ctx->fallback_material); ctx->surface_material_pass->shadow_map_pass = ctx->surface_shadow_map_pass; ctx->surface_material_pass->shadow_map = ctx->shadow_map_depth_texture; ctx->app->get_event_dispatcher()->subscribe(ctx->surface_material_pass); - ctx->surface_outline_pass = new outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); + ctx->surface_outline_pass = new render::outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->surface_outline_pass->set_outline_width(0.25f); ctx->surface_outline_pass->set_outline_color(float4{1.0f, 1.0f, 1.0f, 1.0f}); - ctx->surface_compositor = new compositor(); + ctx->surface_compositor = new render::compositor(); ctx->surface_compositor->add_pass(ctx->surface_shadow_map_clear_pass); ctx->surface_compositor->add_pass(ctx->surface_shadow_map_pass); ctx->surface_compositor->add_pass(ctx->surface_clear_pass); @@ -637,7 +636,7 @@ void setup_rendering(game::context* ctx) } // Create renderer - ctx->renderer = new renderer(); + ctx->renderer = new render::renderer(); ctx->renderer->set_billboard_vao(ctx->billboard_vao); logger->pop_task(EXIT_SUCCESS); @@ -659,6 +658,14 @@ void setup_scenes(game::context* ctx) // Setup UI camera ctx->ui_camera = new scene::camera(); ctx->ui_camera->set_compositor(ctx->ui_compositor); + auto viewport = ctx->app->get_viewport_dimensions(); + float clip_left = -viewport[0] * 0.5f; + float clip_right = viewport[0] * 0.5f; + float clip_top = -viewport[1] * 0.5f; + float clip_bottom = viewport[1] * 0.5f; + float clip_near = 0.0f; + float clip_far = 1000.0f; + ctx->ui_camera->set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far); // Setup underground camera ctx->underground_camera = new scene::camera(); @@ -680,7 +687,7 @@ void setup_scenes(game::context* ctx) const gl::texture_2d* splash_texture = ctx->resource_manager->load("splash.tex"); auto splash_dimensions = splash_texture->get_dimensions(); - ctx->splash_billboard_material = new material(); + ctx->splash_billboard_material = new render::material(); ctx->splash_billboard_material->set_shader_program(ctx->resource_manager->load("ui-element-textured.glsl")); ctx->splash_billboard_material->add_property("background")->set_value(splash_texture); ctx->splash_billboard_material->add_property("tint")->set_value(float4{1, 1, 1, 1}); @@ -693,7 +700,7 @@ void setup_scenes(game::context* ctx) // Create camera flash billboard - material* flash_material = new material(); + render::material* flash_material = new render::material(); flash_material->set_shader_program(ctx->resource_manager->load("ui-element-untextured.glsl")); auto flash_tint = flash_material->add_property("tint"); flash_tint->set_value(float4{1, 1, 1, 1}); @@ -895,14 +902,6 @@ void setup_systems(game::context* ctx) ctx->render_system->add_layer(ctx->surface_scene); ctx->render_system->add_layer(ctx->ui_scene); ctx->render_system->set_renderer(ctx->renderer); - - // Setup UI system - ctx->ui_system = new entity::system::ui(ctx->resource_manager); - ctx->ui_system->set_camera(ctx->ui_camera); - ctx->ui_system->set_scene(ctx->ui_scene); - ctx->ui_system->set_viewport(viewport); - event_dispatcher->subscribe(ctx->ui_system); - event_dispatcher->subscribe(ctx->ui_system); } void setup_controls(game::context* ctx) @@ -988,7 +987,6 @@ void setup_callbacks(game::context* ctx) ctx->painting_system->update(t, dt); ctx->proteome_system->update(t, dt); - ctx->ui_system->update(dt); ctx->render_system->update(t, dt); ctx->animator->animate(dt); } diff --git a/src/game/context.hpp b/src/game/context.hpp index 8f68d5f..f74ec0e 100644 --- a/src/game/context.hpp +++ b/src/game/context.hpp @@ -45,27 +45,19 @@ #include #include "resources/json.hpp" #include "type/typeface.hpp" +#include "type/bitmap-font.hpp" +#include "render/material.hpp" +#include "render/material-property.hpp" // Forward declarations class animator; class application; -class bloom_pass; -class clear_pass; -class compositor; -class final_pass; -class material; -class material_pass; + class resource_manager; class screen_transition; -class shadow_map_pass; -class simple_render_pass; -class sky_pass; class timeline; -class renderer; -class outline_pass; template class animation; -template class material_property; namespace debug { @@ -80,7 +72,6 @@ namespace entity class subterrain; class terrain; class vegetation; - class ui; class spatial; class painting; class astronomy; @@ -100,6 +91,20 @@ namespace entity } } +namespace render +{ + class bloom_pass; + class clear_pass; + class compositor; + class final_pass; + class material_pass; + class renderer; + class outline_pass; + class shadow_map_pass; + class simple_render_pass; + class sky_pass; +} + namespace game { /// Structure containing the state of a game. @@ -141,6 +146,12 @@ struct context string_table_map string_table_map; std::unordered_map* strings; std::unordered_map typefaces; + type::bitmap_font debug_font; + type::bitmap_font menu_font; + type::bitmap_font title_font; + render::material debug_font_material; + render::material menu_font_material; + render::material title_font_material; // Framebuffers gl::framebuffer* shadow_map_framebuffer; @@ -153,31 +164,31 @@ struct context // Rendering gl::rasterizer* rasterizer; - renderer* renderer; + render::renderer* renderer; gl::vertex_buffer* billboard_vbo; gl::vertex_array* billboard_vao; - material* fallback_material; - material* splash_billboard_material; + render::material* fallback_material; + render::material* splash_billboard_material; // Compositing - clear_pass* ui_clear_pass; - material_pass* ui_material_pass; - compositor* ui_compositor; + render::clear_pass* ui_clear_pass; + render::material_pass* ui_material_pass; + render::compositor* ui_compositor; - bloom_pass* common_bloom_pass; - final_pass* common_final_pass; + render::bloom_pass* common_bloom_pass; + render::final_pass* common_final_pass; - clear_pass* underground_clear_pass; - material_pass* underground_material_pass; - compositor* underground_compositor; + render::clear_pass* underground_clear_pass; + render::material_pass* underground_material_pass; + render::compositor* underground_compositor; - clear_pass* surface_shadow_map_clear_pass; - shadow_map_pass* surface_shadow_map_pass; - clear_pass* surface_clear_pass; - sky_pass* surface_sky_pass; - material_pass* surface_material_pass; - outline_pass* surface_outline_pass; - compositor* surface_compositor; + render::clear_pass* surface_shadow_map_clear_pass; + render::shadow_map_pass* surface_shadow_map_pass; + render::clear_pass* surface_clear_pass; + render::sky_pass* surface_sky_pass; + render::material_pass* surface_material_pass; + render::outline_pass* surface_outline_pass; + render::compositor* surface_compositor; // Scene utilities scene::collection* active_scene; @@ -205,7 +216,7 @@ struct context animation* radial_transition_in; animation* radial_transition_out; screen_transition* fade_transition; - material_property* fade_transition_color; + render::material_property* fade_transition_color; screen_transition* radial_transition_inner; screen_transition* radial_transition_outer; animation* equip_tool_animation; @@ -237,7 +248,6 @@ struct context entity::system::samara* samara_system; entity::system::subterrain* subterrain_system; entity::system::terrain* terrain_system; - entity::system::ui* ui_system; entity::system::vegetation* vegetation_system; entity::system::spatial* spatial_system; entity::system::painting* painting_system; diff --git a/src/game/states/brood.cpp b/src/game/states/brood.cpp index 513ec4a..bba854c 100644 --- a/src/game/states/brood.cpp +++ b/src/game/states/brood.cpp @@ -31,7 +31,7 @@ #include "animation/screen-transition.hpp" #include "animation/ease.hpp" #include "resources/resource-manager.hpp" -#include "renderer/passes/sky-pass.hpp" +#include "render/passes/sky-pass.hpp" #include "application.hpp" #include diff --git a/src/game/states/forage.cpp b/src/game/states/forage.cpp index c9ea1aa..dc7be3b 100644 --- a/src/game/states/forage.cpp +++ b/src/game/states/forage.cpp @@ -56,7 +56,7 @@ void enter(game::context* ctx) // Create biome terrain component entity::component::terrain biome_terrain; biome_terrain.max_lod = 18; - biome_terrain.patch_material = ctx->resource_manager->load("desert-terrain.mtl"); + biome_terrain.patch_material = ctx->resource_manager->load("desert-terrain.mtl"); biome_terrain.elevation = [](double, double) -> double { return 0.0; diff --git a/src/game/states/loading.cpp b/src/game/states/loading.cpp index a2ba84c..c7d7485 100644 --- a/src/game/states/loading.cpp +++ b/src/game/states/loading.cpp @@ -42,15 +42,16 @@ #include "gl/vertex-buffer.hpp" #include "physics/light/photometry.hpp" #include "physics/orbit/orbit.hpp" -#include "renderer/material.hpp" -#include "renderer/model.hpp" -#include "renderer/passes/shadow-map-pass.hpp" -#include "renderer/vertex-attribute.hpp" +#include "render/material.hpp" +#include "render/model.hpp" +#include "render/passes/shadow-map-pass.hpp" +#include "render/vertex-attribute.hpp" #include "resources/resource-manager.hpp" #include "scene/ambient-light.hpp" #include "scene/directional-light.hpp" #include "utility/timestamp.hpp" #include "type/type.hpp" +#include "configuration.hpp" #include #include #include @@ -58,7 +59,7 @@ #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" #include "scene/text.hpp" -#include "renderer/material-flags.hpp" +#include "render/material-flags.hpp" namespace game { namespace state { @@ -235,6 +236,43 @@ void load_controls(game::context* ctx) ctx->controls["menu_right"]->set_activation_threshold(menu_activation_threshold); } +static void build_bitmap_font(const type::typeface& typeface, float size, const std::unordered_set& charset, type::bitmap_font& font, render::material& material, gl::shader_program* shader_program) +{ + // Get font metrics for given size + if (type::font_metrics metrics; typeface.get_metrics(size, metrics)) + font.set_font_metrics(metrics); + + // Format font bitmap + image& font_bitmap = font.get_bitmap(); + font_bitmap.format(sizeof(std::byte), 1); + + // For each UTF-32 character code in the character set + for (char32_t code: charset) + { + // Skip missing glyphs + if (!typeface.has_glyph(code)) + continue; + + // Add glyph to font + type::bitmap_glyph& glyph = font[code]; + typeface.get_metrics(size, code, glyph.metrics); + typeface.get_bitmap(size, code, glyph.bitmap); + } + + // Pack glyph bitmaps into the font bitmap + font.pack(); + + // Create font texture from bitmap + gl::texture_2d* font_texture = new gl::texture_2d(font_bitmap.get_width(), font_bitmap.get_height(), gl::pixel_type::uint_8, gl::pixel_format::r, gl::color_space::linear, font_bitmap.get_pixels()); + font_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend); + font_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear); + + // Create font material + material.set_flags(MATERIAL_FLAG_TRANSLUCENT); + material.add_property("font_bitmap")->set_value(font_texture); + material.set_shader_program(shader_program); +} + void load_fonts(game::context* ctx) { // Load typefaces @@ -265,65 +303,56 @@ void load_fonts(game::context* ctx) } } - // Build bitmap fonts + // Load bitmap font shader + gl::shader_program* bitmap_font_shader = ctx->resource_manager->load("bitmap-font.glsl"); + + // Build debug font + if (auto it = ctx->typefaces.find("monospace"); it != ctx->typefaces.end()) + { + build_bitmap_font(*it->second, 22.0f, charset, ctx->debug_font, ctx->debug_font_material, bitmap_font_shader); + } + + // Build menu font if (auto it = ctx->typefaces.find("sans_serif"); it != ctx->typefaces.end()) { - type::typeface* typeface = it->second; - type::bitmap_font* font = new type::bitmap_font(); - - // Get font metrics - const float size = 28.0f; - if (type::font_metrics metrics; typeface->get_metrics(size, metrics)) - font->set_font_metrics(metrics); - - // Format font bitmap - image& font_bitmap = font->get_bitmap(); - font_bitmap.format(sizeof(unsigned char), 1); - - // For each UTF-32 character code in the character set - for (char32_t code: charset) - { - if (!typeface->has_glyph(code)) - continue; - - type::bitmap_glyph& glyph = (*font)[code]; - typeface->get_metrics(size, code, glyph.metrics); - typeface->get_bitmap(size, code, glyph.bitmap); - } - - // Pack glyph bitmaps into the font bitmap - font->pack(); - - // Create font texture from bitmap - gl::texture_2d* font_texture = new gl::texture_2d(font_bitmap.get_width(), font_bitmap.get_height(), gl::pixel_type::uint_8, gl::pixel_format::r, gl::color_space::linear, font_bitmap.get_pixels()); - font_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend); - font_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear); - - // Create font material - material* font_material = new material(); - font_material->set_flags(MATERIAL_FLAG_TRANSLUCENT); - font_material->add_property("font_bitmap")->set_value(font_texture); - font_material->set_shader_program(ctx->resource_manager->load("bitmap-font.glsl")); - - // Create text scene object - scene::text* text_object = new scene::text(); - text_object->set_material(font_material); - text_object->set_font(font); - text_object->set_color({1.0f, 1.0f, 1.0f, 1.0f}); - //text_object->set_content("Hello, World!"); - - if (auto it = ctx->strings->find("continue"); it != ctx->strings->end()) - text_object->set_content(it->second); - - // Add text object to UI scene - ctx->ui_scene->add_object(text_object); - - // Center text object - const auto& text_aabb = static_cast&>(text_object->get_local_bounds()); - float text_w = text_aabb.max_point.x - text_aabb.min_point.x; - float text_h = text_aabb.max_point.y - text_aabb.min_point.y; - text_object->set_translation({std::round(-text_w * 0.5f), std::round(-text_h * 0.5f), 0.0f}); + build_bitmap_font(*it->second, 28.0f, charset, ctx->menu_font, ctx->menu_font_material, bitmap_font_shader); } + + // Build title font + if (auto it = ctx->typefaces.find("serif"); it != ctx->typefaces.end()) + { + build_bitmap_font(*it->second, 96.0f, charset, ctx->title_font, ctx->title_font_material, bitmap_font_shader); + } + + // Create title text + scene::text* title_text = new scene::text(); + title_text->set_material(&ctx->title_font_material); + title_text->set_font(&ctx->title_font); + title_text->set_color({1.0f, 1.0f, 1.0f, 1.0f}); + title_text->set_content((*ctx->strings)["title"]); + ctx->ui_scene->add_object(title_text); + + // Align title text + const auto& title_aabb = static_cast&>(title_text->get_local_bounds()); + float title_w = title_aabb.max_point.x - title_aabb.min_point.x; + float title_h = title_aabb.max_point.y - title_aabb.min_point.y; + title_text->set_translation({std::round(-title_w * 0.5f), std::round(-title_h * 0.5f), 0.0f}); + + // Create version string text + scene::text* version_text = new scene::text(); + version_text->set_material(&ctx->debug_font_material); + version_text->set_font(&ctx->debug_font); + version_text->set_color({1.0f, 1.0f, 1.0f, 1.0f}); + version_text->set_content(ANTKEEPER_VERSION_STRING); + ctx->ui_scene->add_object(version_text); + + // Align version string + const auto& version_aabb = static_cast&>(version_text->get_local_bounds()); + float version_w = version_aabb.max_point.x - version_aabb.min_point.x; + float version_h = version_aabb.max_point.y - version_aabb.min_point.y; + const float version_padding = 12.0f; + auto viewport = ctx->app->get_viewport_dimensions(); + version_text->set_translation({viewport[0] * 0.5f - version_w - version_padding, -viewport[1] * 0.5f + version_padding, 0.0f}); } void cosmogenesis(game::context* ctx) @@ -446,7 +475,7 @@ void planetogenesis(game::context* ctx) ctx->astronomy_system->set_reference_body(planet_eid); // Load sky model - ctx->surface_sky_pass->set_sky_model(ctx->resource_manager->load("sky-dome.mdl")); + ctx->surface_sky_pass->set_sky_model(ctx->resource_manager->load("sky-dome.mdl")); } void selenogenesis(game::context* ctx) @@ -456,7 +485,7 @@ void selenogenesis(game::context* ctx) ctx->entities["moon"] = moon_eid; // Pass moon model to sky pass - ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load("moon.mdl")); + ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load("moon.mdl")); } void extrasolar_heliogenesis(game::context* ctx) @@ -539,7 +568,7 @@ void extrasolar_heliogenesis(game::context* ctx) ctx->resource_manager->unload("stars.csv"); // Allocate stars model - model* stars_model = new model(); + render::model* stars_model = new render::model(); // Get model VBO and VAO gl::vertex_buffer* vbo = stars_model->get_vertex_buffer(); @@ -576,10 +605,10 @@ void extrasolar_heliogenesis(game::context* ctx) vao->bind(render::vertex_attribute::color, color_attribute); // Load star material - material* star_material = ctx->resource_manager->load("fixed-star.mtl"); + render::material* star_material = ctx->resource_manager->load("fixed-star.mtl"); // Create model group - model_group* stars_model_group = stars_model->add_group("stars"); + render::model_group* stars_model_group = stars_model->add_group("stars"); stars_model_group->set_material(star_material); stars_model_group->set_drawing_mode(gl::drawing_mode::points); stars_model_group->set_start_index(0); diff --git a/src/game/states/nuptial-flight.cpp b/src/game/states/nuptial-flight.cpp index 2ba04ff..dbc56a1 100644 --- a/src/game/states/nuptial-flight.cpp +++ b/src/game/states/nuptial-flight.cpp @@ -26,7 +26,6 @@ #include "entity/components/transform.hpp" #include "entity/components/terrain.hpp" #include "entity/commands.hpp" -#include "renderer/material-property.hpp" #include "animation/screen-transition.hpp" #include "animation/ease.hpp" #include "resources/resource-manager.hpp" @@ -49,7 +48,7 @@ void enter(game::context* ctx) ctx->entity_registry->remove(planet_eid); // Enable clouds in sky pass - ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load("cloud-plane.mdl")); + ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load("cloud-plane.mdl")); // Create observer entity::id observer_eid = ctx->entity_registry->create(); diff --git a/src/game/tools.cpp b/src/game/tools.cpp index c283051..67d2b6e 100644 --- a/src/game/tools.cpp +++ b/src/game/tools.cpp @@ -24,7 +24,7 @@ #include "entity/components/tool.hpp" #include "entity/components/celestial-body.hpp" #include "utility/timestamp.hpp" -#include "renderer/material.hpp" +#include "render/material.hpp" namespace game { @@ -45,7 +45,7 @@ entity::id build_camera_tool(game::context* ctx) std::string path = ctx->screenshots_path + "antkeeper-" + timestamp() + ".png"; ctx->app->save_frame(path); - material_property* tint = static_cast*>(ctx->camera_flash_billboard->get_material()->get_property("tint")); + render::material_property* tint = static_cast*>(ctx->camera_flash_billboard->get_material()->get_property("tint")); tint->set_value({1.0f, 1.0f, 1.0f, 1.0f}); ctx->camera_flash_billboard->get_material()->update_tweens(); ctx->ui_scene->add_object(ctx->camera_flash_billboard); diff --git a/src/input/control-set.hpp b/src/input/control-set.hpp index 16b1e0c..0e03b5c 100644 --- a/src/input/control-set.hpp +++ b/src/input/control-set.hpp @@ -28,8 +28,6 @@ class control; /** * A set of controls which can be managed simultaneously. - * - * @ingroup input */ class control_set { diff --git a/src/input/gamepad.hpp b/src/input/gamepad.hpp index f90dd4a..bcbf453 100644 --- a/src/input/gamepad.hpp +++ b/src/input/gamepad.hpp @@ -81,8 +81,6 @@ enum class gamepad_response_curve /** * A virtual gamepad which can generate gamepad-related input events and pass them to an event dispatcher. - * - * @ingroup input */ class gamepad: public device { diff --git a/src/input/mapping.hpp b/src/input/mapping.hpp index 425ffde..ae5f7cb 100644 --- a/src/input/mapping.hpp +++ b/src/input/mapping.hpp @@ -174,8 +174,6 @@ inline mapping_type gamepad_axis_mapping::get_type() const /** * A mapping between a control and a gamepad button. - * - * @ingroup input. */ class gamepad_button_mapping: public mapping { diff --git a/src/renderer/compositor.cpp b/src/render/compositor.cpp similarity index 83% rename from src/renderer/compositor.cpp rename to src/render/compositor.cpp index 87f98bf..ae1ea3e 100644 --- a/src/renderer/compositor.cpp +++ b/src/render/compositor.cpp @@ -17,15 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/compositor.hpp" -#include "renderer/render-pass.hpp" +#include "render/compositor.hpp" +#include "render/pass.hpp" -void compositor::add_pass(render_pass* pass) +namespace render { + +void compositor::add_pass(pass* pass) { passes.push_back(pass); } -void compositor::remove_pass(render_pass* pass) +void compositor::remove_pass(pass* pass) { passes.remove(pass); } @@ -37,7 +39,7 @@ void compositor::remove_passes() void compositor::composite(const render::context& ctx, render::queue& queue) const { - for (const render_pass* pass: passes) + for (const pass* pass: passes) { if (pass->is_enabled()) { @@ -46,3 +48,4 @@ void compositor::composite(const render::context& ctx, render::queue& queue) con } } +} // namespace render diff --git a/src/renderer/compositor.hpp b/src/render/compositor.hpp similarity index 69% rename from src/renderer/compositor.hpp rename to src/render/compositor.hpp index da175e8..3d8c8c7 100644 --- a/src/renderer/compositor.hpp +++ b/src/render/compositor.hpp @@ -17,14 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_COMPOSITOR_HPP -#define ANTKEEPER_COMPOSITOR_HPP +#ifndef ANTKEEPER_RENDER_COMPOSITOR_HPP +#define ANTKEEPER_RENDER_COMPOSITOR_HPP -#include "renderer/context.hpp" -#include "renderer/queue.hpp" +#include "render/context.hpp" +#include "render/queue.hpp" #include -class render_pass; +namespace render { + +class pass; /** * @@ -32,22 +34,23 @@ class render_pass; class compositor { public: - void add_pass(render_pass* pass); - void remove_pass(render_pass* pass); + void add_pass(pass* pass); + void remove_pass(pass* pass); void remove_passes(); void composite(const render::context& ctx, render::queue& queue) const; - const std::list* get_passes() const; + const std::list* get_passes() const; private: - std::list passes; + std::list passes; }; -inline const std::list* compositor::get_passes() const +inline const std::list* compositor::get_passes() const { return &passes; } -#endif // ANTKEEPER_COMPOSITOR_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_COMPOSITOR_HPP diff --git a/src/renderer/context.hpp b/src/render/context.hpp similarity index 100% rename from src/renderer/context.hpp rename to src/render/context.hpp diff --git a/src/renderer/material-flags.hpp b/src/render/material-flags.hpp similarity index 100% rename from src/renderer/material-flags.hpp rename to src/render/material-flags.hpp diff --git a/src/renderer/material-property.cpp b/src/render/material-property.cpp similarity index 93% rename from src/renderer/material-property.cpp rename to src/render/material-property.cpp index 692d812..372eb79 100644 --- a/src/renderer/material-property.cpp +++ b/src/render/material-property.cpp @@ -17,9 +17,11 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/material-property.hpp" +#include "render/material-property.hpp" #include "gl/shader-input.hpp" +namespace render { + material_property_base::material_property_base(): input(nullptr) {} @@ -41,3 +43,4 @@ void material_property_base::disconnect() this->input = nullptr; } +} // namespace render diff --git a/src/renderer/material-property.hpp b/src/render/material-property.hpp similarity index 98% rename from src/renderer/material-property.hpp rename to src/render/material-property.hpp index 64ffdbf..6261858 100644 --- a/src/renderer/material-property.hpp +++ b/src/render/material-property.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MATERIAL_PROPERTY_HPP -#define ANTKEEPER_MATERIAL_PROPERTY_HPP +#ifndef ANTKEEPER_RENDER_MATERIAL_PROPERTY_HPP +#define ANTKEEPER_RENDER_MATERIAL_PROPERTY_HPP #include "animation/tween.hpp" #include "gl/shader-variable-type.hpp" @@ -30,6 +30,8 @@ #include "gl/texture-cube.hpp" #include +namespace render { + class material; /** @@ -439,5 +441,6 @@ material_property_base* material_property::clone() const return property; } -#endif // ANTKEEPER_MATERIAL_PROPERTY_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_MATERIAL_PROPERTY_HPP diff --git a/src/renderer/material.cpp b/src/render/material.cpp similarity index 97% rename from src/renderer/material.cpp rename to src/render/material.cpp index a4426df..31b88bc 100644 --- a/src/renderer/material.cpp +++ b/src/render/material.cpp @@ -17,8 +17,9 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/material.hpp" -#include "gl/shader-program.hpp" +#include "render/material.hpp" + +namespace render { material::material(gl::shader_program* program): program(program), @@ -125,3 +126,4 @@ std::size_t material::reconnect_properties() return disconnected_property_count; } +} // namespace render diff --git a/src/renderer/material.hpp b/src/render/material.hpp similarity index 93% rename from src/renderer/material.hpp rename to src/render/material.hpp index 6816202..0bdbe27 100644 --- a/src/renderer/material.hpp +++ b/src/render/material.hpp @@ -17,17 +17,19 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MATERIAL_HPP -#define ANTKEEPER_MATERIAL_HPP +#ifndef ANTKEEPER_RENDER_MATERIAL_HPP +#define ANTKEEPER_RENDER_MATERIAL_HPP -#include "renderer/material-property.hpp" +#include "render/material-property.hpp" #include "gl/shader-program.hpp" #include #include #include -#include +#include #include +namespace render { + /** * A material is associated with exactly one shader program and contains a set of material properties which can be uploaded to that shader program via shader inputs. */ @@ -134,7 +136,7 @@ private: gl::shader_program* program; std::uint32_t flags; std::list properties; - std::map property_map; + std::unordered_map property_map; }; template @@ -181,5 +183,6 @@ inline const std::list* material::get_properties() cons return &properties; } -#endif // ANTKEEPER_MATERIAL_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_MATERIAL_HPP diff --git a/src/renderer/model.cpp b/src/render/model.cpp similarity index 97% rename from src/renderer/model.cpp rename to src/render/model.cpp index 998cd54..aa9f047 100644 --- a/src/renderer/model.cpp +++ b/src/render/model.cpp @@ -17,7 +17,9 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/model.hpp" +#include "render/model.hpp" + +namespace render { model::model(): bounds({0, 0, 0}, {0, 0, 0}) @@ -115,4 +117,4 @@ model_group* model::get_group(const std::string& name) return nullptr; } - +} // namespace render diff --git a/src/renderer/model.hpp b/src/render/model.hpp similarity index 92% rename from src/renderer/model.hpp rename to src/render/model.hpp index ae509a9..cf58c82 100644 --- a/src/renderer/model.hpp +++ b/src/render/model.hpp @@ -17,20 +17,23 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MODEL_HPP -#define ANTKEEPER_MODEL_HPP +#ifndef ANTKEEPER_RENDER_MODEL_HPP +#define ANTKEEPER_RENDER_MODEL_HPP #include "gl/vertex-array.hpp" #include "gl/vertex-buffer.hpp" #include "gl/drawing-mode.hpp" #include "geom/aabb.hpp" -#include +#include #include #include -class material; class skeleton; +namespace render { + +class material; + /** * Part of a model which is associated with exactly one material. */ @@ -61,7 +64,7 @@ private: std::size_t index_count; }; -inline void model_group::set_material(::material* material) +inline void model_group::set_material(render::material* material) { this->material = material; } @@ -150,7 +153,7 @@ public: private: aabb_type bounds; std::vector groups; - std::map group_map; + std::unordered_map group_map; gl::vertex_array vao; gl::vertex_buffer vbo; skeleton* skeleton; @@ -191,5 +194,6 @@ inline gl::vertex_buffer* model::get_vertex_buffer() return &vbo; } -#endif // ANTKEEPER_MODEL_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_MODEL_HPP diff --git a/src/renderer/operation.hpp b/src/render/operation.hpp similarity index 99% rename from src/renderer/operation.hpp rename to src/render/operation.hpp index 6ed5c75..4f9ae7c 100644 --- a/src/renderer/operation.hpp +++ b/src/render/operation.hpp @@ -26,10 +26,11 @@ #include class pose; -class material; namespace render { +class material; + /** * Encapsulates an atomic render operation. */ diff --git a/src/renderer/render-pass.cpp b/src/render/pass.cpp similarity index 81% rename from src/renderer/render-pass.cpp rename to src/render/pass.cpp index 1020649..b47d0b2 100644 --- a/src/renderer/render-pass.cpp +++ b/src/render/pass.cpp @@ -17,19 +17,22 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/render-pass.hpp" +#include "render/pass.hpp" -render_pass::render_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer): +namespace render { + +pass::pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer): rasterizer(rasterizer), framebuffer(framebuffer), enabled(true) {} -render_pass::~render_pass() +pass::~pass() {} -void render_pass::set_enabled(bool enabled) +void pass::set_enabled(bool enabled) { this->enabled = enabled; } +} // namespace render diff --git a/src/renderer/render-pass.hpp b/src/render/pass.hpp similarity index 82% rename from src/renderer/render-pass.hpp rename to src/render/pass.hpp index 1b05eb8..3458a52 100644 --- a/src/renderer/render-pass.hpp +++ b/src/render/pass.hpp @@ -22,17 +22,19 @@ #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" -#include "renderer/context.hpp" -#include "renderer/queue.hpp" +#include "render/context.hpp" +#include "render/queue.hpp" + +namespace render { /** - * + * Render pass. */ -class render_pass +class pass { public: - render_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer); - virtual ~render_pass(); + pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer); + virtual ~pass(); virtual void render(const render::context& ctx, render::queue& queue) const = 0; @@ -47,10 +49,12 @@ private: bool enabled; }; -inline bool render_pass::is_enabled() const +inline bool pass::is_enabled() const { return enabled; } +} // namespace render + #endif // ANTKEEPER_RENDER_PASS_HPP diff --git a/src/renderer/passes/bloom-pass.cpp b/src/render/passes/bloom-pass.cpp similarity index 97% rename from src/renderer/passes/bloom-pass.cpp rename to src/render/passes/bloom-pass.cpp index fa65847..abcabec 100644 --- a/src/renderer/passes/bloom-pass.cpp +++ b/src/render/passes/bloom-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/bloom-pass.hpp" +#include "render/passes/bloom-pass.hpp" #include "resources/resource-manager.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" @@ -30,14 +30,16 @@ #include "gl/texture-2d.hpp" #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/context.hpp" +#include "render/vertex-attribute.hpp" +#include "render/context.hpp" #include "math/math.hpp" #include #include +namespace render { + bloom_pass::bloom_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), source_texture(nullptr), brightness_threshold(1.0f), blur_iterations(1) @@ -171,3 +173,4 @@ void bloom_pass::set_blur_iterations(int iterations) this->blur_iterations = iterations; } +} // namespace render diff --git a/src/renderer/passes/bloom-pass.hpp b/src/render/passes/bloom-pass.hpp similarity index 90% rename from src/renderer/passes/bloom-pass.hpp rename to src/render/passes/bloom-pass.hpp index 60963d3..2d6a684 100644 --- a/src/renderer/passes/bloom-pass.hpp +++ b/src/render/passes/bloom-pass.hpp @@ -17,11 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_BLOOM_PASS_HPP -#define ANTKEEPER_BLOOM_PASS_HPP +#ifndef ANTKEEPER_RENDER_BLOOM_PASS_HPP +#define ANTKEEPER_RENDER_BLOOM_PASS_HPP -#include "renderer/render-pass.hpp" -#include "math/math.hpp" +#include "render/pass.hpp" #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" #include "gl/vertex-buffer.hpp" @@ -30,10 +29,12 @@ class resource_manager; +namespace render { + /** * */ -class bloom_pass: public render_pass +class bloom_pass: public pass { public: bloom_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager); @@ -68,5 +69,6 @@ private: int blur_iterations; }; -#endif // ANTKEEPER_BLOOM_PASS_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_BLOOM_PASS_HPP diff --git a/src/renderer/passes/clear-pass.cpp b/src/render/passes/clear-pass.cpp similarity index 95% rename from src/renderer/passes/clear-pass.cpp rename to src/render/passes/clear-pass.cpp index 844bf69..00a3b8b 100644 --- a/src/renderer/passes/clear-pass.cpp +++ b/src/render/passes/clear-pass.cpp @@ -17,13 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/clear-pass.hpp" +#include "render/passes/clear-pass.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" #include +namespace render { + clear_pass::clear_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), clear_color_buffer(false), clear_depth_buffer(false), clear_stencil_buffer(false), @@ -76,3 +78,5 @@ void clear_pass::set_clear_stencil(int stencil) { clear_stencil = stencil; } + +} // namespace render diff --git a/src/renderer/passes/clear-pass.hpp b/src/render/passes/clear-pass.hpp similarity index 68% rename from src/renderer/passes/clear-pass.hpp rename to src/render/passes/clear-pass.hpp index e72d8aa..0b4758d 100644 --- a/src/renderer/passes/clear-pass.hpp +++ b/src/render/passes/clear-pass.hpp @@ -17,26 +17,52 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CLEAR_PASS_HPP -#define ANTKEEPER_CLEAR_PASS_HPP +#ifndef ANTKEEPER_RENDER_CLEAR_PASS_HPP +#define ANTKEEPER_RENDER_CLEAR_PASS_HPP -#include "renderer/render-pass.hpp" +#include "render/pass.hpp" #include "utility/fundamental-types.hpp" +namespace render { + /** * Clears the color, depth, or stencil buffer of a render target. */ -class clear_pass: public render_pass +class clear_pass: public pass { public: clear_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer); virtual ~clear_pass(); virtual void render(const render::context& ctx, render::queue& queue) const final; + /** + * Sets the buffers to be cleared. + * + * @param color Clear the color buffer. + * @param depth Clear the depth buffer. + * @param stencil Clear the stencil buffer. + */ void set_cleared_buffers(bool color, bool depth, bool stencil); + /** + * Sets color buffer clear color. + * + * @param color Clear color. + */ void set_clear_color(const float4& color); + + /** + * Sets the depth buffer clear value. + * + * @param depth Clear value. + */ void set_clear_depth(float depth); + + /** + * Sets the stencil buffer clear value. + * + * @param stencil Clear value. + */ void set_clear_stencil(int stencil); private: @@ -48,5 +74,7 @@ private: int clear_stencil; }; -#endif // ANTKEEPER_CLEAR_PASS_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_CLEAR_PASS_HPP diff --git a/src/renderer/passes/final-pass.cpp b/src/render/passes/final-pass.cpp similarity index 95% rename from src/renderer/passes/final-pass.cpp rename to src/render/passes/final-pass.cpp index d2e7cf5..15d2062 100644 --- a/src/renderer/passes/final-pass.cpp +++ b/src/render/passes/final-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/final-pass.hpp" +#include "render/passes/final-pass.hpp" #include "resources/resource-manager.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" @@ -30,14 +30,15 @@ #include "gl/texture-2d.hpp" #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/context.hpp" -#include "math/math.hpp" +#include "render/vertex-attribute.hpp" +#include "render/context.hpp" #include #include +namespace render { + final_pass::final_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), color_texture(nullptr), bloom_texture(nullptr), blue_noise_texture(nullptr), @@ -136,3 +137,5 @@ void final_pass::set_blue_noise_texture(const gl::texture_2d* texture) this->blue_noise_texture = texture; blue_noise_scale = 1.0f / static_cast(texture->get_dimensions()[0]); } + +} // namespace render diff --git a/src/renderer/passes/final-pass.hpp b/src/render/passes/final-pass.hpp similarity index 89% rename from src/renderer/passes/final-pass.hpp rename to src/render/passes/final-pass.hpp index cfe7168..14f93d5 100644 --- a/src/renderer/passes/final-pass.hpp +++ b/src/render/passes/final-pass.hpp @@ -17,24 +17,24 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_FINAL_PASS_HPP -#define ANTKEEPER_FINAL_PASS_HPP +#ifndef ANTKEEPER_RENDER_FINAL_PASS_HPP +#define ANTKEEPER_RENDER_FINAL_PASS_HPP -#include "renderer/render-pass.hpp" -#include "math/math.hpp" +#include "render/pass.hpp" #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" #include "gl/vertex-buffer.hpp" #include "gl/vertex-array.hpp" #include "gl/texture-2d.hpp" -#include "animation/tween.hpp" class resource_manager; +namespace render { + /** * */ -class final_pass: public render_pass +class final_pass: public pass { public: final_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager); @@ -62,5 +62,7 @@ private: float blue_noise_scale; }; -#endif // ANTKEEPER_FINAL_PASS_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_FINAL_PASS_HPP diff --git a/src/renderer/passes/material-pass.cpp b/src/render/passes/material-pass.cpp similarity index 98% rename from src/renderer/passes/material-pass.cpp rename to src/render/passes/material-pass.cpp index 880e18c..fa6ea33 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/render/passes/material-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/material-pass.hpp" +#include "render/passes/material-pass.hpp" #include "configuration.hpp" #include "resources/resource-manager.hpp" #include "gl/rasterizer.hpp" @@ -31,10 +31,10 @@ #include "gl/texture-2d.hpp" #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/material-flags.hpp" -#include "renderer/model.hpp" -#include "renderer/context.hpp" +#include "render/vertex-attribute.hpp" +#include "render/material-flags.hpp" +#include "render/model.hpp" +#include "render/context.hpp" #include "scene/camera.hpp" #include "scene/collection.hpp" #include "scene/ambient-light.hpp" @@ -42,16 +42,17 @@ #include "scene/point-light.hpp" #include "scene/spot-light.hpp" #include "configuration.hpp" -#include "math/math.hpp" #include #include -#include "shadow-map-pass.hpp" +#include "render/passes/shadow-map-pass.hpp" + +namespace render { static bool operation_compare(const render::operation& a, const render::operation& b); material_pass::material_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), fallback_material(nullptr), mouse_position({0.0f, 0.0f}), shadow_map_pass(nullptr), @@ -137,7 +138,7 @@ void material_pass::render(const render::context& ctx, render::queue& queue) con int active_material_flags = 0; const gl::shader_program* active_shader_program = nullptr; - const ::material* active_material = nullptr; + const render::material* active_material = nullptr; const parameter_set* parameters = nullptr; // Reset light counts @@ -274,7 +275,7 @@ void material_pass::render(const render::context& ctx, render::queue& queue) con for (const render::operation& operation: queue) { // Get operation material - const ::material* material = operation.material; + const render::material* material = operation.material; if (!material) { if (fallback_material) @@ -703,3 +704,4 @@ bool operation_compare(const render::operation& a, const render::operation& b) } } +} // namespace render diff --git a/src/renderer/passes/material-pass.hpp b/src/render/passes/material-pass.hpp similarity index 93% rename from src/renderer/passes/material-pass.hpp rename to src/render/passes/material-pass.hpp index 7625b09..005ecda 100644 --- a/src/renderer/passes/material-pass.hpp +++ b/src/render/passes/material-pass.hpp @@ -17,28 +17,29 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MATERIAL_PASS_HPP -#define ANTKEEPER_MATERIAL_PASS_HPP +#ifndef ANTKEEPER_RENDER_MATERIAL_PASS_HPP +#define ANTKEEPER_RENDER_MATERIAL_PASS_HPP -#include "renderer/render-pass.hpp" -#include "renderer/material.hpp" -#include "animation/tween.hpp" +#include "render/pass.hpp" +#include "render/material.hpp" #include "utility/fundamental-types.hpp" #include "event/event-handler.hpp" #include "event/input-events.hpp" -#include #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" #include "gl/texture-2d.hpp" +#include -class camera; class resource_manager; + +namespace render { + class shadow_map_pass; /** * Renders scene objects using their material-specified shaders and properties. */ -class material_pass: public render_pass, +class material_pass: public pass, public event_handler { public: @@ -49,7 +50,7 @@ public: /// Sets the material to be used when a render operation is missing a material. If no fallback material is specified, render operations without materials will not be processed. void set_fallback_material(const material* fallback); - const ::shadow_map_pass* shadow_map_pass; + const render::shadow_map_pass* shadow_map_pass; const gl::texture_2d* shadow_map; private: @@ -132,4 +133,6 @@ private: float2* spot_light_cutoffs; }; -#endif // ANTKEEPER_MATERIAL_PASS_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_MATERIAL_PASS_HPP diff --git a/src/renderer/passes/outline-pass.cpp b/src/render/passes/outline-pass.cpp similarity index 92% rename from src/renderer/passes/outline-pass.cpp rename to src/render/passes/outline-pass.cpp index b42a255..7ab727e 100644 --- a/src/renderer/passes/outline-pass.cpp +++ b/src/render/passes/outline-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/outline-pass.hpp" +#include "render/passes/outline-pass.hpp" #include "resources/resource-manager.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" @@ -27,17 +27,18 @@ #include "gl/vertex-array.hpp" #include "gl/vertex-attribute.hpp" #include "gl/drawing-mode.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/context.hpp" -#include "renderer/material.hpp" -#include "renderer/material-flags.hpp" +#include "render/vertex-attribute.hpp" +#include "render/context.hpp" +#include "render/material.hpp" +#include "render/material-flags.hpp" #include "scene/camera.hpp" -#include "math/math.hpp" #include #include +namespace render { + outline_pass::outline_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), fill_shader(nullptr), stroke_shader(nullptr) { @@ -88,7 +89,7 @@ void outline_pass::render(const render::context& ctx, render::queue& queue) cons // Render fills for (const render::operation& operation: queue) { - const ::material* material = operation.material; + const render::material* material = operation.material; if (!material || !(material->get_flags() & MATERIAL_FLAG_OUTLINE)) continue; @@ -124,7 +125,7 @@ void outline_pass::render(const render::context& ctx, render::queue& queue) cons // Render strokes for (const render::operation& operation: queue) { - const ::material* material = operation.material; + const render::material* material = operation.material; if (!material || !(material->get_flags() & MATERIAL_FLAG_OUTLINE)) continue; @@ -147,3 +148,5 @@ void outline_pass::set_outline_color(const float4& color) { outline_color = color; } + +} // namespace render diff --git a/src/renderer/passes/outline-pass.hpp b/src/render/passes/outline-pass.hpp similarity index 87% rename from src/renderer/passes/outline-pass.hpp rename to src/render/passes/outline-pass.hpp index d7c9957..08dbc05 100644 --- a/src/renderer/passes/outline-pass.hpp +++ b/src/render/passes/outline-pass.hpp @@ -17,20 +17,22 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_OUTLINE_PASS_HPP -#define ANTKEEPER_OUTLINE_PASS_HPP +#ifndef ANTKEEPER_RENDER_OUTLINE_PASS_HPP +#define ANTKEEPER_RENDER_OUTLINE_PASS_HPP -#include "renderer/render-pass.hpp" +#include "render/pass.hpp" #include "utility/fundamental-types.hpp" #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" class resource_manager; +namespace render { + /** * */ -class outline_pass: public render_pass +class outline_pass: public pass { public: outline_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager); @@ -53,5 +55,6 @@ private: float4 outline_color; }; -#endif // ANTKEEPER_OUTLINE_PASS_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_OUTLINE_PASS_HPP diff --git a/src/renderer/passes/shadow-map-pass.cpp b/src/render/passes/shadow-map-pass.cpp similarity index 97% rename from src/renderer/passes/shadow-map-pass.cpp rename to src/render/passes/shadow-map-pass.cpp index 5a7026e..e76618e 100644 --- a/src/renderer/passes/shadow-map-pass.cpp +++ b/src/render/passes/shadow-map-pass.cpp @@ -17,16 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/shadow-map-pass.hpp" +#include "render/passes/shadow-map-pass.hpp" #include "resources/resource-manager.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" #include "gl/drawing-mode.hpp" -#include "renderer/context.hpp" -#include "renderer/material.hpp" -#include "renderer/material-flags.hpp" +#include "render/context.hpp" +#include "render/material.hpp" +#include "render/material-flags.hpp" #include "scene/camera.hpp" #include "scene/light.hpp" #include "geom/view-frustum.hpp" @@ -36,6 +36,8 @@ #include #include +namespace render { + static bool operation_compare(const render::operation& a, const render::operation& b); void shadow_map_pass::distribute_frustum_splits(float* split_distances, std::size_t split_count, float split_scheme, float near, float far) @@ -57,7 +59,7 @@ void shadow_map_pass::distribute_frustum_splits(float* split_distances, std::siz } shadow_map_pass::shadow_map_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), split_scheme_weight(0.5f), light(nullptr) { @@ -217,7 +219,7 @@ void shadow_map_pass::render(const render::context& ctx, render::queue& queue) c for (const render::operation& operation: queue) { // Skip materials which don't cast shadows - const ::material* material = operation.material; + const render::material* material = operation.material; if (material && (material->get_flags() & MATERIAL_FLAG_NOT_SHADOW_CASTER)) { continue; @@ -293,3 +295,5 @@ bool operation_compare(const render::operation& a, const render::operation& b) } } } + +} // namespace render diff --git a/src/renderer/passes/shadow-map-pass.hpp b/src/render/passes/shadow-map-pass.hpp similarity index 92% rename from src/renderer/passes/shadow-map-pass.hpp rename to src/render/passes/shadow-map-pass.hpp index fb39251..1f5dbe6 100644 --- a/src/renderer/passes/shadow-map-pass.hpp +++ b/src/render/passes/shadow-map-pass.hpp @@ -17,10 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SHADOW_MAP_PASS_HPP -#define ANTKEEPER_SHADOW_MAP_PASS_HPP +#ifndef ANTKEEPER_RENDER_SHADOW_MAP_PASS_HPP +#define ANTKEEPER_RENDER_SHADOW_MAP_PASS_HPP -#include "renderer/render-pass.hpp" +#include "render/pass.hpp" #include "utility/fundamental-types.hpp" #include "scene/directional-light.hpp" #include "gl/shader-program.hpp" @@ -28,10 +28,12 @@ class resource_manager; +namespace render { + /** * */ -class shadow_map_pass: public render_pass +class shadow_map_pass: public pass { public: shadow_map_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager); @@ -85,4 +87,6 @@ inline const float* shadow_map_pass::get_split_distances() const return split_distances; } -#endif // ANTKEEPER_SHADOW_MAP_PASS_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_SHADOW_MAP_PASS_HPP diff --git a/src/renderer/simple-render-pass.cpp b/src/render/passes/simple-pass.cpp similarity index 84% rename from src/renderer/simple-render-pass.cpp rename to src/render/passes/simple-pass.cpp index a40b8b6..441d664 100644 --- a/src/renderer/simple-render-pass.cpp +++ b/src/render/passes/simple-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/simple-render-pass.hpp" +#include "render/passes/simple-pass.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" #include "gl/shader-program.hpp" @@ -29,19 +29,20 @@ #include "gl/texture-2d.hpp" #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/context.hpp" -#include "renderer/material.hpp" -#include "renderer/material-property.hpp" -#include "math/math.hpp" +#include "render/vertex-attribute.hpp" +#include "render/context.hpp" +#include "render/material.hpp" +#include "render/material-property.hpp" #include -simple_render_pass::simple_render_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, gl::shader_program* shader_program): - render_pass(rasterizer, framebuffer), +namespace render { + +simple_pass::simple_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, gl::shader_program* shader_program): + pass(rasterizer, framebuffer), shader_program(shader_program) { // Create material - material = new ::material(shader_program); + material = new render::material(shader_program); // Add standard properties to material time_property = material->add_property("time"); @@ -76,14 +77,14 @@ simple_render_pass::simple_render_pass(gl::rasterizer* rasterizer, const gl::fra quad_vao->bind(render::vertex_attribute::position, position_attribute); } -simple_render_pass::~simple_render_pass() +simple_pass::~simple_pass() { delete material; delete quad_vao; delete quad_vbo; } -void simple_render_pass::render(const render::context& ctx, render::queue& queue) const +void simple_pass::render(const render::context& ctx, render::queue& queue) const { // Bind framebuffer rasterizer->use_framebuffer(*framebuffer); @@ -112,3 +113,5 @@ void simple_render_pass::render(const render::context& ctx, render::queue& queue // Draw quad rasterizer->draw_arrays(*quad_vao, gl::drawing_mode::triangles, 0, 6); } + +} // namespace render diff --git a/src/renderer/simple-render-pass.hpp b/src/render/passes/simple-pass.hpp similarity index 71% rename from src/renderer/simple-render-pass.hpp rename to src/render/passes/simple-pass.hpp index 271828f..fb22e90 100644 --- a/src/renderer/simple-render-pass.hpp +++ b/src/render/passes/simple-pass.hpp @@ -17,17 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SIMPLE_RENDER_PASS_HPP -#define ANTKEEPER_SIMPLE_RENDER_PASS_HPP +#ifndef ANTKEEPER_RENDER_SIMPLE_PASS_HPP +#define ANTKEEPER_RENDER_SIMPLE_PASS_HPP -#include "renderer/render-pass.hpp" -#include "animation/tween.hpp" +#include "render/pass.hpp" #include "utility/fundamental-types.hpp" #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" #include "gl/vertex-buffer.hpp" #include "gl/vertex-array.hpp" +namespace render { + class material; template class material_property; @@ -35,15 +36,15 @@ class material_property; /** * Simple render passes are associated with a single shader and a single material. */ -class simple_render_pass: public render_pass +class simple_pass: public pass { public: - simple_render_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, gl::shader_program* shader_program); - virtual ~simple_render_pass(); + simple_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, gl::shader_program* shader_program); + virtual ~simple_pass(); virtual void render(const render::context& ctx, render::queue& queue) const final; - const ::material* get_material() const; - ::material* get_material(); + const render::material* get_material() const; + render::material* get_material(); private: gl::shader_program* shader_program; @@ -55,14 +56,16 @@ private: gl::vertex_array* quad_vao; }; -inline const ::material* simple_render_pass::get_material() const +inline const render::material* simple_pass::get_material() const { return material; } -inline ::material* simple_render_pass::get_material() +inline render::material* simple_pass::get_material() { return material; } -#endif // ANTKEEPER_SIMPLE_RENDER_PASS_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_SIMPLE_PASS_HPP diff --git a/src/renderer/passes/sky-pass.cpp b/src/render/passes/sky-pass.cpp similarity index 98% rename from src/renderer/passes/sky-pass.cpp rename to src/render/passes/sky-pass.cpp index df73afb..d06ea5b 100644 --- a/src/renderer/passes/sky-pass.cpp +++ b/src/render/passes/sky-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/sky-pass.hpp" +#include "render/passes/sky-pass.hpp" #include "resources/resource-manager.hpp" #include "resources/string-table.hpp" #include "gl/rasterizer.hpp" @@ -31,10 +31,10 @@ #include "gl/texture-2d.hpp" #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/context.hpp" -#include "renderer/model.hpp" -#include "renderer/material.hpp" +#include "render/vertex-attribute.hpp" +#include "render/context.hpp" +#include "render/model.hpp" +#include "render/material.hpp" #include "scene/camera.hpp" #include "utility/fundamental-types.hpp" #include "color/color.hpp" @@ -47,10 +47,11 @@ #include #include #include -#include + +namespace render { sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer), + pass(rasterizer, framebuffer), mouse_position({0.0f, 0.0f}), sky_model(nullptr), sky_material(nullptr), @@ -472,3 +473,5 @@ void sky_pass::handle_event(const mouse_moved_event& event) { mouse_position = {static_cast(event.x), static_cast(event.y)}; } + +} // namespace render diff --git a/src/renderer/passes/sky-pass.hpp b/src/render/passes/sky-pass.hpp similarity index 96% rename from src/renderer/passes/sky-pass.hpp rename to src/render/passes/sky-pass.hpp index 0dbaecd..4c4593e 100644 --- a/src/renderer/passes/sky-pass.hpp +++ b/src/render/passes/sky-pass.hpp @@ -17,10 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SKY_PASS_HPP -#define ANTKEEPER_SKY_PASS_HPP +#ifndef ANTKEEPER_RENDER_SKY_PASS_HPP +#define ANTKEEPER_RENDER_SKY_PASS_HPP -#include "renderer/render-pass.hpp" +#include "render/pass.hpp" #include "utility/fundamental-types.hpp" #include "event/event-handler.hpp" #include "event/input-events.hpp" @@ -36,13 +36,16 @@ #include "scene/object.hpp" class resource_manager; -class model; + +namespace render { + class material; +class model; /** * */ -class sky_pass: public render_pass, +class sky_pass: public pass, public event_handler { public: @@ -153,4 +156,6 @@ private: float3 atmosphere_radii; }; -#endif // ANTKEEPER_SKY_PASS_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_SKY_PASS_HPP diff --git a/src/renderer/passes/ui-pass.cpp b/src/render/passes/ui-pass.cpp similarity index 92% rename from src/renderer/passes/ui-pass.cpp rename to src/render/passes/ui-pass.cpp index 34b3508..690d273 100644 --- a/src/renderer/passes/ui-pass.cpp +++ b/src/render/passes/ui-pass.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/passes/ui-pass.hpp" +#include "render/passes/ui-pass.hpp" #include "resources/resource-manager.hpp" #include "gl/rasterizer.hpp" #include "gl/framebuffer.hpp" @@ -30,20 +30,21 @@ #include "gl/texture-2d.hpp" #include "gl/texture-wrapping.hpp" #include "gl/texture-filter.hpp" -#include "renderer/vertex-attribute.hpp" -#include "renderer/material-flags.hpp" -#include "renderer/context.hpp" +#include "render/vertex-attribute.hpp" +#include "render/material-flags.hpp" +#include "render/context.hpp" #include "scene/camera.hpp" #include "scene/collection.hpp" #include "scene/ambient-light.hpp" #include "scene/directional-light.hpp" #include "scene/billboard.hpp" -#include "math/math.hpp" #include #include +namespace render { + ui_pass::ui_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): - render_pass(rasterizer, framebuffer) + pass(rasterizer, framebuffer) {} ui_pass::~ui_pass() @@ -86,3 +87,5 @@ const ui_pass::parameter_set* ui_pass::load_parameter_set(const gl::shader_progr return parameters; } + +} // namespace render diff --git a/src/renderer/passes/ui-pass.hpp b/src/render/passes/ui-pass.hpp similarity index 87% rename from src/renderer/passes/ui-pass.hpp rename to src/render/passes/ui-pass.hpp index 092c56e..a02e7c5 100644 --- a/src/renderer/passes/ui-pass.hpp +++ b/src/render/passes/ui-pass.hpp @@ -17,11 +17,11 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_UI_PASS_HPP -#define ANTKEEPER_UI_PASS_HPP +#ifndef ANTKEEPER_RENDER_UI_PASS_HPP +#define ANTKEEPER_RENDER_UI_PASS_HPP -#include "renderer/render-pass.hpp" -#include "renderer/material.hpp" +#include "render/pass.hpp" +#include "render/material.hpp" #include "gl/shader-program.hpp" #include "gl/shader-input.hpp" #include "gl/texture-2d.hpp" @@ -29,10 +29,12 @@ class resource_manager; +namespace render { + /** * */ -class ui_pass: public render_pass +class ui_pass: public pass { public: ui_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager); @@ -54,5 +56,6 @@ private: mutable std::unordered_map parameter_sets; }; -#endif // ANTKEEPER_UI_PASS_HPP +} // namespace render +#endif // ANTKEEPER_RENDER_UI_PASS_HPP diff --git a/src/renderer/queue.hpp b/src/render/queue.hpp similarity index 96% rename from src/renderer/queue.hpp rename to src/render/queue.hpp index 7a3bec6..b5a1296 100644 --- a/src/renderer/queue.hpp +++ b/src/render/queue.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_RENDER_QUEUE_HPP #define ANTKEEPER_RENDER_QUEUE_HPP -#include "renderer/operation.hpp" +#include "render/operation.hpp" #include namespace render { diff --git a/src/render/render.hpp b/src/render/render.hpp new file mode 100644 index 0000000..976c7f0 --- /dev/null +++ b/src/render/render.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_RENDER_HPP +#define ANTKEEPER_RENDER_HPP + +/** + * High-level rendering. + */ +namespace render {} + +#endif // ANTKEEPER_RENDER_HPP diff --git a/src/renderer/renderer.cpp b/src/render/renderer.cpp similarity index 98% rename from src/renderer/renderer.cpp rename to src/render/renderer.cpp index 0e9fac8..c0db19e 100644 --- a/src/renderer/renderer.cpp +++ b/src/render/renderer.cpp @@ -17,16 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/renderer.hpp" -#include "renderer/context.hpp" -#include "renderer/compositor.hpp" +#include "render/renderer.hpp" +#include "render/context.hpp" +#include "render/compositor.hpp" #include "scene/collection.hpp" #include "scene/camera.hpp" #include "scene/model-instance.hpp" #include "scene/billboard.hpp" #include "scene/lod-group.hpp" #include "scene/text.hpp" -#include "renderer/model.hpp" +#include "render/model.hpp" #include "gl/drawing-mode.hpp" #include "math/math.hpp" #include "geom/projection.hpp" @@ -34,6 +34,8 @@ #include #include +namespace render { + renderer::renderer() { // Setup billboard render operation @@ -244,3 +246,5 @@ void renderer::process_text(const render::context& ctx, render::queue& queue, co text->render(ctx, queue); } + +} // namespace render diff --git a/src/renderer/renderer.hpp b/src/render/renderer.hpp similarity index 76% rename from src/renderer/renderer.hpp rename to src/render/renderer.hpp index a18484e..ec11628 100644 --- a/src/renderer/renderer.hpp +++ b/src/render/renderer.hpp @@ -17,12 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_RENDERER_HPP -#define ANTKEEPER_RENDERER_HPP +#ifndef ANTKEEPER_RENDER_RENDERER_HPP +#define ANTKEEPER_RENDER_RENDERER_HPP -#include "renderer/operation.hpp" -#include "renderer/context.hpp" -#include "renderer/queue.hpp" +#include "render/operation.hpp" +#include "render/context.hpp" +#include "render/queue.hpp" #include "gl/vertex-array.hpp" namespace scene @@ -35,16 +35,7 @@ namespace scene class text; } -/* -# Pipeline - -1. A scene containing meshes, lights, and cameras is passed to renderer::render(). -2. Each camera is processed in order of priority. -3. Scene objects are tested for visibility against camera's view frustum. -4. List of visible scene objects are passed to the camera's compositor. -5. Compositor passes the visible scene objects to each render pass -6. Render pass sorts scene objects according to its own rules, then rasterizes to its render target. -*/ +namespace render { /** * @@ -79,4 +70,6 @@ private: mutable render::operation billboard_op; }; -#endif // ANTKEEPER_RENDERER_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_RENDERER_HPP diff --git a/src/renderer/shader-template.cpp b/src/render/shader-template.cpp similarity index 98% rename from src/renderer/shader-template.cpp rename to src/render/shader-template.cpp index 774adf0..e5d0da2 100644 --- a/src/renderer/shader-template.cpp +++ b/src/render/shader-template.cpp @@ -17,10 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#include "renderer/shader-template.hpp" +#include "render/shader-template.hpp" #include #include +namespace render { + shader_template::shader_template(const std::string& source_code) { source(source_code); @@ -216,3 +218,5 @@ bool shader_template::has_define_directive(const std::string& key) const { return (define_directives.find(key) != define_directives.end()); } + +} // namespace render diff --git a/src/renderer/shader-template.hpp b/src/render/shader-template.hpp similarity index 96% rename from src/renderer/shader-template.hpp rename to src/render/shader-template.hpp index 295fd53..6f6aa40 100644 --- a/src/renderer/shader-template.hpp +++ b/src/render/shader-template.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SHADER_TEMPLATE_HPP -#define ANTKEEPER_SHADER_TEMPLATE_HPP +#ifndef ANTKEEPER_RENDER_SHADER_TEMPLATE_HPP +#define ANTKEEPER_RENDER_SHADER_TEMPLATE_HPP #include "gl/shader-object.hpp" #include "gl/shader-program.hpp" @@ -27,6 +27,8 @@ #include #include +namespace render { + /** * Shader templates can be used to generate multiple shader variants from a single source. * @@ -129,4 +131,6 @@ private: std::multimap define_directives; }; -#endif // ANTKEEPER_SHADER_TEMPLATE_HPP +} // namespace render + +#endif // ANTKEEPER_RENDER_SHADER_TEMPLATE_HPP diff --git a/src/renderer/vertex-attribute.hpp b/src/render/vertex-attribute.hpp similarity index 64% rename from src/renderer/vertex-attribute.hpp rename to src/render/vertex-attribute.hpp index b986355..dbd69be 100644 --- a/src/renderer/vertex-attribute.hpp +++ b/src/render/vertex-attribute.hpp @@ -17,35 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_VERTEX_ATTRIBUTE_HPP -#define ANTKEEPER_VERTEX_ATTRIBUTE_HPP - -/// Vertex position (vec3) -#define VERTEX_POSITION_LOCATION 0 - -/// Vertex texture coordinates (vec2) -#define VERTEX_TEXCOORD_LOCATION 1 - -/// Vertex normal (vec3) -#define VERTEX_NORMAL_LOCATION 2 - -/// Vertex tangent (vec4) -#define VERTEX_TANGENT_LOCATION 3 - -/// Vertex color (vec4) -#define VERTEX_COLOR_LOCATION 4 - -/// Vertex bone indices (vec4) -#define VERTEX_BONE_INDEX_LOCATION 5 - -/// Vertex bone weights (vec4) -#define VERTEX_BONE_WEIGHT_LOCATION 6 - -/// Vertex barycentric coordinates (vec3) -#define VERTEX_BARYCENTRIC_LOCATION 7 - -/// Vertex morph target (vec3) -#define VERTEX_TARGET_LOCATION 8 +#ifndef ANTKEEPER_RENDER_VERTEX_ATTRIBUTE_HPP +#define ANTKEEPER_RENDER_VERTEX_ATTRIBUTE_HPP namespace render { @@ -81,10 +54,13 @@ namespace vertex_attribute barycentric, /// Vertex morph target (vec3) - target + target, + + /// General purpose index (uint) + index }; } } // namespace render -#endif // ANTKEEPER_VERTEX_ATTRIBUTE_HPP +#endif // ANTKEEPER_RENDER_VERTEX_ATTRIBUTE_HPP diff --git a/src/resources/entity-archetype-loader.cpp b/src/resources/entity-archetype-loader.cpp index d95ebaa..28f717c 100644 --- a/src/resources/entity-archetype-loader.cpp +++ b/src/resources/entity-archetype-loader.cpp @@ -19,7 +19,7 @@ #include "resource-loader.hpp" #include "resource-manager.hpp" -#include "renderer/model.hpp" +#include "render/model.hpp" #include "entity/components/atmosphere.hpp" #include "entity/components/behavior.hpp" #include "entity/components/collision.hpp" @@ -138,7 +138,7 @@ static bool load_component_model(entity::archetype& archetype, resource_manager& if (element.contains("file")) { - component.render_model = resource_manager.load(element["file"].get()); + component.render_model = resource_manager.load(element["file"].get()); } archetype.set(component); diff --git a/src/resources/material-loader.cpp b/src/resources/material-loader.cpp index 258841d..54abb12 100644 --- a/src/resources/material-loader.cpp +++ b/src/resources/material-loader.cpp @@ -19,8 +19,8 @@ #include "resource-loader.hpp" #include "resource-manager.hpp" -#include "renderer/material.hpp" -#include "renderer/material-flags.hpp" +#include "render/material.hpp" +#include "render/material-flags.hpp" #include #include #include @@ -39,7 +39,7 @@ static bool read_value(T* value, const nlohmann::json& json, const std::string& return false; } -static bool load_texture_2d_property(resource_manager* resource_manager, material* material, const std::string& name, const nlohmann::json& json) +static bool load_texture_2d_property(resource_manager* resource_manager, render::material* material, const std::string& name, const nlohmann::json& json) { // If JSON element is an array if (json.is_array()) @@ -48,7 +48,7 @@ static bool load_texture_2d_property(resource_manager* resource_manager, materia std::size_t array_size = json.size(); // Create property - material_property* property = material->add_property(name, array_size); + render::material_property* property = material->add_property(name, array_size); // Load textures std::size_t i = 0; @@ -62,7 +62,7 @@ static bool load_texture_2d_property(resource_manager* resource_manager, materia else { // Create property - material_property* property = material->add_property(name); + render::material_property* property = material->add_property(name); // Load texture std::string filename = json.get(); @@ -73,13 +73,13 @@ static bool load_texture_2d_property(resource_manager* resource_manager, materia return true; } -static bool load_texture_cube_property(resource_manager* resource_manager, material* material, const std::string& name, const nlohmann::json& json) +static bool load_texture_cube_property(resource_manager* resource_manager, render::material* material, const std::string& name, const nlohmann::json& json) { return false; } template -static bool load_scalar_property(material* material, const std::string& name, const nlohmann::json& json) +static bool load_scalar_property(render::material* material, const std::string& name, const nlohmann::json& json) { // If JSON element is an array if (json.is_array()) @@ -88,7 +88,7 @@ static bool load_scalar_property(material* material, const std::string& name, co std::size_t array_size = json.size(); // Create property - material_property* property = material->add_property(name, array_size); + render::material_property* property = material->add_property(name, array_size); // Set property values std::size_t i = 0; @@ -98,7 +98,7 @@ static bool load_scalar_property(material* material, const std::string& name, co else { // Create property - material_property* property = material->add_property(name); + render::material_property* property = material->add_property(name); // Set property value property->set_value(json.get()); @@ -108,7 +108,7 @@ static bool load_scalar_property(material* material, const std::string& name, co } template -static bool load_vector_property(material* material, const std::string& name, std::size_t vector_size, const nlohmann::json& json) +static bool load_vector_property(render::material* material, const std::string& name, std::size_t vector_size, const nlohmann::json& json) { // If JSON element is an array of arrays if (json.is_array() && json.begin().value().is_array()) @@ -117,7 +117,7 @@ static bool load_vector_property(material* material, const std::string& name, st std::size_t array_size = json.size(); // Create property - material_property* property = material->add_property(name, array_size); + render::material_property* property = material->add_property(name, array_size); // For each vector in the array std::size_t i = 0; @@ -136,7 +136,7 @@ static bool load_vector_property(material* material, const std::string& name, st else { // Create property - material_property* property = material->add_property(name); + render::material_property* property = material->add_property(name); // Read vector elements T value; @@ -152,7 +152,7 @@ static bool load_vector_property(material* material, const std::string& name, st } template -static bool load_matrix_property(material* material, const std::string& name, std::size_t column_count, std::size_t row_count, const nlohmann::json& json) +static bool load_matrix_property(render::material* material, const std::string& name, std::size_t column_count, std::size_t row_count, const nlohmann::json& json) { // If JSON element is an array of arrays of arrays if (json.is_array() && json.begin().value().is_array()) @@ -163,7 +163,7 @@ static bool load_matrix_property(material* material, const std::string& name, st std::size_t array_size = json.size(); // Create property - material_property* property = material->add_property(name, array_size); + render::material_property* property = material->add_property(name, array_size); // For each matrix in the array std::size_t i = 0; @@ -195,7 +195,7 @@ static bool load_matrix_property(material* material, const std::string& name, st else { // Create property - material_property* property = material->add_property(name); + render::material_property* property = material->add_property(name); // Read matrix elements T value; @@ -223,7 +223,7 @@ static bool load_matrix_property(material* material, const std::string& name, st } template <> -material* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file) +render::material* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file) { // Read file into buffer std::size_t size = static_cast(PHYSFS_fileLength(file)); @@ -235,7 +235,7 @@ material* resource_loader::load(resource_manager* resource_manager, PH nlohmann::json json = nlohmann::json::parse(buffer, nullptr, true, true); // Allocate material - material* material = new ::material(); + render::material* material = new render::material(); // Read shader filename std::string shader_filename; diff --git a/src/resources/model-loader.cpp b/src/resources/model-loader.cpp index db665e5..d854b32 100644 --- a/src/resources/model-loader.cpp +++ b/src/resources/model-loader.cpp @@ -19,8 +19,8 @@ #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" -#include "renderer/model.hpp" -#include "renderer/vertex-attribute.hpp" +#include "render/model.hpp" +#include "render/vertex-attribute.hpp" #include "gl/vertex-attribute.hpp" #include "gl/drawing-mode.hpp" #include "utility/fundamental-types.hpp" @@ -357,7 +357,7 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F */ template <> -model* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file) +render::model* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file) { // Read file into buffer std::size_t size = static_cast(PHYSFS_fileLength(file)); @@ -431,7 +431,7 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F } // Allocate a model - model* model = new ::model(); + render::model* model = new render::model(); // Set the model bounds model->set_bounds(bounds); @@ -512,7 +512,7 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F std::string group_name; std::size_t group_offset = 0; std::size_t group_size = 0; - material* group_material = nullptr; + render::material* group_material = nullptr; if (auto name_node = material_node.value().find("name"); name_node != material_node.value().end()) group_name = name_node.value().get(); @@ -526,9 +526,9 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F std::replace(material_filename.begin(), material_filename.end(), '_', '-'); // Load material from file - group_material = resource_manager->load(material_filename); + group_material = resource_manager->load(material_filename); - model_group* model_group = model->add_group(group_name); + render::model_group* model_group = model->add_group(group_name); model_group->set_drawing_mode(gl::drawing_mode::triangles); model_group->set_start_index(group_offset * 3); model_group->set_index_count(group_size * 3); diff --git a/src/resources/shader-program-loader.cpp b/src/resources/shader-program-loader.cpp index cf46729..74f8ea8 100644 --- a/src/resources/shader-program-loader.cpp +++ b/src/resources/shader-program-loader.cpp @@ -20,7 +20,7 @@ #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/text-file.hpp" -#include "renderer/shader-template.hpp" +#include "render/shader-template.hpp" #include "gl/shader-object.hpp" #include "gl/shader-program.hpp" #include @@ -89,10 +89,10 @@ gl::shader_program* resource_loader::load(resource_manager* std::copy(source_lines.begin(), source_lines.end(), std::ostream_iterator(stream, "\n")); // Create shader template - shader_template* shader = new shader_template(stream.str()); + render::shader_template* shader = new render::shader_template(stream.str()); // Build shader program - gl::shader_program* program = shader->build(shader_template::dictionary_type()); + gl::shader_program* program = shader->build(render::shader_template::dictionary_type()); // Check if shader program was linked successfully if (!program->was_linked()) diff --git a/src/scene/billboard.cpp b/src/scene/billboard.cpp index dad95c9..4eb8c8e 100644 --- a/src/scene/billboard.cpp +++ b/src/scene/billboard.cpp @@ -18,7 +18,6 @@ */ #include "scene/billboard.hpp" -#include "renderer/material.hpp" #include "configuration.hpp" namespace scene { @@ -48,7 +47,7 @@ billboard& billboard::operator=(const billboard& other) return *this; } -void billboard::set_material(::material* material) +void billboard::set_material(render::material* material) { this->material = material; } diff --git a/src/scene/billboard.hpp b/src/scene/billboard.hpp index c826930..325063d 100644 --- a/src/scene/billboard.hpp +++ b/src/scene/billboard.hpp @@ -23,8 +23,7 @@ #include "scene/object.hpp" #include "geom/aabb.hpp" #include "utility/fundamental-types.hpp" - -class material; +#include "render/material.hpp" namespace scene { @@ -53,7 +52,7 @@ public: billboard(const billboard& other); billboard& operator=(const billboard& other); - void set_material(material* material); + void set_material(render::material* material); /// Sets the billboard alignment mode. void set_billboard_type(billboard_type type); @@ -64,7 +63,7 @@ public: virtual const bounding_volume_type& get_local_bounds() const; virtual const bounding_volume_type& get_world_bounds() const; - material* get_material() const; + render::material* get_material() const; billboard_type get_billboard_type() const; const float3& get_alignment_axis() const; @@ -77,7 +76,7 @@ private: aabb_type world_bounds; - material* material; + render::material* material; billboard_type type; float3 alignment_axis; }; @@ -92,7 +91,7 @@ inline const typename object_base::bounding_volume_type& billboard::get_world_bo return world_bounds; } -inline material* billboard::get_material() const +inline render::material* billboard::get_material() const { return material; } diff --git a/src/scene/camera.cpp b/src/scene/camera.cpp index 2f386c2..ca92a9a 100644 --- a/src/scene/camera.cpp +++ b/src/scene/camera.cpp @@ -149,7 +149,7 @@ void camera::set_exposure(float exposure) this->exposure[1] = exposure; } -void camera::set_compositor(::compositor* compositor) +void camera::set_compositor(render::compositor* compositor) { this->compositor = compositor; } diff --git a/src/scene/camera.hpp b/src/scene/camera.hpp index 53a58c9..981affc 100644 --- a/src/scene/camera.hpp +++ b/src/scene/camera.hpp @@ -23,8 +23,7 @@ #include "scene/object.hpp" #include "geom/view-frustum.hpp" #include "utility/fundamental-types.hpp" - -class compositor; +#include "render/compositor.hpp" namespace scene { @@ -85,7 +84,7 @@ public: */ void set_exposure(float exposure); - void set_compositor(compositor* compositor); + void set_compositor(render::compositor* compositor); void set_composite_index(int index); @@ -117,8 +116,8 @@ public: /// Returns the camera's exposure. float get_exposure() const; - const compositor* get_compositor() const; - compositor* get_compositor(); + const render::compositor* get_compositor() const; + render::compositor* get_compositor(); int get_composite_index() const; const tween& get_clip_left_tween() const; @@ -140,7 +139,7 @@ public: private: virtual void transformed(); - compositor* compositor; + render::compositor* compositor; int composite_index; bool orthographic; tween clip_left; @@ -239,13 +238,12 @@ inline float camera::get_exposure() const return exposure[1]; } - -inline const compositor* camera::get_compositor() const +inline const render::compositor* camera::get_compositor() const { return compositor; } -inline compositor* camera::get_compositor() +inline render::compositor* camera::get_compositor() { return compositor; } diff --git a/src/scene/model-instance.cpp b/src/scene/model-instance.cpp index 4bca3e6..f21e1bb 100644 --- a/src/scene/model-instance.cpp +++ b/src/scene/model-instance.cpp @@ -18,12 +18,12 @@ */ #include "scene/model-instance.hpp" -#include "renderer/model.hpp" -#include "renderer/material.hpp" +#include "render/model.hpp" +#include "render/material.hpp" namespace scene { -model_instance::model_instance(::model* model): +model_instance::model_instance(render::model* model): model(nullptr), pose(nullptr), local_bounds{{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}, @@ -56,7 +56,7 @@ model_instance& model_instance::operator=(const model_instance& other) return *this; } -void model_instance::set_model(::model* model) +void model_instance::set_model(render::model* model) { this->model = model; this->pose = nullptr; @@ -75,7 +75,7 @@ void model_instance::set_pose(::pose* pose) this->pose = pose; } -void model_instance::set_material(std::size_t group_index, material* material) +void model_instance::set_material(std::size_t group_index, render::material* material) { materials[group_index] = material; } @@ -117,9 +117,9 @@ void model_instance::update_tweens() // Update model material tweens if (model) { - for (model_group* group: *model->get_groups()) + for (render::model_group* group: *model->get_groups()) { - material* material = group->get_material(); + render::material* material = group->get_material(); if (material) { material->update_tweens(); @@ -128,7 +128,7 @@ void model_instance::update_tweens() } // Update material override tweens - for (::material* material: materials) + for (render::material* material: materials) { if (material) { diff --git a/src/scene/model-instance.hpp b/src/scene/model-instance.hpp index 8de493d..b73b7bc 100644 --- a/src/scene/model-instance.hpp +++ b/src/scene/model-instance.hpp @@ -22,10 +22,9 @@ #include "scene/object.hpp" #include "geom/aabb.hpp" +#include "render/model.hpp" #include -class material; -class model; class pose; namespace scene { @@ -35,7 +34,7 @@ class model_instance: public object public: typedef geom::aabb aabb_type; - explicit model_instance(model* model); + explicit model_instance(render::model* model); model_instance(); model_instance(const model_instance& other); model_instance& operator=(const model_instance& other); @@ -43,7 +42,7 @@ public: /** * Sets the model with which this model instance is associated. This will reset the pose and all overwritten materials. */ - void set_model(model* model); + void set_model(render::model* model); /** * Sets the @@ -56,7 +55,7 @@ public: * @param group_index Index of a model group. * @param material Pointer to the material which should overwrite the model group's material. A value of `nullptr` indicates the material will not be overwritten. */ - void set_material(std::size_t group_index, material* material); + void set_material(std::size_t group_index, render::material* material); void set_instanced(bool instanced, std::size_t instance_count = 1); @@ -68,13 +67,13 @@ public: virtual const bounding_volume_type& get_local_bounds() const; virtual const bounding_volume_type& get_world_bounds() const; - const model* get_model() const; - model* get_model(); + const render::model* get_model() const; + render::model* get_model(); const pose* get_pose() const; pose* get_pose(); - const std::vector* get_materials() const; + const std::vector* get_materials() const; bool is_instanced() const; std::size_t get_instance_count() const; @@ -86,9 +85,9 @@ public: private: virtual void transformed(); - model* model; + render::model* model; pose* pose; - std::vector materials; + std::vector materials; aabb_type local_bounds; aabb_type world_bounds; bool instanced; @@ -105,12 +104,12 @@ inline const typename object_base::bounding_volume_type& model_instance::get_wor return world_bounds; } -inline const model* model_instance::get_model() const +inline const render::model* model_instance::get_model() const { return model; } -inline model* model_instance::get_model() +inline render::model* model_instance::get_model() { return model; } @@ -125,7 +124,7 @@ inline pose* model_instance::get_pose() return pose; } -inline const std::vector* model_instance::get_materials() const +inline const std::vector* model_instance::get_materials() const { return &materials; } diff --git a/src/scene/object.hpp b/src/scene/object.hpp index 64eec6a..a487ecd 100644 --- a/src/scene/object.hpp +++ b/src/scene/object.hpp @@ -25,8 +25,8 @@ #include "math/vector-type.hpp" #include "math/quaternion-type.hpp" #include "math/transform-type.hpp" -#include "renderer/context.hpp" -#include "renderer/queue.hpp" +#include "render/context.hpp" +#include "render/queue.hpp" #include #include @@ -248,7 +248,8 @@ class object: public object_base public: /// Unique type ID for this scene object type. static const std::atomic object_type_id; - + + /// @copydoc object_base::get_object_type_id() const virtual const std::size_t get_object_type_id() const final; }; diff --git a/src/scene/text.cpp b/src/scene/text.cpp index 2b3b0dc..a5b7277 100644 --- a/src/scene/text.cpp +++ b/src/scene/text.cpp @@ -18,8 +18,7 @@ */ #include "scene/text.hpp" -#include "renderer/material.hpp" -#include "renderer/vertex-attribute.hpp" +#include "render/vertex-attribute.hpp" #include "math/vector-operators.hpp" #include #include @@ -114,7 +113,7 @@ void text::refresh() update_content(); } -void text::set_material(::material* material) +void text::set_material(render::material* material) { this->material = material; render_op.material = material; diff --git a/src/scene/text.hpp b/src/scene/text.hpp index 26a11ef..0951db7 100644 --- a/src/scene/text.hpp +++ b/src/scene/text.hpp @@ -25,7 +25,7 @@ #include "utility/fundamental-types.hpp" #include "gl/vertex-array.hpp" #include "gl/vertex-buffer.hpp" -#include "renderer/material.hpp" +#include "render/material.hpp" #include "type/bitmap-font.hpp" #include "type/text-direction.hpp" @@ -58,7 +58,7 @@ public: * * @param material Text material. */ - void set_material(material* material); + void set_material(render::material* material); /** * Sets the text font. @@ -91,7 +91,7 @@ public: void set_color(const float4& color); /// Returns the text material. - material* get_material() const; + render::material* get_material() const; /// Returns the text font. const type::bitmap_font* get_font() const; @@ -123,7 +123,7 @@ private: mutable render::operation render_op; aabb_type local_bounds; aabb_type world_bounds; - material* material; + render::material* material; const type::bitmap_font* font; type::text_direction direction; std::string content_u8; @@ -136,7 +136,7 @@ private: gl::vertex_buffer* vbo; }; -inline material* text::get_material() const +inline render::material* text::get_material() const { return material; } diff --git a/src/ui/ui.hpp b/src/ui/ui.hpp index ec68619..d278825 100644 --- a/src/ui/ui.hpp +++ b/src/ui/ui.hpp @@ -23,4 +23,6 @@ /// UI elements namespace ui {} +#include "ui/element.hpp" + #endif // ANTKEEPER_UI_HPP