Intrinsics for squares

This commit is contained in:
Andrew Golovashevich 2024-12-12 06:31:56 +03:00
parent 21f72b21b8
commit f5f3ccee34
13 changed files with 420 additions and 126 deletions

View File

@ -30,7 +30,7 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
for (long long x = start_x; x < w; x += data->pixel_size, x_flag = !x_flag) { for (long long x = start_x; x < w; x += data->pixel_size, x_flag = !x_flag) {
auto c = x_flag ? this->bg : this->fg; 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<double>::max(), c, c); Utilities::Shapes::fill_square(frame, x, y, data->pixel_size, std::numeric_limits<double>::max(), c);
} }
} }
} }

View File

@ -15,9 +15,18 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi {
component_compact_t green; component_compact_t green;
component_compact_t blue; 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 { class Transparent {
public: public:
@ -26,13 +35,21 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi {
component_compact_t blue; component_compact_t blue;
component_compact_t alpha; 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);
}
}; };
}; };
} }

View File

@ -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_include_directories(utilities PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(utilities PUBLIC renderer_api) target_link_libraries(utilities PUBLIC renderer_api)

View File

@ -0,0 +1,153 @@
namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
template<>
inline void fill_rectangle_pp<DefaultVoxelDrawerCache::VoxelPainterImpl>(
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>(
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>(
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>(
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>(
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>(
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>(
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>(
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>(
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>(
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>(
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>(
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);
}
}

View File

@ -12,8 +12,7 @@
#include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp> #include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp>
#include "color.hpp" #include "color.hpp"
#include "matrix.hpp" #include "matrix.hpp"
#include "shapes/rectangle.hpp"
class QObject;
namespace BGTU::ComputerGraphicsLabWork::Utilities { namespace BGTU::ComputerGraphicsLabWork::Utilities {
class DefaultVoxelDrawerCache { class DefaultVoxelDrawerCache {
@ -136,10 +135,36 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
return &(this->pixels_metadata[y * this->_width + x]); 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: 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 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: private:
@ -241,3 +266,5 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
} }
} }
} }
#include "_default_renderer_linear_intrinsics.hpp"

View File

@ -6,7 +6,7 @@
#include <bgtu/computer_graphics_lab_work/renderer_api/voxel_painter.hpp> #include <bgtu/computer_graphics_lab_work/renderer_api/voxel_painter.hpp>
#include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp> #include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp>
#include "../color.hpp" #include "../color.hpp"
#include "brezenham.hpp" #include "line.hpp"
namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
template<class receiver_t, std::size_t points_count> template<class receiver_t, std::size_t points_count>

View File

@ -5,7 +5,7 @@
#include <bgtu/computer_graphics_lab_work/renderer_api/voxel_painter.hpp> #include <bgtu/computer_graphics_lab_work/renderer_api/voxel_painter.hpp>
#include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp> #include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp>
#include "../color.hpp" #include "../color.hpp"
#include "brezenham.hpp" #include "line.hpp"
namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes { namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
template<class receiver_t, std::size_t points_count> template<class receiver_t, std::size_t points_count>

View File

@ -19,7 +19,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
) noexcept: x_start{x0}, y_start{y0}, x_end{x1}, y_end{y1} {} ) noexcept: x_start{x0}, y_start{y0}, x_end{x1}, y_end{y1} {}
public: 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 x,
RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t y,
RendererApi::PointI<2>::component_t w, RendererApi::PointI<2>::component_t w,
@ -28,7 +28,15 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
return {x, y, x + w, y + h}; 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 left,
RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t top,
RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t right,
@ -37,6 +45,13 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
return {left, top, right, bottom}; 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 { class iterator {
private: private:
RendererApi::PointI<2>::component_t x_start, x_end, y_end; RendererApi::PointI<2>::component_t x_start, x_end, y_end;
@ -94,21 +109,22 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
} }
}; };
template<class receiver_t> template<bool export_is_edge, class receiver_t>
void iterate_rectangle_fill_edges( void iterate_rectangle_fill_pp(
RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t left,
RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t top,
RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t right,
RendererApi::PointI<2>::component_t bottom, RendererApi::PointI<2>::component_t bottom,
receiver_t receiver receiver_t receiver
) { ) {
if constexpr (export_is_edge) {
for (RendererApi::PointI<2>::component_t x = left; x < right; x++) { for (RendererApi::PointI<2>::component_t x = left; x < right; x++) {
receiver(true, x, top); receiver(true, x, top);
} }
right--; right--;
bottom--; bottom--;
for (RendererApi::PointI<2>::component_t y = top+1; y < bottom; y++) { for (RendererApi::PointI<2>::component_t y = top + 1; y < bottom; y++) {
RendererApi::PointI<2>::component_t x = left; RendererApi::PointI<2>::component_t x = left;
receiver(true, x, y); receiver(true, x, y);
for (x++; x < right; x++) { for (x++; x < right; x++) {
@ -120,152 +136,198 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) { for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) {
receiver(true, x, bottom); 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<class receiver_t> template<bool export_is_edge, class receiver_t>
void iterate_rectangle_fill_wh( void iterate_rectangle_fill_pp(
RendererApi::PointI<2> tl,
RendererApi::PointI<2> br,
receiver_t receiver
) {
iterate_rectangle_fill_pp<export_is_edge, receiver_t>(tl.x, tl.y, br.x, br.y, receiver);
}
template<bool export_is_edge, class receiver_t>
void iterate_rectangle_fill_ps(
RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t x,
RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t y,
RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t width,
RendererApi::PointI<2>::component_t height, RendererApi::PointI<2>::component_t height,
receiver_t receiver receiver_t receiver
) { ) {
return iterate_rectangle_fill_edges<receiver_t>(x, y, x + width, y + height, receiver); return iterate_rectangle_fill_pp<export_is_edge, receiver_t>(x, y, x + width, y + height, receiver);
} }
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter> template<bool export_is_edge, class receiver_t>
void draw_rectangle_edges( void iterate_rectangle_fill_ps(
voxel_painter_t *painter, RendererApi::PointI<2> tl,
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<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void draw_rectangle_wh(
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 width,
RendererApi::PointI<2>::component_t height, RendererApi::PointI<2>::component_t height,
double z, receiver_t receiver
RendererApi::Color::Transparent outline
) { ) {
iterate_rectangle_fill_wh( return iterate_rectangle_fill_ps<export_is_edge, receiver_t>(tl.x, tl.y, width, height, receiver);
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); }
);
} }
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter> template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void fill_rectangle_edges( void fill_rectangle_pp(
voxel_painter_t *painter, voxel_painter_t *painter,
RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t left,
RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t top,
RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t right,
RendererApi::PointI<2>::component_t bottom, RendererApi::PointI<2>::component_t bottom,
double z, double z,
RendererApi::Color::Transparent outline,
RendererApi::Color::Transparent fill RendererApi::Color::Transparent fill
) { ) {
iterate_rectangle_fill_edges( iterate_rectangle_fill_pp<false>(
left, top, right, bottom, 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<class voxel_painter_t = RendererApi::VirtualVoxelPainter> template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void fill_rectangle_wh( void fill_rectangle_pp(
voxel_painter_t *painter, voxel_painter_t *painter,
RendererApi::PointI<2>::component_t x, RendererApi::PointI<2> tl,
RendererApi::PointI<2>::component_t y, RendererApi::PointI<2> br,
RendererApi::PointI<2>::component_t width,
RendererApi::PointI<2>::component_t height,
double z, double z,
RendererApi::Color::Transparent outline,
RendererApi::Color::Transparent fill RendererApi::Color::Transparent fill
) { ) {
iterate_rectangle_fill_wh( fill_rectangle_pp<voxel_painter_t>(painter, tl.x, tl.y, br.x, br.y, z, fill);
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); }
);
} }
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter> template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void draw_rectangle_edges( void fill_rectangle_ps(
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<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void draw_rectangle_wh(
voxel_painter_t *painter, voxel_painter_t *painter,
RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t x,
RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t y,
RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t width,
RendererApi::PointI<2>::component_t height, RendererApi::PointI<2>::component_t height,
double z, double z,
RendererApi::Color::Transparent outline, RendererApi::Color::Transparent fill
RendererApi::SpriteMetadata *owner
) { ) {
iterate_rectangle_fill_wh( fill_rectangle_pp<voxel_painter_t>(painter, x, y, x + width, y + height, z, fill);
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); }
);
} }
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter> template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, tl.x, tl.y, width, height, z, fill);
}
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void fill_rectangle_pp(
voxel_painter_t *painter, voxel_painter_t *painter,
RendererApi::PointI<2>::component_t left, RendererApi::PointI<2>::component_t left,
RendererApi::PointI<2>::component_t top, RendererApi::PointI<2>::component_t top,
RendererApi::PointI<2>::component_t right, RendererApi::PointI<2>::component_t right,
RendererApi::PointI<2>::component_t bottom, RendererApi::PointI<2>::component_t bottom,
double z, double z,
RendererApi::Color::Transparent outline,
RendererApi::Color::Transparent fill, RendererApi::Color::Transparent fill,
RendererApi::SpriteMetadata *owner RendererApi::SpriteMetadata *owner
) { ) {
iterate_rectangle_fill_edges( iterate_rectangle_fill_pp<false>(
left, top, right, bottom, 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<class voxel_painter_t = RendererApi::VirtualVoxelPainter> template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, tl.x, tl.y, br.x, br.y, z, fill, owner);
}
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
void fill_rectangle_ps(
voxel_painter_t *painter, voxel_painter_t *painter,
RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t x,
RendererApi::PointI<2>::component_t y, RendererApi::PointI<2>::component_t y,
RendererApi::PointI<2>::component_t width, RendererApi::PointI<2>::component_t width,
RendererApi::PointI<2>::component_t height, RendererApi::PointI<2>::component_t height,
double z, double z,
RendererApi::Color::Transparent outline,
RendererApi::Color::Transparent fill, RendererApi::Color::Transparent fill,
RendererApi::SpriteMetadata *owner RendererApi::SpriteMetadata *owner
) { ) {
iterate_rectangle_fill_wh( fill_rectangle_pp<voxel_painter_t>(painter, x, y, x + width, y + height, z, fill, owner);
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); }
); template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, tl.x, tl.y, width, height, z, fill, owner);
}
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, x, y, x + size, y + size, z, fill);
}
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, tl.x, tl.y, size, size, z, fill);
}
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, x, y, x + size, y + size, z, fill, owner);
}
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
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<voxel_painter_t>(painter, tl.x, tl.y, size, size, z, fill, owner);
} }
} }

