Consolidate poly line code, so it can be used with both renderers. Use it
with D3D instead of hardware lines.
This commit is contained in:
@@ -76,6 +76,74 @@ void RageDisplay::ResetStats()
|
|||||||
|
|
||||||
void RageDisplay::StatsAddVerts( int iNumVertsRendered ) { g_iVertsRenderedSinceLastCheck += iNumVertsRendered; }
|
void RageDisplay::StatsAddVerts( int iNumVertsRendered ) { g_iVertsRenderedSinceLastCheck += iNumVertsRendered; }
|
||||||
|
|
||||||
|
/* Draw a line as a quad. GL_LINES with antialiasing off can draw line
|
||||||
|
* ends at odd angles--they're forced to axis-alignment regardless of the
|
||||||
|
* angle of the line. */
|
||||||
|
void RageDisplay::DrawPolyLine(const RageVertex &p1, const RageVertex &p2, float LineWidth )
|
||||||
|
{
|
||||||
|
/* soh cah toa strikes strikes again! */
|
||||||
|
float opp = p2.p.x - p1.p.x;
|
||||||
|
float adj = p2.p.y - p1.p.y;
|
||||||
|
float hyp = powf(opp*opp + adj*adj, 0.5f);
|
||||||
|
|
||||||
|
float lsin = opp/hyp;
|
||||||
|
float lcos = adj/hyp;
|
||||||
|
|
||||||
|
RageVertex v[4];
|
||||||
|
|
||||||
|
v[0] = v[1] = p1;
|
||||||
|
v[2] = v[3] = p2;
|
||||||
|
|
||||||
|
float ydist = lsin * LineWidth/2;
|
||||||
|
float xdist = lcos * LineWidth/2;
|
||||||
|
|
||||||
|
v[0].p.x += xdist;
|
||||||
|
v[0].p.y -= ydist;
|
||||||
|
v[1].p.x -= xdist;
|
||||||
|
v[1].p.y += ydist;
|
||||||
|
v[2].p.x -= xdist;
|
||||||
|
v[2].p.y += ydist;
|
||||||
|
v[3].p.x += xdist;
|
||||||
|
v[3].p.y -= ydist;
|
||||||
|
|
||||||
|
this->DrawQuad(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RageDisplay::DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth )
|
||||||
|
{
|
||||||
|
ASSERT( iNumVerts >= 2 );
|
||||||
|
|
||||||
|
/* Draw a line strip with rounded corners using polys. This is used on
|
||||||
|
* cards that have strange allergic reactions to antialiased points and
|
||||||
|
* lines. */
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < iNumVerts-1; ++i)
|
||||||
|
DrawPolyLine(v[i], v[i+1], LineWidth);
|
||||||
|
|
||||||
|
/* Join the lines with circles so we get rounded corners. */
|
||||||
|
for(i = 0; i < iNumVerts; ++i)
|
||||||
|
DrawCircle( v[i], LineWidth/2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageDisplay::DrawCircle( const RageVertex &p, float radius )
|
||||||
|
{
|
||||||
|
const int subdivisions = 32;
|
||||||
|
RageVertex v[subdivisions+2];
|
||||||
|
v[0] = p;
|
||||||
|
|
||||||
|
for(int i = 0; i < subdivisions+1; ++i)
|
||||||
|
{
|
||||||
|
const float fRotation = float(i) / subdivisions * 2*PI;
|
||||||
|
const float fX = cosf(fRotation) * radius;
|
||||||
|
const float fY = -sinf(fRotation) * radius;
|
||||||
|
v[1+i] = v[0];
|
||||||
|
v[1+i].p.x += fX;
|
||||||
|
v[1+i].p.y += fY;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->DrawFan( v, subdivisions+2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -133,13 +133,17 @@ public:
|
|||||||
virtual void DrawStrip( const RageVertex v[], int iNumVerts ) = 0;
|
virtual void DrawStrip( const RageVertex v[], int iNumVerts ) = 0;
|
||||||
virtual void DrawTriangles( const RageVertex v[], int iNumVerts ) = 0;
|
virtual void DrawTriangles( const RageVertex v[], int iNumVerts ) = 0;
|
||||||
virtual void DrawIndexedTriangles( const RageVertex v[], const Uint16* pIndices, int iNumIndices ) = 0;
|
virtual void DrawIndexedTriangles( const RageVertex v[], const Uint16* pIndices, int iNumIndices ) = 0;
|
||||||
virtual void DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth ) = 0;
|
virtual void DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth );
|
||||||
|
|
||||||
|
void DrawCircle( const RageVertex &v, float radius );
|
||||||
|
|
||||||
virtual void SaveScreenshot( CString sPath ) = 0;
|
virtual void SaveScreenshot( CString sPath ) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void SetViewport(int shift_left, int shift_down) = 0;
|
virtual void SetViewport(int shift_left, int shift_down) = 0;
|
||||||
|
|
||||||
|
void DrawPolyLine(const RageVertex &p1, const RageVertex &p2, float LineWidth );
|
||||||
|
|
||||||
// Stuff in RageDisplay.cpp
|
// Stuff in RageDisplay.cpp
|
||||||
void SetDefaultRenderStates();
|
void SetDefaultRenderStates();
|
||||||
|
|
||||||
|
|||||||
@@ -665,6 +665,9 @@ void RageDisplay_D3D::DrawIndexedTriangles( const RageVertex v[], const Uint16 p
|
|||||||
StatsAddVerts( iNumIndices );
|
StatsAddVerts( iNumIndices );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use the default poly-based implementation. D3D lines apparently don't support
|
||||||
|
* AA with greater-than-one widths. */
|
||||||
|
/*
|
||||||
void RageDisplay_D3D::DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth )
|
void RageDisplay_D3D::DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth )
|
||||||
{
|
{
|
||||||
ASSERT( iNumVerts >= 2 );
|
ASSERT( iNumVerts >= 2 );
|
||||||
@@ -679,7 +682,7 @@ void RageDisplay_D3D::DrawLineStrip( const RageVertex v[], int iNumVerts, float
|
|||||||
);
|
);
|
||||||
StatsAddVerts( iNumVerts );
|
StatsAddVerts( iNumVerts );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void RageDisplay_D3D::SetTexture( RageTexture* pTexture )
|
void RageDisplay_D3D::SetTexture( RageTexture* pTexture )
|
||||||
{
|
{
|
||||||
if( pTexture == NULL )
|
if( pTexture == NULL )
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
void DrawStrip( const RageVertex v[], int iNumVerts );
|
void DrawStrip( const RageVertex v[], int iNumVerts );
|
||||||
void DrawTriangles( const RageVertex v[], int iNumVerts );
|
void DrawTriangles( const RageVertex v[], int iNumVerts );
|
||||||
void DrawIndexedTriangles( const RageVertex v[], const Uint16* pIndices, int iNumIndices );
|
void DrawIndexedTriangles( const RageVertex v[], const Uint16* pIndices, int iNumIndices );
|
||||||
void DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth );
|
// void DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth );
|
||||||
|
|
||||||
void SaveScreenshot( CString sPath );
|
void SaveScreenshot( CString sPath );
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -485,73 +485,21 @@ void RageDisplay_OGL::DrawIndexedTriangles( const RageVertex v[], const Uint16 p
|
|||||||
StatsAddVerts( iNumIndices );
|
StatsAddVerts( iNumIndices );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw a line as a quad. GL_LINES with antialiasing off can draw line
|
|
||||||
* ends at odd angles--they're forced to axis-alignment regardless of the
|
|
||||||
* angle of the line. */
|
|
||||||
void DrawPolyLine(const RageVertex &p1, const RageVertex &p2, float LineWidth )
|
|
||||||
{
|
|
||||||
/* soh cah toa strikes strikes again! */
|
|
||||||
float opp = p2.p.x - p1.p.x;
|
|
||||||
float adj = p2.p.y - p1.p.y;
|
|
||||||
float hyp = powf(opp*opp + adj*adj, 0.5f);
|
|
||||||
|
|
||||||
float lsin = opp/hyp;
|
|
||||||
float lcos = adj/hyp;
|
|
||||||
|
|
||||||
RageVertex v[4];
|
|
||||||
|
|
||||||
v[0] = v[1] = p1;
|
|
||||||
v[2] = v[3] = p2;
|
|
||||||
|
|
||||||
float ydist = lsin * LineWidth/2;
|
|
||||||
float xdist = lcos * LineWidth/2;
|
|
||||||
|
|
||||||
v[0].p.x += xdist;
|
|
||||||
v[0].p.y -= ydist;
|
|
||||||
v[1].p.x -= xdist;
|
|
||||||
v[1].p.y += ydist;
|
|
||||||
v[2].p.x -= xdist;
|
|
||||||
v[2].p.y += ydist;
|
|
||||||
v[3].p.x += xdist;
|
|
||||||
v[3].p.y -= ydist;
|
|
||||||
|
|
||||||
DISPLAY->DrawQuad(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RageDisplay_OGL::DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth )
|
void RageDisplay_OGL::DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth )
|
||||||
{
|
{
|
||||||
ASSERT( iNumVerts >= 2 );
|
ASSERT( iNumVerts >= 2 );
|
||||||
|
|
||||||
|
if( g_bAALinesBroken )
|
||||||
|
{
|
||||||
|
RageDisplay::DrawLineStrip(v, iNumVerts, LineWidth );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode( GL_PROJECTION );
|
||||||
glLoadMatrixf( (const float*)GetProjection() );
|
glLoadMatrixf( (const float*)GetProjection() );
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode( GL_MODELVIEW );
|
||||||
glLoadMatrixf( (const float*)GetModelViewTop() );
|
glLoadMatrixf( (const float*)GetModelViewTop() );
|
||||||
|
|
||||||
if( g_bAALinesBroken )
|
|
||||||
{
|
|
||||||
/* Draw a line strip with rounded corners using polys. This is used on
|
|
||||||
* cards that have strange allergic reactions to antialiased points and
|
|
||||||
* lines. */
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < iNumVerts-1; ++i)
|
|
||||||
DrawPolyLine(v[i], v[i+1], LineWidth);
|
|
||||||
|
|
||||||
/* Join the lines with circles so we get rounded corners. */
|
|
||||||
GLUquadricObj *q = gluNewQuadric();
|
|
||||||
for(i = 0; i < iNumVerts; ++i)
|
|
||||||
{
|
|
||||||
glPushMatrix();
|
|
||||||
glColor4ub(v[i].c.r, v[i].c.g, v[i].c.b, v[i].c.a);
|
|
||||||
glTexCoord3fv(v[i].t);
|
|
||||||
glTranslatef(v[i].p.x, v[i].p.y, v[i].p.z);
|
|
||||||
|
|
||||||
gluDisk(q, 0, LineWidth/2, 32, 32);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
gluDeleteQuadric(q);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Draw a nice AA'd line loop. One problem with this is that point and line
|
/* Draw a nice AA'd line loop. One problem with this is that point and line
|
||||||
* sizes don't always precisely match, which doesn't look quite right.
|
* sizes don't always precisely match, which doesn't look quite right.
|
||||||
* It's worth it for the AA, though. */
|
* It's worth it for the AA, though. */
|
||||||
@@ -605,7 +553,6 @@ void RageDisplay_OGL::DrawLineStrip( const RageVertex v[], int iNumVerts, float
|
|||||||
glDrawArrays( GL_POINTS, 0, iNumVerts );
|
glDrawArrays( GL_POINTS, 0, iNumVerts );
|
||||||
|
|
||||||
glDisable(GL_POINT_SMOOTH);
|
glDisable(GL_POINT_SMOOTH);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageDisplay_OGL::SetTexture( RageTexture* pTexture )
|
void RageDisplay_OGL::SetTexture( RageTexture* pTexture )
|
||||||
|
|||||||
Reference in New Issue
Block a user