glc_lod.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 
00028 #include "glc_lod.h"
00029 
00030 // Class chunk id
00031 quint32 GLC_Lod::m_ChunkId= 0xA708;
00032 
00033 // Default Constructor
00034 GLC_Lod::GLC_Lod()
00035 : m_Accuracy(0.0)
00036 , m_IboId(0)
00037 , m_IndexVector()
00038 , m_IndexSize(0)
00039 {
00040 
00041 }
00042 
00043 // Construct an engine Lod with the specified accuracy
00044 GLC_Lod::GLC_Lod(double accuracy)
00045 : m_Accuracy(accuracy)
00046 , m_IboId(0)
00047 , m_IndexVector()
00048 , m_IndexSize(0)
00049 {
00050 
00051 }
00052 
00053 // Copy Constructor
00054 GLC_Lod::GLC_Lod(const GLC_Lod& lod)
00055 : m_Accuracy(lod.m_Accuracy)
00056 , m_IboId(0)
00057 , m_IndexVector(lod.indexVector())
00058 , m_IndexSize(lod.m_IndexSize)
00059 {
00060 
00061 
00062 }
00063 
00064 // Overload "=" operator
00065 GLC_Lod& GLC_Lod::operator=(const GLC_Lod& lod)
00066 {
00067         if (this != &lod)
00068         {
00069                 m_Accuracy= lod.m_Accuracy;
00070                 m_IboId= 0;
00071                 m_IndexVector= lod.indexVector();
00072                 m_IndexSize= lod.m_IndexSize;
00073         }
00074 
00075         return *this;
00076 }
00077 
00078 GLC_Lod::~GLC_Lod()
00079 {
00080         // Delete IBO
00081         if (0 != m_IboId)
00082         {
00083                 glDeleteBuffers(1, &m_IboId);
00084         }
00085 }
00086 
00088 // Get Functions
00090 // Return the class Chunk ID
00091 quint32 GLC_Lod::chunckID()
00092 {
00093         return m_ChunkId;
00094 }
00095 
00096 // Return The unique index Vector
00097 QVector<GLuint> GLC_Lod::indexVector() const
00098 {
00099         if (0 != m_IboId)
00100         {
00101                 // VBO created get data from VBO
00102                 const int sizeOfIbo= m_IndexSize;
00103                 const GLsizeiptr dataSize= sizeOfIbo * sizeof(GLuint);
00104                 QVector<GLuint> indexVector(sizeOfIbo);
00105 
00106                 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IboId);
00107                 GLvoid* pIbo = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY);
00108                 memcpy(indexVector.data(), pIbo, dataSize);
00109                 glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
00110                 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
00111                 return indexVector;
00112         }
00113         else
00114         {
00115                 return m_IndexVector;
00116         }
00117 }
00118 
00119 // Non-member stream operator
00120 QDataStream &operator<<(QDataStream &stream, const GLC_Lod &lod)
00121 {
00122         quint32 chunckId= GLC_Lod::m_ChunkId;
00123         stream << chunckId;
00124 
00125         stream << lod.m_Accuracy;
00126         stream << lod.indexVector();
00127 
00128         return stream;
00129 }
00130 QDataStream &operator>>(QDataStream &stream, GLC_Lod &lod)
00131 {
00132         quint32 chunckId;
00133         stream >> chunckId;
00134         Q_ASSERT(chunckId == GLC_Lod::m_ChunkId);
00135 
00136         stream >> lod.m_Accuracy;
00137 
00138         QVector<GLuint> indexVector;
00139         stream >> indexVector;
00140 
00141         *(lod.indexVectorHandle())= indexVector;
00142         return stream;
00143 }
00144 

SourceForge.net Logo

©2005 Laurent Ribon