Support RectF

This commit is contained in:
2023-05-30 22:06:38 +02:00
parent ad7a6c2210
commit 1ff6367918
7 changed files with 187 additions and 104 deletions

View File

@@ -1,5 +1,5 @@
#ifndef __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__
#define __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__
#ifndef __JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__
#define __JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__
#include "primitive_support_types.hpp"
namespace JabyEngine {
@@ -12,8 +12,6 @@ namespace JabyEngine {
static constexpr auto FlatShading = !GouraudShading;
static constexpr auto PolyLine = Bit(27 - BitCorrection);
static constexpr auto SingleLine = !PolyLine;
static constexpr auto SemiTransparent = Bit(25 - BitCorrection);
static constexpr auto NonTransparent = !SemiTransparent;
};
template<typename T>
@@ -21,12 +19,7 @@ namespace JabyEngine {
typedef ::JabyEngine::GPU::internal::LineCode Code;
constexpr T& set_semi_transparent(bool set = true) {
if(set) {
static_cast<T*>(this)->head.code.set(Code::SemiTransparent);
}
else {
static_cast<T*>(this)->head.code.set(Code::NonTransparent);
}
static_cast<T*>(this)->head.code.set_tenary(set, Code::SemiTransparent, Code::NonTransparent);
return *static_cast<T*>(this);
}
};
@@ -123,4 +116,4 @@ namespace JabyEngine {
}
}
#endif //!__JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__
#endif //!__JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__

View File

@@ -12,12 +12,6 @@ namespace JabyEngine {
static constexpr auto FlatShading = !GouraudShading;
static constexpr auto QuadVertics = Bit(27 - BitCorrection);
static constexpr auto TriVertics = !QuadVertics;
static constexpr auto Textured = Bit(26 - BitCorrection);
static constexpr auto Untextured = !Textured;
static constexpr auto SemiTransparent = Bit(25 - BitCorrection);
static constexpr auto NonTransparent = !SemiTransparent;
static constexpr auto NoBlendTexture = Bit(24 - BitCorrection);
static constexpr auto BlendTexture = !NoBlendTexture;
};
template<typename T>
@@ -25,22 +19,12 @@ namespace JabyEngine {
typedef ::JabyEngine::GPU::internal::PolyCode Code;
constexpr T& set_semi_transparent(bool set = true) {
if(set) {
static_cast<T*>(this)->code.set(Code::SemiTransparent);
}
else {
static_cast<T*>(this)->code.set(Code::NonTransparent);
}
static_cast<T*>(this)->code.set_tenary(set, Code::SemiTransparent, Code::NonTransparent);
return *static_cast<T*>(this);
}
constexpr T& set_texture_blending(bool set = true) {
if(set) {
static_cast<T*>(this)->code.set(Code::BlendTexture);
}
else {
static_cast<T*>(this)->code.set(Code::NoBlendTexture);
}
static_cast<T*>(this)->code.set_tenary(set, Code::BlendTexture, Code::NoBlendTexture);
return *static_cast<T*>(this);
}
};

View File

@@ -0,0 +1,65 @@
#ifndef __JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__
#define __JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__
#include "primitive_support_types.hpp"
namespace JabyEngine {
namespace GPU {
namespace internal {
struct RectCode : public CodeBase<RectCode> {
enum struct Size : uint8_t {
Variable = 0,
Pixel1x1 = 1,
Sprite8x8 = 2,
Sprite16x16 = 3
};
static constexpr uint8_t CmdValue = 0b011;
static constexpr auto Size = BitRange::from_to(27 - BitCorrection, 28 - BitCorrection);
};
template<typename T>
struct RectCodeInterface {
typedef typename ::JabyEngine::GPU::internal::RectCode Code;
constexpr T& set_semi_transparent(bool set = true) {
static_cast<T*>(this)->code.set_tenary(set, Code::SemiTransparent, Code::NonTransparent);
return *static_cast<T*>(this);
}
};
template<typename RectCode::Size Size>
struct RECT_F : public RectCodeInterface<RECT_F<Size>> {
typedef RECT_F<Size>::Code Code;
static constexpr auto IdentityCode = Code().set(Code::Size.with(static_cast<uint8_t>(Size))).set(Code::Untextured).set(Code::NonTransparent);
Color24 color;
Code code;
Vertex position;
constexpr RECT_F() = default;
constexpr RECT_F(const Color24& color, const Vertex& position) : color(color), code(IdentityCode), position(position) {
}
};
}
typedef internal::RECT_F<internal::RectCode::Size::Pixel1x1> RECT_F1;
typedef internal::RECT_F<internal::RectCode::Size::Sprite8x8> RECT_F8;
typedef internal::RECT_F<internal::RectCode::Size::Sprite16x16> RECT_F16;
struct RECT_FVAR : public internal::RECT_F<internal::RectCode::Size::Variable> {
Vertex position_bottom_right;
constexpr RECT_FVAR() = default;
constexpr RECT_FVAR(const Color24& color, const AreaI16& area) : RECT_F(color, area.position), position_bottom_right(area.position.move(area.size.width, area.size.height)) {
}
};
namespace internal {
__jaby_engine_declare_render_primitive(RECT_F1);
__jaby_engine_declare_render_primitive(RECT_F8);
__jaby_engine_declare_render_primitive(RECT_F16);
__jaby_engine_declare_render_primitive(RECT_FVAR);
}
}
}
#endif //!__JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__

View File

@@ -13,6 +13,14 @@ namespace JabyEngine {
uint8_t value = bit::value::set_normalized(0u, CmdID.with(T::CmdValue));
// Common values for all the primitves
static constexpr auto Textured = Bit(26 - BitCorrection);
static constexpr auto Untextured = !Textured;
static constexpr auto SemiTransparent = Bit(25 - BitCorrection);
static constexpr auto NonTransparent = !SemiTransparent;
static constexpr auto NoBlendTexture = Bit(24 - BitCorrection);
static constexpr auto BlendTexture = !NoBlendTexture;
constexpr CodeBase() = default;
constexpr CodeBase(const T& code) : value(code.value) {
}
@@ -26,6 +34,22 @@ namespace JabyEngine {
this->value = bit::set(this->value, bit);
return static_cast<T&>(*this);
}
constexpr T& set(BitRange::RangeValuePair<uint8_t> value_pair) {
this->value = bit::value::set_normalized(this->value, value_pair);
return static_cast<T&>(*this);
}
template<typename S, typename R>
constexpr T& set_tenary(bool use_first, const S& first, const R& second) {
if(use_first) {
return this->set(first);
}
else {
return this->set(second);
}
}
};
// Concept for now