Initial Commit
This commit is contained in:
12
include/amethyst.hpp
Executable file
12
include/amethyst.hpp
Executable file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <amethyst/assets.hpp>
|
||||
#include <amethyst/c3d.hpp>
|
||||
#include <amethyst/ctru.hpp>
|
||||
#include <amethyst/image.hpp>
|
||||
#include <amethyst/renderer.hpp>
|
||||
#include <amethyst/texture.hpp>
|
||||
|
||||
namespace amy {
|
||||
void registerCxxExceptionHandler();
|
||||
}
|
||||
15
include/amethyst/app.hpp
Normal file
15
include/amethyst/app.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <amethyst/asset.hpp>
|
||||
|
||||
namespace amy {
|
||||
class app {
|
||||
public:
|
||||
app() {}
|
||||
~app() {}
|
||||
|
||||
void run();
|
||||
private:
|
||||
|
||||
};
|
||||
} // namespace amy
|
||||
9
include/amethyst/asset.hpp
Executable file
9
include/amethyst/asset.hpp
Executable file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace amy {
|
||||
class asset {
|
||||
public:
|
||||
asset() = default;
|
||||
virtual ~asset() = default;
|
||||
};
|
||||
} // namespace amy
|
||||
34
include/amethyst/assets.hpp
Executable file
34
include/amethyst/assets.hpp
Executable file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <amethyst/texture.hpp>
|
||||
#include <amethyst/types.hpp>
|
||||
|
||||
namespace amy {
|
||||
class assets {
|
||||
public:
|
||||
assets() = default;
|
||||
~assets() = default;
|
||||
|
||||
void add(cstr& id, asset* v) { m_assets[id] = v; }
|
||||
void remove(cstr& id) {
|
||||
if (m_assets.count(id)) {
|
||||
m_assets.erase(id);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
T* get(cstr& id) {
|
||||
auto r = m_assets.find(id);
|
||||
if (r == m_assets.end()) {
|
||||
throw std::runtime_error("[amy] assets: unable to find " + id);
|
||||
}
|
||||
if (auto v = dynamic_cast<T*>(r->second)) {
|
||||
return v;
|
||||
} else {
|
||||
throw std::runtime_error(id + " is not of type " + typeid(T).name());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<str, asset*> m_assets;
|
||||
};
|
||||
} // namespace amy
|
||||
76
include/amethyst/c3d.hpp
Executable file
76
include/amethyst/c3d.hpp
Executable file
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <amethyst/asset.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace amy {
|
||||
class c3d {
|
||||
public:
|
||||
c3d() = default;
|
||||
~c3d() = default;
|
||||
|
||||
class screen {
|
||||
public:
|
||||
screen(C3D_RenderTarget* t) {
|
||||
m_target = t;
|
||||
// Width and height are swapped on 3ds due to screen layout
|
||||
m_width = m_target->frameBuf.height;
|
||||
m_height = m_target->frameBuf.width;
|
||||
}
|
||||
~screen() { C3D_RenderTargetDelete(m_target); }
|
||||
|
||||
int width() const { return m_width; }
|
||||
int height() const { return m_height; }
|
||||
void clear() { C3D_RenderTargetClear(m_target, C3D_CLEAR_ALL, 0, 0); }
|
||||
void startDraw() { C3D_FrameDrawOn(m_target); }
|
||||
|
||||
private:
|
||||
C3D_RenderTarget* m_target = nullptr;
|
||||
int m_width = 0;
|
||||
int m_height = 0;
|
||||
};
|
||||
|
||||
class shader : public asset {
|
||||
public:
|
||||
shader(const std::string& path);
|
||||
~shader();
|
||||
|
||||
void load(const std::string& path);
|
||||
void use();
|
||||
void input(int reg, GPU_FORMATS f, int num);
|
||||
void input(GPU_FORMATS f, int num) { input(m_reg++, f, num); }
|
||||
void setMat4(int loc, C3D_Mtx* m);
|
||||
|
||||
private:
|
||||
C3D_AttrInfo m_info;
|
||||
shaderProgram_s m_program;
|
||||
DVLB_s* m_code;
|
||||
int m_reg = 0;
|
||||
};
|
||||
|
||||
class frag {
|
||||
public:
|
||||
frag() = default;
|
||||
~frag() = default;
|
||||
|
||||
static void edit(int id = 0);
|
||||
static void src(C3D_TexEnvMode mode, GPU_TEVSRC s1 = GPU_PRIMARY_COLOR,
|
||||
GPU_TEVSRC s2 = GPU_PRIMARY_COLOR,
|
||||
GPU_TEVSRC s3 = GPU_PRIMARY_COLOR);
|
||||
static void func(C3D_TexEnvMode mode, GPU_COMBINEFUNC func);
|
||||
|
||||
private:
|
||||
static C3D_TexEnv* m_env;
|
||||
};
|
||||
|
||||
static void init();
|
||||
static void deinit();
|
||||
static void startFrame(bool sync = true);
|
||||
static void endFrame();
|
||||
static screen* createScreen(gfxScreen_t screen, gfx3dSide_t side = GFX_LEFT);
|
||||
static void deleteScreen(screen* screen);
|
||||
};
|
||||
} // namespace amy
|
||||
14
include/amethyst/ctru.hpp
Normal file
14
include/amethyst/ctru.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace amy {
|
||||
namespace ctru {
|
||||
enum services {
|
||||
romfs = 1 << 0,
|
||||
cfgu = 1 << 1,
|
||||
gfx = 1 << 2,
|
||||
gfx_def = 1 << 3,
|
||||
def = romfs | gfx_def
|
||||
};
|
||||
void init(unsigned int srv = def);
|
||||
} // namespace ctru
|
||||
} // namespace amy
|
||||
14
include/amethyst/godtrace.hpp
Normal file
14
include/amethyst/godtrace.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace amy {
|
||||
class gtrace {
|
||||
public:
|
||||
gtrace() = default;
|
||||
~gtrace() = default;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
55
include/amethyst/image.hpp
Executable file
55
include/amethyst/image.hpp
Executable file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <amethyst/types.hpp>
|
||||
|
||||
namespace amy {
|
||||
class image {
|
||||
public:
|
||||
enum format {
|
||||
RGBA, // bpp == 4
|
||||
RGB, // bpp == 3
|
||||
RGB565, // bpp == 2 (not supported in laoding)
|
||||
BGR, // bpp == 3
|
||||
ABGR, // bpp == 4
|
||||
BGRA, // bpp == 4
|
||||
};
|
||||
image() = default;
|
||||
image(cstr& path) { this->load(path); }
|
||||
image(const std::vector<uc>& buf) { this->load(buf); }
|
||||
image(const std::vector<uc>& buf, int w, int h, const format& fmt) {
|
||||
this->copy(buf, w, h, fmt);
|
||||
}
|
||||
~image() = default;
|
||||
|
||||
void load(cstr& path);
|
||||
void load(const std::vector<uc>& buf);
|
||||
void copy(const std::vector<uc>& buf, int w, int h, const format& fmt);
|
||||
|
||||
std::vector<uc>& getBuffer() { return m_buffer; }
|
||||
std::vector<uc> getBuffer() const { return m_buffer; }
|
||||
|
||||
int width() const { return m_w; }
|
||||
int height() const { return m_h; }
|
||||
int bpp() const { return getBppOfFmt(m_fmt); }
|
||||
format fmt() const { return m_fmt; }
|
||||
void convert(const format& dst) { convert(*this, dst); }
|
||||
void retile(std::function<ui(int x, int y, int w)> src,
|
||||
std::function<ui(int x, int y, int w)> dst) {
|
||||
retile(*this, src, dst);
|
||||
}
|
||||
|
||||
uc& operator[](int idx) { return m_buffer[idx]; }
|
||||
uc operator[](int idx) const { return m_buffer[idx]; }
|
||||
|
||||
static void convert(image& img, const format& dst);
|
||||
static void retile(image& img, std::function<ui(int x, int y, int w)> src,
|
||||
std::function<ui(int x, int y, int w)> dst);
|
||||
static int getBppOfFmt(const format& fmt);
|
||||
|
||||
private:
|
||||
std::vector<uc> m_buffer;
|
||||
int m_w = 0;
|
||||
int m_h = 0;
|
||||
format m_fmt = RGBA;
|
||||
};
|
||||
} // namespace amy
|
||||
9
include/amethyst/renderer.hpp
Executable file
9
include/amethyst/renderer.hpp
Executable file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace amy {
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
};
|
||||
} // namespace amys
|
||||
30
include/amethyst/texture.hpp
Executable file
30
include/amethyst/texture.hpp
Executable file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <amethyst/asset.hpp>
|
||||
#include <amethyst/image.hpp>
|
||||
|
||||
namespace amy {
|
||||
class texture : public asset {
|
||||
public:
|
||||
texture() = default;
|
||||
texture(cstr& path);
|
||||
~texture();
|
||||
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; }
|
||||
|
||||
C3D_Tex* getTex() { return m_loaded ? &m_tex : nullptr; }
|
||||
|
||||
private:
|
||||
C3D_Tex m_tex;
|
||||
int m_w = 0;
|
||||
int m_h = 0;
|
||||
bool m_loaded = false;
|
||||
};
|
||||
} // namespace amy
|
||||
19
include/amethyst/types.hpp
Normal file
19
include/amethyst/types.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace amy {
|
||||
using uc = unsigned char;
|
||||
using us = unsigned short;
|
||||
using ui = unsigned int;
|
||||
using ull = unsigned long long;
|
||||
using str = std::string;
|
||||
using cstr = const std::string;
|
||||
template <typename T> using vec = std::vector<T>;
|
||||
template <typename T>
|
||||
using cvec = const std::vector<T>;
|
||||
} // namespace amy
|
||||
18
include/amethyst/utils.hpp
Executable file
18
include/amethyst/utils.hpp
Executable file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <amethyst/types.hpp>
|
||||
|
||||
namespace amy {
|
||||
namespace utils {
|
||||
ui fastHash(cstr& s);
|
||||
vec<uc> loadFile2Mem(cstr& path);
|
||||
ui hashMemory(cvec<uc>& data);
|
||||
ui nextPow2(ui v);
|
||||
bool isSingleBitNum(ui v);
|
||||
namespace image {
|
||||
void reverseBuf(vec<uc>& buf, int w, int h, int c);
|
||||
void removeAlphaChannel(vec<uc>& buf, int w, int h);
|
||||
void addAlphaChannel(vec<uc>& buf, int w, int h);
|
||||
} // namespace image
|
||||
} // namespace utils
|
||||
} // namespace amy
|
||||
7988
include/stb_image.h
Executable file
7988
include/stb_image.h
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user