bags refactor

This commit is contained in:
h4570
2022-07-18 23:42:24 +02:00
parent 0953ce3f19
commit f08fc1c8d3
19 changed files with 215 additions and 71 deletions
@@ -43,8 +43,10 @@ std::string DynPipBag::getPrint(const char* name) const {
res << std::fixed << std::setprecision(4);
res << std::endl;
res << "Count: " << count << ", " << std::endl;
res << "Vertices present: " << (vertices != nullptr ? "Yes" : "No") << ", "
<< std::endl;
res << "Vertices from present: " << (verticesFrom != nullptr ? "Yes" : "No")
<< ", " << std::endl;
res << "Vertices to present: " << (verticesTo != nullptr ? "Yes" : "No")
<< ", " << std::endl;
res << "Info present: " << (info != nullptr ? "Yes" : "No") << ", "
<< std::endl;
res << "Color present: " << (color != nullptr ? "Yes" : "No") << ", "
@@ -54,20 +56,32 @@ std::string DynPipBag::getPrint(const char* name) const {
res << "Lighting present: " << (lighting != nullptr ? "Yes" : "No") << ", "
<< std::endl;
res << "Model matrix: " << info->model->getPrint() << ", " << std::endl;
if (color->single) {
res << "Color single: " << color->single->getPrint() << ", " << std::endl;
if (color->singleFrom) {
res << "Color from single: " << color->singleFrom->getPrint() << ", "
<< std::endl;
res << "Color to single: " << color->singleTo->getPrint() << ", "
<< std::endl;
} else {
res << "Color many: " << color->many->getPrint() << ", " << std::endl;
res << "Color many from present: "
<< (color->manyFrom != nullptr ? "Yes" : "No") << ", " << std::endl;
res << "Color many to present: "
<< (color->manyTo != nullptr ? "Yes" : "No") << ", " << std::endl;
}
if (texture) {
res << "Texture coords present: "
<< (texture->coordinates != nullptr ? "Yes" : "No") << ", "
res << "Texture coords from present: "
<< (texture->coordinatesFrom != nullptr ? "Yes" : "No") << ", "
<< std::endl;
res << "Texture coords to present: "
<< (texture->coordinatesTo != nullptr ? "Yes" : "No") << ", "
<< std::endl;
res << "Texture: " << texture->texture->getPrint() << ", " << std::endl;
}
if (lighting) {
res << "Lighting normals present: " << (lighting->normals ? "Yes" : "No")
<< ", " << std::endl;
res << "Lighting normals from present: "
<< (lighting->normalsFrom ? "Yes" : "No") << ", " << std::endl;
res << "Lighting normals to present: "
<< (lighting->normalsTo ? "Yes" : "No") << ", " << std::endl;
res << "Lighting matrix: " << lighting->lightMatrix->getPrint() << ", "
<< std::endl;
}
@@ -13,8 +13,10 @@
namespace Tyra {
DynPipColorBag::DynPipColorBag() {
single = nullptr;
many = nullptr;
singleFrom = nullptr;
singleTo = nullptr;
manyFrom = nullptr;
manyTo = nullptr;
}
DynPipColorBag::~DynPipColorBag() {}
@@ -0,0 +1,24 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# 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/dynamic/bag/dynpip_lighting_bag.hpp"
namespace Tyra {
DynPipLightingBag::DynPipLightingBag() {
lightMatrix = nullptr;
normalsFrom = nullptr;
normalsTo = nullptr;
dirLights = nullptr;
}
DynPipLightingBag::~DynPipLightingBag() {}
} // namespace Tyra
@@ -13,7 +13,8 @@
namespace Tyra {
DynPipTextureBag::DynPipTextureBag() {
coordinates = nullptr;
coordinatesFrom = nullptr;
coordinatesTo = nullptr;
texture = nullptr;
}
@@ -9,15 +9,13 @@
*/
#include "debug/debug.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_lighting_bag.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp"
namespace Tyra {
PipelineLightingBag::PipelineLightingBag(const bool& manual) {
PipelineDirLightsBag::PipelineDirLightsBag(const bool& manual) {
isAllocated = false;
mode = Auto;
normals = nullptr;
lightMatrix = nullptr;
lightColors = nullptr;
lightDirections = nullptr;
if (manual) {
@@ -27,33 +25,33 @@ PipelineLightingBag::PipelineLightingBag(const bool& manual) {
}
}
PipelineLightingBag::~PipelineLightingBag() { deallocate(); }
PipelineDirLightsBag::~PipelineDirLightsBag() { deallocate(); }
void PipelineLightingBag::setAmbientColor(const Color& color) {
void PipelineDirLightsBag::setAmbientColor(const Color& color) {
TYRA_ASSERT(mode != Manual, "Ambient color cannot be set in manual mode");
lightColors[3].set(reinterpret_cast<const Vec4&>(color));
}
void PipelineLightingBag::setDirectionalLightColors(Color* colors,
const u8& count) {
void PipelineDirLightsBag::setDirectionalLightColors(Color* colors,
const u8& count) {
for (u8 i = 0; i < count; i++) setDirectionalLightColor(colors[i], i);
}
void PipelineLightingBag::setDirectionalLightDirections(Vec4* directions,
const u8& count) {
void PipelineDirLightsBag::setDirectionalLightDirections(Vec4* directions,
const u8& count) {
for (u8 i = 0; i < count; i++) setDirectionalLightDirection(directions[i], i);
}
void PipelineLightingBag::setDirectionalLightColor(const Color& color,
const u8& index) {
void PipelineDirLightsBag::setDirectionalLightColor(const Color& color,
const u8& index) {
TYRA_ASSERT(mode != Manual,
"Directional lights cannot be set in manual mode");
TYRA_ASSERT(index < 3, "There are max 3 directional lights");
lightColors[index].set(reinterpret_cast<const Vec4&>(color));
}
void PipelineLightingBag::setDirectionalLightDirection(const Vec4& direction,
const u8& index) {
void PipelineDirLightsBag::setDirectionalLightDirection(const Vec4& direction,
const u8& index) {
TYRA_ASSERT(mode != Manual,
"Directional lights cannot be set in manual mode");
TYRA_ASSERT(index < 3, "There are max 3 directional lights");
@@ -61,19 +59,19 @@ void PipelineLightingBag::setDirectionalLightDirection(const Vec4& direction,
lightDirections[index].set(direction);
}
void PipelineLightingBag::setLightsManually(Vec4* colors, Vec4* directions) {
void PipelineDirLightsBag::setLightsManually(Vec4* colors, Vec4* directions) {
deallocate();
lightColors = colors;
lightDirections = directions;
mode = Manual;
}
void PipelineLightingBag::disableManualMode() {
void PipelineDirLightsBag::disableManualMode() {
allocate();
mode = Auto;
}
void PipelineLightingBag::allocate() {
void PipelineDirLightsBag::allocate() {
if (isAllocated) return;
lightColors = new Vec4[4];
@@ -92,27 +90,27 @@ void PipelineLightingBag::allocate() {
isAllocated = true;
}
void PipelineLightingBag::deallocate() {
void PipelineDirLightsBag::deallocate() {
if (!isAllocated) return;
forceDeallocate();
}
void PipelineLightingBag::forceDeallocate() {
void PipelineDirLightsBag::forceDeallocate() {
forceDeallocateColors();
forceDeallocateDirections();
isAllocated = false;
}
void PipelineLightingBag::forceDeallocateColors() {
void PipelineDirLightsBag::forceDeallocateColors() {
if (lightColors != nullptr) {
delete[] lightColors;
lightColors = nullptr;
}
}
void PipelineLightingBag::forceDeallocateDirections() {
void PipelineDirLightsBag::forceDeallocateDirections() {
if (lightDirections != nullptr) {
delete[] lightDirections;
lightDirections = nullptr;
@@ -63,7 +63,8 @@ std::string StaPipBag::getPrint(const char* name) const {
if (color->single) {
res << "Color single: " << color->single->getPrint() << ", " << std::endl;
} else {
res << "Color many: " << color->many->getPrint() << ", " << std::endl;
res << "Color many present: " << (color->many != nullptr ? "Yes" : "No")
<< ", " << std::endl;
}
if (texture) {
res << "Texture coords present: "
@@ -0,0 +1,23 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# 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/static/core/bag/stapip_lighting_bag.hpp"
namespace Tyra {
StaPipLightingBag::StaPipLightingBag() {
lightMatrix = nullptr;
normals = nullptr;
dirLights = nullptr;
}
StaPipLightingBag::~StaPipLightingBag() {}
} // namespace Tyra
@@ -91,12 +91,13 @@ void StaPipQBufferRenderer::sendObjectData(
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_MATRIX_ADDR,
bag->lighting->lightMatrix, 3, false);
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_DIRS_ADDR,
bag->lighting->getLightDirections(), 3,
false);
packet2_utils_vu_add_unpack_data(
objectDataPacket, VU1_LIGHTS_DIRS_ADDR,
bag->lighting->dirLights->getLightDirections(), 3, false);
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_COLORS_ADDR,
bag->lighting->getLightColors(), 4, false);
bag->lighting->dirLights->getLightColors(),
4, false);
}
u8 singleColorEnabled = bag->color->single != nullptr;
@@ -65,8 +65,10 @@ void StaPipelineCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox) {
(!bag->color->many && bag->lighting),
"Multicolor is not supported with lighting, please choose one!");
TYRA_ASSERT(
!bag->lighting || (bag->lighting->lightMatrix && bag->lighting->normals),
"If you want lighting, please provide light matrix and normals!");
!bag->lighting || (bag->lighting->lightMatrix && bag->lighting->normals &&
bag->lighting->dirLights),
"If you want lighting, please provide light matrix normals and dir "
"lights!");
TYRA_ASSERT(
!bag->texture || (bag->texture->texture && bag->texture->coordinates),
"If you want texture, please provide texture and coordinates!");
@@ -163,7 +163,7 @@ StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh,
return result;
}
PipelineLightingBag* StaticPipeline::getLightingBag(
StaPipLightingBag* StaticPipeline::getLightingBag(
DynamicMesh* mesh, MeshMaterial* material, M4x4* model,
MeshFrame* frameFrom, MeshFrame* frameTo,
const StaPipOptions* options) const {
@@ -171,11 +171,14 @@ PipelineLightingBag* StaticPipeline::getLightingBag(
options->lighting == nullptr)
return nullptr;
auto* result = new PipelineLightingBag(true);
auto* result = new StaPipLightingBag();
auto* dirLightsBag = new PipelineDirLightsBag(true);
result->dirLights = dirLightsBag;
result->lightMatrix = model;
result->setLightsManually(colorsCache,
options->lighting->directionalDirections);
result->dirLights->setLightsManually(
colorsCache, options->lighting->directionalDirections);
result->normals = new Vec4[material->getFacesCount()];
@@ -215,6 +218,7 @@ void StaticPipeline::deallocDrawBags(StaPipBag* bag,
if (bag->lighting) {
delete[] bag->lighting->normals;
delete bag->lighting->dirLights;
delete bag->lighting;
}