- 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:
@@ -12,6 +12,8 @@ const auto DISPLAY_TRANSFER_FLAGS =
|
||||
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
|
||||
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO);
|
||||
C3D_TexEnv* c3d::frag::m_env = nullptr;
|
||||
int c3d::m_drawcalls = 0;
|
||||
int c3d::m__dc__ = 0;
|
||||
|
||||
void c3d::init() { C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); }
|
||||
|
||||
@@ -19,9 +21,13 @@ void c3d::deinit() { C3D_Fini(); }
|
||||
|
||||
void c3d::startFrame(bool sync) {
|
||||
C3D_FrameBegin(sync ? C3D_FRAME_SYNCDRAW : C3D_FRAME_NONBLOCK);
|
||||
m__dc__ = 0;
|
||||
}
|
||||
|
||||
void c3d::endFrame() { C3D_FrameEnd(0); }
|
||||
void c3d::endFrame() {
|
||||
C3D_FrameEnd(0);
|
||||
m_drawcalls = m__dc__;
|
||||
}
|
||||
|
||||
c3d::screen* c3d::createScreen(gfxScreen_t screen, gfx3dSide_t side) {
|
||||
auto t = C3D_RenderTargetCreate(240, screen == GFX_TOP ? 400 : 320,
|
||||
@@ -39,7 +45,8 @@ c3d::shader::~shader() {}
|
||||
void c3d::shader::load(const std::string& path) {
|
||||
auto code = utils::loadFile2Mem(path);
|
||||
if (!code.size()) {
|
||||
throw std::runtime_error("[amy] shader: unable to load " + path);
|
||||
throw std::runtime_error(
|
||||
std::format("[amy] unsable to load shader ({})", path));
|
||||
}
|
||||
load(code);
|
||||
}
|
||||
@@ -58,6 +65,10 @@ void c3d::shader::compile(const std::string& code) {
|
||||
}
|
||||
|
||||
void c3d::shader::use() {
|
||||
C3D_BindProgram(&m_program);
|
||||
// for some reason i need both ???
|
||||
// code works perfectly without C3D_BindProgram
|
||||
// but nor withour shaderProgramUse ...
|
||||
shaderProgramUse(&m_program);
|
||||
C3D_SetAttrInfo(&m_info);
|
||||
}
|
||||
@@ -92,10 +103,32 @@ void c3d::frag::edit(int id) {
|
||||
|
||||
void c3d::drawArrays(int start, int count, GPU_Primitive_t prim) {
|
||||
C3D_DrawArrays(prim, start, count);
|
||||
m__dc__++;
|
||||
}
|
||||
|
||||
void c3d::drawElements(int count, const void* idx_ptr, int type,
|
||||
GPU_Primitive_t prim) {
|
||||
C3D_DrawElements(prim, count, type, idx_ptr);
|
||||
m__dc__++;
|
||||
}
|
||||
|
||||
void c3d::depthTest(bool on, GPU_TESTFUNC func, GPU_WRITEMASK mask) {
|
||||
C3D_DepthTest(on, func, mask);
|
||||
}
|
||||
|
||||
void c3d::disableScissor() { C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0); }
|
||||
|
||||
void c3d::enableScissor(const ivec4 rect) {
|
||||
C3D_SetScissor(GPU_SCISSOR_NORMAL, rect.x, rect.y, rect.z, rect.w);
|
||||
}
|
||||
|
||||
void c3d::bufCfg(void* ptr, int stride, int shader_attribs, u64 permutation) {
|
||||
auto buf = C3D_GetBufInfo();
|
||||
BufInfo_Init(buf);
|
||||
BufInfo_Add(buf, ptr, stride, shader_attribs, permutation);
|
||||
}
|
||||
|
||||
void c3d::bufCfg(void* ptr, int stride, int shader_attribs) {
|
||||
bufCfg(ptr, stride, shader_attribs, permutation(shader_attribs));
|
||||
}
|
||||
} // namespace amy
|
||||
5
source/iron/drawlist.cpp
Normal file
5
source/iron/drawlist.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <amethyst/iron.hpp>
|
||||
|
||||
namespace amy {
|
||||
void iron::drawlist::merge(iron::drawlist* list) {}
|
||||
} // namespace amy
|
||||
@@ -60,6 +60,41 @@ void iron::drawOn(c3d::screen* screen) {
|
||||
m_shader->setMat4(uLocProj, m_mtx);
|
||||
}
|
||||
|
||||
void iron::draw(const std::vector<iron::command::ref>& data) {
|
||||
// disable depthtest cause we have no z buffer
|
||||
c3d::depthTest(false);
|
||||
fragConfig();
|
||||
size_t i = 0;
|
||||
while (i < data.size()) {
|
||||
texture* tex = data[i]->tex;
|
||||
if (!tex) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
auto scissorOn = data[i]->scissorOn;
|
||||
auto scissor = data[i]->scissorRect;
|
||||
auto start = i;
|
||||
// Loop until a statgechange and copy all data into vertex/index buf
|
||||
while (i < data.size() && scissorOn == data[i]->scissorOn &&
|
||||
scissor == data[i]->scissorRect && tex == data[i]->tex) {
|
||||
auto c = data[i].get();
|
||||
for (int j = 0; j < c->indexBuf.size(); j++) {
|
||||
m_ibuf[m_idx++] = m_vtx + c->indexBuf[i];
|
||||
}
|
||||
for (int j = 0; j < c->vertexBuf.size(); j++) {
|
||||
m_vbuf[m_vtx++] = c->vertexBuf[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
///// SCISSOR LOGIC BEG /////
|
||||
///// SCISSOR LOGIC END /////
|
||||
tex->bind();
|
||||
c3d::bufCfg<3>(m_vbuf.data(), sizeof(vertex));
|
||||
c3d::drawElements(i - start, m_ibuf.data() + start);
|
||||
}
|
||||
c3d::depthTest(true);
|
||||
}
|
||||
|
||||
void iron::setupShader() {
|
||||
m_shader = new c3d::shader();
|
||||
m_shader->compile(__ironshader__);
|
||||
@@ -51,24 +51,24 @@ void texture::load(cstr& path) {
|
||||
}
|
||||
|
||||
int bpp = img.bpp();
|
||||
m_w = img.width();
|
||||
if (utils::isSingleBitNum(m_w)) {
|
||||
m_w = utils::nextPow2(m_w);
|
||||
m_size.x = img.width();
|
||||
if (utils::isSingleBitNum(m_size.x)) {
|
||||
m_size.x = utils::nextPow2(m_size.x);
|
||||
}
|
||||
m_h = img.width();
|
||||
if (utils::isSingleBitNum(m_h)) {
|
||||
m_h = utils::nextPow2(m_h);
|
||||
m_size.y = img.height();
|
||||
if (utils::isSingleBitNum(m_size.y)) {
|
||||
m_size.y = utils::nextPow2(m_size.y);
|
||||
}
|
||||
auto filter = GPU_NEAREST;
|
||||
auto format = image2TexFmt(img.fmt());
|
||||
C3D_TexInit(&m_tex, (u16)m_w, (u16)m_h, format);
|
||||
C3D_TexInit(&m_tex, (u16)m_size.x, (u16)m_size.y, format);
|
||||
C3D_TexSetFilter(&m_tex, filter, filter);
|
||||
// Using std::fill_n instead cause i hate this error lines
|
||||
// under the memset func in my editor
|
||||
std::fill_n((unsigned char*)m_tex.data, m_tex.size, 0);
|
||||
for (int x = 0; x < img.width(); x++) {
|
||||
for (int y = 0; y < img.height(); y++) {
|
||||
int dst_pos = tile3dsTex(x, y, m_w) * bpp;
|
||||
int dst_pos = tile3dsTex(x, y, m_size.x) * bpp;
|
||||
int src_pos = (y * img.width() + x) * bpp;
|
||||
/// Best idea i had
|
||||
for (int i = 0; i < bpp; i++) {
|
||||
@@ -81,4 +81,6 @@ void texture::load(cstr& path) {
|
||||
C3D_TexSetWrap(&m_tex, GPU_REPEAT, GPU_REPEAT);
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
void texture::bind(int reg) { C3D_TexBind(reg, &m_tex); }
|
||||
} // namespace amy
|
||||
Reference in New Issue
Block a user