00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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