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
@@ -12,7 +12,7 @@
#include "math/vec4.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
#include "./dynpip_info_bag.hpp"
#include "./dynpip_color_bag.hpp"
#include "./dynpip_lighting_bag.hpp"
#include "./dynpip_texture_bag.hpp"
@@ -31,7 +31,7 @@ class DynPipBag {
~DynPipBag();
/** Mandatory. Object info. */
PipelineInfoBag* info;
DynPipInfoBag* info;
/** Mandatory. Object color(s). */
DynPipColorBag* color;
@@ -8,19 +8,16 @@
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#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() {}
class DynPipInfoBag : public PipelineInfoBag {
public:
DynPipInfoBag() {}
~DynPipInfoBag() {}
};
} // namespace Tyra
@@ -28,18 +28,16 @@ class DynPipCore {
void init(RendererCore* t_core);
/** Force starting VU1 program instead of continueing */
void clear() { qbufferRenderer.clearLastProgramName(); }
void updatePrimLod(PipelineInfoBag* bag);
void begin(PipelineInfoBag* bag);
/**
* Send model matrix, lighting data and other
* repetitve stuff to VU1
*/
void initParts(DynPipBag* data);
void sendObjectDataToVU1(DynPipBag* data);
/** Render 3D via "bags" */
void renderPart(DynPipBag** bags, const u32& count,
const bool& frustumCull = true);
void render(DynPipBag** bags, const u32& count);
/** Get max vert count of VU1 qbuffer (for optimizations) */
u32 getMaxVertCountByParams(const bool& isLightingEnabled,
@@ -53,18 +53,16 @@ class DynamicPipeline : public Renderer3DPipeline {
DynPipBag* buffers;
static const u32 halfBuffersCount;
void setBuffer(DynPipBag* buffers, DynPipBag* buffer, u16* bufferIndex,
const PipelineFrustumCulling& frustumCulling);
void setBuffer(DynPipBag* buffers, DynPipBag* buffer, u16* bufferIndex);
void sendRestOfBuffers(DynPipBag* buffers, u16* bufferIndex,
const PipelineFrustumCulling& frustumCulling);
void sendRestOfBuffers(DynPipBag* buffers, u16* bufferIndex);
void addVertices(MeshMaterialFrame* materialFrameFrom,
MeshMaterialFrame* materialFrameTo, DynPipBag* bag,
const u32& startIndex) const;
PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options,
M4x4* model) const;
DynPipInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options,
M4x4* model) const;
DynPipColorBag* getColorBag(MeshMaterial* material) const;
@@ -82,7 +80,7 @@ class DynamicPipeline : public Renderer3DPipeline {
void setLightingColorsCache(PipelineLightingOptions* lightingOptions);
void freeBuffer(DynPipBag* bag);
void setBuffersDefaultVars(DynPipBag* buffers, DynamicMesh* mesh,
PipelineInfoBag* infoBag);
DynPipInfoBag* infoBag);
void setBuffersColorBag(DynPipBag* buffers, DynPipColorBag* colorBag);
};
@@ -16,33 +16,43 @@
#include "../pipeline_shading_type.hpp"
#include "../pipeline_texture_mapping_type.hpp"
#include "../pipeline_transformation_type.hpp"
#include "./pipeline_info_bag_frustum_culling.hpp"
namespace Tyra {
class PipelineInfoBag {
public:
PipelineInfoBag();
~PipelineInfoBag();
PipelineInfoBag() {
shadingType = TyraShadingFlat;
transformationType = TyraMVP;
textureMappingType = TyraLinear;
blendingEnabled = true;
antiAliasingEnabled = false;
model = nullptr;
frustumCulling = PipelineInfoBagFrustumCulling_None;
}
~PipelineInfoBag() {}
/** Mandatory. Model matrix */
M4x4* model;
/** Flat or gouraud */
PipelineShadingType shadingType;
/** Linear or nearest */
PipelineTextureMappingType textureMappingType;
/** Multiply by model matrix by view-projection or projection matrix */
PipelineTransformationType transformationType;
/** Blending texture with color */
bool blendingEnabled;
/** Anti-aliasing */
bool antiAliasingEnabled;
/**
* @brief Experimental! False -> disables "clip against each plane" algorithm.
* Default: True.
*
* Full clip checks are slow, but they are
* preventing visual artifacts, which can happen
* for big 3D objects (or objects near camera eyes)
* Force enabled in dynamic pipe, because of efficiency.
*/
bool fullClipChecks;
/** Type of frustum culling */
PipelineInfoBagFrustumCulling frustumCulling;
};
} // namespace Tyra
@@ -0,0 +1,22 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
namespace Tyra {
enum PipelineInfoBagFrustumCulling {
/** No frustum culling */
PipelineInfoBagFrustumCulling_None = 0,
/** Frustum culling of parts of an object */
PipelineInfoBagFrustumCulling_Precise = 2,
};
}
@@ -45,7 +45,7 @@ class PipelineOptions {
/** Anti-aliasing */
bool antiAliasingEnabled;
/** Multiply by model matrix by MVP or MP */
/** Multiply by model matrix by view-projection or projection matrix */
PipelineTransformationType transformationType;
/** Optional */
@@ -11,7 +11,7 @@
#pragma once
#include "math/vec4.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
#include "./stapip_info_bag.hpp"
#include "./stapip_color_bag.hpp"
#include "./stapip_lighting_bag.hpp"
#include "./stapip_texture_bag.hpp"
@@ -31,7 +31,7 @@ class StaPipBag {
~StaPipBag();
/** Mandatory. Object info. */
PipelineInfoBag* info;
StaPipInfoBag* info;
/** Mandatory. Object color(s). */
StaPipColorBag* color;
@@ -0,0 +1,41 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
#include "renderer/3d/pipeline/static/stapip_ztest.hpp"
namespace Tyra {
class StaPipInfoBag : public PipelineInfoBag {
public:
StaPipInfoBag() {
fullClipChecks = false;
zTestType = StaPipZTest_Standard;
}
~StaPipInfoBag() {}
/**
* @brief Experimental! False -> disables "clip against each plane" algorithm.
* Default: True.
*
* Full clip checks are slow, but they are
* preventing visual artifacts, which can happen
* for big 3D objects (or objects near camera eyes)
* Force enabled in dynamic pipe, because of efficiency.
*/
bool fullClipChecks;
/** @brief Type of z buffer testing. */
StaPipZTest zTestType;
};
} // namespace Tyra
@@ -29,8 +29,7 @@ class StaPipCore {
void init(RendererCore* t_core);
/** Render 3D via "bags" */
void render(StaPipBag* bag, const bool& frustumCull, const StaPipZTest& zTest,
StaPipBagPackagesBBox* bbox = nullptr);
void render(StaPipBag* bag, StaPipBagPackagesBBox* bbox = nullptr);
/** Get max vert count of VU1 qbuffer (for optimizations) */
u32 getMaxVertCountByParams(const bool& isSingleColor,
@@ -53,7 +53,7 @@ class StaticPipeline : public Renderer3DPipeline {
void addVertices(MeshMaterialFrame* materialFrame, StaPipBag* bag) const;
PipelineInfoBag* getInfoBag(StaticMesh* mesh, const StaPipOptions* options,
StaPipInfoBag* getInfoBag(StaticMesh* mesh, const StaPipOptions* options,
M4x4* model) const;
StaPipColorBag* getColorBag(MeshMaterial* material,
-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;
@@ -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;