From 237066bfd4f4f31c8c92b4d5755622c78a48963f Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 25 Jul 2022 21:00:33 +0200 Subject: [PATCH] finish of renderer refactor --- ROADMAP.txt | 4 -- .../3d/pipeline/dynamic/core/dynpip_core.hpp | 7 ++- .../pipeline/dynamic/core/dynpip_renderer.hpp | 6 ++- .../3d/pipeline/dynamic/dynamic_pipeline.hpp | 4 +- .../pipeline/minecraft/minecraft_pipeline.hpp | 3 +- .../programs/mcpip_programs_manager.hpp | 3 ++ .../3d/pipeline/renderer_3d_pipeline.hpp | 3 +- .../3d/pipeline/static/core/stapip_core.hpp | 3 ++ .../static/core/stapip_qbuffer_renderer.hpp | 6 ++- .../3d/pipeline/static/static_pipeline.hpp | 4 +- .../core/texture/texture_repository.hpp | 16 +++--- .../3d/pipeline/dynamic/core/dynpip_core.cpp | 4 +- .../pipeline/dynamic/core/dynpip_renderer.cpp | 36 +++++++------ .../3d/pipeline/dynamic/dynamic_pipeline.cpp | 35 +++++++----- .../pipeline/minecraft/minecraft_pipeline.cpp | 16 ++++-- .../programs/mcpip_programs_manager.cpp | 15 ++++-- .../static/core/stapip_qbuffer_renderer.cpp | 54 ++++++++++--------- .../3d/pipeline/static/static_pipeline.cpp | 18 +++++-- engine/src/renderer/3d/renderer_3d.cpp | 1 + .../core/texture/texture_repository.cpp | 20 +++++++ samples/h4570/src/h4570.cpp | 8 +-- samples/wellinator/src/wellinator.cpp | 4 +- 22 files changed, 176 insertions(+), 94 deletions(-) diff --git a/ROADMAP.txt b/ROADMAP.txt index eac4da5..f960a19 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -1,10 +1,6 @@ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------ --- H4570 -- [Renderer] Allocate dynamic pipeline memory only in "onUse" (core,qbuffrenderer,pipeline..) -- [Texture] Unload texture -- [Texture] Dont load loaded texture by name - - [Loaders] Think about ".tyrobj" format - implement it (add multicolor support) - [Loaders] DFF loader as static Mesh loader - [Game] Update intellisense from docker 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 ffa127b..2e4dca0 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp @@ -25,7 +25,7 @@ class DynPipCore { DynPipProgramsRepository repository; - void init(RendererCore* t_core, const u32& t_packetSize); + void init(RendererCore* t_core); /** Force starting VU1 program instead of continueing */ void clear() { qbufferRenderer.clearLastProgramName(); } @@ -52,6 +52,11 @@ class DynPipCore { */ void reinitVU1Programs(); + void allocateOnUse(const u32& t_packetSize) { + qbufferRenderer.allocateOnUse(t_packetSize); + } + void deallocateOnUse() { qbufferRenderer.deallocateOnUse(); } + private: M4x4 mvp; RendererCore* rendererCore; 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 bb111c8..e5a33c6 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_renderer.hpp @@ -21,8 +21,7 @@ class DynPipRenderer { DynPipRenderer(); ~DynPipRenderer(); - void init(RendererCore* t_core, DynPipProgramsRepository* t_programRepo, - const u32& t_packetSize); + void init(RendererCore* t_core, DynPipProgramsRepository* t_programRepo); void reinitVU1(); @@ -35,6 +34,9 @@ class DynPipRenderer { const u16& getBufferSize() { return bufferSize; } + void allocateOnUse(const u32& t_packetSize); + void deallocateOnUse(); + private: void sendStaticData() const; void setProgramsCache(); diff --git a/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp b/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp index ae1d64d..b77a604 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp @@ -35,10 +35,12 @@ class DynamicPipeline : public Renderer3DPipeline { DynPipCore core; - void init(RendererCore* core); + void setRenderer(RendererCore* core); void onUse(); + void onUseEnd(); + /** * Render dynamic model. * This render() method is a bridge to core.render() method. diff --git a/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp b/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp index 275b83f..dded51d 100644 --- a/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp @@ -29,9 +29,10 @@ class MinecraftPipeline : public Renderer3DPipeline { MinecraftPipeline(); ~MinecraftPipeline(); - void init(RendererCore* core); + void setRenderer(RendererCore* core); void onUse(); + void onUseEnd(); /** * @brief Render voxels diff --git a/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp b/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp index 2864a46..6dac5c4 100644 --- a/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp +++ b/engine/inc/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.hpp @@ -58,6 +58,9 @@ class BlockizerProgramsManager { const McpipBlockData& getBlockData() const { return singleTexBlockData; } + void allocateOnUse(); + void deallocateOnUse(); + private: McpipProgramsRepository repo; Renderer* renderer; diff --git a/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp b/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp index 7b9f3a6..d447c71 100644 --- a/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/renderer_3d_pipeline.hpp @@ -19,8 +19,9 @@ class Renderer3DPipeline { Renderer3DPipeline() {} ~Renderer3DPipeline() {} - virtual void init(RendererCore* core) = 0; + virtual void setRenderer(RendererCore* core) = 0; virtual void onUse() = 0; + virtual void onUseEnd() = 0; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp index 0573b66..6c95766 100644 --- a/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_core.hpp @@ -47,6 +47,9 @@ class StaPipCore { */ void reinitVU1Programs(); + void allocateOnUse() { qbufferRenderer.allocateOnUse(); } + void deallocateOnUse() { qbufferRenderer.deallocateOnUse(); } + private: u32 maxVertCount; RendererCore* rendererCore; diff --git a/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp b/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp index 3b1201e..4db373e 100644 --- a/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp +++ b/engine/inc/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.hpp @@ -65,6 +65,9 @@ class StaPipQBufferRenderer { const u16& getBufferSize() { return bufferSize; } + void allocateOnUse(); + void deallocateOnUse(); + private: bool is1stDBufferFlushTime(); bool is2ndDBufferFlushTime(); @@ -74,6 +77,7 @@ class StaPipQBufferRenderer { void uploadPrograms(); void setDoubleBuffer(); u16 getQBufferIndex(StaPipQBuffer* buffer); + u16 qbuffersPacketSize; static const u16 buffersCount; @@ -88,7 +92,7 @@ class StaPipQBufferRenderer { packet2_t* programsPacket; packet2_t** packets; - StaPipVU1Program** programs; // dbuffer + StaPipVU1Program** dBufferPrograms; StaPipQBuffer** buffers; packet2_t* currentPacket; packet2_t* staticDataPacket; diff --git a/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp b/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp index b5c3d50..1131bc0 100644 --- a/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/static/static_pipeline.hpp @@ -35,10 +35,12 @@ class StaticPipeline : public Renderer3DPipeline { StaPipCore core; - void init(RendererCore* core); + void setRenderer(RendererCore* core); void onUse(); + void onUseEnd(); + /** * Render static model * This render() method is a bridge to core.render() method. diff --git a/engine/inc/renderer/core/texture/texture_repository.hpp b/engine/inc/renderer/core/texture/texture_repository.hpp index 0382337..e4a7ed5 100644 --- a/engine/inc/renderer/core/texture/texture_repository.hpp +++ b/engine/inc/renderer/core/texture/texture_repository.hpp @@ -95,19 +95,19 @@ class TextureRepository { * Remove texture from repository. * Texture is NOT destructed. */ - void removeByIndex(const u32& t_index) { - textures.erase(textures.begin() + t_index); - } + void removeByIndex(const u32& t_index); /** * Remove texture from repository. * Texture is NOT destructed. */ - const void removeById(const u32& t_texId) { - s32 index = getIndexOf(t_texId); - TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!"); - removeByIndex(index); - } + void removeById(const u32& t_texId); + + /** + * Remove texture from repository. + * Texture IS destructed. + */ + void free(const u32& t_texId); private: std::vector textures; 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 df289f3..5ee7f90 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp @@ -19,9 +19,9 @@ DynPipCore::DynPipCore() {} DynPipCore::~DynPipCore() {} -void DynPipCore::init(RendererCore* t_core, const u32& t_packetSize) { +void DynPipCore::init(RendererCore* t_core) { rendererCore = t_core; - qbufferRenderer.init(t_core, &repository, t_packetSize); + qbufferRenderer.init(t_core, &repository); } void DynPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); } 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 2ddc43f..760290f 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp @@ -18,23 +18,34 @@ 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); + programsPacket = nullptr; } DynPipRenderer::~DynPipRenderer() { - packet2_free(packets[0]); - packet2_free(packets[1]); - packet2_free(staticDataPacket); - packet2_free(objectDataPacket); - if (programsPacket) packet2_free(programsPacket); } +void DynPipRenderer::allocateOnUse(const u32& t_packetSize) { + staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + + for (u16 i = 0; i < 2; i++) + packets[i] = + packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + + sendStaticData(); +} + +void DynPipRenderer::deallocateOnUse() { + packet2_free(staticDataPacket); + packet2_free(objectDataPacket); + + for (u16 i = 0; i < 2; i++) packet2_free(packets[i]); +} + void DynPipRenderer::init(RendererCore* t_core, - DynPipProgramsRepository* t_programRepo, - const u32& t_packetSize) { + DynPipProgramsRepository* t_programRepo) { path1 = t_core->getPath1(); rendererCore = t_core; programsRepo = t_programRepo; @@ -42,12 +53,6 @@ void DynPipRenderer::init(RendererCore* t_core, dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); dma_channel_fast_waits(DMA_CHANNEL_VIF1); - packets[0] = - packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - - packets[1] = - packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - setProgramsCache(); reinitVU1(); @@ -56,7 +61,6 @@ void DynPipRenderer::init(RendererCore* t_core, } void DynPipRenderer::reinitVU1() { - sendStaticData(); uploadPrograms(); setDoubleBuffer(); } diff --git a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp index c40dc2e..1ec4de8 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp @@ -15,25 +15,36 @@ namespace Tyra { const u32 DynamicPipeline::buffersCount = 64; const u32 DynamicPipeline::halfBuffersCount = buffersCount / 2; -DynamicPipeline::DynamicPipeline() { - colorsCache = new Vec4[4]; - buffers = new DynPipBag[buffersCount]; -} +DynamicPipeline::DynamicPipeline() {} -DynamicPipeline::~DynamicPipeline() { - delete[] colorsCache; - for (u32 i = 0; i < buffersCount; i++) freeBuffer(&buffers[i]); - delete[] buffers; -} +DynamicPipeline::~DynamicPipeline() {} -void DynamicPipeline::init(RendererCore* t_core) { +void DynamicPipeline::setRenderer(RendererCore* t_core) { rendererCore = t_core; + + core.init(t_core); +} + +void DynamicPipeline::onUse() { + colorsCache = new Vec4[4]; + + buffers = new DynPipBag[buffersCount]; + auto packetSize = buffersCount * 5.1F; // 5.1 = packet2_get_qw_count / buffersCount - core.init(t_core, static_cast(packetSize)); + + core.allocateOnUse(static_cast(packetSize)); + core.reinitVU1Programs(); } -void DynamicPipeline::onUse() { core.reinitVU1Programs(); } +void DynamicPipeline::onUseEnd() { + delete[] colorsCache; + + for (u32 i = 0; i < buffersCount; i++) freeBuffer(&buffers[i]); + delete[] buffers; + + core.deallocateOnUse(); +} void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { auto model = mesh->getModelMatrix(); diff --git a/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp b/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp index 4cca364..49ab140 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/minecraft_pipeline.cpp @@ -17,8 +17,6 @@ namespace Tyra { MinecraftPipeline::MinecraftPipeline() { latestMode = UndefinedMcpipProgram; spamBuffersCount = 4; - spamBuffers = new McpipBlock**[spamBuffersCount]; - spamCounts = new u32[spamBuffersCount]; spammerIndex = 0; } @@ -26,11 +24,9 @@ MinecraftPipeline::~MinecraftPipeline() { if (bbox) { delete bbox; } - delete[] spamBuffers; - delete[] spamCounts; } -void MinecraftPipeline::init(RendererCore* core) { +void MinecraftPipeline::setRenderer(RendererCore* core) { rendererCore = core; manager.init(core); @@ -38,11 +34,21 @@ void MinecraftPipeline::init(RendererCore* core) { } void MinecraftPipeline::onUse() { + spamBuffers = new McpipBlock**[spamBuffersCount]; + spamCounts = new u32[spamBuffersCount]; + manager.allocateOnUse(); + manager.uploadVU1Programs(); changeMode(McPipCull, true); } +void MinecraftPipeline::onUseEnd() { + delete[] spamBuffers; + delete[] spamCounts; + manager.deallocateOnUse(); +} + void MinecraftPipeline::initBBox() { const auto& block = manager.getBlockData(); bbox = new RenderBBox(block.vertices, block.count); diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp index 7e6c95b..69e5632 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp @@ -16,16 +16,23 @@ BlockizerProgramsManager::BlockizerProgramsManager() { lastProgramName = UndefinedMcpipProgram; context = 0; vu1BlockData = BlockNotUploaded; - dynamicPackets[0] = packet2_create(300, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - dynamicPackets[1] = packet2_create(300, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - staticPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + setProgramsCache(); } -BlockizerProgramsManager::~BlockizerProgramsManager() { +void BlockizerProgramsManager::allocateOnUse() { + dynamicPackets[0] = packet2_create(300, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + dynamicPackets[1] = packet2_create(300, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + staticPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); +} + +void BlockizerProgramsManager::deallocateOnUse() { packet2_free(dynamicPackets[0]); packet2_free(dynamicPackets[1]); packet2_free(staticPacket); +} + +BlockizerProgramsManager::~BlockizerProgramsManager() { packet2_free(programsPacket); } 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 10e4a01..4c9eb45 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 @@ -42,38 +42,43 @@ StaPipQBufferRenderer::StaPipQBufferRenderer() { context = 0; lastProgramName = StaPipUndefinedProgram; - u32 qbuffersPacketSize = 4 * buffersCount; - - packets = new packet2_t*[buffersCount]; - packets[0] = - packet2_create(qbuffersPacketSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - packets[1] = - packet2_create(qbuffersPacketSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); + qbuffersPacketSize = 4 * buffersCount; + programsPacket = nullptr; +} +void StaPipQBufferRenderer::allocateOnUse() { staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); - programsPacket = nullptr; + packets = new packet2_t*[buffersCount]; + for (u16 i = 0; i < 2; i++) + packets[i] = + packet2_create(qbuffersPacketSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); buffers = new StaPipQBuffer*[buffersCount]; - programs = new StaPipVU1Program*[buffersCount]; for (u16 i = 0; i < buffersCount; i++) { buffers[i] = new StaPipQBuffer(); } + + dBufferPrograms = new StaPipVU1Program*[buffersCount]; + + sendStaticData(); } -StaPipQBufferRenderer::~StaPipQBufferRenderer() { + +void StaPipQBufferRenderer::deallocateOnUse() { packet2_free(staticDataPacket); packet2_free(objectDataPacket); - packet2_free(packets[0]); - packet2_free(packets[1]); - - for (u16 i = 0; i < buffersCount; i++) { - delete buffers[i]; - } + for (u16 i = 0; i < 2; i++) packet2_free(packets[i]); delete[] packets; + + for (u16 i = 0; i < buffersCount; i++) delete buffers[i]; delete[] buffers; + delete[] dBufferPrograms; +} + +StaPipQBufferRenderer::~StaPipQBufferRenderer() { if (programsPacket) packet2_free(programsPacket); } @@ -93,7 +98,6 @@ void StaPipQBufferRenderer::init(RendererCore* t_core) { } void StaPipQBufferRenderer::reinitVU1() { - sendStaticData(); uploadPrograms(); setDoubleBuffer(); } @@ -239,7 +243,7 @@ void StaPipQBufferRenderer::cull(StaPipQBuffer* buffer) { return; } - programs[getQBufferIndex(buffer)] = getCullProgramByBag(buffer->bag); + dBufferPrograms[getQBufferIndex(buffer)] = getCullProgramByBag(buffer->bag); auto is1stDBuffer = is1stDBufferFlushTime(); auto is2ndDBuffer = is2ndDBufferFlushTime(); @@ -256,7 +260,7 @@ void StaPipQBufferRenderer::clip(StaPipQBuffer* buffer) { return; } - programs[getQBufferIndex(buffer)] = getAsIsProgramByBag(buffer->bag); + dBufferPrograms[getQBufferIndex(buffer)] = getAsIsProgramByBag(buffer->bag); clipper.clip(buffer); @@ -282,13 +286,13 @@ void StaPipQBufferRenderer::addBufferDataToPacket(StaPipQBuffer** buffers, for (u32 i = 0; i < count; i++) { if (!buffers[i]->any()) continue; - programs[i]->addBufferDataToPacket(currentPacket, buffers[i], - &rendererCore->gs.prim); + dBufferPrograms[i]->addBufferDataToPacket(currentPacket, buffers[i], + &rendererCore->gs.prim); - if (lastProgramName != programs[i]->getName()) { - packet2_utils_vu_add_start_program(currentPacket, - programs[i]->getDestinationAddress()); - lastProgramName = programs[i]->getName(); + if (lastProgramName != dBufferPrograms[i]->getName()) { + packet2_utils_vu_add_start_program( + currentPacket, dBufferPrograms[i]->getDestinationAddress()); + lastProgramName = dBufferPrograms[i]->getName(); } else { packet2_utils_vu_add_continue_program(currentPacket); } diff --git a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp index c1fbf7c..34b93e6 100644 --- a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp @@ -13,16 +13,26 @@ namespace Tyra { -StaticPipeline::StaticPipeline() { colorsCache = new Vec4[4]; } +StaticPipeline::StaticPipeline() {} -StaticPipeline::~StaticPipeline() { delete[] colorsCache; } +StaticPipeline::~StaticPipeline() {} -void StaticPipeline::init(RendererCore* t_core) { +void StaticPipeline::setRenderer(RendererCore* t_core) { rendererCore = t_core; core.init(t_core); } -void StaticPipeline::onUse() { core.reinitVU1Programs(); } +void StaticPipeline::onUse() { + colorsCache = new Vec4[4]; + core.allocateOnUse(); + core.reinitVU1Programs(); +} + +void StaticPipeline::onUseEnd() { + delete[] colorsCache; + + core.deallocateOnUse(); +} void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) { auto model = mesh->getModelMatrix(); diff --git a/engine/src/renderer/3d/renderer_3d.cpp b/engine/src/renderer/3d/renderer_3d.cpp index f9352f7..2ffb4b8 100644 --- a/engine/src/renderer/3d/renderer_3d.cpp +++ b/engine/src/renderer/3d/renderer_3d.cpp @@ -19,6 +19,7 @@ Renderer3D::~Renderer3D() {} void Renderer3D::usePipeline(Renderer3DPipeline* pipeline) { if (currentPipeline != pipeline) { + if (currentPipeline) currentPipeline->onUseEnd(); currentPipeline = pipeline; currentPipeline->onUse(); } diff --git a/engine/src/renderer/core/texture/texture_repository.cpp b/engine/src/renderer/core/texture/texture_repository.cpp index 63ec8a1..06539e7 100644 --- a/engine/src/renderer/core/texture/texture_repository.cpp +++ b/engine/src/renderer/core/texture/texture_repository.cpp @@ -46,6 +46,26 @@ Texture* TextureRepository::add(Texture* texture) { return texture; } +void TextureRepository::removeByIndex(const u32& t_index) { + textures.erase(textures.begin() + t_index); +} + +void TextureRepository::removeById(const u32& t_texId) { + s32 index = getIndexOf(t_texId); + TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!"); + removeByIndex(index); +} + +void TextureRepository::free(const u32& t_texId) { + s32 index = getIndexOf(t_texId); + auto* tex = textures[index]; + + TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!"); + removeByIndex(index); + + delete tex; +} + Texture* TextureRepository::add(const char* fullpath) { TextureLoader& loader = texLoaderSelector.getLoaderByFileName(fullpath); diff --git a/samples/h4570/src/h4570.cpp b/samples/h4570/src/h4570.cpp index 5cbce43..f89589a 100644 --- a/samples/h4570/src/h4570.cpp +++ b/samples/h4570/src/h4570.cpp @@ -76,9 +76,9 @@ void H4570::init() { blocksTex = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("blocks.png")); - mcPip.init(&engine->renderer.core); - dynpip.init(&engine->renderer.core); - stapip.init(&engine->renderer.core); + mcPip.setRenderer(&engine->renderer.core); + dynpip.setRenderer(&engine->renderer.core); + stapip.setRenderer(&engine->renderer.core); picture = get2DPicture(&engine->renderer); @@ -121,7 +121,7 @@ u32 counter = 0; void H4570::loop() { if (counter++ > 30) { - TYRA_LOG(engine->info.getFps()); + // TYRA_LOG(engine->info.getFps()); counter = 0; } diff --git a/samples/wellinator/src/wellinator.cpp b/samples/wellinator/src/wellinator.cpp index 3658058..4673a8e 100644 --- a/samples/wellinator/src/wellinator.cpp +++ b/samples/wellinator/src/wellinator.cpp @@ -41,8 +41,8 @@ void Wellinator::init() { blocksTex = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("blocks.png")); - mcPip.init(&engine->renderer.core); - stapip.init(&engine->renderer.core); + mcPip.setRenderer(&engine->renderer.core); + stapip.setRenderer(&engine->renderer.core); picture = get2DPicture(&engine->renderer);