From f5f3ccee34306cfaaf8ab2e0c713974303b5ae26 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Thu, 12 Dec 2024 06:31:56 +0300 Subject: [PATCH] Intrinsics for squares --- programs/lab1/src/pixel_grid_sprite.hpp | 2 +- .../renderer_api/color.hpp | 29 +- utilities/CMakeLists.txt | 11 +- .../_default_renderer_linear_intrinsics.hpp | 153 +++++++++++ .../utilities/default_renderer_linear.hpp | 35 ++- .../shapes/{brezenham.hpp => line.hpp} | 0 .../utilities/shapes/polygon.hpp | 2 +- .../utilities/shapes/polyline.hpp | 2 +- .../utilities/shapes/rectangle.hpp | 256 +++++++++++------- .../utilities/triangle_fill_iterable.hpp | 2 +- .../utilities/zoomed_voxel_painter.hpp | 10 +- ...efault_renderer_linear_implementation.cpp} | 16 +- ...ault_renderer_linear_shapes_intrinsics.cpp | 28 ++ 13 files changed, 420 insertions(+), 126 deletions(-) create mode 100644 utilities/include/bgtu/computer_graphics_lab_work/utilities/_default_renderer_linear_intrinsics.hpp rename utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/{brezenham.hpp => line.hpp} (100%) rename utilities/src/{default_renderer_linear.cpp => default_renderer_linear_implementation.cpp} (95%) create mode 100644 utilities/src/default_renderer_linear_shapes_intrinsics.cpp diff --git a/programs/lab1/src/pixel_grid_sprite.hpp b/programs/lab1/src/pixel_grid_sprite.hpp index 8b35441..748f979 100644 --- a/programs/lab1/src/pixel_grid_sprite.hpp +++ b/programs/lab1/src/pixel_grid_sprite.hpp @@ -30,7 +30,7 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 { for (long long x = start_x; x < w; x += data->pixel_size, x_flag = !x_flag) { auto c = x_flag ? this->bg : this->fg; - Utilities::Shapes::fill_rectangle_wh(frame, x, y, data->pixel_size, data->pixel_size, std::numeric_limits::max(), c, c); + Utilities::Shapes::fill_square(frame, x, y, data->pixel_size, std::numeric_limits::max(), c); } } } diff --git a/renderer-api/include/bgtu/computer_graphics_lab_work/renderer_api/color.hpp b/renderer-api/include/bgtu/computer_graphics_lab_work/renderer_api/color.hpp index 2562c67..27654ef 100644 --- a/renderer-api/include/bgtu/computer_graphics_lab_work/renderer_api/color.hpp +++ b/renderer-api/include/bgtu/computer_graphics_lab_work/renderer_api/color.hpp @@ -15,9 +15,18 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi { component_compact_t green; component_compact_t blue; - constexpr Color() : red{0}, green{0}, blue{0} {} + constexpr Color() noexcept: red{0}, green{0}, blue{0} {} + + constexpr Color(component_fast_t red, component_fast_t green, component_fast_t blue) noexcept: red{red}, green{green}, blue{blue} {} + + constexpr bool operator==(Color const &other) const noexcept { + return this->red == other.red && this->green == other.green && this->blue == other.blue; + } + + constexpr bool operator!=(Color const &other) const noexcept { + return !(*this == other); + } - constexpr Color(component_fast_t red, component_fast_t green, component_fast_t blue) : red{red}, green{green}, blue{blue} {} class Transparent { public: @@ -26,13 +35,21 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi { component_compact_t blue; component_compact_t alpha; - constexpr Transparent() : red{component_min_value}, green{component_min_value}, blue{component_min_value}, alpha{component_max_value} {} + constexpr Transparent() noexcept: red{component_min_value}, green{component_min_value}, blue{component_min_value}, alpha{component_max_value} {} - constexpr Transparent(component_fast_t red, component_fast_t green, component_fast_t blue) : red{red}, green{green}, blue{blue}, alpha{component_max_value} {} + constexpr Transparent(component_fast_t red, component_fast_t green, component_fast_t blue) noexcept: red{red}, green{green}, blue{blue}, alpha{component_max_value} {} - constexpr Transparent(component_fast_t red, component_fast_t green, component_fast_t blue, component_fast_t alpha) : red{red}, green{green}, blue{blue}, alpha{alpha} {} + constexpr Transparent(component_fast_t red, component_fast_t green, component_fast_t blue, component_fast_t alpha) noexcept: red{red}, green{green}, blue{blue}, alpha{alpha} {} - constexpr Transparent(Color c) : red{c.red}, green{c.green}, blue{c.blue}, alpha{component_max_value} {} + constexpr Transparent(Color c) noexcept: red{c.red}, green{c.green}, blue{c.blue}, alpha{component_max_value} {} + + constexpr bool operator==(Color::Transparent const &other) const noexcept { + return this->red == other.red && this->green == other.green && this->blue == other.blue && this->alpha == other.alpha; + } + + constexpr bool operator!=(Color::Transparent const &other) const noexcept { + return !(*this == other); + } }; }; } \ No newline at end of file diff --git a/utilities/CMakeLists.txt b/utilities/CMakeLists.txt index a5e9718..2133519 100644 --- a/utilities/CMakeLists.txt +++ b/utilities/CMakeLists.txt @@ -1,3 +1,12 @@ -add_library(utilities OBJECT src/shader.cpp src/memory_pages_management.cpp src/default_renderer_linear.cpp src/color.asm) +add_library( + utilities + OBJECT + src/shader.cpp + src/memory_pages_management.cpp + src/default_renderer_linear_implementation.cpp + src/default_renderer_linear_shapes_intrinsics.cpp + + src/color.asm +) target_include_directories(utilities PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(utilities PUBLIC renderer_api) \ No newline at end of file diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/_default_renderer_linear_intrinsics.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/_default_renderer_linear_intrinsics.hpp new file mode 100644 index 0000000..fd1a867 --- /dev/null +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/_default_renderer_linear_intrinsics.hpp @@ -0,0 +1,153 @@ +namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { + template<> + inline void fill_rectangle_pp( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2>::component_t left, + RendererApi::PointI<2>::component_t top, + RendererApi::PointI<2>::component_t right, + RendererApi::PointI<2>::component_t bottom, + double z, + RendererApi::Color::Transparent fill + ) { + painter->fill_rectangle(left, top, right, bottom, z, fill); + } + + template<> + inline void fill_rectangle_pp( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2> br, + double z, + RendererApi::Color::Transparent fill + ) { + painter->fill_rectangle(tl.x, tl.y, br.x, br.y, z, fill); + } + + template<> + inline void fill_rectangle_ps( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2>::component_t x, + RendererApi::PointI<2>::component_t y, + RendererApi::PointI<2>::component_t width, + RendererApi::PointI<2>::component_t height, + double z, + RendererApi::Color::Transparent fill + ) { + painter->fill_rectangle(x, y, x + width, y + height, z, fill); + } + + template<> + inline void fill_rectangle_ps( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t width, + RendererApi::PointI<2>::component_t height, + double z, + RendererApi::Color::Transparent fill + ) { + painter->fill_rectangle(tl.x, tl.y, tl.x + width, tl.y + height, z, fill); + } + + + template<> + inline void fill_rectangle_pp( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2>::component_t left, + RendererApi::PointI<2>::component_t top, + RendererApi::PointI<2>::component_t right, + RendererApi::PointI<2>::component_t bottom, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + painter->fill_rectangle(left, top, right, bottom, z, fill, owner); + } + + template<> + inline void fill_rectangle_pp( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2> br, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + painter->fill_rectangle(tl.x, tl.y, br.x, br.y, z, fill, owner); + } + + template<> + inline void fill_rectangle_ps( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2>::component_t x, + RendererApi::PointI<2>::component_t y, + RendererApi::PointI<2>::component_t width, + RendererApi::PointI<2>::component_t height, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + painter->fill_rectangle(x, y, x + width, y + height, z, fill, owner); + } + + template<> + inline void fill_rectangle_ps( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t width, + RendererApi::PointI<2>::component_t height, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + painter->fill_rectangle(tl.x, tl.y, tl.x + width, tl.y + height, z, fill, owner); + } + + + template<> + inline void fill_square( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2>::component_t x, + RendererApi::PointI<2>::component_t y, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill + ) { + painter->fill_rectangle(x, y, x + size, y + size, z, fill); + } + + template<> + inline void fill_square( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill + ) { + painter->fill_rectangle(tl.x, tl.y, tl.x + size, tl.y + size, z, fill); + } + + template<> + inline void fill_square( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2>::component_t x, + RendererApi::PointI<2>::component_t y, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + painter->fill_rectangle(x, y, x + size, y + size, z, fill, owner); + } + + template<> + inline void fill_square( + DefaultVoxelDrawerCache::VoxelPainterImpl *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + painter->fill_rectangle(tl.x, tl.y, tl.x + size, tl.y + size, z, fill, owner); + } +} \ No newline at end of file diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp index aa92ea2..a92fd85 100644 --- a/utilities/include/bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp @@ -12,8 +12,7 @@ #include #include "color.hpp" #include "matrix.hpp" - -class QObject; +#include "shapes/rectangle.hpp" namespace BGTU::ComputerGraphicsLabWork::Utilities { class DefaultVoxelDrawerCache { @@ -136,10 +135,36 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities { return &(this->pixels_metadata[y * this->_width + x]); } + void _add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner); + public: - void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c) final; + inline void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c) final { + return this->add_voxel(x, y, z, c, this->current_artist); + } void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) final; + + + void fill_rectangle( + RendererApi::PointI<2>::component_t left, + RendererApi::PointI<2>::component_t top, + RendererApi::PointI<2>::component_t right, + RendererApi::PointI<2>::component_t bottom, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ); + + inline void fill_rectangle( + RendererApi::PointI<2>::component_t left, + RendererApi::PointI<2>::component_t top, + RendererApi::PointI<2>::component_t right, + RendererApi::PointI<2>::component_t bottom, + double z, + RendererApi::Color::Transparent fill + ) { + this->fill_rectangle(left, top, right, bottom, z, fill, this->current_artist); + } }; private: @@ -240,4 +265,6 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities { } } } -} \ No newline at end of file +} + +#include "_default_renderer_linear_intrinsics.hpp" \ No newline at end of file diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/brezenham.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/line.hpp similarity index 100% rename from utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/brezenham.hpp rename to utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/line.hpp diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polygon.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polygon.hpp index 649afd8..8b67e62 100644 --- a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polygon.hpp +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polygon.hpp @@ -6,7 +6,7 @@ #include #include #include "../color.hpp" -#include "brezenham.hpp" +#include "line.hpp" namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { template diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polyline.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polyline.hpp index d1aa6c1..806c8f4 100644 --- a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polyline.hpp +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/polyline.hpp @@ -5,7 +5,7 @@ #include #include #include "../color.hpp" -#include "brezenham.hpp" +#include "line.hpp" namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { template diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/rectangle.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/rectangle.hpp index 4b61749..09f0f12 100644 --- a/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/rectangle.hpp +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/shapes/rectangle.hpp @@ -19,7 +19,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { ) noexcept: x_start{x0}, y_start{y0}, x_end{x1}, y_end{y1} {} public: - static constexpr rectangle_fill_iterable from_wh( + static constexpr rectangle_fill_iterable from_ps( RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t w, @@ -28,7 +28,15 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { return {x, y, x + w, y + h}; } - static constexpr rectangle_fill_iterable from_edges( + static constexpr rectangle_fill_iterable from_ps( + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t w, + RendererApi::PointI<2>::component_t h + ) noexcept { + return {tl.x, tl.y, tl.x + w, tl.y + h}; + } + + static constexpr rectangle_fill_iterable from_pp( RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t right, @@ -37,6 +45,13 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { return {left, top, right, bottom}; } + static constexpr rectangle_fill_iterable from_pp( + RendererApi::PointI<2> tl, + RendererApi::PointI<2> br + ) noexcept { + return {tl.x, tl.y, br.x, br.y}; + } + class iterator { private: RendererApi::PointI<2>::component_t x_start, x_end, y_end; @@ -94,178 +109,225 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { } }; - template - void iterate_rectangle_fill_edges( + template + void iterate_rectangle_fill_pp( RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t bottom, receiver_t receiver ) { - for (RendererApi::PointI<2>::component_t x = left; x < right; x++) { - receiver(true, x, top); - } - - right--; - bottom--; - for (RendererApi::PointI<2>::component_t y = top+1; y < bottom; y++) { - RendererApi::PointI<2>::component_t x = left; - receiver(true, x, y); - for (x++; x < right; x++) { - receiver(false, x, y); + if constexpr (export_is_edge) { + for (RendererApi::PointI<2>::component_t x = left; x < right; x++) { + receiver(true, x, top); } - receiver(true, x, y); - } - for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) { - receiver(true, x, bottom); + right--; + bottom--; + for (RendererApi::PointI<2>::component_t y = top + 1; y < bottom; y++) { + RendererApi::PointI<2>::component_t x = left; + receiver(true, x, y); + for (x++; x < right; x++) { + receiver(false, x, y); + } + receiver(true, x, y); + } + + for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) { + receiver(true, x, bottom); + } + } else { + for (RendererApi::PointI<2>::component_t y = top; y < bottom; y++) { + for (RendererApi::PointI<2>::component_t x = left; x < right; x++) { + receiver(x, y); + } + } } } - template - void iterate_rectangle_fill_wh( + template + void iterate_rectangle_fill_pp( + RendererApi::PointI<2> tl, + RendererApi::PointI<2> br, + receiver_t receiver + ) { + iterate_rectangle_fill_pp(tl.x, tl.y, br.x, br.y, receiver); + } + + template + void iterate_rectangle_fill_ps( RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t height, receiver_t receiver ) { - return iterate_rectangle_fill_edges(x, y, x + width, y + height, receiver); + return iterate_rectangle_fill_pp(x, y, x + width, y + height, receiver); } - template - void draw_rectangle_edges( - voxel_painter_t *painter, - RendererApi::PointI<2>::component_t left, - RendererApi::PointI<2>::component_t top, - RendererApi::PointI<2>::component_t right, - RendererApi::PointI<2>::component_t bottom, - double z, - RendererApi::Color::Transparent outline - ) { - iterate_rectangle_fill_edges( - left, top, right, bottom, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { if (is_edge) painter->add_voxel(x, y, z, outline); } - ); - } - - template - void draw_rectangle_wh( - voxel_painter_t *painter, - RendererApi::PointI<2>::component_t x, - RendererApi::PointI<2>::component_t y, + template + void iterate_rectangle_fill_ps( + RendererApi::PointI<2> tl, RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t height, - double z, - RendererApi::Color::Transparent outline + receiver_t receiver ) { - iterate_rectangle_fill_wh( - x, y, width, height, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { if (is_edge) painter->add_voxel(x, y, z, outline); } - ); + return iterate_rectangle_fill_ps(tl.x, tl.y, width, height, receiver); } template - void fill_rectangle_edges( + void fill_rectangle_pp( voxel_painter_t *painter, RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t bottom, double z, - RendererApi::Color::Transparent outline, RendererApi::Color::Transparent fill ) { - iterate_rectangle_fill_edges( + iterate_rectangle_fill_pp( left, top, right, bottom, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, is_edge ? outline : fill); } + [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, fill); } ); } template - void fill_rectangle_wh( + void fill_rectangle_pp( voxel_painter_t *painter, - RendererApi::PointI<2>::component_t x, - RendererApi::PointI<2>::component_t y, - RendererApi::PointI<2>::component_t width, - RendererApi::PointI<2>::component_t height, + RendererApi::PointI<2> tl, + RendererApi::PointI<2> br, double z, - RendererApi::Color::Transparent outline, RendererApi::Color::Transparent fill ) { - iterate_rectangle_fill_wh( - x, y, width, height, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, is_edge ? outline : fill); } - ); + fill_rectangle_pp(painter, tl.x, tl.y, br.x, br.y, z, fill); } template - void draw_rectangle_edges( - voxel_painter_t *painter, - RendererApi::PointI<2>::component_t left, - RendererApi::PointI<2>::component_t top, - RendererApi::PointI<2>::component_t right, - RendererApi::PointI<2>::component_t bottom, - double z, - RendererApi::Color::Transparent outline, - RendererApi::SpriteMetadata *owner - ) { - iterate_rectangle_fill_edges( - left, top, right, bottom, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { if (is_edge) painter->add_voxel(x, y, z, outline, owner); } - ); - } - - template - void draw_rectangle_wh( + void fill_rectangle_ps( voxel_painter_t *painter, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t height, double z, - RendererApi::Color::Transparent outline, - RendererApi::SpriteMetadata *owner + RendererApi::Color::Transparent fill ) { - iterate_rectangle_fill_wh( - x, y, width, height, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { if (is_edge) painter->add_voxel(x, y, z, outline, owner); } - ); + fill_rectangle_pp(painter, x, y, x + width, y + height, z, fill); } template - void fill_rectangle_edges( + void fill_rectangle_ps( + voxel_painter_t *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t width, + RendererApi::PointI<2>::component_t height, + double z, + RendererApi::Color::Transparent fill + ) { + fill_rectangle_ps(painter, tl.x, tl.y, width, height, z, fill); + } + + template + void fill_rectangle_pp( voxel_painter_t *painter, RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t bottom, double z, - RendererApi::Color::Transparent outline, RendererApi::Color::Transparent fill, RendererApi::SpriteMetadata *owner ) { - iterate_rectangle_fill_edges( + iterate_rectangle_fill_pp( left, top, right, bottom, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, (is_edge ? outline : fill), owner); } + [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, fill, owner); } ); } template - void fill_rectangle_wh( + void fill_rectangle_pp( + voxel_painter_t *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2> br, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + fill_rectangle_pp(painter, tl.x, tl.y, br.x, br.y, z, fill, owner); + } + + template + void fill_rectangle_ps( voxel_painter_t *painter, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t height, double z, - RendererApi::Color::Transparent outline, RendererApi::Color::Transparent fill, RendererApi::SpriteMetadata *owner ) { - iterate_rectangle_fill_wh( - x, y, width, height, - [=](bool is_edge, RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, (is_edge ? outline : fill), owner); } - ); + fill_rectangle_pp(painter, x, y, x + width, y + height, z, fill, owner); + } + + template + void fill_rectangle_ps( + voxel_painter_t *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t width, + RendererApi::PointI<2>::component_t height, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + fill_rectangle_ps(painter, tl.x, tl.y, width, height, z, fill, owner); + } + + template + void fill_square( + voxel_painter_t *painter, + RendererApi::PointI<2>::component_t x, + RendererApi::PointI<2>::component_t y, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill + ) { + fill_rectangle_ps(painter, x, y, x + size, y + size, z, fill); + } + + template + void fill_square( + voxel_painter_t *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill + ) { + fill_square(painter, tl.x, tl.y, size, size, z, fill); + } + + template + void fill_square( + voxel_painter_t *painter, + RendererApi::PointI<2>::component_t x, + RendererApi::PointI<2>::component_t y, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + fill_rectangle_ps(painter, x, y, x + size, y + size, z, fill, owner); + } + + template + void fill_square( + voxel_painter_t *painter, + RendererApi::PointI<2> tl, + RendererApi::PointI<2>::component_t size, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + fill_square(painter, tl.x, tl.y, size, size, z, fill, owner); } } \ No newline at end of file diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/triangle_fill_iterable.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/triangle_fill_iterable.hpp index bc0f2fb..ea10141 100644 --- a/utilities/include/bgtu/computer_graphics_lab_work/utilities/triangle_fill_iterable.hpp +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/triangle_fill_iterable.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "bgtu/computer_graphics_lab_work/utilities/shapes/brezenham.hpp" +#include "bgtu/computer_graphics_lab_work/utilities/shapes/line.hpp" namespace BGTU::ComputerGraphicsLabWork::Utilities { diff --git a/utilities/include/bgtu/computer_graphics_lab_work/utilities/zoomed_voxel_painter.hpp b/utilities/include/bgtu/computer_graphics_lab_work/utilities/zoomed_voxel_painter.hpp index dcf8537..04d4075 100644 --- a/utilities/include/bgtu/computer_graphics_lab_work/utilities/zoomed_voxel_painter.hpp +++ b/utilities/include/bgtu/computer_graphics_lab_work/utilities/zoomed_voxel_painter.hpp @@ -29,26 +29,24 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities { ) noexcept: dst{dst}, cx{center_tl.x}, cy{center_tl.y}, pixel_size{pixel_size} {} void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c) final { - Shapes::fill_rectangle_wh( + Shapes::fill_square( this->dst, this->cx + x * this->pixel_size, this->cy + y * this->pixel_size, this->pixel_size, - this->pixel_size, z, - c, c + c ); } void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) final { - Shapes::fill_rectangle_wh( + Shapes::fill_square( this->dst, this->cx + x * this->pixel_size, this->cy + y * this->pixel_size, this->pixel_size, - this->pixel_size, z, - c, {0, 255, 255}, + c, owner ); } diff --git a/utilities/src/default_renderer_linear.cpp b/utilities/src/default_renderer_linear_implementation.cpp similarity index 95% rename from utilities/src/default_renderer_linear.cpp rename to utilities/src/default_renderer_linear_implementation.cpp index fa4661c..5eb32f3 100644 --- a/utilities/src/default_renderer_linear.cpp +++ b/utilities/src/default_renderer_linear_implementation.cpp @@ -135,14 +135,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities { current_artist{nullptr} {} - void DefaultVoxelDrawerCache::VoxelPainterImpl::add_voxel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, double z, RendererApi::Color::Transparent c) { - return this->add_voxel(x, y, z, c, this->current_artist); - } - - void DefaultVoxelDrawerCache::VoxelPainterImpl::add_voxel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) { - if (x < 0 || this->_width <= x) return; - if (y < 0 || this->_height <= y) return; - if (z < 0) return; + void DefaultVoxelDrawerCache::VoxelPainterImpl::_add_voxel(long long int x, long long int y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) { auto p = this->at(x, y); #if 0 @@ -162,4 +155,11 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities { p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, owner); } + + void DefaultVoxelDrawerCache::VoxelPainterImpl::add_voxel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) { + if (x < 0 || this->_width <= x) return; + if (y < 0 || this->_height <= y) return; + if (z < 0) return; + this->_add_voxel(x, y, z, c, owner); + } } \ No newline at end of file diff --git a/utilities/src/default_renderer_linear_shapes_intrinsics.cpp b/utilities/src/default_renderer_linear_shapes_intrinsics.cpp new file mode 100644 index 0000000..2b198ae --- /dev/null +++ b/utilities/src/default_renderer_linear_shapes_intrinsics.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +namespace BGTU::ComputerGraphicsLabWork::Utilities { + void DefaultVoxelDrawerCache::VoxelPainterImpl::fill_rectangle( + RendererApi::PointI<2>::component_t left, + RendererApi::PointI<2>::component_t top, + RendererApi::PointI<2>::component_t right, + RendererApi::PointI<2>::component_t bottom, + double z, + RendererApi::Color::Transparent fill, + RendererApi::SpriteMetadata *owner + ) { + if (left < 0) left = 0; + if (top < 0) top = 0; + if (right >= this->_width) right = this->_width; + if (bottom >= this->_height) bottom = this->_height; + + Shapes::iterate_rectangle_fill_pp( + left, top, right, bottom, + [=, this](RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { + this->_add_voxel(x, y, z, fill, owner); + } + ); + } +} \ No newline at end of file