Integrate all the progress into master #6
|
@ -87,9 +87,17 @@ static constexpr const auto rectangle5 = JabyEngine::GPU::POLY_GT4(
|
|||
JabyEngine::GPU::Color24::White()}
|
||||
).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},
|
||||
{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 const JabyEngine::CDFile Assets[] = {
|
||||
|
@ -122,7 +130,6 @@ static void load_assets() {
|
|||
|
||||
void main() {
|
||||
load_assets();
|
||||
printf("Dino: 0x%02X\n", rectangle4.code.value);
|
||||
|
||||
while(true) {
|
||||
JabyEngine::GPU::render(triangle1);
|
||||
|
@ -137,6 +144,7 @@ void main() {
|
|||
JabyEngine::GPU::render(rectangle5);
|
||||
|
||||
JabyEngine::GPU::render(line1);
|
||||
JabyEngine::GPU::render(line2);
|
||||
|
||||
JabyEngine::GPU::swap_buffers_vsync(2);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,50 @@ namespace JabyEngine {
|
|||
struct enable_if<true, T> {
|
||||
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__
|
|
@ -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])}};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,14 +45,9 @@ namespace JabyEngine {
|
|||
internal::render(reinterpret_cast<const uint32_t*>(&primitive), sizeof(T)/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
static void render(const LINE_F (&line)[N]) {
|
||||
internal::render(reinterpret_cast<const uint32_t*>(&line), 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));
|
||||
template<typename T, size_t N>
|
||||
static enable_if<internal::is_render_primitive<T>::value>::type render(const LINE_F (&primitives)[N]) {
|
||||
internal::render(reinterpret_cast<const uint32_t*>(&primitives), (sizeof(T)/sizeof(uint32_t))*N);
|
||||
}
|
||||
|
||||
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true);
|
||||
|
|
|
@ -68,6 +68,10 @@ namespace JabyEngine {
|
|||
static constexpr Color24 Blue() {
|
||||
return Color24(0x0, 0x0, 0xFF);
|
||||
}
|
||||
|
||||
constexpr Color24 invert() const {
|
||||
return Color24(0xFF - this->red, 0xFF - this->green, 0xFF - this->blue);
|
||||
}
|
||||
};
|
||||
|
||||
class Color {
|
||||
|
|
Loading…
Reference in New Issue