Integrate all the progress into master #6
|
@ -22,13 +22,13 @@ 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 const JabyEngine::GPU::POLY_F3 triangle1({
|
||||
static constexpr const auto triangle1 = JabyEngine::GPU::POLY_F3({
|
||||
{TriangleArea.position.x, TriangleArea.position.y},
|
||||
{TriangleArea.size.width, TriangleArea.size.height},
|
||||
{TriangleArea.position.x, TriangleArea.size.height}},
|
||||
TriangleColor
|
||||
);
|
||||
static constexpr const JabyEngine::GPU::POLY_FT3 triangle2({
|
||||
static constexpr const auto triangle2 = JabyEngine::GPU::POLY_FT3({
|
||||
{TriangleArea.position.x, TriangleArea.position.y},
|
||||
{TriangleArea.size.width, TriangleArea.position.y},
|
||||
{TriangleArea.size.width, TriangleArea.size.height}},{
|
||||
|
@ -40,12 +40,12 @@ static constexpr const JabyEngine::GPU::POLY_FT3 triangle2({
|
|||
TriangleClut,
|
||||
JabyEngine::GPU::Color24::Grey()
|
||||
);
|
||||
static constexpr const JabyEngine::GPU::POLY_G3 triangle3({
|
||||
static constexpr const auto triangle3 = JabyEngine::GPU::POLY_G3({
|
||||
{triangle1.vertex0.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Red()},
|
||||
{triangle1.vertex1.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Green()},
|
||||
{triangle1.vertex2.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Blue()}}
|
||||
);
|
||||
static constexpr const JabyEngine::GPU::POLY_GT3 triangle4({
|
||||
static constexpr const auto triangle4 = JabyEngine::GPU::POLY_GT3({
|
||||
{triangle2.vertex0.move(TriangleArea.size.width, 0), triangle2.page0, JabyEngine::GPU::Color24::Red()},
|
||||
{triangle2.vertex1.move(TriangleArea.size.width, 0), triangle2.page1, JabyEngine::GPU::Color24::Blue()},
|
||||
{triangle2.vertex2.move(TriangleArea.size.width, 0), triangle2.page2, JabyEngine::GPU::Color24::Green()}},
|
||||
|
@ -53,20 +53,20 @@ static constexpr const JabyEngine::GPU::POLY_GT3 triangle4({
|
|||
TriangleClut
|
||||
);
|
||||
|
||||
static constexpr const JabyEngine::GPU::POLY_F4 rectangle1(RectangleArea, RectangleColor);
|
||||
static constexpr const JabyEngine::GPU::POLY_FT4 rectangle2({
|
||||
static constexpr const auto rectangle1 = JabyEngine::GPU::POLY_F4(RectangleArea, RectangleColor);
|
||||
static constexpr const auto rectangle2 = JabyEngine::GPU::POLY_FT4({
|
||||
RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size}, {0, 0},
|
||||
RectangleTPage,
|
||||
RectangleClut,
|
||||
JabyEngine::GPU::Color24::Grey()
|
||||
);
|
||||
static constexpr const JabyEngine::GPU::POLY_G4 rectangle3(
|
||||
static constexpr const auto rectangle3 = JabyEngine::GPU::POLY_G4(
|
||||
{RectangleArea.position.move(RectangleArea.size.width*2, 0), RectangleArea.size}, {
|
||||
JabyEngine::GPU::Color24::Red(),
|
||||
JabyEngine::GPU::Color24::Blue(),
|
||||
JabyEngine::GPU::Color24::Green(),
|
||||
JabyEngine::GPU::Color24::White()});
|
||||
static constexpr const JabyEngine::GPU::POLY_GT4 rectangle4(
|
||||
static constexpr const auto rectangle4 = JabyEngine::GPU::POLY_GT4(
|
||||
{RectangleArea.position.move(RectangleArea.size.width*3, 0), RectangleArea.size}, {0, 0},
|
||||
RectangleTPage,
|
||||
RectangleClut, {
|
||||
|
@ -107,7 +107,7 @@ static void load_assets() {
|
|||
|
||||
void main() {
|
||||
load_assets();
|
||||
|
||||
|
||||
while(true) {
|
||||
JabyEngine::GPU::render(triangle1);
|
||||
JabyEngine::GPU::render(triangle2);
|
||||
|
|
|
@ -0,0 +1,339 @@
|
|||
#ifndef __JABYENGINE_PRIMITIVE_POLY_TYPES_HPP__
|
||||
#define __JABYENGINE_PRIMITIVE_POLY_TYPES_HPP__
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace internal {
|
||||
struct Code : public CodeBase<Code> {
|
||||
static constexpr uint8_t CmdValue = 0b001;
|
||||
|
||||
static constexpr auto GouraudShading = Bit(28 - BitCorrection);
|
||||
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>
|
||||
struct CodeInterface {
|
||||
typedef ::JabyEngine::GPU::internal::Code 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
1
|
||||
/ \
|
||||
3 - 2
|
||||
*/
|
||||
struct POLY_F3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F3> {
|
||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Vertex vertex1; // c
|
||||
Vertex vertex2; // d
|
||||
|
||||
constexpr POLY_F3() = default;
|
||||
constexpr POLY_F3(const Vertex (&verticies)[3], Color24 color) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(verticies[0]),
|
||||
vertex1(verticies[1]),
|
||||
vertex2(verticies[2]) {
|
||||
}
|
||||
};
|
||||
|
||||
struct POLY_FT3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_FT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
};
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::Textured);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Vertex vertex1; // d
|
||||
PagePosition page1; // e
|
||||
TPage tpage; // e
|
||||
Vertex vertex2; // f
|
||||
PagePosition page2; // g
|
||||
uint16_t padded2; // g
|
||||
|
||||
constexpr POLY_FT3() = default;
|
||||
constexpr POLY_FT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], TPage tpage, PageClut clut, Color24 color = Color24::Grey()) : POLY_FT3({
|
||||
{verticies[0], page_pos[0]},
|
||||
{verticies[1], page_pos[1]},
|
||||
{verticies[2], page_pos[2]}}, tpage, clut, color) {}
|
||||
constexpr POLY_FT3(const VertexEx (&vertices_ex)[3], TPage tpage, PageClut clut, Color24 color) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(vertices_ex[0].position), page0(vertices_ex[0].page), page_clut(clut),
|
||||
vertex1(vertices_ex[1].position), page1(vertices_ex[1].page), tpage(tpage),
|
||||
vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {}
|
||||
};
|
||||
|
||||
struct POLY_G3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_G3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
Color24 color;
|
||||
};
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::GouraudShading);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Color24 color1; // c
|
||||
uint8_t pad1; // c
|
||||
Vertex vertex1; // d
|
||||
Color24 color2; // e
|
||||
uint8_t pad2; // e
|
||||
Vertex vertex2; // f
|
||||
|
||||
constexpr POLY_G3() = default;
|
||||
constexpr POLY_G3(const Vertex (&verticies)[3], const Color24 (&color)[3]) : POLY_G3({
|
||||
{verticies[0], color[0]},
|
||||
{verticies[1], color[1]},
|
||||
{verticies[2], color[2]}}) {}
|
||||
constexpr POLY_G3(const VertexEx (&verticies_ex)[3]) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {}
|
||||
};
|
||||
|
||||
struct POLY_GT3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_GT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
Color24 color;
|
||||
};
|
||||
static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::Textured);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Color24 color1; // d
|
||||
uint8_t pad1; // d
|
||||
Vertex vertex1; // e
|
||||
PagePosition page1; // f
|
||||
TPage tpage; // f
|
||||
Color24 color2; // g
|
||||
uint8_t pad2; // g
|
||||
Vertex vertex2; // h
|
||||
PagePosition page2; // i
|
||||
uint16_t pad3; // i
|
||||
|
||||
constexpr POLY_GT3() = default;
|
||||
constexpr POLY_GT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], const Color24 (&color)[3], TPage tpage, PageClut clut) : POLY_GT3({
|
||||
{verticies[0], page_pos[0], color[0]},
|
||||
{verticies[1], page_pos[1], color[1]},
|
||||
{verticies[2], page_pos[2], color[2]}}, tpage, clut) {}
|
||||
constexpr POLY_GT3(const VertexEx (&verticies_ex)[3], TPage tpage, PageClut clut) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position), page0(verticies_ex[0].page), page_clut(clut),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position), page1(verticies_ex[1].page), tpage(tpage),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position), page2(verticies_ex[2].page), pad3(0) {}
|
||||
};
|
||||
|
||||
/*
|
||||
1 - 2
|
||||
| |
|
||||
3 - 4
|
||||
*/
|
||||
struct POLY_F4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F4> {
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Vertex vertex1; // c
|
||||
Vertex vertex2; // d
|
||||
Vertex vertex3; // e
|
||||
|
||||
constexpr POLY_F4() = default;
|
||||
constexpr POLY_F4(const Vertex (&verticies)[4], Color24 color) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(verticies[0]),
|
||||
vertex1(verticies[1]),
|
||||
vertex2(verticies[2]),
|
||||
vertex3(verticies[3]) {}
|
||||
constexpr POLY_F4(const AreaI16& area, Color24 color) : POLY_F4({
|
||||
area.position,
|
||||
area.position.move(area.size.width, 0),
|
||||
area.position.move(0, area.size.height),
|
||||
area.position.move(area.size.width, area.size.height)},
|
||||
color) {}
|
||||
};
|
||||
|
||||
struct POLY_FT4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_FT4> {
|
||||
typedef POLY_FT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Vertex vertex1; // d
|
||||
PagePosition page1; // e
|
||||
TPage tpage; // e
|
||||
Vertex vertex2; // f
|
||||
PagePosition page2; // g
|
||||
uint16_t pad2; // g
|
||||
Vertex vertex3; // h
|
||||
PagePosition page3; // i
|
||||
uint16_t pad3; // i
|
||||
|
||||
constexpr POLY_FT4() = default;
|
||||
constexpr POLY_FT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], TPage tpage, PageClut clut, Color24 color) : POLY_FT4({
|
||||
{verticies[0], page_pos[0]},
|
||||
{verticies[1], page_pos[1]},
|
||||
{verticies[2], page_pos[2]},
|
||||
{verticies[3], page_pos[3]}}, tpage, clut, color) {}
|
||||
constexpr POLY_FT4(const VertexEx (&vertices_ex)[4], TPage tpage, PageClut clut, Color24 color = Color24::Grey()) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(vertices_ex[0].position), page0(vertices_ex[0].page), page_clut(clut),
|
||||
vertex1(vertices_ex[1].position), page1(vertices_ex[1].page), tpage(tpage),
|
||||
vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), pad2(0),
|
||||
vertex3(vertices_ex[3].position), page3(vertices_ex[3].page), pad3(0) {}
|
||||
constexpr POLY_FT4(const AreaI16& area, const PagePosition& texture_pos, TPage tpage, PageClut clut, Color24 color) : POLY_FT4({
|
||||
{area.position, texture_pos},
|
||||
{area.position.move(area.size.width, 0), texture_pos.move(area.size.width, 0)},
|
||||
{area.position.move(0, area.size.height), texture_pos.move(0, area.size.height)},
|
||||
{area.position.move(area.size.width, area.size.height), texture_pos.move(area.size.width, area.size.height)}},
|
||||
tpage, clut, color
|
||||
) {}
|
||||
};
|
||||
|
||||
struct POLY_G4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_G4> {
|
||||
typedef POLY_G3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Color24 color1; // c
|
||||
uint8_t pad1; // c
|
||||
Vertex vertex1; // d
|
||||
Color24 color2; // e
|
||||
uint8_t pad2; // e
|
||||
Vertex vertex2; // f
|
||||
Color24 color3; // g
|
||||
uint8_t pad3; // g
|
||||
Vertex vertex3; // h
|
||||
|
||||
constexpr POLY_G4() = default;
|
||||
constexpr POLY_G4(const Vertex (&verticies)[4], const Color24 (&color)[4]) : POLY_G4({
|
||||
{verticies[0], color[0]},
|
||||
{verticies[1], color[1]},
|
||||
{verticies[2], color[2]},
|
||||
{verticies[3], color[3]}
|
||||
}) {}
|
||||
constexpr POLY_G4(const VertexEx (&verticies_ex)[4]) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position),
|
||||
color3(verticies_ex[3].color), pad3(0), vertex3(verticies_ex[3].position) {}
|
||||
constexpr POLY_G4(const AreaI16& area, const Color24 (&color)[4]) : POLY_G4({
|
||||
{area.position, color[0]},
|
||||
{area.position.move(area.size.width, 0), color[1]},
|
||||
{area.position.move(0, area.size.height), color[2]},
|
||||
{area.position.move(area.size.width, area.size.height), color[3]}}
|
||||
) {}
|
||||
};
|
||||
|
||||
struct POLY_GT4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_GT4> {
|
||||
typedef POLY_GT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Color24 color1; // d
|
||||
uint8_t pad1; // d
|
||||
Vertex vertex1; // e
|
||||
PagePosition page1; // f
|
||||
TPage tpage; // f
|
||||
Color24 color2; // g
|
||||
uint8_t pad2; // g
|
||||
Vertex vertex2; // h
|
||||
PagePosition page2; // i
|
||||
uint16_t pad3; // i
|
||||
Color24 color3; // j
|
||||
uint8_t pad4; // j
|
||||
Vertex vertex3; // k
|
||||
PagePosition page3; // l
|
||||
uint16_t pad5; // l
|
||||
|
||||
constexpr POLY_GT4() = default;
|
||||
constexpr POLY_GT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], const Color24 (&color)[4], TPage tpage, PageClut clut) : POLY_GT4({
|
||||
{verticies[0], page_pos[0], color[0]},
|
||||
{verticies[1], page_pos[1], color[1]},
|
||||
{verticies[2], page_pos[2], color[2]},
|
||||
{verticies[3], page_pos[3], color[3]},
|
||||
}, tpage, clut) {}
|
||||
constexpr POLY_GT4(const VertexEx (&verticies_ex)[4], TPage tpage, PageClut clut) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position), page0(verticies_ex[0].page), page_clut(clut),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position), page1(verticies_ex[1].page), tpage(tpage),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position), page2(verticies_ex[2].page), pad3(0),
|
||||
color3(verticies_ex[3].color), pad4(0), vertex3(verticies_ex[3].position), page3(verticies_ex[3].page), pad5(0) {}
|
||||
constexpr POLY_GT4(const AreaI16& area, const PagePosition& texture_pos, TPage tpage, PageClut clut, const Color24 (&color)[4]) : POLY_GT4({
|
||||
{area.position, texture_pos, color[0]},
|
||||
{area.position.move(area.size.width, 0), texture_pos.move(area.size.width, 0), color[1]},
|
||||
{area.position.move(0, area.size.height), texture_pos.move(0, area.size.height), color[2]},
|
||||
{area.position.move(area.size.width, area.size.height), texture_pos.move(area.size.width, area.size.height), color[3]}
|
||||
}, tpage, clut) {}
|
||||
};
|
||||
|
||||
typedef POLY_F3 FlatTriangle;
|
||||
typedef POLY_FT3 FlatTexturedTriangle;
|
||||
typedef POLY_G3 GouraudTriangle;
|
||||
typedef POLY_GT3 GouraudTexturedTriangle;
|
||||
|
||||
typedef POLY_F4 FlatRectangle;
|
||||
typedef POLY_FT4 FlatTexturedRectangle;
|
||||
typedef POLY_G4 GouraudRectangle;
|
||||
typedef POLY_GT4 GouraudTexturedRectangle;
|
||||
|
||||
static_assert(sizeof(POLY_F3) == 16);
|
||||
static_assert(sizeof(POLY_FT3) == 28);
|
||||
static_assert(sizeof(POLY_G3) == 24);
|
||||
static_assert(sizeof(POLY_GT3) == 36);
|
||||
|
||||
static_assert(sizeof(POLY_F4) == 20);
|
||||
static_assert(sizeof(POLY_FT4) == 36);
|
||||
static_assert(sizeof(POLY_G4) == 32);
|
||||
static_assert(sizeof(POLY_GT4) == 48);
|
||||
}
|
||||
}
|
||||
#endif // !__JABYENGINE_PRIMITIVE_POLY_TYPES_HPP__
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef __JABYENGINE_PRIMITIVE_SUPPORT_TYPES_HPP__
|
||||
#define __JABYENGINE_PRIMITIVE_SUPPORT_TYPES_HPP__
|
||||
#include "../gpu_types.hpp"
|
||||
#include "../../System/IOPorts/gpu_io.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace internal {
|
||||
template<typename T>
|
||||
struct CodeBase {
|
||||
static constexpr auto BitCorrection = 24;
|
||||
static constexpr auto CmdID = BitRange::from_to(29 - BitCorrection, 31 - BitCorrection);
|
||||
|
||||
uint8_t value = bit::value::set_normalized(0u, CmdID.with(T::CmdValue));
|
||||
|
||||
constexpr CodeBase() = default;
|
||||
constexpr CodeBase(const T& code) : value(code.value) {
|
||||
}
|
||||
|
||||
constexpr T& set(Bit bit) {
|
||||
this->value = bit::set(this->value, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr T& set(ClearBit bit) {
|
||||
this->value = bit::set(this->value, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
// Concept for now
|
||||
template<typename T>
|
||||
struct Hooked {
|
||||
uint32_t hook;
|
||||
T primitive;
|
||||
};
|
||||
|
||||
struct IsPrimitive {
|
||||
static constexpr bool is_primitive = true;
|
||||
};
|
||||
}
|
||||
|
||||
// Reexport for easier use
|
||||
typedef JabyEngine::GPU_IO::SemiTransparency SemiTransparency;
|
||||
typedef JabyEngine::GPU_IO::TexturePageColor TexturePageColor;
|
||||
|
||||
struct PageClut {
|
||||
uint16_t value = 0;
|
||||
|
||||
constexpr PageClut() = default;
|
||||
constexpr PageClut(uint16_t x, uint16_t y) : value((y << 6) | ((x >> 4) & 0x3f)) {
|
||||
}
|
||||
};
|
||||
|
||||
struct TPage {
|
||||
static constexpr auto TexturePageX = BitRange::from_to(0, 3);
|
||||
static constexpr auto TexturePageY = BitRange::from_to(4, 4);
|
||||
static constexpr auto SemiTransparency = BitRange::from_to(5, 6);
|
||||
static constexpr auto TextureClut = BitRange::from_to(7, 8);
|
||||
|
||||
uint16_t value = 0;
|
||||
|
||||
constexpr TPage() = default;
|
||||
constexpr TPage(uint16_t x, uint16_t y, ::JabyEngine::GPU::SemiTransparency transparency, TexturePageColor clut_color) : value(TexturePageX.as_value(x >> 6) | TexturePageY.as_value(y >> 8) | SemiTransparency.as_value(static_cast<uint16_t>(transparency)) | TextureClut.as_value(static_cast<uint16_t>(clut_color))) {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_PRIMITIVE_SUPPORT_TYPES_HPP__
|
|
@ -1,398 +1,4 @@
|
|||
#ifndef __JABYENGINE_GPU_PRIMITIVES_HPP__
|
||||
#define __JABYENGINE_GPU_PRIMITIVES_HPP__
|
||||
#include "gpu_types.hpp"
|
||||
#include <PSX/System/IOPorts/gpu_io.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace internal {
|
||||
struct Code {
|
||||
static constexpr uint8_t CmdValue = 0b001;
|
||||
static constexpr auto BitCorrection = 24;
|
||||
|
||||
static constexpr auto CmdID = BitRange::from_to(29 - BitCorrection, 31 - BitCorrection);
|
||||
static constexpr auto GouraudShading = Bit(28 - BitCorrection);
|
||||
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 BlendTexture = Bit(24 - BitCorrection);
|
||||
static constexpr auto NoBlendTexture = !BlendTexture;
|
||||
|
||||
uint8_t value = bit::value::set_normalized(0u, CmdID.with(CmdValue));
|
||||
|
||||
constexpr Code() = default;
|
||||
constexpr Code(const Code& code) : value(code.value) {
|
||||
}
|
||||
|
||||
constexpr Code& set(Bit bit) {
|
||||
this->value = bit::set(this->value, bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Code& set(ClearBit bit) {
|
||||
this->value = bit::set(this->value, bit);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// Concept for now
|
||||
template<typename T>
|
||||
struct Hooked {
|
||||
uint32_t hook;
|
||||
T primitive;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct CodeInterface {
|
||||
constexpr T& set_semi_transparent() {
|
||||
static_cast<T*>(this)->code.set(Code::SemiTransparent);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
constexpr T& set_non_transparent() {
|
||||
static_cast<T*>(this)->code.set(Code::NonTransparent);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
constexpr T& set_texture_blending() {
|
||||
static_cast<T*>(this)->code.set(Code::BlendTexture);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
constexpr T& set_non_texture_blening() {
|
||||
static_cast<T*>(this)->code.set(Code::NoBlendTexture);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
};
|
||||
|
||||
struct IsPrimitive {
|
||||
static constexpr bool is_primitive = true;
|
||||
|
||||
typedef JabyEngine::GPU::internal::Code Code;
|
||||
};
|
||||
}
|
||||
|
||||
// Reexport for easier use
|
||||
typedef JabyEngine::GPU_IO::SemiTransparency SemiTransparency;
|
||||
typedef JabyEngine::GPU_IO::TexturePageColor TexturePageColor;
|
||||
|
||||
struct PageClut {
|
||||
uint16_t value = 0;
|
||||
|
||||
constexpr PageClut() = default;
|
||||
constexpr PageClut(uint16_t x, uint16_t y) : value((y << 6) | ((x >> 4) & 0x3f)) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct TPage {
|
||||
static constexpr auto TexturePageX = BitRange::from_to(0, 3);
|
||||
static constexpr auto TexturePageY = BitRange::from_to(4, 4);
|
||||
static constexpr auto SemiTransparency = BitRange::from_to(5, 6);
|
||||
static constexpr auto TextureClut = BitRange::from_to(7, 8);
|
||||
|
||||
uint16_t value = 0;
|
||||
|
||||
constexpr TPage() = default;
|
||||
constexpr TPage(uint16_t x, uint16_t y, ::JabyEngine::GPU::SemiTransparency transparency, TexturePageColor clut_color) : value(TexturePageX.as_value(x >> 6) | TexturePageY.as_value(y >> 8) | SemiTransparency.as_value(static_cast<uint16_t>(transparency)) | TextureClut.as_value(static_cast<uint16_t>(clut_color))) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
1
|
||||
/ \
|
||||
3 - 2
|
||||
*/
|
||||
struct POLY_F3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F3> {
|
||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent).set(Code::NoBlendTexture);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Vertex vertex1; // c
|
||||
Vertex vertex2; // d
|
||||
|
||||
constexpr POLY_F3() = default;
|
||||
constexpr POLY_F3(const Vertex (&verticies)[3], Color24 color) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(verticies[0]),
|
||||
vertex1(verticies[1]),
|
||||
vertex2(verticies[2]) {
|
||||
}
|
||||
};
|
||||
|
||||
struct POLY_FT3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_FT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
};
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::Textured);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Vertex vertex1; // d
|
||||
PagePosition page1; // e
|
||||
TPage tpage; // e
|
||||
Vertex vertex2; // f
|
||||
PagePosition page2; // g
|
||||
uint16_t padded2; // g
|
||||
|
||||
constexpr POLY_FT3() = default;
|
||||
constexpr POLY_FT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], TPage tpage, PageClut clut, Color24 color = Color24::Grey()) : POLY_FT3({
|
||||
{verticies[0], page_pos[0]},
|
||||
{verticies[1], page_pos[1]},
|
||||
{verticies[2], page_pos[2]}}, tpage, clut, color) {}
|
||||
constexpr POLY_FT3(const VertexEx (&vertices_ex)[3], TPage tpage, PageClut clut, Color24 color) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(vertices_ex[0].position), page0(vertices_ex[0].page), page_clut(clut),
|
||||
vertex1(vertices_ex[1].position), page1(vertices_ex[1].page), tpage(tpage),
|
||||
vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {}
|
||||
};
|
||||
|
||||
struct POLY_G3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_G3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
Color24 color;
|
||||
};
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::GouraudShading);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Color24 color1; // c
|
||||
uint8_t pad1; // c
|
||||
Vertex vertex1; // d
|
||||
Color24 color2; // e
|
||||
uint8_t pad2; // e
|
||||
Vertex vertex2; // f
|
||||
|
||||
constexpr POLY_G3() = default;
|
||||
constexpr POLY_G3(const Vertex (&verticies)[3], const Color24 (&color)[3]) : POLY_G3({
|
||||
{verticies[0], color[0]},
|
||||
{verticies[1], color[1]},
|
||||
{verticies[2], color[2]}}) {}
|
||||
constexpr POLY_G3(const VertexEx (&verticies_ex)[3]) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {}
|
||||
};
|
||||
|
||||
struct POLY_GT3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_GT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
Color24 color;
|
||||
};
|
||||
static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::Textured);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Color24 color1; // d
|
||||
uint8_t pad1; // d
|
||||
Vertex vertex1; // e
|
||||
PagePosition page1; // f
|
||||
TPage tpage; // f
|
||||
Color24 color2; // g
|
||||
uint8_t pad2; // g
|
||||
Vertex vertex2; // h
|
||||
PagePosition page2; // i
|
||||
uint16_t pad3; // i
|
||||
|
||||
constexpr POLY_GT3() = default;
|
||||
constexpr POLY_GT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], const Color24 (&color)[3], TPage tpage, PageClut clut) : POLY_GT3({
|
||||
{verticies[0], page_pos[0], color[0]},
|
||||
{verticies[1], page_pos[1], color[1]},
|
||||
{verticies[2], page_pos[2], color[2]}}, tpage, clut) {}
|
||||
constexpr POLY_GT3(const VertexEx (&verticies_ex)[3], TPage tpage, PageClut clut) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position), page0(verticies_ex[0].page), page_clut(clut),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position), page1(verticies_ex[1].page), tpage(tpage),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position), page2(verticies_ex[2].page), pad3(0) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
1 - 2
|
||||
| |
|
||||
3 - 4
|
||||
*/
|
||||
struct POLY_F4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F4> {
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Vertex vertex1; // c
|
||||
Vertex vertex2; // d
|
||||
Vertex vertex3; // e
|
||||
|
||||
constexpr POLY_F4() = default;
|
||||
constexpr POLY_F4(const Vertex (&verticies)[4], Color24 color) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(verticies[0]),
|
||||
vertex1(verticies[1]),
|
||||
vertex2(verticies[2]),
|
||||
vertex3(verticies[3]) {}
|
||||
constexpr POLY_F4(const AreaI16& area, Color24 color) : POLY_F4({
|
||||
area.position,
|
||||
area.position.move(area.size.width, 0),
|
||||
area.position.move(0, area.size.height),
|
||||
area.position.move(area.size.width, area.size.height)},
|
||||
color) {}
|
||||
};
|
||||
|
||||
struct POLY_FT4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_FT4> {
|
||||
typedef POLY_FT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Vertex vertex1; // d
|
||||
PagePosition page1; // e
|
||||
TPage tpage; // e
|
||||
Vertex vertex2; // f
|
||||
PagePosition page2; // g
|
||||
uint16_t pad2; // g
|
||||
Vertex vertex3; // h
|
||||
PagePosition page3; // i
|
||||
uint16_t pad3; // i
|
||||
|
||||
constexpr POLY_FT4() = default;
|
||||
constexpr POLY_FT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], TPage tpage, PageClut clut, Color24 color) : POLY_FT4({
|
||||
{verticies[0], page_pos[0]},
|
||||
{verticies[1], page_pos[1]},
|
||||
{verticies[2], page_pos[2]},
|
||||
{verticies[3], page_pos[3]}}, tpage, clut, color) {}
|
||||
constexpr POLY_FT4(const VertexEx (&vertices_ex)[4], TPage tpage, PageClut clut, Color24 color = Color24::Grey()) :
|
||||
color(color), code(IdentityCode),
|
||||
vertex0(vertices_ex[0].position), page0(vertices_ex[0].page), page_clut(clut),
|
||||
vertex1(vertices_ex[1].position), page1(vertices_ex[1].page), tpage(tpage),
|
||||
vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), pad2(0),
|
||||
vertex3(vertices_ex[3].position), page3(vertices_ex[3].page), pad3(0) {}
|
||||
constexpr POLY_FT4(const AreaI16& area, const PagePosition& texture_pos, TPage tpage, PageClut clut, Color24 color) : POLY_FT4({
|
||||
{area.position, texture_pos},
|
||||
{area.position.move(area.size.width, 0), texture_pos.move(area.size.width, 0)},
|
||||
{area.position.move(0, area.size.height), texture_pos.move(0, area.size.height)},
|
||||
{area.position.move(area.size.width, area.size.height), texture_pos.move(area.size.width, area.size.height)}},
|
||||
tpage, clut, color
|
||||
) {}
|
||||
};
|
||||
|
||||
struct POLY_G4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_G4> {
|
||||
typedef POLY_G3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
Color24 color1; // c
|
||||
uint8_t pad1; // c
|
||||
Vertex vertex1; // d
|
||||
Color24 color2; // e
|
||||
uint8_t pad2; // e
|
||||
Vertex vertex2; // f
|
||||
Color24 color3; // g
|
||||
uint8_t pad3; // g
|
||||
Vertex vertex3; // h
|
||||
|
||||
constexpr POLY_G4() = default;
|
||||
constexpr POLY_G4(const Vertex (&verticies)[4], const Color24 (&color)[4]) : POLY_G4({
|
||||
{verticies[0], color[0]},
|
||||
{verticies[1], color[1]},
|
||||
{verticies[2], color[2]},
|
||||
{verticies[3], color[3]}
|
||||
}) {}
|
||||
constexpr POLY_G4(const VertexEx (&verticies_ex)[4]) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position),
|
||||
color3(verticies_ex[3].color), pad3(0), vertex3(verticies_ex[3].position) {}
|
||||
constexpr POLY_G4(const AreaI16& area, const Color24 (&color)[4]) : POLY_G4({
|
||||
{area.position, color[0]},
|
||||
{area.position.move(area.size.width, 0), color[1]},
|
||||
{area.position.move(0, area.size.height), color[2]},
|
||||
{area.position.move(area.size.width, area.size.height), color[3]}}
|
||||
) {}
|
||||
};
|
||||
|
||||
struct POLY_GT4 : public internal::IsPrimitive, public internal::CodeInterface<POLY_GT4> {
|
||||
typedef POLY_GT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color0; // a
|
||||
Code code = IdentityCode; // a
|
||||
Vertex vertex0; // b
|
||||
PagePosition page0; // c
|
||||
PageClut page_clut; // c
|
||||
Color24 color1; // d
|
||||
uint8_t pad1; // d
|
||||
Vertex vertex1; // e
|
||||
PagePosition page1; // f
|
||||
TPage tpage; // f
|
||||
Color24 color2; // g
|
||||
uint8_t pad2; // g
|
||||
Vertex vertex2; // h
|
||||
PagePosition page2; // i
|
||||
uint16_t pad3; // i
|
||||
Color24 color3; // j
|
||||
uint8_t pad4; // j
|
||||
Vertex vertex3; // k
|
||||
PagePosition page3; // l
|
||||
uint16_t pad5; // l
|
||||
|
||||
constexpr POLY_GT4() = default;
|
||||
constexpr POLY_GT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], const Color24 (&color)[4], TPage tpage, PageClut clut) : POLY_GT4({
|
||||
{verticies[0], page_pos[0], color[0]},
|
||||
{verticies[1], page_pos[1], color[1]},
|
||||
{verticies[2], page_pos[2], color[2]},
|
||||
{verticies[3], page_pos[3], color[3]},
|
||||
}, tpage, clut) {}
|
||||
constexpr POLY_GT4(const VertexEx (&verticies_ex)[4], TPage tpage, PageClut clut) :
|
||||
color0(verticies_ex[0].color), code(IdentityCode), vertex0(verticies_ex[0].position), page0(verticies_ex[0].page), page_clut(clut),
|
||||
color1(verticies_ex[1].color), pad1(0), vertex1(verticies_ex[1].position), page1(verticies_ex[1].page), tpage(tpage),
|
||||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position), page2(verticies_ex[2].page), pad3(0),
|
||||
color3(verticies_ex[3].color), pad4(0), vertex3(verticies_ex[3].position), page3(verticies_ex[3].page), pad5(0) {}
|
||||
constexpr POLY_GT4(const AreaI16& area, const PagePosition& texture_pos, TPage tpage, PageClut clut, const Color24 (&color)[4]) : POLY_GT4({
|
||||
{area.position, texture_pos, color[0]},
|
||||
{area.position.move(area.size.width, 0), texture_pos.move(area.size.width, 0), color[1]},
|
||||
{area.position.move(0, area.size.height), texture_pos.move(0, area.size.height), color[2]},
|
||||
{area.position.move(area.size.width, area.size.height), texture_pos.move(area.size.width, area.size.height), color[3]}
|
||||
}, tpage, clut) {}
|
||||
};
|
||||
|
||||
typedef POLY_F3 FlatTriangle;
|
||||
typedef POLY_FT3 FlatTexturedTriangle;
|
||||
typedef POLY_G3 GouraudTriangle;
|
||||
typedef POLY_GT3 GouraudTexturedTriangle;
|
||||
|
||||
typedef POLY_F4 FlatRectangle;
|
||||
typedef POLY_FT4 FlatTexturedRectangle;
|
||||
typedef POLY_G4 GouraudRectangle;
|
||||
typedef POLY_GT4 GouraudTexturedRectangle;
|
||||
|
||||
static_assert(sizeof(POLY_F3) == 16);
|
||||
static_assert(sizeof(POLY_FT3) == 28);
|
||||
static_assert(sizeof(POLY_G3) == 24);
|
||||
static_assert(sizeof(POLY_GT3) == 36);
|
||||
|
||||
static_assert(sizeof(POLY_F4) == 20);
|
||||
static_assert(sizeof(POLY_FT4) == 36);
|
||||
static_assert(sizeof(POLY_G4) == 32);
|
||||
static_assert(sizeof(POLY_GT4) == 48);
|
||||
}
|
||||
}
|
||||
|
||||
#include "Primitives/primitive_poly_types.hpp"
|
||||
#endif // !__JABYENGINE_GPU_PRIMITIVES_HPP__
|
Loading…
Reference in New Issue