diff --git a/ROADMAP.txt b/ROADMAP.txt index 53f5dd4..853fae4 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -21,6 +21,8 @@ - [General] Control generated id to avoid duplication. Maybe Just increment from 0? Add interface IIdentificable? +- [General] rsync is excluding folder like "objects" lol XD + - [DMA] Check if all chain transfers have end tag! - [General] Change libs of sample? (remove -lpng, -lz...), probably they are not required diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp index 39f42c7..c6d7065 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.hpp @@ -22,13 +22,8 @@ class DynPipColorBag { DynPipColorBag(); ~DynPipColorBag(); - /** Optional. Single color for all vertices. */ - Color* singleFrom; - Color* singleTo; - - /** Optional. Color per vertex. */ - Color* manyFrom; - Color* manyTo; + /** Mandatory */ + Color* single; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp index 6f1797f..3f0bfec 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.hpp @@ -29,6 +29,8 @@ class DynPipLightingBag { /** Mandatory. Directional lights */ PipelineDirLightsBag* dirLights; + + void freeNormals(); }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp index eb2d246..f08863b 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.hpp @@ -26,6 +26,8 @@ class DynPipTextureBag { /** Mandatory. Texture image. */ Texture* texture; + + void freeCoords(); }; } // namespace Tyra 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 4e60735..8f48a1e 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_core.hpp @@ -13,6 +13,8 @@ #include #include "./bag/dynpip_bag.hpp" #include "renderer/core/renderer_core.hpp" +#include "./dynpip_programs_repository.hpp" +#include "./dynpip_qbuffer_renderer.hpp" namespace Tyra { @@ -21,11 +23,18 @@ class DynPipCore { DynPipCore(); ~DynPipCore(); + DynPipProgramsRepository repository; + void init(RendererCore* t_core); /** Render 3D via "bags" */ void render(DynPipBag* data); + /** Get max vert count of VU1 qbuffer (for optimizations) */ + u32 getMaxVertCountByParams(const bool& isSingleColor, + const bool& isLightingEnabled, + const bool& isTextureEnabled); + /** * - Uploads standard VU1 programs. * - Sends static "Tyra Renderer3D" VU1 data. @@ -36,6 +45,7 @@ class DynPipCore { private: RendererCore* rendererCore; + DynPipQBufferRenderer qbufferRenderer; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp index 6b7a442..c53f9cf 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_programs_repository.hpp @@ -12,6 +12,7 @@ #include "debug/debug.hpp" #include "renderer/core/paths/path1/vu1_program.hpp" +#include "./bag/dynpip_bag.hpp" #include "./programs/dynpip_c_vu1_program.hpp" #include "./programs/dynpip_d_vu1_program.hpp" @@ -26,6 +27,9 @@ class DynPipProgramsRepository { ~DynPipProgramsRepository(); DynPipVU1Program* getProgram(const DynPipProgramName& name); + DynPipVU1Program* getProgramByParams(const bool& isLightingEnabled, + const bool& isTextureEnabled); + DynPipVU1Program* getProgramByBag(const DynPipBag* bag); private: DynPipCVU1Program color; diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp index 192fc7a..a7b0673 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.hpp @@ -29,9 +29,6 @@ class DynPipQBuffer { Vec4* stsFrom; Vec4* stsTo; - Vec4* colorsFrom; - Vec4* colorsTo; - Vec4* normalsFrom; Vec4* normalsTo; diff --git a/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer_renderer.hpp b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer_renderer.hpp new file mode 100644 index 0000000..da7d201 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer_renderer.hpp @@ -0,0 +1,68 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include + +namespace Tyra { + +class DynPipQBufferRenderer { + public: + DynPipQBufferRenderer(); + ~DynPipQBufferRenderer(); + + // void init(RendererCore* t_core); + + // 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 clearLastProgramName(); + + const u16& getBufferSize() { return bufferSize; } + + private: + // void sendStaticData() const; + // void setProgramsCache(); + // void uploadPrograms(); + // void setDoubleBuffer(); + + // void addBufferDataToPacket(DynPipVU1Program* program, DynPipQBuffer* + // buffer); void sendPacket(); + + // packet2_t* packets[2]; + // packet2_t* programsPacket; + // DynPipQBuffer buffers[2]; + // packet2_t* currentPacket; + // packet2_t* staticDataPacket; + // packet2_t* objectDataPacket; + + // RendererCore* rendererCore; + + // DynPipProgramName lastProgramName; + // Path1* path1; + // DynPipClipper clipper; + // DynPipProgramsRepository repository; + + u16 bufferSize; + // u8 context; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp b/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp index 5ba6f94..9c6ceb4 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp @@ -41,20 +41,27 @@ class DynamicPipeline : public Renderer3DPipeline { Vec4* colorsCache; void addVertices(DynamicMesh* mesh, MeshMaterial* material, DynPipBag* bag, - MeshFrame* frameFrom, MeshFrame* frameTo) const; + MeshFrame* frameFrom, MeshFrame* frameTo, + const u32& startIndex) const; PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options, M4x4* model) const; - DynPipColorBag* getColorBag(DynamicMesh* mesh, MeshMaterial* material, - MeshFrame* frameFrom, MeshFrame* frameTo) const; + DynPipColorBag* getColorBag(MeshMaterial* material) const; DynPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material, - MeshFrame* frameFrom, MeshFrame* frameTo); + MeshFrame* frameFrom, MeshFrame* frameTo, + const u32& count, const u32& startIndex); DynPipLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material, M4x4* model, MeshFrame* frameFrom, MeshFrame* frameTo, - const DynPipOptions* options) const; - void deallocDrawBags(DynPipBag* bag, MeshMaterial* material) const; + const DynPipOptions* options, + PipelineDirLightsBag* dirLightsBag, + const u32& count, + const u32& startIndex) const; void setLightingColorsCache(PipelineLightingOptions* lightingOptions); + void freeBuffer(DynPipBag* bag); + void setBuffersDefaultVars(DynPipBag* buffers, DynamicMesh* mesh, + PipelineInfoBag* infoBag); + void setBuffersColorBag(DynPipBag* buffers, DynPipColorBag* colorBag); }; } // 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 a3dcd96..ece1bad 100644 --- a/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp +++ b/engine/inc/renderer/3d/pipeline/dynamic/dynpip_options.hpp @@ -10,22 +10,14 @@ #pragma once -#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp" -#include "../shared/pipeline_lighting_options.hpp" +#include "renderer/3d/pipeline/shared/pipeline_options.hpp" namespace Tyra { -class DynPipOptions { +class DynPipOptions : public PipelineOptions { public: DynPipOptions() {} ~DynPipOptions() {} - - PipelineShadingType shadingType; - bool blendingEnabled; - bool antiAliasingEnabled; - - /** Optional */ - PipelineLightingOptions* lighting; }; } // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp new file mode 100644 index 0000000..000ccdd --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp @@ -0,0 +1,31 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp" +#include "../shared/pipeline_lighting_options.hpp" + +namespace Tyra { + +class PipelineOptions { + public: + PipelineOptions() {} + ~PipelineOptions() {} + + PipelineShadingType shadingType; + bool blendingEnabled; + bool antiAliasingEnabled; + + /** Optional */ + PipelineLightingOptions* lighting; +}; + +} // namespace Tyra diff --git a/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp b/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp index f1a4cf6..17108d6 100644 --- a/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp +++ b/engine/inc/renderer/3d/pipeline/static/stapip_options.hpp @@ -10,20 +10,15 @@ #pragma once -#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp" -#include "../shared/pipeline_lighting_options.hpp" +#include "renderer/3d/pipeline/shared/pipeline_options.hpp" namespace Tyra { -class StaPipOptions { +class StaPipOptions : public PipelineOptions { public: StaPipOptions() {} ~StaPipOptions() {} - PipelineShadingType shadingType; - bool blendingEnabled; - bool antiAliasingEnabled; - /** * @brief True -> disables "clip against each plane" algorithm. * Mandatory, default: false. @@ -33,9 +28,6 @@ class StaPipOptions { * for big 3D objects (or objects near camera eyes) */ bool noFullClipChecks; - - /** Optional */ - PipelineLightingOptions* lighting; }; } // namespace Tyra diff --git a/engine/inc/renderer/core/texture/texture_repository.hpp b/engine/inc/renderer/core/texture/texture_repository.hpp index 93aa353..6ab1638 100644 --- a/engine/inc/renderer/core/texture/texture_repository.hpp +++ b/engine/inc/renderer/core/texture/texture_repository.hpp @@ -36,31 +36,19 @@ class TextureRepository { * For 3D: MeshMaterial id. * For 2D: Sprite id. */ - Texture* getBySpriteOrMesh(const u32& t_id) { - for (u32 i = 0; i < textures.size(); i++) - if (textures[i]->isLinkedWith(t_id)) return textures[i]; - return nullptr; - } + Texture* getBySpriteOrMesh(const u32& t_id) const; /** * Returns single texture. * nullptr if not found. */ - Texture* getByTextureId(const u32& t_id) const { - for (u32 i = 0; i < textures.size(); i++) - if (t_id == textures[i]->getId()) return textures[i]; - return nullptr; - } + Texture* getByTextureId(const u32& t_id) const; /** * Returns index of link. * -1 if not found. */ - const s32 getIndexOf(const u32& t_texId) const { - for (u32 i = 0; i < textures.size(); i++) - if (textures[i]->getId() == t_texId) return i; - return -1; - } + const s32 getIndexOf(const u32& t_texId) const; // ---- // Setters diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp index 983054f..0578573 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_bag.cpp @@ -19,6 +19,8 @@ DynPipBag::DynPipBag() { color = nullptr; texture = nullptr; lighting = nullptr; + verticesFrom = nullptr; + verticesTo = nullptr; } DynPipBag::~DynPipBag() {} @@ -56,16 +58,8 @@ std::string DynPipBag::getPrint(const char* name) const { res << "Lighting present: " << (lighting != nullptr ? "Yes" : "No") << ", " << std::endl; res << "Model matrix: " << info->model->getPrint() << ", " << std::endl; - if (color->singleFrom) { - res << "Color from single: " << color->singleFrom->getPrint() << ", " - << std::endl; - res << "Color to single: " << color->singleTo->getPrint() << ", " - << std::endl; - } else { - res << "Color many from present: " - << (color->manyFrom != nullptr ? "Yes" : "No") << ", " << std::endl; - res << "Color many to present: " - << (color->manyTo != nullptr ? "Yes" : "No") << ", " << std::endl; + if (color->single) { + res << "Color single: " << color->single->getPrint() << ", " << std::endl; } if (texture) { res << "Texture coords from present: " diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp index d196bcd..e942ef6 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_color_bag.cpp @@ -12,12 +12,7 @@ namespace Tyra { -DynPipColorBag::DynPipColorBag() { - singleFrom = nullptr; - singleTo = nullptr; - manyFrom = nullptr; - manyTo = nullptr; -} +DynPipColorBag::DynPipColorBag() { single = nullptr; } DynPipColorBag::~DynPipColorBag() {} diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp index 8d6872c..c33b89f 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_lighting_bag.cpp @@ -21,4 +21,9 @@ DynPipLightingBag::DynPipLightingBag() { DynPipLightingBag::~DynPipLightingBag() {} +void DynPipLightingBag::freeNormals() { + if (normalsFrom) delete[] normalsFrom; + if (normalsTo) delete[] normalsTo; +} + } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp index ccfc152..a47a44b 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/bag/dynpip_texture_bag.cpp @@ -20,4 +20,9 @@ DynPipTextureBag::DynPipTextureBag() { DynPipTextureBag::~DynPipTextureBag() {} +void DynPipTextureBag::freeCoords() { + if (coordinatesFrom) delete[] coordinatesFrom; + if (coordinatesTo) delete[] coordinatesTo; +} + } // 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 c358534..8d80a60 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp @@ -22,6 +22,16 @@ void DynPipCore::init(RendererCore* t_core) { rendererCore = t_core; } void DynPipCore::reinitVU1Programs() {} -void DynPipCore::render(DynPipBag* bag) {} +u32 DynPipCore::getMaxVertCountByParams(const bool& isSingleColor, + const bool& isLightingEnabled, + const bool& isTextureEnabled) { + return repository.getProgramByParams(isLightingEnabled, isTextureEnabled) + ->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize()); +} + +void DynPipCore::render(DynPipBag* bag) { + // Zrobic bbox + // TODO: Potem wrzucic programy i obliczyc bufferSize w qbufferrenderer +} } // 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 d07db08..3150486 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,18 @@ DynPipProgramsRepository::DynPipProgramsRepository() {} DynPipProgramsRepository::~DynPipProgramsRepository() {} +DynPipVU1Program* DynPipProgramsRepository::getProgramByParams( + const bool& isLightingEnabled, const bool& isTextureEnabled) { + if (isLightingEnabled && isTextureEnabled) + return &textureDirLights; + else if (isLightingEnabled) + return &dirLights; + else if (isTextureEnabled) + return &textureColor; + else + return &color; +} + DynPipVU1Program* DynPipProgramsRepository::getProgram( const DynPipProgramName& name) { switch (name) { diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp index 779d4e9..86f9096 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer.cpp @@ -59,18 +59,6 @@ std::string DynPipQBuffer::getPrint(const char* name) const { res << i << ": " << stsTo[i].getPrint() << std::endl; } - if (bag->color->manyFrom != nullptr) { - res << "Colors from: " << std::endl; - for (u32 i = 0; i < size; i++) - res << i << ": " << colorsFrom[i].getPrint() << std::endl; - } - - if (bag->color->manyTo != nullptr) { - res << "Colors to: " << std::endl; - for (u32 i = 0; i < size; i++) - res << i << ": " << colorsTo[i].getPrint() << std::endl; - } - if (bag->lighting != nullptr) { res << "Normals from: " << std::endl; for (u32 i = 0; i < size; i++) { diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer_renderer.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer_renderer.cpp new file mode 100644 index 0000000..1ba92c7 --- /dev/null +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_qbuffer_renderer.cpp @@ -0,0 +1,19 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# 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_renderer.hpp" +#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h" + +namespace Tyra { + +DynPipQBufferRenderer::DynPipQBufferRenderer() {} +DynPipQBufferRenderer::~DynPipQBufferRenderer() {} + +} // namespace Tyra 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 d437daa..ce66464 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 @@ -56,14 +56,6 @@ void DynPipTDVU1Program::addProgramQBufferDataToPacket( packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->normalsTo, qbuffer->size, true); addr += qbuffer->size; - - // Add colors - if (qbuffer->bag->color->singleFrom == nullptr) { - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->colorsFrom, - qbuffer->size, true); - packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->colorsTo, - qbuffer->size, true); - } } } // 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 1744bcb..6a84017 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp @@ -12,72 +12,108 @@ namespace Tyra { -DynamicPipeline::DynamicPipeline() {} +DynamicPipeline::DynamicPipeline() { colorsCache = new Vec4[4]; } -DynamicPipeline::~DynamicPipeline() {} +DynamicPipeline::~DynamicPipeline() { delete[] colorsCache; } -void DynamicPipeline::init(RendererCore* t_core) {} +void DynamicPipeline::init(RendererCore* t_core) { rendererCore = t_core; } void DynamicPipeline::onUse() {} void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { auto model = mesh->getModelMatrix(); + auto* frameFrom = mesh->getFrame(mesh->getCurrentAnimationFrame()); + auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame()); + auto* infoBag = getInfoBag(mesh, options, &model); + PipelineDirLightsBag* dirLights = nullptr; - MeshFrame* frameFrom = mesh->getFramesCount() > 0 - ? mesh->getFrame(mesh->getCurrentAnimationFrame()) - : mesh->getFrame(0); + if (options && options->lighting) { + setLightingColorsCache(options->lighting); + dirLights = new PipelineDirLightsBag(true); + dirLights->setLightsManually(colorsCache, + options->lighting->directionalDirections); + } - MeshFrame* frameTo = mesh->getFramesCount() > 0 - ? mesh->getFrame(mesh->getNextAnimationFrame()) - : nullptr; + DynPipBag buffers[2]; + u8 context = 0; - // auto* infoBag = getInfoBag(mesh, options, &model); - - if (options && options->lighting) setLightingColorsCache(options->lighting); + setBuffersDefaultVars(buffers, mesh, infoBag); for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { auto* material = mesh->getMaterial(i); + auto partSize = core.getMaxVertCountByParams( + material->isSingleColorActivated(), options && options->lighting, + material->getTextureCoordFaces()); + u32 partsCount = + ceil(material->getFacesCount() / static_cast(partSize)); + auto* colorBag = getColorBag(material); + setBuffersColorBag(buffers, colorBag); - // 2x bufory[maxVertCount*2] -> pętla po mniejszych częściach i czestsze - // rendery + for (u32 j = 0; j < partsCount; j++) { + auto& buffer = buffers[context]; - // TODO: Double buffering in future - // auto maxVertCount = core->renderer3D.getMaxVertCountByParams( - // material->isSingleColorActivated(), material->getNormalFaces(), - // material->getTextureCoordFaces()); + freeBuffer(&buffer); + buffer.count = j == partsCount - 1 + ? material->getFacesCount() - j * partSize + : partSize; - DynPipBag bag; - addVertices(mesh, material, &bag, frameFrom, frameTo); - // bag.info = infoBag; - // bag.color = getColorBag(mesh, material, frameFrom, frameTo); - // bag.texture = getTextureBag(mesh, material, frameFrom, frameTo); - // bag.lighting = - // getLightingBag(mesh, material, &model, frameFrom, frameTo, options); + u32 startIndex = j * partSize; - core.render(&bag); + addVertices(mesh, material, &buffer, frameFrom, frameTo, startIndex); + buffer.texture = getTextureBag(mesh, material, frameFrom, frameTo, + buffer.count, startIndex); + buffer.lighting = + getLightingBag(mesh, material, &model, frameFrom, frameTo, options, + dirLights, buffer.count, startIndex); - // deallocDrawBags(&bag, material); + core.render(&buffer); + + context = !context; + } + + freeBuffer(&buffers[context]); + freeBuffer(&buffers[!context]); + + delete colorBag; } - // delete infoBag; // TODO + delete infoBag; } -void DynamicPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material, - DynPipBag* bag, MeshFrame* frameFrom, - MeshFrame* frameTo) const { - // bag->count = material->getFacesCount(); - // bag->vertices = new Vec4[bag->count]; +void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers, + DynamicMesh* mesh, + PipelineInfoBag* infoBag) { + for (int i = 0; i < 2; i++) { + buffers[i].info = infoBag; + buffers[i].interpolation = mesh->getAnimState().interpolation; + } +} - // for (u32 i = 0; i < bag->count; i++) { - // auto& face = material->getVertexFaces()[i]; - // if (frameTo == nullptr) { - // bag->vertices[i] = frameFrom->getVertices()[face]; - // } else { - // Vec4::setLerp(&bag->vertices[i], frameFrom->getVertices()[face], - // frameTo->getVertices()[face], - // mesh->getAnimState().interpolation); - // } - // } +void DynamicPipeline::setBuffersColorBag(DynPipBag* buffers, + DynPipColorBag* colorBag) { + for (int i = 0; i < 2; i++) { + buffers[i].color = colorBag; + } +} + +void DynamicPipeline::freeBuffer(DynPipBag* bag) { + if (bag->texture) { + bag->texture->freeCoords(); + delete bag->texture; + } + + if (bag->lighting) { + bag->lighting->freeNormals(); + delete bag->lighting; + } + + if (bag->verticesFrom) { + delete[] bag->verticesFrom; + } + + if (bag->verticesTo) { + delete[] bag->verticesTo; + } } PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh, @@ -100,99 +136,71 @@ PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh, return result; } -DynPipColorBag* DynamicPipeline::getColorBag(DynamicMesh* mesh, - MeshMaterial* material, - MeshFrame* frameFrom, - MeshFrame* frameTo) const { - // auto* result = new DynPipColorBag(); +void DynamicPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material, + DynPipBag* bag, MeshFrame* frameFrom, + MeshFrame* frameTo, + const u32& startIndex) const { + bag->verticesFrom = new Vec4[bag->count]; + bag->verticesTo = new Vec4[bag->count]; - // if (material->isSingleColorActivated()) { - // result->single = &material->singleColor; - // } else { - // result->many = new Color[material->getFacesCount()]; - - // for (u32 i = 0; i < material->getFacesCount(); i++) { - // auto& face = material->getColorFaces()[i]; - // if (frameTo == nullptr) { - // result->many[i] = frameFrom->getColors()[face]; - // } else { - // Vec4::setLerp( - // reinterpret_cast(&result->many[i]), - // reinterpret_cast(frameFrom->getColors()[face]), - // reinterpret_cast(frameTo->getColors()[face]), - // mesh->getAnimState().interpolation); - // } - // } - // } - - // return result; - return nullptr; // TODO + 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]; + } } -DynPipTextureBag* DynamicPipeline::getTextureBag(DynamicMesh* mesh, - MeshMaterial* material, - MeshFrame* frameFrom, - MeshFrame* frameTo) { - // if (!material->getTextureCoordFaces()) return nullptr; +DynPipColorBag* DynamicPipeline::getColorBag(MeshMaterial* material) const { + auto* result = new DynPipColorBag(); + result->single = &material->singleColor; + return result; +} - // auto* result = new DynPipTextureBag(); +DynPipTextureBag* DynamicPipeline::getTextureBag( + DynamicMesh* mesh, MeshMaterial* material, MeshFrame* frameFrom, + MeshFrame* frameTo, const u32& count, const u32& startIndex) { + if (!material->getTextureCoordFaces()) return nullptr; - // result->texture = - // rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); - // TYRA_ASSERT(result->texture, "Texture for material id: ", - // material->getId(), - // " was not found in texture repository!"); + auto* result = new DynPipTextureBag(); + result->texture = + rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); + TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), + "was not found in texture repository!"); - // result->coordinates = new Vec4[material->getFacesCount()]; + result->coordinatesFrom = new Vec4[count]; + result->coordinatesTo = new Vec4[count]; - // for (u32 i = 0; i < material->getFacesCount(); i++) { - // auto& face = material->getTextureCoordFaces()[i]; - // if (frameTo == nullptr) { - // result->coordinates[i] = frameFrom->getTextureCoords()[face]; - // } else { - // Vec4::setLerp(&result->coordinates[i], - // frameFrom->getTextureCoords()[face], - // frameTo->getTextureCoords()[face], - // mesh->getAnimState().interpolation); - // } - // } + 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]; + } - // return result; - return nullptr; // TODO + return result; } DynPipLightingBag* DynamicPipeline::getLightingBag( DynamicMesh* mesh, MeshMaterial* material, M4x4* model, - MeshFrame* frameFrom, MeshFrame* frameTo, - const DynPipOptions* options) const { - // if (!material->getNormalFaces() || options == nullptr || - // options->lighting == nullptr) - // return nullptr; + MeshFrame* frameFrom, MeshFrame* frameTo, const DynPipOptions* options, + PipelineDirLightsBag* dirLightsBag, const u32& count, + const u32& startIndex) const { + if (!material->getNormalFaces() || options == nullptr || + options->lighting == nullptr) + return nullptr; - // auto* result = new DynPipLightingBag(); - // auto* dirLightsBag = new PipelineDirLightsBag(true); - // result->dirLights = dirLightsBag; + auto* result = new DynPipLightingBag(); - // result->lightMatrix = model; + result->lightMatrix = model; + result->normalsFrom = new Vec4[count]; + result->normalsTo = new Vec4[count]; - // result->dirLights->setLightsManually( - // colorsCache, options->lighting->directionalDirections); + 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]; + } - // result->normals = new Vec4[material->getFacesCount()]; - - // for (u32 i = 0; i < material->getFacesCount(); i++) { - // auto& face = material->getNormalFaces()[i]; - // if (frameTo == nullptr) { - // result->normals[i] = frameFrom->getNormals()[face]; - // } else { - // Vec4::setLerp(&result->normals[i], frameFrom->getNormals()[face], - // frameTo->getNormals()[face], - // mesh->getAnimState().interpolation); - // } - // } - - // return result; - return nullptr; // TODO + return result; } void DynamicPipeline::setLightingColorsCache( @@ -204,29 +212,4 @@ void DynamicPipeline::setLightingColorsCache( colorsCache[3] = reinterpret_cast(*lightingOptions->ambientColor); } -void DynamicPipeline::deallocDrawBags(DynPipBag* bag, - MeshMaterial* material) const { - if (bag->color->manyFrom) { - delete[] bag->color->manyFrom; - delete[] bag->color->manyTo; - } - - if (bag->texture) { - delete[] bag->texture->coordinatesFrom; - delete[] bag->texture->coordinatesTo; - delete bag->texture; - } - - if (bag->lighting) { - delete[] bag->lighting->normalsFrom; - delete[] bag->lighting->normalsTo; - delete bag->lighting->dirLights; - delete bag->lighting; - } - - delete[] bag->verticesFrom; - delete[] bag->verticesTo; - delete bag->color; -} - } // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp index f54a603..2e069c1 100644 --- a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp @@ -144,7 +144,7 @@ StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh, result->texture = rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(), - " was not found in texture repository!"); + "was not found in texture repository!"); result->coordinates = new Vec4[material->getFacesCount()]; @@ -172,7 +172,8 @@ StaPipLightingBag* StaticPipeline::getLightingBag( return nullptr; auto* result = new StaPipLightingBag(); - auto* dirLightsBag = new PipelineDirLightsBag(true); + auto* dirLightsBag = new PipelineDirLightsBag(true); // TODO: 1 dir + // lights per obiekt, dealokowac recznie result->dirLights = dirLightsBag; result->lightMatrix = model; @@ -218,7 +219,7 @@ void StaticPipeline::deallocDrawBags(StaPipBag* bag, if (bag->lighting) { delete[] bag->lighting->normals; - delete bag->lighting->dirLights; + delete bag->lighting->dirLights; // TODO delete bag->lighting; } diff --git a/engine/src/renderer/core/texture/models/texture.cpp b/engine/src/renderer/core/texture/models/texture.cpp index 2898785..a4ab27b 100644 --- a/engine/src/renderer/core/texture/models/texture.cpp +++ b/engine/src/renderer/core/texture/models/texture.cpp @@ -162,10 +162,15 @@ std::string Texture::getPrint(const char* objectName) const { else if (wrap.horizontal == WRAP_CLAMP) wrapString = "WRAP_CLAMP"; - res << "id: " << id << ", "; - res << "name: " << name << ", "; - res << "core: " << core->getPrint() << ", "; - if (clut != nullptr) res << "clut: " << clut->getPrint() << ", "; + res << "id: " << id << ", " << std::endl; + res << "name: " << name << ", " << std::endl; + res << "core: " << core->getPrint() << ", " << std::endl; + if (clut != nullptr) res << "clut: " << clut->getPrint() << ", " << std::endl; + if (links.size()) { + for (size_t i = 0; i < links.size(); i++) { + res << "link " << i << " for id: " << links[i].id << ", " << std::endl; + } + } res << "wrap: " << wrapString << ")"; return res.str(); } diff --git a/engine/src/renderer/core/texture/texture_repository.cpp b/engine/src/renderer/core/texture/texture_repository.cpp index 18b5bfd..92952cc 100644 --- a/engine/src/renderer/core/texture/texture_repository.cpp +++ b/engine/src/renderer/core/texture/texture_repository.cpp @@ -22,9 +22,24 @@ TextureRepository::~TextureRepository() { } } -// ---- -// Methods -// ---- +Texture* TextureRepository::getBySpriteOrMesh(const u32& t_id) const { + for (u32 i = 0; i < textures.size(); i++) { + if (textures[i]->isLinkedWith(t_id)) return textures[i]; + } + return nullptr; +} + +Texture* TextureRepository::getByTextureId(const u32& t_id) const { + for (u32 i = 0; i < textures.size(); i++) + if (t_id == textures[i]->getId()) return textures[i]; + return nullptr; +} + +const s32 TextureRepository::getIndexOf(const u32& t_texId) const { + for (u32 i = 0; i < textures.size(); i++) + if (textures[i]->getId() == t_texId) return i; + return -1; +} Texture* TextureRepository::add(Texture* texture) { textures.push_back(texture); diff --git a/samples/h4570/inc/h4570.hpp b/samples/h4570/inc/h4570.hpp index de13f2d..6dc7d89 100644 --- a/samples/h4570/inc/h4570.hpp +++ b/samples/h4570/inc/h4570.hpp @@ -42,7 +42,9 @@ class H4570 : public Game { MinecraftPipeline mcPip; DynamicPipeline dynpip; StaticPipeline stapip; - StaPipOptions* renderOptions; + StaPipOptions* staOptions; + DynPipOptions* dynOptions; + Texture* warriorTex; Texture* blocksTex; u32 blocksCount; diff --git a/samples/h4570/src/h4570.cpp b/samples/h4570/src/h4570.cpp index 7d08daa..11ff112 100644 --- a/samples/h4570/src/h4570.cpp +++ b/samples/h4570/src/h4570.cpp @@ -18,7 +18,9 @@ H4570::H4570(Engine* t_engine) { engine = t_engine; } H4570::~H4570() {} DynamicMesh* getWarrior(Renderer* renderer); -StaPipOptions* getRenderingOptions(); +StaPipOptions* getStaPipOptions(); +DynPipOptions* getDynPipOptions(); +void setPipelineOptions(PipelineOptions* options); Sprite* get2DPicture(Renderer* renderer); void H4570::init() { @@ -34,8 +36,7 @@ void H4570::init() { engine->renderer.setClearScreenColor(Color(64.0F, 64.0F, 64.0F)); warrior = getWarrior(&engine->renderer); - - auto* warriorTex = engine->renderer.core.texture.repository.getBySpriteOrMesh( + warriorTex = engine->renderer.core.texture.repository.getBySpriteOrMesh( warrior->getMaterial(0)->getId()); warrior2 = new DynamicMesh(*warrior); @@ -56,7 +57,8 @@ void H4570::init() { warrior4->playAnimation(0, warrior4->getFramesCount() - 1); warrior4->setAnimSpeed(0.5F); - renderOptions = getRenderingOptions(); + staOptions = getStaPipOptions(); + dynOptions = getDynPipOptions(); cameraPosition = Vec4(0.0F, 0.0F, 20.0F); cameraLookAt = *warrior->getPosition(); @@ -140,14 +142,14 @@ void H4570::loop() { // engine->renderer.renderer3D.usePipeline(&stapip); // { - // stapip.render(warrior, renderOptions); - // // stapip.render(warrior2, renderOptions); - // // stapip.render(warrior3, renderOptions); - // // stapip.render(warrior4, renderOptions); + // stapip.render(warrior, staOptions); + // // stapip.render(warrior2, staOptions); + // // stapip.render(warrior3, staOptions); + // // stapip.render(warrior4, staOptions); // } engine->renderer.renderer3D.usePipeline(&dynpip); - { dynpip.render(warrior); } + { dynpip.render(warrior, dynOptions); } engine->renderer.renderer3D.usePipeline(&mcPip); { mcPip.render(blocks, blocksCount, blocksTex, false); } @@ -183,9 +185,19 @@ Sprite* get2DPicture(Renderer* renderer) { return sprite; } -StaPipOptions* getRenderingOptions() { +StaPipOptions* getStaPipOptions() { auto* options = new StaPipOptions(); + setPipelineOptions(options); + return options; +} +DynPipOptions* getDynPipOptions() { + auto* options = new DynPipOptions(); + setPipelineOptions(options); + return options; +} + +void setPipelineOptions(PipelineOptions* options) { auto* ambientColor = new Color(32.0F, 32.0F, 32.0F, 32.0F); auto* directionalColors = new Color[3]; for (int i = 0; i < 3; i++) directionalColors[i].set(0.0F, 0.0F, 0.0F, 1.0F); @@ -208,8 +220,6 @@ StaPipOptions* getRenderingOptions() { directionalDirections[1].set(1.0F, 0.0F, 0.0F); directionalColors[1].set(96.0F, 0.0F, 0.0F); - - return options; } } // namespace Tyra