Improve LINE_F code
This commit is contained in:
parent
1b37748e0a
commit
f1563b990f
|
@ -87,9 +87,17 @@ static constexpr const auto rectangle5 = JabyEngine::GPU::POLY_GT4(
|
||||||
JabyEngine::GPU::Color24::White()}
|
JabyEngine::GPU::Color24::White()}
|
||||||
).set_semi_transparent(true);
|
).set_semi_transparent(true);
|
||||||
|
|
||||||
static constexpr const auto line1 = JabyEngine::GPU::LineMaker::new_line_f(LineColor, {
|
static constexpr const auto line1 = JabyEngine::GPU::LINE_F::create(LineColor, {
|
||||||
{0, 0},
|
{0, 0},
|
||||||
{JabyEngine::GPU::Display::Width, JabyEngine::GPU::Display::Height}});
|
{JabyEngine::GPU::Display::Width, JabyEngine::GPU::Display::Height}
|
||||||
|
});
|
||||||
|
|
||||||
|
static constexpr const auto line2 = JabyEngine::GPU::LINE_F::create(LineColor.invert(),
|
||||||
|
JabyEngine::GPU::Vertex(0, 0),
|
||||||
|
JabyEngine::GPU::Vertex(16, 0),
|
||||||
|
JabyEngine::GPU::Vertex(16, 16),
|
||||||
|
JabyEngine::GPU::Vertex(0, 0)
|
||||||
|
);
|
||||||
|
|
||||||
static void load_assets() {
|
static void load_assets() {
|
||||||
static const JabyEngine::CDFile Assets[] = {
|
static const JabyEngine::CDFile Assets[] = {
|
||||||
|
@ -122,7 +130,6 @@ static void load_assets() {
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
load_assets();
|
load_assets();
|
||||||
printf("Dino: 0x%02X\n", rectangle4.code.value);
|
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
JabyEngine::GPU::render(triangle1);
|
JabyEngine::GPU::render(triangle1);
|
||||||
|
@ -137,6 +144,7 @@ void main() {
|
||||||
JabyEngine::GPU::render(rectangle5);
|
JabyEngine::GPU::render(rectangle5);
|
||||||
|
|
||||||
JabyEngine::GPU::render(line1);
|
JabyEngine::GPU::render(line1);
|
||||||
|
JabyEngine::GPU::render(line2);
|
||||||
|
|
||||||
JabyEngine::GPU::swap_buffers_vsync(2);
|
JabyEngine::GPU::swap_buffers_vsync(2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,50 @@ namespace JabyEngine {
|
||||||
struct enable_if<true, T> {
|
struct enable_if<true, T> {
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// #############################################
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
struct is_same {
|
||||||
|
static constexpr bool value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct is_same<T, T> {
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// #############################################
|
||||||
|
|
||||||
|
template<bool B, class T, class F>
|
||||||
|
struct conditional {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class F>
|
||||||
|
struct conditional<false, T, F> {
|
||||||
|
using type = F;
|
||||||
|
};
|
||||||
|
|
||||||
|
// #############################################
|
||||||
|
|
||||||
|
template<class...>
|
||||||
|
struct conjunction {
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class B1>
|
||||||
|
struct conjunction<B1> : B1 {
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class B1, class... Bn>
|
||||||
|
struct conjunction<B1, Bn...> : conditional<bool(B1::value), conjunction<Bn...>, B1>::type {
|
||||||
|
};
|
||||||
|
|
||||||
|
// #############################################
|
||||||
|
|
||||||
|
template<typename T, typename... Ts>
|
||||||
|
using variadic_force_same = enable_if<conjunction<is_same<T, Ts>...>::value>::type;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //! __JABYENGINE_TYPE_TRAITS_HPP__
|
#endif //! __JABYENGINE_TYPE_TRAITS_HPP__
|
|
@ -22,66 +22,76 @@ namespace JabyEngine {
|
||||||
|
|
||||||
constexpr T& set_poly_line(bool set = true) {
|
constexpr T& set_poly_line(bool set = true) {
|
||||||
if(set) {
|
if(set) {
|
||||||
static_cast<T*>(this)->head.code.set(Code::PolyLine);
|
static_cast<T*>(this)->code.set(Code::PolyLine);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
static_cast<T*>(this)->head.code.set(Code::SingleLine);
|
static_cast<T*>(this)->code.set(Code::SingleLine);
|
||||||
}
|
}
|
||||||
return *static_cast<T*>(this);
|
return *static_cast<T*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T& set_semi_transparent(bool set = true) {
|
constexpr T& set_semi_transparent(bool set = true) {
|
||||||
if(set) {
|
if(set) {
|
||||||
static_cast<T*>(this)->head.code.set(Code::SemiTransparent);
|
static_cast<T*>(this)->code.set(Code::SemiTransparent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
static_cast<T*>(this)->head.code.set(Code::NonTransparent);
|
static_cast<T*>(this)->code.set(Code::NonTransparent);
|
||||||
}
|
}
|
||||||
return *static_cast<T*>(this);
|
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)};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LINE_F : public internal::LineCodeInterface<LINE_F> {
|
static constexpr LineUnion create_vertex(const Vertex& vertex) {
|
||||||
struct Head {
|
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 {
|
||||||
|
typedef ::JabyEngine::GPU::internal::LineCode Code;
|
||||||
|
typedef ::JabyEngine::GPU::internal::LineUnion LineUnion;
|
||||||
|
|
||||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent);
|
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent);
|
||||||
|
|
||||||
Color24 color;
|
static constexpr internal::Line<3> create(const Color24& color, const Vertex (&vertices)[2]) {
|
||||||
Code code = IdentityCode;
|
return internal::Line<3>{LineUnion::create_head(color, IdentityCode, false), LineUnion::create_vertex(vertices[0]), LineUnion::create_vertex(vertices[1])};
|
||||||
};
|
|
||||||
|
|
||||||
typedef Vertex Body;
|
|
||||||
|
|
||||||
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 LINE_F new_point(const Vertex& vertex) {
|
template<typename...ARGS>
|
||||||
return {.vertex = vertex};
|
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()};
|
||||||
|
|
||||||
static constexpr LINE_F new_terminate() {
|
|
||||||
return {.vertex = {static_cast<short>(0xF000), static_cast<short>(0xF000u)}};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LineMaker {
|
namespace internal {
|
||||||
// Make this it's own outside type??
|
template<size_t N>
|
||||||
template<typename T, size_t N>
|
struct is_render_primitive<Line<N>> {
|
||||||
struct Type {
|
static constexpr bool value = true;
|
||||||
T head;
|
|
||||||
T body[N];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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])}};
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,14 +45,9 @@ namespace JabyEngine {
|
||||||
internal::render(reinterpret_cast<const uint32_t*>(&primitive), sizeof(T)/sizeof(uint32_t));
|
internal::render(reinterpret_cast<const uint32_t*>(&primitive), sizeof(T)/sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N>
|
template<typename T, size_t N>
|
||||||
static void render(const LINE_F (&line)[N]) {
|
static enable_if<internal::is_render_primitive<T>::value>::type render(const LINE_F (&primitives)[N]) {
|
||||||
internal::render(reinterpret_cast<const uint32_t*>(&line), N);
|
internal::render(reinterpret_cast<const uint32_t*>(&primitives), (sizeof(T)/sizeof(uint32_t))*N);
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t N>
|
|
||||||
static void render(const LineMaker::Type<LINE_F, N>& line_type) {
|
|
||||||
internal::render(reinterpret_cast<const uint32_t*>(&line_type), sizeof(line_type)/sizeof(uint32_t));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true);
|
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true);
|
||||||
|
|
|
@ -68,6 +68,10 @@ namespace JabyEngine {
|
||||||
static constexpr Color24 Blue() {
|
static constexpr Color24 Blue() {
|
||||||
return Color24(0x0, 0x0, 0xFF);
|
return Color24(0x0, 0x0, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Color24 invert() const {
|
||||||
|
return Color24(0xFF - this->red, 0xFF - this->green, 0xFF - this->blue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Color {
|
class Color {
|
||||||
|
|
Loading…
Reference in New Issue