diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp index 53213c8..3b4e31e 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp @@ -40,8 +40,7 @@ class DynPipCore { void renderPart(DynPipBag* data, const bool& frustumCull = true); /** Get max vert count of VU1 qbuffer (for optimizations) */ - u32 getMaxVertCountByParams(const bool& isSingleColor, - const bool& isLightingEnabled, + u32 getMaxVertCountByParams(const bool& isLightingEnabled, const bool& isTextureEnabled); /** diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp deleted file mode 100644 index a7b0673..0000000 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#pragma once - -#include "./bag/dynpip_bag.hpp" - -namespace Tyra { - -class DynPipQBuffer { - public: - DynPipQBuffer(); - ~DynPipQBuffer(); - - void setMaxVertCount(const u32& count); - - DynPipBag* bag; - - Vec4* verticesFrom; - Vec4* verticesTo; - - Vec4* stsFrom; - Vec4* stsTo; - - Vec4* normalsFrom; - Vec4* normalsTo; - - /** Size per frame */ - u32 size; - - void print() const; - void print(const char* name) const; - void print(const std::string& name) const { print(name.c_str()); } - std::string getPrint(const char* name = nullptr) const; - - private: - u32 maxVertCount; -}; - -} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp index 9706346..3fced1d 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp @@ -25,16 +25,10 @@ class DynPipRenderer { void reinitVU1(); - // DynPipQBuffer* getBuffer(); - void sendObjectData(DynPipBag* bag, M4x4* mvp, RendererCoreTextureBuffers* texBuffers) const; - // void setMaxVertCount(const u32& count); - - // void setInfo(PipelineInfoBag* bag); - - // void render(DynPipQBuffer* buffer); + void render(DynPipBag* bag); void clearLastProgramName(); @@ -46,9 +40,8 @@ class DynPipRenderer { void uploadPrograms(); void setDoubleBuffer(); - // void addBufferDataToPacket(DynPipVU1Program* program, DynPipQBuffer* - // buffer); void sendPacket(); - // DynPipQBuffer buffers[2]; + void addBufferDataToPacket(DynPipVU1Program* program, DynPipBag* bag); + void sendPacket(); packet2_t* packets[2]; packet2_t* programsPacket; diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp index 054f862..fb15cd9 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.hpp @@ -13,7 +13,7 @@ #include "./dynpip_program_name.hpp" #include "renderer/core/paths/path1/vu1_program.hpp" #include "./programs/dynpip_vu1_shared_defines.h" -#include "./dynpip_qbuffer.hpp" +#include "./bag/dynpip_bag.hpp" namespace Tyra { @@ -28,11 +28,9 @@ class DynPipVU1Program : public VU1Program { const DynPipProgramName& getName() const; - u16 getMaxVertCount(const bool& singleColorEnabled, - const u16& vu1DBufferSize) const; + u16 getMaxVertCount(const u16& vu1DBufferSize) const; - void addBufferDataToPacket(packet2_t* packet, DynPipQBuffer* buffer, - prim_t* prim); + void addBufferDataToPacket(packet2_t* packet, DynPipBag* bag, prim_t* prim); protected: DynPipProgramName name; @@ -40,10 +38,10 @@ class DynPipVU1Program : public VU1Program { u32 destinationAddress, reglist; virtual void addProgramQBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* qbuffer) const = 0; + DynPipBag* bag) const = 0; private: - void addStandardBufferDataToPacket(packet2_t* packet, DynPipQBuffer* buffer, + void addStandardBufferDataToPacket(packet2_t* packet, DynPipBag* bag, prim_t* prim); }; diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp index 2a2aa07..994355f 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.hpp @@ -22,8 +22,7 @@ class DynPipCVU1Program : public DynPipVU1Program { ~DynPipCVU1Program(); std::string getStringName() const; - void addProgramQBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* qbuffer) const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp index f74b531..b498ad1 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.hpp @@ -22,8 +22,7 @@ class DynPipDVU1Program : public DynPipVU1Program { ~DynPipDVU1Program(); std::string getStringName() const; - void addProgramQBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* qbuffer) const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp index 5cef343..5b1d231 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.hpp @@ -22,8 +22,7 @@ class DynPipTCVU1Program : public DynPipVU1Program { ~DynPipTCVU1Program(); std::string getStringName() const; - void addProgramQBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* qbuffer) const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp index 192caab..5f528e0 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.hpp @@ -22,8 +22,7 @@ class DynPipTDVU1Program : public DynPipVU1Program { ~DynPipTDVU1Program(); std::string getStringName() const; - void addProgramQBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* qbuffer) const; + void addProgramQBufferDataToPacket(packet2_t* packet, DynPipBag* bag) const; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp b/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp index ece1bad..9f0ce84 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp @@ -14,10 +14,19 @@ namespace Tyra { +enum DynPipFrustumCulling { + DynPipFrustumCulling_None = 0, + DynPipFrustumCulling_Simple = 1, + DynPipFrustumCulling_Precise = 2, +}; + class DynPipOptions : public PipelineOptions { public: DynPipOptions() {} ~DynPipOptions() {} + + /** Default: Simple */ + DynPipFrustumCulling frustumCulling; }; } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp index d1696bf..946b655 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp @@ -11,6 +11,7 @@ #include "renderer/3d/pipeline/dynamic/core/dynpip_core.hpp" #include #include +#include "thread/threading.hpp" namespace Tyra { @@ -25,11 +26,10 @@ void DynPipCore::init(RendererCore* t_core) { void DynPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); } -u32 DynPipCore::getMaxVertCountByParams(const bool& isSingleColor, - const bool& isLightingEnabled, +u32 DynPipCore::getMaxVertCountByParams(const bool& isLightingEnabled, const bool& isTextureEnabled) { return repository.getProgramByParams(isLightingEnabled, isTextureEnabled) - ->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize()); + ->getMaxVertCount(qbufferRenderer.getBufferSize()); } void DynPipCore::initParts(DynPipBag* bag) { @@ -49,6 +49,24 @@ void DynPipCore::initParts(DynPipBag* bag) { void DynPipCore::renderPart(DynPipBag* bag, const bool& frustumCull) { if (bag->count <= 0) return; + TYRA_ASSERT(bag->verticesFrom != nullptr && bag->verticesTo != nullptr, + "Vertices are required in 3D render bag!"); + TYRA_ASSERT(bag->info != nullptr, "Info bag is required in 3D render bag!"); + TYRA_ASSERT(bag->info->model != nullptr, + "Info bag's model pointer is empty!"); + TYRA_ASSERT(bag->color != nullptr, "Color bag is required in 3D render bag!"); + TYRA_ASSERT(bag->color->single, "Color is required in 3D render bag!"); + TYRA_ASSERT( + !bag->lighting || + (bag->lighting->lightMatrix && bag->lighting->normalsFrom && + bag->lighting->normalsTo && bag->lighting->dirLights), + "If you want lighting, please provide light matrix normals and dir " + "lights!"); + TYRA_ASSERT(!bag->texture || + (bag->texture->texture && bag->texture->coordinatesFrom && + bag->texture->coordinatesTo), + "If you want texture, please provide texture and coordinates!"); + if (frustumCull) { CoreBBox bbox(bag->verticesTo, bag->count); if (bbox.isInFrustum(rendererCore->renderer3D.frustumPlanes.getAll(), @@ -58,10 +76,7 @@ void DynPipCore::renderPart(DynPipBag* bag, const bool& frustumCull) { } } - // TODO: Uruchomic odpowiedni program - // TODO: Wyslac wierzcholki - // TODO: Program VU1 TD - // TODO: Reszta programow VU1 + qbufferRenderer.render(bag); } } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp index 3150486..c47e9f4 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.cpp @@ -16,6 +16,11 @@ DynPipProgramsRepository::DynPipProgramsRepository() {} DynPipProgramsRepository::~DynPipProgramsRepository() {} +DynPipVU1Program* DynPipProgramsRepository::getProgramByBag( + const DynPipBag* bag) { + return getProgramByParams(bag->lighting, bag->texture); +} + DynPipVU1Program* DynPipProgramsRepository::getProgramByParams( const bool& isLightingEnabled, const bool& isTextureEnabled) { if (isLightingEnabled && isTextureEnabled) diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp deleted file mode 100644 index 86f9096..0000000 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2022, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp" -#include -#include - -namespace Tyra { - -DynPipQBuffer::DynPipQBuffer() {} - -DynPipQBuffer::~DynPipQBuffer() {} - -void DynPipQBuffer::setMaxVertCount(const u32& count) { maxVertCount = count; } - -void DynPipQBuffer::print() const { - auto text = getPrint(nullptr); - printf("%s\n", text.c_str()); -} - -void DynPipQBuffer::print(const char* name) const { - auto text = getPrint(name); - printf("%s\n", text.c_str()); -} - -std::string DynPipQBuffer::getPrint(const char* name) const { - std::stringstream res; - if (name) { - res << name << "("; - } else { - res << "DynPipQBuffer("; - } - res << std::fixed << std::setprecision(2); - res << std::endl; - res << "Size: " << static_cast(size) << std::endl; - - res << "Vertices from: " << std::endl; - for (u32 i = 0; i < size; i++) - res << i << ": " << verticesFrom[i].getPrint() << std::endl; - - res << "Vertices to: " << std::endl; - for (u32 i = 0; i < size; i++) - res << i << ": " << verticesTo[i].getPrint() << std::endl; - - if (bag->texture != nullptr) { - res << "STs from: " << std::endl; - for (u32 i = 0; i < size; i++) - res << i << ": " << stsFrom[i].getPrint() << std::endl; - - res << "STs to: " << std::endl; - for (u32 i = 0; i < size; i++) - res << i << ": " << stsTo[i].getPrint() << std::endl; - } - - if (bag->lighting != nullptr) { - res << "Normals from: " << std::endl; - for (u32 i = 0; i < size; i++) { - res << i << ": " << normalsFrom[i].getPrint() << std::endl; - } - - res << "Normals to: " << std::endl; - for (u32 i = 0; i < size; i++) { - res << i << ": " << normalsTo[i].getPrint(); - if (i < size - 1) { - res << std::endl; - } - } - } - - res << ")"; - return res.str(); -} - -} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp index 2d6177a..56c0b52 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp @@ -16,6 +16,7 @@ namespace Tyra { DynPipRenderer::DynPipRenderer() { context = 0; + bufferSize = 0; lastProgramName = DynPipProgramName::DynPipUndefinedProgram; staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); @@ -33,32 +34,32 @@ DynPipRenderer::~DynPipRenderer() { void DynPipRenderer::init(RendererCore* t_core, DynPipProgramsRepository* t_programRepo) { - // path1 = t_core->getPath1(); - // rendererCore = t_core; - // programsRepo = t_programRepo; + path1 = t_core->getPath1(); + rendererCore = t_core; + programsRepo = t_programRepo; - // dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); - // dma_channel_fast_waits(DMA_CHANNEL_VIF1); + dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); + dma_channel_fast_waits(DMA_CHANNEL_VIF1); - // const u32 VU1_PACKET_SIZE = 16; + const u32 VU1_PACKET_SIZE = 16; - // packets[0] = - // packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + packets[0] = + packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - // packets[1] = - // packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + packets[1] = + packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - // setProgramsCache(); + setProgramsCache(); - // reinitVU1(); + reinitVU1(); - // TYRA_LOG("Renderer3DQBufferRenderer initialized"); + TYRA_LOG("DynPipRenderer initialized"); } void DynPipRenderer::reinitVU1() { - // sendStaticData(); - // uploadPrograms(); - // setDoubleBuffer(); + sendStaticData(); + uploadPrograms(); + setDoubleBuffer(); } void DynPipRenderer::setProgramsCache() { @@ -136,6 +137,36 @@ void DynPipRenderer::sendObjectData( // dma_channel_send_packet2(objectDataPacket, DMA_CHANNEL_VIF1, true); } +void DynPipRenderer::render(DynPipBag* bag) { + auto* program = programsRepo->getProgramByBag(bag); + addBufferDataToPacket(program, bag); + sendPacket(); +} + +void DynPipRenderer::addBufferDataToPacket(DynPipVU1Program* program, + DynPipBag* bag) { + currentPacket = packets[context]; + packet2_reset(currentPacket, false); + program->addBufferDataToPacket(currentPacket, bag, &rendererCore->gs.prim); + + if (lastProgramName != program->getName()) { + packet2_utils_vu_add_start_program(currentPacket, + program->getDestinationAddress()); + lastProgramName = program->getName(); + } else { + packet2_utils_vu_add_continue_program(currentPacket); + } + packet2_utils_vu_add_end_tag(currentPacket); +} + +void DynPipRenderer::sendPacket() { + dma_channel_wait(DMA_CHANNEL_VIF1, 0); + dma_channel_send_packet2(currentPacket, DMA_CHANNEL_VIF1, true); + + // Switch packet, so we can proceed during DMA transfer + context = !context; +} + void DynPipRenderer::clearLastProgramName() { lastProgramName = DynPipUndefinedProgram; } diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp index 165c1f8..50b8819 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_vu1_program.cpp @@ -32,15 +32,14 @@ const DynPipProgramName& DynPipVU1Program::getName() const { return name; } u32& DynPipVU1Program::getReglist() { return reglist; } -void DynPipVU1Program::addBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* buffer, +void DynPipVU1Program::addBufferDataToPacket(packet2_t* packet, DynPipBag* bag, prim_t* prim) { - addStandardBufferDataToPacket(packet, buffer, prim); - addProgramQBufferDataToPacket(packet, buffer); + addStandardBufferDataToPacket(packet, bag, prim); + addProgramQBufferDataToPacket(packet, bag); } void DynPipVU1Program::addStandardBufferDataToPacket(packet2_t* packet, - DynPipQBuffer* buffer, + DynPipBag* bag, prim_t* prim) { // if (buffer->bag->texture) // prim->mapping = 1; @@ -61,12 +60,9 @@ void DynPipVU1Program::addStandardBufferDataToPacket(packet2_t* packet, // packet2_utils_vu_close_unpack(packet); } -u16 DynPipVU1Program::getMaxVertCount(const bool& singleColorEnabled, - const u16& bufferSize) const { +u16 DynPipVU1Program::getMaxVertCount(const u16& bufferSize) const { u16 res = bufferSize - 4; - u8 colorElementsPerVertex = - singleColorEnabled ? (elementsPerVertex - 1) : elementsPerVertex; - res /= (colorElementsPerVertex + reglistCount); + res /= (elementsPerVertex + reglistCount); // Buffer size = VU1 double buffer size (xtop) // QBufferSize = res (it is placed inside VU1) diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp index 4a76c80..497efdc 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_c_vu1_program.cpp @@ -19,7 +19,7 @@ namespace Tyra { DynPipCVU1Program::DynPipCVU1Program() : DynPipVU1Program( DynPipColor, &DynPipVU1_C_CodeStart, &DynPipVU1_C_CodeEnd, - ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 2) {} + ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 1) {} DynPipCVU1Program::~DynPipCVU1Program() {} @@ -27,8 +27,8 @@ std::string DynPipCVU1Program::getStringName() const { return std::string("DynPip - C"); } -void DynPipCVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, DynPipQBuffer* qbuffer) const { +void DynPipCVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { // u32 addr = VU1_VERT_DATA_ADDR; // // Add vertices diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp index c7bc969..6bd8653 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_d_vu1_program.cpp @@ -19,7 +19,7 @@ namespace Tyra { DynPipDVU1Program::DynPipDVU1Program() : DynPipVU1Program( DynPipDirLights, &DynPipVU1_D_CodeStart, &DynPipVU1_D_CodeEnd, - ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 3) {} + ((u64)GIF_REG_RGBAQ) << 0 | ((u64)GIF_REG_XYZ2) << 4, 2, 2) {} DynPipDVU1Program::~DynPipDVU1Program() {} @@ -27,8 +27,8 @@ std::string DynPipDVU1Program::getStringName() const { return std::string("DynPip - D"); } -void DynPipDVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, DynPipQBuffer* qbuffer) const { +void DynPipDVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { // u32 addr = VU1_VERT_DATA_ADDR; // // Add vertices diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp index 4a85c77..676fd6d 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_tc_vu1_program.cpp @@ -21,7 +21,7 @@ DynPipTCVU1Program::DynPipTCVU1Program() &DynPipVU1_TC_CodeEnd, ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | ((u64)GIF_REG_XYZ2) << 8, - 3, 3) {} + 3, 2) {} DynPipTCVU1Program::~DynPipTCVU1Program() {} @@ -29,8 +29,8 @@ std::string DynPipTCVU1Program::getStringName() const { return std::string("DynPip - TC"); } -void DynPipTCVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, DynPipQBuffer* qbuffer) const { +void DynPipTCVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { // u32 addr = VU1_VERT_DATA_ADDR; // // Add vertices diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp index a71f104..3c0beec 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1.vclpp @@ -32,8 +32,14 @@ #vuprog DynPipVU1TD ---cont +ResetClipFlags{ } +begin: + xtop buffer + + +; --cont + #endvuprog --exit diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp index ce66464..f3cc69c 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/programs/dynpip_td_vu1_program.cpp @@ -21,7 +21,7 @@ DynPipTDVU1Program::DynPipTDVU1Program() &DynPipVU1_TD_CodeEnd, ((u64)GIF_REG_ST) << 0 | ((u64)GIF_REG_RGBAQ) << 4 | ((u64)GIF_REG_XYZ2) << 8, - 3, 4) {} + 3, 3) {} DynPipTDVU1Program::~DynPipTDVU1Program() {} @@ -29,33 +29,37 @@ std::string DynPipTDVU1Program::getStringName() const { return std::string("DynPip - TD"); } -void DynPipTDVU1Program::addProgramQBufferDataToPacket( - packet2_t* packet, DynPipQBuffer* qbuffer) const { +void DynPipTDVU1Program::addProgramQBufferDataToPacket(packet2_t* packet, + DynPipBag* bag) const { u32 addr = VU1_VERT_DATA_ADDR; // Add vertices - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->verticesFrom, - qbuffer->size, true); - addr += qbuffer->size; - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->verticesTo, - qbuffer->size, true); - addr += qbuffer->size; - - // Add sts - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->stsFrom, - qbuffer->size, true); - addr += qbuffer->size; - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->stsTo, qbuffer->size, + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesFrom, bag->count, true); - addr += qbuffer->size; + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->verticesTo, bag->count, + true); + addr += bag->count; - // Add normal - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->normalsFrom, - qbuffer->size, true); - addr += qbuffer->size; - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->normalsTo, - qbuffer->size, true); - addr += qbuffer->size; + if (bag->texture) { + // Add sts + packet2_utils_vu_add_unpack_data( + packet, addr, bag->texture->coordinatesFrom, bag->count, true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->texture->coordinatesTo, + bag->count, true); + addr += bag->count; + } + + if (bag->lighting) { + // Add normal + packet2_utils_vu_add_unpack_data(packet, addr, bag->lighting->normalsFrom, + bag->count, true); + addr += bag->count; + packet2_utils_vu_add_unpack_data(packet, addr, bag->lighting->normalsTo, + bag->count, true); + addr += bag->count; + } } } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp index c0e62a9..e5fc654 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp @@ -21,7 +21,7 @@ void DynamicPipeline::init(RendererCore* t_core) { core.init(t_core); } -void DynamicPipeline::onUse() {} +void DynamicPipeline::onUse() { core.reinitVU1Programs(); } void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { auto model = mesh->getModelMatrix(); @@ -29,6 +29,16 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame()); auto* infoBag = getInfoBag(mesh, options, &model); PipelineDirLightsBag* dirLights = nullptr; + auto frustumCulling = + options ? options->frustumCulling : DynPipFrustumCulling_Simple; + + if (frustumCulling == DynPipFrustumCulling_Simple) { + if (frameTo->getBBox().isInFrustum( + rendererCore->renderer3D.frustumPlanes.getAll(), model) == + CoreBBoxFrustum::OUTSIDE_FRUSTUM) { + return; + } + } if (options && options->lighting) { setLightingColorsCache(options->lighting); @@ -46,8 +56,7 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { auto* material = mesh->getMaterial(i); auto partSize = core.getMaxVertCountByParams( - material->isSingleColorActivated(), options && options->lighting, - material->getTextureCoordFaces()); + options && options->lighting, material->getTextureCoordFaces()); u32 partsCount = ceil(material->getFacesCount() / static_cast(partSize)); auto* colorBag = getColorBag(material); @@ -76,7 +85,7 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { isPartInitialized = true; } - core.renderPart(&buffer); + core.renderPart(&buffer, frustumCulling == DynPipFrustumCulling_Precise); context = !context; } @@ -155,8 +164,9 @@ void DynamicPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material, for (u32 i = startIndex; i < startIndex + bag->count; i++) { auto& face = material->getVertexFaces()[i]; - bag->verticesFrom[i] = frameFrom->getVertices()[face]; - bag->verticesTo[i] = frameTo->getVertices()[face]; + auto offset = i - startIndex; + bag->verticesFrom[offset] = frameFrom->getVertices()[face]; + bag->verticesTo[offset] = frameTo->getVertices()[face]; } } @@ -182,8 +192,9 @@ DynPipTextureBag* DynamicPipeline::getTextureBag( for (u32 i = startIndex; i < startIndex + count; i++) { auto& face = material->getTextureCoordFaces()[i]; - result->coordinatesFrom[i] = frameFrom->getTextureCoords()[face]; - result->coordinatesTo[i] = frameTo->getTextureCoords()[face]; + auto offset = i - startIndex; + result->coordinatesFrom[offset] = frameFrom->getTextureCoords()[face]; + result->coordinatesTo[offset] = frameTo->getTextureCoords()[face]; } return result; @@ -201,13 +212,15 @@ DynPipLightingBag* DynamicPipeline::getLightingBag( auto* result = new DynPipLightingBag(); result->lightMatrix = model; + result->dirLights = dirLightsBag; result->normalsFrom = new Vec4[count]; result->normalsTo = new Vec4[count]; for (u32 i = startIndex; i < startIndex + count; i++) { auto& face = material->getNormalFaces()[i]; - result->normalsFrom[i] = frameFrom->getNormals()[face]; - result->normalsTo[i] = frameTo->getNormals()[face]; + auto offset = i - startIndex; + result->normalsFrom[offset] = frameFrom->getNormals()[face]; + result->normalsTo[offset] = frameTo->getNormals()[face]; } return result; diff --git a/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp b/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp index 2212b45..19c4487 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp @@ -70,8 +70,6 @@ void MinecraftPipeline::render(McpipBlock* blocks, const u32& count, if (culled > 0) cull(blocks, cullIndexes, &texBuffers, isMulti); if (clipped > 0) clip(blocks, clipIndexes, &texBuffers, isMulti); } - - Threading::switchThread(); } CoreBBoxFrustum MinecraftPipeline::isInFrustum(const McpipBlock& block) const { diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp index 9a3a19f..ce1daf5 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp @@ -136,8 +136,6 @@ void StaPipCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox) { if (!bbox) delete renderBbox; if (texBuffers) delete texBuffers; - Threading::switchThread(); - Verbose("Render finished"); } diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp index 96d5659..4d9efc9 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp @@ -70,7 +70,7 @@ void StaPipQBufferRenderer::init(RendererCore* t_core) { reinitVU1(); - TYRA_LOG("Renderer3DQBufferRenderer initialized"); + TYRA_LOG("StaPipQBufferRenderer initialized"); } void StaPipQBufferRenderer::reinitVU1() { diff --git a/samples/h4570/src/h4570.cpp b/samples/h4570/src/h4570.cpp index 11ff112..a92de55 100644 --- a/samples/h4570/src/h4570.cpp +++ b/samples/h4570/src/h4570.cpp @@ -104,6 +104,7 @@ void H4570::init() { } engine->audio.playSong(); + // engine->renderer.setFrameLimit(false); } u32 counter = 0; @@ -142,17 +143,19 @@ void H4570::loop() { // engine->renderer.renderer3D.usePipeline(&stapip); // { - // stapip.render(warrior, staOptions); - // // stapip.render(warrior2, staOptions); - // // stapip.render(warrior3, staOptions); - // // stapip.render(warrior4, staOptions); + // stapip.render(terrain, staOptions); // } engine->renderer.renderer3D.usePipeline(&dynpip); - { dynpip.render(warrior, dynOptions); } + { + dynpip.render(warrior, dynOptions); + // dynpip.render(warrior2, dynOptions); + // dynpip.render(warrior3, dynOptions); + // dynpip.render(warrior4, dynOptions); + } engine->renderer.renderer3D.usePipeline(&mcPip); - { mcPip.render(blocks, blocksCount, blocksTex, false); } + { mcPip.render(blocks, blocksCount, blocksTex); } } engine->renderer.endFrame(); }