Support LINE_F
This commit is contained in:
parent
59991a480f
commit
fc0e2db726
|
@ -22,6 +22,8 @@ static constexpr auto RectangleArea = JabyEngine::GPU::AreaI16({0, TriangleArea
|
|||
static constexpr auto RectangleTPage = JabyEngine::GPU::TPage(320, 256, JabyEngine::GPU::SemiTransparency::B_Half_add_F_Half, JabyEngine::GPU::TexturePageColor::$4bit);
|
||||
static constexpr auto RectangleClut = JabyEngine::GPU::PageClut(320, 510);
|
||||
|
||||
static constexpr auto LineColor = JabyEngine::GPU::Color24(0xFF, 0x0, 0x0);
|
||||
|
||||
static constexpr const auto triangle1 = JabyEngine::GPU::POLY_F3({
|
||||
{TriangleArea.position.x, TriangleArea.position.y},
|
||||
{TriangleArea.size.width, TriangleArea.size.height},
|
||||
|
@ -85,6 +87,12 @@ static constexpr const auto rectangle5 = JabyEngine::GPU::POLY_GT4(
|
|||
JabyEngine::GPU::Color24::White()}
|
||||
).set_semi_transparent(true);
|
||||
|
||||
static constexpr const JabyEngine::GPU::LINE_F line1[] = {
|
||||
JabyEngine::GPU::LINE_F::new_line(LineColor, false),
|
||||
JabyEngine::GPU::LINE_F::new_point({0, 0}),
|
||||
JabyEngine::GPU::LINE_F::new_point({JabyEngine::GPU::Display::Width, JabyEngine::GPU::Display::Height})
|
||||
};
|
||||
|
||||
static void load_assets() {
|
||||
static const JabyEngine::CDFile Assets[] = {
|
||||
JabyEngine::CDFileBuilder::simple_tim(LBA::FONT, JabyEngine::SimpleTIM(320, 0, 320, 511)),
|
||||
|
@ -130,6 +138,8 @@ void main() {
|
|||
JabyEngine::GPU::render(rectangle4);
|
||||
JabyEngine::GPU::render(rectangle5);
|
||||
|
||||
JabyEngine::GPU::render(line1);
|
||||
|
||||
JabyEngine::GPU::swap_buffers_vsync(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#ifndef __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__
|
||||
#define __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace internal {
|
||||
struct LineCode : public CodeBase<LineCode> {
|
||||
static constexpr uint8_t CmdValue = 0b010;
|
||||
|
||||
static constexpr auto GouraudShading = Bit(28 - BitCorrection);
|
||||
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>
|
||||
struct LineCodeInterface {
|
||||
typedef ::JabyEngine::GPU::internal::LineCode Code;
|
||||
|
||||
constexpr T& set_poly_line(bool set = true) {
|
||||
if(set) {
|
||||
static_cast<T*>(this)->head.code.set(Code::PolyLine);
|
||||
}
|
||||
else {
|
||||
static_cast<T*>(this)->head.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);
|
||||
}
|
||||
else {
|
||||
static_cast<T*>(this)->head.code.set(Code::NonTransparent);
|
||||
}
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct LINE_F : public internal::IsPrimitive, 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;
|
||||
};
|
||||
|
||||
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) {
|
||||
return {.vertex = vertex};
|
||||
}
|
||||
|
||||
static constexpr LINE_F new_terminate() {
|
||||
return {.vertex = {static_cast<short>(0xF000), static_cast<short>(0xF000u)}};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!__JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__
|
|
@ -5,7 +5,7 @@
|
|||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace internal {
|
||||
struct Code : public CodeBase<Code> {
|
||||
struct PolyCode : public CodeBase<PolyCode> {
|
||||
static constexpr uint8_t CmdValue = 0b001;
|
||||
|
||||
static constexpr auto GouraudShading = Bit(28 - BitCorrection);
|
||||
|
@ -21,8 +21,8 @@ namespace JabyEngine {
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
struct CodeInterface {
|
||||
typedef ::JabyEngine::GPU::internal::Code Code;
|
||||
struct PolyCodeInterface {
|
||||
typedef ::JabyEngine::GPU::internal::PolyCode Code;
|
||||
|
||||
constexpr T& set_semi_transparent(bool set = true) {
|
||||
if(set) {
|
||||
|
@ -51,7 +51,7 @@ namespace JabyEngine {
|
|||
/ \
|
||||
3 - 2
|
||||
*/
|
||||
struct POLY_F3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F3> {
|
||||
struct POLY_F3 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_F3> {
|
||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent);
|
||||
|
||||
Color24 color; // a
|
||||
|
@ -69,7 +69,7 @@ namespace JabyEngine {
|
|||
}
|
||||
};
|
||||
|
||||
struct POLY_FT3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_FT3> {
|
||||
struct POLY_FT3 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_FT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
|
@ -100,7 +100,7 @@ namespace JabyEngine {
|
|||
vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {}
|
||||
};
|
||||
|
||||
struct POLY_G3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_G3> {
|
||||
struct POLY_G3 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_G3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
Color24 color;
|
||||
|
@ -128,7 +128,7 @@ namespace JabyEngine {
|
|||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {}
|
||||
};
|
||||
|
||||
struct POLY_GT3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_GT3> {
|
||||
struct POLY_GT3 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_GT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
|
@ -168,7 +168,7 @@ namespace JabyEngine {
|
|||
| |
|
||||
3 - 4
|
||||
*/
|
||||
struct POLY_F4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F4> {
|
||||
struct POLY_F4 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_F4> {
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color; // a
|
||||
|
@ -193,7 +193,7 @@ namespace JabyEngine {
|
|||
color) {}
|
||||
};
|
||||
|
||||
struct POLY_FT4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_FT4> {
|
||||
struct POLY_FT4 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_FT4> {
|
||||
typedef POLY_FT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
|
@ -233,7 +233,7 @@ namespace JabyEngine {
|
|||
) {}
|
||||
};
|
||||
|
||||
struct POLY_G4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_G4> {
|
||||
struct POLY_G4 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_G4> {
|
||||
typedef POLY_G3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
|
@ -270,7 +270,7 @@ namespace JabyEngine {
|
|||
) {}
|
||||
};
|
||||
|
||||
struct POLY_GT4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_GT4> {
|
||||
struct POLY_GT4 : public internal::IsPrimitive, public internal::PolyCodeInterface<POLY_GT4> {
|
||||
typedef POLY_GT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
|
|
|
@ -45,6 +45,11 @@ 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);
|
||||
}
|
||||
|
||||
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef __JABYENGINE_GPU_PRIMITIVES_HPP__
|
||||
#define __JABYENGINE_GPU_PRIMITIVES_HPP__
|
||||
#include "Primitives/primitive_line_types.hpp"
|
||||
#include "Primitives/primitive_poly_types.hpp"
|
||||
#endif // !__JABYENGINE_GPU_PRIMITIVES_HPP__
|
Loading…
Reference in New Issue