finished tutorial 9
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
|
||||||
- [Tutorials] 9.
|
|
||||||
|
|
||||||
- [General] Check all left TODOs -> Github issues
|
- [General] Check all left TODOs -> Github issues
|
||||||
- [General] Readme Credits: clipping, obj loader
|
- [General] Readme Credits: clipping, obj loader
|
||||||
- [Video] How to setup environment
|
- [Video] How to setup environment
|
||||||
|
|||||||
+3
-3
@@ -20,9 +20,9 @@ namespace Tyra {
|
|||||||
*/
|
*/
|
||||||
class StaPipBagPackagesBBox {
|
class StaPipBagPackagesBBox {
|
||||||
public:
|
public:
|
||||||
StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces, const u32& t_facesCount,
|
StaPipBagPackagesBBox(const Vec4* t_vertices, u32* t_faces,
|
||||||
const u32& t_maxVertCount);
|
const u32& t_facesCount, const u32& t_maxVertCount);
|
||||||
StaPipBagPackagesBBox(Vec4* t_vertices, const u32& t_counts,
|
StaPipBagPackagesBBox(const Vec4* t_vertices, const u32& t_counts,
|
||||||
const u32& t_maxVertCount);
|
const u32& t_maxVertCount);
|
||||||
~StaPipBagPackagesBBox();
|
~StaPipBagPackagesBBox();
|
||||||
|
|
||||||
|
|||||||
+5
-6
@@ -11,7 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tamtypes.h>
|
#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 "renderer/3d/mesh/mesh.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -20,7 +20,7 @@ namespace Tyra {
|
|||||||
|
|
||||||
struct StapipBagBBoxesCacheItem {
|
struct StapipBagBBoxesCacheItem {
|
||||||
u32 vu1MaxVertCount;
|
u32 vu1MaxVertCount;
|
||||||
u32 frameId;
|
u32 id;
|
||||||
std::unique_ptr<StaPipBagPackagesBBox> bboxes;
|
std::unique_ptr<StaPipBagPackagesBBox> bboxes;
|
||||||
int framesLeftToDestroy;
|
int framesLeftToDestroy;
|
||||||
};
|
};
|
||||||
@@ -35,12 +35,11 @@ class StapipBagBBoxesCacher {
|
|||||||
|
|
||||||
void onFrameEnd();
|
void onFrameEnd();
|
||||||
|
|
||||||
StaPipBagPackagesBBox* getBBoxesByMesh(const MeshMaterialFrame* frame,
|
StaPipBagPackagesBBox* getBBoxes(const Vec4* vertices, const u32& count,
|
||||||
const u32& maxVertCount);
|
const u32& id, const u32& maxVertCount);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StapipBagBBoxesCacheItem* getCache(const u32& maxVertCount,
|
StapipBagBBoxesCacheItem* getCache(const u32& maxVertCount, const u32& id);
|
||||||
const u32& frameId);
|
|
||||||
|
|
||||||
std::vector<StapipBagBBoxesCacheItem> storage;
|
std::vector<StapipBagBBoxesCacheItem> storage;
|
||||||
};
|
};
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "./bag/packaging/stapip_bag_package.hpp"
|
#include "./bag/packaging/stapip_bag_package.hpp"
|
||||||
#include "./bag/packaging/stapip_bag_packager.hpp"
|
#include "./bag/packaging/stapip_bag_packager.hpp"
|
||||||
#include "./stapip_qbuffer_renderer.hpp"
|
#include "./stapip_qbuffer_renderer.hpp"
|
||||||
|
#include "./stapip_bag_bboxes_cacher.hpp"
|
||||||
#include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp"
|
#include "renderer/3d/pipeline/shared/pipeline_frustum_culling.hpp"
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
@@ -27,9 +28,10 @@ class StaPipCore {
|
|||||||
|
|
||||||
void init(RendererCore* t_core);
|
void init(RendererCore* t_core);
|
||||||
|
|
||||||
|
void onFrameEnd();
|
||||||
|
|
||||||
/** Render 3D via "bags" */
|
/** Render 3D via "bags" */
|
||||||
void render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
|
void render(StaPipBag* bag);
|
||||||
const u32& maxVertCount);
|
|
||||||
|
|
||||||
/** Get max vert count of VU1 qbuffer (for optimizations) */
|
/** Get max vert count of VU1 qbuffer (for optimizations) */
|
||||||
u32 getMaxVertCountByParams(const bool& isSingleColor,
|
u32 getMaxVertCountByParams(const bool& isSingleColor,
|
||||||
@@ -59,6 +61,7 @@ class StaPipCore {
|
|||||||
|
|
||||||
u32 maxVertCount;
|
u32 maxVertCount;
|
||||||
RendererCore* rendererCore;
|
RendererCore* rendererCore;
|
||||||
|
StapipBagBBoxesCacher cacher;
|
||||||
|
|
||||||
void setMaxVertCount(const u32& count);
|
void setMaxVertCount(const u32& count);
|
||||||
StaPipBagPackager packager;
|
StaPipBagPackager packager;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include "renderer/3d/mesh/static/static_mesh.hpp"
|
#include "renderer/3d/mesh/static/static_mesh.hpp"
|
||||||
#include "./core/stapip_core.hpp"
|
#include "./core/stapip_core.hpp"
|
||||||
#include "./stapip_options.hpp"
|
#include "./stapip_options.hpp"
|
||||||
#include "./stapip_bag_bboxes_cacher.hpp"
|
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
@@ -51,7 +50,6 @@ class StaticPipeline : public Renderer3DPipeline {
|
|||||||
void render(const StaticMesh* mesh, const StaPipOptions* options);
|
void render(const StaticMesh* mesh, const StaPipOptions* options);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StapipBagBBoxesCacher cacher;
|
|
||||||
RendererCore* rendererCore;
|
RendererCore* rendererCore;
|
||||||
Vec4* colorsCache;
|
Vec4* colorsCache;
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
namespace Tyra {
|
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_facesCount,
|
||||||
const u32& t_maxVertCount) {
|
const u32& t_maxVertCount) {
|
||||||
u32 splitPartSize = t_maxVertCount / 3;
|
u32 splitPartSize = t_maxVertCount / 3;
|
||||||
@@ -35,7 +36,7 @@ StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices, u32* t_faces,
|
|||||||
mainBBox = new RenderBBox(*bboxParts, 0, partsCount);
|
mainBBox = new RenderBBox(*bboxParts, 0, partsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
StaPipBagPackagesBBox::StaPipBagPackagesBBox(Vec4* t_vertices,
|
StaPipBagPackagesBBox::StaPipBagPackagesBBox(const Vec4* t_vertices,
|
||||||
const u32& t_count,
|
const u32& t_count,
|
||||||
const u32& t_maxVertCount) {
|
const u32& t_maxVertCount) {
|
||||||
u32 splitPartSize = t_maxVertCount / 3;
|
u32 splitPartSize = t_maxVertCount / 3;
|
||||||
|
|||||||
+10
-9
@@ -8,7 +8,7 @@
|
|||||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
# 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>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
@@ -31,29 +31,30 @@ void StapipBagBBoxesCacher::onFrameEnd() {
|
|||||||
storage.end());
|
storage.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
StaPipBagPackagesBBox* StapipBagBBoxesCacher::getBBoxesByMesh(
|
StaPipBagPackagesBBox* StapipBagBBoxesCacher::getBBoxes(
|
||||||
const MeshMaterialFrame* frame, const u32& maxVertCount) {
|
const Vec4* vertices, const u32& count, const u32& id,
|
||||||
auto* cache = getCache(maxVertCount, frame->id);
|
const u32& maxVertCount) {
|
||||||
|
auto* cache = getCache(maxVertCount, id);
|
||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
cache->framesLeftToDestroy = cacheFramesCount * cacheSecondsCount;
|
cache->framesLeftToDestroy = cacheFramesCount * cacheSecondsCount;
|
||||||
return cache->bboxes.get();
|
return cache->bboxes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bboxes = std::make_unique<StaPipBagPackagesBBox>(
|
auto bboxes =
|
||||||
frame->vertices, frame->count, maxVertCount);
|
std::make_unique<StaPipBagPackagesBBox>(vertices, count, maxVertCount);
|
||||||
|
|
||||||
storage.push_back(
|
storage.push_back(
|
||||||
StapipBagBBoxesCacheItem{maxVertCount, frame->id, std::move(bboxes),
|
StapipBagBBoxesCacheItem{maxVertCount, id, std::move(bboxes),
|
||||||
cacheFramesCount * cacheSecondsCount});
|
cacheFramesCount * cacheSecondsCount});
|
||||||
|
|
||||||
return storage.back().bboxes.get();
|
return storage.back().bboxes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
StapipBagBBoxesCacheItem* StapipBagBBoxesCacher::getCache(
|
StapipBagBBoxesCacheItem* StapipBagBBoxesCacher::getCache(
|
||||||
const u32& maxVertCount, const u32& frameId) {
|
const u32& maxVertCount, const u32& id) {
|
||||||
for (auto& item : storage) {
|
for (auto& item : storage) {
|
||||||
if (item.vu1MaxVertCount == maxVertCount && item.frameId == frameId) {
|
if (item.vu1MaxVertCount == maxVertCount && item.id == id) {
|
||||||
return &item;
|
return &item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,8 @@ void StaPipCore::setLod() {
|
|||||||
lod.k = 0.0F;
|
lod.k = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StaPipCore::onFrameEnd() { cacher.onFrameEnd(); }
|
||||||
|
|
||||||
void StaPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); }
|
void StaPipCore::reinitVU1Programs() { qbufferRenderer.reinitVU1(); }
|
||||||
|
|
||||||
u32 StaPipCore::getMaxVertCountByBag(const StaPipBag* bag) {
|
u32 StaPipCore::getMaxVertCountByBag(const StaPipBag* bag) {
|
||||||
@@ -72,8 +74,7 @@ u32 StaPipCore::getMaxVertCountByParams(const bool& isSingleColor,
|
|||||||
->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize());
|
->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaPipCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
|
void StaPipCore::render(StaPipBag* bag) {
|
||||||
const u32& maxVertCount) {
|
|
||||||
if (bag->count <= 0) return;
|
if (bag->count <= 0) return;
|
||||||
|
|
||||||
bool frustumCull =
|
bool frustumCull =
|
||||||
@@ -106,6 +107,14 @@ void StaPipCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
|
|||||||
TYRA_ASSERT(!(!frustumCull && bag->info->fullClipChecks == true),
|
TYRA_ASSERT(!(!frustumCull && bag->info->fullClipChecks == true),
|
||||||
"Full clip checks are not supported with frustum culling = off!");
|
"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);
|
setMaxVertCount(maxVertCount);
|
||||||
|
|
||||||
CoreBBoxFrustum frustumCheck = OUTSIDE_FRUSTUM;
|
CoreBBoxFrustum frustumCheck = OUTSIDE_FRUSTUM;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void StaticPipeline::onUseEnd() {
|
|||||||
core.deallocateOnUse();
|
core.deallocateOnUse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticPipeline::onFrameEnd() { cacher.onFrameEnd(); }
|
void StaticPipeline::onFrameEnd() { core.onFrameEnd(); }
|
||||||
|
|
||||||
void StaticPipeline::render(const StaticMesh* mesh) { render(mesh, nullptr); }
|
void StaticPipeline::render(const StaticMesh* mesh) { render(mesh, nullptr); }
|
||||||
|
|
||||||
@@ -93,14 +93,7 @@ void StaticPipeline::render(const StaticMesh* mesh,
|
|||||||
bag.lighting =
|
bag.lighting =
|
||||||
getLightingBag(materialFrame, dirLightsBag.get(), &model, options);
|
getLightingBag(materialFrame, dirLightsBag.get(), &model, options);
|
||||||
|
|
||||||
u32 maxVertCount = core.getMaxVertCountByBag(&bag);
|
core.render(&bag);
|
||||||
|
|
||||||
StaPipBagPackagesBBox* bbox = nullptr;
|
|
||||||
if (bag.info->frustumCulling == PipelineInfoBagFrustumCulling_Precise) {
|
|
||||||
bbox = cacher.getBBoxesByMesh(materialFrame, maxVertCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
core.render(&bag, bbox, maxVertCount);
|
|
||||||
|
|
||||||
deallocDrawBags(&bag, material);
|
deallocDrawBags(&bag, material);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tyra>
|
#include <tyra>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
@@ -23,7 +24,22 @@ class Tutorial09 : public Game {
|
|||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setDrawData();
|
||||||
|
void loadBags();
|
||||||
|
|
||||||
Engine* engine;
|
Engine* engine;
|
||||||
|
|
||||||
|
StaticPipeline stapip;
|
||||||
|
|
||||||
|
Vec4 cameraPosition, cameraLookAt;
|
||||||
|
M4x4 translation, rotation, scale, model;
|
||||||
|
|
||||||
|
std::array<Vec4, 3> vertices;
|
||||||
|
std::array<Color, 3> colors;
|
||||||
|
|
||||||
|
std::unique_ptr<StaPipBag> bag;
|
||||||
|
std::unique_ptr<StaPipInfoBag> infoBag;
|
||||||
|
std::unique_ptr<StaPipColorBag> colorBag;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Tyra
|
} // namespace Tyra
|
||||||
|
|||||||
@@ -13,12 +13,84 @@
|
|||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
Tutorial09::Tutorial09(Engine* t_engine) : engine(t_engine) {}
|
Tutorial09::Tutorial09(Engine* t_engine) : engine(t_engine) {
|
||||||
|
translation = M4x4::Identity;
|
||||||
|
rotation = M4x4::Identity;
|
||||||
|
scale = M4x4::Identity;
|
||||||
|
model = M4x4::Identity;
|
||||||
|
}
|
||||||
|
|
||||||
Tutorial09::~Tutorial09() {}
|
Tutorial09::~Tutorial09() {}
|
||||||
|
|
||||||
void Tutorial09::init() {}
|
void Tutorial09::init() {
|
||||||
|
stapip.setRenderer(&engine->renderer.core);
|
||||||
|
|
||||||
void Tutorial09::loop() {}
|
cameraPosition = Vec4(0.0F, 0.0F, -10.0F);
|
||||||
|
cameraLookAt.unit();
|
||||||
|
|
||||||
|
setDrawData();
|
||||||
|
loadBags();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tutorial09::loop() {
|
||||||
|
rotation.rotateY(0.1F);
|
||||||
|
model = translation * rotation * scale;
|
||||||
|
|
||||||
|
engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt));
|
||||||
|
{
|
||||||
|
engine->renderer.renderer3D.usePipeline(stapip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets draw manually via "bags".
|
||||||
|
* You can do the same thing with dynamic pipeline.
|
||||||
|
*/
|
||||||
|
stapip.core.render(bag.get());
|
||||||
|
}
|
||||||
|
engine->renderer.endFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tutorial09::setDrawData() {
|
||||||
|
vertices = {
|
||||||
|
Vec4(-3.0F, -3.0F, 0.0F),
|
||||||
|
Vec4(3.0F, -3.0F, 0.0F),
|
||||||
|
Vec4(0.0F, 3.0F, 0.0F),
|
||||||
|
};
|
||||||
|
|
||||||
|
colors = {
|
||||||
|
Color(128.0F, 0.0F, 0.0F),
|
||||||
|
Color(0.0F, 128.0F, 0.0F),
|
||||||
|
Color(0.0F, 0.0F, 128.0F),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tutorial09::loadBags() {
|
||||||
|
/**
|
||||||
|
* Create info bag and fill it with model matrix and shading type.
|
||||||
|
* Keep rest of the options as default.
|
||||||
|
*/
|
||||||
|
infoBag = std::make_unique<StaPipInfoBag>();
|
||||||
|
infoBag->model = &model;
|
||||||
|
infoBag->shadingType = TyraShadingGouraud;
|
||||||
|
|
||||||
|
/** Create colors bag and set data pointer */
|
||||||
|
colorBag = std::make_unique<StaPipColorBag>();
|
||||||
|
colorBag->many = colors.begin();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create main bag and set:
|
||||||
|
* - vertices data
|
||||||
|
* - vertices count
|
||||||
|
* - pointers to other bags
|
||||||
|
*
|
||||||
|
* You can add here lighting and texture bag as well.
|
||||||
|
* If you want to have deeper look of this feature, please
|
||||||
|
* read static_pipeline.cpp code file.
|
||||||
|
*/
|
||||||
|
bag = std::make_unique<StaPipBag>();
|
||||||
|
bag->color = colorBag.get();
|
||||||
|
bag->info = infoBag.get();
|
||||||
|
bag->vertices = vertices.begin();
|
||||||
|
bag->count = vertices.size();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Tyra
|
} // namespace Tyra
|
||||||
|
|||||||
Reference in New Issue
Block a user