EgtGraphics 1.5c3 :
- aggiunta visualizzaziono di punti, vettori e frame - aggiunti NewGrAtom per gestione potenziata e con colori di VAO/VBO - aggiunti OldGrAtom per displaylist proprietarie in modo OpenGL immediato.
This commit is contained in:
+100
-31
@@ -15,6 +15,8 @@
|
||||
#include "stdafx.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "Scene.h"
|
||||
#include "GraphObjs.h"
|
||||
#include "/EgtDev/Include/EGkPolyLine.h"
|
||||
|
||||
#define glewGetContext() (( m_pScene != nullptr) ? m_pScene->glewGetContext() : nullptr)
|
||||
|
||||
@@ -22,8 +24,7 @@
|
||||
//----------------------------------------------------------------------------
|
||||
ObjNewGraphics::~ObjNewGraphics( void)
|
||||
{
|
||||
// cancello eventuali vecchi vertici
|
||||
DeleteVaoVbo() ;
|
||||
Clear() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -33,6 +34,58 @@ ObjNewGraphics::Reset( void)
|
||||
m_bValid = false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
ObjNewGraphics::Clear( void)
|
||||
{
|
||||
DeleteVaoVbo() ;
|
||||
m_ngaList.clear() ;
|
||||
m_bValid = false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddColor( const Color& colC)
|
||||
{
|
||||
return AddColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddPoint( const Point3d& ptP)
|
||||
{
|
||||
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
|
||||
// definisco i buffer per la scheda grafica e vi inserisco i nuovi vertici
|
||||
unsigned int nVaoId ;
|
||||
glGenVertexArrays( 1, &nVaoId) ;
|
||||
if ( nVaoId == 0)
|
||||
return false ;
|
||||
glBindVertexArray( nVaoId) ;
|
||||
unsigned int nVboId ;
|
||||
glGenBuffers( 1, &nVboId) ;
|
||||
if ( nVboId == 0) {
|
||||
glBindVertexArray( 0) ;
|
||||
glDeleteVertexArrays( 1, &nVaoId) ;
|
||||
return false ;
|
||||
}
|
||||
glBindBuffer( GL_ARRAY_BUFFER, nVboId) ;
|
||||
glBufferData( GL_ARRAY_BUFFER, 1 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
|
||||
Vert3f v3V( ptP.x, ptP.y, ptP.z) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 0, SIZEV3F, &v3V) ;
|
||||
int nCount = 1 ;
|
||||
glVertexPointer( 3, GL_FLOAT, 0, ((void*)(0))) ;
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_POINTS, nCount, nVaoId, nVboId) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddPolyLine( const PolyLine& PL)
|
||||
@@ -40,30 +93,36 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL)
|
||||
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
|
||||
// cancello eventuali vecchi vertici
|
||||
DeleteVaoVbo() ;
|
||||
// imposto il nuovo stato
|
||||
m_bValid = true ;
|
||||
m_nMode = GL_LINE_STRIP ;
|
||||
// inserisco i nuovi vertici
|
||||
glGenVertexArrays( 1, &m_nVaoId) ;
|
||||
if ( m_nVaoId == 0)
|
||||
// definisco i buffer per la scheda grafica e vi inserisco i nuovi vertici
|
||||
unsigned int nVaoId ;
|
||||
glGenVertexArrays( 1, &nVaoId) ;
|
||||
if ( nVaoId == 0)
|
||||
return false ;
|
||||
glBindVertexArray( m_nVaoId) ;
|
||||
glGenBuffers( 1, &m_nVboId) ;
|
||||
glBindBuffer( GL_ARRAY_BUFFER, m_nVboId) ;
|
||||
glBindVertexArray( nVaoId) ;
|
||||
unsigned int nVboId ;
|
||||
glGenBuffers( 1, &nVboId) ;
|
||||
if ( nVboId == 0) {
|
||||
glBindVertexArray( 0) ;
|
||||
glDeleteVertexArrays( 1, &nVaoId) ;
|
||||
return false ;
|
||||
}
|
||||
glBindBuffer( GL_ARRAY_BUFFER, nVboId) ;
|
||||
glBufferData( GL_ARRAY_BUFFER, PL.GetPointNbr() * SIZEV3F, NULL, GL_STATIC_DRAW) ;
|
||||
Point3d ptP ;
|
||||
Vert3f v3V ;
|
||||
m_nCount = 0 ;
|
||||
int nCount = 0 ;
|
||||
for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) {
|
||||
v3V.Set( ptP.x, ptP.y, ptP.z) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, m_nCount * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
++ m_nCount ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, nCount * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
++ nCount ;
|
||||
}
|
||||
glVertexPointer( 3, GL_FLOAT, 0, ((void*)(0))) ;
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_LINE_STRIP, nCount, nVaoId, nVboId) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -75,14 +134,21 @@ ObjNewGraphics::Draw( void)
|
||||
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
|
||||
// se vuoto non faccio alcunché
|
||||
if ( m_nCount == 0)
|
||||
return true ;
|
||||
|
||||
if ( m_nVaoId != 0) {
|
||||
glBindVertexArray( m_nVaoId) ;
|
||||
glDrawArrays( m_nMode, 0, m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// ciclo di disegno
|
||||
NGALIST::iterator iIter ;
|
||||
for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) {
|
||||
switch ( iIter->m_nType) {
|
||||
case NewGrAtom::VERTS :
|
||||
if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
|
||||
glBindVertexArray( iIter->m_nVaoId) ;
|
||||
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
case NewGrAtom::COLOR :
|
||||
glColor4f( iIter->m_fRed, iIter->m_fGreen, iIter->m_fBlue, iIter->m_fAlpha) ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
@@ -95,13 +161,16 @@ ObjNewGraphics::DeleteVaoVbo( void)
|
||||
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
|
||||
// cancellazione VAO/VBO
|
||||
if ( m_nCount > 0) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
|
||||
glDeleteBuffers( 1, &m_nVboId) ;
|
||||
glBindVertexArray( 0) ;
|
||||
glDeleteVertexArrays( 1, &m_nVaoId) ;
|
||||
m_nCount = 0 ;
|
||||
// ciclo di cancellazione VAO/VBO
|
||||
NGALIST::iterator iIter ;
|
||||
for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) {
|
||||
if ( iIter->m_nType == NewGrAtom::VERTS && iIter->m_nCount > 0) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
|
||||
glDeleteBuffers( 1, &iIter->m_nVboId) ;
|
||||
glBindVertexArray( 0) ;
|
||||
glDeleteVertexArrays( 1, &iIter->m_nVaoId) ;
|
||||
iIter->m_nCount = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
|
||||
Reference in New Issue
Block a user