Removed shaderless OpenGL backend.

This commit is contained in:
Maciej Suminski 2013-07-29 16:38:07 +02:00
parent bd182aad9f
commit f9d74ccb70
9 changed files with 126 additions and 366 deletions

View File

@ -55,7 +55,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_view = NULL;
m_painter = NULL;
SwitchBackend( aGalType, true );
SwitchBackend( aGalType );
SetBackgroundStyle( wxBG_STYLE_CUSTOM );
// Initial display settings
@ -149,13 +149,10 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
}
void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders )
void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
{
wxLogDebug( wxT( "EDA_DRAW_PANEL_GAL::SwitchBackend: using shaders: %s" ),
aUseShaders ? "true" : "false" );
// Do not do anything if the currently used GAL is correct
if( aGalType == m_currentGal && aUseShaders == m_useShaders && m_gal != NULL )
if( aGalType == m_currentGal && m_gal != NULL )
return;
delete m_gal;
@ -163,7 +160,7 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders )
switch( aGalType )
{
case GAL_TYPE_OPENGL:
m_gal = new KiGfx::OPENGL_GAL( this, this, this, aUseShaders );
m_gal = new KiGfx::OPENGL_GAL( this, this, this );
break;
case GAL_TYPE_CAIRO:
@ -191,5 +188,4 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders )
m_gal->ResizeScreen( size.GetX(), size.GetY() );
m_currentGal = aGalType;
m_useShaders = aUseShaders;
}

View File

