dynamic pipeline - render

This commit is contained in:
h4570
2022-07-21 17:47:10 +02:00
parent 4e0785754e
commit 2c72abe081
28 changed files with 382 additions and 256 deletions
@@ -22,13 +22,8 @@ class DynPipColorBag {
DynPipColorBag();
~DynPipColorBag();
/** Optional. Single color for all vertices. */
Color* singleFrom;
Color* singleTo;
/** Optional. Color per vertex. */
Color* manyFrom;
Color* manyTo;
/** Mandatory */
Color* single;
};
} // namespace Tyra
@@ -29,6 +29,8 @@ class DynPipLightingBag {
/** Mandatory. Directional lights */
PipelineDirLightsBag* dirLights;
void freeNormals();
};
} // namespace Tyra
@@ -26,6 +26,8 @@ class DynPipTextureBag {
/** Mandatory. Texture image. */
Texture* texture;
void freeCoords();
};
} // namespace Tyra
@@ -13,6 +13,8 @@
#include <tamtypes.h>
#include "./bag/dynpip_bag.hpp"
#include "renderer/core/renderer_core.hpp"
#include "./dynpip_programs_repository.hpp"
#include "./dynpip_qbuffer_renderer.hpp"
namespace Tyra {
@@ -21,11 +23,18 @@ class DynPipCore {
DynPipCore();
~DynPipCore();
DynPipProgramsRepository repository;
void init(RendererCore* t_core);
/** Render 3D via "bags" */
void render(DynPipBag* data);
/** Get max vert count of VU1 qbuffer (for optimizations) */
u32 getMaxVertCountByParams(const bool& isSingleColor,
const bool& isLightingEnabled,
const bool& isTextureEnabled);
/**
* - Uploads standard VU1 programs.
* - Sends static "Tyra Renderer3D" VU1 data.
@@ -36,6 +45,7 @@ class DynPipCore {
private:
RendererCore* rendererCore;
DynPipQBufferRenderer qbufferRenderer;
};
} // namespace Tyra
@@ -12,6 +12,7 @@
#include "debug/debug.hpp"
#include "renderer/core/paths/path1/vu1_program.hpp"
#include "./bag/dynpip_bag.hpp"
#include "./programs/dynpip_c_vu1_program.hpp"
#include "./programs/dynpip_d_vu1_program.hpp"
@@ -26,6 +27,9 @@ class DynPipProgramsRepository {
~DynPipProgramsRepository();
DynPipVU1Program* getProgram(const DynPipProgramName& name);
DynPipVU1Program* getProgramByParams(const bool& isLightingEnabled,
const bool& isTextureEnabled);
DynPipVU1Program* getProgramByBag(const DynPipBag* bag);
private:
DynPipCVU1Program color;
@@ -29,9 +29,6 @@ class DynPipQBuffer {
Vec4* stsFrom;
Vec4* stsTo;
Vec4* colorsFrom;
Vec4* colorsTo;
Vec4* normalsFrom;
Vec4* normalsTo;
@@ -0,0 +1,68 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <tamtypes.h>
namespace Tyra {
class DynPipQBufferRenderer {
public:
DynPipQBufferRenderer();
~DynPipQBufferRenderer();
// void init(RendererCore* t_core);
// void reinitVU1();
// DynPipQBuffer* getBuffer();
// void sendObjectData(DynPipBag* bag, M4x4* mvp,
// RendererCoreTextureBuffers* texBuffers) const;
// void setMaxVertCount(const u32& count);
// void setInfo(PipelineInfoBag* bag);
// void render(DynPipQBuffer* buffer);
// void clearLastProgramName();
const u16& getBufferSize() { return bufferSize; }
private:
// void sendStaticData() const;
// void setProgramsCache();
// void uploadPrograms();
// void setDoubleBuffer();
// void addBufferDataToPacket(DynPipVU1Program* program, DynPipQBuffer*
// buffer); void sendPacket();
// packet2_t* packets[2];
// packet2_t* programsPacket;
// DynPipQBuffer buffers[2];
// packet2_t* currentPacket;
// packet2_t* staticDataPacket;
// packet2_t* objectDataPacket;
// RendererCore* rendererCore;
// DynPipProgramName lastProgramName;
// Path1* path1;
// DynPipClipper clipper;
// DynPipProgramsRepository repository;
u16 bufferSize;
// u8 context;
};
} // namespace Tyra
@@ -41,20 +41,27 @@ class DynamicPipeline : public Renderer3DPipeline {
Vec4* colorsCache;
void addVertices(DynamicMesh* mesh, MeshMaterial* material, DynPipBag* bag,
MeshFrame* frameFrom, MeshFrame* frameTo) const;
MeshFrame* frameFrom, MeshFrame* frameTo,
const u32& startIndex) const;
PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options,
M4x4* model) const;
DynPipColorBag* getColorBag(DynamicMesh* mesh, MeshMaterial* material,
MeshFrame* frameFrom, MeshFrame* frameTo) const;
DynPipColorBag* getColorBag(MeshMaterial* material) const;
DynPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material,
MeshFrame* frameFrom, MeshFrame* frameTo);
MeshFrame* frameFrom, MeshFrame* frameTo,
const u32& count, const u32& startIndex);
DynPipLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material,
M4x4* model, MeshFrame* frameFrom,
MeshFrame* frameTo,
const DynPipOptions* options) const;
void deallocDrawBags(DynPipBag* bag, MeshMaterial* material) const;
const DynPipOptions* options,
PipelineDirLightsBag* dirLightsBag,
const u32& count,
const u32& startIndex) const;
void setLightingColorsCache(PipelineLightingOptions* lightingOptions);
void freeBuffer(DynPipBag* bag);
void setBuffersDefaultVars(DynPipBag* buffers, DynamicMesh* mesh,
PipelineInfoBag* infoBag);
void setBuffersColorBag(DynPipBag* buffers, DynPipColorBag* colorBag);
};
} // namespace Tyra
@@ -10,22 +10,14 @@
#pragma once
#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp"
#include "../shared/pipeline_lighting_options.hpp"
#include "renderer/3d/pipeline/shared/pipeline_options.hpp"
namespace Tyra {
class DynPipOptions {
class DynPipOptions : public PipelineOptions {
public:
DynPipOptions() {}
~DynPipOptions() {}
PipelineShadingType shadingType;
bool blendingEnabled;
bool antiAliasingEnabled;
/** Optional */
PipelineLightingOptions* lighting;
};
} // namespace Tyra
@@ -0,0 +1,31 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# 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/pipeline_shading_type.hpp"
#include "../shared/pipeline_lighting_options.hpp"
namespace Tyra {
class PipelineOptions {
public:
PipelineOptions() {}
~PipelineOptions() {}
PipelineShadingType shadingType;
bool blendingEnabled;
bool antiAliasingEnabled;
/** Optional */
PipelineLightingOptions* lighting;
};
} // namespace Tyra
@@ -10,20 +10,15 @@
#pragma once
#include "renderer/3d/pipeline/shared/pipeline_shading_type.hpp"
#include "../shared/pipeline_lighting_options.hpp"
#include "renderer/3d/pipeline/shared/pipeline_options.hpp"
namespace Tyra {
class StaPipOptions {
class StaPipOptions : public PipelineOptions {
public:
StaPipOptions() {}
~StaPipOptions() {}
PipelineShadingType shadingType;
bool blendingEnabled;
bool antiAliasingEnabled;
/**
* @brief True -> disables "clip against each plane" algorithm.
* Mandatory, default: false.
@@ -33,9 +28,6 @@ class StaPipOptions {
* for big 3D objects (or objects near camera eyes)
*/
bool noFullClipChecks;
/** Optional */
PipelineLightingOptions* lighting;
};
} // namespace Tyra
@@ -36,31 +36,19 @@ class TextureRepository {
* For 3D: MeshMaterial id.
* For 2D: Sprite id.
*/
Texture* getBySpriteOrMesh(const u32& t_id) {
for (u32 i = 0; i < textures.size(); i++)
if (textures[i]->isLinkedWith(t_id)) return textures[i];
return nullptr;
}
Texture* getBySpriteOrMesh(const u32& t_id) const;
/**
* Returns single texture.
* nullptr if not found.
*/
Texture* getByTextureId(const u32& t_id) const {
for (u32 i = 0; i < textures.size(); i++)
if (t_id == textures[i]->getId()) return textures[i];
return nullptr;
}
Texture* getByTextureId(const u32& t_id) const;
/**
* Returns index of link.
* -1 if not found.
*/
const s32 getIndexOf(const u32& t_texId) const {
for (u32 i = 0; i < textures.size(); i++)
if (textures[i]->getId() == t_texId) return i;
return -1;
}
const s32 getIndexOf(const u32& t_texId) const;
// ----
// Setters
@@ -19,6 +19,8 @@ DynPipBag::DynPipBag() {
color = nullptr;
texture = nullptr;
lighting = nullptr;
verticesFrom = nullptr;
verticesTo = nullptr;
}
DynPipBag::~DynPipBag() {}
@@ -56,16 +58,8 @@ 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->singleFrom) {
res << "Color from single: " << color->singleFrom->getPrint() << ", "
<< std::endl;
res << "Color to single: " << color->singleTo->getPrint() << ", "
<< std::endl;
} else {
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 (color->single) {
res << "Color single: " << color->single->getPrint() << ", " << std::endl;
}
if (texture) {
res << "Texture coords from present: "
@@ -12,12 +12,7 @@
namespace Tyra {
DynPipColorBag::DynPipColorBag() {
singleFrom = nullptr;
singleTo = nullptr;
manyFrom = nullptr;
manyTo = nullptr;
}
DynPipColorBag::DynPipColorBag() { single = nullptr; }
DynPipColorBag::~DynPipColorBag() {}
@@ -21,4 +21,9 @@ DynPipLightingBag::DynPipLightingBag() {
DynPipLightingBag::~DynPipLightingBag() {}
void DynPipLightingBag::freeNormals() {
if (normalsFrom) delete[] normalsFrom;
if (normalsTo) delete[] normalsTo;
}
} // namespace Tyra
@@ -20,4 +20,9 @@ DynPipTextureBag::DynPipTextureBag() {
DynPipTextureBag::~DynPipTextureBag() {}
void DynPipTextureBag::freeCoords() {
if (coordinatesFrom) delete[] coordinatesFrom;
if (coordinatesTo) delete[] coordinatesTo;
}
} // namespace Tyra
@@ -22,6 +22,16 @@ void DynPipCore::init(RendererCore* t_core) { rendererCore = t_core; }
void DynPipCore::reinitVU1Programs() {}
void DynPipCore::render(DynPipBag* bag) {}
u32 DynPipCore::getMaxVertCountByParams(const bool& isSingleColor,
const bool& isLightingEnabled,
const bool& isTextureEnabled) {
return repository.getProgramByParams(isLightingEnabled, isTextureEnabled)
->getMaxVertCount(isSingleColor, qbufferRenderer.getBufferSize());
}
void DynPipCore::render(DynPipBag* bag) {
// Zrobic bbox
// TODO: Potem wrzucic programy i obliczyc bufferSize w qbufferrenderer
}
} // namespace Tyra
@@ -16,6 +16,18 @@ DynPipProgramsRepository::DynPipProgramsRepository() {}
DynPipProgramsRepository::~DynPipProgramsRepository() {}
DynPipVU1Program* DynPipProgramsRepository::getProgramByParams(
const bool& isLightingEnabled, const bool& isTextureEnabled) {
if (isLightingEnabled && isTextureEnabled)
return &textureDirLights;
else if (isLightingEnabled)
return &dirLights;
else if (isTextureEnabled)
return &textureColor;
else
return &color;
}
DynPipVU1Program* DynPipProgramsRepository::getProgram(
const DynPipProgramName& name) {
switch (name) {
@@ -59,18 +59,6 @@ std::string DynPipQBuffer::getPrint(const char* name) const {
res << i << ": " << stsTo[i].getPrint() << std::endl;
}
if (bag->color->manyFrom != nullptr) {
res << "Colors from: " << std::endl;
for (u32 i = 0; i < size; i++)
res << i << ": " << colorsFrom[i].getPrint() << std::endl;
}
if (bag->color->manyTo != nullptr) {
res << "Colors to: " << std::endl;
for (u32 i = 0; i < size; i++)
res << i << ": " << colorsTo[i].getPrint() << std::endl;
}
if (bag->lighting != nullptr) {
res << "Normals from: " << std::endl;
for (u32 i = 0; i < size; i++) {
@@ -0,0 +1,19 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# 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/core/dynpip_qbuffer_renderer.hpp"
#include "renderer/3d/pipeline/dynamic/core/programs/dynpip_vu1_shared_defines.h"
namespace Tyra {
DynPipQBufferRenderer::DynPipQBufferRenderer() {}
DynPipQBufferRenderer::~DynPipQBufferRenderer() {}
} // namespace Tyra
@@ -56,14 +56,6 @@ void DynPipTDVU1Program::addProgramQBufferDataToPacket(
packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->normalsTo,
qbuffer->size, true);
addr += qbuffer->size;
// Add colors
if (qbuffer->bag->color->singleFrom == nullptr) {
packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->colorsFrom,
qbuffer->size, true);
packet2_utils_vu_add_unpack_data(packet, addr, qbuffer->colorsTo,
qbuffer->size, true);
}
}
} // namespace Tyra
@@ -12,72 +12,108 @@
namespace Tyra {
DynamicPipeline::DynamicPipeline() {}
DynamicPipeline::DynamicPipeline() { colorsCache = new Vec4[4]; }
DynamicPipeline::~DynamicPipeline() {}
DynamicPipeline::~DynamicPipeline() { delete[] colorsCache; }
void DynamicPipeline::init(RendererCore* t_core) {}
void DynamicPipeline::init(RendererCore* t_core) { rendererCore = t_core; }
void DynamicPipeline::onUse() {}
void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
auto model = mesh->getModelMatrix();
auto* frameFrom = mesh->getFrame(mesh->getCurrentAnimationFrame());
auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame());
auto* infoBag = getInfoBag(mesh, options, &model);
PipelineDirLightsBag* dirLights = nullptr;
MeshFrame* frameFrom = mesh->getFramesCount() > 0
? mesh->getFrame(mesh->getCurrentAnimationFrame())
: mesh->getFrame(0);
if (options && options->lighting) {
setLightingColorsCache(options->lighting);
dirLights = new PipelineDirLightsBag(true);
dirLights->setLightsManually(colorsCache,
options->lighting->directionalDirections);
}
MeshFrame* frameTo = mesh->getFramesCount() > 0
? mesh->getFrame(mesh->getNextAnimationFrame())
: nullptr;
DynPipBag buffers[2];
u8 context = 0;
// auto* infoBag = getInfoBag(mesh, options, &model);
if (options && options->lighting) setLightingColorsCache(options->lighting);
setBuffersDefaultVars(buffers, mesh, infoBag);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i);
auto partSize = core.getMaxVertCountByParams(
material->isSingleColorActivated(), options && options->lighting,
material->getTextureCoordFaces());
u32 partsCount =
ceil(material->getFacesCount() / static_cast<float>(partSize));
auto* colorBag = getColorBag(material);
setBuffersColorBag(buffers, colorBag);
// 2x bufory[maxVertCount*2] -> pętla po mniejszych częściach i czestsze
// rendery
for (u32 j = 0; j < partsCount; j++) {
auto& buffer = buffers[context];
// TODO: Double buffering in future
// auto maxVertCount = core->renderer3D.getMaxVertCountByParams(
// material->isSingleColorActivated(), material->getNormalFaces(),
// material->getTextureCoordFaces());
freeBuffer(&buffer);
buffer.count = j == partsCount - 1
? material->getFacesCount() - j * partSize
: partSize;
DynPipBag bag;
addVertices(mesh, material, &bag, frameFrom, frameTo);
// bag.info = infoBag;
// bag.color = getColorBag(mesh, material, frameFrom, frameTo);
// bag.texture = getTextureBag(mesh, material, frameFrom, frameTo);
// bag.lighting =
// getLightingBag(mesh, material, &model, frameFrom, frameTo, options);
u32 startIndex = j * partSize;
core.render(&bag);
addVertices(mesh, material, &buffer, frameFrom, frameTo, startIndex);
buffer.texture = getTextureBag(mesh, material, frameFrom, frameTo,
buffer.count, startIndex);
buffer.lighting =
getLightingBag(mesh, material, &model, frameFrom, frameTo, options,
dirLights, buffer.count, startIndex);
// deallocDrawBags(&bag, material);
core.render(&buffer);
context = !context;
}
freeBuffer(&buffers[context]);
freeBuffer(&buffers[!context]);
delete colorBag;
}
// delete infoBag; // TODO
delete infoBag;
}
void DynamicPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material,
DynPipBag* bag, MeshFrame* frameFrom,
MeshFrame* frameTo) const {
// bag->count = material->getFacesCount();
// bag->vertices = new Vec4[bag->count];
void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers,
DynamicMesh* mesh,
PipelineInfoBag* infoBag) {
for (int i = 0; i < 2; i++) {
buffers[i].info = infoBag;
buffers[i].interpolation = mesh->getAnimState().interpolation;
}
}
// for (u32 i = 0; i < bag->count; i++) {
// auto& face = material->getVertexFaces()[i];
// if (frameTo == nullptr) {
// bag->vertices[i] = frameFrom->getVertices()[face];
// } else {
// Vec4::setLerp(&bag->vertices[i], frameFrom->getVertices()[face],
// frameTo->getVertices()[face],
// mesh->getAnimState().interpolation);
// }
// }
void DynamicPipeline::setBuffersColorBag(DynPipBag* buffers,
DynPipColorBag* colorBag) {
for (int i = 0; i < 2; i++) {
buffers[i].color = colorBag;
}
}
void DynamicPipeline::freeBuffer(DynPipBag* bag) {
if (bag->texture) {
bag->texture->freeCoords();
delete bag->texture;
}
if (bag->lighting) {
bag->lighting->freeNormals();
delete bag->lighting;
}
if (bag->verticesFrom) {
delete[] bag->verticesFrom;
}
if (bag->verticesTo) {
delete[] bag->verticesTo;
}
}
PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
@@ -100,99 +136,71 @@ PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
return result;
}
DynPipColorBag* DynamicPipeline::getColorBag(DynamicMesh* mesh,
MeshMaterial* material,
MeshFrame* frameFrom,
MeshFrame* frameTo) const {
// auto* result = new DynPipColorBag();
void DynamicPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material,
DynPipBag* bag, MeshFrame* frameFrom,
MeshFrame* frameTo,
const u32& startIndex) const {
bag->verticesFrom = new Vec4[bag->count];
bag->verticesTo = new Vec4[bag->count];
// if (material->isSingleColorActivated()) {
// result->single = &material->singleColor;
// } else {
// result->many = new Color[material->getFacesCount()];
// for (u32 i = 0; i < material->getFacesCount(); i++) {
// auto& face = material->getColorFaces()[i];
// if (frameTo == nullptr) {
// result->many[i] = frameFrom->getColors()[face];
// } else {
// Vec4::setLerp(
// reinterpret_cast<Vec4*>(&result->many[i]),
// reinterpret_cast<const Vec4&>(frameFrom->getColors()[face]),
// reinterpret_cast<const Vec4&>(frameTo->getColors()[face]),
// mesh->getAnimState().interpolation);
// }
// }
// }
// return result;
return nullptr; // TODO
for (u32 i = startIndex; i < startIndex + bag->count; i++) {
auto& face = material->getVertexFaces()[i];
bag->verticesFrom[i] = frameFrom->getVertices()[face];
bag->verticesTo[i] = frameTo->getVertices()[face];
}
}
DynPipTextureBag* DynamicPipeline::getTextureBag(DynamicMesh* mesh,
MeshMaterial* material,
MeshFrame* frameFrom,
MeshFrame* frameTo) {
// if (!material->getTextureCoordFaces()) return nullptr;
DynPipColorBag* DynamicPipeline::getColorBag(MeshMaterial* material) const {
auto* result = new DynPipColorBag();
result->single = &material->singleColor;
return result;
}
// auto* result = new DynPipTextureBag();
DynPipTextureBag* DynamicPipeline::getTextureBag(
DynamicMesh* mesh, MeshMaterial* material, MeshFrame* frameFrom,
MeshFrame* frameTo, const u32& count, const u32& startIndex) {
if (!material->getTextureCoordFaces()) return nullptr;
// result->texture =
// rendererCore->texture.repository.getBySpriteOrMesh(material->getId());
// TYRA_ASSERT(result->texture, "Texture for material id: ",
// material->getId(),
// " was not found in texture repository!");
auto* result = new DynPipTextureBag();
result->texture =
rendererCore->texture.repository.getBySpriteOrMesh(material->getId());
TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(),
"was not found in texture repository!");
// result->coordinates = new Vec4[material->getFacesCount()];
result->coordinatesFrom = new Vec4[count];
result->coordinatesTo = new Vec4[count];
// for (u32 i = 0; i < material->getFacesCount(); i++) {
// auto& face = material->getTextureCoordFaces()[i];
// if (frameTo == nullptr) {
// result->coordinates[i] = frameFrom->getTextureCoords()[face];
// } else {
// Vec4::setLerp(&result->coordinates[i],
// frameFrom->getTextureCoords()[face],
// frameTo->getTextureCoords()[face],
// mesh->getAnimState().interpolation);
// }
// }
for (u32 i = startIndex; i < startIndex + count; i++) {
auto& face = material->getTextureCoordFaces()[i];
result->coordinatesFrom[i] = frameFrom->getTextureCoords()[face];
result->coordinatesTo[i] = frameTo->getTextureCoords()[face];
}
// return result;
return nullptr; // TODO
return result;
}
DynPipLightingBag* DynamicPipeline::getLightingBag(
DynamicMesh* mesh, MeshMaterial* material, M4x4* model,
MeshFrame* frameFrom, MeshFrame* frameTo,
const DynPipOptions* options) const {
// if (!material->getNormalFaces() || options == nullptr ||
// options->lighting == nullptr)
// return nullptr;
MeshFrame* frameFrom, MeshFrame* frameTo, const DynPipOptions* options,
PipelineDirLightsBag* dirLightsBag, const u32& count,
const u32& startIndex) const {
if (!material->getNormalFaces() || options == nullptr ||
options->lighting == nullptr)
return nullptr;
// auto* result = new DynPipLightingBag();
// auto* dirLightsBag = new PipelineDirLightsBag(true);
// result->dirLights = dirLightsBag;
auto* result = new DynPipLightingBag();
// result->lightMatrix = model;
result->lightMatrix = model;
result->normalsFrom = new Vec4[count];
result->normalsTo = new Vec4[count];
// result->dirLights->setLightsManually(
// colorsCache, options->lighting->directionalDirections);
for (u32 i = startIndex; i < startIndex + count; i++) {
auto& face = material->getNormalFaces()[i];
result->normalsFrom[i] = frameFrom->getNormals()[face];
result->normalsTo[i] = frameTo->getNormals()[face];
}
// result->normals = new Vec4[material->getFacesCount()];
// for (u32 i = 0; i < material->getFacesCount(); i++) {
// auto& face = material->getNormalFaces()[i];
// if (frameTo == nullptr) {
// result->normals[i] = frameFrom->getNormals()[face];
// } else {
// Vec4::setLerp(&result->normals[i], frameFrom->getNormals()[face],
// frameTo->getNormals()[face],
// mesh->getAnimState().interpolation);
// }
// }
// return result;
return nullptr; // TODO
return result;
}
void DynamicPipeline::setLightingColorsCache(
@@ -204,29 +212,4 @@ void DynamicPipeline::setLightingColorsCache(
colorsCache[3] = reinterpret_cast<Vec4&>(*lightingOptions->ambientColor);
}
void DynamicPipeline::deallocDrawBags(DynPipBag* bag,
MeshMaterial* material) const {
if (bag->color->manyFrom) {
delete[] bag->color->manyFrom;
delete[] bag->color->manyTo;
}
if (bag->texture) {
delete[] bag->texture->coordinatesFrom;
delete[] bag->texture->coordinatesTo;
delete bag->texture;
}
if (bag->lighting) {
delete[] bag->lighting->normalsFrom;
delete[] bag->lighting->normalsTo;
delete bag->lighting->dirLights;
delete bag->lighting;
}
delete[] bag->verticesFrom;
delete[] bag->verticesTo;
delete bag->color;
}
} // namespace Tyra
@@ -144,7 +144,7 @@ StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh,
result->texture =
rendererCore->texture.repository.getBySpriteOrMesh(material->getId());
TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(),
" was not found in texture repository!");
"was not found in texture repository!");
result->coordinates = new Vec4[material->getFacesCount()];
@@ -172,7 +172,8 @@ StaPipLightingBag* StaticPipeline::getLightingBag(
return nullptr;
auto* result = new StaPipLightingBag();
auto* dirLightsBag = new PipelineDirLightsBag(true);
auto* dirLightsBag = new PipelineDirLightsBag(true); // TODO: 1 dir
// lights per obiekt, dealokowac recznie
result->dirLights = dirLightsBag;
result->lightMatrix = model;
@@ -218,7 +219,7 @@ void StaticPipeline::deallocDrawBags(StaPipBag* bag,
if (bag->lighting) {
delete[] bag->lighting->normals;
delete bag->lighting->dirLights;
delete bag->lighting->dirLights; // TODO
delete bag->lighting;
}
@@ -162,10 +162,15 @@ std::string Texture::getPrint(const char* objectName) const {
else if (wrap.horizontal == WRAP_CLAMP)
wrapString = "WRAP_CLAMP";
res << "id: " << id << ", ";
res << "name: " << name << ", ";
res << "core: " << core->getPrint() << ", ";
if (clut != nullptr) res << "clut: " << clut->getPrint() << ", ";
res << "id: " << id << ", " << std::endl;
res << "name: " << name << ", " << std::endl;
res << "core: " << core->getPrint() << ", " << std::endl;
if (clut != nullptr) res << "clut: " << clut->getPrint() << ", " << std::endl;
if (links.size()) {
for (size_t i = 0; i < links.size(); i++) {
res << "link " << i << " for id: " << links[i].id << ", " << std::endl;
}
}
res << "wrap: " << wrapString << ")";
return res.str();
}
@@ -22,9 +22,24 @@ TextureRepository::~TextureRepository() {
}
}
// ----
// Methods
// ----
Texture* TextureRepository::getBySpriteOrMesh(const u32& t_id) const {
for (u32 i = 0; i < textures.size(); i++) {
if (textures[i]->isLinkedWith(t_id)) return textures[i];
}
return nullptr;
}
Texture* TextureRepository::getByTextureId(const u32& t_id) const {
for (u32 i = 0; i < textures.size(); i++)
if (t_id == textures[i]->getId()) return textures[i];
return nullptr;
}
const s32 TextureRepository::getIndexOf(const u32& t_texId) const {
for (u32 i = 0; i < textures.size(); i++)
if (textures[i]->getId() == t_texId) return i;
return -1;
}
Texture* TextureRepository::add(Texture* texture) {
textures.push_back(texture);