Files
EgtGraphics/ObjNewGraphics.cpp
T
Dario Sassi 8560bc5cae EgtGraphics :
- cambiato nome da Invalidate a Reset a metodo di Obj*Graphics.
2014-02-17 09:41:18 +00:00

108 lines
3.0 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : ObjNewGraphics.cpp Data : 10.02.14 Versione : 1.5b1
// Contenuto : Implementazione della classe grafica di un oggetto geometrico.
//
//
//
// Modifiche : 10.02.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "ObjNewGraphics.h"
#include "Scene.h"
#define glewGetContext() (( m_pScene != nullptr) ? m_pScene->glewGetContext() : nullptr)
//----------------------------------------------------------------------------
ObjNewGraphics::~ObjNewGraphics( void)
{
// cancello eventuali vecchi vertici
DeleteVaoVbo() ;
}
//----------------------------------------------------------------------------
void
ObjNewGraphics::Reset( void)
{
m_bValid = false ;
}
//----------------------------------------------------------------------------
bool
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)
return false ;
glBindVertexArray( m_nVaoId) ;
glGenBuffers( 1, &m_nVboId) ;
glBindBuffer( GL_ARRAY_BUFFER, m_nVboId) ;
glBufferData( GL_ARRAY_BUFFER, PL.GetPointNbr() * SIZEV3F, NULL, GL_STATIC_DRAW) ;
Point3d ptP ;
Vert3f v3V ;
m_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 ;
}
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
return true ;
}
//----------------------------------------------------------------------------
bool
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) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
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 ;
}
return true ;
}