- Start work on drawlist

- Fix issue in texloader
- add ivec2 to tecloader / screen
- add draw func for iron
- add bufCfg in 3 variants to c3d
- add poc for c3d_permutation
This commit is contained in:
2025-11-24 14:25:35 +01:00
parent f0117e07d4
commit a9eed546b9
14 changed files with 212 additions and 20 deletions

View File

@@ -5,6 +5,7 @@
#include <amethyst/asset.hpp>
#include <amethyst/maths/mat.hpp>
#include <amethyst/maths/vec.hpp>
#include <amethyst/types.hpp>
#include <string>
@@ -26,6 +27,7 @@ class c3d {
int width() const { return m_width; }
int height() const { return m_height; }
ivec2 size() const { return ivec2(m_width, m_height); }
void clear() { C3D_RenderTargetClear(m_target, C3D_CLEAR_ALL, 0, 0); }
void startDraw() { C3D_FrameDrawOn(m_target); }
@@ -83,5 +85,57 @@ class c3d {
GPU_Primitive_t prim = GPU_TRIANGLES);
static void drawElements(int count, const void* idx_ptr, int type = GPU_SHORT,
GPU_Primitive_t prim = GPU_TRIANGLES);
static void depthTest(bool on, GPU_TESTFUNC func = GPU_GREATER,
GPU_WRITEMASK mask = GPU_WRITE_ALL);
static void disableScissor();
static void enableScissor(const ivec4 rect);
/**
* Buf cfg die permutation at runtime berechnet
*/
static void bufCfg(void* ptr, int stride, int shader_attribs);
/**
* Klassische config bei der man selber die permutation eintragen muss
*/
static void bufCfg(void* ptr, int stride, int shader_attribs,
u64 permutation);
/**
* Hacky funktion um die permutation automatisch at compile time zu berechnen,
* falls diese immer gleich bleibt.
* In der <> steht die anzahl der shader input werte
* usage: c3d::bufCfg<3>(data, sizeof(vertex));
*/
template <int attribs>
constexpr static void bufCfg(void* ptr, int stride) {
auto buf = C3D_GetBufInfo();
BufInfo_Init(buf);
constexpr int pm = permutation(attribs);
BufInfo_Add(buf, ptr, stride, attribs, pm);
}
static int drawcalls() { return m_drawcalls; }
private:
static int m_drawcalls;
static int m__dc__;
/**
* Funktion die anhand von **ac** genau den permu station wert für BufInfo
* ausrechnet wie z.B
* ```
* ac = 3 -> 0x210
* ac = 4 -> 0x3210
* ```
*/
constexpr static u64 permutation(int ac) {
u64 ret = 0;
if (ac < 1 || ac > 15) {
throw std::runtime_error("[amy] " + std::to_string(ac) +
" is out of range (1...15)!");
}
for (int i = 0; i < ac; i++) {
ret = (ret << 4) | (ac - 1 - i);
}
return ret;
}
};
} // namespace amy

View File

@@ -26,6 +26,7 @@ class iron {
u32 color = 0;
};
class command {
public:
command() = default;
using ref = up<command>;
command& add(const u16& idx) {
@@ -58,7 +59,7 @@ class iron {
void merge(drawlist* list);
command::ref newCommand();
void push(commad* cmd);
void push(command ::ref cmd);
void clear();
void drawSolid();
@@ -74,7 +75,7 @@ class iron {
static void init();
static void newFrame();
static void drawOn(c3d::screen* screen);
static void draw(const std::vector<command>& data);
static void draw(const std::vector<command::ref>& data);
private:
static void setupShader();

View File

@@ -4,6 +4,7 @@
#include <amethyst/asset.hpp>
#include <amethyst/image.hpp>
#include <amethyst/types.hpp>
namespace amy {
class texture : public asset {
@@ -14,17 +15,20 @@ class texture : public asset {
void load(cstr& path);
void unload();
int w() const { return m_w; }
int& w() { return m_w; }
int h() const { return m_h; }
int& h() { return m_h; }
int w() const { return m_size.x; }
int& w() { return m_size.x; }
int h() const { return m_size.y; }
int& h() { return m_size.y; }
ivec2 size() const { return m_size; }
ivec2& size() { return m_size; }
C3D_Tex* getTex() { return m_loaded ? &m_tex : nullptr; }
C3D_Tex* ptr() { return m_loaded ? &m_tex : nullptr; }
void bind(int reg = 0);
private:
C3D_Tex m_tex;
int m_w = 0;
int m_h = 0;
ivec2 m_size;
bool m_loaded = false;
};
} // namespace amy

View File

@@ -1,7 +1,10 @@
#pragma once
#include <amethyst/maths/vec.hpp>
#include <cinttypes>
#include <functional>
#include <map>
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>