Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

polygonbuffer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002               polygonbuffer.h  -  Polygon and polygon strip buffers
00003                              -------------------
00004     begin                : Fri Nov 2 2001
00005     copyright            : (C) 2001 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, polygonbuffer.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2001
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEPOLYGONBUFFER_H
00028 #define __NEPOLYGONBUFFER_H
00029 
00030 
00031 #include "base.h"
00032 #include "polygon.h"
00033 #include "pointer.h"
00034 #include "buffer.h"
00035 #include "vertexbuffer.h"
00036 #include "material.h"
00037 #include "nemath.h"
00038 #include "util.h"
00039 
00040 #include <assert.h>
00041 
00042 #include <vector>
00043 
00044 
00051 namespace NeoEngine
00052 {
00053 
00054 
00060 class NEOENGINE_API PolygonStripBuffer : public Buffer
00061 {
00062     friend class PolygonBuffer;
00063 
00064     protected:
00065 
00067         unsigned short                               *m_pusBuffer;
00068 
00070         unsigned short                               *m_pusIndices;
00071 
00076         virtual bool                                  AcquireLock() { m_pusIndices = m_pusBuffer; return true; }
00077 
00081         virtual void                                  ReleaseLock() { m_pusIndices = 0; }
00082 
00083 
00084     public:
00085 
00086 
00092                                                       PolygonStripBuffer( unsigned int uiType, unsigned int uiNumPolygons, const unsigned short *pusData = 0 ) : Buffer( uiType ), m_pusBuffer( 0 ), m_pusIndices( 0 ) { AllocateStrip( uiNumPolygons, pusData ); }
00093 
00097         virtual                                      ~PolygonStripBuffer();
00098 
00104         virtual void                                  AllocateStrip( unsigned int uiNumPolygons, const unsigned short *pusData = 0 );
00105 
00110         inline void                                   LoadStripData( const unsigned short *pusData ) { fmemcpy( m_pusIndices, pusData, sizeof( unsigned short ) * ( m_uiNumCurrent + 2 ) ); }
00111 
00116         inline unsigned short                        *GetIndices() { return m_pusIndices; }
00117 
00123         virtual const void                           *GetRenderData() const { return m_pusBuffer; }
00124 };
00125 
00126 
00127 #ifndef __HAVE_SMARTPOINTER_NEPOLYGONSTRIPBUFFER
00128    //Define smart pointer
00129 #  ifdef _MSC_VER
00130 #    pragma warning( disable : 4786 )
00131 #  endif
00132    SmartPointer( PolygonStripBuffer );
00133 #  define __HAVE_SMARTPOINTER_NEPOLYGONSTRIPBUFFER
00134 #endif
00135 
00136 
00143 class NEOENGINE_API PolygonBuffer : public Buffer
00144 {
00145     protected:
00146 
00153         class AdjacencyData
00154         {
00155             public:
00156 
00158                 unsigned int                          m_uiEdges[3][2];
00159 
00161                 unsigned int                          m_uiAdjTri[3];
00162     
00164                 unsigned short                        m_uiOtherVertex[3];
00165         };
00166 
00168         Polygon                                      *m_pkBuffer;
00169 
00171         Polygon                                      *m_pkPolygons;
00172 
00174         Vector3d                                     *m_pkNormals;
00175 
00177         Edge                                         *m_pkEdges;
00178 
00179 
00189         void                                          ExtendStrip( unsigned int uiPolygon, unsigned int uiEdge, AdjacencyData *pkAdj, unsigned int *puiStrip, unsigned int *puiStripLen, unsigned char *pucAdded );
00190 
00191 
00196         virtual bool                                  AcquireLock() { m_pkPolygons = m_pkBuffer; return true; }
00197 
00201         virtual void                                  ReleaseLock() { m_pkPolygons = 0; }
00202 
00203 
00204     public:
00205 
00207         PolygonStripBufferPtr                         m_pkStrip;
00208 
00210         VertexBufferPtr                               m_pkVertexBuffer;
00211 
00213         MaterialPtr                                   m_pkMaterial;
00214 
00215 
00222                                                       PolygonBuffer( unsigned int uiType, unsigned int uiNumPolygons, const Polygon *pkData = 0, bool bStripify = false ) : Buffer( uiType ), m_pkBuffer( 0 ), m_pkPolygons( 0 ), m_pkNormals( 0 ), m_pkEdges( 0 ) { AllocatePolygons( uiNumPolygons, pkData, bStripify ); }
00223 
00227         virtual                                      ~PolygonBuffer();
00228 
00235         virtual void                                  AllocatePolygons( unsigned int iNumPolygons, const Polygon *pkData = 0, bool bStripify = false );
00236     
00242         inline void                                   LoadPolygonData( const Polygon *pkPolygons, bool bStripify = false ) { fmemcpy( m_pkPolygons, pkPolygons, sizeof( Polygon ) * m_uiNumCurrent ); if( bStripify ) Stripify(); else m_pkStrip = 0; }
00243 
00247         void                                          Stripify();
00248 
00252         inline bool                                   IsStripped() const { return( (bool)m_pkStrip ); }
00253 
00259         void                                          CalculateNormals( VertexBufferPtr pkVertexBuffer = 0, bool bNormalize = true );
00260 
00265         void                                          CalculateEdges( VertexBufferPtr pkVertexBuffer = 0 );
00266 
00270         inline Vector3d                              *GetNormals() { return m_pkNormals; }
00271 
00275         inline Edge                                  *GetEdges() { return m_pkEdges; }
00276 
00280         inline PolygonStripBufferPtr                 &GetStrip() { return m_pkStrip; }
00281 
00286         inline Polygon                               *GetPolygon( unsigned int uiElement = 0 ) { assert( uiElement < m_uiNumCurrent ); return &m_pkPolygons[ uiElement ]; }
00287 
00293         virtual const void                           *GetRenderData() const { return m_pkBuffer; }
00294 
00299         inline Polygon                               &operator []( unsigned int uiElement ) { assert( uiElement < m_uiNumCurrent ); return m_pkPolygons[ uiElement ]; }
00300 };
00301 
00302 
00303 #ifndef __HAVE_SMARTPOINTER_NEPOLYGONBUFFER
00304    //Define smart pointer
00305 #  ifdef _MSC_VER
00306 #    pragma warning( disable : 4786 )
00307 #  endif
00308    SmartPointer( PolygonBuffer );
00309 #  define __HAVE_SMARTPOINTER_NEPOLYGONBUFFER
00310 #endif
00311 
00312 
00313 };
00314 
00315 
00316 #endif

Generated on Wed Jan 21 14:21:07 2004 for NeoEngine by doxygen 1.3.5