TestEgr 1.5b4 : aggiunta gestione immediate mode per OpenGL vecchio stile.

This commit is contained in:
Dario Sassi
2014-02-07 08:13:24 +00:00
parent 069487c790
commit fcd21f0318
7 changed files with 273 additions and 123 deletions
+42
View File
@@ -0,0 +1,42 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : EGrGraphObjs.h Data : 06.02.14 Versione : 1.5b4
// Contenuto : Oggetti grafici e loro raccolte.
//
//
//
// Modifiche : 06.02.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include <vector>
#include <list>
//----------------------------------------------------------------------------
// Definizione di Vert3f
class Vert3f {
public :
Vert3f( double dX, double dY, double dZ) : x( (float)dX), y( (float)dY), z( (float)dZ) {}
Vert3f( void) : x( 0), y( 0), z( 0) {}
void Set( double dX, double dY, double dZ) { x = (float)dX ; y = (float)dY ; z = (float)dZ ;}
const Vert3f& operator =( const Vert3f& ptSrc)
{ if ( &ptSrc != this) {
x = ptSrc.x , y = ptSrc.y , z = ptSrc.z ; }
return *this ; }
public :
float x ;
float y ;
float z ;
} ;
const size_t SIZEV3F = sizeof( Vert3f) ;
//----------------------------------------------------------------------------
// Raccolte di Vert3f
typedef std::vector<Vert3f> V3FVECTOR ; // vettore di vertici
typedef std::list<Vert3f> V3FLIST ; // lista di vertici
+208 -112
View File
@@ -14,6 +14,7 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "EGrScene.h"
#include "/EgtDev/Include/EgtILogger.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGkFrame3d.h"
@@ -24,18 +25,11 @@ static const double MIN_DIST_CAMERA = 10 ;
static const double STD_DIST_CAMERA = 1000 ;
static const double MIN_EXTENSION = 50 ;
//--------------------------- Structs ----------------------------------------
struct Vert3f {
GLfloat x ;
GLfloat y ;
GLfloat z ;
} ;
#define SET_VERT3F( P, X, Y, Z) {P.x=X;P.y=Y;P.z=Z;}
//----------------------------------------------------------------------------
EGrScene::EGrScene( void)
{
m_pLogger = nullptr ;
// Context data
m_hDC = nullptr ;
m_hRC = nullptr ;
@@ -60,19 +54,33 @@ EGrScene::~EGrScene( void)
//----------------------------------------------------------------------------
bool
EGrScene::CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, int nDepthBits)
EGrScene::Init( ILogger* pLogger)
{
m_pLogger = pLogger ;
return true ;
}
//----------------------------------------------------------------------------
bool
EGrScene::CreateContext( HDC hDC, int nDriver, bool b2Buff, int nColorBits, int nDepthBits)
{
// verifico validità Device Context
if ( hDC == nullptr)
return false ;
m_hDC = hDC ;
// riporto nei limiti il tipo di driver
if ( nDriver < OD_SOFT)
nDriver = OD_SOFT ;
else if ( nDriver > OD_NEW)
nDriver = OD_NEW ;
// assegno formato pixel
PIXELFORMATDESCRIPTOR pfd ;
memset( &pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)) ;
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR) ;
pfd.nVersion = 1 ;
pfd.dwFlags = ( bDouBuff ? PFD_DOUBLEBUFFER : 0) | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW ;
pfd.dwFlags = ( b2Buff ? PFD_DOUBLEBUFFER : 0) | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW ;
pfd.iPixelType = PFD_TYPE_RGBA ;
pfd.cColorBits = nColorBits ;
pfd.cDepthBits = nDepthBits ;
@@ -82,7 +90,7 @@ EGrScene::CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, in
if ( nPixelFormat == 0)
return false ;
if ( nDriver == OD_SOFT) {
int nPixFormGen = ChooseGenPixelFormat( nPixelFormat, bDouBuff, nColorBits, nDepthBits) ;
int nPixFormGen = ChooseGenPixelFormat( nPixelFormat, b2Buff, nColorBits, nDepthBits) ;
if ( nPixFormGen != 0)
nPixelFormat = nPixFormGen ;
}
@@ -95,16 +103,33 @@ EGrScene::CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, in
GLenum WglewInitResult ;
WglewInitResult = wglewInit() ;
if ( WglewInitResult != GLEW_OK) {
AfxMessageBox( _T("WGLEW is not initialized!")) ;
}
if ( WglewInitResult != GLEW_OK)
LOG_INFO( m_pLogger, "WGLEW is not initialized !")
int attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
} ;
int attribs[10] ;
if ( nDriver == OD_SOFT) {
attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB ;
attribs[1] = 1 ;
attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB ;
attribs[3] = 1 ;
attribs[4] = 0 ;
}
else if ( nDriver == OD_OLD) {
attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB ;
attribs[1] = 2 ;
attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB ;
attribs[3] = 0 ;
attribs[4] = 0 ;
}
else {
attribs[0] = WGL_CONTEXT_MAJOR_VERSION_ARB ;
attribs[1] = 3 ;
attribs[2] = WGL_CONTEXT_MINOR_VERSION_ARB ;
attribs[3] = 0 ;
attribs[4] = WGL_CONTEXT_PROFILE_MASK_ARB ;
attribs[5] = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB ;
attribs[6] = 0 ;
}
if ( wglewIsSupported( "WGL_ARB_create_context") == 1) {
m_hRC = wglCreateContextAttribsARB( m_hDC, 0, attribs) ;
@@ -114,7 +139,8 @@ EGrScene::CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, in
}
else {
//It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before)
m_hRC = tempContext;
m_hRC = tempContext ;
LOG_INFO( m_pLogger, "WGL_ARB_create_context missing !")
}
// verifico validità Rendering Context
@@ -125,19 +151,23 @@ EGrScene::CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, in
glewExperimental = GL_TRUE ;
GlewInitResult = glewInit() ;
if ( GlewInitResult != GLEW_OK) {
AfxMessageBox( _T("GLEW is not initialized!")) ;
}
if ( GlewInitResult != GLEW_OK)
LOG_INFO( m_pLogger, "GLEW is not initialized !")
// verifico se posso lavorare in modalità nuova
m_bNewWay = ( glewIsSupported( "GL_VERSION_3_0") == 1) ;
m_bNewWay = ( nDriver == OD_NEW && glewIsSupported( "GL_VERSION_3_0") == 1) ;
if ( ! m_bNewWay)
LOG_INFO( m_pLogger, "OpenGL old way rendering !")
// reset stato di errore di OpenGL
glGetError() ;
return true ;
}
//----------------------------------------------------------------------------
int
EGrScene::ChooseGenPixelFormat( int nPfd, bool bDouBuff, int nColorBits, int nDepthBits)
EGrScene::ChooseGenPixelFormat( int nPfd, bool b2Buff, int nColorBits, int nDepthBits)
{
PIXELFORMATDESCRIPTOR pfdR ;
@@ -155,7 +185,7 @@ EGrScene::ChooseGenPixelFormat( int nPfd, bool bDouBuff, int nColorBits, int nDe
DescribePixelFormat( m_hDC, nI, sizeof(PIXELFORMATDESCRIPTOR), &pfdR) ;
if ( pfdR.dwFlags & PFD_GENERIC_FORMAT &&
! (pfdR.dwFlags & PFD_GENERIC_ACCELERATED) &&
( ! bDouBuff || pfdR.dwFlags & PFD_DOUBLEBUFFER)) {
( ! b2Buff || pfdR.dwFlags & PFD_DOUBLEBUFFER)) {
int nErr = abs( nColorBits - pfdR.cColorBits) +
abs( nDepthBits - pfdR.cDepthBits) ;
if ( nErr < nErrOpt) {
@@ -204,6 +234,9 @@ EGrScene::GetOpenGLInfo( void)
else
sInfo += "ERROR" ;
// reset stato di errore di OpenGL
glGetError() ;
return sInfo ;
}
@@ -223,6 +256,9 @@ EGrScene::GetGLSLInfo( void)
else
sInfo += "ERROR" ;
// reset stato di errore di OpenGL
glGetError() ;
return sInfo ;
}
@@ -261,6 +297,9 @@ EGrScene::GetPixelFormatInfo( void)
else
sInfo += "ERROR" ;
// reset stato di errore di OpenGL
glGetError() ;
return sInfo ;
}
@@ -522,6 +561,14 @@ EGrScene::AdjustDimView( double dHalfWidth, double dHalfHeight)
return false ;
m_nViewportW = rect.right ;
m_nViewportH = rect.bottom ;
// aggiorno la vista
glViewport( 0, 0, m_nViewportW, m_nViewportH) ;
// verifico presenza errori
GLenum nErr = glGetError() ;
if ( nErr != GL_NO_ERROR) {
string sOut = "First glViewport OpenGL error " + ToString( (int)nErr) ;
LOG_INFO( m_pLogger, sOut.c_str())
}
}
// adatto il rapporto tra le dimensioni calcolate a quello delle dimensioni della vista
@@ -573,6 +620,13 @@ EGrScene::Reshape( int nW, int nH)
// aggiorno la vista
glViewport( 0, 0, m_nViewportW, m_nViewportH) ;
// verifico presenza errori
GLenum nErr = glGetError() ;
if ( nErr != GL_NO_ERROR) {
string sOut = "Reshape OpenGL error " + ToString( (int)nErr) ;
LOG_INFO( m_pLogger, sOut.c_str())
}
// aggiorno
AdjustDimView( m_dHalfWidth, m_dHalfHeight) ;
@@ -599,8 +653,6 @@ EGrScene::Prepare( void)
glLoadIdentity() ;
glOrtho( - m_dHalfWidth, m_dHalfWidth, - m_dHalfHeight, m_dHalfHeight, m_dZNear, m_dZFar) ;
GLenum nErr = glGetError() ;
// imposto matrice modello/vista
glMatrixMode( GL_MODELVIEW) ;
glLoadIdentity() ;
@@ -609,7 +661,12 @@ EGrScene::Prepare( void)
m_ptCenter.x, m_ptCenter.y, m_ptCenter.z,
m_vtUp.x, m_vtUp.y, m_vtUp.z) ;
nErr = glGetError() ;
// verifico presenza errori
GLenum nErr = glGetError() ;
if ( nErr != GL_NO_ERROR) {
string sOut = "Prepare OpenGL error " + ToString( (int)nErr) ;
LOG_INFO( m_pLogger, sOut.c_str())
}
return true ;
}
@@ -626,18 +683,38 @@ EGrScene::Draw( void)
glClear( GL_COLOR_BUFFER_BIT) ;
// disegno
for ( int i = 0 ; i < NUM_VAO ; ++ i) {
if ( m_vaoID[i] != 0) {
glBindVertexArray( m_vaoID[i]) ;
glDrawArrays( m_nMode[i], 0, m_nCount[i]) ;
if ( m_bNewWay) {
for ( int i = 0 ; i < NUM_VAO ; ++ i) {
if ( m_vaoID[i] != 0) {
glBindVertexArray( m_vaoID[i]) ;
glDrawArrays( m_nMode[i], 0, m_nCount[i]) ;
}
}
}
else {
for ( int i = 0 ; i < NUM_VAO ; ++ i) {
if ( m_nCount[i] != 0) {
glBegin( m_nMode[i]) ;
for ( int j = 0 ; j < m_nCount[i] ; ++ j)
glVertex3f( m_v3fVect[i][j].x, m_v3fVect[i][j].y, m_v3fVect[i][j].z) ;
glEnd() ;
}
}
}
// aggiorno
glFlush() ;
// scambio i buffer back e front (se previsti)
SwapBuffers( m_hDC) ;
// verifico presenza errori
GLenum nErr = glGetError() ;
if ( nErr != GL_NO_ERROR) {
string sOut = "Draw OpenGL error " + ToString( (int)nErr) ;
LOG_INFO( m_pLogger, sOut.c_str())
}
// scambio i buffer back e front ( eseguita solo se previsti)
if ( ! SwapBuffers( m_hDC))
LOG_INFO( m_pLogger, "Draw SwapBuffers error")
return true ;
}
@@ -683,12 +760,11 @@ EGrScene::SetSquare( void)
return ;
// vertici
size_t nSizeV3f = sizeof( Vert3f) ;
Vert3f Point[4] ;
SET_VERT3F( Point[0], -0.5f, -0.5f, 0.0f)
SET_VERT3F( Point[1], -0.5f, 0.5f, 0.0f)
SET_VERT3F( Point[2], 0.5f, 0.5f, 0.0f)
SET_VERT3F( Point[3], 0.5f, -0.5f, 0.0f)
Point[0].Set( -0.5, -0.5, 0.0) ;
Point[1].Set( -0.5, 0.5, 0.0) ;
Point[2].Set( 0.5, 0.5, 0.0) ;
Point[3].Set( 0.5, -0.5, 0.0) ;
// dimensioni di ingombro
BBox3d b3Ext ;
@@ -696,11 +772,10 @@ EGrScene::SetSquare( void)
b3Ext.Add( Point[i].x, Point[i].y, Point[i].z) ;
SetExtension( b3Ext) ;
// inizializzo VAOs a non allocati
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_vaoID[i] = 0 ;
if ( m_bNewWay) {
// inizializzo VAOs a non allocati
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_vaoID[i] = 0 ;
// VAO allocation
glGenVertexArrays( 1, &m_vaoID[0]) ;
if ( m_vaoID[0] == 0)
@@ -711,12 +786,12 @@ EGrScene::SetSquare( void)
glBindBuffer( GL_ARRAY_BUFFER, m_vboID[0]) ;
m_nMode[0] = GL_LINE_STRIP ;
m_nCount[0] = 5 ;
glBufferData( GL_ARRAY_BUFFER, 5 * nSizeV3f, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferData( GL_ARRAY_BUFFER, 5 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * SIZEV3F, SIZEV3F, &Point[0]) ;
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
@@ -734,16 +809,15 @@ EGrScene::SetCube( void)
return ;
// vertici
size_t nSizeV3f = sizeof( Vert3f) ;
Vert3f Point[8] ;
SET_VERT3F( Point[0], -0.5f, -0.5f, 0.0f)
SET_VERT3F( Point[1], -0.5f, 0.5f, 0.0f)
SET_VERT3F( Point[2], 0.5f, 0.5f, 0.0f)
SET_VERT3F( Point[3], 0.5f, -0.5f, 0.0f)
SET_VERT3F( Point[4], -0.5f, -0.5f, 1.0f)
SET_VERT3F( Point[5], -0.5f, 0.5f, 1.0f)
SET_VERT3F( Point[6], 0.5f, 0.5f, 1.0f)
SET_VERT3F( Point[7], 0.5f, -0.5f, 1.0f)
Point[0].Set( -0.5, -0.5, 0.0) ;
Point[1].Set( -0.5, 0.5, 0.0) ;
Point[2].Set( 0.5, 0.5, 0.0) ;
Point[3].Set( 0.5, -0.5, 0.0) ;
Point[4].Set( -0.5, -0.5, 1.0) ;
Point[5].Set( -0.5, 0.5, 1.0) ;
Point[6].Set( 0.5, 0.5, 1.0) ;
Point[7].Set( 0.5, -0.5, 1.0) ;
// dimensioni di ingombro
BBox3d b3Ext ;
@@ -751,11 +825,10 @@ EGrScene::SetCube( void)
b3Ext.Add( Point[i].x, Point[i].y, Point[i].z) ;
SetExtension( b3Ext) ;
// inizializzo VAOs a non allocati
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_vaoID[i] = 0 ;
if ( m_bNewWay) {
// inizializzo VAOs a non allocati
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_vaoID[i] = 0 ;
// VAO allocation
glGenVertexArrays( 3, &m_vaoID[0]) ;
if ( m_vaoID[0] == 0)
@@ -766,12 +839,12 @@ EGrScene::SetCube( void)
glBindBuffer( GL_ARRAY_BUFFER, m_vboID[0]) ;
m_nMode[0] = GL_LINE_STRIP ;
m_nCount[0] = 5 ;
glBufferData( GL_ARRAY_BUFFER, 5 * nSizeV3f, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferData( GL_ARRAY_BUFFER, 5 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * SIZEV3F, SIZEV3F, &Point[0]) ;
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
@@ -781,12 +854,12 @@ EGrScene::SetCube( void)
glBindBuffer( GL_ARRAY_BUFFER, m_vboID[1]) ;
m_nMode[1] = GL_LINE_STRIP ;
m_nCount[1] = 5 ;
glBufferData( GL_ARRAY_BUFFER, 5 * nSizeV3f, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[4]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[5]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[6]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[7]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * nSizeV3f, nSizeV3f, &Point[4]) ;
glBufferData( GL_ARRAY_BUFFER, 5 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &Point[4]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &Point[5]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &Point[6]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &Point[7]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * SIZEV3F, SIZEV3F, &Point[4]) ;
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
@@ -796,15 +869,15 @@ EGrScene::SetCube( void)
glBindBuffer( GL_ARRAY_BUFFER, m_vboID[2]) ;
m_nMode[2] = GL_LINES ;
m_nCount[2] = 8 ;
glBufferData( GL_ARRAY_BUFFER, 8 * nSizeV3f, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[4]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[5]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * nSizeV3f, nSizeV3f, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 5 * nSizeV3f, nSizeV3f, &Point[6]) ;
glBufferSubData( GL_ARRAY_BUFFER, 6 * nSizeV3f, nSizeV3f, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 7 * nSizeV3f, nSizeV3f, &Point[7]) ;
glBufferData( GL_ARRAY_BUFFER, 8 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &Point[4]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &Point[5]) ;
glBufferSubData( GL_ARRAY_BUFFER, 4 * SIZEV3F, SIZEV3F, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 5 * SIZEV3F, SIZEV3F, &Point[6]) ;
glBufferSubData( GL_ARRAY_BUFFER, 6 * SIZEV3F, SIZEV3F, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 7 * SIZEV3F, SIZEV3F, &Point[7]) ;
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
@@ -819,14 +892,13 @@ EGrScene::SetTriangle( void)
return ;
// vertici
size_t nSizeV3f = sizeof( Vert3f) ;
Vert3f Point[6] ;
SET_VERT3F( Point[0], -0.3f, 0.5f, -1.0f)
SET_VERT3F( Point[1], -0.8f, -0.5f, -1.0f)
SET_VERT3F( Point[2], 0.2f, -0.5f, -1.0f)
SET_VERT3F( Point[3], -0.2f, 0.5f, -1.0f)
SET_VERT3F( Point[4], 0.3f, -0.5f, -1.0f)
SET_VERT3F( Point[5], 0.8f, 0.5f, -1.0f)
Point[0].Set( -0.3, 0.5, -1.0) ;
Point[1].Set( -0.8, -0.5, -1.0) ;
Point[2].Set( 0.2, -0.5, -1.0) ;
Point[3].Set( -0.2, 0.5, -1.0) ;
Point[4].Set( 0.3, -0.5, -1.0) ;
Point[5].Set( 0.8, 0.5, -1.0) ;
// dimensioni di ingombro
BBox3d b3Ext ;
@@ -834,25 +906,23 @@ EGrScene::SetTriangle( void)
b3Ext.Add( Point[i].x, Point[i].y, Point[i].z) ;
SetExtension( b3Ext) ;
// inizializzo VAOs a non allocati
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_vaoID[i] = 0 ;
if ( m_bNewWay) {
// inizializzo VAOs a non allocati
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_vaoID[i] = 0 ;
// VAOs allocation
glGenVertexArrays( 2, &m_vaoID[0]) ;
// First VAO setup
glBindVertexArray( m_vaoID[0]) ;
glGenBuffers( 1, &m_vboID[0]) ; //VBO allocation
glBindBuffer( GL_ARRAY_BUFFER, m_vboID[0]) ;
m_nMode[0] = GL_LINE_STRIP ;
m_nCount[0] = 4 ;
glBufferData( GL_ARRAY_BUFFER, 4 * nSizeV3f, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[0]) ;
glBufferData( GL_ARRAY_BUFFER, 4 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &Point[0]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &Point[1]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &Point[2]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &Point[0]) ;
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
@@ -862,25 +932,51 @@ EGrScene::SetTriangle( void)
glBindBuffer( GL_ARRAY_BUFFER, m_vboID[1]) ;
m_nMode[1] = GL_LINE_STRIP ;
m_nCount[1] = 4 ;
glBufferData( GL_ARRAY_BUFFER, 4 * nSizeV3f, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[4]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[5]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[3]) ;
glBufferData( GL_ARRAY_BUFFER, 4 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &Point[3]) ;
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &Point[4]) ;
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &Point[5]) ;
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &Point[3]) ;
glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ;
glEnableVertexAttribArray( 0) ;
glBindVertexArray( 0) ;
}
else {
// First VAO setup
m_nMode[0] = GL_LINE_STRIP ;
m_nCount[0] = 4 ;
m_v3fVect[0].reserve( 4) ;
m_v3fVect[0].push_back( Point[0]) ;
m_v3fVect[0].push_back( Point[1]) ;
m_v3fVect[0].push_back( Point[2]) ;
m_v3fVect[0].push_back( Point[0]) ;
// Second VAO setup
m_nMode[1] = GL_LINE_STRIP ;
m_nCount[1] = 4 ;
m_v3fVect[1].reserve( 4) ;
m_v3fVect[1].push_back( Point[3]) ;
m_v3fVect[1].push_back( Point[4]) ;
m_v3fVect[1].push_back( Point[5]) ;
m_v3fVect[1].push_back( Point[3]) ;
// Third VAO null
m_nCount[2] = 0 ;
}
}
//----------------------------------------------------------------------------
void
EGrScene::ResetData( void)
{
if ( m_bNewWay && MakeCurrent()) {
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
glDeleteBuffers( NUM_VAO, m_vboID) ;
glBindVertexArray( 0) ;
glDeleteVertexArrays( NUM_VAO, m_vaoID) ;
if ( m_bNewWay) {
if ( MakeCurrent()) {
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
glDeleteBuffers( NUM_VAO, m_vboID) ;
glBindVertexArray( 0) ;
glDeleteVertexArrays( NUM_VAO, m_vaoID) ;
}
}
else {
for ( int i = 0 ; i < NUM_VAO ; ++ i)
m_v3fVect[i].clear() ;
}
}
+11 -5
View File
@@ -16,11 +16,13 @@
//----------------------------------------------------------------------------
#include "/EgtDev/Include/EGkPoint3d.h"
#include "/EgtDev/Include/EGkBBox3d.h"
#include "EGrGraphObjs.h"
#define GLEW_MX
#include "/EgtDev/Extern/GLEW/Include/glew.h"
#include "/EgtDev/Extern/GLEW/Include/wglew.h"
#include <string>
class ILogger ;
//----------------------------------------------------------------------------
class EGrScene
@@ -32,13 +34,13 @@ class EGrScene
public:
EGrScene( void);
virtual ~EGrScene( void);
bool CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, int nDepthBits) ;
bool Init( ILogger* pLogger) ;
bool CreateContext( HDC hDC, int nDriver, bool b2Buff, int nColorBits, int nDepthBits) ;
bool IsValid( void)
{ return ( m_hDC != nullptr && m_hRC != nullptr) ; }
std::string GetOpenGLInfo( void) ;
std::string GetGLSLInfo( void) ;
std::string GetPixelFormatInfo( void) ;
bool Prepare( void) ;
bool Reshape( int nW, int nH) ;
bool Draw( void) ;
void Destroy( void) ;
@@ -59,7 +61,7 @@ class EGrScene
void ResetData( void) ;
private :
int ChooseGenPixelFormat( int nPfd, bool bDouBuff, int nColorBits, int nDepthBits) ;
int ChooseGenPixelFormat( int nPfd, bool b2Buff, int nColorBits, int nDepthBits) ;
bool MakeCurrent( void) ;
GLEWContext* glewGetContext( void)
{ return &m_glewc ; }
@@ -71,12 +73,15 @@ class EGrScene
bool CalcDimViewFromExtView( void) ;
bool AdjustDimView( double dHalfWidth, double dHalfHeight) ;
bool CalcClippingPlanesFromExtView( void) ;
bool Prepare( void) ;
void SetTriangle( void) ;
void SetSquare( void) ;
void SetCube( void) ;
private :
ILogger* m_pLogger ;
HDC m_hDC ; // Device Context
HGLRC m_hRC ; // OpenGL Rendering Context
WGLEWContext m_wglewc ; // WGLEW Context
@@ -100,8 +105,9 @@ class EGrScene
double m_dZFar ;
static const int NUM_VAO = 3 ;
GLuint m_vaoID[NUM_VAO] ; // VAOs
GLuint m_vboID[NUM_VAO] ; // VBOs
int m_nMode[NUM_VAO] ; // modo di utilizzo dei vertici
int m_nCount[NUM_VAO] ; // contatore di vertici
GLuint m_vaoID[NUM_VAO] ; // VAOs
GLuint m_vboID[NUM_VAO] ; // VBOs
V3FVECTOR m_v3fVect[NUM_VAO] ; // array di vertici equivalenti per vecchio modo
} ;
BIN
View File
Binary file not shown.
+1
View File
@@ -207,6 +207,7 @@
<ClInclude Include="..\Include\EGkGeoConst.h" />
<ClInclude Include="..\Include\EGkPoint3d.h" />
<ClInclude Include="..\Include\EGkVector3d.h" />
<ClInclude Include="EGrGraphObjs.h" />
<ClInclude Include="EgrScene.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
+3
View File
@@ -59,6 +59,9 @@
<ClInclude Include="..\Include\EGkGeoConst.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="EGrGraphObjs.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="TestEGr.cpp">
+8 -6
View File
@@ -169,10 +169,11 @@ CTestEGrDlg::OnPaint( void)
dc.DrawIcon( x, y, m_hIcon) ;
}
else {
//m_Scene.Reshape( 0, 0) ;
// ridisegno dialogo
CDialog::OnPaint() ;
// ridisegno finestra OpenGL
m_Scene.Draw() ;
m_View.ValidateRgn( NULL) ;
CDialog::OnPaint() ;
}
}
@@ -222,7 +223,7 @@ CTestEGrDlg::OnSize( UINT nType, int cx, int cy)
m_nPrevCx = cx ;
m_nPrevCy = cy ;
// lancio ridisegno
Invalidate() ;
RedrawWindow() ;
}
}
@@ -310,8 +311,8 @@ void
CTestEGrDlg::StartScene( void)
{
// recupero i parametri
int nDriver = ( GetPrivateProfileInt( "OpenGL", "Driver", 2, AfxGetApp()->m_pszProfileName) == 1) ;
bool bDouBuff = ( GetPrivateProfileInt( "OpenGL", "DoubleBuffer", 1, AfxGetApp()->m_pszProfileName) == 1) ;
int nDriver = GetPrivateProfileInt( "OpenGL", "Driver", 2, AfxGetApp()->m_pszProfileName) ;
bool b2Buff = ( GetPrivateProfileInt( "OpenGL", "DoubleBuffer", 1, AfxGetApp()->m_pszProfileName) == 1) ;
int nColorBits = GetPrivateProfileInt( "OpenGL", "ColorBits", 16, AfxGetApp()->m_pszProfileName) ;
int nDepthBits = GetPrivateProfileInt( "OpenGL", "DepthBits", 16, AfxGetApp()->m_pszProfileName) ;
@@ -325,7 +326,8 @@ CTestEGrDlg::StartScene( void)
m_View.Create( this, IDC_SCENE) ;
// creazione della scena
m_Scene.CreateContext( m_View.GetSafeHdc(), nDriver, bDouBuff, nColorBits, nDepthBits) ;
m_Scene.Init( m_pLogger) ;
m_Scene.CreateContext( m_View.GetSafeHdc(), nDriver, b2Buff, nColorBits, nDepthBits) ;
// impostazione dati geometrie
m_Scene.SetData( 3) ;