spamming with multiple buffers to vu1

This commit is contained in:
h4570
2022-07-22 00:12:36 +02:00
parent c8592e0c67
commit c5aea0d50f
17 changed files with 382 additions and 360 deletions
@@ -25,21 +25,13 @@ void StaticPipeline::onUse() { core.reinitVU1Programs(); }
void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) {
auto model = mesh->getModelMatrix();
MeshFrame* frameFrom = mesh->getFramesCount() > 0
? mesh->getFrame(mesh->getCurrentAnimationFrame())
: mesh->getFrame(0);
MeshFrame* frameTo = mesh->getFramesCount() > 0
? mesh->getFrame(mesh->getNextAnimationFrame())
: nullptr;
auto* infoBag = getInfoBag(mesh, options, &model);
if (options && options->lighting) setLightingColorsCache(options->lighting);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i);
auto* materialFrame = material->getFrame(0);
// 2x bufory[maxVertCount*2] -> pętla po mniejszych częściach i czestsze
// rendery
@@ -50,12 +42,11 @@ void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) {
// material->getTextureCoordFaces());
StaPipBag bag;
addVertices(mesh, material, &bag, frameFrom, frameTo);
addVertices(materialFrame, &bag);
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);
bag.color = getColorBag(material, materialFrame);
bag.texture = getTextureBag(material, materialFrame);
bag.lighting = getLightingBag(materialFrame, &model, options);
core.render(&bag);
@@ -65,22 +56,10 @@ void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) {
delete infoBag;
}
void StaticPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material,
StaPipBag* bag, MeshFrame* frameFrom,
MeshFrame* frameTo) const {
bag->count = material->getFacesCount();
bag->vertices = new Vec4[bag->count];
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 StaticPipeline::addVertices(MeshMaterialFrame* materialFrame,
StaPipBag* bag) const {
bag->count = materialFrame->getVertexCount();
bag->vertices = materialFrame->getVertices();
}
PipelineInfoBag* StaticPipeline::getInfoBag(DynamicMesh* mesh,
@@ -105,39 +84,22 @@ PipelineInfoBag* StaticPipeline::getInfoBag(DynamicMesh* mesh,
return result;
}
StaPipColorBag* StaticPipeline::getColorBag(DynamicMesh* mesh,
MeshMaterial* material,
MeshFrame* frameFrom,
MeshFrame* frameTo) const {
StaPipColorBag* StaticPipeline::getColorBag(
MeshMaterial* material, MeshMaterialFrame* materialFrame) const {
auto* result = new StaPipColorBag();
if (material->isSingleColorActivated()) {
result->single = &material->singleColor;
result->single = &material->color;
} 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);
}
}
result->many = materialFrame->getColors();
}
return result;
}
StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh,
MeshMaterial* material,
MeshFrame* frameFrom,
MeshFrame* frameTo) {
if (!material->getTextureCoordFaces()) return nullptr;
StaPipTextureBag* StaticPipeline::getTextureBag(
MeshMaterial* material, MeshMaterialFrame* materialFrame) {
if (!materialFrame->getTextureCoords()) return nullptr;
auto* result = new StaPipTextureBag();
@@ -146,28 +108,15 @@ StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh,
TYRA_ASSERT(result->texture, "Texture for material id: ", material->getId(),
"was not found in texture repository!");
result->coordinates = new Vec4[material->getFacesCount()];
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);
}
}
result->coordinates = materialFrame->getTextureCoords();
return result;
}
StaPipLightingBag* StaticPipeline::getLightingBag(
DynamicMesh* mesh, MeshMaterial* material, M4x4* model,
MeshFrame* frameFrom, MeshFrame* frameTo,
MeshMaterialFrame* materialFrame, M4x4* model,
const StaPipOptions* options) const {
if (!material->getNormalFaces() || options == nullptr ||
if (!materialFrame->getNormals() || options == nullptr ||
options->lighting == nullptr)
return nullptr;
@@ -181,18 +130,7 @@ StaPipLightingBag* StaticPipeline::getLightingBag(
result->dirLights->setLightsManually(
colorsCache, options->lighting->directionalDirections);
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);
}
}
result->normals = materialFrame->getNormals();
return result;
}
@@ -208,22 +146,15 @@ void StaticPipeline::setLightingColorsCache(
void StaticPipeline::deallocDrawBags(StaPipBag* bag,
MeshMaterial* material) const {
if (bag->color->many) {
delete[] bag->color->many;
}
if (bag->texture) {
delete[] bag->texture->coordinates;
delete bag->texture;
}
if (bag->lighting) {
delete[] bag->lighting->normals;
delete bag->lighting->dirLights; // TODO
delete bag->lighting;
}
delete[] bag->vertices;
delete bag->color;
}