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
+4 -2
View File
@@ -26,11 +26,13 @@ public:
float xy[2] __attribute__((__aligned__(16)));
};
Point(float x, float y);
Point(float t_x, float t_y);
Point(const Point &v);
Point();
~Point();
void set(float x, float y);
void set(float t_x, float t_y);
void set(const Point &v);
void print();
};
+1 -1
View File
@@ -31,7 +31,7 @@ public:
float xyz[3] __attribute__((__aligned__(16)));
};
Vector3(float x, float y, float z);
Vector3(float t_x, float t_y, float t_z);
Vector3(const Vector3 &v);
Vector3();
~Vector3();
+86
View File
@@ -12,6 +12,9 @@
#define _TYRA_MESH_FRAME_
#include <tamtypes.h>
#include "math/point.hpp"
#include "math/vector3.hpp"
#include "./mesh_material.hpp"
class MeshFrame
{
@@ -20,7 +23,90 @@ public:
MeshFrame();
~MeshFrame();
// ----
// Getters
// ----
const u32 &getVertexCount() const { return vertexCount; };
const u32 &getSTsCount() const { return stsCount; };
const u32 &getNormalsCount() const { return normalsCount; };
const u32 &getMaterialsCount() const { return materialsCount; };
/** Returns vertex. 3 vertices = 1 triangle. */
Vector3 &getVertex(const u32 &i) const { return vertices[i]; };
/** Returns texture coordinate. */
Point &getST(const u32 &i) const { return sts[i]; };
/** Returns normal vector. Used for lighting. */
Vector3 &getNormal(const u32 &i) const { return normals[i]; };
/** Returns material, which is a mesh "subgroup". */
MeshMaterial &getMaterial(const u32 &i) const { return materials[i]; };
/** Array of vertices. Size of getVertexCount() */
Vector3 *getVertices() const { return vertices; };
/** Array of vertices. Size of getSTsCount() */
Point *getSTs() const { return sts; };
/** Array of vertices. Size of getNormalsCount() */
Vector3 *getNormals() const { return normals; };
/** Array of materials. Size of getMaterialsCount() */
MeshMaterial *getMaterials() const { return materials; };
// ----
// Setters
// ----
/**
* Do not call this method unless you know what you do.
* Should be called by data loader.
*/
void setVertex(const u32 &t_index, const Vector3 &t_val) { vertices[t_index].set(t_val); }
/**
* Do not call this method unless you know what you do.
* Should be called by data loader.
*/
void setNormal(const u32 &t_index, const Vector3 &t_val) { normals[t_index].set(t_val); }
/**
* Do not call this method unless you know what you do.
* Should be called by data loader.
*/
void setST(const u32 &t_index, const Point &t_val) { sts[t_index].set(t_val); }
// ----
// Other
// ----
const u8 &areSTsAllocated() const { return _areSTsAllocated; };
const u8 &areVerticesAllocated() const { return _areVerticesAllocated; };
const u8 &areNormalsAllocated() const { return _areNormalsAllocated; };
const u8 &areMaterialsAllocated() const { return _areMaterialsAllocated; };
/** Set STs count and allocate memory. */
void allocateSTs(const u32 &t_val);
/** Set vertex count and allocate memory. */
void allocateVertices(const u32 &t_val);
/** Set normals count and allocate memory. */
void allocateNormals(const u32 &t_val);
/** Set materials count and allocate memory. */
void allocateMaterials(const u32 &t_val);
private:
u8 _areSTsAllocated, _areVerticesAllocated, _areNormalsAllocated, _areMaterialsAllocated;
u32 vertexCount, stsCount, normalsCount, materialsCount;
MeshMaterial *materials;
Point *sts __attribute__((aligned(16)));
Vector3
*vertices __attribute__((aligned(16))),
*normals __attribute__((aligned(16)));
};
#endif
+56 -17
View File
@@ -13,6 +13,11 @@
#include <tamtypes.h>
/** Class which contains draw data for mesh part.
* Mesh can have many materials.
* For example, car can have three materials:
* body, tires and windows.
*/
class MeshMaterial
{
@@ -20,44 +25,78 @@ public:
MeshMaterial();
~MeshMaterial();
// ----
// Getters
// ----
/** Material name. */
char *getName() const { return name; };
/**
* Auto generated unique Id.
* Core role of this variable is to select correct texture to draw
*/
const u32 &getId() const { return id; };
const u32 &getFacesCount() const { return facesCount; };
/** Indexes of vertices. Each 3 faces will give you vertices of next triangle. */
const u32 &getVertexFace(const u32 &i) const { return vertexFaces[i]; };
u32 &getVertexFace(const u32 &i) const { return vertexFaces[i]; };
/** Indexes of texture coords. Each 3 faces will give you texture coords of next triangle. */
const u32 &getStFace(const u32 &i) const { return stFaces[i]; };
u32 &getSTFace(const u32 &i) const { return stFaces[i]; };
/** Indexes of normal vectors used for lighting. Each 3 faces will give you normal vectors of next triangle. */
const u32 &getNormalFace(const u32 &i) const { return normalFaces[i]; };
u32 &getNormalFace(const u32 &i) const { return normalFaces[i]; };
/** Array of vertex faces. Size of getFacesCount() */
const u32 *getVertexFaces() const { return vertexFaces; };
u32 *getVertexFaces() const { return vertexFaces; };
/** Array of texture coords faces. Size of getFacesCount() */
const u32 *getStFaces() const { return stFaces; };
u32 *getSTFaces() const { return stFaces; };
/** Array of normal vector faces. Size of getFacesCount() */
const u32 *getNormalFaces() const { return normalFaces; };
u32 *getNormalFaces() const { return normalFaces; };
/** Set faces count and allocate faces memory. */
void setFacesCount(const u32 &t_val);
// ----
// Setters
// ----
/** Set vertex face. Do not call this method until you know what you do.
* Should be called by data loader. */
/**
* Do not call this method unless you know what you do.
* Should be called by data loader.
*/
void setVertexFace(const u32 &t_index, const u32 &t_val) { vertexFaces[t_index] = t_val; }
/** Set st face. Do not call this method until you know what you do.
* Should be called by data loader. */
void setStFace(const u32 &t_index, const u32 &t_val) { stFaces[t_index] = t_val; }
/**
* Do not call this method unless you know what you do.
* Should be called by data loader.
*/
void setSTFace(const u32 &t_index, const u32 &t_val) { stFaces[t_index] = t_val; }
/** Set vertex face. Do not call this method until you know what you do.
* Should be called by data loader. */
/**
* Do not call this method unless you know what you do.
* Should be called by data loader.
*/
void setNormalFace(const u32 &t_index, const u32 &t_val) { normalFaces[t_index] = t_val; }
/** Set material name. */
void setName(char *t_val);
// ----
// Other
// ----
const u8 &isNameSet() const { return _isNameSet; };
const u8 &areFacesAllocated() const { return _areFacesAllocated; };
/** Set faces count and allocate memory. */
void allocateFaces(const u32 &t_val);
private:
u32 facesCount;
u32 facesCount, id;
u32 *vertexFaces, *stFaces, *normalFaces;
u8 isNameAllocated, areFacesAllocated;
u8 _isNameSet, _areFacesAllocated;
char *name;
};
+1 -4
View File
@@ -22,20 +22,17 @@ class MeshSpec
{
public:
texbuffer_t textureBuffer;
clutbuffer_t clut;
lod_t lod;
MeshSpec();
~MeshSpec();
void allocateTextureBuffer(u16 t_width, u16 t_height);
void deallocateTextureBuffer();
void allocateMemory();
void setupLodAndClut();
Texture *textures;
private:
u8 isTextureVRAMAllocated;
};
#endif
+2 -24
View File
@@ -17,29 +17,7 @@
#include "utils/debug.hpp"
#include "./anim_state.hpp"
#include "./mesh_material.hpp"
class Frame2
{
public:
Frame2() { printf("Frame2 constructor\n"); };
~Frame2() { printf("Frame2 destructor\n"); };
u16 number;
u32 verticesCount, coordinatesCount, normalsCount, materialsCount;
Vector3 *vertices __attribute__((aligned(16))),
*coordinates __attribute__((aligned(16))),
*normals __attribute__((aligned(16)));
MeshMaterial *materials;
};
struct Frame
{
u16 number;
u32 verticesCount, coordinatesCount, normalsCount, materialsCount;
Vector3 *vertices __attribute__((aligned(16))),
*coordinates __attribute__((aligned(16))),
*normals __attribute__((aligned(16)));
MeshMaterial *materials;
};
#include "./mesh_frame.hpp"
/** Class which have common types for all 3D objects */
class ObjModel
@@ -49,7 +27,7 @@ public:
/** File name without extension */
char *filename;
u16 frameCount;
Frame *frames;
MeshFrame *frames;
AnimState animState;
ObjModel(char *t_objFile);