Get it finally working (somehow)
- Add working example - Add Namespace defs for Iron Ctr and C3D - Add Exit func / Vertex / Index counter to Iron - Add format bytes function to utils - Make stb_image optional - Compute texture uv's - Clear Everything in Drawlist::Clear - Use Amy::mat4 as matrix lib - Fix the most stupid rendering bug (i -> m_idx)
This commit is contained in:
@@ -1,25 +1,57 @@
|
||||
#include <amethyst.hpp>
|
||||
#include <iostream>
|
||||
|
||||
class Example : public Amy::App {
|
||||
public:
|
||||
public:
|
||||
Example() {
|
||||
Amy::Ctr::Init();
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
Amy::C3D::Init();
|
||||
Top = Amy::C3D::CreateScreen(GFX_TOP);
|
||||
Mgr = new Amy::AssetMgr();
|
||||
Mgr->AutoLoad("icon", "romfs:/icon.png");
|
||||
Amy::Iron::Init();
|
||||
dl = new Amy::Iron::Drawlist();
|
||||
}
|
||||
~Example() {
|
||||
delete Top;
|
||||
delete dl;
|
||||
delete Mgr;
|
||||
Amy::C3D::Deinit();
|
||||
}
|
||||
~Example() { delete Top; }
|
||||
|
||||
void Main() {
|
||||
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;1H\nLin: {}\nVertices: {}\nIndices: "
|
||||
"{}\x1b[K",
|
||||
Amy::Utils::FormatBytes(linearSpaceFree()), Amy::Iron::VerticesDrawn(),
|
||||
Amy::Iron::IndicesDrawn());
|
||||
Amy::C3D::StartFrame();
|
||||
Top->Clear();
|
||||
Top->Use();
|
||||
dl->DrawTex(Mgr->Get<Amy::Texture>("icon"));
|
||||
dl->DrawRectFilled(Amy::fvec2(50, 0), 48, 0x99999999);
|
||||
dl->DrawCircleFilled(Amy::fvec2(200, 120), 50, 0xffffffff, 40);
|
||||
dl->DrawSolid();
|
||||
dl->DrawRectFilled(0, 50, 0x4400ff00);
|
||||
|
||||
Amy::Iron::NewFrame();
|
||||
Amy::Iron::DrawOn(Top);
|
||||
Amy::Iron::Draw(*dl);
|
||||
dl->Clear();
|
||||
Amy::C3D::EndFrame();
|
||||
}
|
||||
|
||||
Amy::C3D::Screen *Top;
|
||||
Amy::C3D::Screen* Top;
|
||||
Amy::AssetMgr* Mgr;
|
||||
Amy::Iron::Drawlist* dl;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Amy::RegisterCxxExceptionHandler();
|
||||
Example App;
|
||||
App.Run();
|
||||
return 0;
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user