Browse Source

Rename rasterizer folder to gl and put all files in the gl folder into the gl namespace

master
C. J. Howard 9 months ago
parent
commit
ccbbd08b32
77 changed files with 791 additions and 704 deletions
  1. +0
    -1
      CMakeLists.txt
  2. +1
    -2
      src/application.cpp
  3. +4
    -4
      src/application.hpp
  4. +7
    -7
      src/ecs/systems/painting-system.cpp
  5. +2
    -2
      src/ecs/systems/painting-system.hpp
  6. +11
    -11
      src/ecs/systems/subterrain-system.cpp
  7. +11
    -11
      src/ecs/systems/terrain-system.cpp
  8. +1
    -1
      src/ecs/systems/ui-system.cpp
  9. +67
    -67
      src/game/bootloader.cpp
  10. +17
    -17
      src/game/game-context.hpp
  11. +1
    -1
      src/game/states/map-state.cpp
  12. +3
    -3
      src/game/states/play-state.cpp
  13. +1
    -1
      src/game/states/splash-state.cpp
  14. +7
    -3
      src/gl/buffer-usage.hpp
  15. +7
    -3
      src/gl/color-space.hpp
  16. +7
    -3
      src/gl/drawing-mode.hpp
  17. +7
    -3
      src/gl/element-array-type.hpp
  18. +6
    -2
      src/gl/framebuffer.cpp
  19. +6
    -3
      src/gl/framebuffer.hpp
  20. +22
    -1
      src/gl/gl.hpp
  21. +7
    -3
      src/gl/pixel-format.hpp
  22. +7
    -3
      src/gl/pixel-type.hpp
  23. +8
    -5
      src/gl/rasterizer.cpp
  24. +8
    -4
      src/gl/rasterizer.hpp
  25. +6
    -3
      src/gl/shader-input.cpp
  26. +7
    -3
      src/gl/shader-input.hpp
  27. +7
    -4
      src/gl/shader-program.cpp
  28. +7
    -3
      src/gl/shader-program.hpp
  29. +7
    -3
      src/gl/shader-type.hpp
  30. +7
    -3
      src/gl/shader-variable-type.hpp
  31. +4
    -1
      src/gl/shader.cpp
  32. +7
    -3
      src/gl/shader.hpp
  33. +10
    -7
      src/gl/texture-2d.cpp
  34. +16
    -12
      src/gl/texture-2d.hpp
  35. +4
    -1
      src/gl/texture-cube.cpp
  36. +7
    -3
      src/gl/texture-cube.hpp
  37. +7
    -3
      src/gl/texture-filter.hpp
  38. +7
    -3
      src/gl/texture-wrapping.hpp
  39. +5
    -2
      src/gl/vertex-array.cpp
  40. +7
    -3
      src/gl/vertex-array.hpp
  41. +7
    -3
      src/gl/vertex-attribute-type.hpp
  42. +4
    -1
      src/gl/vertex-buffer.cpp
  43. +8
    -4
      src/gl/vertex-buffer.hpp
  44. +0
    -37
      src/rasterizer/buffer-usage.cpp
  45. +2
    -2
      src/renderer/material-property.cpp
  46. +51
    -51
      src/renderer/material-property.hpp
  47. +3
    -3
      src/renderer/material.cpp
  48. +6
    -6
      src/renderer/material.hpp
  49. +1
    -2
      src/renderer/model.cpp
  50. +18
    -20
      src/renderer/model.hpp
  51. +25
    -25
      src/renderer/passes/bloom-pass.cpp
  52. +22
    -22
      src/renderer/passes/bloom-pass.hpp
  53. +3
    -3
      src/renderer/passes/clear-pass.cpp
  54. +1
    -1
      src/renderer/passes/clear-pass.hpp
  55. +19
    -19
      src/renderer/passes/final-pass.cpp
  56. +16
    -16
      src/renderer/passes/final-pass.hpp
  57. +20
    -20
      src/renderer/passes/material-pass.cpp
  58. +41
    -41
      src/renderer/passes/material-pass.hpp
  59. +11
    -11
      src/renderer/passes/outline-pass.cpp
  60. +9
    -9
      src/renderer/passes/outline-pass.hpp
  61. +10
    -10
      src/renderer/passes/shadow-map-pass.cpp
  62. +7
    -7
      src/renderer/passes/shadow-map-pass.hpp
  63. +13
    -13
      src/renderer/passes/sky-pass.cpp
  64. +35
    -35
      src/renderer/passes/sky-pass.hpp
  65. +15
    -15
      src/renderer/passes/ui-pass.cpp
  66. +8
    -8
      src/renderer/passes/ui-pass.hpp
  67. +4
    -4
      src/renderer/render-operation.hpp
  68. +1
    -1
      src/renderer/render-pass.cpp
  69. +6
    -5
      src/renderer/render-pass.hpp
  70. +3
    -3
      src/renderer/renderer.cpp
  71. +2
    -2
      src/renderer/renderer.hpp
  72. +16
    -16
      src/renderer/simple-render-pass.cpp
  73. +8
    -8
      src/renderer/simple-render-pass.hpp
  74. +26
    -26
      src/resources/material-loader.cpp
  75. +6
    -6
      src/resources/model-loader.cpp
  76. +19
    -19
      src/resources/shader-program-loader.cpp
  77. +12
    -12
      src/resources/texture-2d-loader.cpp

+ 0
- 1
CMakeLists.txt View File

@ -14,7 +14,6 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies
set(STATIC_LIBS
dr_wav

+ 1
- 2
src/application.cpp View File

@ -29,7 +29,6 @@
#include "input/keyboard.hpp"
#include "input/mouse.hpp"
#include "input/game-controller.hpp"
#include "rasterizer/rasterizer.hpp"
#include "resources/image.hpp"
#include <SDL2/SDL.h>
#include <glad/glad.h>
@ -203,7 +202,7 @@ application::application():
*/
// Setup rasterizer
rasterizer = new ::rasterizer();
rasterizer = new gl::rasterizer();
// Setup events
event_dispatcher = new ::event_dispatcher();

+ 4
- 4
src/application.hpp View File

@ -25,6 +25,7 @@
#include <list>
#include <memory>
#include <unordered_map>
#include "gl/rasterizer.hpp"
// Forward declarations
typedef struct SDL_Window SDL_Window;
@ -34,7 +35,6 @@ class frame_scheduler;
class game_controller;
class keyboard;
class mouse;
class rasterizer;
class image;
namespace debug
@ -180,7 +180,7 @@ public:
bool is_fullscreen() const;
/// Returns the rasterizer for the window.
::rasterizer* get_rasterizer();
gl::rasterizer* get_rasterizer();
/// Returns the application logger.
debug::logger* get_logger();
@ -222,7 +222,7 @@ private:
SDL_Window* sdl_window;
SDL_GLContext sdl_gl_context;
rasterizer* rasterizer;
gl::rasterizer* rasterizer;
// Frame timing
frame_scheduler* frame_scheduler;
@ -263,7 +263,7 @@ inline bool application::is_fullscreen() const
return fullscreen;
}
inline rasterizer* application::get_rasterizer()
inline gl::rasterizer* application::get_rasterizer()
{
return rasterizer;
}

