GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_primitivegroup.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #include "glc_primitivegroup.h"
26 #include "../glc_state.h"
27 
28 // Class chunk id
29 quint32 GLC_PrimitiveGroup::m_ChunkId= 0xA700;
30 
31 // Default constructor
33 : m_Id(materialId)
34 , m_TrianglesIndex()
35 , m_TrianglesGroupsSizes()
36 , m_TrianglesGroupOffset()
37 , m_TrianglesGroupOffseti()
38 , m_TrianglesId()
39 , m_StripsIndex()
40 , m_StripIndexSizes()
41 , m_StripIndexOffset()
42 , m_StripIndexOffseti()
43 , m_StripsId()
44 , m_FansIndex()
45 , m_FansIndexSizes()
46 , m_FanIndexOffset()
47 , m_FanIndexOffseti()
48 , m_FansId()
49 , m_IsFinished(false)
50 , m_TrianglesIndexSize(0)
51 , m_TrianglesStripSize(0)
52 , m_TrianglesFanSize(0)
53 {
54 
55 
56 }
59 : m_Id(group.m_Id)
60 , m_TrianglesIndex(group.m_TrianglesIndex)
61 , m_TrianglesGroupsSizes(group.m_TrianglesGroupsSizes)
62 , m_TrianglesGroupOffset(group.m_TrianglesGroupOffset)
63 , m_TrianglesGroupOffseti(group.m_TrianglesGroupOffseti)
64 , m_TrianglesId(group.m_TrianglesId)
65 , m_StripsIndex(group.m_StripsIndex)
66 , m_StripIndexSizes(group.m_StripIndexSizes)
67 , m_StripIndexOffset(group.m_StripIndexOffset)
68 , m_StripIndexOffseti(group.m_StripIndexOffseti)
69 , m_StripsId(group.m_StripsId)
70 , m_FansIndex(group.m_FansIndex)
71 , m_FansIndexSizes(group.m_FansIndexSizes)
72 , m_FanIndexOffset(group.m_FanIndexOffset)
73 , m_FanIndexOffseti(group.m_FanIndexOffseti)
74 , m_FansId(group.m_FansId)
75 , m_IsFinished(group.m_IsFinished)
76 , m_TrianglesIndexSize(group.m_TrianglesIndexSize)
77 , m_TrianglesStripSize(group.m_TrianglesStripSize)
78 , m_TrianglesFanSize(group.m_TrianglesFanSize)
79 {
80 
81 
82 }
83 
86 : m_Id(id)
87 , m_TrianglesIndex(group.m_TrianglesIndex)
88 , m_TrianglesGroupsSizes(group.m_TrianglesGroupsSizes)
89 , m_TrianglesGroupOffset(group.m_TrianglesGroupOffset)
90 , m_TrianglesGroupOffseti(group.m_TrianglesGroupOffseti)
91 , m_TrianglesId(group.m_TrianglesId)
92 , m_StripsIndex(group.m_StripsIndex)
93 , m_StripIndexSizes(group.m_StripIndexSizes)
94 , m_StripIndexOffset(group.m_StripIndexOffset)
95 , m_StripIndexOffseti(group.m_StripIndexOffseti)
96 , m_StripsId(group.m_StripsId)
97 , m_FansIndex(group.m_FansIndex)
98 , m_FansIndexSizes(group.m_FansIndexSizes)
99 , m_FanIndexOffset(group.m_FanIndexOffset)
100 , m_FanIndexOffseti(group.m_FanIndexOffseti)
101 , m_FansId(group.m_FansId)
102 , m_IsFinished(group.m_IsFinished)
103 , m_TrianglesIndexSize(group.m_TrianglesIndexSize)
104 , m_TrianglesStripSize(group.m_TrianglesStripSize)
105 , m_TrianglesFanSize(group.m_TrianglesFanSize)
106 {
107 
108 
109 }
110 
111 // = operator
113 {
114  if (this != &group)
115  {
116  m_Id= group.m_Id;
126  m_StripsId= group.m_StripsId;
127  m_FansIndex= group.m_FansIndex;
131  m_FansId= group.m_FansId;
132  m_IsFinished= group.m_IsFinished;
136  }
137  return *this;
138 }
139 
141 {
142 
143 }
144 // Return the class Chunk ID
146 {
147  return m_ChunkId;
148 }
149 
150 // Add triangles to the group
152 {
153  m_TrianglesIndex+= input;
155 
156  m_TrianglesGroupsSizes.append(static_cast<GLsizei>(input.size()));
157 
158  if (m_TrianglesGroupOffseti.isEmpty())
159  {
160  m_TrianglesGroupOffseti.append(0);
161  }
162  int offset= m_TrianglesGroupOffseti.last() + m_TrianglesGroupsSizes.last();
163  m_TrianglesGroupOffseti.append(offset);
164 
165  // The Triangles group id
166  if (0 != id) m_TrianglesId.append(id);
167  else Q_ASSERT(m_TrianglesId.isEmpty());
168 }
169 
170 // Add triangle strip to the group
172 {
173  m_StripsIndex+= input;
175 
176  m_StripIndexSizes.append(static_cast<GLsizei>(input.size()));
177 
178  if (m_StripIndexOffseti.isEmpty())
179  {
180  m_StripIndexOffseti.append(0);
181  }
182  int offset= m_StripIndexOffseti.last() + m_StripIndexSizes.last();
183  m_StripIndexOffseti.append(offset);
184 
185  // The strip id
186  if (0 != id) m_StripsId.append(id);
187  else Q_ASSERT(m_StripsId.isEmpty());
188 }
189 // Set the triangle index offset
191 {
192  //m_TrianglesGroupOffseti.pop_back();
193  const int size= m_TrianglesGroupOffseti.size();
194  for (int i= 0; i < size; ++i)
195  {
196  m_TrianglesGroupOffset.append(BUFFER_OFFSET(static_cast<GLsizei>(m_TrianglesGroupOffseti[i]) * sizeof(GLuint) + reinterpret_cast<GLsizeiptr>(pOffset)));
197  }
198 }
199 
200 // Set the triangle index offset
202 {
203  m_TrianglesGroupOffseti.pop_back();
204  const int size= m_TrianglesGroupOffseti.size();
205  for (int i= 0; i < size; ++i)
206  {
208  }
209 }
210 
211 // Set base triangle strip offset
213 {
214  //m_StripIndexOffseti.pop_back();
215  const int size= m_StripIndexOffseti.size();
216  for (int i= 0; i < size; ++i)
217  {
218  m_StripIndexOffset.append(BUFFER_OFFSET(static_cast<GLsizei>(m_StripIndexOffseti[i]) * sizeof(GLuint) + reinterpret_cast<GLsizeiptr>(pOffset)));
219  }
220 }
221 
222 // Set base triangle strip offset
224 {
225  m_StripIndexOffseti.pop_back();
226  const int size= m_StripIndexOffseti.size();
227  for (int i= 0; i < size; ++i)
228  {
230  }
231 }
232 
235 {
236  m_FansIndex+= input;
238 
239  m_FansIndexSizes.append(static_cast<GLsizei>(input.size()));
240 
241  if (m_FanIndexOffseti.isEmpty())
242  {
243  m_FanIndexOffseti.append(0);
244  }
245  int offset= m_FanIndexOffseti.last() + m_FansIndexSizes.last();
246  m_FanIndexOffseti.append(offset);
247 
248  // The fan id
249  if (0 != id) m_FansId.append(id);
250  else Q_ASSERT(m_FansId.isEmpty());
251 
252 
253 }
254 
255 // Set base triangle fan offset
257 {
258  //m_FanIndexOffseti.pop_back();
259  const int size= m_FanIndexOffseti.size();
260  for (int i= 0; i < size; ++i)
261  {
262  m_FanIndexOffset.append(BUFFER_OFFSET(static_cast<GLsizei>(m_FanIndexOffseti[i]) * sizeof(GLuint) + reinterpret_cast<GLsizeiptr>(pOffset)));
263  }
264 }
265 
266 // Set base triangle fan offset
268 {
269  m_FanIndexOffseti.pop_back();
270  const int size= m_FanIndexOffseti.size();
271  for (int i= 0; i < size; ++i)
272  {
273  m_FanIndexOffseti[i]= m_FanIndexOffseti[i] + offset;
274  }
275 }
276 
277 // Change index to VBO mode
279 {
280  m_TrianglesGroupOffset.clear();
281  const int triangleOffsetSize= m_TrianglesGroupOffseti.size();
282  for (int i= 0; i < triangleOffsetSize; ++i)
283  {
284  m_TrianglesGroupOffset.append(BUFFER_OFFSET(static_cast<GLsizei>(m_TrianglesGroupOffseti.at(i)) * sizeof(GLuint)));
285  }
286 
287  m_StripIndexOffset.clear();
288  const int stripOffsetSize= m_StripIndexOffseti.size();
289  for (int i= 0; i < stripOffsetSize; ++i)
290  {
291  m_StripIndexOffset.append(BUFFER_OFFSET(static_cast<GLsizei>(m_StripIndexOffseti.at(i)) * sizeof(GLuint)));
292  }
293 
294  m_FanIndexOffset.clear();
295  const int fanOffsetSize= m_FanIndexOffseti.size();
296  for (int i= 0; i < fanOffsetSize; ++i)
297  {
298  m_FanIndexOffset.append(BUFFER_OFFSET(static_cast<GLsizei>(m_FanIndexOffseti.at(i)) * sizeof(GLuint)));
299  }
300 }
301 
302 // Clear the group
304 {
305  m_TrianglesIndex.clear();
306  m_TrianglesGroupsSizes.clear();
307  m_TrianglesGroupOffset.clear();
308  m_TrianglesGroupOffseti.clear();
309  m_StripsIndex.clear();
310  m_StripIndexSizes.clear();
311  m_StripIndexOffset.clear();
312  m_StripIndexOffseti.clear();
313  m_FansIndex.clear();
314  m_FansIndexSizes.clear();
315  m_FanIndexOffset.clear();
316  m_FanIndexOffseti.clear();
317  m_IsFinished= false;
321 }
322 
323 
324 // Non Member methods
325 // Non-member stream operator
326 QDataStream &operator<<(QDataStream &stream, const GLC_PrimitiveGroup &primitiveGroup)
327 {
328  Q_ASSERT(primitiveGroup.isFinished());
329  quint32 chunckId= GLC_PrimitiveGroup::m_ChunkId;
330  stream << chunckId;
331 
332  // Primitive group id
333  stream << primitiveGroup.m_Id;
334 
335  // Triangles, strips and fan offset index
336  OffsetVectori trianglesGroupOffseti;
337  OffsetVectori stripIndexOffseti;
338  OffsetVectori fanIndexOffseti;
339 
340  // Get triangles, strips and fans offset
341  trianglesGroupOffseti= primitiveGroup.m_TrianglesGroupOffseti;
342  stripIndexOffseti= primitiveGroup.m_StripIndexOffseti;
343  fanIndexOffseti= primitiveGroup.m_FanIndexOffseti;
344 
345  // Triangles index
346  stream << primitiveGroup.m_TrianglesIndexSize;
347  stream << trianglesGroupOffseti;
348  stream << primitiveGroup.m_TrianglesGroupsSizes;
349  stream << primitiveGroup.m_TrianglesId;
350 
351  // Triangles strips index
352  stream << primitiveGroup.m_TrianglesStripSize;
353  stream << stripIndexOffseti;
354  stream << primitiveGroup.m_StripIndexSizes;
355  stream << primitiveGroup.m_StripsId;
356 
357  // Triangles fans index
358  stream << primitiveGroup.m_TrianglesFanSize;
359  stream << fanIndexOffseti;
360  stream << primitiveGroup.m_FansIndexSizes;
361  stream << primitiveGroup.m_FansId;
362 
363  return stream;
364 }
365 QDataStream &operator>>(QDataStream &stream, GLC_PrimitiveGroup &primitiveGroup)
366 {
367  quint32 chunckId;
368  stream >> chunckId;
369  Q_ASSERT(chunckId == GLC_PrimitiveGroup::m_ChunkId);
370  stream >> primitiveGroup.m_Id;
371 
372  // Triangles index
373  stream >> primitiveGroup.m_TrianglesIndexSize;
374  stream >> primitiveGroup.m_TrianglesGroupOffseti;
375  stream >> primitiveGroup.m_TrianglesGroupsSizes;
376  stream >> primitiveGroup.m_TrianglesId;
377 
378  // Triangles strips index
379  stream >> primitiveGroup.m_TrianglesStripSize;
380  stream >> primitiveGroup.m_StripIndexOffseti;
381  stream >> primitiveGroup.m_StripIndexSizes;
382  stream >> primitiveGroup.m_StripsId;
383 
384  // Triangles fans index
385  stream >> primitiveGroup.m_TrianglesFanSize;
386  stream >> primitiveGroup.m_FanIndexOffseti;
387  stream >> primitiveGroup.m_FansIndexSizes;
388  stream >> primitiveGroup.m_FansId;
389 
390 
391  primitiveGroup.finish();
392 
393  return stream;
394 }
395 

©2005-2013 Laurent Ribon