Improve LINE_F code
This commit is contained in:
@@ -22,66 +22,76 @@ namespace JabyEngine {
|
||||
|
||||
constexpr T& set_poly_line(bool set = true) {
|
||||
if(set) {
|
||||
static_cast<T*>(this)->head.code.set(Code::PolyLine);
|
||||
static_cast<T*>(this)->code.set(Code::PolyLine);
|
||||
}
|
||||
else {
|
||||
static_cast<T*>(this)->head.code.set(Code::SingleLine);
|
||||
static_cast<T*>(this)->code.set(Code::SingleLine);
|
||||
}
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
constexpr T& set_semi_transparent(bool set = true) {
|
||||
if(set) {
|
||||
static_cast<T*>(this)->head.code.set(Code::SemiTransparent);
|
||||
static_cast<T*>(this)->code.set(Code::SemiTransparent);
|
||||
}
|
||||
else {
|
||||
static_cast<T*>(this)->head.code.set(Code::NonTransparent);
|
||||
static_cast<T*>(this)->code.set(Code::NonTransparent);
|
||||
}
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
};
|
||||
|
||||
struct LineHead : public LineCodeInterface<LineHead> {
|
||||
Color24 color;
|
||||
Code code;
|
||||
};
|
||||
|
||||
union LineUnion {
|
||||
LineHead head;
|
||||
Vertex vertex;
|
||||
Color24 color;
|
||||
|
||||
static constexpr LineUnion create_head(const Color24& color, const LineCode& code, bool is_poly) {
|
||||
return LineUnion{.head = LineHead{.color = color, .code = code}.set_poly_line(is_poly)};
|
||||
}
|
||||
|
||||
static constexpr LineUnion create_vertex(const Vertex& vertex) {
|
||||
return LineUnion{.vertex = {vertex.x, vertex.y}};
|
||||
}
|
||||
|
||||
static constexpr LineUnion create_terminate() {
|
||||
return LineUnion{.vertex = {static_cast<short>(0x5000), static_cast<short>(0x5000)}};
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct Line {
|
||||
LineUnion data[N];
|
||||
};
|
||||
}
|
||||
|
||||
struct LINE_F : public internal::LineCodeInterface<LINE_F> {
|
||||
struct Head {
|
||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent);
|
||||
|
||||
Color24 color;
|
||||
Code code = IdentityCode;
|
||||
};
|
||||
struct LINE_F {
|
||||
typedef ::JabyEngine::GPU::internal::LineCode Code;
|
||||
typedef ::JabyEngine::GPU::internal::LineUnion LineUnion;
|
||||
|
||||
typedef Vertex Body;
|
||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent);
|
||||
|
||||
union {
|
||||
Head head;
|
||||
Vertex vertex;
|
||||
};
|
||||
|
||||
static constexpr LINE_F new_line(const Color24& color, bool is_poly) {
|
||||
return LINE_F{.head = {.color = color, .code = Head::IdentityCode}}.set_poly_line(is_poly);
|
||||
static constexpr internal::Line<3> create(const Color24& color, const Vertex (&vertices)[2]) {
|
||||
return internal::Line<3>{LineUnion::create_head(color, IdentityCode, false), LineUnion::create_vertex(vertices[0]), LineUnion::create_vertex(vertices[1])};
|
||||
}
|
||||
|
||||
static constexpr LINE_F new_point(const Vertex& vertex) {
|
||||
return {.vertex = vertex};
|
||||
}
|
||||
|
||||
static constexpr LINE_F new_terminate() {
|
||||
return {.vertex = {static_cast<short>(0xF000), static_cast<short>(0xF000u)}};
|
||||
template<typename...ARGS>
|
||||
static constexpr internal::Line<sizeof...(ARGS) + 2> create(const Color24& color, const ARGS&...args) {
|
||||
return internal::Line<sizeof...(ARGS) + 2>{LineUnion::create_head(color, IdentityCode, true), LineUnion::create_vertex(args)..., LineUnion::create_terminate()};
|
||||
}
|
||||
};
|
||||
|
||||
struct LineMaker {
|
||||
// Make this it's own outside type??
|
||||
template<typename T, size_t N>
|
||||
struct Type {
|
||||
T head;
|
||||
T body[N];
|
||||
namespace internal {
|
||||
template<size_t N>
|
||||
struct is_render_primitive<Line<N>> {
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
static constexpr Type<LINE_F, 2> new_line_f(const Color24& color, const Vertex (&vertices)[2]) {
|
||||
return Type<LINE_F, 2>{.head = LINE_F::new_line(color, false), .body = {LINE_F::new_point(vertices[0]), LINE_F::new_point(vertices[1])}};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user