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
@@ -11,9 +11,10 @@
#pragma once
#include "math/vec4.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_lighting_bag.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
#include "./dynpip_color_bag.hpp"
#include "./dynpip_lighting_bag.hpp"
#include "./dynpip_texture_bag.hpp"
#include "renderer/core/texture/models/texture.hpp"
@@ -35,17 +36,27 @@ class DynPipBag {
/** Mandatory. Object color(s). */
DynPipColorBag* color;
/** Mandatory. Vertex count. */
/** Mandatory. Vertex count per frame. */
u32 count;
/** Mandatory. Vertices. */
Vec4* vertices;
/** Mandatory. From (frame) vertices */
Vec4* verticesFrom;
/** Mandatory. To (frame) vertices */
Vec4* verticesTo;
/**
* Mandatory.
* State of animation interpolation
* (between from and to)
*/
float interpolation;
/** Optional. Texture coordinates and image. */
DynPipTextureBag* texture;
/** Optional. Object lighting. */
PipelineLightingBag* lighting;
DynPipLightingBag* lighting;
void print() const;
void print(const char* name) const;
@@ -23,10 +23,12 @@ class DynPipColorBag {
~DynPipColorBag();
/** Optional. Single color for all vertices. */
Color* single;
Color* singleFrom;
Color* singleTo;
/** Optional. Color per vertex. */
Color* many;
Color* manyFrom;
Color* manyTo;
};
} // namespace Tyra
@@ -0,0 +1,34 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include "math/vec4.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp"
namespace Tyra {
class DynPipLightingBag {
public:
DynPipLightingBag();
~DynPipLightingBag();
/** Mandatory. Model matrix for lights. */
M4x4* lightMatrix;
/** Mandatory. Lighting normals per vertex. */
Vec4* normalsFrom;
Vec4* normalsTo;
/** Mandatory. Directional lights */
PipelineDirLightsBag* dirLights;
};
} // namespace Tyra
@@ -21,7 +21,8 @@ class DynPipTextureBag {
~DynPipTextureBag();
/** Mandatory. Texture coordinates per vertex. */
Vec4* coordinates;
Vec4* coordinatesFrom;
Vec4* coordinatesTo;
/** Mandatory. Texture image. */
Texture* texture;
@@ -27,10 +27,6 @@ class DynamicPipeline : public Renderer3DPipeline {
void onUse();
/**
* Render 3D data via "meshes".
* This render() method is a bridge to core.render() method.
*/
void render(DynamicMesh* mesh, const DynPipOptions* options = nullptr);
};
@@ -16,15 +16,12 @@
namespace Tyra {
enum PipelineLightingBagMode { Auto, Manual };
enum PipelineDirLightsBagMode { Auto, Manual };
class PipelineLightingBag {
class PipelineDirLightsBag {
public:
explicit PipelineLightingBag(const bool& manual = false);
~PipelineLightingBag();
Vec4* normals;
M4x4* lightMatrix;
explicit PipelineDirLightsBag(const bool& manual = false);
~PipelineDirLightsBag();
void setAmbientColor(const Color& color);
void setDirectionalLightColors(Color* colors, const u8& count);
@@ -47,7 +44,7 @@ class PipelineLightingBag {
void deallocate();
void forceDeallocate();
u8 isAllocated;
PipelineLightingBagMode mode;
PipelineDirLightsBagMode mode;
Vec4* lightColors;
Vec4* lightDirections;
@@ -11,9 +11,9 @@
#pragma once
#include "math/vec4.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_lighting_bag.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
#include "./stapip_color_bag.hpp"
#include "./stapip_lighting_bag.hpp"
#include "./stapip_texture_bag.hpp"
#include "renderer/core/texture/models/texture.hpp"
#include "./packaging/stapip_bag_packages_bbox.hpp"
@@ -46,7 +46,7 @@ class StaPipBag {
StaPipTextureBag* texture;
/** Optional. Object lighting. */
PipelineLightingBag* lighting;
StaPipLightingBag* lighting;
/**
* @param maxVertCount This parameter is available in renderer API.
@@ -0,0 +1,33 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include "math/vec4.hpp"
#include "renderer/3d/pipeline/shared/bag/pipeline_dir_lights_bag.hpp"
namespace Tyra {
class StaPipLightingBag {
public:
StaPipLightingBag();
~StaPipLightingBag();
/** Mandatory. Model matrix for lights. */
M4x4* lightMatrix;
/** Mandatory. Lighting normals per vertex. */
Vec4* normals;
/** Mandatory. Directional lights */
PipelineDirLightsBag* dirLights;
};
} // namespace Tyra
@@ -29,7 +29,7 @@ class StaticPipeline : public Renderer3DPipeline {
void onUse();
/**
* Render 3D data via "meshes".
* Render 3D via "meshes".
* This render() method is a bridge to core.render() method.
*/
void render(DynamicMesh* mesh, const StaPipOptions* options = nullptr);
@@ -47,10 +47,10 @@ class StaticPipeline : public Renderer3DPipeline {
MeshFrame* frameFrom, MeshFrame* frameTo) const;
StaPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material,
MeshFrame* frameFrom, MeshFrame* frameTo);
PipelineLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material,
M4x4* model, MeshFrame* frameFrom,
MeshFrame* frameTo,
const StaPipOptions* options) const;
StaPipLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material,
M4x4* model, MeshFrame* frameFrom,
MeshFrame* frameTo,
const StaPipOptions* options) const;
void deallocDrawBags(StaPipBag* bag, MeshMaterial* material) const;
void setLightingColorsCache(StaPipLightingOptions* lightingOptions);
@@ -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;
}