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
+1 -12
View File
@@ -23,18 +23,9 @@ class MeshFrame {
~MeshFrame(); ~MeshFrame();
const u32& getId() const { return id; } const u32& getId() const { return id; }
const u32& getVertexCount() const { return vertexCount; }
const u32& getTextureCoordsCount() const { return textureCoordsCount; }
const u32& getNormalsCount() const { return normalsCount; }
const u32& getColorsCount() const { return colorsCount; }
const u8& isMother() const { return _isMother; } const u8& isMother() const { return _isMother; }
const BBox& getBBox() const { return *bbox; } const BBox& getBBox() const { return *bbox; }
Vec4* getVertices() const { return vertices; }
Vec4* getNormals() const { return normals; }
Vec4* getTextureCoords() const { return textureCoords; }
Color* getColors() const { return colors; }
void print() const; void print() const;
void print(const char* name) const; void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); } void print(const std::string& name) const { print(name.c_str()); }
@@ -43,9 +34,7 @@ class MeshFrame {
private: private:
u8 _isMother; u8 _isMother;
BBox* bbox; BBox* bbox;
u32 id, vertexCount, textureCoordsCount, normalsCount, colorsCount; u32 id;
Vec4 *vertices, *textureCoords, *normals;
Color* colors;
}; };
} // namespace Tyra } // namespace Tyra
+9 -10
View File
@@ -22,18 +22,18 @@ class MeshMaterial {
explicit MeshMaterial(const MeshMaterial& material); explicit MeshMaterial(const MeshMaterial& material);
~MeshMaterial(); ~MeshMaterial();
Color singleColor; Color color;
const u32& getId() const { return id; } const u32& getId() const { return id; }
const std::string& getName() const { return _name; } const std::string& getName() const { return _name; }
const u32& getFacesCount() const { return facesCount; }
const u8& isMother() const { return _isMother; } const u8& isMother() const { return _isMother; }
const u8& isSingleColorActivated() const { return singleColorFlag; } const u32& getFramesCount() const { return framesCount; }
u32* getVertexFaces() const { return vertexFaces; } const u8& isSingleColorActivated() const {
u32* getTextureCoordFaces() const { return textureCoordFaces; } return singleColorFlag;
u32* getNormalFaces() const { return normalFaces; } } // TODO: colormode -> color / lightmap
u32* getColorFaces() const { return normalFaces; }
MeshMaterialFrame* getFrames() const { return *frames; } MeshMaterialFrame** getFrames() const { return frames; }
MeshMaterialFrame* getFrame(const u32& i) const { return frames[i]; }
const BBox& getBBox(const u32& frame) const; const BBox& getBBox(const u32& frame) const;
void setSingleColorFlag(const u8& flag); void setSingleColorFlag(const u8& flag);
@@ -48,8 +48,7 @@ class MeshMaterial {
std::string _name; std::string _name;
u8 _isMother, singleColorFlag; u8 _isMother, singleColorFlag;
u32 id, facesCount, framesCount; u32 id, framesCount;
u32 *vertexFaces, *textureCoordFaces, *normalFaces, *colorFaces;
}; };
} // namespace Tyra } // namespace Tyra
@@ -26,11 +26,33 @@ class MeshMaterialFrame {
const u8& isMother() const { return _isMother; } const u8& isMother() const { return _isMother; }
const BBox& getBBox() const { return *bbox; } const BBox& getBBox() const { return *bbox; }
const u32& getVertexCount() const { return vertexCount; }
Vec4* getVertices() const { return vertices; }
Vec4* getNormals() const { return normals; }
Vec4* getTextureCoords() const { return textureCoords; }
Color* getColors() const { return colors; }
void print() const;
void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
private: private:
void allocateVertices(const MeshBuilderData& data, const u32& frameIndex,
const u32& materialIndex);
void allocateTextureCoords(const MeshBuilderData& data, const u32& frameIndex,
const u32& materialIndex);
void allocateNormals(const MeshBuilderData& data, const u32& frameIndex,
const u32& materialIndex);
void allocateColors(const MeshBuilderData& data, const u32& frameIndex,
const u32& materialIndex);
BBox* bbox; BBox* bbox;
u8 _isMother; u8 _isMother;
u32 id; u32 id, vertexCount;
Vec4 *vertices, *textureCoords, *normals;
Color* colors;
}; };
} // namespace Tyra } // namespace Tyra
@@ -36,6 +36,9 @@ class DynPipCore {
*/ */
void initParts(DynPipBag* data); void initParts(DynPipBag* data);
// TODO: TEST!
void renderTEST(DynPipBag** bags, const u32& count);
/** Render 3D via "bags" */ /** Render 3D via "bags" */
void renderPart(DynPipBag* data, const bool& frustumCull = true); void renderPart(DynPipBag* data, const bool& frustumCull = true);
@@ -29,6 +29,7 @@ class DynPipRenderer {
RendererCoreTextureBuffers* texBuffers) const; RendererCoreTextureBuffers* texBuffers) const;
void render(DynPipBag* bag); void render(DynPipBag* bag);
void renderTEST(DynPipBag** bags, const u32& count);
void clearLastProgramName(); void clearLastProgramName();
@@ -40,6 +41,8 @@ class DynPipRenderer {
void uploadPrograms(); void uploadPrograms();
void setDoubleBuffer(); void setDoubleBuffer();
void addBufferDataToPacketTEST(DynPipVU1Program* program, DynPipBag** bags,
const u32& count);
void addBufferDataToPacket(DynPipVU1Program* program, DynPipBag* bag); void addBufferDataToPacket(DynPipVU1Program* program, DynPipBag* bag);
void sendPacket(); void sendPacket();
@@ -40,21 +40,24 @@ class DynamicPipeline : public Renderer3DPipeline {
RendererCore* rendererCore; RendererCore* rendererCore;
Vec4* colorsCache; Vec4* colorsCache;
void addVertices(DynamicMesh* mesh, MeshMaterial* material, DynPipBag* bag, void addVertices(MeshMaterialFrame* materialFrameFrom,
MeshFrame* frameFrom, MeshFrame* frameTo, MeshMaterialFrame* materialFrameTo, DynPipBag* bag,
const u32& startIndex) const; const u32& startIndex) const;
PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options, PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const DynPipOptions* options,
M4x4* model) const; M4x4* model) const;
DynPipColorBag* getColorBag(MeshMaterial* material) const; DynPipColorBag* getColorBag(MeshMaterial* material) const;
DynPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material,
MeshFrame* frameFrom, MeshFrame* frameTo, DynPipTextureBag* getTextureBag(MeshMaterial* material,
const u32& count, const u32& startIndex); MeshMaterialFrame* materialFrameFrom,
DynPipLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material, MeshMaterialFrame* materialFrameTo,
M4x4* model, MeshFrame* frameFrom, const u32& startIndex);
MeshFrame* frameTo,
const DynPipOptions* options, DynPipLightingBag* getLightingBag(MeshMaterialFrame* materialFrameFrom,
MeshMaterialFrame* materialFrameTo,
M4x4* model, const DynPipOptions* options,
PipelineDirLightsBag* dirLightsBag, PipelineDirLightsBag* dirLightsBag,
const u32& count,
const u32& startIndex) const; const u32& startIndex) const;
void setLightingColorsCache(PipelineLightingOptions* lightingOptions); void setLightingColorsCache(PipelineLightingOptions* lightingOptions);
@@ -41,18 +41,21 @@ class StaticPipeline : public Renderer3DPipeline {
RendererCore* rendererCore; RendererCore* rendererCore;
Vec4* colorsCache; Vec4* colorsCache;
void addVertices(DynamicMesh* mesh, MeshMaterial* material, StaPipBag* bag, void addVertices(MeshMaterialFrame* materialFrame, StaPipBag* bag) const;
MeshFrame* frameFrom, MeshFrame* frameTo) const;
PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const StaPipOptions* options, PipelineInfoBag* getInfoBag(DynamicMesh* mesh, const StaPipOptions* options,
M4x4* model) const; M4x4* model) const;
StaPipColorBag* getColorBag(DynamicMesh* mesh, MeshMaterial* material,
MeshFrame* frameFrom, MeshFrame* frameTo) const; StaPipColorBag* getColorBag(MeshMaterial* material,
StaPipTextureBag* getTextureBag(DynamicMesh* mesh, MeshMaterial* material, MeshMaterialFrame* materialFrame) const;
MeshFrame* frameFrom, MeshFrame* frameTo);
StaPipLightingBag* getLightingBag(DynamicMesh* mesh, MeshMaterial* material, StaPipTextureBag* getTextureBag(MeshMaterial* material,
M4x4* model, MeshFrame* frameFrom, MeshMaterialFrame* materialFrame);
MeshFrame* frameTo,
StaPipLightingBag* getLightingBag(MeshMaterialFrame* materialFrame,
M4x4* model,
const StaPipOptions* options) const; const StaPipOptions* options) const;
void deallocDrawBags(StaPipBag* bag, MeshMaterial* material) const; void deallocDrawBags(StaPipBag* bag, MeshMaterial* material) const;
void setLightingColorsCache(PipelineLightingOptions* lightingOptions); void setLightingColorsCache(PipelineLightingOptions* lightingOptions);
@@ -24,7 +24,20 @@ MeshBuilderFrameData::MeshBuilderFrameData() {
colorsCount = 0; colorsCount = 0;
} }
MeshBuilderFrameData::~MeshBuilderFrameData() {} MeshBuilderFrameData::~MeshBuilderFrameData() {
if (vertices) {
delete[] vertices;
}
if (normals) {
delete[] normals;
}
if (textureCoords) {
delete[] textureCoords;
}
if (colors) {
delete[] colors;
}
}
void MeshBuilderFrameData::allocateTextureCoords(const u32& count) { void MeshBuilderFrameData::allocateTextureCoords(const u32& count) {
textureCoordsCount = count; textureCoordsCount = count;
@@ -22,7 +22,20 @@ MeshBuilderMaterialData::MeshBuilderMaterialData() {
count = 0; count = 0;
} }
MeshBuilderMaterialData::~MeshBuilderMaterialData() {} MeshBuilderMaterialData::~MeshBuilderMaterialData() {
if (vertexFaces) {
delete[] vertexFaces;
}
if (textureCoordFaces) {
delete[] textureCoordFaces;
}
if (normalFaces) {
delete[] normalFaces;
}
if (colorFaces) {
delete[] colorFaces;
}
}
void MeshBuilderMaterialData::allocateFaces(const u32& t_count) { void MeshBuilderMaterialData::allocateFaces(const u32& t_count) {
vertexFaces = new u32[t_count]; vertexFaces = new u32[t_count];
@@ -25,38 +25,6 @@ MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) {
id = rand() % 1000000; id = rand() % 1000000;
vertices = data.frames[index]->vertices;
TYRA_ASSERT(vertices != nullptr, "Vertices are required");
vertexCount = data.frames[index]->verticesCount;
TYRA_ASSERT(vertexCount > 0, "Vertices count must be greater than 0");
if (data.normalsEnabled) {
normals = data.frames[index]->normals;
normalsCount = data.frames[index]->normalsCount;
TYRA_ASSERT(normals != nullptr, "Normals are required");
} else {
normalsCount = 0;
normals = nullptr;
}
if (data.textureCoordsEnabled) {
textureCoords = data.frames[index]->textureCoords;
textureCoordsCount = data.frames[index]->textureCoordsCount;
TYRA_ASSERT(textureCoords != nullptr, "Texture coordinates are required");
} else {
textureCoordsCount = 0;
textureCoords = nullptr;
}
if (data.manyColorsEnabled) {
colors = data.frames[index]->colors;
colorsCount = data.frames[index]->colorsCount;
TYRA_ASSERT(colors != nullptr, "Colors are required");
} else {
colorsCount = 0;
colors = nullptr;
}
bbox = bbox =
new BBox(data.frames[index]->vertices, data.frames[index]->verticesCount); new BBox(data.frames[index]->vertices, data.frames[index]->verticesCount);
@@ -66,16 +34,6 @@ MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) {
MeshFrame::MeshFrame(const MeshFrame& frame) { MeshFrame::MeshFrame(const MeshFrame& frame) {
id = rand() % 1000000; id = rand() % 1000000;
vertices = frame.vertices;
normals = frame.normals;
textureCoords = frame.textureCoords;
colors = frame.colors;
vertexCount = frame.vertexCount;
normalsCount = frame.normalsCount;
textureCoordsCount = frame.textureCoordsCount;
colorsCount = frame.colorsCount;
bbox = frame.bbox; bbox = frame.bbox;
_isMother = false; _isMother = false;
@@ -83,10 +41,6 @@ MeshFrame::MeshFrame(const MeshFrame& frame) {
MeshFrame::~MeshFrame() { MeshFrame::~MeshFrame() {
if (_isMother) { if (_isMother) {
delete[] vertices;
if (normals) delete[] normals;
if (textureCoords) delete[] textureCoords;
if (colors) delete[] colors;
delete bbox; delete bbox;
} }
} }
@@ -111,38 +65,7 @@ std::string MeshFrame::getPrint(const char* name) const {
res << std::fixed << std::setprecision(2); res << std::fixed << std::setprecision(2);
res << "Id: " << id << ", " << std::endl; res << "Id: " << id << ", " << std::endl;
res << "VertexCount: " << vertexCount << ", " << std::endl;
res << "NormalsCount: " << normalsCount << ", " << std::endl;
res << "TextureCoordsCount: " << textureCoordsCount << ", " << std::endl;
res << "ColorsCount: " << colorsCount << ", " << std::endl;
res << "BBox: " << bbox->getPrint() << ", " << std::endl; res << "BBox: " << bbox->getPrint() << ", " << std::endl;
res << "Vertices: ";
for (u32 i = 0; i < vertexCount; i++) {
res << vertices[i].getPrint() << ", " << std::endl;
}
if (normals) {
res << "Normals: ";
for (u32 i = 0; i < normalsCount; i++) {
res << normals[i].getPrint() << ", " << std::endl;
}
}
if (textureCoords) {
res << "TextureCoords: ";
for (u32 i = 0; i < textureCoordsCount; i++) {
res << textureCoords[i].getPrint() << ", " << std::endl;
}
}
if (colors) {
res << "Colors: ";
for (u32 i = 0; i < colorsCount; i++) {
res << colors[i].getPrint() << ", " << std::endl;
}
}
res << ")"; res << ")";
return res.str(); return res.str();
+8 -74
View File
@@ -19,43 +19,20 @@ namespace Tyra {
MeshMaterial::MeshMaterial(const MeshBuilderData& data, MeshMaterial::MeshMaterial(const MeshBuilderData& data,
const u32& materialIndex) const u32& materialIndex)
: singleColor(false) { : color(false) {
TYRA_ASSERT(materialIndex < data.materialsCount && materialIndex >= 0, TYRA_ASSERT(materialIndex < data.materialsCount && materialIndex >= 0,
"Provided index \"", materialIndex, "\" is out of range"); "Provided index \"", materialIndex, "\" is out of range");
id = rand() % 1000000; id = rand() % 1000000;
vertexFaces = data.materials[materialIndex]->vertexFaces;
TYRA_ASSERT(vertexFaces != nullptr, "Vertex faces are required");
if (data.textureCoordsEnabled) {
textureCoordFaces = data.materials[materialIndex]->textureCoordFaces;
TYRA_ASSERT(textureCoordFaces != nullptr,
"Texture coord faces are required");
} else {
textureCoordFaces = nullptr;
}
if (data.normalsEnabled) {
normalFaces = data.materials[materialIndex]->normalFaces;
TYRA_ASSERT(normalFaces != nullptr, "Normal faces are required");
} else {
normalFaces = nullptr;
}
if (data.manyColorsEnabled) { if (data.manyColorsEnabled) {
colorFaces = data.materials[materialIndex]->colorFaces;
singleColorFlag = false; singleColorFlag = false;
TYRA_ASSERT(colorFaces != nullptr, "Colors faces are required"); TYRA_ASSERT(data.frames[0]->colors != nullptr, "Colors faces are required");
} else { } else {
colorFaces = nullptr;
singleColorFlag = true; singleColorFlag = true;
} }
singleColor.set(128.0F, 128.0F, 128.0F, 128.0F); color.set(128.0F, 128.0F, 128.0F, 128.0F);
facesCount = data.materials[materialIndex]->count;
TYRA_ASSERT(facesCount > 0, "Faces count must be greater than 0");
_name = data.materials[materialIndex]->name; _name = data.materials[materialIndex]->name;
TYRA_ASSERT(_name.length() > 0, "MeshMaterial name cannot be empty"); TYRA_ASSERT(_name.length() > 0, "MeshMaterial name cannot be empty");
@@ -72,16 +49,11 @@ MeshMaterial::MeshMaterial(const MeshBuilderData& data,
MeshMaterial::MeshMaterial(const MeshMaterial& mesh) { MeshMaterial::MeshMaterial(const MeshMaterial& mesh) {
id = rand() % 1000000; id = rand() % 1000000;
vertexFaces = mesh.vertexFaces; singleColorFlag = mesh.singleColorFlag;
textureCoordFaces = mesh.textureCoordFaces;
normalFaces = mesh.normalFaces;
colorFaces = mesh.colorFaces;
facesCount = mesh.facesCount;
framesCount = mesh.framesCount; framesCount = mesh.framesCount;
_name = mesh._name; _name = mesh._name;
singleColor.set(128.0F, 128.0F, 128.0F, 128.0F); color.set(128.0F, 128.0F, 128.0F, 128.0F);
frames = new MeshMaterialFrame*[framesCount]; frames = new MeshMaterialFrame*[framesCount];
for (u32 i = 0; i < framesCount; i++) { for (u32 i = 0; i < framesCount; i++) {
@@ -92,13 +64,6 @@ MeshMaterial::MeshMaterial(const MeshMaterial& mesh) {
} }
MeshMaterial::~MeshMaterial() { MeshMaterial::~MeshMaterial() {
if (_isMother) {
delete[] vertexFaces;
if (textureCoordFaces) delete[] textureCoordFaces;
if (normalFaces) delete[] normalFaces;
if (colorFaces) delete[] colorFaces;
}
for (u32 i = 0; i < framesCount; i++) { for (u32 i = 0; i < framesCount; i++) {
delete frames[i]; delete frames[i];
} }
@@ -111,7 +76,7 @@ const BBox& MeshMaterial::getBBox(const u32& frame) const {
void MeshMaterial::setSingleColorFlag(const u8& flag) { void MeshMaterial::setSingleColorFlag(const u8& flag) {
TYRA_ASSERT( TYRA_ASSERT(
colorFaces != nullptr, frames[0]->getColors() != nullptr,
"Colors and color faces are required to use color-per-vertex mode"); "Colors and color faces are required to use color-per-vertex mode");
singleColorFlag = flag; singleColorFlag = flag;
@@ -139,39 +104,8 @@ std::string MeshMaterial::getPrint(const char* name) const {
res << std::fixed << std::setprecision(2); res << std::fixed << std::setprecision(2);
res << "Id: " << id << ", " << std::endl; res << "Id: " << id << ", " << std::endl;
res << "Name: " << _name << ", " << std::endl; res << "Name: " << _name << ", " << std::endl;
res << "FacesCount: " << facesCount << ", " << std::endl; res << "Frames count: " << framesCount << ", " << std::endl;
res << "FramesCount: " << framesCount << ", " << std::endl; res << "Single color?: " << static_cast<u32>(singleColorFlag) << std::endl;
res << "vertexFaces: " << std::endl;
for (u32 i = 0; i < facesCount; i++) {
res << vertexFaces[i] << ", ";
if (i % 3 == 2) res << std::endl;
}
if (textureCoordFaces) {
res << "TextureCoordFaces: " << std::endl;
for (u32 i = 0; i < facesCount; i++) {
res << textureCoordFaces[i] << ", ";
if (i % 3 == 2) res << std::endl;
}
}
if (normalFaces) {
res << "NormalFaces: " << std::endl;
for (u32 i = 0; i < facesCount; i++) {
res << normalFaces[i] << ", ";
if (i % 3 == 2) res << std::endl;
}
}
if (colorFaces) {
res << "ColorFaces: " << std::endl;
for (u32 i = 0; i < facesCount; i++) {
res << colorFaces[i] << ", ";
if (i % 3 == 2) res << std::endl;
}
}
res << ")"; res << ")";
return res.str(); return res.str();
@@ -11,6 +11,8 @@
#include "debug/debug.hpp" #include "debug/debug.hpp"
#include <tamtypes.h> #include <tamtypes.h>
#include <iomanip>
#include <string>
#include "renderer/models/color.hpp" #include "renderer/models/color.hpp"
#include "loaders/3d/builder/mesh_builder_data.hpp" #include "loaders/3d/builder/mesh_builder_data.hpp"
#include "renderer/3d/mesh/mesh_material_frame.hpp" #include "renderer/3d/mesh/mesh_material_frame.hpp"
@@ -31,12 +33,24 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data,
data.materials[materialIndex]->vertexFaces, data.materials[materialIndex]->vertexFaces,
data.materials[materialIndex]->count); data.materials[materialIndex]->count);
allocateVertices(data, frameIndex, materialIndex);
allocateNormals(data, frameIndex, materialIndex);
allocateTextureCoords(data, frameIndex, materialIndex);
allocateColors(data, frameIndex, materialIndex);
_isMother = true; _isMother = true;
} }
MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) { MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) {
id = rand() % 1000000; id = rand() % 1000000;
vertexCount = frame.vertexCount;
vertices = frame.vertices;
normals = frame.normals;
textureCoords = frame.textureCoords;
colors = frame.colors;
bbox = frame.bbox; bbox = frame.bbox;
_isMother = false; _isMother = false;
@@ -44,8 +58,124 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) {
MeshMaterialFrame::~MeshMaterialFrame() { MeshMaterialFrame::~MeshMaterialFrame() {
if (_isMother) { if (_isMother) {
delete[] vertices;
if (normals) delete[] normals;
if (textureCoords) delete[] textureCoords;
if (colors) delete[] colors;
delete bbox; delete bbox;
} }
} }
std::string MeshMaterialFrame::getPrint(const char* name) const {
std::stringstream res;
if (name) {
res << name << "(";
} else {
res << "MeshMaterialFrame(";
}
res << std::fixed << std::setprecision(2);
res << "Id: " << id << ", " << std::endl;
res << "Vertex count: " << vertexCount << ", " << std::endl;
res << "BBox: " << bbox->getPrint() << ", " << std::endl;
res << "Vertices: ";
for (u32 i = 0; i < vertexCount; i++) {
res << vertices[i].getPrint() << ", " << std::endl;
}
if (normals) {
res << "Normals: ";
for (u32 i = 0; i < vertexCount; i++) {
res << normals[i].getPrint() << ", " << std::endl;
}
}
if (textureCoords) {
res << "TextureCoords: ";
for (u32 i = 0; i < vertexCount; i++) {
res << textureCoords[i].getPrint() << ", " << std::endl;
}
}
if (colors) {
res << "Colors: ";
for (u32 i = 0; i < vertexCount; i++) {
res << colors[i].getPrint() << ", " << std::endl;
}
}
res << ")";
return res.str();
}
void MeshMaterialFrame::allocateVertices(const MeshBuilderData& data,
const u32& frameIndex,
const u32& materialIndex) {
vertexCount = data.materials[materialIndex]->count; // faces count
vertices = new Vec4[vertexCount];
TYRA_ASSERT(vertexCount > 0, "Vertex count must be greater than 0");
auto* rolled = data.frames[frameIndex]->vertices;
auto* faces = data.materials[materialIndex]->vertexFaces;
TYRA_ASSERT(rolled != nullptr, "Vertices are required");
TYRA_ASSERT(faces != nullptr, "Vertex faces are required");
for (u32 i = 0; i < vertexCount; i++) vertices[i] = rolled[faces[i]];
}
void MeshMaterialFrame::allocateTextureCoords(const MeshBuilderData& data,
const u32& frameIndex,
const u32& materialIndex) {
textureCoords = nullptr;
if (!data.textureCoordsEnabled) return;
textureCoords = new Vec4[vertexCount];
auto* rolled = data.frames[frameIndex]->textureCoords;
auto* faces = data.materials[materialIndex]->textureCoordFaces;
TYRA_ASSERT(rolled != nullptr, "Texture coordinates are required");
TYRA_ASSERT(faces != nullptr, "Texture coordinate faces are required");
for (u32 i = 0; i < vertexCount; i++) textureCoords[i] = rolled[faces[i]];
}
void MeshMaterialFrame::allocateNormals(const MeshBuilderData& data,
const u32& frameIndex,
const u32& materialIndex) {
normals = nullptr;
if (!data.normalsEnabled) return;
normals = new Vec4[vertexCount];
auto* rolled = data.frames[frameIndex]->normals;
auto* faces = data.materials[materialIndex]->normalFaces;
TYRA_ASSERT(rolled != nullptr, "Normals are required");
TYRA_ASSERT(faces != nullptr, "Normal faces are required");
for (u32 i = 0; i < vertexCount; i++) normals[i] = rolled[faces[i]];
}
void MeshMaterialFrame::allocateColors(const MeshBuilderData& data,
const u32& frameIndex,
const u32& materialIndex) {
colors = nullptr;
if (!data.manyColorsEnabled) return;
colors = new Color[vertexCount];
auto* rolled = data.frames[frameIndex]->colors;
auto* faces = data.materials[materialIndex]->colorFaces;
TYRA_ASSERT(rolled != nullptr, "Colors are required");
TYRA_ASSERT(faces != nullptr, "Color faces are required");
for (u32 i = 0; i < vertexCount; i++) colors[i] = rolled[faces[i]];
}
} // namespace Tyra } // namespace Tyra
@@ -46,6 +46,10 @@ void DynPipCore::initParts(DynPipBag* bag) {
delete texBuffers; delete texBuffers;
} }
void DynPipCore::renderTEST(DynPipBag** bags, const u32& count) {
qbufferRenderer.renderTEST(bags, count);
}
void DynPipCore::renderPart(DynPipBag* bag, const bool& frustumCull) { void DynPipCore::renderPart(DynPipBag* bag, const bool& frustumCull) {
if (bag->count <= 0) return; if (bag->count <= 0) return;
@@ -41,7 +41,7 @@ void DynPipRenderer::init(RendererCore* t_core,
dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0);
dma_channel_fast_waits(DMA_CHANNEL_VIF1); dma_channel_fast_waits(DMA_CHANNEL_VIF1);
const u32 VU1_PACKET_SIZE = 16; const u32 VU1_PACKET_SIZE = 256;
packets[0] = packets[0] =
packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
@@ -143,10 +143,40 @@ void DynPipRenderer::render(DynPipBag* bag) {
sendPacket(); sendPacket();
} }
void DynPipRenderer::renderTEST(DynPipBag** bags, const u32& count) {
if (count <= 0) return;
auto* program = programsRepo->getProgramByBag(bags[0]);
addBufferDataToPacketTEST(program, bags, count);
sendPacket();
}
void DynPipRenderer::addBufferDataToPacketTEST(DynPipVU1Program* program,
DynPipBag** bags,
const u32& count) {
currentPacket = packets[context];
packet2_reset(currentPacket, false);
for (u32 i = 0; i < count; i++) {
program->addBufferDataToPacket(currentPacket, bags[i],
&rendererCore->gs.prim);
}
if (lastProgramName != program->getName()) {
packet2_utils_vu_add_start_program(currentPacket,
program->getDestinationAddress());
lastProgramName = program->getName();
} else {
packet2_utils_vu_add_continue_program(currentPacket);
}
packet2_utils_vu_add_end_tag(currentPacket);
}
void DynPipRenderer::addBufferDataToPacket(DynPipVU1Program* program, void DynPipRenderer::addBufferDataToPacket(DynPipVU1Program* program,
DynPipBag* bag) { DynPipBag* bag) {
currentPacket = packets[context]; currentPacket = packets[context];
packet2_reset(currentPacket, false); packet2_reset(currentPacket, false);
program->addBufferDataToPacket(currentPacket, bag, &rendererCore->gs.prim); program->addBufferDataToPacket(currentPacket, bag, &rendererCore->gs.prim);
if (lastProgramName != program->getName()) { if (lastProgramName != program->getName()) {
@@ -163,6 +193,9 @@ void DynPipRenderer::sendPacket() {
dma_channel_wait(DMA_CHANNEL_VIF1, 0); dma_channel_wait(DMA_CHANNEL_VIF1, 0);
dma_channel_send_packet2(currentPacket, DMA_CHANNEL_VIF1, true); dma_channel_send_packet2(currentPacket, DMA_CHANNEL_VIF1, true);
// TODO
// TYRA_LOG(packet2_get_qw_count(currentPacket));
// Switch packet, so we can proceed during DMA transfer // Switch packet, so we can proceed during DMA transfer
context = !context; context = !context;
} }
@@ -23,16 +23,17 @@ void DynamicPipeline::init(RendererCore* t_core) {
void DynamicPipeline::onUse() { core.reinitVU1Programs(); } void DynamicPipeline::onUse() { core.reinitVU1Programs(); }
#define BUFFER_COUNT 64
void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) { void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
auto model = mesh->getModelMatrix(); auto model = mesh->getModelMatrix();
auto* frameFrom = mesh->getFrame(mesh->getCurrentAnimationFrame());
auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame());
auto* infoBag = getInfoBag(mesh, options, &model); auto* infoBag = getInfoBag(mesh, options, &model);
PipelineDirLightsBag* dirLights = nullptr; PipelineDirLightsBag* dirLights = nullptr;
auto frustumCulling = auto frustumCulling =
options ? options->frustumCulling : DynPipFrustumCulling_Simple; options ? options->frustumCulling : DynPipFrustumCulling_Simple;
if (frustumCulling == DynPipFrustumCulling_Simple) { if (frustumCulling == DynPipFrustumCulling_Simple) {
auto* frameTo = mesh->getFrame(mesh->getNextAnimationFrame());
if (frameTo->getBBox().isInFrustum( if (frameTo->getBBox().isInFrustum(
rendererCore->renderer3D.frustumPlanes.getAll(), model) == rendererCore->renderer3D.frustumPlanes.getAll(), model) ==
CoreBBoxFrustum::OUTSIDE_FRUSTUM) { CoreBBoxFrustum::OUTSIDE_FRUSTUM) {
@@ -47,7 +48,7 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
options->lighting->directionalDirections); options->lighting->directionalDirections);
} }
DynPipBag buffers[2]; DynPipBag buffers[BUFFER_COUNT];
u8 context = 0; u8 context = 0;
setBuffersDefaultVars(buffers, mesh, infoBag); setBuffersDefaultVars(buffers, mesh, infoBag);
@@ -55,54 +56,78 @@ void DynamicPipeline::render(DynamicMesh* mesh, const DynPipOptions* options) {
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i); auto* material = mesh->getMaterial(i);
auto partSize = core.getMaxVertCountByParams( auto* frameFrom = material->getFrame(mesh->getCurrentAnimationFrame());
options && options->lighting, material->getTextureCoordFaces()); auto* frameTo = material->getFrame(mesh->getNextAnimationFrame());
auto partSize =
core.getMaxVertCountByParams(options && options->lighting,
material->getFrame(0)->getTextureCoords());
u32 partsCount = u32 partsCount =
ceil(material->getFacesCount() / static_cast<float>(partSize)); ceil(frameFrom->getVertexCount() / static_cast<float>(partSize));
auto* colorBag = getColorBag(material); auto* colorBag = getColorBag(material);
setBuffersColorBag(buffers, colorBag); setBuffersColorBag(buffers, colorBag);
u8 isPartInitialized = false; u8 isPartInitialized = false;
for (u32 j = 0; j < partsCount; j++) { for (u32 k = 0; k < partsCount; k++) {
auto& buffer = buffers[context]; auto& buffer = buffers[context++];
freeBuffer(&buffer); freeBuffer(&buffer);
buffer.count = j == partsCount - 1 buffer.count = k == partsCount - 1
? material->getFacesCount() - j * partSize ? frameFrom->getVertexCount() - k * partSize
: partSize; : partSize;
u32 startIndex = j * partSize; u32 startIndex = k * partSize;
addVertices(mesh, material, &buffer, frameFrom, frameTo, startIndex); addVertices(frameFrom, frameTo, &buffer, startIndex);
buffer.texture = getTextureBag(mesh, material, frameFrom, frameTo, buffer.texture = getTextureBag(material, frameFrom, frameTo, startIndex);
buffer.count, startIndex); buffer.lighting = getLightingBag(frameFrom, frameTo, &model, options,
buffer.lighting = dirLights, startIndex);
getLightingBag(mesh, material, &model, frameFrom, frameTo, options,
dirLights, buffer.count, startIndex);
if (!isPartInitialized) { if (!isPartInitialized) {
core.initParts(&buffer); core.initParts(&buffer);
isPartInitialized = true; isPartInitialized = true;
} }
core.renderPart(&buffer, frustumCulling == DynPipFrustumCulling_Precise); // core.renderPart(&buffer, frustumCulling ==
// DynPipFrustumCulling_Precise);
context = !context; if (context == BUFFER_COUNT / 2 || context == BUFFER_COUNT) {
DynPipBag** sendBuffers = new DynPipBag*[BUFFER_COUNT / 2];
for (u32 i = 0; i < BUFFER_COUNT / 2; i++) {
sendBuffers[i] = &buffers[context - ((BUFFER_COUNT / 2) - i)];
}
core.renderTEST(sendBuffers, BUFFER_COUNT / 2);
delete[] sendBuffers;
if (context == BUFFER_COUNT) context = 0;
}
} }
freeBuffer(&buffers[context]);
freeBuffer(&buffers[!context]);
delete colorBag; delete colorBag;
} }
// TODO: Refactor (define itd, wywalic te wszystkie TEST i poprawic)
// TODO: Rozmiar pakietu VU1 na podstawie rozmiaru buforow
// TODO: Dorenderowac brakujace (np gdy context == 1-buffersize-1 itd)
// TODO: Program renderujacy w VU1
// TODO: Github: Ten sam myk zrobic w static pipeline?
for (u32 i = 0; i < BUFFER_COUNT; i++) freeBuffer(&buffers[i]);
if (dirLights) {
delete dirLights;
}
delete infoBag; delete infoBag;
} }
void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers, void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers,
DynamicMesh* mesh, DynamicMesh* mesh,
PipelineInfoBag* infoBag) { PipelineInfoBag* infoBag) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < BUFFER_COUNT; i++) {
buffers[i].info = infoBag; buffers[i].info = infoBag;
buffers[i].interpolation = mesh->getAnimState().interpolation; buffers[i].interpolation = mesh->getAnimState().interpolation;
} }
@@ -110,29 +135,19 @@ void DynamicPipeline::setBuffersDefaultVars(DynPipBag* buffers,
void DynamicPipeline::setBuffersColorBag(DynPipBag* buffers, void DynamicPipeline::setBuffersColorBag(DynPipBag* buffers,
DynPipColorBag* colorBag) { DynPipColorBag* colorBag) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < BUFFER_COUNT; i++) {
buffers[i].color = colorBag; buffers[i].color = colorBag;
} }
} }
void DynamicPipeline::freeBuffer(DynPipBag* bag) { void DynamicPipeline::freeBuffer(DynPipBag* bag) {
if (bag->texture) { if (bag->texture) {
bag->texture->freeCoords();
delete bag->texture; delete bag->texture;
} }
if (bag->lighting) { if (bag->lighting) {
bag->lighting->freeNormals();
delete bag->lighting; delete bag->lighting;
} }
if (bag->verticesFrom) {
delete[] bag->verticesFrom;
}
if (bag->verticesTo) {
delete[] bag->verticesTo;
}
} }
PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh, PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
@@ -155,57 +170,42 @@ PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
return result; return result;
} }
void DynamicPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material, void DynamicPipeline::addVertices(MeshMaterialFrame* materialFrameFrom,
DynPipBag* bag, MeshFrame* frameFrom, MeshMaterialFrame* materialFrameTo,
MeshFrame* frameTo, DynPipBag* bag, const u32& startIndex) const {
const u32& startIndex) const { bag->verticesFrom = &materialFrameFrom->getVertices()[startIndex];
bag->verticesFrom = new Vec4[bag->count]; bag->verticesTo = &materialFrameTo->getVertices()[startIndex];
bag->verticesTo = new Vec4[bag->count];
for (u32 i = startIndex; i < startIndex + bag->count; i++) {
auto& face = material->getVertexFaces()[i];
auto offset = i - startIndex;
bag->verticesFrom[offset] = frameFrom->getVertices()[face];
bag->verticesTo[offset] = frameTo->getVertices()[face];
}
} }
DynPipColorBag* DynamicPipeline::getColorBag(MeshMaterial* material) const { DynPipColorBag* DynamicPipeline::getColorBag(MeshMaterial* material) const {
auto* result = new DynPipColorBag(); auto* result = new DynPipColorBag();
result->single = &material->singleColor; result->single = &material->color;
return result; return result;
} }
DynPipTextureBag* DynamicPipeline::getTextureBag( DynPipTextureBag* DynamicPipeline::getTextureBag(
DynamicMesh* mesh, MeshMaterial* material, MeshFrame* frameFrom, MeshMaterial* material, MeshMaterialFrame* materialFrameFrom,
MeshFrame* frameTo, const u32& count, const u32& startIndex) { MeshMaterialFrame* materialFrameTo, const u32& startIndex) {
if (!material->getTextureCoordFaces()) return nullptr; if (!materialFrameFrom->getTextureCoords()) return nullptr;
auto* result = new DynPipTextureBag(); auto* result = new DynPipTextureBag();
result->texture = result->texture =
rendererCore->texture.repository.getBySpriteOrMesh(material->getId()); rendererCore->texture.repository.getBySpriteOrMesh(material->getId());
TYRA_ASSERT(result->texture, "Texture for material id: ", 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->coordinatesFrom = new Vec4[count]; result->coordinatesFrom = &materialFrameFrom->getTextureCoords()[startIndex];
result->coordinatesTo = new Vec4[count]; result->coordinatesTo = &materialFrameTo->getTextureCoords()[startIndex];
for (u32 i = startIndex; i < startIndex + count; i++) {
auto& face = material->getTextureCoordFaces()[i];
auto offset = i - startIndex;
result->coordinatesFrom[offset] = frameFrom->getTextureCoords()[face];
result->coordinatesTo[offset] = frameTo->getTextureCoords()[face];
}
return result; return result;
} }
DynPipLightingBag* DynamicPipeline::getLightingBag( DynPipLightingBag* DynamicPipeline::getLightingBag(
DynamicMesh* mesh, MeshMaterial* material, M4x4* model, MeshMaterialFrame* materialFrameFrom, MeshMaterialFrame* materialFrameTo,
MeshFrame* frameFrom, MeshFrame* frameTo, const DynPipOptions* options, M4x4* model, const DynPipOptions* options,
PipelineDirLightsBag* dirLightsBag, const u32& count, PipelineDirLightsBag* dirLightsBag, const u32& startIndex) const {
const u32& startIndex) const { if (!materialFrameFrom->getNormals() || options == nullptr ||
if (!material->getNormalFaces() || options == nullptr ||
options->lighting == nullptr) options->lighting == nullptr)
return nullptr; return nullptr;
@@ -213,15 +213,9 @@ DynPipLightingBag* DynamicPipeline::getLightingBag(
result->lightMatrix = model; result->lightMatrix = model;
result->dirLights = dirLightsBag; result->dirLights = dirLightsBag;
result->normalsFrom = new Vec4[count];
result->normalsTo = new Vec4[count];
for (u32 i = startIndex; i < startIndex + count; i++) { result->normalsFrom = &materialFrameFrom->getNormals()[startIndex];
auto& face = material->getNormalFaces()[i]; result->normalsTo = &materialFrameTo->getNormals()[startIndex];
auto offset = i - startIndex;
result->normalsFrom[offset] = frameFrom->getNormals()[face];
result->normalsTo[offset] = frameTo->getNormals()[face];
}
return result; return result;
} }
@@ -25,21 +25,13 @@ void StaticPipeline::onUse() { core.reinitVU1Programs(); }
void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) { void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) {
auto model = mesh->getModelMatrix(); 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); auto* infoBag = getInfoBag(mesh, options, &model);
if (options && options->lighting) setLightingColorsCache(options->lighting); if (options && options->lighting) setLightingColorsCache(options->lighting);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) { for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i); auto* material = mesh->getMaterial(i);
auto* materialFrame = material->getFrame(0);
// 2x bufory[maxVertCount*2] -> pętla po mniejszych częściach i czestsze // 2x bufory[maxVertCount*2] -> pętla po mniejszych częściach i czestsze
// rendery // rendery
@@ -50,12 +42,11 @@ void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) {
// material->getTextureCoordFaces()); // material->getTextureCoordFaces());
StaPipBag bag; StaPipBag bag;
addVertices(mesh, material, &bag, frameFrom, frameTo); addVertices(materialFrame, &bag);
bag.info = infoBag; bag.info = infoBag;
bag.color = getColorBag(mesh, material, frameFrom, frameTo); bag.color = getColorBag(material, materialFrame);
bag.texture = getTextureBag(mesh, material, frameFrom, frameTo); bag.texture = getTextureBag(material, materialFrame);
bag.lighting = bag.lighting = getLightingBag(materialFrame, &model, options);
getLightingBag(mesh, material, &model, frameFrom, frameTo, options);
core.render(&bag); core.render(&bag);
@@ -65,22 +56,10 @@ void StaticPipeline::render(DynamicMesh* mesh, const StaPipOptions* options) {
delete infoBag; delete infoBag;
} }
void StaticPipeline::addVertices(DynamicMesh* mesh, MeshMaterial* material, void StaticPipeline::addVertices(MeshMaterialFrame* materialFrame,
StaPipBag* bag, MeshFrame* frameFrom, StaPipBag* bag) const {
MeshFrame* frameTo) const { bag->count = materialFrame->getVertexCount();
bag->count = material->getFacesCount(); bag->vertices = materialFrame->getVertices();
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);
}
}
} }
PipelineInfoBag* StaticPipeline::getInfoBag(DynamicMesh* mesh, PipelineInfoBag* StaticPipeline::getInfoBag(DynamicMesh* mesh,
@@ -105,39 +84,22 @@ PipelineInfoBag* StaticPipeline::getInfoBag(DynamicMesh* mesh,
return result; return result;
} }
StaPipColorBag* StaticPipeline::getColorBag(DynamicMesh* mesh, StaPipColorBag* StaticPipeline::getColorBag(
MeshMaterial* material, MeshMaterial* material, MeshMaterialFrame* materialFrame) const {
MeshFrame* frameFrom,
MeshFrame* frameTo) const {
auto* result = new StaPipColorBag(); auto* result = new StaPipColorBag();
if (material->isSingleColorActivated()) { if (material->isSingleColorActivated()) {
result->single = &material->singleColor; result->single = &material->color;
} else { } else {
result->many = new Color[material->getFacesCount()]; result->many = materialFrame->getColors();
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 result;
} }
StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh, StaPipTextureBag* StaticPipeline::getTextureBag(
MeshMaterial* material, MeshMaterial* material, MeshMaterialFrame* materialFrame) {
MeshFrame* frameFrom, if (!materialFrame->getTextureCoords()) return nullptr;
MeshFrame* frameTo) {
if (!material->getTextureCoordFaces()) return nullptr;
auto* result = new StaPipTextureBag(); auto* result = new StaPipTextureBag();
@@ -146,28 +108,15 @@ StaPipTextureBag* StaticPipeline::getTextureBag(DynamicMesh* mesh,
TYRA_ASSERT(result->texture, "Texture for material id: ", 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()]; result->coordinates = materialFrame->getTextureCoords();
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);
}
}
return result; return result;
} }
StaPipLightingBag* StaticPipeline::getLightingBag( StaPipLightingBag* StaticPipeline::getLightingBag(
DynamicMesh* mesh, MeshMaterial* material, M4x4* model, MeshMaterialFrame* materialFrame, M4x4* model,
MeshFrame* frameFrom, MeshFrame* frameTo,
const StaPipOptions* options) const { const StaPipOptions* options) const {
if (!material->getNormalFaces() || options == nullptr || if (!materialFrame->getNormals() || options == nullptr ||
options->lighting == nullptr) options->lighting == nullptr)
return nullptr; return nullptr;
@@ -181,18 +130,7 @@ StaPipLightingBag* StaticPipeline::getLightingBag(
result->dirLights->setLightsManually( result->dirLights->setLightsManually(
colorsCache, options->lighting->directionalDirections); colorsCache, options->lighting->directionalDirections);
result->normals = new Vec4[material->getFacesCount()]; result->normals = materialFrame->getNormals();
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 result;
} }
@@ -208,22 +146,15 @@ void StaticPipeline::setLightingColorsCache(
void StaticPipeline::deallocDrawBags(StaPipBag* bag, void StaticPipeline::deallocDrawBags(StaPipBag* bag,
MeshMaterial* material) const { MeshMaterial* material) const {
if (bag->color->many) {
delete[] bag->color->many;
}
if (bag->texture) { if (bag->texture) {
delete[] bag->texture->coordinates;
delete bag->texture; delete bag->texture;
} }
if (bag->lighting) { if (bag->lighting) {
delete[] bag->lighting->normals;
delete bag->lighting->dirLights; // TODO delete bag->lighting->dirLights; // TODO
delete bag->lighting; delete bag->lighting;
} }
delete[] bag->vertices;
delete bag->color; delete bag->color;
} }
+26 -1
View File
@@ -104,7 +104,7 @@ void H4570::init() {
} }
engine->audio.playSong(); engine->audio.playSong();
// engine->renderer.setFrameLimit(false); engine->renderer.setFrameLimit(false);
} }
u32 counter = 0; u32 counter = 0;
@@ -149,9 +149,34 @@ void H4570::loop() {
engine->renderer.renderer3D.usePipeline(&dynpip); engine->renderer.renderer3D.usePipeline(&dynpip);
{ {
dynpip.render(warrior, dynOptions); dynpip.render(warrior, dynOptions);
// dynpip.render(warrior2, dynOptions); // dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior3, dynOptions); // dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior4, dynOptions); // dynpip.render(warrior4, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior2, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
// dynpip.render(warrior3, dynOptions);
} }
engine->renderer.renderer3D.usePipeline(&mcPip); engine->renderer.renderer3D.usePipeline(&mcPip);