bags refactor
This commit is contained in:
@@ -11,9 +11,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "math/vec4.hpp"
|
#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 "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
|
||||||
#include "./dynpip_color_bag.hpp"
|
#include "./dynpip_color_bag.hpp"
|
||||||
|
#include "./dynpip_lighting_bag.hpp"
|
||||||
#include "./dynpip_texture_bag.hpp"
|
#include "./dynpip_texture_bag.hpp"
|
||||||
#include "renderer/core/texture/models/texture.hpp"
|
#include "renderer/core/texture/models/texture.hpp"
|
||||||
|
|
||||||
@@ -35,17 +36,27 @@ class DynPipBag {
|
|||||||
/** Mandatory. Object color(s). */
|
/** Mandatory. Object color(s). */
|
||||||
DynPipColorBag* color;
|
DynPipColorBag* color;
|
||||||
|
|
||||||
/** Mandatory. Vertex count. */
|
/** Mandatory. Vertex count per frame. */
|
||||||
u32 count;
|
u32 count;
|
||||||
|
|
||||||
/** Mandatory. Vertices. */
|
/** Mandatory. From (frame) vertices */
|
||||||
Vec4* 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. */
|
/** Optional. Texture coordinates and image. */
|
||||||
DynPipTextureBag* texture;
|
DynPipTextureBag* texture;
|
||||||
|
|
||||||
/** Optional. Object lighting. */
|
/** Optional. Object lighting. */
|
||||||
PipelineLightingBag* lighting;
|
DynPipLightingBag* lighting;
|
||||||
|
|
||||||
void print() const;
|
void print() const;
|
||||||
void print(const char* name) const;
|
void print(const char* name) const;
|
||||||
|
|||||||
@@ -23,10 +23,12 @@ class DynPipColorBag {
|
|||||||
~DynPipColorBag();
|
~DynPipColorBag();
|
||||||
|
|
||||||
/** Optional. Single color for all vertices. */
|
/** Optional. Single color for all vertices. */
|
||||||
Color* single;
|
Color* singleFrom;
|
||||||
|
Color* singleTo;
|
||||||
|
|
||||||
/** Optional. Color per vertex. */
|
/** Optional. Color per vertex. */
|
||||||
Color* many;
|
Color* manyFrom;
|
||||||
|
Color* manyTo;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Tyra
|
} // 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();
|
~DynPipTextureBag();
|
||||||
|
|
||||||
/** Mandatory. Texture coordinates per vertex. */
|
/** Mandatory. Texture coordinates per vertex. */
|
||||||
Vec4* coordinates;
|
Vec4* coordinatesFrom;
|
||||||
|
Vec4* coordinatesTo;
|
||||||
|
|
||||||
/** Mandatory. Texture image. */
|
/** Mandatory. Texture image. */
|
||||||
Texture* texture;
|
Texture* texture;
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ class DynamicPipeline : public Renderer3DPipeline {
|
|||||||
|
|
||||||
void onUse();
|
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);
|
void render(DynamicMesh* mesh, const DynPipOptions* options = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+5
-8
@@ -16,15 +16,12 @@
|
|||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
enum PipelineLightingBagMode { Auto, Manual };
|
enum PipelineDirLightsBagMode { Auto, Manual };
|
||||||
|
|
||||||
class PipelineLightingBag {
|
class PipelineDirLightsBag {
|
||||||
public:
|
public:
|
||||||
explicit PipelineLightingBag(const bool& manual = false);
|
explicit PipelineDirLightsBag(const bool& manual = false);
|
||||||
~PipelineLightingBag();
|
~PipelineDirLightsBag();
|
||||||
|
|
||||||
Vec4* normals;
|
|
||||||
M4x4* lightMatrix;
|
|
||||||
|
|
||||||
void setAmbientColor(const Color& color);
|
void setAmbientColor(const Color& color);
|
||||||
void setDirectionalLightColors(Color* colors, const u8& count);
|
void setDirectionalLightColors(Color* colors, const u8& count);
|
||||||
@@ -47,7 +44,7 @@ class PipelineLightingBag {
|
|||||||
void deallocate();
|
void deallocate();
|
||||||
void forceDeallocate();
|
void forceDeallocate();
|
||||||
u8 isAllocated;
|
u8 isAllocated;
|
||||||
PipelineLightingBagMode mode;
|
PipelineDirLightsBagMode mode;
|
||||||
|
|
||||||
Vec4* lightColors;
|
Vec4* lightColors;
|
||||||
Vec4* lightDirections;
|
Vec4* lightDirections;
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "math/vec4.hpp"
|
#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 "renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp"
|
||||||
#include "./stapip_color_bag.hpp"
|
#include "./stapip_color_bag.hpp"
|
||||||
|
#include "./stapip_lighting_bag.hpp"
|
||||||
#include "./stapip_texture_bag.hpp"
|
#include "./stapip_texture_bag.hpp"
|
||||||
#include "renderer/core/texture/models/texture.hpp"
|
#include "renderer/core/texture/models/texture.hpp"
|
||||||
#include "./packaging/stapip_bag_packages_bbox.hpp"
|
#include "./packaging/stapip_bag_packages_bbox.hpp"
|
||||||
@@ -46,7 +46,7 @@ class StaPipBag {
|
|||||||
StaPipTextureBag* texture;
|
StaPipTextureBag* texture;
|
||||||
|
|
||||||
/** Optional. Object lighting. */
|
/** Optional. Object lighting. */
|
||||||
PipelineLightingBag* lighting;
|
StaPipLightingBag* lighting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param maxVertCount This parameter is available in renderer API.
|
* @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();
|
void onUse();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render 3D data via "meshes".
|
* Render 3D via "meshes".
|
||||||
* This render() method is a bridge to core.render() method.
|
* This render() method is a bridge to core.render() method.
|
||||||
*/
|
*/
|
||||||
void render(DynamicMesh* mesh, const StaPipOptions* options = nullptr);
|
void render(DynamicMesh* mesh, const StaPipOptions* options = nullptr);
|
||||||
@@ -47,7 +47,7 @@ class StaticPipeline : public Renderer3DPipeline {
|
|||||||
MeshFrame* frameFrom, MeshFrame* frameTo) const;
|
MeshFrame* frameFrom, MeshFrame* frameTo) const;
|
||||||
StaPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material,
|
StaPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material,
|
||||||
MeshFrame* frameFrom, MeshFrame* frameTo);
|
MeshFrame* frameFrom, MeshFrame* frameTo);
|
||||||
PipelineLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material,
|
StaPipLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material,
|
||||||
M4x4* model, MeshFrame* frameFrom,
|
M4x4* model, MeshFrame* frameFrom,
|
||||||
MeshFrame* frameTo,
|
MeshFrame* frameTo,
|
||||||
const StaPipOptions* options) const;
|
const StaPipOptions* options) const;
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ std::string DynPipBag::getPrint(const char* name) const {
|
|||||||
res << std::fixed << std::setprecision(4);
|
res << std::fixed << std::setprecision(4);
|
||||||
res << std::endl;
|
res << std::endl;
|
||||||
res << "Count: " << count << ", " << std::endl;
|
res << "Count: " << count << ", " << std::endl;
|
||||||
res << "Vertices present: " << (vertices != nullptr ? "Yes" : "No") << ", "
|
res << "Vertices from present: " << (verticesFrom != nullptr ? "Yes" : "No")
|
||||||
<< std::endl;
|
<< ", " << std::endl;
|
||||||
|
res << "Vertices to present: " << (verticesTo != nullptr ? "Yes" : "No")
|
||||||
|
<< ", " << std::endl;
|
||||||
res << "Info present: " << (info != nullptr ? "Yes" : "No") << ", "
|
res << "Info present: " << (info != nullptr ? "Yes" : "No") << ", "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
res << "Color present: " << (color != nullptr ? "Yes" : "No") << ", "
|
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") << ", "
|
res << "Lighting present: " << (lighting != nullptr ? "Yes" : "No") << ", "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
res << "Model matrix: " << info->model->getPrint() << ", " << std::endl;
|
res << "Model matrix: " << info->model->getPrint() << ", " << std::endl;
|
||||||
if (color->single) {
|
if (color->singleFrom) {
|
||||||
res << "Color single: " << color->single->getPrint() << ", " << std::endl;
|
res << "Color from single: " << color->singleFrom->getPrint() << ", "
|
||||||
|
<< std::endl;
|
||||||
|
res << "Color to single: " << color->singleTo->getPrint() << ", "
|
||||||
|
<< std::endl;
|
||||||
} else {
|
} 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) {
|
if (texture) {
|
||||||
res << "Texture coords present: "
|
res << "Texture coords from present: "
|
||||||
<< (texture->coordinates != nullptr ? "Yes" : "No") << ", "
|
<< (texture->coordinatesFrom != nullptr ? "Yes" : "No") << ", "
|
||||||
|
<< std::endl;
|
||||||
|
res << "Texture coords to present: "
|
||||||
|
<< (texture->coordinatesTo != nullptr ? "Yes" : "No") << ", "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
res << "Texture: " << texture->texture->getPrint() << ", " << std::endl;
|
res << "Texture: " << texture->texture->getPrint() << ", " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lighting) {
|
if (lighting) {
|
||||||
res << "Lighting normals present: " << (lighting->normals ? "Yes" : "No")
|
res << "Lighting normals from present: "
|
||||||
<< ", " << std::endl;
|
<< (lighting->normalsFrom ? "Yes" : "No") << ", " << std::endl;
|
||||||
|
res << "Lighting normals to present: "
|
||||||
|
<< (lighting->normalsTo ? "Yes" : "No") << ", " << std::endl;
|
||||||
res << "Lighting matrix: " << lighting->lightMatrix->getPrint() << ", "
|
res << "Lighting matrix: " << lighting->lightMatrix->getPrint() << ", "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,10 @@
|
|||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
DynPipColorBag::DynPipColorBag() {
|
DynPipColorBag::DynPipColorBag() {
|
||||||
single = nullptr;
|
singleFrom = nullptr;
|
||||||
many = nullptr;
|
singleTo = nullptr;
|
||||||
|
manyFrom = nullptr;
|
||||||
|
manyTo = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
DynPipColorBag::~DynPipColorBag() {}
|
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 {
|
namespace Tyra {
|
||||||
|
|
||||||
DynPipTextureBag::DynPipTextureBag() {
|
DynPipTextureBag::DynPipTextureBag() {
|
||||||
coordinates = nullptr;
|
coordinatesFrom = nullptr;
|
||||||
|
coordinatesTo = nullptr;
|
||||||
texture = nullptr;
|
texture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-17
@@ -9,15 +9,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "debug/debug.hpp"
|
#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 {
|
namespace Tyra {
|
||||||
|
|
||||||
PipelineLightingBag::PipelineLightingBag(const bool& manual) {
|
PipelineDirLightsBag::PipelineDirLightsBag(const bool& manual) {
|
||||||
isAllocated = false;
|
isAllocated = false;
|
||||||
mode = Auto;
|
mode = Auto;
|
||||||
normals = nullptr;
|
|
||||||
lightMatrix = nullptr;
|
|
||||||
lightColors = nullptr;
|
lightColors = nullptr;
|
||||||
lightDirections = nullptr;
|
lightDirections = nullptr;
|
||||||
if (manual) {
|
if (manual) {
|
||||||
@@ -27,24 +25,24 @@ 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");
|
TYRA_ASSERT(mode != Manual, "Ambient color cannot be set in manual mode");
|
||||||
lightColors[3].set(reinterpret_cast<const Vec4&>(color));
|
lightColors[3].set(reinterpret_cast<const Vec4&>(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::setDirectionalLightColors(Color* colors,
|
void PipelineDirLightsBag::setDirectionalLightColors(Color* colors,
|
||||||
const u8& count) {
|
const u8& count) {
|
||||||
for (u8 i = 0; i < count; i++) setDirectionalLightColor(colors[i], i);
|
for (u8 i = 0; i < count; i++) setDirectionalLightColor(colors[i], i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::setDirectionalLightDirections(Vec4* directions,
|
void PipelineDirLightsBag::setDirectionalLightDirections(Vec4* directions,
|
||||||
const u8& count) {
|
const u8& count) {
|
||||||
for (u8 i = 0; i < count; i++) setDirectionalLightDirection(directions[i], i);
|
for (u8 i = 0; i < count; i++) setDirectionalLightDirection(directions[i], i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::setDirectionalLightColor(const Color& color,
|
void PipelineDirLightsBag::setDirectionalLightColor(const Color& color,
|
||||||
const u8& index) {
|
const u8& index) {
|
||||||
TYRA_ASSERT(mode != Manual,
|
TYRA_ASSERT(mode != Manual,
|
||||||
"Directional lights cannot be set in manual mode");
|
"Directional lights cannot be set in manual mode");
|
||||||
@@ -52,7 +50,7 @@ void PipelineLightingBag::setDirectionalLightColor(const Color& color,
|
|||||||
lightColors[index].set(reinterpret_cast<const Vec4&>(color));
|
lightColors[index].set(reinterpret_cast<const Vec4&>(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::setDirectionalLightDirection(const Vec4& direction,
|
void PipelineDirLightsBag::setDirectionalLightDirection(const Vec4& direction,
|
||||||
const u8& index) {
|
const u8& index) {
|
||||||
TYRA_ASSERT(mode != Manual,
|
TYRA_ASSERT(mode != Manual,
|
||||||
"Directional lights cannot be set in manual mode");
|
"Directional lights cannot be set in manual mode");
|
||||||
@@ -61,19 +59,19 @@ void PipelineLightingBag::setDirectionalLightDirection(const Vec4& direction,
|
|||||||
lightDirections[index].set(direction);
|
lightDirections[index].set(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::setLightsManually(Vec4* colors, Vec4* directions) {
|
void PipelineDirLightsBag::setLightsManually(Vec4* colors, Vec4* directions) {
|
||||||
deallocate();
|
deallocate();
|
||||||
lightColors = colors;
|
lightColors = colors;
|
||||||
lightDirections = directions;
|
lightDirections = directions;
|
||||||
mode = Manual;
|
mode = Manual;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::disableManualMode() {
|
void PipelineDirLightsBag::disableManualMode() {
|
||||||
allocate();
|
allocate();
|
||||||
mode = Auto;
|
mode = Auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::allocate() {
|
void PipelineDirLightsBag::allocate() {
|
||||||
if (isAllocated) return;
|
if (isAllocated) return;
|
||||||
|
|
||||||
lightColors = new Vec4[4];
|
lightColors = new Vec4[4];
|
||||||
@@ -92,27 +90,27 @@ void PipelineLightingBag::allocate() {
|
|||||||
isAllocated = true;
|
isAllocated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::deallocate() {
|
void PipelineDirLightsBag::deallocate() {
|
||||||
if (!isAllocated) return;
|
if (!isAllocated) return;
|
||||||
|
|
||||||
forceDeallocate();
|
forceDeallocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::forceDeallocate() {
|
void PipelineDirLightsBag::forceDeallocate() {
|
||||||
forceDeallocateColors();
|
forceDeallocateColors();
|
||||||
forceDeallocateDirections();
|
forceDeallocateDirections();
|
||||||
|
|
||||||
isAllocated = false;
|
isAllocated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::forceDeallocateColors() {
|
void PipelineDirLightsBag::forceDeallocateColors() {
|
||||||
if (lightColors != nullptr) {
|
if (lightColors != nullptr) {
|
||||||
delete[] lightColors;
|
delete[] lightColors;
|
||||||
lightColors = nullptr;
|
lightColors = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLightingBag::forceDeallocateDirections() {
|
void PipelineDirLightsBag::forceDeallocateDirections() {
|
||||||
if (lightDirections != nullptr) {
|
if (lightDirections != nullptr) {
|
||||||
delete[] lightDirections;
|
delete[] lightDirections;
|
||||||
lightDirections = nullptr;
|
lightDirections = nullptr;
|
||||||
@@ -63,7 +63,8 @@ std::string StaPipBag::getPrint(const char* name) const {
|
|||||||
if (color->single) {
|
if (color->single) {
|
||||||
res << "Color single: " << color->single->getPrint() << ", " << std::endl;
|
res << "Color single: " << color->single->getPrint() << ", " << std::endl;
|
||||||
} else {
|
} else {
|
||||||
res << "Color many: " << color->many->getPrint() << ", " << std::endl;
|
res << "Color many present: " << (color->many != nullptr ? "Yes" : "No")
|
||||||
|
<< ", " << std::endl;
|
||||||
}
|
}
|
||||||
if (texture) {
|
if (texture) {
|
||||||
res << "Texture coords present: "
|
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,
|
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_MATRIX_ADDR,
|
||||||
bag->lighting->lightMatrix, 3, false);
|
bag->lighting->lightMatrix, 3, false);
|
||||||
|
|
||||||
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_DIRS_ADDR,
|
packet2_utils_vu_add_unpack_data(
|
||||||
bag->lighting->getLightDirections(), 3,
|
objectDataPacket, VU1_LIGHTS_DIRS_ADDR,
|
||||||
false);
|
bag->lighting->dirLights->getLightDirections(), 3, false);
|
||||||
|
|
||||||
packet2_utils_vu_add_unpack_data(objectDataPacket, VU1_LIGHTS_COLORS_ADDR,
|
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;
|
u8 singleColorEnabled = bag->color->single != nullptr;
|
||||||
|
|||||||
@@ -65,8 +65,10 @@ void StaPipelineCore::render(StaPipBag* bag, StaPipBagPackagesBBox* bbox) {
|
|||||||
(!bag->color->many && bag->lighting),
|
(!bag->color->many && bag->lighting),
|
||||||
"Multicolor is not supported with lighting, please choose one!");
|
"Multicolor is not supported with lighting, please choose one!");
|
||||||
TYRA_ASSERT(
|
TYRA_ASSERT(
|
||||||
!bag->lighting || (bag->lighting->lightMatrix && bag->lighting->normals),
|
!bag->lighting || (bag->lighting->lightMatrix && bag->lighting->normals &&
|
||||||
"If you want lighting, please provide light matrix and normals!");
|
bag->lighting->dirLights),
|
||||||
|
"If you want lighting, please provide light matrix normals and dir "
|
||||||
|
"lights!");
|
||||||
TYRA_ASSERT(
|
TYRA_ASSERT(
|
||||||
!bag->texture || (bag->texture->texture && bag->texture->coordinates),
|
!bag->texture || (bag->texture->texture && bag->texture->coordinates),
|
||||||
"If you want texture, please provide texture and coordinates!");
|
"If you want texture, please provide texture and coordinates!");
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PipelineLightingBag* StaticPipeline::getLightingBag(
|
StaPipLightingBag* StaticPipeline::getLightingBag(
|
||||||
DynamicMesh* mesh, MeshMaterial* material, M4x4* model,
|
DynamicMesh* mesh, MeshMaterial* material, M4x4* model,
|
||||||
MeshFrame* frameFrom, MeshFrame* frameTo,
|
MeshFrame* frameFrom, MeshFrame* frameTo,
|
||||||
const StaPipOptions* options) const {
|
const StaPipOptions* options) const {
|
||||||
@@ -171,11 +171,14 @@ PipelineLightingBag* StaticPipeline::getLightingBag(
|
|||||||
options->lighting == nullptr)
|
options->lighting == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto* result = new PipelineLightingBag(true);
|
auto* result = new StaPipLightingBag();
|
||||||
|
auto* dirLightsBag = new PipelineDirLightsBag(true);
|
||||||
|
result->dirLights = dirLightsBag;
|
||||||
|
|
||||||
result->lightMatrix = model;
|
result->lightMatrix = model;
|
||||||
|
|
||||||
result->setLightsManually(colorsCache,
|
result->dirLights->setLightsManually(
|
||||||
options->lighting->directionalDirections);
|
colorsCache, options->lighting->directionalDirections);
|
||||||
|
|
||||||
result->normals = new Vec4[material->getFacesCount()];
|
result->normals = new Vec4[material->getFacesCount()];
|
||||||
|
|
||||||
@@ -215,6 +218,7 @@ void StaticPipeline::deallocDrawBags(StaPipBag* bag,
|
|||||||
|
|
||||||
if (bag->lighting) {
|
if (bag->lighting) {
|
||||||
delete[] bag->lighting->normals;
|
delete[] bag->lighting->normals;
|
||||||
|
delete bag->lighting->dirLights;
|
||||||
delete bag->lighting;
|
delete bag->lighting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user