@ -50,7 +50,7 @@ void InitTesselatorCallbacks( GLUtesselator* aTesselator );
const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0 };
OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
wxEvtHandler* aPaintListener, bool isUseShaders, const wxString& aName ) :
wxEvtHandler* aPaintListener, const wxString& aName ) :
wxGLCanvas( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
wxEXPAND, aName ),
cachedManager( true ),
@ -70,7 +70,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
// Initialize the flags
isGlewInitialized = false;
isFramebufferInitialized = false;
isUseShader = isUseShaders;
isShaderInitialized = false;
isGrouping = false;
wxSize parentSize = aParent->GetSize();
@ -255,7 +254,7 @@ void OPENGL_GAL::BeginDrawing()
}
// Compile the shaders
if( !isShaderInitialized && isUseShader )
if( !isShaderInitialized )
{
if( !shader.LoadBuiltinShader( 0, SHADER_TYPE_VERTEX ) )
wxLogFatalError( wxT( "Cannot compile vertex shader!" ) );
@ -351,9 +350,6 @@ inline void OPENGL_GAL::drawLineQuad( const VECTOR2D& aStartPoint, const VECTOR2
return;
VECTOR2D perpendicularVector( -startEndVector.y * scale, startEndVector.x * scale );
if( isUseShader )
{
glm::vec4 vector( perpendicularVector.x, perpendicularVector.y, 0.0, 0.0 );
// The perpendicular vector also needs transformations
@ -378,23 +374,6 @@ inline void OPENGL_GAL::drawLineQuad( const VECTOR2D& aStartPoint, const VECTOR2
currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v2
}
else
{
// Compute the edge points of the line
VECTOR2D v0 = aStartPoint + perpendicularVector;
VECTOR2D v1 = aStartPoint - perpendicularVector;
VECTOR2D v2 = aEndPoint + perpendicularVector;
VECTOR2D v3 = aEndPoint - perpendicularVector;
currentManager->Vertex( v0.x, v0.y, layerDepth );
currentManager->Vertex( v1.x, v1.y, layerDepth );
currentManager->Vertex( v3.x, v3.y, layerDepth );
currentManager->Vertex( v0.x, v0.y, layerDepth );
currentManager->Vertex( v3.x, v3.y, layerDepth );
currentManager->Vertex( v2.x, v2.y, layerDepth );
}
}
void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint,
@ -532,8 +511,6 @@ void OPENGL_GAL::DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEn
void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
{
if( isUseShader )
{
if( isFillEnabled )
{
@ -589,89 +566,6 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
layerDepth );
}
}
else
{
if( isStrokeEnabled )
{
// Compute the factors for the unit circle
double outerScale = lineWidth / aRadius / 2;
double innerScale = -outerScale;
outerScale += 1.0;
innerScale += 1.0;
if( innerScale < outerScale )
{
// Draw the outline
VERTEX* circle = circleContainer.GetAllVertices();
int next;
currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b,
strokeColor.a );
Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
currentManager->Scale( aRadius, aRadius, 0.0f );
for( int i = 0; i < 3 * CIRCLE_POINTS; ++i )
{
// verticesCircle contains precomputed circle points interleaved with vertex
// (0,0,0), so filled circles can be drawn as consecutive triangles, ie:
// { 0,a,b, 0,c,d, 0,e,f, 0,g,h, ... }
// where letters stand for consecutive circle points and 0 for (0,0,0) vertex.
// We have to skip all (0,0,0) vertices (every third vertex)
if( i % 3 == 0 )
{
i++;
// Depending on the vertex, next circle point
// may be stored in the next vertex..
next = i + 1;
}
else
{
// ..or 2 vertices away (in case it is preceded by (0,0,0) vertex)
next = i + 2;
}
currentManager->Vertex( circle[i].x * innerScale,
circle[i].y * innerScale,
layerDepth );
currentManager->Vertex( circle[i].x * outerScale,
circle[i].y * outerScale,
layerDepth );
currentManager->Vertex( circle[next].x * innerScale,
circle[next].y * innerScale,
layerDepth );
currentManager->Vertex( circle[i].x * outerScale,
circle[i].y * outerScale,
layerDepth );
currentManager->Vertex( circle[next].x * outerScale,
circle[next].y * outerScale,
layerDepth );
currentManager->Vertex( circle[next].x * innerScale,
circle[next].y * innerScale,
layerDepth );
}
Restore();
}
}
// Filled circles are easy to draw by using the stored vertices list
if( isFillEnabled )
{
currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a );
Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, layerDepth );
currentManager->Scale( aRadius, aRadius, 0.0f );
currentManager->Vertices( circleContainer.GetAllVertices(), CIRCLE_POINTS * 3 );
Restore();
}
}
}
void OPENGL_GAL::drawSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, double aAngle )
@ -692,8 +586,6 @@ void OPENGL_GAL::drawSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, d
void OPENGL_GAL::drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRadius,
double aAngle )
{
if( isUseShader )
{
Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
@ -719,25 +611,10 @@ void OPENGL_GAL::drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRad
Restore();
}
else
{
Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, layerDepth );
currentManager->Scale( aRadius, aRadius, 0.0f );
currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
// It is enough just to draw a half of the circle vertices to make a semicircle
currentManager->Vertices( circleContainer.GetAllVertices(), ( CIRCLE_POINTS * 3 ) / 2 );
Restore();
}
}
void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRadius,
double aAngle )
{
if( isUseShader )
{
double outerRadius = aRadius + ( lineWidth / 2 );
@ -766,52 +643,6 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
Restore();
}
else
{
// Compute the factors for the unit circle
double innerScale = 1.0 - lineWidth / aRadius;
Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, layerDepth );
currentManager->Scale( aRadius, aRadius, 0.0f );
currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
// Draw the outline
VERTEX* circle = circleContainer.GetAllVertices();
int next;
for( int i = 0; i < ( 3 * CIRCLE_POINTS ) / 2; ++i )
{
// verticesCircle contains precomputed circle points interleaved with vertex
// (0,0,0), so filled circles can be drawn as consecutive triangles, ie:
// { 0,a,b, 0,c,d, 0,e,f, 0,g,h, ... }
// where letters stand for consecutive circle points and 0 for (0,0,0) vertex.
// We have to skip all (0,0,0) vertices (every third vertex)
if( i % 3 == 0 )
{
i++;
// Depending on the vertex, next circle point may be stored in the next vertex..
next = i + 1;
}
else
{
// ..or 2 vertices away (in case it is preceded by (0,0,0) vertex)
next = i + 2;
}
currentManager->Vertex( circle[i].x * innerScale, circle[i].y * innerScale, 0.0 );
currentManager->Vertex( circle[i].x, circle[i].y, 0.0 );
currentManager->Vertex( circle[next].x * innerScale, circle[next].y * innerScale, 0.0 );
currentManager->Vertex( circle[i].x, circle[i].y, 0.0 );
currentManager->Vertex( circle[next].x, circle[next].y, 0.0 );
currentManager->Vertex( circle[next].x * innerScale, circle[next].y * innerScale, 0.0 );
}
Restore();
}
}
// FIXME Optimize
@ -833,8 +664,6 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, layerDepth );
if( isStrokeEnabled )
{
if( isUseShader )
{
double alphaIncrement = 2.0 * M_PI / CIRCLE_POINTS;
currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a );
@ -856,46 +685,6 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
DrawLine( p, p_last );
}
}
else
{
Scale( VECTOR2D( aRadius, aRadius ) );
double outerScale = lineWidth / aRadius / 2;
double innerScale = -outerScale;
outerScale += 1.0;
innerScale += 1.0;
double alphaIncrement = 2.0 * M_PI / CIRCLE_POINTS;
currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a );
for( double alpha = aStartAngle; alpha < aEndAngle; )
{
double v0[] = { cos( alpha ) * innerScale, sin( alpha ) * innerScale };
double v1[] = { cos( alpha ) * outerScale, sin( alpha ) * outerScale };
alpha += alphaIncrement;
if( alpha > aEndAngle )
alpha = aEndAngle;
double v2[] = { cos( alpha ) * innerScale, sin( alpha ) * innerScale };
double v3[] = { cos( alpha ) * outerScale, sin( alpha ) * outerScale };
currentManager->Vertex( v0[0], v0[1], 0.0 );
currentManager->Vertex( v1[0], v1[1], 0.0 );
currentManager->Vertex( v2[0], v2[1], 0.0 );
currentManager->Vertex( v1[0], v1[1], 0.0 );
currentManager->Vertex( v3[0], v3[1], 0.0 );
currentManager->Vertex( v2[0], v2[1], 0.0 );
}
// Draw line caps
drawFilledSemiCircle( startPoint, lineWidth / aRadius / 2.0, aStartAngle + M_PI );
drawFilledSemiCircle( endPoint, lineWidth / aRadius / 2.0, aEndAngle );
}
}
if( isFillEnabled )
{
@ -1362,6 +1151,7 @@ void OPENGL_GAL::DrawCursor( VECTOR2D aCursorPosition )
void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
{
// TODO change to simple drawline
// We check, if we got a horizontal or a vertical grid line and compute the offset
VECTOR2D perpendicularVector;
@ -1382,9 +1172,7 @@ void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd
VECTOR2D point3 = aEndPoint + perpendicularVector;
VECTOR2D point4 = aEndPoint - perpendicularVector;
// Set color
currentManager->Color( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
currentManager->Shader( SHADER_NONE );
// Draw the quad for the grid line

View File

@ -64,7 +64,7 @@ public:
* Switches method of rendering graphics.
* @param aGalType is a type of rendering engine that you want to use.
*/
void SwitchBackend( GalType aGalType, bool aUseShaders = false );
void SwitchBackend( GalType aGalType );
/**
* Function GetGAL
@ -89,8 +89,7 @@ protected:
///< using GAL
KiGfx::WX_VIEW_CONTROLS* m_viewControls; ///< Control for VIEW (moving, zooming, etc.)
GalType m_currentGal; ///< Currently used GAL
bool m_useShaders; ///< Are shaders used? (only for OpenGL GAL)
wxLongLong m_timeStamp;
wxLongLong m_timeStamp; ///< Timestamp for framelimiter
};
#endif

View File

@ -82,14 +82,9 @@ public:
* a wxCommandEvent holding EVT_GAL_REDRAW, as sent by PostPaint().
*
* @param aName is the name of this window for use by wxWindow::FindWindowByName()
*
* @param isUseShaders is a flag, that indicates, if shaders should be used
* for higher quality rendering.
*
*/
OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener = NULL,
wxEvtHandler* aPaintListener = NULL, bool isUseShaders = false,
const wxString& aName = wxT( "GLCanvas" ) );
wxEvtHandler* aPaintListener = NULL, const wxString& aName = wxT( "GLCanvas" ) );
virtual ~OPENGL_GAL();
@ -366,7 +361,6 @@ private:
bool isGlewInitialized; ///< Is GLEW initialized?
bool isFramebufferInitialized; ///< Are the framebuffers initialized?
bool isShaderInitialized; ///< Was the shader initialized?
bool isUseShader; ///< Should the shaders be used?
bool isGrouping; ///< Was a group started?
/**

View File

@ -85,9 +85,7 @@ static EDA_HOTKEY HkSwitchHighContrastMode( wxT("Switch Highcontrast mode"),
static EDA_HOTKEY HkCanvasDefault( wxT( "Switch to default canvas" ),
HK_CANVAS_DEFAULT, GR_KB_ALT + WXK_F9 );
static EDA_HOTKEY HkCanvasOpenGL( wxT( "Switch to OpenGL canvas" ),
HK_CANVAS_OPENGL, GR_KB_ALT + WXK_F10 );
static EDA_HOTKEY HkCanvasOpenGLShaders( wxT( "Switch to OpenGL canvas with shaders" ),
HK_CANVAS_OPENGL_SHADERS, GR_KB_ALT + WXK_F11 );
HK_CANVAS_OPENGL, GR_KB_ALT + WXK_F11 );
static EDA_HOTKEY HkCanvasCairo( wxT( "Switch to Cairo canvas" ),
HK_CANVAS_CAIRO, GR_KB_ALT + WXK_F12 );
@ -237,7 +235,7 @@ EDA_HOTKEY* board_edit_Hotkey_List[] =
&HkRecordMacros6, &HkCallMacros6, &HkRecordMacros7, &HkCallMacros7,
&HkRecordMacros8, &HkCallMacros8, &HkRecordMacros9, &HkCallMacros9,
&HkSwitchHighContrastMode,
&HkCanvasDefault, &HkCanvasCairo, &HkCanvasOpenGL, &HkCanvasOpenGLShaders,
&HkCanvasDefault, &HkCanvasCairo, &HkCanvasOpenGL,
NULL
};

View File

@ -84,7 +84,6 @@ enum hotkey_id_commnand {
HK_SWITCH_HIGHCONTRAST_MODE,
HK_CANVAS_DEFAULT,
HK_CANVAS_OPENGL,
HK_CANVAS_OPENGL_SHADERS,
HK_CANVAS_CAIRO,
};

View File

@ -365,13 +365,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
text, _( "Switch the canvas implementation to OpenGL" ),
KiBitmap( tools_xpm ) );
text = AddHotkeyName( _( "&Switch canvas to OpenGL (shaders)" ), g_Pcbnew_Editor_Hokeys_Descr,
HK_CANVAS_OPENGL_SHADERS, IS_ACCELERATOR );
AddMenuItem( viewMenu, ID_MENU_CANVAS_OPENGL_SHADERS,
text, _( "Switch the canvas implementation to OpenGL that uses shaders" ),
KiBitmap( tools_xpm ) );
text = AddHotkeyName( _( "&Switch canvas to Cairo" ), g_Pcbnew_Editor_Hokeys_Descr,
HK_CANVAS_CAIRO, IS_ACCELERATOR );

View File

@ -163,7 +163,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL_SHADERS, PCB_EDIT_FRAME::SwitchCanvas )
// Menu Get Design Rules Editor
EVT_MENU( ID_MENU_PCB_SHOW_DESIGN_RULES_DIALOG, PCB_EDIT_FRAME::ShowDesignRulesEditor )
@ -611,12 +610,7 @@ void PCB_EDIT_FRAME::SwitchCanvas( wxCommandEvent& aEvent )
break;
case ID_MENU_CANVAS_OPENGL:
m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL, false );
UseGalCanvas( true );
break;
case ID_MENU_CANVAS_OPENGL_SHADERS:
m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL, true );
m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
UseGalCanvas( true );
break;
}

View File

@ -268,7 +268,6 @@ enum pcbnew_ids
ID_MENU_PCB_SHOW_3D_FRAME,
ID_MENU_CANVAS_DEFAULT,
ID_MENU_CANVAS_OPENGL,
ID_MENU_CANVAS_OPENGL_SHADERS,
ID_MENU_CANVAS_CAIRO,
ID_PCB_USER_GRID_SETUP,
ID_PCB_GEN_BOM_FILE_FROM_BOARD,