+ 7
- 7
src/ecs/systems/painting-system.cpp View File

@ -30,8 +30,8 @@
#include "ecs/commands.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "rasterizer/vertex-buffer.hpp"
#include "rasterizer/vertex-attribute-type.hpp"
#include "gl/vertex-buffer.hpp"
#include "gl/vertex-attribute-type.hpp"
#include "renderer/vertex-attributes.hpp"
#include "geom/mesh-functions.hpp"
#include <limits>
@ -66,11 +66,11 @@ painting_system::painting_system(ecs::registry& registry, ::event_dispatcher* ev
// Setup stroke vbo and vao
stroke_vbo = stroke_model->get_vertex_buffer();
stroke_vbo->repurpose(sizeof(float) * vertex_size * vertex_count, nullptr, buffer_usage::dynamic_draw);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_POSITION_LOCATION, *stroke_vbo, 4, vertex_attribute_type::float_32, vertex_stride, 0);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_NORMAL_LOCATION, *stroke_vbo, 3, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 4);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_TEXCOORD_LOCATION, *stroke_vbo, 2, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 7);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_TANGENT_LOCATION, *stroke_vbo, 4, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 9);
stroke_vbo->repurpose(sizeof(float) * vertex_size * vertex_count, nullptr, gl::buffer_usage::dynamic_draw);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_POSITION_LOCATION, *stroke_vbo, 4, gl::vertex_attribute_type::float_32, vertex_stride, 0);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_NORMAL_LOCATION, *stroke_vbo, 3, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 4);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_TEXCOORD_LOCATION, *stroke_vbo, 2, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 7);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_TANGENT_LOCATION, *stroke_vbo, 4, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 9);
// Create stroke model instance
stroke_model_instance = new scene::model_instance();

+ 2
- 2
src/ecs/systems/painting-system.hpp View File

@ -27,6 +27,7 @@
#include "utility/fundamental-types.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "gl/vertex-buffer.hpp"
#include <vector>
#include <optional>
@ -35,7 +36,6 @@ class event_dispatcher;
class resource_manager;
class model;
class model_group;
class vertex_buffer;
namespace ecs {
@ -83,7 +83,7 @@ private:
model* stroke_model;
model_group* stroke_model_group;
vertex_buffer* stroke_vbo;
gl::vertex_buffer* stroke_vbo;
bool midstroke;
scene::model_instance* stroke_model_instance;

+ 11
- 11
src/ecs/systems/subterrain-system.cpp View File

@ -25,9 +25,9 @@
#include "renderer/material.hpp"
#include "geom/mesh-functions.hpp"
#include "renderer/vertex-attributes.hpp"
#include "rasterizer/vertex-attribute-type.hpp"
#include "rasterizer/drawing-mode.hpp"
#include "rasterizer/vertex-buffer.hpp"
#include "gl/vertex-attribute-type.hpp"
#include "gl/drawing-mode.hpp"
#include "gl/vertex-buffer.hpp"
#include "resources/resource-manager.hpp"
#include "geom/marching-cubes.hpp"
#include "geom/intersection.hpp"
@ -203,14 +203,14 @@ subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager
// 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_drawing_mode(drawing_mode::triangles);
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_drawing_mode(drawing_mode::triangles);
subterrain_outside_group->set_drawing_mode(gl::drawing_mode::triangles);
subterrain_outside_group->set_start_index(0);
subterrain_outside_group->set_index_count(0);
@ -219,14 +219,14 @@ subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager
subterrain_model_vertex_stride = subterrain_model_vertex_size * sizeof(float);
// Bind vertex attributes
vertex_buffer* vbo = subterrain_model->get_vertex_buffer();
vertex_array* vao = subterrain_model->get_vertex_array();
gl::vertex_buffer* vbo = subterrain_model->get_vertex_buffer();
gl::vertex_array* vao = subterrain_model->get_vertex_array();
std::size_t offset = 0;
vao->bind_attribute(VERTEX_POSITION_LOCATION, *vbo, 3, vertex_attribute_type::float_32, subterrain_model_vertex_stride, 0);
vao->bind_attribute(VERTEX_POSITION_LOCATION, *vbo, 3, gl::vertex_attribute_type::float_32, subterrain_model_vertex_stride, 0);
offset += 3;
vao->bind_attribute(VERTEX_NORMAL_LOCATION, *vbo, 3, vertex_attribute_type::float_32, subterrain_model_vertex_stride, sizeof(float) * offset);
vao->bind_attribute(VERTEX_NORMAL_LOCATION, *vbo, 3, gl::vertex_attribute_type::float_32, subterrain_model_vertex_stride, sizeof(float) * offset);
offset += 3;
vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *vbo, 3, vertex_attribute_type::float_32, subterrain_model_vertex_stride, sizeof(float) * offset);
vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *vbo, 3, gl::vertex_attribute_type::float_32, subterrain_model_vertex_stride, sizeof(float) * offset);
offset += 3;
// Calculate adjusted bounds to fit isosurface resolution
@ -438,7 +438,7 @@ void subterrain_system::regenerate_subterrain_model()
}
// Resized VBO and upload vertex data
vertex_buffer* vbo = subterrain_model->get_vertex_buffer();
gl::vertex_buffer* vbo = subterrain_model->get_vertex_buffer();
vbo->resize(subterrain_mesh->get_faces().size() * 3 * subterrain_model_vertex_stride, vertex_data);
// Deallocate vertex data

+ 11
- 11
src/ecs/systems/terrain-system.cpp View File

