Draw first triangle

This commit is contained in:
Jaby
2023-05-07 00:07:20 +02:00
parent 5ccbd2ebd1
commit 09b16dae16
12 changed files with 190 additions and 32 deletions

View File

@@ -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__

View 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__

View File

@@ -1,5 +1,6 @@
#ifndef __JABYENGINE_GPU_TYPES_HPP__
#define __JABYENGINE_GPU_TYPES_HPP__
#include "../Auxiliary/bits.hpp"
#include "../jabyengine_defines.h"
namespace JabyEngine {