moved texturebuffer outside of spec

This commit is contained in:
Sandro Sobczyński
2020-10-29 21:53:08 +01:00
parent ab69ba28e3
commit 8501a85f49
22 changed files with 363 additions and 180 deletions
+19 -6
View File
@@ -17,10 +17,17 @@
// ----
/** Create by specifying values */
Point::Point(float x, float y)
Point::Point(float t_x, float t_y)
{
this->x = x;
this->y = y;
x = t_x;
y = t_y;
}
/** Create with other point values */
Point::Point(const Point &v)
{
x = v.x;
y = v.y;
}
/** Create empty point */
@@ -36,10 +43,16 @@ Point::~Point() {}
// Methods
// ----
void Point::set(float x, float y)
void Point::set(float t_x, float t_y)
{
this->x = x;
this->y = y;
x = x;
y = y;
}
void Point::set(const Point &v)
{
x = v.x;
y = v.y;
}
void Point::print()
+4 -4
View File
@@ -18,11 +18,11 @@
// ----
/** Create by specifying 3 points */
Vector3::Vector3(float x, float y, float z)
Vector3::Vector3(float t_x, float t_y, float t_z)
{
this->x = x;
this->y = y;
this->z = z;
x = t_x;
y = t_y;
z = t_z;
}
/** Create with another vector values */
+7 -10
View File
@@ -62,7 +62,6 @@ void Mesh::loadDff(char *t_subfolder, char *t_dffFile, Vector3 &t_initPos, float
setDefaultColor();
isDffLoaded = true;
loadTextures(t_subfolder, ".bmp");
spec->allocateTextureBuffer(spec->textures[0].width, spec->textures[0].height); // wtf?
}
void Mesh::setDff(Vector3 &t_initPos, DffModel *t_dffModel, MeshSpec *t_spec)
@@ -85,7 +84,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float
obj = new ObjModel(t_objFile);
obj->frameCount = framesAmount;
obj->frames = new Frame[framesAmount];
obj->frames = new MeshFrame[framesAmount];
char *part1 = String::createConcatenated(t_subfolder, t_objFile); // "folder/object"
char *part2 = String::createConcatenated(part1, "_"); // "folder/object_"
@@ -98,7 +97,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float
char *part4 = String::createWithLeadingZeros(part3); // "000001"
char *part5 = String::createConcatenated(part2, part4); // "folder/object_000001"
char *finalPath = String::createConcatenated(part5, ".obj"); // "folder/object_000001.obj"
loader.load(&obj->frames[i], finalPath, t_scale);
loader.load(&obj->frames[i], finalPath, t_scale, false);
delete[] part3;
delete[] part4;
delete[] part5;
@@ -108,11 +107,10 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float
delete[] part2;
position = t_initPos;
setVerticesReference(obj->getFacesCount(), obj->frames[0].vertices);
setVerticesReference(obj->getFacesCount(), obj->frames[0].getVertices());
setDefaultColor();
isObjLoaded = true;
loadTextures(t_subfolder, ".bmp");
spec->allocateTextureBuffer(spec->textures[0].width, spec->textures[0].height); // wtf?
}
void Mesh::setObj(Vector3 &t_initPos, ObjModel *t_objModel, MeshSpec *t_spec)
@@ -121,7 +119,7 @@ void Mesh::setObj(Vector3 &t_initPos, ObjModel *t_objModel, MeshSpec *t_spec)
spec = t_spec;
isSpecInitialized = true;
obj = t_objModel;
setVerticesReference(obj->getFacesCount(), obj->frames[0].vertices);
setVerticesReference(obj->getFacesCount(), obj->frames[0].getVertices());
setDefaultColor();
isObjLoaded = true;
}
@@ -180,10 +178,10 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension)
BmpLoader bmpLoader = BmpLoader();
if (isObjLoaded)
{
spec->textures = new Texture[obj->frames[0].materialsCount];
for (u8 i = 0; i < obj->frames[0].materialsCount; i++)
spec->textures = new Texture[obj->frames[0].getMaterialsCount()];
for (u8 i = 0; i < obj->frames[0].getMaterialsCount(); i++)
{
bmpLoader.load(spec->textures[i], t_subfolder, obj->frames[0].materials[i].getName(), t_extension);
bmpLoader.load(spec->textures[i], t_subfolder, obj->frames[0].getMaterial(i).getName(), t_extension);
setDefaultWrapSettings(spec->textures[i].wrapSettings);
}
}
@@ -234,7 +232,6 @@ void Mesh::loadMD2(char *t_subfolder, char *t_md2File, Vector3 &t_initPos, float
setDefaultColor();
isMd2Loaded = true;
loadTextures(t_subfolder, ".bmp");
spec->allocateTextureBuffer(spec->textures[0].width, spec->textures[0].height); // wtf?
}
/** Set's default object color + no transparency */
+70 -2
View File
@@ -15,10 +15,78 @@
// Constructors/Destructors
// ----
MeshFrame::MeshFrame() {}
MeshFrame::MeshFrame()
{
vertexCount = 0;
stsCount = 0;
normalsCount = 0;
materialsCount = 0;
_areSTsAllocated = false;
_areVerticesAllocated = false;
_areNormalsAllocated = false;
_areMaterialsAllocated = false;
}
MeshFrame::~MeshFrame() {}
MeshFrame::~MeshFrame()
{
if (_areSTsAllocated)
delete[] sts;
if (_areVerticesAllocated)
delete[] vertices;
if (_areNormalsAllocated)
delete[] normals;
if (_areMaterialsAllocated)
delete[] materials;
}
// ----
// Methods
// ----
void MeshFrame::allocateSTs(const u32 &t_val)
{
if (_areSTsAllocated)
{
PRINT_ERR("Can't allocate STs, because were already set!");
return;
}
stsCount = t_val;
sts = new Point[t_val];
_areSTsAllocated = true;
}
void MeshFrame::allocateVertices(const u32 &t_val)
{
if (_areVerticesAllocated)
{
PRINT_ERR("Can't allocate vertices, because were already set!");
return;
}
vertexCount = t_val;
vertices = new Vector3[t_val];
_areVerticesAllocated = true;
}
void MeshFrame::allocateNormals(const u32 &t_val)
{
if (_areNormalsAllocated)
{
PRINT_ERR("Can't allocate normals, because were already set!");
return;
}
normalsCount = t_val;
normals = new Vector3[t_val];
_areNormalsAllocated = true;
}
void MeshFrame::allocateMaterials(const u32 &t_val)
{
if (_areMaterialsAllocated)
{
PRINT_ERR("Can't allocate materials, because were already set!");
return;
}
materialsCount = t_val;
materials = new MeshMaterial[t_val];
_areMaterialsAllocated = true;
}
+12 -13
View File
@@ -11,6 +11,7 @@
#include "../include/models/mesh_material.hpp"
#include "../include/utils/debug.hpp"
#include "../include/utils/string.hpp"
#include <cstdlib>
// ----
// Constructors/Destructors
@@ -18,51 +19,49 @@
MeshMaterial::MeshMaterial()
{
id = rand() % 100000;
facesCount = 0;
isNameAllocated = false;
areFacesAllocated = false;
_isNameSet = false;
_areFacesAllocated = false;
}
MeshMaterial::~MeshMaterial()
{
if (areFacesAllocated)
if (_areFacesAllocated)
{
delete[] vertexFaces;
delete[] stFaces;
delete[] normalFaces;
}
if (isNameAllocated)
{
if (_isNameSet)
delete[] name;
}
}
// ----
// Methods
// ----
void MeshMaterial::setFacesCount(const u32 &t_val)
void MeshMaterial::allocateFaces(const u32 &t_val)
{
if (areFacesAllocated)
if (_areFacesAllocated)
{
PRINT_ERR("Can't set faces, because faces were already set!");
PRINT_ERR("Can't allocate faces, because were already set!");
return;
}
facesCount = t_val;
stFaces = new u32[t_val];
normalFaces = new u32[t_val];
vertexFaces = new u32[t_val];
areFacesAllocated = true;
_areFacesAllocated = true;
}
void MeshMaterial::setName(char *t_val)
{
if (isNameAllocated)
if (_isNameSet)
{
PRINT_ERR("Can't set name, because was already set!");
return;
}
name = String::createCopy(t_val);
isNameAllocated = true;
_isNameSet = true;
}
-27
View File
@@ -29,39 +29,12 @@ MeshSpec::MeshSpec()
/** Release memory if object was initialized */
MeshSpec::~MeshSpec()
{
if (this->isTextureVRAMAllocated == true)
graph_vram_free(this->textureBuffer.address);
}
// ----
// Methods
// ----
/** Configure and allocate vRAM for texture buffer */
void MeshSpec::allocateTextureBuffer(u16 t_width, u16 t_height)
{
this->textureBuffer.width = t_width;
this->textureBuffer.psm = GS_PSM_24;
this->textureBuffer.address = graph_vram_allocate(t_width, t_height, GS_PSM_24, GRAPH_ALIGN_BLOCK);
if (this->textureBuffer.address <= 1)
PRINT_ERR("Texture buffer allocation error. No memory!");
this->textureBuffer.info.width = draw_log2(t_width);
this->textureBuffer.info.height = draw_log2(t_height);
this->textureBuffer.info.components = TEXTURE_COMPONENTS_RGB;
this->textureBuffer.info.function = TEXTURE_FUNCTION_MODULATE;
this->isTextureVRAMAllocated = true;
}
/** Configure and allocate vRAM for texture buffer */
void MeshSpec::deallocateTextureBuffer()
{
if (this->isTextureVRAMAllocated)
{
graph_vram_free(textureBuffer.address);
this->isTextureVRAMAllocated = false;
}
}
/** Sets texture level of details settings and CLUT settings */
void MeshSpec::setupLodAndClut()
{
+10 -10
View File
@@ -55,8 +55,8 @@ ObjModel::~ObjModel()
u32 ObjModel::getFacesCount()
{
u32 result = 0; // TODO
for (u16 i = 0; i < frames[0].materialsCount; i++)
result += frames[0].materials[i].getFacesCount();
for (u16 i = 0; i < frames[0].getMaterialsCount(); i++)
result += frames[0].getMaterial(i).getFacesCount();
return result;
}
@@ -76,9 +76,9 @@ u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_nor
{
#define CURR_FRAME frames[animState.currentFrame]
#define NEXT_FRAME frames[animState.nextFrame]
#define MATERIAL CURR_FRAME.materials[t_materialIndex]
#define CURR_VERT CURR_FRAME.vertices[MATERIAL.getVertexFace(matI + vertI)]
#define NEXT_VERT NEXT_FRAME.vertices[MATERIAL.getVertexFace(matI + vertI)]
#define MATERIAL CURR_FRAME.getMaterial(t_materialIndex)
#define CURR_VERT CURR_FRAME.getVertex(MATERIAL.getVertexFace(matI + vertI))
#define NEXT_VERT NEXT_FRAME.getVertex(MATERIAL.getVertexFace(matI + vertI))
u32 addedFaces = 0;
for (u32 matI = 0; matI < MATERIAL.getFacesCount(); matI += 3)
@@ -99,13 +99,13 @@ u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_nor
o_vertices[addedFaces][2] = calc3Vectors[vertI].z;
o_vertices[addedFaces][3] = 1.0F;
o_normals[addedFaces][0] = CURR_FRAME.normals[MATERIAL.getNormalFace(matI + vertI)].x;
o_normals[addedFaces][1] = CURR_FRAME.normals[MATERIAL.getNormalFace(matI + vertI)].y;
o_normals[addedFaces][2] = CURR_FRAME.normals[MATERIAL.getNormalFace(matI + vertI)].z;
o_normals[addedFaces][0] = CURR_FRAME.getNormal(MATERIAL.getNormalFace(matI + vertI)).x;
o_normals[addedFaces][1] = CURR_FRAME.getNormal(MATERIAL.getNormalFace(matI + vertI)).y;
o_normals[addedFaces][2] = CURR_FRAME.getNormal(MATERIAL.getNormalFace(matI + vertI)).z;
o_normals[addedFaces][3] = 1.0F;
o_coordinates[addedFaces][0] = CURR_FRAME.coordinates[MATERIAL.getStFace(matI + vertI)].x;
o_coordinates[addedFaces][1] = CURR_FRAME.coordinates[MATERIAL.getStFace(matI + vertI)].y;
o_coordinates[addedFaces][0] = CURR_FRAME.getST(MATERIAL.getSTFace(matI + vertI)).x;
o_coordinates[addedFaces][1] = CURR_FRAME.getST(MATERIAL.getSTFace(matI + vertI)).y;
o_coordinates[addedFaces][2] = 1.0F;
o_coordinates[addedFaces++][3] = 1.0F;
}