moved texturebuffer outside of spec
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#define _TYRA_OBJ_LOADER_
|
||||
|
||||
#include "../models/obj_model.hpp"
|
||||
#include "../models/mesh_frame.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
/** Class responsible for loading&parsing .obj 3D files */
|
||||
@@ -22,10 +23,10 @@ public:
|
||||
ObjLoader();
|
||||
~ObjLoader();
|
||||
|
||||
void load(Frame *o_result, char *t_fileName, float t_scale);
|
||||
void load(MeshFrame *o_result, char *t_fileName, float t_scale, u8 invertT);
|
||||
|
||||
private:
|
||||
void allocateObjMemory(FILE *t_file, Frame *t_result);
|
||||
void allocateObjMemory(FILE *t_file, MeshFrame *t_result);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
~GifSender();
|
||||
|
||||
void initPacket(u8 context);
|
||||
void addObjects(RenderData *t_renderData, Mesh **t_objects3D, u32 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
void addObjects(RenderData *t_renderData, Mesh **t_objects3D, u32 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer);
|
||||
void addClear(zbuffer_t *t_zBuffer);
|
||||
void sendPacket();
|
||||
void sendClear(zbuffer_t *t_zBuffer);
|
||||
|
||||
@@ -56,13 +56,15 @@ public:
|
||||
void endFrame(float fps);
|
||||
|
||||
private:
|
||||
void allocateTextureBuffer(u16 t_width, u16 t_height);
|
||||
void deallocateTextureBuffer();
|
||||
void changeTexture(Mesh *t_mesh, u8 t_textureIndex);
|
||||
void flipBuffers();
|
||||
void beginFrameIfNeeded();
|
||||
u8 isFrameEmpty;
|
||||
u8 isFrameEmpty, isTextureVRAMAllocated;
|
||||
Matrix perspective;
|
||||
RenderData renderData;
|
||||
|
||||
texbuffer_t textureBuffer;
|
||||
u32 lastTextureId;
|
||||
GifSender *gifSender;
|
||||
VifSender *vifSender;
|
||||
|
||||
@@ -28,10 +28,10 @@ public:
|
||||
~VifSender();
|
||||
|
||||
// TODO refactor
|
||||
void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer);
|
||||
|
||||
private:
|
||||
void drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim);
|
||||
void drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer);
|
||||
|
||||
MATRIX localWorld, localScreen;
|
||||
VECTOR position, rotation;
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define PRINT_LOG(TEXT) printf("LOG: " TEXT " (" __FILE__ ")\n")
|
||||
#define PRINT_ERR(TEXT) printf("---\n--- ---\n--- --- --- ERR: " TEXT " (" __FILE__ ")\n--- ---\n---\n")
|
||||
#define PRINT_ERR(TEXT) printf("\n====================================\n| ERROR: " TEXT "\n| File : " __FILE__ "\n====================================\n\n")
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user