Upload all my tests
- Add Count<> to AssetManager - Initialize pCode in Shader - Rename linearAllocator to LinearAllocator - Add Construct and destroy to linear allocator - Add Shader unloader (fixes atexit crash i guess) -
This commit is contained in:
BIN
.clang-format
Normal file
BIN
.clang-format
Normal file
Binary file not shown.
@@ -28,7 +28,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||
# target_link_libraries(${PROJECT_NAME} PUBLIC pica::pica)
|
||||
if(${AMY_BUILD_3DS})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC m z ctru citro3d)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC AMY_3DS )
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC AMY_3DS)
|
||||
endif()
|
||||
|
||||
add_subdirectory(example)
|
||||
|
||||
BIN
example/romfs/white.png
Normal file
BIN
example/romfs/white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 B |
@@ -16,8 +16,7 @@
|
||||
.alias in_uvc v1
|
||||
.alias in_col v2
|
||||
|
||||
.entry vmain
|
||||
.proc vmain
|
||||
.proc main
|
||||
mov r0.xy, in_xy.xy
|
||||
mov r0.w, ones
|
||||
|
||||
|
||||
@@ -1,118 +1,26 @@
|
||||
#include <amethyst.hpp>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "amethyst/iron.hpp"
|
||||
|
||||
struct memory_metrics {
|
||||
uint64_t t_TotalAllocated = 0; ///< Total Allocated Memory
|
||||
uint64_t t_TotalFreed = 0; ///< Total Deleted Memory
|
||||
/// @brief Gets the Currently Allocated Memory
|
||||
uint32_t t_CurrentlyAllocated() { return t_TotalAllocated - t_TotalFreed; }
|
||||
};
|
||||
|
||||
static memory_metrics metrics;
|
||||
|
||||
bool rd7i_enable_memtrack = true;
|
||||
|
||||
void* operator new(size_t size) {
|
||||
void* ptr = malloc(size);
|
||||
if (rd7i_enable_memtrack) metrics.t_TotalAllocated += size;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void operator delete(void* memory, size_t size) {
|
||||
if (rd7i_enable_memtrack) metrics.t_TotalFreed += size;
|
||||
free(memory);
|
||||
}
|
||||
|
||||
size_t GetTotalAllocated() { return metrics.t_TotalAllocated; }
|
||||
|
||||
size_t GetTotalFreed() { return metrics.t_TotalFreed; }
|
||||
|
||||
size_t GetCurrent() { return metrics.t_CurrentlyAllocated(); }
|
||||
|
||||
std::string FormatBytes(unsigned long long bytes) {
|
||||
static const std::vector<std::string> endings = {
|
||||
"B", "KB", "MB", "GB", "TB", "Unk",
|
||||
};
|
||||
int i = 0;
|
||||
double b = bytes;
|
||||
while (b > 1024) {
|
||||
i++;
|
||||
b /= 1024;
|
||||
}
|
||||
if (i >= (int)endings.size()) {
|
||||
i = (int)endings.size() - 1;
|
||||
}
|
||||
return std::format("{:.1f} {}", b, endings[i]);
|
||||
}
|
||||
|
||||
class example : public Amy::App {
|
||||
public:
|
||||
example() {
|
||||
class Example : public Amy::App {
|
||||
public:
|
||||
Example() {
|
||||
Amy::Ctr::Init();
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
Amy::C3D::Init();
|
||||
m_top = Amy::C3D::CreateScreen(GFX_TOP);
|
||||
Amy::Iron::Init();
|
||||
dl = new Amy::Iron::Drawlist();
|
||||
dl->DrawSolid();
|
||||
mgr.AutoLoad("shader", "romfs:/shaders/shader2d.shbin");
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 3);
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 3);
|
||||
mgr.AutoLoad("icon", "romfs:/icon.png");
|
||||
};
|
||||
~example() {
|
||||
Amy::C3D::DeleteScreen(m_top);
|
||||
Amy::C3D::Deinit();
|
||||
};
|
||||
|
||||
void Main() override {
|
||||
std::cout << std::format("\x1b[1;1HDelta: {:.3f} -> {:.3} FPS\x1b[K", this->Delta(), 1000.0/this->Delta());
|
||||
std::cout << std::format("\x1b[2;1HTime: {:.3f}\x1b[K", this->Time());
|
||||
std::cout << std::format(
|
||||
"\x1b[3;1HMem: {}\n +{}\n -{}\nLin: {}\x1b[K",
|
||||
FormatBytes(GetCurrent()), FormatBytes(GetTotalAllocated()),
|
||||
FormatBytes(GetTotalFreed()), FormatBytes(linearSpaceFree()));
|
||||
Top = Amy::C3D::CreateScreen(GFX_TOP);
|
||||
}
|
||||
~Example() { delete Top; }
|
||||
|
||||
void Main() {
|
||||
Amy::C3D::StartFrame();
|
||||
m_top->Use();
|
||||
m_top->Clear();
|
||||
dl->DrawTex(mgr.Get<Amy::Texture>("icon"));
|
||||
dl->DrawRectFilled(100, 48, 0xffffffff);
|
||||
dl->DrawSolid();
|
||||
dl->DrawRectFilled(0, 50, 0xffffffff);
|
||||
Amy::Iron::NewFrame();
|
||||
Amy::Iron::DrawOn(m_top);
|
||||
Amy::Iron::Draw(*dl);
|
||||
dl->Clear();
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->Use();
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->SetMat4(0, mtx);
|
||||
C3D_ImmDrawBegin(GPU_TRIANGLES);
|
||||
C3D_ImmSendAttrib(200, 50, 0, 0);
|
||||
C3D_ImmSendAttrib(1, 0, 0, 1);
|
||||
C3D_ImmSendAttrib(300, 190, 0, 0);
|
||||
C3D_ImmSendAttrib(0, 1, 0, 1);
|
||||
C3D_ImmSendAttrib(100, 190, 0, 0);
|
||||
C3D_ImmSendAttrib(0, 0, 1, 1);
|
||||
C3D_ImmDrawEnd();
|
||||
Top->Clear();
|
||||
Top->Use();
|
||||
Amy::C3D::EndFrame();
|
||||
}
|
||||
|
||||
private:
|
||||
Amy::C3D::Screen* m_top = nullptr;
|
||||
Amy::Iron::Drawlist* dl = nullptr;
|
||||
Amy::C3D::Shader* test = nullptr;
|
||||
Amy::AssetMgr mgr;
|
||||
Amy::mat4 mtx =
|
||||
Amy::mat4::identity() * Amy::mat4::ortho(0, 400, 240, 0, 0, 1);
|
||||
Amy::C3D::Screen *Top;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Amy::RegisterCxxExceptionHandler();
|
||||
example app;
|
||||
app.Run();
|
||||
Example App;
|
||||
App.Run();
|
||||
return 0;
|
||||
}
|
||||
118
example/source/main.cpp.2
Normal file
118
example/source/main.cpp.2
Normal file
@@ -0,0 +1,118 @@
|
||||
#include <amethyst.hpp>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "amethyst/iron.hpp"
|
||||
|
||||
struct memory_metrics {
|
||||
uint64_t t_TotalAllocated = 0; ///< Total Allocated Memory
|
||||
uint64_t t_TotalFreed = 0; ///< Total Deleted Memory
|
||||
/// @brief Gets the Currently Allocated Memory
|
||||
uint32_t t_CurrentlyAllocated() { return t_TotalAllocated - t_TotalFreed; }
|
||||
};
|
||||
|
||||
static memory_metrics metrics;
|
||||
|
||||
bool rd7i_enable_memtrack = true;
|
||||
|
||||
void* operator new(size_t size) {
|
||||
void* ptr = malloc(size);
|
||||
if (rd7i_enable_memtrack) metrics.t_TotalAllocated += size;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void operator delete(void* memory, size_t size) {
|
||||
if (rd7i_enable_memtrack) metrics.t_TotalFreed += size;
|
||||
free(memory);
|
||||
}
|
||||
|
||||
size_t GetTotalAllocated() { return metrics.t_TotalAllocated; }
|
||||
|
||||
size_t GetTotalFreed() { return metrics.t_TotalFreed; }
|
||||
|
||||
size_t GetCurrent() { return metrics.t_CurrentlyAllocated(); }
|
||||
|
||||
std::string FormatBytes(unsigned long long bytes) {
|
||||
static const std::vector<std::string> endings = {
|
||||
"B", "KB", "MB", "GB", "TB", "Unk",
|
||||
};
|
||||
int i = 0;
|
||||
double b = bytes;
|
||||
while (b > 1024) {
|
||||
i++;
|
||||
b /= 1024;
|
||||
}
|
||||
if (i >= (int)endings.size()) {
|
||||
i = (int)endings.size() - 1;
|
||||
}
|
||||
return std::format("{:.1f} {}", b, endings[i]);
|
||||
}
|
||||
|
||||
class example : public Amy::App {
|
||||
public:
|
||||
example() {
|
||||
Amy::Ctr::Init();
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
Amy::C3D::Init();
|
||||
m_top = Amy::C3D::CreateScreen(GFX_TOP);
|
||||
Amy::Iron::Init();
|
||||
dl = new Amy::Iron::Drawlist();
|
||||
dl->DrawSolid();
|
||||
mgr.AutoLoad("shader", "romfs:/shaders/shader2d.shbin");
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 3);
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 3);
|
||||
mgr.AutoLoad("icon", "romfs:/icon.png");
|
||||
};
|
||||
~example() {
|
||||
Amy::C3D::DeleteScreen(m_top);
|
||||
Amy::C3D::Deinit();
|
||||
};
|
||||
|
||||
void Main() override {
|
||||
std::cout << std::format("\x1b[1;1HDelta: {:.3f} -> {:.3} FPS\x1b[K", this->Delta(), 1000.0/this->Delta());
|
||||
std::cout << std::format("\x1b[2;1HTime: {:.3f}\x1b[K", this->Time());
|
||||
std::cout << std::format(
|
||||
"\x1b[3;1HMem: {}\n +{}\n -{}\nLin: {}\x1b[K",
|
||||
FormatBytes(GetCurrent()), FormatBytes(GetTotalAllocated()),
|
||||
FormatBytes(GetTotalFreed()), FormatBytes(linearSpaceFree()));
|
||||
|
||||
Amy::C3D::StartFrame();
|
||||
m_top->Use();
|
||||
m_top->Clear();
|
||||
dl->DrawTex(mgr.Get<Amy::Texture>("icon"));
|
||||
dl->DrawRectFilled(100, 48, 0xffffffff);
|
||||
dl->DrawSolid();
|
||||
dl->DrawRectFilled(0, 50, 0xffffffff);
|
||||
Amy::Iron::NewFrame();
|
||||
Amy::Iron::DrawOn(m_top);
|
||||
Amy::Iron::Draw(*dl);
|
||||
dl->Clear();
|
||||
/*mgr.Get<Amy::C3D::Shader>("shader")->Use();
|
||||
mgr.Get<Amy::C3D::Shader>("shader")->SetMat4(0, mtx);
|
||||
C3D_ImmDrawBegin(GPU_TRIANGLES);
|
||||
C3D_ImmSendAttrib(200, 50, 0, 0);
|
||||
C3D_ImmSendAttrib(1, 0, 0, 1);
|
||||
C3D_ImmSendAttrib(300, 190, 0, 0);
|
||||
C3D_ImmSendAttrib(0, 1, 0, 1);
|
||||
C3D_ImmSendAttrib(100, 190, 0, 0);
|
||||
C3D_ImmSendAttrib(0, 0, 1, 1);
|
||||
C3D_ImmDrawEnd();*/
|
||||
Amy::C3D::EndFrame();
|
||||
}
|
||||
|
||||
private:
|
||||
Amy::C3D::Screen* m_top = nullptr;
|
||||
Amy::Iron::Drawlist* dl = nullptr;
|
||||
Amy::C3D::Shader* test = nullptr;
|
||||
Amy::AssetMgr mgr;
|
||||
Amy::mat4 mtx =
|
||||
Amy::mat4::identity() * Amy::mat4::ortho(0, 400, 240, 0, 0, 1);
|
||||
};
|
||||
|
||||
int main() {
|
||||
Amy::RegisterCxxExceptionHandler();
|
||||
example app;
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
91
example/source/main.cpp.3
Normal file
91
example/source/main.cpp.3
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <amethyst.hpp>
|
||||
|
||||
struct vertex {
|
||||
vertex(Amy::fvec2 p, Amy::fvec2 tc, Amy::ui c) {
|
||||
pos = pos;
|
||||
uv = tc;
|
||||
color = c;
|
||||
}
|
||||
vertex() = default;
|
||||
Amy::fvec2 pos;
|
||||
Amy::fvec2 uv;
|
||||
Amy::ui color;
|
||||
};
|
||||
|
||||
std::vector<vertex, Amy::LinearAllocator<vertex>> vbuf;
|
||||
static int uLoc_projection = 0;
|
||||
static Amy::C3D::Shader* Shader = nullptr;
|
||||
static Amy::AssetMgr Assets;
|
||||
|
||||
static void sceneInit(void) {
|
||||
Shader = new Amy::C3D::Shader("romfs:/shaders/li2.shbin");
|
||||
uLoc_projection = Shader->loc("projection");
|
||||
Shader->Input(GPU_FLOAT, 2);
|
||||
Shader->Input(GPU_FLOAT, 2);
|
||||
Shader->Input(GPU_UNSIGNED_BYTE, 4);
|
||||
|
||||
vbuf.resize(6);
|
||||
|
||||
vbuf[0] = vertex(Amy::fvec2(300, 40), Amy::fvec2(1, 1), 0xffffffff);
|
||||
vbuf[1] = vertex(Amy::fvec2(100, 40), Amy::fvec2(0, 1), 0xffffffff);
|
||||
vbuf[2] = vertex(Amy::fvec2(100, 200), Amy::fvec2(0, 0), 0xffffffff);
|
||||
vbuf[3] = vertex(Amy::fvec2(100, 200), Amy::fvec2(0, 0), 0xffffffff);
|
||||
vbuf[4] = vertex(Amy::fvec2(300, 200), Amy::fvec2(1, 0), 0xffffffff);
|
||||
vbuf[5] = vertex(Amy::fvec2(300, 40), Amy::fvec2(1, 1), 0xffffffff);
|
||||
|
||||
Amy::C3D::BufCfg<3>(vbuf.data(), sizeof(vertex));
|
||||
|
||||
Amy::C3D::Frag::Edit();
|
||||
Amy::C3D::Frag::Src(C3D_Both, GPU_TEXTURE0);
|
||||
Amy::C3D::Frag::Func(C3D_Both, GPU_MODULATE);
|
||||
|
||||
Assets.AutoLoad("white", "romfs:/white.png");
|
||||
}
|
||||
|
||||
static void sceneRender(void) {
|
||||
Amy::C3D::DepthTest(false);
|
||||
Shader->Use();
|
||||
Shader->SetMat4(uLoc_projection, Amy::mat4::ortho(0, 400, 240, 0, 1, -1));
|
||||
Assets.Get<Amy::Texture>("white")->Bind();
|
||||
Amy::C3D::DrawArrays(0, vbuf.size());
|
||||
Amy::C3D::DepthTest(true);
|
||||
}
|
||||
|
||||
static void sceneExit(void) {
|
||||
vbuf.clear();
|
||||
delete Shader;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Amy::RegisterCxxExceptionHandler();
|
||||
Amy::Ctr::Init();
|
||||
Amy::C3D::Init();
|
||||
auto Top = Amy::C3D::CreateScreen(GFX_TOP);
|
||||
|
||||
sceneInit();
|
||||
|
||||
while (aptMainLoop()) {
|
||||
hidScanInput();
|
||||
|
||||
u32 kDown = hidKeysDown();
|
||||
if (kDown & KEY_START) break;
|
||||
|
||||
Amy::C3D::StartFrame();
|
||||
Top->Clear();
|
||||
Top->Use();
|
||||
sceneRender();
|
||||
Amy::C3D::EndFrame();
|
||||
}
|
||||
|
||||
// Deinitialize the scene
|
||||
sceneExit();
|
||||
|
||||
Amy::C3D::Deinit();
|
||||
gfxExit();
|
||||
romfsExit();
|
||||
return 0;
|
||||
}
|
||||
89
example/source/main.cpp44
Normal file
89
example/source/main.cpp44
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <amethyst.hpp>
|
||||
|
||||
typedef struct {
|
||||
float pos[3];
|
||||
float color[4];
|
||||
} Vertex;
|
||||
|
||||
static const Vertex vertex_list[] = {
|
||||
{{200.0f, 200.0f, 0.5f}, {1.0f, 0.0f, 0.0f, 1.0f}},
|
||||
{{100.0f, 40.0f, 0.5f}, {0.0f, 1.0f, 0.0f, 1.0f}},
|
||||
{{300.0f, 40.0f, 0.5f}, {0.0f, 0.0f, 1.0f, 1.0f}},
|
||||
};
|
||||
|
||||
#define vertex_list_count (sizeof(vertex_list) / sizeof(vertex_list[0]))
|
||||
|
||||
static int uLoc_projection;
|
||||
|
||||
Amy::AssetMgr* Assets = nullptr;
|
||||
|
||||
static void* vbo_data;
|
||||
|
||||
extern "C" {
|
||||
static void sceneInit(void) {
|
||||
Assets->AutoLoad("shader", "romfs:/shaders/shader2d.shbin");
|
||||
Assets->Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 3);
|
||||
Assets->Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 4);
|
||||
uLoc_projection = Assets->Get<Amy::C3D::Shader>("shader")->loc("projecttion");
|
||||
|
||||
vbo_data = linearAlloc(sizeof(vertex_list));
|
||||
memcpy(vbo_data, vertex_list, sizeof(vertex_list));
|
||||
|
||||
// Configure buffers
|
||||
C3D_BufInfo* bufInfo = C3D_GetBufInfo();
|
||||
BufInfo_Init(bufInfo);
|
||||
BufInfo_Add(bufInfo, vbo_data, sizeof(Vertex), 2, 0x10);
|
||||
|
||||
// Configure the first fragment shading substage to just pass through the
|
||||
// vertex color See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml
|
||||
// for more insight
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvInit(env);
|
||||
C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR);
|
||||
C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE);
|
||||
}
|
||||
}
|
||||
static void sceneRender(void) {
|
||||
Assets->Get<Amy::C3D::Shader>("shader")->Use();
|
||||
Assets->Get<Amy::C3D::Shader>("shader")->SetMat4(
|
||||
uLoc_projection, Amy::mat4::ortho(0, 400, 240, 0, 1, -1));
|
||||
|
||||
Amy::C3D::DrawArrays(0, vertex_list_count);
|
||||
}
|
||||
|
||||
static void sceneExit(void) {
|
||||
// Free the VBO
|
||||
linearFree(vbo_data);
|
||||
|
||||
Assets->Remove("shader");
|
||||
}
|
||||
|
||||
int main() {
|
||||
Amy::RegisterCxxExceptionHandler();
|
||||
Amy::Ctr::Init();
|
||||
Amy::C3D::Init();
|
||||
auto Top = Amy::C3D::CreateScreen(GFX_TOP);
|
||||
Assets = new Amy::AssetMgr();
|
||||
|
||||
sceneInit();
|
||||
|
||||
while (aptMainLoop()) {
|
||||
hidScanInput();
|
||||
|
||||
u32 kDown = hidKeysDown();
|
||||
if (kDown & KEY_START) break;
|
||||
|
||||
Amy::C3D::StartFrame();
|
||||
Top->Clear();
|
||||
Top->Use();
|
||||
sceneRender();
|
||||
Amy::C3D::EndFrame();
|
||||
}
|
||||
|
||||
sceneExit();
|
||||
|
||||
C3D_Fini();
|
||||
gfxExit();
|
||||
romfsExit();
|
||||
return 0;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <amethyst/c3d.hpp>
|
||||
#include <amethyst/ctru.hpp>
|
||||
#include <amethyst/image.hpp>
|
||||
#include <amethyst/iron.hpp>
|
||||
#include <amethyst/renderer.hpp>
|
||||
#include <amethyst/texture.hpp>
|
||||
|
||||
|
||||
@@ -49,6 +49,17 @@ class AssetMgr {
|
||||
return dynamic_cast<T*>(r->second) != nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t Count() const {
|
||||
size_t ret = 0;
|
||||
for (auto& it : pAssets) {
|
||||
if (dynamic_cast<T*>(it.second)) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<ID, Asset*> pAssets;
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ class C3D {
|
||||
// private:
|
||||
C3D_AttrInfo pInfo;
|
||||
shaderProgram_s pProgram;
|
||||
DVLB_s* pCode;
|
||||
DVLB_s* pCode = nullptr;
|
||||
int pReg = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -158,8 +158,8 @@ class Iron {
|
||||
static void pInitSolidTex();
|
||||
static bool pCheckSize(size_t idx, size_t vtx);
|
||||
|
||||
static std::vector<Vertex, linearAllocator<Vertex>> m_vbuf;
|
||||
static std::vector<u16, linearAllocator<u16>> m_ibuf;
|
||||
static std::vector<Vertex, LinearAllocator<Vertex>> m_vbuf;
|
||||
static std::vector<u16, LinearAllocator<u16>> m_ibuf;
|
||||
static int uLocProj;
|
||||
static C3D::Shader* m_shader;
|
||||
static mat4 m_mtx;
|
||||
|
||||
@@ -11,25 +11,35 @@
|
||||
|
||||
namespace Amy {
|
||||
template <typename T>
|
||||
class linearAllocator {
|
||||
class LinearAllocator {
|
||||
public:
|
||||
using value_type = T;
|
||||
linearAllocator() = default;
|
||||
LinearAllocator() noexcept = default;
|
||||
template <typename U>
|
||||
constexpr linearAllocator(const linearAllocator<U>&) noexcept {}
|
||||
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
|
||||
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > std::allocator_traits<linearAllocator>::max_size(*this)) {
|
||||
if (n > max_size()) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return static_cast<T*>(linearAlloc(n * sizeof(T)));
|
||||
}
|
||||
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
|
||||
|
||||
friend bool operator==(const linearAllocator, const linearAllocator) {
|
||||
template <class U, class... Args>
|
||||
void construct(U* p, Args&&... args) {
|
||||
::new ((void*)p) U(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void destroy(U* p) {
|
||||
p->~U();
|
||||
}
|
||||
|
||||
friend bool operator==(const LinearAllocator, const LinearAllocator) {
|
||||
return true;
|
||||
}
|
||||
friend bool operator!=(const linearAllocator, const linearAllocator) {
|
||||
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,13 @@ void C3D::DeleteScreen(C3D::Screen* screen) { delete screen; }
|
||||
|
||||
C3D::Shader::Shader(const std::string& path) { Load(path); }
|
||||
|
||||
C3D::Shader::~Shader() {}
|
||||
C3D::Shader::~Shader() {
|
||||
if (pCode) {
|
||||
shaderProgramFree(&pProgram);
|
||||
DVLB_Free(pCode);
|
||||
pCode = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void C3D::Shader::Load(const std::string& path) {
|
||||
auto code = Utils::LoadFile2Mem(path);
|
||||
@@ -66,7 +72,7 @@ void C3D::Shader::Compile(const std::string& code) {
|
||||
}
|
||||
|
||||
void C3D::Shader::Use() {
|
||||
C3D_BindProgram(&pProgram);
|
||||
// C3D_BindProgram(&pProgram);
|
||||
// for some reason i need both ???
|
||||
// code works perfectly without C3D_BindProgram
|
||||
// but nor withour shaderProgramUse ...
|
||||
|
||||
@@ -16,7 +16,7 @@ enum LiPathRectFlags_ : Amy::ui {
|
||||
namespace Amy {
|
||||
constexpr auto __pi = std::numbers::pi;
|
||||
|
||||
void Iron::Drawlist::Merge(Iron::Drawlist* list) {
|
||||
void Iron::Drawlist::Merge(Iron::Drawlist *list) {
|
||||
for (size_t i = 0; i < list->pData.size(); i++) {
|
||||
pData.push_back(std::move(list->pData[i]));
|
||||
}
|
||||
@@ -33,7 +33,7 @@ Iron::Command::ref Iron::Drawlist::NewCommand() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Iron::Drawlist::clipCmd(Command* ptr) {
|
||||
void Iron::Drawlist::clipCmd(Command *ptr) {
|
||||
if (!ClipRects.empty()) {
|
||||
ptr->ScissorOn = true;
|
||||
ptr->ScissorRect = ivec4(ClipRects.top());
|
||||
@@ -44,7 +44,7 @@ void Iron::Drawlist::Push(Command::ref cmd) { pData.push_back(std::move(cmd)); }
|
||||
|
||||
void Iron::Drawlist::DrawSolid() { pTex = Iron::WhiteTex(); }
|
||||
|
||||
void Iron::Drawlist::PathArcToN(const fvec2& c, float radius, float a_min,
|
||||
void Iron::Drawlist::PathArcToN(const fvec2 &c, float radius, float a_min,
|
||||
float a_max, int segments) {
|
||||
// pathAdd(c)
|
||||
PathReserve(segments + 1);
|
||||
@@ -54,7 +54,7 @@ void Iron::Drawlist::PathArcToN(const fvec2& c, float radius, float a_min,
|
||||
}
|
||||
}
|
||||
|
||||
void Iron::Drawlist::PathFastArcToN(const fvec2& c, float r, float amin,
|
||||
void Iron::Drawlist::PathFastArcToN(const fvec2 &c, float r, float amin,
|
||||
float amax, int s) {
|
||||
/**
|
||||
* Funcion with less division overhead
|
||||
@@ -68,7 +68,7 @@ void Iron::Drawlist::PathFastArcToN(const fvec2& c, float r, float amin,
|
||||
}
|
||||
}
|
||||
|
||||
void Iron::Drawlist::PathRect(const fvec2& a, const fvec2& b, float rounding) {
|
||||
void Iron::Drawlist::PathRect(const fvec2 &a, const fvec2 &b, float rounding) {
|
||||
if (rounding == 0.f) {
|
||||
PathAdd(a);
|
||||
PathAdd(fvec2(b.x, a.y));
|
||||
@@ -100,7 +100,7 @@ void Iron::Drawlist::PathRect(const fvec2& a, const fvec2& b, float rounding) {
|
||||
}
|
||||
}
|
||||
|
||||
void Iron::Drawlist::PathRectEx(const fvec2& a, const fvec2& b, float rounding,
|
||||
void Iron::Drawlist::PathRectEx(const fvec2 &a, const fvec2 &b, float rounding,
|
||||
ui flags) {
|
||||
if (rounding == 0.f) {
|
||||
PathAdd(a);
|
||||
@@ -150,35 +150,35 @@ void Iron::Drawlist::PathRectEx(const fvec2& a, const fvec2& b, float rounding,
|
||||
}
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawRect(const fvec2& pos, const fvec2& size, ui color,
|
||||
void Iron::Drawlist::DrawRect(const fvec2 &pos, const fvec2 &size, ui color,
|
||||
int thickness) {
|
||||
PathRect(pos, pos + size);
|
||||
PathStroke(color, thickness, 1);
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawRectFilled(const fvec2& pos, const fvec2& size,
|
||||
void Iron::Drawlist::DrawRectFilled(const fvec2 &pos, const fvec2 &size,
|
||||
ui color) {
|
||||
PathRect(pos, pos + size);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawTriangle(const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, ui color, int thickness) {
|
||||
void Iron::Drawlist::DrawTriangle(const fvec2 &a, const fvec2 &b,
|
||||
const fvec2 &c, ui color, int thickness) {
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathAdd(c);
|
||||
PathStroke(color, thickness, 1);
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawTriangleFilled(const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, ui color) {
|
||||
void Iron::Drawlist::DrawTriangleFilled(const fvec2 &a, const fvec2 &b,
|
||||
const fvec2 &c, ui color) {
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathAdd(c);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawCircle(const fvec2& center, float rad, ui color,
|
||||
void Iron::Drawlist::DrawCircle(const fvec2 ¢er, float rad, ui color,
|
||||
int segments, int thickness) {
|
||||
if (segments <= 0) {
|
||||
// Auto Segment
|
||||
@@ -186,11 +186,11 @@ void Iron::Drawlist::DrawCircle(const fvec2& center, float rad, ui color,
|
||||
float am = (__pi * 2.0f) * ((float)segments) / (float)segments;
|
||||
PathArcToN(center, rad, 0.f, am, segments);
|
||||
}
|
||||
DrawSolid(); // Only Solid Color Supported
|
||||
DrawSolid(); // Only Solid Color Supported
|
||||
PathStroke(color, thickness, 1);
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawCircleFilled(const fvec2& center, float rad, ui color,
|
||||
void Iron::Drawlist::DrawCircleFilled(const fvec2 ¢er, float rad, ui color,
|
||||
int segments) {
|
||||
if (segments <= 0) {
|
||||
// Auto Segment
|
||||
@@ -201,7 +201,7 @@ void Iron::Drawlist::DrawCircleFilled(const fvec2& center, float rad, ui color,
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2>& points, ui clr,
|
||||
void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2> &points, ui clr,
|
||||
ui flags, int thickness) {
|
||||
if (points.size() < 2) {
|
||||
return;
|
||||
@@ -223,17 +223,17 @@ void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2>& points, ui clr,
|
||||
Push(std::move(cmd));
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawConvexPolyFilled(const std::vector<fvec2>& points,
|
||||
void Iron::Drawlist::DrawConvexPolyFilled(const std::vector<fvec2> &points,
|
||||
ui clr) {
|
||||
if (points.size() < 3) {
|
||||
return; // Need at least three points
|
||||
return; // Need at least three points
|
||||
}
|
||||
auto cmd = NewCommand();
|
||||
CmdConvexPolyFilled(cmd.get(), points, clr, pTex);
|
||||
Push(std::move(cmd));
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawText(const fvec2& pos, const std::string& text,
|
||||
void Iron::Drawlist::DrawText(const fvec2 &pos, const std::string &text,
|
||||
ui color) {
|
||||
/*if (!pCurrentFont) {
|
||||
return;
|
||||
@@ -247,8 +247,8 @@ void Iron::Drawlist::DrawText(const fvec2& pos, const std::string& text,
|
||||
}*/
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawTextEx(const fvec2& p, const std::string& text,
|
||||
ui color, ui flags, const fvec2& box) {
|
||||
void Iron::Drawlist::DrawTextEx(const fvec2 &p, const std::string &text,
|
||||
ui color, ui flags, const fvec2 &box) {
|
||||
/*if (!pCurrentFont) {
|
||||
return;
|
||||
}
|
||||
@@ -261,9 +261,9 @@ void Iron::Drawlist::DrawTextEx(const fvec2& p, const std::string& text,
|
||||
}*/
|
||||
}
|
||||
|
||||
void Iron::Drawlist::DrawLine(const fvec2& a, const fvec2& b, ui color, int t) {
|
||||
void Iron::Drawlist::DrawLine(const fvec2 &a, const fvec2 &b, ui color, int t) {
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathStroke(color, t);
|
||||
}
|
||||
} // namespace Amy
|
||||
} // namespace Amy
|
||||
@@ -57,13 +57,14 @@ unsigned char li_shader[] = {
|
||||
};
|
||||
// clang-format on
|
||||
size_t li_shader_size = 0x124;
|
||||
std::vector<Iron::Vertex, linearAllocator<Iron::Vertex>> Iron::m_vbuf;
|
||||
std::vector<u16, linearAllocator<u16>> Iron::m_ibuf;
|
||||
std::vector<Iron::Vertex, LinearAllocator<Iron::Vertex>> Iron::m_vbuf;
|
||||
std::vector<u16, LinearAllocator<u16>> Iron::m_ibuf;
|
||||
int Iron::uLocProj = 0;
|
||||
C3D::Shader* Iron::m_shader = nullptr;
|
||||
mat4 Iron::m_mtx;
|
||||
int Iron::m_idx = 0, Iron::m_vtx = 0;
|
||||
Texture* Iron::m_solid = nullptr;
|
||||
C3D_Mtx __m;
|
||||
|
||||
void Iron::Init() {
|
||||
pSetupShader();
|
||||
@@ -79,9 +80,13 @@ void Iron::NewFrame() {
|
||||
|
||||
void Iron::DrawOn(C3D::Screen* screen) {
|
||||
m_shader->Use();
|
||||
m_mtx = mat4::ortho(0.f, (float)screen->Width(), (float)screen->Height(), 0.f,
|
||||
1.f, -1.f);
|
||||
m_shader->SetMat4(uLocProj, m_mtx);
|
||||
Mtx_Identity(&__m);
|
||||
Mtx_OrthoTilt(&__m, 0, (float)screen->Width(), (float)screen->Height(), 0.f,
|
||||
1.f, -1.f, true);
|
||||
// m_mtx = mat4::ortho(0.f, (float)screen->Width(), (float)screen->Height(),
|
||||
// 0.f,
|
||||
// 1.f, -1.f);
|
||||
m_shader->SetMat4(uLocProj, &__m);
|
||||
}
|
||||
|
||||
void Iron::Draw(const std::vector<Iron::Command::ref>& data) {
|
||||
@@ -148,11 +153,11 @@ void Iron::pSetupShader() {
|
||||
AttrInfo_AddLoader(&m_shader->pInfo, 0, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&m_shader->pInfo, 1, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&m_shader->pInfo, 2, GPU_UNSIGNED_BYTE, 4);
|
||||
// m_shader->Load("romfs:/shaders/lithium.shbin");
|
||||
// m_shader->Compile(__ironshader__);
|
||||
// m_shader->Input(GPU_FLOAT, 2); // pos
|
||||
// m_shader->Input(GPU_FLOAT, 2); // uv
|
||||
// m_shader->Input(GPU_UNSIGNED_BYTE, 4); // color
|
||||
/* m_shader->Load("romfs:/shaders/lithium.shbin");
|
||||
// m_shader->Compile(__ironshader__);
|
||||
m_shader->Input(GPU_FLOAT, 2); // pos
|
||||
m_shader->Input(GPU_FLOAT, 2); // uv
|
||||
m_shader->Input(GPU_UNSIGNED_BYTE, 4); // color*/
|
||||
uLocProj = m_shader->loc("projection");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user