"L. Spiro Engine"
|
00001 00017 #ifndef __LSG_OPENGLVERTEXBUFFER_H__ 00018 #define __LSG_OPENGLVERTEXBUFFER_H__ 00019 00020 #include "../LSGGraphicsLib.h" 00021 00022 #ifdef LSG_OGL 00023 00024 #include "../VertexBuffer/LSGVertexBufferBase.h" 00025 #include "CriticalSection/LSHCriticalSection.h" 00026 #include "Vector/LSTLVectorPoD.h" 00027 00028 namespace lsg { 00029 00037 class COpenGlVertexBuffer : public CVertexBufferBase { 00038 public : 00039 // == Various constructors. 00040 LSE_CALLCTOR COpenGlVertexBuffer(); 00041 LSE_CALLCTOR ~COpenGlVertexBuffer(); 00042 00043 00044 // == Types. 00048 typedef LSUINT32 (LSE_CALL * PfElementConv)( LSUINT32 ); 00049 00050 00051 // == Functions. 00057 LSE_INLINE GLenum LSE_CALL GetOpenGlApiType() const; 00058 00064 LSE_INLINE PfElementConv LSE_CALL GetOpenGlElementConverter() const; 00065 00066 protected : 00067 // == Types. 00071 typedef struct LSG_OPENGL_PREFINED_VERT_ATT { 00075 LSUINT32 ui32Mask; 00076 00080 LSUINT32 ui32Size; 00081 00085 GLint iElements; 00086 00090 GLenum eType; 00091 00095 GLboolean bNormalized; 00096 } * LPLSG_OPENGL_PREFINED_VERT_ATT, * const LPCLSG_OPENGL_PREFINED_VERT_ATT; 00097 00101 typedef struct LSG_VERTEX_ATTRIB_POINTER { 00105 LSVOID * pvPointer; 00106 00110 LSUINT32 ui32Type; 00111 00115 LSUINT16 ui16LocClass; 00116 00120 LSUINT16 ui16LocUsage; 00121 00125 LSUINT16 ui16Stride; 00126 00130 LSUINT8 ui8Elements; 00131 00135 LSUINT8 ui8Normalized; 00136 } * LPLSG_VERTEX_ATTRIB_POINTER, * const LPCLSG_VERTEX_ATTRIB_POINTER; 00137 00138 00139 // == Members. 00143 CVectorPoD<LSG_VERTEX_ATTRIB_POINTER> m_vVertexAttribPointers; 00144 00148 PfElementConv m_pfElementFunc; 00149 00153 GLuint m_uiVboId; 00154 00158 GLsizei m_siStride; 00159 00163 GLsizei m_siElements; 00164 00168 LSUINT32 m_ui32OffsetApi; 00169 00173 GLenum m_ePrimitiveType; 00174 00179 static CCriticalSection m_csOglCrit; 00180 00184 static LSG_OPENGL_PREFINED_VERT_ATT m_opvaVertices[]; 00185 00186 00187 // == Functions. 00193 LSBOOL LSE_CALL CreateApiVertexBuffer(); 00194 00201 LSVOID LSE_CALL ResetApi( LSBOOL _bFull = true ); 00202 00206 LSVOID LSE_CALL UnLockApi(); 00207 00217 LSVOID LSE_CALL AdjustInputsToApi( LSG_VB_CONTENTS &_vcContents, LSUINT16 &_ui16UsageAndAccess ); 00218 00225 LSUINT32 LSE_CALL GetVertexAttributeSizeApi( const LSG_VB_CONTENTS &_vcContents ); 00226 00235 LSBOOL LSE_CALL SetStreamApi( LSUINT32 _ui32Stream, LSUINT32 _ui32Offset, LSUINT32 _ui32ElementsSize ); 00236 00245 LSBOOL LSE_CALL CanBufferBeDestroyedApi( LSUINT32 _ui32Elements, LSUINT32 _ui32ElementsSize, LSUINT32 _ui32UsageAndAccess ); 00246 00256 LSUINT32 LSE_CALL RawColorToApiColor( LSREAL _fR, LSREAL _fG, LSREAL _fB, LSVOID * _pvBuffer ); 00257 00268 LSUINT32 LSE_CALL RawColorToApiColor( LSREAL _fR, LSREAL _fG, LSREAL _fB, LSREAL _fA, LSVOID * _pvBuffer ); 00269 00278 LSVOID LSE_CALL SetColorApi( LSREAL _fR, LSREAL _fG, LSREAL _fB, LSVOID * _pvBuffer ); 00279 00286 LSVOID LSE_CALL SetAlphaApi( LSREAL _fA, LSVOID * _pvBuffer ); 00287 00291 LSVOID LSE_CALL PrepareToRenderApi(); 00292 00296 LSVOID LSE_CALL EndRenderApi(); 00297 00304 LSVOID LSE_CALL RenderApi( LSUINT32 _ui32TotalPrimitives ); 00305 00312 LSUINT32 LSE_CALL BestStrideApi( LSUINT32 _ui32Size ); 00313 00314 private : 00321 static LSUINT32 LSE_CALL GetTriangleListElements( LSUINT32 _ui32Primitives ); 00322 00329 static LSUINT32 LSE_CALL GetTriangleStripElements( LSUINT32 _ui32Primitives ); 00330 }; 00331 00332 00333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00334 // DEFINITIONS 00335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00336 // == Functions. 00342 LSE_INLINE GLenum LSE_CALL COpenGlVertexBuffer::GetOpenGlApiType() const { 00343 return m_ePrimitiveType; 00344 } 00345 00351 LSE_INLINE COpenGlVertexBuffer::PfElementConv LSE_CALL COpenGlVertexBuffer::GetOpenGlElementConverter() const { 00352 return m_pfElementFunc; 00353 } 00354 00364 LSE_INLINE LSUINT32 LSE_CALL COpenGlVertexBuffer::RawColorToApiColor( LSREAL _fR, LSREAL _fG, LSREAL _fB, LSVOID * _pvBuffer ) { 00365 LSREAL * pfDest = static_cast<LSREAL *>(_pvBuffer); 00366 (*pfDest++) = _fR; 00367 (*pfDest++) = _fG; 00368 (*pfDest) = _fB; 00369 return sizeof( LSREAL ) * 3UL; 00370 } 00371 00382 LSE_INLINE LSUINT32 LSE_CALL COpenGlVertexBuffer::RawColorToApiColor( LSREAL _fR, LSREAL _fG, LSREAL _fB, LSREAL _fA, LSVOID * _pvBuffer ) { 00383 LSREAL * pfDest = static_cast<LSREAL *>(_pvBuffer); 00384 (*pfDest++) = _fR; 00385 (*pfDest++) = _fG; 00386 (*pfDest++) = _fB; 00387 (*pfDest) = _fA; 00388 return sizeof( LSREAL ) * 4UL; 00389 } 00390 00399 LSE_INLINE LSVOID LSE_CALL COpenGlVertexBuffer::SetColorApi( LSREAL _fR, LSREAL _fG, LSREAL _fB, LSVOID * _pvBuffer ) { 00400 LSGREAL * pfDest = static_cast<LSGREAL *>(_pvBuffer); 00401 (*pfDest++) = static_cast<LSGREAL>(_fR); 00402 (*pfDest++) = static_cast<LSGREAL>(_fG); 00403 (*pfDest) = static_cast<LSGREAL>(_fB); 00404 } 00405 00412 LSE_INLINE LSVOID LSE_CALL COpenGlVertexBuffer::SetAlphaApi( LSREAL _fA, LSVOID * _pvBuffer ) { 00413 LSGREAL * pfDest = static_cast<LSGREAL *>(_pvBuffer); 00414 (*pfDest) = static_cast<LSGREAL>(_fA); 00415 } 00416 00417 } // namespace lsg 00418 00419 #endif // #ifdef LSG_OGL 00420 00421 #endif // __LSG_OPENGLVERTEXBUFFER_H__ 00422