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
@@ -20,9 +20,9 @@ namespace Tyra {
*/
class StaPipBagPackagesBBox {
public:
StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, const u32& t_facesCount,
const u32& t_maxVertCount);
StaPipBagPackagesBBox(Vec4* t_vertices, const u32& t_counts,
StaPipBagPackagesBBox(const Vec4* t_vertices, u32* t_faces,
const u32& t_facesCount, const u32& t_maxVertCount);
StaPipBagPackagesBBox(const Vec4* t_vertices, const u32& t_counts,
const u32& t_maxVertCount);
~StaPipBagPackagesBBox();
@@ -11,7 +11,7 @@
#pragma once
#include <tamtypes.h>
#include "core/bag/packaging/stapip_bag_packages_bbox.hpp"
#include "./bag/packaging/stapip_bag_packages_bbox.hpp"
#include "renderer/3d/mesh/mesh.hpp"
#include <memory>
#include <vector>
@@ -20,7 +20,7 @@ namespace Tyra {
struct StapipBagBBoxesCacheItem {
u32 vu1MaxVertCount;
u32 frameId;
u32 id;
std::unique_ptr<StaPipBagPackagesBBox> bboxes;
int framesLeftToDestroy;
};
@@ -35,12 +35,11 @@ class StapipBagBBoxesCacher {
void onFrameEnd();
StaPipBagPackagesBBox* getBBoxesByMesh(const MeshMaterialFrame* frame,
const u32& maxVertCount);
StaPipBagPackagesBBox* getBBoxes(const Vec4* vertices, const u32& count,
const u32& id, const u32& maxVertCount);
private:
StapipBagBBoxesCacheItem* getCache(const u32& maxVertCount,
const u32& frameId);
StapipBagBBoxesCacheItem* getCache(const u32& maxVertCount, const u32& id);
std::vector<StapipBagBBoxesCacheItem> storage;
};
@@ -16,6 +16,7 @@
#include "./bag/packaging/stapip_bag_package.hpp"
#include "./bag/packaging/stapip_bag_packager.hpp"
#include "./stapip_qbuffer_renderer.hpp"
#include "./stapip_bag_bboxes_cacher.hpp"
#include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp"
namespace Tyra {
@@ -27,9 +28,10 @@ class StaPipCore {
void init(RendererCore* t_core);
void onFrameEnd();
/** Render 3D via "bags" */
void render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
const u32& maxVertCount);
void render(StaPipBag* bag);
/** Get max vert count of VU1 qbuffer (for optimizations) */
u32 getMaxVertCountByParams(const bool& isSingleColor,
@@ -59,6 +61,7 @@ class StaPipCore {
u32 maxVertCount;
RendererCore* rendererCore;
StapipBagBBoxesCacher cacher;
void setMaxVertCount(const u32& count);
StaPipBagPackager packager;
@@ -17,7 +17,6 @@
#include "renderer/3d/mesh/static/static_mesh.hpp"
#include "./core/stapip_core.hpp"
#include "./stapip_options.hpp"
#include "./stapip_bag_bboxes_cacher.hpp"
namespace Tyra {
@@ -51,7 +50,6 @@ class StaticPipeline : public Renderer3DPipeline {
void render(const StaticMesh* mesh, const StaPipOptions* options);
private:
StapipBagBBoxesCacher cacher;
RendererCore* rendererCore;
Vec4* colorsCache;
@@ -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);
}