EgtGraphics 2.5g1 :
- aggiunta gestione Stipple per GeoPoint3d, GeoVector3d e GeoCurve.
This commit is contained in:
+87
-47
@@ -1,7 +1,7 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2014-2014
|
||||
// EgalTech 2014-2023
|
||||
//----------------------------------------------------------------------------
|
||||
// File : ObjNewGraphics.cpp Data : 23.04.14 Versione : 1.5d5
|
||||
// File : ObjNewGraphics.cpp Data : 08.07.23 Versione : 2.5g1
|
||||
// Contenuto : Implementazione della classe grafica di un oggetto geometrico.
|
||||
//
|
||||
//
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "/EgtDev/Include/EGkPolyLine.h"
|
||||
#include "/EgtDev/Include/EGkGdbConst.h"
|
||||
#include "/EgtDev/Include/EGkTriangle3d.h"
|
||||
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
|
||||
//--------------------------- Macro e Costanti -------------------------------
|
||||
// Dimensioni flag per edge di triangoli
|
||||
@@ -27,6 +27,7 @@ const size_t SIZEFLAG = sizeof( unsigned char) ;
|
||||
// Dimensioni record del buffer ( vertice + normale + flag)
|
||||
const size_t SIZEVNF = ( 2 * SIZEV3F + SIZEFLAG) ;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ObjNewGraphics::~ObjNewGraphics( void)
|
||||
{
|
||||
@@ -55,7 +56,7 @@ ObjNewGraphics::Clear( void)
|
||||
bool
|
||||
ObjNewGraphics::AddColor( const Color& colC)
|
||||
{
|
||||
return AddColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ;
|
||||
return AddNgaColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -63,21 +64,28 @@ bool
|
||||
ObjNewGraphics::AddMaterial( const Color& colAmb, const Color& colDiff,
|
||||
const Color& colSpec, float fShin)
|
||||
{
|
||||
return AddMaterial( NgAtom::MAT_A, colAmb.GetRed(), colAmb.GetGreen(),
|
||||
colAmb.GetBlue(), colDiff.GetAlpha()) &&
|
||||
AddMaterial( NgAtom::MAT_D, colDiff.GetRed(), colDiff.GetGreen(),
|
||||
colDiff.GetBlue(), colDiff.GetAlpha()) &&
|
||||
AddMaterial( NgAtom::MAT_S, colSpec.GetRed(), colSpec.GetGreen(),
|
||||
colSpec.GetBlue(), colDiff.GetAlpha()) &&
|
||||
AddMaterial( NgAtom::MAT_SH, fShin, 0, 0, 0) ;
|
||||
return AddNgaMaterial( NgAtom::MAT_A, colAmb.GetRed(), colAmb.GetGreen(),
|
||||
colAmb.GetBlue(), colDiff.GetAlpha()) &&
|
||||
AddNgaMaterial( NgAtom::MAT_D, colDiff.GetRed(), colDiff.GetGreen(),
|
||||
colDiff.GetBlue(), colDiff.GetAlpha()) &&
|
||||
AddNgaMaterial( NgAtom::MAT_S, colSpec.GetRed(), colSpec.GetGreen(),
|
||||
colSpec.GetBlue(), colDiff.GetAlpha()) &&
|
||||
AddNgaMaterial( NgAtom::MAT_SH, fShin, 0, 0, 0) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddBackMaterial( const Color& colAmbDiff)
|
||||
{
|
||||
return AddMaterial( NgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(),
|
||||
colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ;
|
||||
return AddNgaMaterial( NgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(),
|
||||
colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddLineStipple( int nFactor, int nPattern)
|
||||
{
|
||||
return AddNgaLineStipple( nFactor, nPattern) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -109,7 +117,7 @@ ObjNewGraphics::AddPoint( const Point3d& ptP, bool bAux)
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_POINTS, nCount, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_POINTS, nCount, nVaoId, nVboId, bAux) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
@@ -148,7 +156,7 @@ ObjNewGraphics::AddPoints( const PNTVECTOR& vPnt, bool bAux)
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_POINTS, nCount, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_POINTS, nCount, nVaoId, nVboId, bAux) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
@@ -187,7 +195,7 @@ ObjNewGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_LINES, nCount, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_LINES, nCount, nVaoId, nVboId, bAux) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
@@ -228,7 +236,7 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_LINE_STRIP, nCount, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_LINE_STRIP, nCount, nVaoId, nVboId, bAux) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
@@ -261,7 +269,7 @@ ObjNewGraphics::StartTriangles( int nNum, bool bAux)
|
||||
// NumTria * 3 * dimensione( vertice+normale+flag)
|
||||
glBufferData( GL_ARRAY_BUFFER, nNum * 3 * SIZEVNF, NULL, GL_STATIC_DRAW) ;
|
||||
// aggiungo i dati in lista
|
||||
AddVerts( GL_TRIANGLES, 0, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_TRIANGLES, 0, nVaoId, nVboId, bAux) ;
|
||||
// dichiaro modo triangoli
|
||||
m_nCurrMode = GL_TRIANGLES ;
|
||||
return true ;
|
||||
@@ -329,8 +337,8 @@ ObjNewGraphics::EndTriangles( void)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static float*
|
||||
AdjustColor( float fCol[4], bool bDark)
|
||||
static const float*
|
||||
AdjustColor( const float fCol[4], bool bDark)
|
||||
{
|
||||
if ( ! bDark) {
|
||||
return fCol ;
|
||||
@@ -399,42 +407,58 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
|
||||
// ciclo di disegno
|
||||
for ( auto iIter = m_ngaVect.begin() ; iIter != m_ngaVect.end() ; ++ iIter) {
|
||||
switch ( iIter->m_nType) {
|
||||
bool bLineStipple = false ;
|
||||
for ( const auto& Nga : m_ngaVect) {
|
||||
switch ( Nga.m_nType) {
|
||||
case NgAtom::VERTS :
|
||||
if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
|
||||
glBindVertexArray( iIter->m_nVaoId) ;
|
||||
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
|
||||
if ( Nga.m_nCount > 0 && Nga.m_nVaoId != 0) {
|
||||
glBindVertexArray( Nga.m_nVaoId) ;
|
||||
glDrawArrays( Nga.m_nMode, 0, Nga.m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
case NgAtom::VERTS_A :
|
||||
if ( bShowAux && iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
|
||||
glBindVertexArray( iIter->m_nVaoId) ;
|
||||
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
|
||||
if ( bShowAux && Nga.m_nCount > 0 && Nga.m_nVaoId != 0) {
|
||||
glBindVertexArray( Nga.m_nVaoId) ;
|
||||
glDrawArrays( Nga.m_nMode, 0, Nga.m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
case NgAtom::COLOR :
|
||||
glColor4fv( ( bStdCol ? AdjustColor( iIter->m_fCol, bDark) : fSelMarkCol)) ;
|
||||
glColor4fv( ( bStdCol ? AdjustColor( Nga.m_fCol, bDark) : fSelMarkCol)) ;
|
||||
break ;
|
||||
case NgAtom::MAT_A :
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT, ( bStdCol ? iIter->m_fCol : fSelMarkCol)) ;
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT, ( bStdCol ? Nga.m_fCol : fSelMarkCol)) ;
|
||||
break ;
|
||||
case NgAtom::MAT_D :
|
||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, ( bStdCol ? iIter->m_fCol : fSelMarkCol)) ;
|
||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, ( bStdCol ? Nga.m_fCol : fSelMarkCol)) ;
|
||||
break ;
|
||||
case NgAtom::MAT_S :
|
||||
glMaterialfv( GL_FRONT, GL_SPECULAR, ( bStdCol ? iIter->m_fCol : fSelMarkCol)) ;
|
||||
glMaterialfv( GL_FRONT, GL_SPECULAR, ( bStdCol ? Nga.m_fCol : fSelMarkCol)) ;
|
||||
break ;
|
||||
case NgAtom::MAT_SH :
|
||||
glMaterialf( GL_FRONT, GL_SHININESS, iIter->m_fCol[0]) ;
|
||||
glMaterialf( GL_FRONT, GL_SHININESS, Nga.m_fCol[0]) ;
|
||||
break ;
|
||||
case NgAtom::MAT_B :
|
||||
glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, ( bStdCol ? iIter->m_fCol : fSelMarkBackCol)) ;
|
||||
glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, ( bStdCol ? Nga.m_fCol : fSelMarkBackCol)) ;
|
||||
break ;
|
||||
case NgAtom::LINE_STIPPLE :
|
||||
if ( Nga.m_nMode > 0) {
|
||||
bLineStipple = true ;
|
||||
glLineStipple( Clamp( Nga.m_nFactor, 1, 256), Clamp( Nga.m_nPattern, 0, 65535)) ;
|
||||
glEnable( GL_LINE_STIPPLE) ;
|
||||
}
|
||||
else {
|
||||
bLineStipple = false ;
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
}
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if ( bLineStipple) {
|
||||
bLineStipple = false ;
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
}
|
||||
|
||||
// se marcato e non superficie in shading, disegno halo
|
||||
if ( nMark == GDB_MK_ON && ! bSurfSha) {
|
||||
@@ -450,25 +474,41 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
glColor4f( colMark.GetRed(), colMark.GetGreen(), colMark.GetBlue(), colMark.GetAlpha()) ;
|
||||
|
||||
// ciclo di disegno
|
||||
for ( auto iIter = m_ngaVect.begin() ; iIter != m_ngaVect.end() ; ++ iIter) {
|
||||
switch ( iIter->m_nType) {
|
||||
bool bLineStipple = false ;
|
||||
for ( const auto& Nga : m_ngaVect) {
|
||||
switch ( Nga.m_nType) {
|
||||
case NgAtom::VERTS :
|
||||
if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
|
||||
glBindVertexArray( iIter->m_nVaoId) ;
|
||||
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
|
||||
if ( Nga.m_nCount > 0 && Nga.m_nVaoId != 0) {
|
||||
glBindVertexArray( Nga.m_nVaoId) ;
|
||||
glDrawArrays( Nga.m_nMode, 0, Nga.m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
case NgAtom::VERTS_A :
|
||||
if ( bShowAux && iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
|
||||
glBindVertexArray( iIter->m_nVaoId) ;
|
||||
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
|
||||
if ( bShowAux && Nga.m_nCount > 0 && Nga.m_nVaoId != 0) {
|
||||
glBindVertexArray( Nga.m_nVaoId) ;
|
||||
glDrawArrays( Nga.m_nMode, 0, Nga.m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
// non si impostano i colori, si usa quello di marcatura
|
||||
case NgAtom::LINE_STIPPLE :
|
||||
if ( Nga.m_nMode > 0) {
|
||||
bLineStipple = true ;
|
||||
glLineStipple( Clamp( Nga.m_nFactor, 1, 256), Clamp( Nga.m_nPattern, 0, 65535)) ;
|
||||
glEnable( GL_LINE_STIPPLE) ;
|
||||
}
|
||||
else {
|
||||
bLineStipple = false ;
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
}
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if ( bLineStipple) {
|
||||
bLineStipple = false ;
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
}
|
||||
// ripristino test di depth
|
||||
glDepthFunc( GL_LEQUAL) ;
|
||||
}
|
||||
@@ -490,13 +530,13 @@ ObjNewGraphics::DeleteVaoVbo( void)
|
||||
return false ;
|
||||
|
||||
// ciclo di cancellazione VAO/VBO
|
||||
for ( auto iIter = m_ngaVect.begin() ; iIter != m_ngaVect.end() ; ++ iIter) {
|
||||
if ( iIter->m_nType == NgAtom::VERTS && iIter->m_nCount > 0) {
|
||||
for ( auto& Nga : m_ngaVect) {
|
||||
if ( Nga.m_nType == NgAtom::VERTS && Nga.m_nCount > 0) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
|
||||
glDeleteBuffers( 1, &iIter->m_nVboId) ;
|
||||
glDeleteBuffers( 1, &Nga.m_nVboId) ;
|
||||
glBindVertexArray( 0) ;
|
||||
glDeleteVertexArrays( 1, &iIter->m_nVaoId) ;
|
||||
iIter->m_nCount = 0 ;
|
||||
glDeleteVertexArrays( 1, &Nga.m_nVaoId) ;
|
||||
Nga.m_nCount = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user