"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSGraphicsLib/Src/IndexBuffer/LSGIndexBuffer.h

00001 
00016 #ifndef __LSG_INDEXBUFFER_H__
00017 #define __LSG_INDEXBUFFER_H__
00018 
00019 #include "../LSGGraphicsLib.h"
00020 #include "../TriangleStrips/LSGTriangleStripper.h"
00021 #include "../VertexBuffer/LSGVertexBuffer.h"
00022 #ifdef LSG_DX9
00023 #include "../DirectX/LSGDirectX9IndexBuffer.h"
00024 #endif  // #ifdef LSG_DX9
00025 #ifdef LSG_DX10
00026 #include "../DirectX/LSGDirectX10IndexBuffer.h"
00027 #endif  // #ifdef LSG_DX10
00028 #ifdef LSG_DX11
00029 #include "../DirectX/LSGDirectX11IndexBuffer.h"
00030 #endif  // #ifdef LSG_DX11
00031 #ifdef LSG_OGLES
00032 #include "../OpenGLES/LSGOpenGlEsIndexBuffer.h"
00033 #endif  // #ifdef LSG_OGLES
00034 #ifdef LSG_OGL
00035 #include "../OpenGL/LSGOpenGlIndexBuffer.h"
00036 #endif  // #ifdef LSG_OGL
00037 #include "LSGIndexBufferBase.h"
00038 
00039 namespace lsg {
00040 
00047         class CIndexBuffer : protected
00048 #ifdef LSG_OGL
00049                 COpenGlIndexBuffer
00050 #endif  // #ifdef LSG_OGL
00051 #ifdef LSG_OGLES
00052                 COpenGlEsIndexBuffer
00053 #endif  // #ifdef LSG_OGLES
00054 #ifdef LSG_DX9
00055                 CDirectX9IndexBuffer
00056 #endif  // #ifdef LSG_DX9
00057 #ifdef LSG_DX10
00058                 CDirectX10IndexBuffer
00059 #endif  // #ifdef LSG_DX10
00060 #ifdef LSG_DX11
00061                 CDirectX11IndexBuffer
00062 #endif  // #ifdef LSG_DX11
00063 
00064         {
00065         public :
00066                 // == Various constructors.
00067                 LSE_CALLCTOR                                                            CIndexBuffer();
00068                 LSE_CALLCTOR                                                            ~CIndexBuffer();
00069 
00070 
00071                 // == Operators.
00078                 CIndexBuffer & LSE_CALL                                         operator = ( const CIndexBuffer &_ibOther );
00079 
00080 
00081                 // == Functions.
00093                 LSBOOL LSE_CALL                                                         CreateIndexBuffer( LSUINT32 _ui32InitialElements, LSUINT32 _ui32Usage, LSBOOL _bUse32Bits = false, CAllocator * _paAllocator = NULL );
00094 
00104                 LSBOOL LSE_CALL                                                         CreateIndexBufferFromVertexBuffer( CVertexBuffer &_vbBuffer, LSUINT32 _ui32Usage, CAllocator * _paAllocator = NULL );
00105 
00119                 LSBOOL LSE_CALL                                                         CreateTriangleStripGrid( LSUINT32 _ui32VerticesPerRow, LSUINT32 _ui32Rows,
00120                         LSUINT32 _ui32Usage, CAllocator * _paAllocator = NULL );
00121 
00122 
00129                 LSVOID LSE_CALL                                                         SetAllocator( CAllocator * _paAllocator );
00130 
00136                 LSBOOL LSE_CALL                                                         MakeTriangleStrip();
00137 
00141                 LSVOID LSE_CALL                                                         Reset();
00142 
00150                 LSBOOL LSE_CALL                                                         Finalize();
00151 
00158                 LSBOOL LSE_CALL                                                         Lock();
00159 
00166                 LSBOOL LSE_CALL                                                         UnLock();
00167 
00174                 LSBOOL LSE_CALL                                                         PushIndex( LSUINT32 _ui32Index );
00175 
00185                 LSE_INLINE LSBOOL LSE_CALL                                      SetIndex( LSUINT32 _ui32IndexIndex, LSUINT32 _ui32Value );
00186 
00192                 LSE_INLINE LSUINT32 LSE_CALL                            TotalIndices() const;
00193 
00200                 LSE_INLINE const LSVOID * LSE_CALL                      GetIndices() const;
00201 
00208                 LSE_INLINE const LSUINT32 * LSE_CALL            Get32BitIndices() const;
00209 
00216                 LSE_INLINE const LSUINT16 * LSE_CALL            Get16BitIndices() const;
00217 
00223                 LSE_INLINE LSBOOL LSE_CALL                                      IndicesAre32Bits() const;
00224 
00225         protected :
00226                 // == Types.
00230                 typedef struct LSG_UNIQUE_VB_ELEMENT {
00234                         LSVOID *                                                                pvElement;
00235 
00239                         LSUINT32                                                                ui32Size;
00240 
00241 
00242                         // == Operators.
00249                         LSBOOL LSE_CALL                                                 operator < ( const LSG_UNIQUE_VB_ELEMENT &_uveOther ) const;
00250 
00257                         LSBOOL LSE_CALL                                                 operator == ( const LSG_UNIQUE_VB_ELEMENT &_uveOther ) const;
00258                 } * LPLSG_UNIQUE_VB_ELEMENT, * const LPCLSG_UNIQUE_VB_ELEMENT;
00259 
00260                 // == Members.
00261                 
00262 
00263                 // == Functions.
00269                 LSBOOL LSE_CALL                                                         UpgradeList();
00270 
00277                 LSE_INLINE LSVOID LSE_CALL                                      Render( const CVertexBuffer &_vbBuffer, LSUINT32 _ui32TotalPrimitives ) const;
00278 
00279         private :
00280 #ifdef LSG_OGL
00281                 typedef COpenGlIndexBuffer                                      Parent;
00282 #endif  // #ifdef LSG_OGL
00283 #ifdef LSG_OGLES
00284                 typedef COpenGlEsIndexBuffer                            Parent;
00285 #endif  // #ifdef LSG_OGLES
00286 #ifdef LSG_DX9
00287                 typedef CDirectX9IndexBuffer                            Parent;
00288 #endif  // #ifdef LSG_DX9
00289 #ifdef LSG_DX10
00290                 typedef CDirectX10IndexBuffer                           Parent;
00291 #endif  // #ifdef LSG_DX10
00292 #ifdef LSG_DX11
00293                 typedef CDirectX11IndexBuffer                           Parent;
00294 #endif  // #ifdef LSG_DX11
00295 
00296                 friend class                                                            CFnd;
00297         };
00298 
00299 
00300         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00301         // DEFINITIONS
00302         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00303         // == Functions.
00313         LSE_INLINE LSBOOL LSE_CALL CIndexBuffer::SetIndex( LSUINT32 _ui32IndexIndex, LSUINT32 _ui32Value ) {
00314                 register LSUINT32 ui32Total = m_vBuffer.Length() / m_ui32ElementSize;
00315                 if ( _ui32IndexIndex >= ui32Total ) { return false; }
00316 
00317                 // If the index is above 0xFFFF, we need 32 bits to hold it.
00318                 if ( _ui32Value & 0xFFFF0000UL ) {
00319                         //      If not using 32 bits already, upgrade the list.
00320                         if ( m_ui32ElementSize != sizeof( LSUINT32 ) ) {
00321                                 if ( !UpgradeList() ) { return false; }
00322                         }
00323                 }
00324                 if ( m_ui32ElementSize == sizeof( LSUINT32 ) ) {
00325                         register LSUINT32 * pui32Dest = reinterpret_cast<LSUINT32 *>(&m_vBuffer[0]) + _ui32IndexIndex;
00326                         (*pui32Dest) = _ui32Value;
00327                 }
00328                 else {
00329                         register LSUINT16 * pui16Dest = reinterpret_cast<LSUINT16 *>(&m_vBuffer[0]) + _ui32IndexIndex;
00330                         (*pui16Dest) = static_cast<LSUINT16>(_ui32Value);
00331                 }
00332                 return true;
00333         }
00334 
00340         LSE_INLINE LSUINT32 LSE_CALL CIndexBuffer::TotalIndices() const {
00341                 return m_ui32TotalIndices;
00342         }
00343 
00350         LSE_INLINE const LSVOID * LSE_CALL CIndexBuffer::GetIndices() const {
00351                 if ( m_ui32LockCount == 0UL || !m_vBuffer.Length() ) { return NULL; }
00352                 return &m_vBuffer[0];
00353         }
00354 
00361         LSE_INLINE const LSUINT32 * LSE_CALL CIndexBuffer::Get32BitIndices() const {
00362                 return static_cast<const LSUINT32 *>(GetIndices());
00363         }
00364 
00371         LSE_INLINE const LSUINT16 * LSE_CALL CIndexBuffer::Get16BitIndices() const {
00372                 return static_cast<const LSUINT16 *>(GetIndices());
00373         }
00374 
00380         LSE_INLINE LSBOOL LSE_CALL CIndexBuffer::IndicesAre32Bits() const {
00381                 return m_ui32ElementSize == sizeof( LSUINT32 );
00382         }
00383 
00390         LSE_INLINE LSVOID LSE_CALL CIndexBuffer::Render( const CVertexBuffer &_vbBuffer, LSUINT32 _ui32TotalPrimitives ) const {
00391                 Parent::RenderApi( _vbBuffer, _ui32TotalPrimitives );
00392         }
00393 
00394 }       // namespace lsg
00395 
00396 #endif  // __LSG_INDEXBUFFER_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator