Browse Source

Put classes related to high-level rendering into render namespace

master
C. J. Howard 3 years ago
parent
commit
54d9c199f5
80 changed files with 666 additions and 804 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +1
    -1
      src/animation/screen-transition.cpp
  3. +6
    -6
      src/animation/screen-transition.hpp
  4. +3
    -3
      src/entity/components/model.hpp
  5. +2
    -2
      src/entity/components/terrain.hpp
  6. +1
    -1
      src/entity/systems/astronomy.cpp
  7. +3
    -3
      src/entity/systems/astronomy.hpp
  8. +3
    -3
      src/entity/systems/painting.cpp
  9. +3
    -5
      src/entity/systems/painting.hpp
  10. +1
    -2
      src/entity/systems/render.cpp
  11. +3
    -4
      src/entity/systems/render.hpp
  12. +11
    -11
      src/entity/systems/subterrain.cpp
  13. +6
    -8
      src/entity/systems/subterrain.hpp
  14. +10
    -10
      src/entity/systems/terrain.cpp
  15. +4
    -4
      src/entity/systems/terrain.hpp
  16. +0
    -192
      src/entity/systems/ui.cpp
  17. +0
    -89
      src/entity/systems/ui.hpp
  18. +1
    -1
      src/entity/systems/vegetation.cpp
  19. +40
    -42
      src/game/bootloader.cpp
  20. +43
    -33
      src/game/context.hpp
  21. +1
    -1
      src/game/states/brood.cpp
  22. +1
    -1
      src/game/states/forage.cpp
  23. +95
    -66
      src/game/states/loading.cpp
  24. +1
    -2
      src/game/states/nuptial-flight.cpp
  25. +2
    -2
      src/game/tools.cpp
  26. +0
    -2
      src/input/control-set.hpp
  27. +0
    -2
      src/input/gamepad.hpp
  28. +0
    -2
      src/input/mapping.hpp
  29. +8
    -5
      src/render/compositor.cpp
  30. +14
    -11
      src/render/compositor.hpp
  31. +0
    -0
      src/render/context.hpp
  32. +0
    -0
      src/render/material-flags.hpp
  33. +4
    -1
      src/render/material-property.cpp
  34. +6
    -3
      src/render/material-property.hpp
  35. +4
    -2
      src/render/material.cpp
  36. +9
    -6
      src/render/material.hpp
  37. +4
    -2
      src/render/model.cpp
  38. +11
    -7
      src/render/model.hpp
  39. +2
    -1
      src/render/operation.hpp
  40. +7
    -4
      src/render/pass.cpp
  41. +11
    -7
      src/render/pass.hpp
  42. +7
    -4
      src/render/passes/bloom-pass.cpp
  43. +8
    -6
      src/render/passes/bloom-pass.hpp
  44. +6
    -2
      src/render/passes/clear-pass.cpp
  45. +33
    -5
      src/render/passes/clear-pass.hpp
  46. +8
    -5
      src/render/passes/final-pass.cpp
  47. +9
    -7
      src/render/passes/final-pass.hpp
  48. +12
    -10
      src/render/passes/material-pass.cpp
  49. +13
    -10
      src/render/passes/material-pass.hpp
  50. +12
    -9
      src/render/passes/outline-pass.cpp
  51. +8
    -5
      src/render/passes/outline-pass.hpp
  52. +10
    -6
      src/render/passes/shadow-map-pass.cpp
  53. +9
    -5
      src/render/passes/shadow-map-pass.hpp
  54. +14
    -11
      src/render/passes/simple-pass.cpp
  55. +15
    -12
      src/render/passes/simple-pass.hpp
  56. +10
    -7
      src/render/passes/sky-pass.cpp
  57. +11
    -6
      src/render/passes/sky-pass.hpp
  58. +9
    -6
      src/render/passes/ui-pass.cpp
  59. +9
    -6
      src/render/passes/ui-pass.hpp
  60. +1
    -1
      src/render/queue.hpp
  61. +28
    -0
      src/render/render.hpp
  62. +8
    -4
      src/render/renderer.cpp
  63. +9
    -16
      src/render/renderer.hpp
  64. +5
    -1
      src/render/shader-template.cpp
  65. +7
    -3
      src/render/shader-template.hpp
  66. +7
    -31
      src/render/vertex-attribute.hpp
  67. +2
    -2
      src/resources/entity-archetype-loader.cpp
  68. +17
    -17
      src/resources/material-loader.cpp
  69. +7
    -7
      src/resources/model-loader.cpp
  70. +3
    -3
      src/resources/shader-program-loader.cpp
  71. +1
    -2
      src/scene/billboard.cpp
  72. +5
    -6
      src/scene/billboard.hpp
  73. +1
    -1
      src/scene/camera.cpp
  74. +7
    -9
      src/scene/camera.hpp
  75. +8
    -8
      src/scene/model-instance.cpp
  76. +12
    -13
      src/scene/model-instance.hpp
  77. +4
    -3
      src/scene/object.hpp
  78. +2
    -3
      src/scene/text.cpp
  79. +5
    -5
      src/scene/text.hpp
  80. +2
    -0
      src/ui/ui.hpp

+ 1
- 0
CMakeLists.txt View File

@ -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)

+ 1
- 1
src/animation/screen-transition.cpp View File

@ -18,7 +18,7 @@
*/
#include "screen-transition.hpp"
#include "renderer/material-flags.hpp"
#include "render/material-flags.hpp"
#include <functional>
screen_transition::screen_transition()

+ 6
- 6
src/animation/screen-transition.hpp View File

@ -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<float>::interpolator_type interpolator);
scene::billboard* get_billboard();
::material* get_material();
render::material* get_material();
::animation<float>* get_animation();
private:
scene::billboard billboard;
::material material;
material_property<float>* progress;
render::material material;
render::material_property<float>* progress;
::animation<float> animation;
::animation<float>::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;
}

+ 3
- 3
src/entity/components/model.hpp View File

@ -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 <unordered_map>
namespace entity {
@ -28,8 +28,8 @@ namespace component {
struct model
{
::model* render_model;
std::unordered_map<int, material*> materials;
render::model* render_model;
std::unordered_map<int, render::material*> materials;
int instance_count;
unsigned int layers;
};

+ 2
- 2
src/entity/components/terrain.hpp View File

@ -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 <functional>
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

+ 1
- 1
src/entity/systems/astronomy.cpp View File

@ -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;
}

+ 3
- 3
src/entity/systems/astronomy.hpp View File

@ -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<double> ezs_to_sez;
scene::directional_light* sun_light;
sky_pass* sky_pass;
::render::sky_pass* sky_pass;
};
} // namespace system

+ 3
- 3
src/entity/systems/painting.cpp View File

@ -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 <limits>

+ 3
- 5
src/entity/systems/painting.hpp View File

@ -28,14 +28,12 @@
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "gl/vertex-buffer.hpp"
#include "render/model.hpp"
#include <vector>
#include <optional>
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;

+ 1
- 2
src/entity/systems/render.cpp View File

@ -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;
}

+ 3
- 4
src/entity/systems/render.hpp View File

@ -27,11 +27,10 @@
#include "entity/components/model.hpp"
#include "entity/components/light.hpp"
#include "entity/id.hpp"
#include "render/renderer.hpp"
#include <unordered_map>
#include <vector>
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<scene::collection*> layers;
std::unordered_map<entity::id, scene::model_instance*> model_instances;
std::unordered_map<entity::id, scene::light*> lights;

+ 11
- 11
src/entity/systems/subterrain.cpp View File

@ -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<material>("subterrain-inside.mtl");
subterrain_inside_material = resource_manager->load<material>("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<material>("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<material>("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;

+ 6
- 8
src/entity/systems/subterrain.hpp View File

@ -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 <unordered_map>
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<float> subterrain_bounds;

+ 10
- 10
src/entity/systems/terrain.cpp View File

@ -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 <functional>
#include <iostream>
@ -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);

+ 4
- 4
src/entity/systems/terrain.hpp View File

@ -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 <unordered_map>
@ -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;

+ 0
- 192
src/entity/systems/ui.cpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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<gl::shader_program>("ui-element-untextured.glsl"));
modal_bg_material.set_flags(1);
modal_bg_material.add_property<float4>("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<material>("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<float> / static_cast<float>(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<float> + selection_angle));
int sector = static_cast<int>((selection_angle + sector_angle * 0.5f) / sector_angle) % sector_count;
float rotation_angle = static_cast<float>(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<float>(event.w), static_cast<float>(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

+ 0
- 89
src/entity/systems/ui.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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<mouse_moved_event>,
public event_handler<window_resized_event>
{
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

+ 1
- 1
src/entity/systems/vegetation.cpp View File

@ -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 <cmath>

+ 40
- 42
src/game/bootloader.cpp View File

@ -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<gl::texture_2d>("blue-noise.tex");
// Load fallback material
ctx->fallback_material = ctx->resource_manager->load<material>("fallback.mtl");
ctx->fallback_material = ctx->resource_manager->load<render::material>("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<mouse_moved_event>(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<mouse_moved_event>(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<mouse_moved_event>(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<gl::texture_2d>("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<gl::shader_program>("ui-element-textured.glsl"));
ctx->splash_billboard_material->add_property<const gl::texture_2d*>("background")->set_value(splash_texture);
ctx->splash_billboard_material->add_property<float4>("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<gl::shader_program>("ui-element-untextured.glsl"));
auto flash_tint = flash_material->add_property<float4>("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<mouse_moved_event>(ctx->ui_system);
event_dispatcher->subscribe<window_resized_event>(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);
}

+ 43
- 33
src/game/context.hpp View File

@ -45,27 +45,19 @@
#include <unordered_map>
#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 <typename T> class animation;
template <typename T> 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<std::string, std::string>* strings;
std::unordered_map<std::string, type::typeface*> 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<float>* radial_transition_in;
animation<float>* radial_transition_out;
screen_transition* fade_transition;
material_property<float3>* fade_transition_color;
render::material_property<float3>* fade_transition_color;
screen_transition* radial_transition_inner;
screen_transition* radial_transition_outer;
animation<float>* 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;

+ 1
- 1
src/game/states/brood.cpp View File

@ -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 <iostream>

+ 1
- 1
src/game/states/forage.cpp View File

@ -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<material>("desert-terrain.mtl");
biome_terrain.patch_material = ctx->resource_manager->load<render::material>("desert-terrain.mtl");
biome_terrain.elevation = [](double, double) -> double
{
return 0.0;

+ 95
- 66
src/game/states/loading.cpp View File

@ -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 <stb/stb_image_write.h>
#include <unordered_set>
#include <codecvt>
@ -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<char32_t>& 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<const gl::texture_2d*>("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<gl::shader_program>("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<const gl::texture_2d*>("font_bitmap")->set_value(font_texture);
font_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("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<const geom::aabb<float>&>(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<const geom::aabb<float>&>(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<const geom::aabb<float>&>(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<model>("sky-dome.mdl"));
ctx->surface_sky_pass->set_sky_model(ctx->resource_manager->load<render::model>("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<model>("moon.mdl"));
ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load<render::model>("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<material>("fixed-star.mtl");
render::material* star_material = ctx->resource_manager->load<render::material>("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);

+ 1
- 2
src/game/states/nuptial-flight.cpp View File

@ -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<entity::component::terrain>(planet_eid);
// Enable clouds in sky pass
ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load<model>("cloud-plane.mdl"));
ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load<render::model>("cloud-plane.mdl"));
// Create observer
entity::id observer_eid = ctx->entity_registry->create();

+ 2
- 2
src/game/tools.cpp View File

@ -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<float4>* tint = static_cast<material_property<float4>*>(ctx->camera_flash_billboard->get_material()->get_property("tint"));
render::material_property<float4>* tint = static_cast<render::material_property<float4>*>(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);

+ 0
- 2
src/input/control-set.hpp View File

@ -28,8 +28,6 @@ class control;
/**
* A set of controls which can be managed simultaneously.
*
* @ingroup input
*/
class control_set
{

+ 0
- 2
src/input/gamepad.hpp View File

@ -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
{

+ 0
- 2
src/input/mapping.hpp View File

@ -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
{

src/renderer/compositor.cpp → src/render/compositor.cpp View File

@ -17,15 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/compositor.hpp → src/render/compositor.hpp View File

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <list>
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<render_pass*>* get_passes() const;
const std::list<pass*>* get_passes() const;
private:
std::list<render_pass*> passes;
std::list<pass*> passes;
};
inline const std::list<render_pass*>* compositor::get_passes() const
inline const std::list<pass*>* compositor::get_passes() const
{
return &passes;
}
#endif // ANTKEEPER_COMPOSITOR_HPP
} // namespace render
#endif // ANTKEEPER_RENDER_COMPOSITOR_HPP

src/renderer/context.hpp → src/render/context.hpp View File


src/renderer/material-flags.hpp → src/render/material-flags.hpp View File


src/renderer/material-property.cpp → src/render/material-property.cpp View File

@ -17,9 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/material-property.hpp → src/render/material-property.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cstddef>
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

src/renderer/material.cpp → src/render/material.cpp View File

@ -17,8 +17,9 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/material.hpp → src/render/material.hpp View File

@ -17,17 +17,19 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cstdint>
#include <cstddef>
#include <list>
#include <map>
#include <unordered_map>
#include <string>
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<material_property_base*> properties;
std::map<std::string, material_property_base*> property_map;
std::unordered_map<std::string, material_property_base*> property_map;
};
template <typename T>
@ -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

src/renderer/model.cpp → src/render/model.cpp View File

@ -17,7 +17,9 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/model.hpp → src/render/model.hpp View File

@ -17,20 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <map>
#include <unordered_map>
#include <string>
#include <vector>
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<model_group*> groups;
std::map<std::string, model_group*> group_map;
std::unordered_map<std::string, model_group*> 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

src/renderer/operation.hpp → src/render/operation.hpp View File

@ -26,10 +26,11 @@
#include <cstddef>
class pose;
class material;
namespace render {
class material;
/**
* Encapsulates an atomic render operation.
*/

src/renderer/render-pass.cpp → src/render/pass.cpp View File

@ -17,19 +17,22 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/render-pass.hpp → src/render/pass.hpp View File

@ -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

src/renderer/passes/bloom-pass.cpp → src/render/passes/bloom-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <glad/glad.h>
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

src/renderer/passes/bloom-pass.hpp → src/render/passes/bloom-pass.hpp View File

@ -17,11 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/passes/clear-pass.cpp → src/render/passes/clear-pass.cpp View File

@ -17,13 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "renderer/passes/clear-pass.hpp"
#include "render/passes/clear-pass.hpp"
#include "gl/rasterizer.hpp"
#include "gl/framebuffer.hpp"
#include <glad/glad.h>
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

src/renderer/passes/clear-pass.hpp → src/render/passes/clear-pass.hpp View File

@ -17,26 +17,52 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/passes/final-pass.cpp → src/render/passes/final-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <glad/glad.h>
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<float>(texture->get_dimensions()[0]);
}
} // namespace render

src/renderer/passes/final-pass.hpp → src/render/passes/final-pass.hpp View File

@ -17,24 +17,24 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/passes/material-pass.cpp → src/render/passes/material-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <glad/glad.h>
#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

src/renderer/passes/material-pass.hpp → src/render/passes/material-pass.hpp View File

@ -17,28 +17,29 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <unordered_map>
#include "gl/shader-program.hpp"
#include "gl/shader-input.hpp"
#include "gl/texture-2d.hpp"
#include <unordered_map>
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<mouse_moved_event>
{
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

src/renderer/passes/outline-pass.cpp → src/render/passes/outline-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <glad/glad.h>
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

src/renderer/passes/outline-pass.hpp → src/render/passes/outline-pass.hpp View File

@ -17,20 +17,22 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/passes/shadow-map-pass.cpp → src/render/passes/shadow-map-pass.cpp View File

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <glad/glad.h>
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

src/renderer/passes/shadow-map-pass.hpp → src/render/passes/shadow-map-pass.hpp View File

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/simple-render-pass.cpp → src/render/passes/simple-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <glad/glad.h>
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<float>("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

src/renderer/simple-render-pass.hpp → src/render/passes/simple-pass.hpp View File

@ -17,17 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 T>
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

src/renderer/passes/sky-pass.cpp → src/render/passes/sky-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <stdexcept>
#include <glad/glad.h>
#include <iostream>
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<float>(event.x), static_cast<float>(event.y)};
}
} // namespace render

src/renderer/passes/sky-pass.hpp → src/render/passes/sky-pass.hpp View File

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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<mouse_moved_event>
{
public:
@ -153,4 +156,6 @@ private:
float3 atmosphere_radii;
};
#endif // ANTKEEPER_SKY_PASS_HPP
} // namespace render
#endif // ANTKEEPER_RENDER_SKY_PASS_HPP

src/renderer/passes/ui-pass.cpp → src/render/passes/ui-pass.cpp View File

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cmath>
#include <glad/glad.h>
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

src/renderer/passes/ui-pass.hpp → src/render/passes/ui-pass.hpp View File

@ -17,11 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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<const gl::shader_program*, parameter_set*> parameter_sets;
};
#endif // ANTKEEPER_UI_PASS_HPP
} // namespace render
#endif // ANTKEEPER_RENDER_UI_PASS_HPP

src/renderer/queue.hpp → src/render/queue.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_RENDER_QUEUE_HPP
#define ANTKEEPER_RENDER_QUEUE_HPP
#include "renderer/operation.hpp"
#include "render/operation.hpp"
#include <list>
namespace render {

+ 28
- 0
src/render/render.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_RENDER_HPP
#define ANTKEEPER_RENDER_HPP
/**
* High-level rendering.
*/
namespace render {}
#endif // ANTKEEPER_RENDER_HPP

src/renderer/renderer.cpp → src/render/renderer.cpp View File

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <functional>
#include <set>
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

src/renderer/renderer.hpp → src/render/renderer.hpp View File

@ -17,12 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

src/renderer/shader-template.cpp → src/render/shader-template.cpp View File

@ -17,10 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "renderer/shader-template.hpp"
#include "render/shader-template.hpp"
#include <algorithm>
#include <sstream>
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

src/renderer/shader-template.hpp → src/render/shader-template.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <unordered_set>
#include <vector>
namespace render {
/**
* Shader templates can be used to generate multiple shader variants from a single source.
*
@ -129,4 +131,6 @@ private:
std::multimap<std::string, std::size_t> define_directives;
};
#endif // ANTKEEPER_SHADER_TEMPLATE_HPP
} // namespace render
#endif // ANTKEEPER_RENDER_SHADER_TEMPLATE_HPP

src/renderer/vertex-attribute.hpp → src/render/vertex-attribute.hpp View File

@ -17,35 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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

+ 2
- 2
src/resources/entity-archetype-loader.cpp View File

@ -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<model>(element["file"].get<std::string>());
component.render_model = resource_manager.load<render::model>(element["file"].get<std::string>());
}
archetype.set<entity::component::model>(component);

+ 17
- 17
src/resources/material-loader.cpp View File

@ -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 <nlohmann/json.hpp>
#include <physfs.h>
#include <utility>
@ -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<const gl::texture_2d*>* property = material->add_property<const gl::texture_2d*>(name, array_size);
render::material_property<const gl::texture_2d*>* property = material->add_property<const gl::texture_2d*>(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<const gl::texture_2d*>* property = material->add_property<const gl::texture_2d*>(name);
render::material_property<const gl::texture_2d*>* property = material->add_property<const gl::texture_2d*>(name);
// Load texture
std::string filename = json.get<std::string>();
@ -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 <typename T>
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<T>* property = material->add_property<T>(name, array_size);
render::material_property<T>* property = material->add_property<T>(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<T>* property = material->add_property<T>(name);
render::material_property<T>* property = material->add_property<T>(name);
// Set property value
property->set_value(json.get<T>());
@ -108,7 +108,7 @@ static bool load_scalar_property(material* material, const std::string& name, co
}
template <typename T>
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<T>* property = material->add_property<T>(name, array_size);
render::material_property<T>* property = material->add_property<T>(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<T>* property = material->add_property<T>(name);
render::material_property<T>* property = material->add_property<T>(name);
// Read vector elements
T value;
@ -152,7 +152,7 @@ static bool load_vector_property(material* material, const std::string& name, st
}
template <typename T>
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<T>* property = material->add_property<T>(name, array_size);
render::material_property<T>* property = material->add_property<T>(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<T>* property = material->add_property<T>(name);
render::material_property<T>* property = material->add_property<T>(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<material>::load(resource_manager* resource_manager, PHYSFS_File* file)
render::material* resource_loader<render::material>::load(resource_manager* resource_manager, PHYSFS_File* file)
{
// Read file into buffer
std::size_t size = static_cast<int>(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;

+ 7
- 7
src/resources/model-loader.cpp View File

@ -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<model>::load(resource_manager* resource_manager, PHYSFS_File* file)
render::model* resource_loader<render::model>::load(resource_manager* resource_manager, PHYSFS_File* file)
{
// Read file into buffer
std::size_t size = static_cast<int>(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<std::string>();
@ -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>(material_filename);
group_material = resource_manager->load<render::material>(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);

+ 3
- 3
src/resources/shader-program-loader.cpp View File

@ -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 <sstream>
@ -89,10 +89,10 @@ gl::shader_program* resource_loader::load(resource_manager*
std::copy(source_lines.begin(), source_lines.end(), std::ostream_iterator<std::string>(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())

+ 1
- 2
src/scene/billboard.cpp View File

@ -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;
}

+ 5
- 6
src/scene/billboard.hpp View File

@ -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;
}

+ 1
- 1
src/scene/camera.cpp View File

@ -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;
}

+ 7
- 9
src/scene/camera.hpp View File

@ -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<float>& 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<float> 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;
}

+ 8
- 8
src/scene/model-instance.cpp View File

@ -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)
{

+ 12
- 13
src/scene/model-instance.hpp View File

@ -22,10 +22,9 @@
#include "scene/object.hpp"
#include "geom/aabb.hpp"
#include "render/model.hpp"
#include <vector>
class material;
class model;
class pose;
namespace scene {
@ -35,7 +34,7 @@ class model_instance: public object
public:
typedef geom::aabb<float> 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<material*>* get_materials() const;
const std::vector<render::material*>* 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<material*> materials;
std::vector<render::material*> 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<material*>* model_instance::get_materials() const
inline const std::vector<render::material*>* model_instance::get_materials() const
{
return &materials;
}

+ 4
- 3
src/scene/object.hpp View File

@ -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 <atomic>
#include <cstddef>
@ -248,7 +248,8 @@ class object: public object_base
public:
/// Unique type ID for this scene object type.
static const std::atomic<std::size_t> object_type_id;
/// @copydoc object_base::get_object_type_id() const
virtual const std::size_t get_object_type_id() const final;
};

+ 2
- 3
src/scene/text.cpp View File

@ -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 <cstddef>
#include <codecvt>
@ -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;

+ 5
- 5
src/scene/text.hpp View File

@ -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;
}

+ 2
- 0
src/ui/ui.hpp View File

@ -23,4 +23,6 @@
/// UI elements
namespace ui {}
#include "ui/element.hpp"
#endif // ANTKEEPER_UI_HPP

Loading…
Cancel
Save