Draw first triangle
This commit is contained in:
14
include/PSX/Auxiliary/type_traits.hpp
Normal file
14
include/PSX/Auxiliary/type_traits.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __JABYENGINE_TYPE_TRAITS_HPP__
|
||||
#define __JABYENGINE_TYPE_TRAITS_HPP__
|
||||
|
||||
namespace JabyEngine {
|
||||
template<bool B, class T = void>
|
||||
struct enable_if {};
|
||||
|
||||
template<class T>
|
||||
struct enable_if<true, T> {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //! __JABYENGINE_TYPE_TRAITS_HPP__
|
@@ -16,9 +16,7 @@ namespace JabyEngine {
|
||||
|
||||
uint32_t raw;
|
||||
|
||||
constexpr SimpleTIM() {
|
||||
this->raw = 0;
|
||||
}
|
||||
constexpr SimpleTIM() : raw(0) {}
|
||||
|
||||
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : raw(TextureX.as_value(texX >> 1) | TextureY.as_value(texY >> 1) | ClutX.as_value(clutX >> 4) | ClutY.as_value(static_cast<uint32_t>(clutY))) {
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#ifndef __JABYENGINE_GPU_HPP__
|
||||
#define __JABYENGINE_GPU_HPP__
|
||||
#include "../Auxiliary/type_traits.hpp"
|
||||
#include "../System/IOPorts/gpu_io.hpp"
|
||||
#include "gpu_primitives.hpp"
|
||||
|
||||
#if !defined(JABYENGINE_NTSC) && !defined(JABYENGINE_PAL)
|
||||
#error "JABYENGINE_NTSC or JABYENGINE_PAL must be defined"
|
||||
@@ -34,7 +36,16 @@ namespace JabyEngine {
|
||||
static void set_offset(uint16_t x, uint16_t y);
|
||||
};
|
||||
|
||||
uint8_t swap_buffers_vsync(uint8_t syncs);
|
||||
namespace internal {
|
||||
void render(const uint32_t* data, size_t words);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static enable_if<T::is_primitive>::type render(const T& primitive) {
|
||||
internal::render(reinterpret_cast<const uint32_t*>(&primitive), sizeof(T)/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true);
|
||||
}
|
||||
}
|
||||
#endif //!__JABYENGINE_GPU_HPP__
|
90
include/PSX/GPU/gpu_primitives.hpp
Normal file
90
include/PSX/GPU/gpu_primitives.hpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef __JABYENGINE_GPU_PRIMITIVES_HPP__
|
||||
#define __JABYENGINE_GPU_PRIMITIVES_HPP__
|
||||
#include "gpu_types.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 QuardVertics = Bit(27 - BitCorrection);
|
||||
static constexpr auto TriVertics = !QuardVertics;
|
||||
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& 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;
|
||||
}
|
||||
};
|
||||
|
||||
struct IsPrimitive {
|
||||
static constexpr bool is_primitive = true;
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
// Concept for now
|
||||
template<typename T>
|
||||
struct Hooked {
|
||||
uint32_t hook;
|
||||
T primitive;
|
||||
};
|
||||
}
|
||||
|
||||
struct POLY_F3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F3> {
|
||||
static constexpr auto IdentityCode = internal::Code().set(internal::Code::FlatShading).set(internal::Code::TriVertics).set(internal::Code::Untextured).set(internal::Code::NonTransparent).set(internal::Code::NoBlendTexture);
|
||||
|
||||
Color24 color;
|
||||
internal::Code code = IdentityCode;
|
||||
PositionI16 vertex[3];
|
||||
|
||||
constexpr POLY_F3() = default;
|
||||
constexpr POLY_F3(Color24 color, const PositionI16 (&verticies)[3]) : color(color), code(IdentityCode), vertex{verticies[0], verticies[1], verticies[2]} {
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(POLY_F3) == 16);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !__JABYENGINE_GPU_PRIMITIVES_HPP__
|
@@ -1,5 +1,6 @@
|
||||
#ifndef __JABYENGINE_GPU_TYPES_HPP__
|
||||
#define __JABYENGINE_GPU_TYPES_HPP__
|
||||
#include "../Auxiliary/bits.hpp"
|
||||
#include "../jabyengine_defines.h"
|
||||
|
||||
namespace JabyEngine {
|
||||
|
@@ -89,16 +89,16 @@ namespace JabyEngine {
|
||||
|
||||
struct Command {
|
||||
struct Helper {
|
||||
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
|
||||
return ((cmd << 24) | value);
|
||||
}
|
||||
|
||||
static constexpr GP0_t DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
|
||||
constexpr auto Command = BitRange::from_to(24, 31);
|
||||
constexpr auto Y = BitRange::from_to(10, 18);
|
||||
constexpr auto X = BitRange::from_to(0, 9);
|
||||
|
||||
return GP0_t::from(Command.with(code), Y.with(y), X.with(x));
|
||||
}
|
||||
|
||||
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
|
||||
return ((cmd << 24) | value);
|
||||
return {construct_cmd(code, Y.as_value(static_cast<uint32_t>(y)) | X.as_value(static_cast<uint32_t>(x)))};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -122,12 +122,19 @@ namespace JabyEngine {
|
||||
return Helper::DrawAreaTemplate(0xE4, x, y);
|
||||
}
|
||||
|
||||
static GP0_t SetDrawOffset(int16_t x, int16_t y) {
|
||||
constexpr auto X = BitRange::from_to(0, 10);
|
||||
constexpr auto Y = BitRange::from_to(11, 21);
|
||||
|
||||
return {Helper::construct_cmd(0xE5, X.as_value(static_cast<int32_t>(x)) | Y.as_value(static_cast<int32_t>(y)))};
|
||||
}
|
||||
|
||||
static constexpr GP0_t TopLeftPosition(uint16_t x, uint16_t y) {
|
||||
return {static_cast<uint32_t>((y << 16u) | x)};
|
||||
return {(static_cast<uint32_t>(y) << 16u) | x};
|
||||
}
|
||||
|
||||
static constexpr GP0_t WidthHeight(uint16_t w, uint16_t h) {
|
||||
return {static_cast<uint32_t>((h << 16u) | w)};
|
||||
return {(static_cast<uint32_t>(h) << 16u) | w};
|
||||
}
|
||||
|
||||
static constexpr GP1_t Reset() {
|
||||
@@ -146,25 +153,25 @@ namespace JabyEngine {
|
||||
return {Helper::construct_cmd(0x04, static_cast<uint32_t>(dir))};
|
||||
}
|
||||
|
||||
static constexpr GP1_t DisplayArea(uint32_t x, uint32_t y) {
|
||||
static constexpr GP1_t DisplayArea(uint16_t x, uint16_t y) {
|
||||
constexpr auto X = BitRange::from_to(0, 9);
|
||||
constexpr auto Y = BitRange::from_to(10, 18);
|
||||
|
||||
return {Helper::construct_cmd(0x05, X.as_value(x) | Y.as_value(y))};
|
||||
return {Helper::construct_cmd(0x05, X.as_value(static_cast<uint32_t>(x)) | Y.as_value(static_cast<uint32_t>(y)))};
|
||||
}
|
||||
|
||||
static constexpr GP1_t HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
|
||||
static constexpr GP1_t HorizontalDisplayRange(uint16_t x1, uint16_t x2) {
|
||||
constexpr auto X1 = BitRange::from_to(0, 11);
|
||||
constexpr auto X2 = BitRange::from_to(12, 23);
|
||||
|
||||
return {Helper::construct_cmd(0x06, X1.as_value(x1) | X2.as_value(x2))};
|
||||
return {Helper::construct_cmd(0x06, X1.as_value(static_cast<uint32_t>(x1)) | X2.as_value(static_cast<uint32_t>(x2)))};
|
||||
}
|
||||
|
||||
static constexpr GP1_t VerticalDisplayRange(uint32_t y1, uint32_t y2) {
|
||||
static constexpr GP1_t VerticalDisplayRange(uint16_t y1, uint16_t y2) {
|
||||
constexpr auto Y1 = BitRange::from_to(0, 9);
|
||||
constexpr auto Y2 = BitRange::from_to(10, 19);
|
||||
|
||||
return {Helper::construct_cmd(0x07, Y1.as_value(y1) | Y2.as_value(y2))};
|
||||
return {Helper::construct_cmd(0x07, Y1.as_value(static_cast<uint32_t>(y1)) | Y2.as_value(static_cast<uint32_t>(y2)))};
|
||||
}
|
||||
|
||||
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
|
||||
|
Reference in New Issue
Block a user