View File

@ -4,7 +4,7 @@
#include <utility> #include <utility>
#include <limits> #include <limits>
#include <bgtu/computer_graphics_lab_work/renderer_api/point.hpp> #include <bgtu/computer_graphics_lab_work/renderer_api/point.hpp>
#include "bgtu/computer_graphics_lab_work/utilities/shapes/brezenham.hpp" #include "bgtu/computer_graphics_lab_work/utilities/shapes/line.hpp"
namespace BGTU::ComputerGraphicsLabWork::Utilities { namespace BGTU::ComputerGraphicsLabWork::Utilities {

View File

@ -29,26 +29,24 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
) noexcept: dst{dst}, cx{center_tl.x}, cy{center_tl.y}, pixel_size{pixel_size} {} ) 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 { void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c) final {
Shapes::fill_rectangle_wh<unzoomed_painter_t>( Shapes::fill_square<unzoomed_painter_t>(
this->dst, this->dst,
this->cx + x * this->pixel_size, this->cx + x * this->pixel_size,
this->cy + y * this->pixel_size, this->cy + y * this->pixel_size,
this->pixel_size, this->pixel_size,
this->pixel_size,
z, z,
c, c c
); );
} }
void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) final { void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) final {
Shapes::fill_rectangle_wh<unzoomed_painter_t>( Shapes::fill_square<unzoomed_painter_t>(
this->dst, this->dst,
this->cx + x * this->pixel_size, this->cx + x * this->pixel_size,
this->cy + y * this->pixel_size, this->cy + y * this->pixel_size,
this->pixel_size, this->pixel_size,
this->pixel_size,
z, z,
c, {0, 255, 255}, c,
owner owner
); );
} }

View File

@ -135,14 +135,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
current_artist{nullptr} {} 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) { void DefaultVoxelDrawerCache::VoxelPainterImpl::_add_voxel(long long int x, long long int y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) {
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;
auto p = this->at(x, y); auto p = this->at(x, y);
#if 0 #if 0
@ -162,4 +155,11 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, owner); 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);
}
} }

View File

@ -0,0 +1,28 @@
#include <bgtu/computer_graphics_lab_work/renderer_api/point.hpp>
#include <bgtu/computer_graphics_lab_work/renderer_api/color.hpp>
#include <bgtu/computer_graphics_lab_work/utilities/shapes/rectangle.hpp>
#include <bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp>
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<false>(
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);
}
);
}
}