finish of renderer refactor

This commit is contained in:
h4570
2022-07-25 21:00:33 +02:00
parent 0c63de8ac9
commit 237066bfd4
22 changed files with 176 additions and 94 deletions
@@ -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;
@@ -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();
@@ -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.
@@ -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
@@ -58,6 +58,9 @@ class BlockizerProgramsManager {
const McpipBlockData& getBlockData() const { return singleTexBlockData; }
void allocateOnUse();
void deallocateOnUse();
private:
McpipProgramsRepository repo;
Renderer* renderer;
@@ -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
@@ -47,6 +47,9 @@ class StaPipCore {
*/
void reinitVU1Programs();
void allocateOnUse() { qbufferRenderer.allocateOnUse(); }
void deallocateOnUse() { qbufferRenderer.deallocateOnUse(); }
private:
u32 maxVertCount;
RendererCore* rendererCore;
@@ -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;
@@ -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.
@@ -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<Texture*> textures;
@@ -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(); }
@@ -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();
}
@@ -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<u32>(packetSize));
core.allocateOnUse(static_cast<u32>(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();
@@ -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);
@@ -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);
}
@@ -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);
}
@@ -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();
+1
View File
@@ -19,6 +19,7 @@ Renderer3D::~Renderer3D() {}
void Renderer3D::usePipeline(Renderer3DPipeline* pipeline) {
if (currentPipeline != pipeline) {
if (currentPipeline) currentPipeline->onUseEnd();
currentPipeline = pipeline;
currentPipeline->onUse();
}
@@ -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);