finished tutorial 9

This commit is contained in:
h4570
2022-08-24 19:27:16 +02:00
parent 5c375dd24f
commit a21bcee671
11 changed files with 130 additions and 41 deletions
@@ -18,7 +18,8 @@
namespace Tyra {
StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces,
StaPipBagPackagesBBox::StaPipBagPackagesBBox(const Vec4* t_vertices,
u32* t_faces,
const u32& t_facesCount,
const u32& t_maxVertCount) {
u32 splitPartSize = t_maxVertCount / 3;
@@ -35,7 +36,7 @@ StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces,
mainBBox = new RenderBBox(*bboxParts, 0, partsCount);
}
StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices,
StaPipBagPackagesBBox::StaPipBagPackagesBBox(const Vec4* t_vertices,
const u32& t_count,
const u32& t_maxVertCount) {
u32 splitPartSize = t_maxVertCount / 3;
@@ -8,7 +8,7 @@
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "renderer/3d/pipeline/static/stapip_bag_bboxes_cacher.hpp"
#include "renderer/3d/pipeline/static/core/stapip_bag_bboxes_cacher.hpp"
#include <algorithm>
namespace Tyra {
@@ -31,29 +31,30 @@ void StapipBagBBoxesCacher::onFrameEnd() {
storage.end());
}
StaPipBagPackagesBBox* StapipBagBBoxesCacher::getBBoxesByMesh(
const MeshMaterialFrame* frame, const u32& maxVertCount) {
auto* cache = getCache(maxVertCount, frame->id);
StaPipBagPackagesBBox* StapipBagBBoxesCacher::getBBoxes(
const Vec4* vertices, const u32& count, const u32& id,
const u32& maxVertCount) {
auto* cache = getCache(maxVertCount, id);
if (cache) {
cache->framesLeftToDestroy = cacheFramesCount * cacheSecondsCount;
return cache->bboxes.get();
}
auto bboxes = std::make_unique<StaPipBagPackagesBBox>(
frame->vertices, frame->count, maxVertCount);
auto bboxes =
std::make_unique<StaPipBagPackagesBBox>(vertices, count, maxVertCount);
storage.push_back(
StapipBagBBoxesCacheItem{maxVertCount, frame->id, std::move(bboxes),
StapipBagBBoxesCacheItem{maxVertCount, id, std::move(bboxes),
cacheFramesCount * cacheSecondsCount});
return storage.back().bboxes.get();
}
StapipBagBBoxesCacheItem* StapipBagBBoxesCacher::getCache(
const u32& maxVertCount, const u32& frameId) {
const u32& maxVertCount, const u32& id) {
for (auto& item : storage) {
if (item.vu1MaxVertCount == maxVertCount && item.frameId == frameId) {
if (item.vu1MaxVertCount == maxVertCount && item.id == id) {
return &item;
}
}
@@ -57,6 +57,8 @@ void StaPipCore::setLod() {
lod.k = 0.0F;
}
void StaPipCore::onFrameEnd() { cacher.onFrameEnd(); }
void StaPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); }
u32 StaPipCore::getMaxVertCountByBag(const StaPipBag* bag) {
@@ -72,8 +74,7 @@ u32 StaPipCore::getMaxVertCountByParams(const bool& isSingleColor,
->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize());
}
void StaPipCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
const u32& maxVertCount) {
void StaPipCore::render(StaPipBag* bag) {
if (bag->count <= 0) return;
bool frustumCull =
@@ -106,6 +107,14 @@ void StaPipCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
TYRA_ASSERT(!(!frustumCull && bag->info->fullClipChecks == true),
"Full clip checks are not supported with frustum culling = off!");
u32 maxVertCount = getMaxVertCountByBag(bag);
StaPipBagPackagesBBox* bbox = nullptr;
if (bag->info->frustumCulling == PipelineInfoBagFrustumCulling_Precise) {
bbox = cacher.getBBoxes(bag->vertices, bag->count,
reinterpret_cast<u32>(bag->vertices), maxVertCount);
}
setMaxVertCount(maxVertCount);
CoreBBoxFrustum frustumCheck = OUTSIDE_FRUSTUM;
@@ -39,7 +39,7 @@ void StaticPipeline::onUseEnd() {
core.deallocateOnUse();
}
void StaticPipeline::onFrameEnd() { cacher.onFrameEnd(); }
void StaticPipeline::onFrameEnd() { core.onFrameEnd(); }
void StaticPipeline::render(const StaticMesh* mesh) { render(mesh, nullptr); }
@@ -93,14 +93,7 @@ void StaticPipeline::render(const StaticMesh* mesh,
bag.lighting =
getLightingBag(materialFrame, dirLightsBag.get(), &model, options);
u32 maxVertCount = core.getMaxVertCountByBag(&bag);
StaPipBagPackagesBBox* bbox = nullptr;
if (bag.info->frustumCulling == PipelineInfoBagFrustumCulling_Precise) {
bbox = cacher.getBBoxesByMesh(materialFrame, maxVertCount);
}
core.render(&bag, bbox, maxVertCount);
core.render(&bag);
deallocDrawBags(&bag, material);
}