update for MingW/CMake
[blender-staging.git] / source / gameengine / Rasterizer / RAS_MeshObject.h
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29 #ifndef __RAS_MESHOBJECT
30 #define __RAS_MESHOBJECT
31
32 #if defined(WIN32) && !defined(FREE_WINDOWS)
33 // disable the STL warnings ("debug information length > 255")
34 #pragma warning (disable:4786)
35 #endif
36
37 #include <vector>
38 #include <set>
39 #include <list>
40
41 #include "RAS_Polygon.h"
42 #include "RAS_MaterialBucket.h"
43 #include "MT_Transform.h"
44
45 #include "GEN_HashedPtr.h"
46
47 struct Mesh;
48 class RAS_Deformer;
49
50 /* RAS_MeshObject is a mesh used for rendering. It stores polygons,
51  * but the actual vertices and index arrays are stored in material
52  * buckets, referenced by the list of RAS_MeshMaterials. */
53
54 class RAS_MeshObject
55 {
56 private:
57         unsigned int                            m_debugcolor;
58
59         bool                                            m_bModified;
60         bool                                            m_bMeshModified;
61
62         STR_String                                      m_name;
63         static STR_String                       s_emptyname;
64
65         vector<class RAS_Polygon*>      m_Polygons;
66
67         /* polygon sorting */
68         struct polygonSlot;
69         struct backtofront;
70         struct fronttoback;
71
72 protected:
73         vector<int>                                             m_cacheWeightIndex;
74         list<RAS_MeshMaterial>                  m_materials;
75         Mesh*                                                   m_mesh;
76
77 public:
78         // for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime)
79         RAS_MeshObject(Mesh* mesh);
80         virtual ~RAS_MeshObject();
81
82
83         // for shape keys, 
84         void CheckWeightCache(struct Object* obj);
85         
86         /* materials */
87         int                                     NumMaterials();
88         const STR_String&       GetMaterialName(unsigned int matid);
89         const STR_String&       GetTextureName(unsigned int matid);
90
91         RAS_MeshMaterial*       GetMeshMaterial(unsigned int matid);
92         RAS_MeshMaterial*       GetMeshMaterial(RAS_IPolyMaterial *mat);
93         int                                     GetMaterialId(RAS_IPolyMaterial *mat);
94
95         list<RAS_MeshMaterial>::iterator GetFirstMaterial();
96         list<RAS_MeshMaterial>::iterator GetLastMaterial();
97
98         //unsigned int          GetLightLayer();
99
100         /* name */
101         void                            SetName(const char *name);
102         STR_String&                     GetName();
103
104         /* modification state */
105         bool                            MeshModified();
106         void                            SetMeshModified(bool v){m_bMeshModified = v;}
107
108         /* original blender mesh */
109         Mesh*                           GetMesh() { return m_mesh; }
110
111         /* mesh construction */
112         
113         virtual RAS_Polygon*    AddPolygon(RAS_MaterialBucket *bucket, int numverts);
114         virtual void                    AddVertex(RAS_Polygon *poly, int i,
115                                                         const MT_Point3& xyz,
116                                                         const MT_Point2& uv,
117                                                         const MT_Point2& uv2,
118                                                         const MT_Vector4& tangent,
119                                                         const unsigned int rgbacolor,
120                                                         const MT_Vector3& normal,
121                                                         bool flat,
122                                                         int origindex);
123
124         void                                    SchedulePolygons(int drawingmode);
125
126         /* vertex and polygon acces */
127         int                                     NumVertices(RAS_IPolyMaterial* mat);
128         RAS_TexVert*            GetVertex(unsigned int matid, unsigned int index);
129         const float*            GetVertexLocation(unsigned int orig_index);
130
131         int                                     NumPolygons();
132         RAS_Polygon*            GetPolygon(int num) const;
133         
134         /* buckets */
135         virtual void            AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
136
137         void                            RemoveFromBuckets(void *clientobj);
138         void                            EndConversion() {
139 #if 0
140                 m_sharedvertex_map.clear(); // SharedVertex
141                 vector<vector<SharedVertex> >   shared_null(0);
142                 shared_null.swap( m_sharedvertex_map ); /* really free the memory */
143 #endif
144         }
145
146         /* colors */
147         void                            DebugColor(unsigned int abgr);
148         void                            SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
149         
150         /* polygon sorting by Z for alpha */
151         void                            SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform);
152
153
154         bool                            HasColliderPolygon() {
155                 int numpolys= NumPolygons();
156                 for (int p=0; p<numpolys; p++)
157                         if (m_Polygons[p]->IsCollider())
158                                 return true;
159                 
160                 return false;
161         }
162
163         /* for construction to find shared vertices */
164         struct SharedVertex {
165                 RAS_DisplayArray *m_darray;
166                 int m_offset;
167         };
168
169         vector<vector<SharedVertex> >   m_sharedvertex_map;
170         
171         
172 #ifdef WITH_CXX_GUARDEDALLOC
173 public:
174         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_MeshObject"); }
175         void operator delete( void *mem ) { MEM_freeN(mem); }
176 #endif
177 };
178
179 #endif //__RAS_MESHOBJECT
180