@ -26,9 +26,9 @@
#include "geom/mesh.hpp"
#include "geom/mesh-functions.hpp"
#include "renderer/vertex-attributes.hpp"
#include "rasterizer/vertex-attribute-type.hpp"
#include "rasterizer/drawing-mode.hpp"
#include "rasterizer/vertex-buffer.hpp"
#include "gl/vertex-attribute-type.hpp"
#include "gl/drawing-mode.hpp"
#include "gl/vertex-buffer.hpp"
#include "resources/resource-manager.hpp"
#include "resources/image.hpp"
#include "utility/fundamental-types.hpp"
@ -82,8 +82,8 @@ model* terrain_system::generate_terrain_model(geom::mesh* terrain_mesh)
model* terrain_model = new model();
// Get model's VAO and VBO
vertex_buffer* vbo = terrain_model->get_vertex_buffer();
vertex_array* vao = terrain_model->get_vertex_array();
gl::vertex_buffer* vbo = terrain_model->get_vertex_buffer();
gl::vertex_array* vao = terrain_model->get_vertex_array();
// Resize VBO
int vertex_size = 3 + 2 + 3 + 4 + 3;
@ -92,21 +92,21 @@ model* terrain_system::generate_terrain_model(geom::mesh* terrain_mesh)
// Bind vertex attributes
std::size_t offset = 0;
vao->bind_attribute(VERTEX_POSITION_LOCATION, *vbo, 3, vertex_attribute_type::float_32, vertex_stride, 0);
vao->bind_attribute(VERTEX_POSITION_LOCATION, *vbo, 3, gl::vertex_attribute_type::float_32, vertex_stride, 0);
offset += 3;
vao->bind_attribute(VERTEX_TEXCOORD_LOCATION, *vbo, 2, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
vao->bind_attribute(VERTEX_TEXCOORD_LOCATION, *vbo, 2, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 2;
vao->bind_attribute(VERTEX_NORMAL_LOCATION, *vbo, 3, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
vao->bind_attribute(VERTEX_NORMAL_LOCATION, *vbo, 3, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 3;
vao->bind_attribute(VERTEX_TANGENT_LOCATION, *vbo, 4, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
vao->bind_attribute(VERTEX_TANGENT_LOCATION, *vbo, 4, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 4;
vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *vbo, 3, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *vbo, 3, gl::vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 3;
// Create model group
model_group* model_group = terrain_model->add_group("terrain");
model_group->set_material(resource_manager->load<material>("grassland-terrain.mtl"));
model_group->set_drawing_mode(drawing_mode::triangles);
model_group->set_drawing_mode(gl::drawing_mode::triangles);
model_group->set_start_index(0);
model_group->set_index_count(terrain_mesh->get_faces().size() * 3);

+ 1
- 1
src/ecs/systems/ui-system.cpp View File

@ -37,7 +37,7 @@ ui_system::ui_system(::resource_manager* resource_manager):
direct_light.update_tweens();
// Setup modal background
modal_bg_material.set_shader_program(resource_manager->load<shader_program>("ui-element-untextured.glsl"));
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);

+ 67
- 67
src/game/bootloader.cpp View File

@ -27,16 +27,16 @@
#include "debug/console-commands.hpp"
#include "debug/logger.hpp"
#include "game/game-context.hpp"
#include "rasterizer/framebuffer.hpp"
#include "rasterizer/pixel-format.hpp"
#include "rasterizer/pixel-type.hpp"
#include "rasterizer/rasterizer.hpp"
#include "rasterizer/texture-2d.hpp"
#include "rasterizer/texture-filter.hpp"
#include "rasterizer/texture-wrapping.hpp"
#include "rasterizer/vertex-array.hpp"
#include "rasterizer/vertex-attribute-type.hpp"
#include "rasterizer/vertex-buffer.hpp"
#include "gl/framebuffer.hpp"
#include "gl/pixel-format.hpp"
#include "gl/pixel-type.hpp"
#include "gl/rasterizer.hpp"
#include "gl/texture-2d.hpp"
#include "gl/texture-filter.hpp"
#include "gl/texture-wrapping.hpp"
#include "gl/vertex-array.hpp"
#include "gl/vertex-attribute-type.hpp"
#include "gl/vertex-buffer.hpp"
#include "renderer/material-flags.hpp"
#include "renderer/material-property.hpp"
#include "renderer/passes/bloom-pass.hpp"
@ -443,22 +443,22 @@ void setup_rendering(game_context* ctx)
ctx->rasterizer = ctx->app->get_rasterizer();
// Get default framebuffer
const framebuffer& default_framebuffer = ctx->rasterizer->get_default_framebuffer();
const gl::framebuffer& default_framebuffer = ctx->rasterizer->get_default_framebuffer();
const auto& viewport_dimensions = default_framebuffer.get_dimensions();
// Create HDR framebuffer (32F color, 32F depth)
ctx->framebuffer_hdr_color = new texture_2d(viewport_dimensions[0], viewport_dimensions[1], pixel_type::float_32, pixel_format::rgb);
ctx->framebuffer_hdr_color->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp);
ctx->framebuffer_hdr_color->set_filters(texture_min_filter::linear, texture_mag_filter::linear);
ctx->framebuffer_hdr_color = new gl::texture_2d(viewport_dimensions[0], viewport_dimensions[1], gl::pixel_type::float_32, gl::pixel_format::rgb);
ctx->framebuffer_hdr_color->set_wrapping(gl::texture_wrapping::clamp, gl::texture_wrapping::clamp);
ctx->framebuffer_hdr_color->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
ctx->framebuffer_hdr_color->set_max_anisotropy(0.0f);
ctx->framebuffer_hdr_depth = new texture_2d(viewport_dimensions[0], viewport_dimensions[1], pixel_type::float_32, pixel_format::ds);
ctx->framebuffer_hdr_depth->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp);
ctx->framebuffer_hdr_depth->set_filters(texture_min_filter::linear, texture_mag_filter::linear);
ctx->framebuffer_hdr_depth = new gl::texture_2d(viewport_dimensions[0], viewport_dimensions[1], gl::pixel_type::float_32, gl::pixel_format::ds);
ctx->framebuffer_hdr_depth->set_wrapping(gl::texture_wrapping::clamp, gl::texture_wrapping::clamp);
ctx->framebuffer_hdr_depth->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
ctx->framebuffer_hdr_depth->set_max_anisotropy(0.0f);
ctx->framebuffer_hdr = new framebuffer(viewport_dimensions[0], viewport_dimensions[1]);
ctx->framebuffer_hdr->attach(framebuffer_attachment_type::color, ctx->framebuffer_hdr_color);
ctx->framebuffer_hdr->attach(framebuffer_attachment_type::depth, ctx->framebuffer_hdr_depth);
ctx->framebuffer_hdr->attach(framebuffer_attachment_type::stencil, ctx->framebuffer_hdr_depth);
ctx->framebuffer_hdr = new gl::framebuffer(viewport_dimensions[0], viewport_dimensions[1]);
ctx->framebuffer_hdr->attach(gl::framebuffer_attachment_type::color, ctx->framebuffer_hdr_color);
ctx->framebuffer_hdr->attach(gl::framebuffer_attachment_type::depth, ctx->framebuffer_hdr_depth);
ctx->framebuffer_hdr->attach(gl::framebuffer_attachment_type::stencil, ctx->framebuffer_hdr_depth);
// Create shadow map framebuffer
int shadow_map_resolution = 4096;
@ -466,29 +466,29 @@ void setup_rendering(game_context* ctx)
{
shadow_map_resolution = ctx->config->get<int>("shadow_map_resolution");
}
ctx->shadow_map_depth_texture = new texture_2d(shadow_map_resolution, shadow_map_resolution, pixel_type::float_32, pixel_format::d);
ctx->shadow_map_depth_texture->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp);
ctx->shadow_map_depth_texture->set_filters(texture_min_filter::linear, texture_mag_filter::linear);
ctx->shadow_map_depth_texture = new gl::texture_2d(shadow_map_resolution, shadow_map_resolution, gl::pixel_type::float_32, gl::pixel_format::d);
ctx->shadow_map_depth_texture->set_wrapping(gl::texture_wrapping::clamp, gl::texture_wrapping::clamp);
ctx->shadow_map_depth_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
ctx->shadow_map_depth_texture->set_max_anisotropy(0.0f);
ctx->shadow_map_framebuffer = new framebuffer(shadow_map_resolution, shadow_map_resolution);
ctx->shadow_map_framebuffer->attach(framebuffer_attachment_type::depth, ctx->shadow_map_depth_texture);
ctx->shadow_map_framebuffer = new gl::framebuffer(shadow_map_resolution, shadow_map_resolution);
ctx->shadow_map_framebuffer->attach(gl::framebuffer_attachment_type::depth, ctx->shadow_map_depth_texture);
// Create bloom pingpong framebuffers (16F color, no depth)
int bloom_width = viewport_dimensions[0] >> 1;
int bloom_height = viewport_dimensions[1] >> 1;
ctx->bloom_texture = new texture_2d(bloom_width, bloom_height, pixel_type::float_16, pixel_format::rgb);
ctx->bloom_texture->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp);
ctx->bloom_texture->set_filters(texture_min_filter::linear, texture_mag_filter::linear);
ctx->bloom_texture = new gl::texture_2d(bloom_width, bloom_height, gl::pixel_type::float_16, gl::pixel_format::rgb);
ctx->bloom_texture->set_wrapping(gl::texture_wrapping::clamp, gl::texture_wrapping::clamp);
ctx->bloom_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
ctx->bloom_texture->set_max_anisotropy(0.0f);
ctx->framebuffer_bloom = new framebuffer(bloom_width, bloom_height);
ctx->framebuffer_bloom->attach(framebuffer_attachment_type::color, ctx->bloom_texture);
ctx->framebuffer_bloom = new gl::framebuffer(bloom_width, bloom_height);
ctx->framebuffer_bloom->attach(gl::framebuffer_attachment_type::color, ctx->bloom_texture);
// Load blue noise texture
texture_2d* blue_noise_map = ctx->resource_manager->load<texture_2d>("blue-noise.png");
blue_noise_map->set_wrapping(texture_wrapping::repeat, texture_wrapping::repeat);
blue_noise_map->set_wrapping(texture_wrapping::repeat, texture_wrapping::repeat);
blue_noise_map->set_filters(texture_min_filter::nearest, texture_mag_filter::nearest);
blue_noise_map->set_filters(texture_min_filter::nearest, texture_mag_filter::nearest);
gl::texture_2d* blue_noise_map = ctx->resource_manager->load<gl::texture_2d>("blue-noise.png");
blue_noise_map->set_wrapping(gl::texture_wrapping::repeat, gl::texture_wrapping::repeat);
blue_noise_map->set_wrapping(gl::texture_wrapping::repeat, gl::texture_wrapping::repeat);
blue_noise_map->set_filters(gl::texture_min_filter::nearest, gl::texture_mag_filter::nearest);
blue_noise_map->set_filters(gl::texture_min_filter::nearest, gl::texture_mag_filter::nearest);
// Load fallback material
ctx->fallback_material = ctx->resource_manager->load<material>("fallback.mtl");
@ -538,9 +538,9 @@ void setup_rendering(game_context* ctx)
ctx->underworld_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->underworld_material_pass->set_fallback_material(ctx->fallback_material);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->underworld_material_pass);
shader_program* underworld_final_shader = ctx->resource_manager->load<shader_program>("underground-final.glsl");
gl::shader_program* underworld_final_shader = ctx->resource_manager->load<gl::shader_program>("underground-final.glsl");
ctx->underworld_final_pass = new simple_render_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), underworld_final_shader);
ctx->underground_color_texture_property = ctx->underworld_final_pass->get_material()->add_property<const texture_2d*>("color_texture");
ctx->underground_color_texture_property = ctx->underworld_final_pass->get_material()->add_property<const gl::texture_2d*>("color_texture");
ctx->underground_color_texture_property->set_value(ctx->framebuffer_hdr_color);
ctx->underworld_final_pass->get_material()->update_tweens();
ctx->underworld_compositor = new compositor();
@ -574,28 +574,28 @@ void setup_rendering(game_context* ctx)
std::size_t billboard_vertex_stride = sizeof(float) * billboard_vertex_size;
std::size_t billboard_vertex_count = 6;
ctx->billboard_vbo = new vertex_buffer(sizeof(float) * billboard_vertex_size * billboard_vertex_count, billboard_vertex_data);
ctx->billboard_vao = new vertex_array();
ctx->billboard_vao->bind_attribute(VERTEX_POSITION_LOCATION, *ctx->billboard_vbo, 3, vertex_attribute_type::float_32, billboard_vertex_stride, 0);
ctx->billboard_vao->bind_attribute(VERTEX_TEXCOORD_LOCATION, *ctx->billboard_vbo, 2, vertex_attribute_type::float_32, billboard_vertex_stride, sizeof(float) * 3);
ctx->billboard_vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *ctx->billboard_vbo, 3, vertex_attribute_type::float_32, billboard_vertex_stride, sizeof(float) * 5);
ctx->billboard_vbo = new gl::vertex_buffer(sizeof(float) * billboard_vertex_size * billboard_vertex_count, billboard_vertex_data);
ctx->billboard_vao = new gl::vertex_array();
ctx->billboard_vao->bind_attribute(VERTEX_POSITION_LOCATION, *ctx->billboard_vbo, 3, gl::vertex_attribute_type::float_32, billboard_vertex_stride, 0);
ctx->billboard_vao->bind_attribute(VERTEX_TEXCOORD_LOCATION, *ctx->billboard_vbo, 2, gl::vertex_attribute_type::float_32, billboard_vertex_stride, sizeof(float) * 3);
ctx->billboard_vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *ctx->billboard_vbo, 3, gl::vertex_attribute_type::float_32, billboard_vertex_stride, sizeof(float) * 5);
}
// Load marker albedo textures
ctx->marker_albedo_textures = new texture_2d*[8];
ctx->marker_albedo_textures[0] = ctx->resource_manager->load<texture_2d>("marker-clear-albedo.png");
ctx->marker_albedo_textures[1] = ctx->resource_manager->load<texture_2d>("marker-yellow-albedo.png");
ctx->marker_albedo_textures[2] = ctx->resource_manager->load<texture_2d>("marker-green-albedo.png");
ctx->marker_albedo_textures[3] = ctx->resource_manager->load<texture_2d>("marker-blue-albedo.png");
ctx->marker_albedo_textures[4] = ctx->resource_manager->load<texture_2d>("marker-purple-albedo.png");
ctx->marker_albedo_textures[5] = ctx->resource_manager->load<texture_2d>("marker-pink-albedo.png");
ctx->marker_albedo_textures[6] = ctx->resource_manager->load<texture_2d>("marker-red-albedo.png");
ctx->marker_albedo_textures[7] = ctx->resource_manager->load<texture_2d>("marker-orange-albedo.png");
ctx->marker_albedo_textures = new gl::texture_2d*[8];
ctx->marker_albedo_textures[0] = ctx->resource_manager->load<gl::texture_2d>("marker-clear-albedo.png");
ctx->marker_albedo_textures[1] = ctx->resource_manager->load<gl::texture_2d>("marker-yellow-albedo.png");
ctx->marker_albedo_textures[2] = ctx->resource_manager->load<gl::texture_2d>("marker-green-albedo.png");
ctx->marker_albedo_textures[3] = ctx->resource_manager->load<gl::texture_2d>("marker-blue-albedo.png");
ctx->marker_albedo_textures[4] = ctx->resource_manager->load<gl::texture_2d>("marker-purple-albedo.png");
ctx->marker_albedo_textures[5] = ctx->resource_manager->load<gl::texture_2d>("marker-pink-albedo.png");
ctx->marker_albedo_textures[6] = ctx->resource_manager->load<gl::texture_2d>("marker-red-albedo.png");
ctx->marker_albedo_textures[7] = ctx->resource_manager->load<gl::texture_2d>("marker-orange-albedo.png");
for (int i = 0; i < 8; ++i)
{
texture_2d* texture = ctx->marker_albedo_textures[i];
texture->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp);
texture->set_filters(texture_min_filter::nearest, texture_mag_filter::nearest);
gl::texture_2d* texture = ctx->marker_albedo_textures[i];
texture->set_wrapping(gl::texture_wrapping::clamp, gl::texture_wrapping::clamp);
texture->set_filters(gl::texture_min_filter::nearest, gl::texture_mag_filter::nearest);
texture->set_max_anisotropy(0.0f);
}
@ -676,11 +676,11 @@ void setup_scenes(game_context* ctx)
const texture_2d* splash_texture = ctx->resource_manager->load<texture_2d>("splash.png");
const gl::texture_2d* splash_texture = ctx->resource_manager->load<gl::texture_2d>("splash.png");
auto splash_dimensions = splash_texture->get_dimensions();
ctx->splash_billboard_material = new material();
ctx->splash_billboard_material->set_shader_program(ctx->resource_manager->load<shader_program>("ui-element-textured.glsl"));
ctx->splash_billboard_material->add_property<const texture_2d*>("background")->set_value(splash_texture);
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});
ctx->splash_billboard_material->update_tweens();
ctx->splash_billboard = new scene::billboard();
@ -693,8 +693,8 @@ void setup_scenes(game_context* ctx)
// Create depth debug billboard
/*
material* depth_debug_material = new material();
depth_debug_material->set_shader_program(ctx->resource_manager->load<shader_program>("ui-element-textured.glsl"));
depth_debug_material->add_property<const texture_2d*>("background")->set_value(shadow_map_depth_texture);
depth_debug_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
depth_debug_material->add_property<const gl::texture_2d*>("background")->set_value(shadow_map_depth_texture);
depth_debug_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
billboard* depth_debug_billboard = new billboard();
depth_debug_billboard->set_material(depth_debug_material);
@ -750,19 +750,19 @@ void setup_animation(game_context* ctx)
// Create fade transition
ctx->fade_transition = new screen_transition();
ctx->fade_transition->get_material()->set_shader_program(ctx->resource_manager->load<shader_program>("fade-transition.glsl"));
ctx->fade_transition->get_material()->set_shader_program(ctx->resource_manager->load<gl::shader_program>("fade-transition.glsl"));
ctx->ui_scene->add_object(ctx->fade_transition->get_billboard());
ctx->animator->add_animation(ctx->fade_transition->get_animation());
// Create inner radial transition
ctx->radial_transition_inner = new screen_transition();
ctx->radial_transition_inner->get_material()->set_shader_program(ctx->resource_manager->load<shader_program>("radial-transition-inner.glsl"));
ctx->radial_transition_inner->get_material()->set_shader_program(ctx->resource_manager->load<gl::shader_program>("radial-transition-inner.glsl"));
ctx->ui_scene->add_object(ctx->radial_transition_inner->get_billboard());
ctx->animator->add_animation(ctx->radial_transition_inner->get_animation());
// Create outer radial transition
ctx->radial_transition_outer = new screen_transition();
ctx->radial_transition_outer->get_material()->set_shader_program(ctx->resource_manager->load<shader_program>("radial-transition-outer.glsl"));
ctx->radial_transition_outer->get_material()->set_shader_program(ctx->resource_manager->load<gl::shader_program>("radial-transition-outer.glsl"));
ctx->ui_scene->add_object(ctx->radial_transition_outer->get_billboard());
ctx->animator->add_animation(ctx->radial_transition_outer->get_animation());
@ -1153,7 +1153,7 @@ void setup_controls(game_context* ctx)
{
auto& marker_component = ctx->ecs_registry->get<ecs::marker_component>(ctx->marker_entity);
marker_component.color = (marker_component.color + 1) % 8;
const texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker_component.color];
const gl::texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker_component.color];
model* marker_model = ctx->render_system->get_model_instance(ctx->marker_entity)->get_model();
for (::model_group* group: *marker_model->get_groups())
@ -1161,7 +1161,7 @@ void setup_controls(game_context* ctx)
material_property_base* albedo_property = group->get_material()->get_property("albedo_texture");
if (albedo_property)
{
static_cast<material_property<const texture_2d*>*>(albedo_property)->set_value(marker_albedo_texture);
static_cast<material_property<const gl::texture_2d*>*>(albedo_property)->set_value(marker_albedo_texture);
}
}
}
@ -1173,7 +1173,7 @@ void setup_controls(game_context* ctx)
{
auto& marker_component = ctx->ecs_registry->get<ecs::marker_component>(ctx->marker_entity);
marker_component.color = (marker_component.color + 7) % 8;
const texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker_component.color];
const gl::texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker_component.color];
model* marker_model = ctx->render_system->get_model_instance(ctx->marker_entity)->get_model();
for (::model_group* group: *marker_model->get_groups())
@ -1181,7 +1181,7 @@ void setup_controls(game_context* ctx)
material_property_base* albedo_property = group->get_material()->get_property("albedo_texture");
if (albedo_property)
{
static_cast<material_property<const texture_2d*>*>(albedo_property)->set_value(marker_albedo_texture);
static_cast<material_property<const gl::texture_2d*>*>(albedo_property)->set_value(marker_albedo_texture);
}
}
}

+ 17
- 17
src/game/game-context.hpp View File

@ -25,6 +25,11 @@
#include "ecs/entity.hpp"
#include "ecs/registry.hpp"
#include "geom/aabb.hpp"
#include "gl/vertex-array.hpp"
#include "gl/vertex-buffer.hpp"
#include "gl/texture-2d.hpp"
#include "gl/rasterizer.hpp"
#include "gl/framebuffer.hpp"
#include <optional>
#include <entt/entt.hpp>
#include <fstream>
@ -40,22 +45,17 @@ class config_file;
class control;
class control_set;
class final_pass;
class framebuffer;
class material;
class input_listener;
class material_pass;
class orbit_cam;
class pheromone_matrix;
class rasterizer;
class resource_manager;
class screen_transition;
class shadow_map_pass;
class simple_render_pass;
class sky_pass;
class texture_2d;
class timeline;
class vertex_array;
class vertex_buffer;
class renderer;
class input_event_router;
class input_mapper;
@ -141,22 +141,22 @@ struct game_context
std::unordered_map<std::string, std::string>* strings;
// Framebuffers
framebuffer* shadow_map_framebuffer;
texture_2d* shadow_map_depth_texture;
framebuffer* framebuffer_hdr;
texture_2d* framebuffer_hdr_color;
texture_2d* framebuffer_hdr_depth;
framebuffer* framebuffer_bloom; // General purpose framebuffer A
texture_2d* bloom_texture;
gl::framebuffer* shadow_map_framebuffer;
gl::texture_2d* shadow_map_depth_texture;
gl::framebuffer* framebuffer_hdr;
gl::texture_2d* framebuffer_hdr_color;
gl::texture_2d* framebuffer_hdr_depth;
gl::framebuffer* framebuffer_bloom; // General purpose framebuffer A
gl::texture_2d* bloom_texture;
// Rendering
rasterizer* rasterizer;
gl::rasterizer* rasterizer;
renderer* renderer;
vertex_buffer* billboard_vbo;
vertex_array* billboard_vao;
gl::vertex_buffer* billboard_vbo;
gl::vertex_array* billboard_vao;
material* fallback_material;
material* splash_billboard_material;
texture_2d** marker_albedo_textures;
gl::texture_2d** marker_albedo_textures;
// Compositing
bloom_pass* overworld_bloom_pass;
@ -172,7 +172,7 @@ struct game_context
shadow_map_pass* overworld_shadow_map_pass;
simple_render_pass* underworld_final_pass;
sky_pass* overworld_sky_pass;
material_property<const texture_2d*>* underground_color_texture_property;
material_property<const gl::texture_2d*>* underground_color_texture_property;
compositor* overworld_compositor;
compositor* underworld_compositor;
compositor* ui_compositor;

+ 1
- 1
src/game/states/map-state.cpp View File

@ -25,7 +25,7 @@
#include "game/game-context.hpp"
#include "input/input-listener.hpp"
#include "event/input-events.hpp"
#include "rasterizer/rasterizer.hpp"
#include "gl/rasterizer.hpp"
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"

+ 3
- 3
src/game/states/play-state.cpp View File

@ -39,9 +39,9 @@
#include "math/math.hpp"
#include "nest.hpp"
#include "renderer/material.hpp"
#include "rasterizer/texture-2d.hpp"
#include "rasterizer/texture-filter.hpp"
#include "rasterizer/texture-wrapping.hpp"
#include "gl/texture-2d.hpp"
#include "gl/texture-filter.hpp"
#include "gl/texture-wrapping.hpp"
#include "renderer/model.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "resources/resource-manager.hpp"

+ 1
- 1
src/game/states/splash-state.cpp View File

@ -25,7 +25,7 @@
#include "game/game-context.hpp"
#include "input/input-listener.hpp"
#include "event/input-events.hpp"
#include "rasterizer/rasterizer.hpp"
#include "gl/rasterizer.hpp"
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"

src/rasterizer/buffer-usage.hpp → src/gl/buffer-usage.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_BUFFER_USAGE_HPP
#define ANTKEEPER_BUFFER_USAGE_HPP
#ifndef ANTKEEPER_GL_BUFFER_USAGE_HPP
#define ANTKEEPER_GL_BUFFER_USAGE_HPP
namespace gl {
enum class buffer_usage
{
@ -33,5 +35,7 @@ enum class buffer_usage
dynamic_copy
};
#endif // ANTKEEPER_BUFFER_USAGE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_BUFFER_USAGE_HPP

src/rasterizer/color-space.hpp → src/gl/color-space.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_COLOR_SPACE_HPP
#define ANTKEEPER_COLOR_SPACE_HPP
#ifndef ANTKEEPER_GL_COLOR_SPACE_HPP
#define ANTKEEPER_GL_COLOR_SPACE_HPP
namespace gl {
enum class color_space
{
@ -26,5 +28,7 @@ enum class color_space
srgb ///< sRGB color space
};
#endif // ANTKEEPER_COLOR_SPACE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_COLOR_SPACE_HPP

src/rasterizer/drawing-mode.hpp → src/gl/drawing-mode.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_DRAWING_MODE_HPP
#define ANTKEEPER_DRAWING_MODE_HPP
#ifndef ANTKEEPER_GL_DRAWING_MODE_HPP
#define ANTKEEPER_GL_DRAWING_MODE_HPP
namespace gl {
enum class drawing_mode
{
@ -35,5 +37,7 @@ enum class drawing_mode
triangles_adjacency
};
#endif // ANTKEEPER_DRAWING_MODE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_DRAWING_MODE_HPP

src/rasterizer/element-array-type.hpp → src/gl/element-array-type.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ELEMENT_ARRAY_TYPE_HPP
#define ANTKEEPER_ELEMENT_ARRAY_TYPE_HPP
#ifndef ANTKEEPER_GL_ELEMENT_ARRAY_TYPE_HPP
#define ANTKEEPER_GL_ELEMENT_ARRAY_TYPE_HPP
namespace gl {
enum class element_array_type
{
@ -27,5 +29,7 @@ enum class element_array_type
uint_32
};
#endif // ANTKEEPER_ELEMENT_ARRAY_TYPE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_ELEMENT_ARRAY_TYPE_HPP

src/rasterizer/framebuffer.cpp → src/gl/framebuffer.cpp View File

@ -17,10 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rasterizer/framebuffer.hpp"
#include "rasterizer/texture-2d.hpp"
#include "gl/framebuffer.hpp"
#include "gl/texture-2d.hpp"
#include <glad/glad.h>
namespace gl {
static constexpr GLenum attachment_lut[] =
{
GL_COLOR_ATTACHMENT0,
@ -86,3 +88,5 @@ void framebuffer::attach(framebuffer_attachment_type attachment_type, texture_2d
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
} // namespace gl

src/rasterizer/framebuffer.hpp → src/gl/framebuffer.hpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_FRAMEBUFFER_HPP
#define ANTKEEPER_FRAMEBUFFER_HPP
#ifndef ANTKEEPER_GL_FRAMEBUFFER_HPP
#define ANTKEEPER_GL_FRAMEBUFFER_HPP
#include <array>
namespace gl {
class rasterizer;
class texture_2d;
@ -115,6 +117,7 @@ inline texture_2d* framebuffer::get_stencil_attachment()
return stencil_attachment;
}
} // namespace gl
#endif // ANTKEEPER_FRAMEBUFFER_HPP
#endif // ANTKEEPER_GL_FRAMEBUFFER_HPP

src/rasterizer/gl.hpp → src/gl/gl.hpp View File

@ -20,7 +20,28 @@
#ifndef ANTKEEPER_GL_HPP
#define ANTKEEPER_GL_HPP
/// Graphics library (GL) provides a cross-platform GPU interface.
/// Graphics library (GL) is a cross-platform GPU interface.
namespace gl {}
#include "buffer-usage.hpp"
#include "color-space.hpp"
#include "drawing-mode.hpp"
#include "element-array-type.hpp"
#include "framebuffer.hpp"
#include "pixel-format.hpp"
#include "pixel-type.hpp"
#include "rasterizer.hpp"
#include "shader.hpp"
#include "shader-input.hpp"
#include "shader-program.hpp"
#include "shader-type.hpp"
#include "shader-variable-type.hpp"
#include "texture-2d.hpp"
#include "texture-cube.hpp"
#include "texture-filter.hpp"
#include "texture-wrapping.hpp"
#include "vertex-array.hpp"
#include "vertex-attribute-type.hpp"
#include "vertex-buffer.hpp"
#endif // ANTKEEPER_GL_HPP

src/rasterizer/pixel-format.hpp → src/gl/pixel-format.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_PIXEL_FORMAT_HPP
#define ANTKEEPER_PIXEL_FORMAT_HPP
#ifndef ANTKEEPER_GL_PIXEL_FORMAT_HPP
#define ANTKEEPER_GL_PIXEL_FORMAT_HPP
namespace gl {
enum class pixel_format
{
@ -32,5 +34,7 @@ enum class pixel_format
bgra ///< Blue, green, red, alpha
};
#endif // ANTKEEPER_PIXEL_FORMAT_HPP
} // namespace gl
#endif // ANTKEEPER_GL_PIXEL_FORMAT_HPP

src/rasterizer/pixel-type.hpp → src/gl/pixel-type.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_PIXEL_TYPE_HPP
#define ANTKEEPER_PIXEL_TYPE_HPP
#ifndef ANTKEEPER_GL_PIXEL_TYPE_HPP
#define ANTKEEPER_GL_PIXEL_TYPE_HPP
namespace gl {
enum class pixel_type
{
@ -32,5 +34,7 @@ enum class pixel_type
float_32
};
#endif // ANTKEEPER_PIXEL_TYPE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_PIXEL_TYPE_HPP

src/rasterizer/rasterizer.cpp → src/gl/rasterizer.cpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rasterizer/rasterizer.hpp"
#include "rasterizer/framebuffer.hpp"
#include "rasterizer/shader-program.hpp"
#include "rasterizer/vertex-array.hpp"
#include "gl/rasterizer.hpp"
#include "gl/framebuffer.hpp"
#include "gl/shader-program.hpp"
#include "gl/vertex-array.hpp"
#include <glad/glad.h>
namespace gl {
static constexpr GLenum drawing_mode_lut[] =
{
GL_POINTS,
@ -72,7 +74,7 @@ void rasterizer::context_resized(int width, int height)
default_framebuffer->dimensions = {width, height};
}
void rasterizer::use_framebuffer(const ::framebuffer& framebuffer)
void rasterizer::use_framebuffer(const gl::framebuffer& framebuffer)
{
if (bound_framebuffer != &framebuffer)
{
@ -161,3 +163,4 @@ void rasterizer::draw_elements(const vertex_array& vao, drawing_mode mode, std::
glDrawElements(gl_mode, static_cast<GLsizei>(count), gl_type, (const GLvoid*)offset);
}
} // namespace gl

src/rasterizer/rasterizer.hpp → src/gl/rasterizer.hpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_RASTERIZER_HPP
#define ANTKEEPER_RASTERIZER_HPP
#ifndef ANTKEEPER_GL_RASTERIZER_HPP
#define ANTKEEPER_GL_RASTERIZER_HPP
#include <cstdlib>
namespace gl {
class framebuffer;
class vertex_array;
class shader_program;
@ -52,7 +54,7 @@ public:
*
* @param framebuffer Framebuffer to use.
*/
void use_framebuffer(const ::framebuffer& framebuffer);
void use_framebuffer(const framebuffer& framebuffer);
/**
* Sets the color to be used when the color buffer of a framebuffer is cleared.
@ -133,5 +135,7 @@ inline const framebuffer& rasterizer::get_default_framebuffer() const
return *default_framebuffer;
}
#endif // ANTKEEPER_RASTERIZER_HPP
} // namespace gl
#endif // ANTKEEPER_GL_RASTERIZER_HPP

src/rasterizer/shader-input.cpp → src/gl/shader-input.cpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rasterizer/shader-input.hpp"
#include "rasterizer/texture-2d.hpp"
#include "rasterizer/texture-cube.hpp"
#include "gl/shader-input.hpp"
#include "gl/texture-2d.hpp"
#include "gl/texture-cube.hpp"
#include <glad/glad.h>
namespace gl {
shader_input::shader_input(shader_program* program, std::size_t input_index, int gl_uniform_location, const std::string& name, shader_variable_type data_type, std::size_t element_count, int texture_unit):
program(program),
input_index(input_index),
@ -670,3 +672,4 @@ bool shader_input::upload(std::size_t index, const texture_cube** values, std::s
return true;
}
} // namespace gl

src/rasterizer/shader-input.hpp → src/gl/shader-input.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SHADER_INPUT_HPP
#define ANTKEEPER_SHADER_INPUT_HPP
#ifndef ANTKEEPER_GL_SHADER_INPUT_HPP
#define ANTKEEPER_GL_SHADER_INPUT_HPP
#include "utility/fundamental-types.hpp"
#include <string>
namespace gl {
class shader_program;
class texture_2d;
class texture_cube;
@ -186,5 +188,7 @@ inline std::size_t shader_input::get_element_count() const
return element_count;
}
#endif // ANTKEEPER_SHADER_INPUT_HPP
} // namespace gl
#endif // ANTKEEPER_GL_SHADER_INPUT_HPP

src/rasterizer/shader-program.cpp → src/gl/shader-program.cpp View File

@ -17,13 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rasterizer/shader-program.hpp"
#include "rasterizer/shader.hpp"
#include "rasterizer/shader-variable-type.hpp"
#include "rasterizer/shader-input.hpp"
#include "gl/shader-program.hpp"
#include "gl/shader.hpp"
#include "gl/shader-variable-type.hpp"
#include "gl/shader-input.hpp"
#include <glad/glad.h>
#include <stdexcept>
namespace gl {
shader_program::shader_program(const std::list<shader*>& shaders):
gl_program_id(0)
{
@ -221,3 +223,4 @@ std::string shader_program::get_info_log() const
return std::string();
}
} // namespace gl

src/rasterizer/shader-program.hpp → src/gl/shader-program.hpp View File

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SHADER_PROGRAM_HPP
#define ANTKEEPER_SHADER_PROGRAM_HPP
#ifndef ANTKEEPER_GL_SHADER_PROGRAM_HPP
#define ANTKEEPER_GL_SHADER_PROGRAM_HPP
#include <cstdlib>
#include <list>
#include <map>
#include <string>
namespace gl {
class shader;
class rasterizer;
class shader_input;
@ -73,5 +75,7 @@ inline const shader_input* shader_program::get_input(const std::string& name) co
return it->second;
}
#endif // ANTKEEPER_SHADER_PROGRAM_HPP
} // namespace gl
#endif // ANTKEEPER_GL_SHADER_PROGRAM_HPP

src/rasterizer/shader-type.hpp → src/gl/shader-type.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SHADER_TYPE_HPP
#define ANTKEEPER_SHADER_TYPE_HPP
#ifndef ANTKEEPER_GL_SHADER_TYPE_HPP
#define ANTKEEPER_GL_SHADER_TYPE_HPP
namespace gl {
enum class shader_type
{
@ -27,5 +29,7 @@ enum class shader_type
geometry
};
#endif // ANTKEEPER_SHADER_TYPE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_SHADER_TYPE_HPP

src/rasterizer/shader-variable-type.hpp → src/gl/shader-variable-type.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SHADER_VARIABLE_TYPE_HPP
#define ANTKEEPER_SHADER_VARIABLE_TYPE_HPP
#ifndef ANTKEEPER_GL_SHADER_VARIABLE_TYPE_HPP
#define ANTKEEPER_GL_SHADER_VARIABLE_TYPE_HPP
namespace gl {
enum class shader_variable_type
{
@ -45,5 +47,7 @@ enum class shader_variable_type
texture_cube
};
#endif // ANTKEEPER_SHADER_VARIABLE_TYPE_HPP
} // namespace gl
#endif // ANTKEEPER_GL_SHADER_VARIABLE_TYPE_HPP

src/rasterizer/shader.cpp → src/gl/shader.cpp View File

@ -17,10 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rasterizer/shader.hpp"
#include "gl/shader.hpp"
#include <glad/glad.h>
#include <stdexcept>
namespace gl {
static constexpr GLenum shader_type_lut[] =
{
GL_VERTEX_SHADER,
@ -67,3 +69,4 @@ std::string shader::get_info_log() const
return std::string();
}
} // namespace gl

src/rasterizer/shader.hpp → src/gl/shader.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SHADER_HPP
#define ANTKEEPER_SHADER_HPP
#ifndef ANTKEEPER_GL_SHADER_HPP
#define ANTKEEPER_GL_SHADER_HPP
#include <cstdlib>
#include <string>
namespace gl {
enum class shader_type;
class shader_program;
@ -51,5 +53,7 @@ inline shader_type shader::get_type() const
return type;
}
#endif // ANTKEEPER_SHADER_HPP
} // namespace gl
#endif // ANTKEEPER_GL_SHADER_HPP

src/rasterizer/texture-2d.cpp → src/gl/texture-2d.cpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rasterizer/texture-2d.hpp"
#include "rasterizer/texture-wrapping.hpp"
#include "rasterizer/texture-filter.hpp"
#include "gl/texture-2d.hpp"
#include "gl/texture-wrapping.hpp"
#include "gl/texture-filter.hpp"
#include <glad/glad.h>
#include <algorithm>
namespace gl {
static constexpr GLenum pixel_format_lut[] =
{
GL_DEPTH_COMPONENT,
@ -109,7 +111,7 @@ static constexpr GLenum mag_filter_lut[] =
GL_LINEAR
};
texture_2d::texture_2d(int width, int height, ::pixel_type type, ::pixel_format format, ::color_space color_space, const void* data):
texture_2d::texture_2d(int width, int height, gl::pixel_type type, gl::pixel_format format, gl::color_space color_space, const void* data):
gl_texture_id(0),
dimensions({0, 0}),
wrapping({texture_wrapping::repeat, texture_wrapping::repeat}),
@ -128,7 +130,7 @@ texture_2d::~texture_2d()
glDeleteTextures(1, &gl_texture_id);
}
void texture_2d::resize(int width, int height, ::pixel_type type, ::pixel_format format, ::color_space color_space, const void* data)
void texture_2d::resize(int width, int height, gl::pixel_type type, gl::pixel_format format, gl::color_space color_space, const void* data)
{
dimensions = {width, height};
pixel_type = type;
@ -136,7 +138,7 @@ void texture_2d::resize(int width, int height, ::pixel_type type, ::pixel_format
this->color_space = color_space;
GLenum gl_internal_format;
if (color_space == ::color_space::srgb)
if (color_space == gl::color_space::srgb)
{
gl_internal_format = srgb_internal_format_lut[static_cast<std::size_t>(format)][static_cast<std::size_t>(type)];
}
@ -172,7 +174,7 @@ void texture_2d::resize(int width, int height, ::pixel_type type, ::pixel_format
}
}
void texture_2d::set_wrapping(texture_wrapping wrap_s, texture_wrapping wrap_t)
void texture_2d::set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t)
{
wrapping = {wrap_s, wrap_t};
@ -209,3 +211,4 @@ void texture_2d::set_max_anisotropy(float anisotropy)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_max_anisotropy);
}
} // namespace gl

src/rasterizer/texture-2d.hpp → src/gl/texture-2d.hpp View File

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_TEXTURE_2D_HPP
#define ANTKEEPER_TEXTURE_2D_HPP
#ifndef ANTKEEPER_GL_TEXTURE_2D_HPP
#define ANTKEEPER_GL_TEXTURE_2D_HPP
#include <array>
#include <tuple>
#include "rasterizer/color-space.hpp"
#include "rasterizer/pixel-format.hpp"
#include "rasterizer/pixel-type.hpp"
#include "gl/color-space.hpp"
#include "gl/pixel-format.hpp"
#include "gl/pixel-type.hpp"
namespace gl {
class framebuffer;
class shader_input;
@ -45,7 +47,7 @@ public:
*
* @warning If the sRGB color space is specified, pixel data will be stored internally as 8 bits per channel, and automatically converted to linear space before reading.
*/
texture_2d(int width, int height, ::pixel_type type = ::pixel_type::uint_8, ::pixel_format format = ::pixel_format::rgba, ::color_space color_space = ::color_space::linear, const void* data = nullptr);
texture_2d(int width, int height, gl::pixel_type type = gl::pixel_type::uint_8, gl::pixel_format format = gl::pixel_format::rgba, gl::color_space color_space = gl::color_space::linear, const void* data = nullptr);
/**
* Destroys a 2D texture.
@ -57,7 +59,7 @@ public:
*
* @warning If the sRGB color space is specified, pixel data will be stored internally as 8 bits per channel, and automatically converted to linear space before reading.
*/
void resize(int width, int height, ::pixel_type type, ::pixel_format format, ::color_space color_space, const void* data);
void resize(int width, int height, gl::pixel_type type, gl::pixel_format format, gl::color_space color_space, const void* data);
/**
* Sets the texture wrapping modes.
@ -65,7 +67,7 @@ public:
* @param wrap_s Wrapping mode for s-coordinates.
* @param wrap_t Wrapping mode for t-coordinates.
*/
void set_wrapping(texture_wrapping wrap_s, texture_wrapping wrap_t);
void set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t);
/**
* Sets the texture filtering modes.
@ -109,9 +111,9 @@ private:
unsigned int gl_texture_id;
std::array<int, 2> dimensions;
::pixel_type pixel_type;
::pixel_format pixel_format;
::color_space color_space;
gl::pixel_type pixel_type;
gl::pixel_format pixel_format;
gl::color_space color_space;
std::tuple<texture_wrapping, texture_wrapping> wrapping;
std::tuple<texture_min_filter, texture_mag_filter> filters;
float max_anisotropy;
@ -152,5 +154,7 @@ inline float texture_2d::get_max_anisotropy() const
return max_anisotropy;
}
#endif // ANTKEEPER_TEXTURE_2D_HPP
} // namespace gl
#endif // ANTKEEPER_GL_TEXTURE_2D_HPP

src/rasterizer/texture-cube.cpp → src/gl/texture-cube.cpp View File