123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- /*!
- * \file include/Mesh.h
- * \brief OpenGL Mesh
- *
- * \author Mongoose
- *
- * \todo Unify the parallel systems here, arrays and the allocate/set
- */
-
- #ifndef _MESH_H_
- #define _MESH_H_
-
- #include "glm/vec3.hpp"
-
- /*!
- * \brief OpenGL Mesh
- */
- class Mesh {
- public:
-
- struct rectangle_t {
- glm::vec3 a, b, c, d;
- uint16_t texture;
- float red, green, blue;
-
- rectangle_t(glm::vec3 _a, glm::vec3 _b, glm::vec3 _c, glm::vec3 _d, uint16_t t,
- float re = 0.0f, float gr = 0.0f, float bl = 0.0f)
- : a(_a), b(_b), c(_c), d(_d), texture(t), red(re), green(gr), blue(bl) { }
- };
-
- Mesh();
- ~Mesh();
-
- void drawAlpha();
- void drawSolid();
-
- void addTexturedRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, uint16_t textile);
- void addTexturedTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, uint16_t textile);
-
- void addColoredRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, float re, float gr,
- float bl);
- void addColoredTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, float re, float gr, float bl);
-
- void addNormal(glm::vec3 n);
-
- std::vector<rectangle_t> texturedRectangles;
- std::vector<rectangle_t> coloredRectangles;
- std::vector<rectangle_t> texturedTriangles;
- std::vector<rectangle_t> coloredTriangles;
- std::vector<glm::vec3> normals;
-
-
- // Old API
-
- typedef enum {
- MeshModeSolid,
- MeshModeWireframe,
- MeshModeTexture,
- MeshModeMultiTexture
- } MeshMode;
-
- typedef enum {
- fMesh_UseVertexArray = (1 << 0)
- } MeshFlags;
-
- typedef struct {
- int texture;
- #ifdef MULTITEXTURE
- int bumpmap;
- #endif
-
- unsigned int cnum_triangles;
- unsigned int cnum_alpha_triangles;
-
- unsigned int num_texcoors;
- float** texcoors; // 2D
-
- unsigned int num_texcoors2;
- float** texcoors2; // 2D
-
- //! Arrays of triangle indices sorted by texture
- unsigned int num_triangles;
- unsigned int* triangles; //!< ABCABCABC...
-
- //! Arrays of alpha triangle indices sorted by texture
- unsigned int num_alpha_triangles;
- unsigned int* alpha_triangles; //!< ABCABCABC...
- } tris_t;
-
- typedef struct {
-
- int texture;
- #ifdef MULTITEXTURE
- int bumpmap;
- #endif
-
- unsigned int cnum_quads;
- unsigned int cnum_alpha_quads;
-
- unsigned int num_texcoors;
- float** texcoors; // 2D
-
- unsigned int num_texcoors2;
- float** texcoors2; // 2D
-
- //! Arrays of rectangle indices sorted by texture
- unsigned int num_quads;
- unsigned int* quads; //!< ABCDABCDABCD...
-
- //! Arrays of alpha rectangle indices sorted by texture
- unsigned int num_alpha_quads;
- unsigned int* alpha_quads; //!< ABCDABCDABCD...
-
- } rect_t;
-
- void drawAlphaOld();
- void drawSolidOld();
-
- void allocateColors(unsigned int n);
-
- void allocateNormals(unsigned int n);
-
- void allocateRectangles(unsigned int n);
-
- void allocateTriangles(unsigned int n);
-
- void allocateVertices(unsigned int n);
-
- void bufferColorArray(unsigned int colorCount, float* colors);
-
- void bufferNormalArray(unsigned int normalCount, float* normals);
-
- void bufferTriangles(unsigned int count,
- unsigned int* indices, float* texCoords,
- int* textures, unsigned int* flags);
-
- void bufferVertexArray(unsigned int vertexCount, float* vertices);
-
- void setColor(unsigned int index, float r, float g, float b, float a);
-
- void setColor(unsigned int index, float rgba[4]);
-
- void setNormal(unsigned int index, float i, float j, float k);
-
- void setVertex(unsigned int index, float x, float y, float z);
-
- #if 0
- void sortFacesByTexture();
-
- void addFace(int textureIndex, int textureIndexB, unsigned int flags,
- unsigned int vertexIndexCount, float* vertexIndices);
-
- void addTexTiledFace(int textureIndex, int textureIndexB,
- unsigned int flags, unsigned int indexCount,
- float* vertexIndices, float* texcoords);
-
- void bufferTexcoords(unsigned int texcoordCount, float* texcoords);
-
- void duplicateArraysForTexTiledTexcoords();
- #endif
-
- unsigned int mFlags;
-
- MeshMode mMode;
-
- unsigned int mNumVertices;
- float** mVertices; //!< XYZ
-
- unsigned int mNumNormals;
- float** mNormals; //!< IJK
-
- unsigned int mNumColors;
- float** mColors; //!< RGBA
-
- unsigned int mNumTris;
- tris_t* mTris;
-
- unsigned int mNumQuads;
- rect_t* mQuads;
-
- unsigned int mTriangleCount;
- int* mTriangleTextures;
- unsigned int* mTriangleIndices;
- unsigned int* mTriangleFlags;
- float* mTriangleTexCoordArray;
-
- float* mVertexArray;
- float* mNormalArray;
- float* mColorArray;
- };
-
- #endif
|