renderer cleanup, demo changes

This commit is contained in:
h4570
2022-08-03 10:37:27 +02:00
parent da958cb094
commit 0a024e745f
27 changed files with 329 additions and 149 deletions
-3
View File
@@ -149,9 +149,6 @@ MeshBuilderData* MD2Loader::load(const char* fullpath, const float& scale,
texCoord_t* texCoord;
TYRA_LOG("Skin width: ", header.skinwidth,
" Skin height: ", header.skinheight);
for (u32 i = 0; i < stsCount; i++) {
texCoord =
reinterpret_cast<texCoord_t*>(&stsBuffer[sizeof(texCoord_t) * i]);
@@ -243,8 +243,7 @@ void TyrobjLoader::readFaces(TyraobjReadInfo* info, FILE* file,
&normalIndex[1], &vertexIndex[2], &coordIndex[2], &normalIndex[2]);
} break;
/** Loaded only two digits (V, VT) succesfuly. Not setting
VN. */
/** Loaded only two digits (V, VT) succesfuly. Not setting VN. */
case 3: {
fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", &vertexIndex[0], &coordIndex[0],
&vertexIndex[1], &coordIndex[1], &vertexIndex[2], &coordIndex[2]);
@@ -56,7 +56,7 @@ u32 DynPipCore::getMaxVertCountByParams(const bool& isLightingEnabled,
->getMaxVertCount(qbufferRenderer.getBufferSize());
}
void DynPipCore::initParts(DynPipBag* bag) {
void DynPipCore::sendObjectDataToVU1(DynPipBag* bag) {
RendererCoreTextureBuffers* texBuffers = nullptr;
if (bag->texture) {
auto temp = rendererCore->texture.useTexture(bag->texture->texture);
@@ -74,7 +74,9 @@ void DynPipCore::initParts(DynPipBag* bag) {
delete texBuffers;
}
void DynPipCore::updatePrimLod(PipelineInfoBag* bag) {
void DynPipCore::begin(PipelineInfoBag* bag) {
qbufferRenderer.clearLastProgramName();
prim.antialiasing = bag->antiAliasingEnabled;
prim.blending = bag->blendingEnabled;
prim.shading = bag->shadingType;
@@ -88,8 +90,7 @@ void DynPipCore::updatePrimLod(PipelineInfoBag* bag) {
}
}
void DynPipCore::renderPart(DynPipBag** bags, const u32& count,
const bool& frustumCull) {
void DynPipCore::render(DynPipBag** bags, const u32& count) {
if (count <= 0) return;
TYRA_ASSERT(
@@ -113,7 +114,7 @@ void DynPipCore::renderPart(DynPipBag** bags, const u32& count,
bags[0]->texture->coordinatesTo),
"If you want texture, please provide texture and coordinates!");
if (!frustumCull) {
if (bags[0]->info->frustumCulling == PipelineInfoBagFrustumCulling_None) {
qbufferRenderer.render(bags, count);
return;
}
@@ -9,6 +9,7 @@
*/
#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
namespace Tyra {
@@ -49,13 +50,18 @@ void DynamicPipeline::onUseEnd() {
}
void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
bool optionsManuallyAllocated = false;
if (!options) {
options = new DynPipOptions();
optionsManuallyAllocated = true;
}
auto model = mesh->getModelMatrix();
auto* infoBag = getInfoBag(mesh, options, &model);
PipelineDirLightsBag* dirLights = nullptr;
auto frustumCulling =
options ? options->frustumCulling : PipelineFrustumCulling_Simple;
if (frustumCulling == PipelineFrustumCulling_Simple) {
if (options->frustumCulling == PipelineFrustumCulling_Simple) {
auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame());
if (frameTo->getBBox().isInFrustum(
rendererCore->renderer3D.frustumPlanes.getAll(), model) ==
@@ -74,8 +80,7 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
u16 bufferIndex = 0;
setBuffersDefaultVars(buffers, mesh, infoBag);
core.clear();
core.updatePrimLod(infoBag);
core.begin(infoBag);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i);
@@ -110,28 +115,29 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
dirLights, startIndex);
if (!isPartInitialized) {
core.initParts(&buffer);
core.sendObjectDataToVU1(&buffer);
isPartInitialized = true;
}
setBuffer(buffers, &buffer, &bufferIndex, frustumCulling);
setBuffer(buffers, &buffer, &bufferIndex);
}
delete colorBag;
}
sendRestOfBuffers(buffers, &bufferIndex, frustumCulling);
sendRestOfBuffers(buffers, &bufferIndex);
if (dirLights) {
delete dirLights;
}
delete infoBag;
if (optionsManuallyAllocated) delete options;
}
void DynamicPipeline::setBuffer(DynPipBag* buffers, DynPipBag* buffer,
u16* bufferIndex,
const PipelineFrustumCulling& frustumCulling) {
u16* bufferIndex) {
auto isEndOf1stDBuffer = *bufferIndex == halfBuffersCount - 1;
auto isEndOf2ndDBuffer = *bufferIndex == buffersCount - 1;
@@ -143,8 +149,7 @@ void DynamicPipeline::setBuffer(DynPipBag* buffers, DynPipBag* buffer,
for (u32 i = 0; i < halfBuffersCount; i++)
sendBuffers[i] = &buffers[offset + i];
core.renderPart(sendBuffers, halfBuffersCount,
frustumCulling == PipelineFrustumCulling_Precise);
core.render(sendBuffers, halfBuffersCount);
delete[] sendBuffers;
}
@@ -155,9 +160,7 @@ void DynamicPipeline::setBuffer(DynPipBag* buffers, DynPipBag* buffer,
*bufferIndex += 1;
}
void DynamicPipeline::sendRestOfBuffers(
DynPipBag* buffers, u16* bufferIndex,
const PipelineFrustumCulling& frustumCulling) {
void DynamicPipeline::sendRestOfBuffers(DynPipBag* buffers, u16* bufferIndex) {
auto isEndOf1stDBuffer = *bufferIndex <= halfBuffersCount - 1;
u32 offset = isEndOf1stDBuffer ? 0 : halfBuffersCount;
@@ -170,15 +173,14 @@ void DynamicPipeline::sendRestOfBuffers(
sendBuffers[i] = &buffers[offset + i];
}
core.renderPart(sendBuffers, size,
frustumCulling == PipelineFrustumCulling_Precise);
core.render(sendBuffers, size);
delete[] sendBuffers;
}
void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers,
DynamicMesh* mesh,
PipelineInfoBag* infoBag) {
DynPipInfoBag* infoBag) {
for (u32 i = 0; i < buffersCount; i++) {
buffers[i].info = infoBag;
buffers[i].interpolation = mesh->getAnimState().interpolation;
@@ -202,25 +204,20 @@ void DynamicPipeline::freeBuffer(DynPipBag* bag) {
}
}
PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
const DynPipOptions* options,
M4x4* model) const {
auto* result = new PipelineInfoBag();
if (options) {
result->antiAliasingEnabled = options->antiAliasingEnabled;
result->blendingEnabled = options->blendingEnabled;
result->shadingType = options->shadingType;
result->textureMappingType = options->textureMappingType;
result->transformationType = options->transformationType;
} else {
result->antiAliasingEnabled = false;
result->blendingEnabled = true;
result->shadingType = TyraShadingFlat;
result->textureMappingType = TyraLinear;
result->transformationType = TyraMVP;
}
DynPipInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
const DynPipOptions* options,
M4x4* model) const {
auto* result = new DynPipInfoBag();
result->antiAliasingEnabled = options->antiAliasingEnabled;
result->blendingEnabled = options->blendingEnabled;
result->shadingType = options->shadingType;
result->textureMappingType = options->textureMappingType;
result->transformationType = options->transformationType;
result->frustumCulling =
options->frustumCulling == PipelineFrustumCulling_Precise
? PipelineInfoBagFrustumCulling_Precise
: PipelineInfoBagFrustumCulling_None;
result->model = model;
return result;
@@ -1,26 +0,0 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
namespace Tyra {
PipelineInfoBag::PipelineInfoBag() {
shadingType = TyraShadingFlat;
transformationType = TyraMVP;
textureMappingType = TyraLinear;
blendingEnabled = true;
antiAliasingEnabled = false;
model = nullptr;
}
PipelineInfoBag::~PipelineInfoBag() {}
} // namespace Tyra
@@ -72,10 +72,12 @@ u32 StaPipCore::getMaxVertCountByParams(const bool& isSingleColor,
->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize());
}
void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
const StaPipZTest& zTest, StaPipBagPackagesBBox* bbox) {
void StaPipCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox) {
if (bag->count <= 0) return;
bool frustumCull =
bag->info->frustumCulling == PipelineInfoBagFrustumCulling_Precise;
TYRA_ASSERT(bag->vertices != nullptr,
"Vertices are required in 3D render bag!");
TYRA_ASSERT(bag->info != nullptr, "Info bag is required in 3D render bag!");
@@ -100,7 +102,7 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
(!bag->info->fullClipChecks && !frustumCull),
"Please disable clip checks and frustum culling if not using MVP "
"matrix!");
TYRA_ASSERT(!(frustumCull == false && bag->info->fullClipChecks == true),
TYRA_ASSERT(!(!frustumCull && bag->info->fullClipChecks == true),
"Full clip checks are not supported with frustum culling = off!");
u32 maxVertCount = getMaxVertCountByBag(bag);
@@ -128,7 +130,7 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
}
}
if (zTest == StaPipZTest_AllPass) {
if (bag->info->zTestType == StaPipZTest_AllPass) {
rendererCore->gs.setAllPassZTest();
}
@@ -208,7 +210,7 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
qbufferRenderer.flushBuffers();
if (zTest == StaPipZTest_AllPass) {
if (bag->info->zTestType == StaPipZTest_AllPass) {
rendererCore->gs.setStandardZTest();
}
@@ -10,6 +10,7 @@
#include "renderer/3d/pipeline/static/static_pipeline.hpp"
#include "debug/debug.hpp"
#include "renderer/3d/pipeline/static/core/bag/stapip_info_bag.hpp"
namespace Tyra {
@@ -37,15 +38,18 @@ void StaticPipeline::onUseEnd() {
}
void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
bool optionsManuallyAllocated = false;
if (!options) {
options = new StaPipOptions();
optionsManuallyAllocated = true;
}
auto model = mesh->getModelMatrix();
auto* infoBag = getInfoBag(mesh, options, &model);
auto zTesting = options ? options->zTestType : StaPipZTest_Standard;
auto frustumCulling =
options ? options->frustumCulling : PipelineFrustumCulling_Simple;
TYRA_ASSERT(
!(frustumCulling != PipelineFrustumCulling_Precise &&
!(options->frustumCulling != PipelineFrustumCulling_Precise &&
infoBag->fullClipChecks == true),
"Full clip checks are only supported with frustum culling == Precise!");
TYRA_ASSERT(options->transformationType == TyraMVP ||
@@ -54,7 +58,7 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
"Please disable clip checks and frustum culling if not using MVP "
"matrix!");
if (frustumCulling == PipelineFrustumCulling_Simple) {
if (options->frustumCulling == PipelineFrustumCulling_Simple) {
auto* frame = mesh->getFrame();
if (frame->getBBox().isInFrustum(
rendererCore->renderer3D.frustumPlanes.getAll(), model) ==
@@ -68,21 +72,19 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i);
auto* materialFrame = material->getFrame(0);
StaPipBag bag;
addVertices(materialFrame, &bag);
bag.info = infoBag;
bag.color = getColorBag(material, materialFrame);
bag.texture = getTextureBag(material, materialFrame);
bag.lighting = getLightingBag(materialFrame, &model, options);
core.render(&bag, frustumCulling == PipelineFrustumCulling_Precise,
zTesting);
core.render(&bag);
deallocDrawBags(&bag, material);
}
delete infoBag;
if (optionsManuallyAllocated) delete options;
}
void StaticPipeline::addVertices(MeshMaterialFrame* materialFrame,
@@ -91,27 +93,22 @@ void StaticPipeline::addVertices(MeshMaterialFrame* materialFrame,
bag->vertices = materialFrame->getVertices();
}
PipelineInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh,
const StaPipOptions* options,
M4x4* model) const {
auto* result = new PipelineInfoBag();
if (options) {
result->antiAliasingEnabled = options->antiAliasingEnabled;
result->blendingEnabled = options->blendingEnabled;
result->shadingType = options->shadingType;
result->fullClipChecks = options->fullClipChecks;
result->textureMappingType = options->textureMappingType;
result->transformationType = options->transformationType;
} else {
result->antiAliasingEnabled = false;
result->blendingEnabled = true;
result->shadingType = TyraShadingFlat;
result->textureMappingType = TyraLinear;
result->fullClipChecks = false;
result->transformationType = TyraMVP;
}
StaPipInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh,
const StaPipOptions* options,
M4x4* model) const {
auto* result = new StaPipInfoBag();
result->antiAliasingEnabled = options->antiAliasingEnabled;
result->blendingEnabled = options->blendingEnabled;
result->shadingType = options->shadingType;
result->textureMappingType = options->textureMappingType;
result->transformationType = options->transformationType;
result->frustumCulling =
options->frustumCulling == PipelineFrustumCulling_Precise
? PipelineInfoBagFrustumCulling_Precise
: PipelineInfoBagFrustumCulling_None;
result->fullClipChecks = options->fullClipChecks;
result->zTestType = options->zTestType;
result->model = model;
return result;