get rid of vertex queue

This commit is contained in:
Glenn Maynard
2003-01-08 23:16:28 +00:00
parent 185b128ab1
commit 8c4a024888
5 changed files with 28 additions and 124 deletions
+24 -118
View File
@@ -28,14 +28,12 @@ RageDisplay* DISPLAY = NULL;
//////////// ////////////
// Globals // Globals
//////////// ////////////
const int MAX_NUM_VERTICIES = 1000;
SDL_Surface *g_screen = NULL; // this class is a singleton, so there can be only one SDL_Surface *g_screen = NULL; // this class is a singleton, so there can be only one
int g_flags = 0; /* SDL video flags */ int g_flags = 0; /* SDL video flags */
GLenum g_vertMode = GL_TRIANGLES; GLenum g_vertMode = GL_TRIANGLES;
RageVertex g_vertQueue[MAX_NUM_VERTICIES];
RageTimer g_LastCheckTimer; RageTimer g_LastCheckTimer;
int g_iNumVerts; int g_iNumVerts;
int g_iFPS, g_iVPF, g_iDPF; int g_iFPS, g_iVPF;
int g_PerspectiveMode = 0; int g_PerspectiveMode = 0;
@@ -43,11 +41,10 @@ int g_CurrentHeight, g_CurrentWidth, g_CurrentBPP;
int g_ModelMatrixCnt=0; int g_ModelMatrixCnt=0;
int RageDisplay::GetFPS() const { return g_iFPS; } int RageDisplay::GetFPS() const { return g_iFPS; }
int RageDisplay::GetVPF() const { return g_iVPF; } int RageDisplay::GetVPF() const { return g_iVPF; }
int RageDisplay::GetDPF() const { return g_iDPF; }
static int g_iFramesRenderedSinceLastCheck, static int g_iFramesRenderedSinceLastCheck,
g_iVertsRenderedSinceLastCheck, g_iVertsRenderedSinceLastCheck;
g_iDrawsSinceLastCheck;
PWSWAPINTERVALEXTPROC GLExt::wglSwapIntervalEXT; PWSWAPINTERVALEXTPROC GLExt::wglSwapIntervalEXT;
void GetGLExtensions(set<string> &ext) void GetGLExtensions(set<string> &ext)
@@ -287,7 +284,6 @@ void RageDisplay::Clear()
void RageDisplay::Flip() void RageDisplay::Flip()
{ {
FlushQueue();
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
g_iFramesRenderedSinceLastCheck++; g_iFramesRenderedSinceLastCheck++;
@@ -296,17 +292,16 @@ void RageDisplay::Flip()
g_LastCheckTimer.GetDeltaTime(); g_LastCheckTimer.GetDeltaTime();
g_iFPS = g_iFramesRenderedSinceLastCheck; g_iFPS = g_iFramesRenderedSinceLastCheck;
g_iVPF = g_iVertsRenderedSinceLastCheck / g_iFPS; g_iVPF = g_iVertsRenderedSinceLastCheck / g_iFPS;
g_iDPF = g_iDrawsSinceLastCheck / g_iFPS; g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = 0;
g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = g_iDrawsSinceLastCheck = 0; LOG->Trace( "FPS: %d, VPF: %d", g_iFPS, g_iVPF );
LOG->Trace( "FPS: %d, VPF: %d, DPF: %d", g_iFPS, g_iVPF, g_iDPF );
} }
} }
void RageDisplay::ResetStats() void RageDisplay::ResetStats()
{ {
g_iFPS = g_iVPF = g_iDPF = 0; g_iFPS = g_iVPF = 0;
g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = g_iDrawsSinceLastCheck = 0; g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = 0;
g_LastCheckTimer.GetDeltaTime(); g_LastCheckTimer.GetDeltaTime();
} }
@@ -318,51 +313,37 @@ void RageDisplay::DrawQuad( const RageVertex v[4] ) // upper-left, upper-right,
{ {
DrawQuads( v, 4 ); DrawQuads( v, 4 );
} }
const GLenum RageVertexFormat = GL_T2F_C4UB_V3F;
void RageDisplay::DrawQuads( const RageVertex v[], int iNumVerts ) void RageDisplay::DrawQuads( const RageVertex v[], int iNumVerts )
{ {
if( g_vertMode != GL_QUADS )
FlushQueue();
ASSERT( (iNumVerts%4) == 0 ); ASSERT( (iNumVerts%4) == 0 );
g_vertMode = GL_QUADS;
AddVerts( v, iNumVerts );
glInterleavedArrays( GL_T2F_C4UB_V3F, sizeof(RageVertex), g_vertQueue ); glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v );
glDrawArrays( g_vertMode, 0, g_iNumVerts ); glDrawArrays( GL_QUADS, 0, iNumVerts );
g_iVertsRenderedSinceLastCheck += g_iNumVerts; g_iVertsRenderedSinceLastCheck += iNumVerts;
g_iNumVerts = 0;
g_iDrawsSinceLastCheck++;
} }
void RageDisplay::DrawFan( const RageVertex v[], int iNumVerts ) void RageDisplay::DrawFan( const RageVertex v[], int iNumVerts )
{ {
if( g_vertMode != GL_TRIANGLE_FAN )
FlushQueue();
ASSERT( iNumVerts >= 3 ); ASSERT( iNumVerts >= 3 );
g_vertMode = GL_TRIANGLE_FAN; glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v );
AddVerts( v, iNumVerts ); glDrawArrays( GL_TRIANGLE_FAN, 0, iNumVerts );
FlushQueue(); g_iVertsRenderedSinceLastCheck += iNumVerts;
} }
void RageDisplay::DrawStrip( const RageVertex v[], int iNumVerts ) void RageDisplay::DrawStrip( const RageVertex v[], int iNumVerts )
{ {
if( g_vertMode != GL_TRIANGLE_STRIP )
FlushQueue();
ASSERT( iNumVerts >= 3 ); ASSERT( iNumVerts >= 3 );
g_vertMode = GL_TRIANGLE_STRIP; glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v );
AddVerts( v, iNumVerts ); glDrawArrays( GL_TRIANGLE_STRIP, 0, iNumVerts );
FlushQueue(); g_iVertsRenderedSinceLastCheck += iNumVerts;
} }
void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth ) void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth )
{ {
ASSERT( iNumVerts >= 3 ); ASSERT( iNumVerts >= 3 );
if( g_vertMode != GL_LINE_LOOP )
FlushQueue();
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
/* Our line width is wrt the regular internal SCREEN_WIDTHxSCREEN_HEIGHT screen, /* Our line width is wrt the regular internal SCREEN_WIDTHxSCREEN_HEIGHT screen,
@@ -385,9 +366,8 @@ void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth
glLineWidth(LineWidth); glLineWidth(LineWidth);
/* Draw the line loop: */ /* Draw the line loop: */
g_vertMode = GL_LINE_LOOP; glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v );
AddVerts( v, iNumVerts ); glDrawArrays( GL_LINE_LOOP, 0, iNumVerts );
FlushQueue();
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
@@ -409,42 +389,12 @@ void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth
glEnable(GL_POINT_SMOOTH); glEnable(GL_POINT_SMOOTH);
g_vertMode = GL_POINTS; glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v );
AddVerts( v, iNumVerts ); glDrawArrays( GL_POINTS, 0, iNumVerts );
FlushQueue();
glDisable(GL_POINT_SMOOTH); glDisable(GL_POINT_SMOOTH);
} }
void RageDisplay::AddVerts( const RageVertex v[], int iNumVerts )
{
for( int i=0; i<iNumVerts; i++ )
{
// Don't overflow the queue
if( g_iNumVerts+1 > MAX_NUM_VERTICIES )
FlushQueue();
g_vertQueue[g_iNumVerts].p = v[i].p;
g_vertQueue[g_iNumVerts].c = v[i].c;
g_vertQueue[g_iNumVerts].t = v[i].t;
g_iNumVerts++;
}
}
void RageDisplay::FlushQueue()
{
if( g_iNumVerts == 0 )
return;
glInterleavedArrays( GL_T2F_C4UB_V3F, sizeof(RageVertex), g_vertQueue );
glDrawArrays( g_vertMode, 0, g_iNumVerts );
g_iVertsRenderedSinceLastCheck += g_iNumVerts;
g_iNumVerts = 0;
g_iDrawsSinceLastCheck++;
}
void RageDisplay::PushMatrix() void RageDisplay::PushMatrix()
{ {
glPushMatrix(); glPushMatrix();
@@ -484,8 +434,6 @@ void RageDisplay::EnterPerspective(float fov, bool preserve_loc)
return; return;
} }
DISPLAY->FlushQueue();
/* Save the old matrices. */ /* Save the old matrices. */
DISPLAY->PushMatrix(); DISPLAY->PushMatrix();
glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION );
@@ -612,23 +560,10 @@ void RageDisplay::smPostMultMatrixf( const RageMatrix &f )
void RageDisplay::SetTexture( RageTexture* pTexture ) void RageDisplay::SetTexture( RageTexture* pTexture )
{ {
static int iLastTexID = 0; glBindTexture( GL_TEXTURE_2D, pTexture? pTexture->GetGLTextureID() : 0 );
int iNewTexID = pTexture ? pTexture->GetGLTextureID() : 0;
if( iLastTexID != iNewTexID )
FlushQueue();
iLastTexID = iNewTexID;
glBindTexture( GL_TEXTURE_2D, iNewTexID );
} }
void RageDisplay::SetTextureModeModulate() void RageDisplay::SetTextureModeModulate()
{ {
int a;
glGetTexEnviv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &a );
if( a != GL_MODULATE )
FlushQueue();
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
} }
@@ -636,20 +571,11 @@ void RageDisplay::SetTextureModeModulate()
* available pre-OpenGL 1.4. */ * available pre-OpenGL 1.4. */
void RageDisplay::SetBlendMode(int src, int dst) void RageDisplay::SetBlendMode(int src, int dst)
{ {
int a, b;
glGetIntegerv( GL_BLEND_SRC, &a );
glGetIntegerv( GL_BLEND_DST, &b );
if( a!=src || b!=dst )
FlushQueue();
glBlendFunc( src, dst ); glBlendFunc( src, dst );
} }
void RageDisplay::SetTextureModeGlow() void RageDisplay::SetTextureModeGlow()
{ {
FlushQueue();
if(!m_oglspecs->EXT_texture_env_combine) { if(!m_oglspecs->EXT_texture_env_combine) {
SetBlendMode( GL_SRC_ALPHA, GL_ONE ); SetBlendMode( GL_SRC_ALPHA, GL_ONE );
return; return;
@@ -686,39 +612,19 @@ bool RageDisplay::ZBufferEnabled() const
void RageDisplay::EnableZBuffer() void RageDisplay::EnableZBuffer()
{ {
if( !ZBufferEnabled() )
FlushQueue();
glEnable( GL_DEPTH_TEST ); glEnable( GL_DEPTH_TEST );
} }
void RageDisplay::DisableZBuffer() void RageDisplay::DisableZBuffer()
{ {
if( ZBufferEnabled() )
FlushQueue();
glDisable( GL_DEPTH_TEST ); glDisable( GL_DEPTH_TEST );
} }
void RageDisplay::EnableTextureWrapping() void RageDisplay::EnableTextureWrapping()
{ {
int a, b;
glGetTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &a );
glGetTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &b );
if( a!=GL_REPEAT || b!=GL_REPEAT )
FlushQueue();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
} }
void RageDisplay::DisableTextureWrapping() void RageDisplay::DisableTextureWrapping()
{ {
int a, b;
glGetTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &a );
glGetTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &b );
if( a!=GL_CLAMP || b!=GL_CLAMP )
FlushQueue();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
} }
-1
View File
@@ -79,7 +79,6 @@ public:
/* Statistics */ /* Statistics */
int GetFPS() const; int GetFPS() const;
int GetVPF() const; int GetVPF() const;
int GetDPF() const;
void ResetStats(); void ResetStats();
const oglspecs_t &GetSpecs() const { return *m_oglspecs; } const oglspecs_t &GetSpecs() const { return *m_oglspecs; }
+1 -1
View File
@@ -36,7 +36,7 @@ void Sample3dObject::Update( float fDeltaTime )
*/ */
void Sample3dObject::DrawPrimitives() void Sample3dObject::DrawPrimitives()
{ {
DISPLAY->FlushQueue(); /* do this before rendering directly */ // DISPLAY->FlushQueue(); /* do this before rendering directly */
/* If this is a sub-object (3d object within a 3d object), this won't /* If this is a sub-object (3d object within a 3d object), this won't
* actually do anything: */ * actually do anything: */
+3 -3
View File
@@ -137,9 +137,9 @@ void ScreenManager::Draw()
{ {
/* If FPS == 0, we don't have stats yet. */ /* If FPS == 0, we don't have stats yet. */
m_textStats.SetText( ssprintf(DISPLAY->GetFPS()? m_textStats.SetText( ssprintf(DISPLAY->GetFPS()?
"%i FPS\n%i VPF\n%i DPF": "%i FPS\n%i VPF":
"-- FPS\n-- VPF\n-- DPF", "-- FPS\n-- VPF",
DISPLAY->GetFPS(), DISPLAY->GetVPF(), DISPLAY->GetDPF()) ); DISPLAY->GetFPS(), DISPLAY->GetVPF()) );
m_textStats.Draw(); m_textStats.Draw();
} }
-1
View File
@@ -439,7 +439,6 @@ static void GameLoop()
SCREENMAN->Draw(); // draw the game SCREENMAN->Draw(); // draw the game
DISPLAY->FlushQueue();
DISPLAY->Flip(); DISPLAY->Flip();
::Sleep( 0 ); // give some time to other processes and threads ::Sleep( 0 ); // give some time to other processes and threads