Commit 191cb40e authored by Maciej Suminski's avatar Maciej Suminski

Introduction of VBO. Now only tracks are rendered in a very simple way.

parent 0cd108b5
...@@ -20,6 +20,7 @@ set(GAL_SRCS ...@@ -20,6 +20,7 @@ set(GAL_SRCS
gal/color4d.cpp gal/color4d.cpp
gal/opengl/opengl_gal.cpp gal/opengl/opengl_gal.cpp
gal/opengl/shader.cpp gal/opengl/shader.cpp
gal/opengl/vbo_item.cpp
gal/cairo/cairo_gal.cpp gal/cairo/cairo_gal.cpp
view/wx_view_controls.cpp view/wx_view_controls.cpp
) )
......
...@@ -65,9 +65,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ...@@ -65,9 +65,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_gal->ComputeWorldScreenMatrix(); m_gal->ComputeWorldScreenMatrix();
m_painter = new KiGfx::PCB_PAINTER( m_gal ); m_painter = new KiGfx::PCB_PAINTER( m_gal );
m_painter->SetGAL( m_gal );
m_view = new KiGfx::VIEW( true ); m_view = new KiGfx::VIEW( true, true );
m_view->SetPainter( m_painter ); m_view->SetPainter( m_painter );
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
...@@ -157,9 +156,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders ) ...@@ -157,9 +156,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders )
if( m_view ) if( m_view )
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
if( m_painter )
m_painter->SetGAL( m_gal );
wxSize size = GetClientSize(); wxSize size = GetClientSize();
m_gal->ResizeScreen( size.GetX(), size.GetY() ); m_gal->ResizeScreen( size.GetX(), size.GetY() );
} }
This diff is collapsed.
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file vbo_item.cpp
* @brief Class to handle an item held in a Vertex Buffer Object.
*/
#include <gal/opengl/vbo_item.h>
#include <cstring>
using namespace KiGfx;
VBO_ITEM::VBO_ITEM() :
m_vertices( NULL ),
m_indices( NULL ),
m_offset( 0 ),
m_size( 0 ),
m_isDirty( true )
{
}
VBO_ITEM::~VBO_ITEM()
{
if( m_vertices )
delete m_vertices;
}
void VBO_ITEM::PushVertex( const GLfloat* aVertex )
{
GLfloat* newVertices = new GLfloat[( m_size + 1 ) * VertStride];
GLuint* newIndices = new GLuint[( m_size + 1 ) * IndStride];
// Handle a new vertex
if( m_vertices )
{
// Copy all previous vertices data
memcpy( newVertices, m_vertices, ( m_size ) * VertSize );
delete m_vertices;
}
m_vertices = newVertices;
// Add the new vertex
memcpy( &newVertices[m_size * VertStride], aVertex, VertSize );
// Handle a new index
if( m_indices )
{
// Copy all previous vertices data
memcpy( newIndices, m_indices, ( m_size ) * IndSize );
delete m_indices;
}
m_indices = newIndices;
// Add the new vertex
newIndices[m_size] = m_offset + m_size;
m_size++;
m_isDirty = true;
}
void VBO_ITEM::PushVertices( const GLfloat* aVertex, GLuint aSize )
{
// FIXME to be done
m_isDirty = true;
}
GLfloat* VBO_ITEM::GetVertices() const
{
return m_vertices;
}
GLuint* VBO_ITEM::GetIndices() const
{
return m_indices;
}
int VBO_ITEM::GetSize() const
{
return m_size;
}
void VBO_ITEM::SetOffset( int aOffset )
{
m_offset = aOffset;
// TODO change offset for all the vertices?
}
int VBO_ITEM::GetOffset() const
{
return m_offset;
}
/*
// TODO
void SetVbo( int aVboId )
{
}
int GetVbo()
{
}
*/
...@@ -205,6 +205,9 @@ void VIEW::SetGAL( GAL* aGal ) ...@@ -205,6 +205,9 @@ void VIEW::SetGAL( GAL* aGal )
{ {
m_gal = aGal; m_gal = aGal;
if( m_painter )
m_painter->SetGAL( m_gal );
// items need to be recached after changing GAL // items need to be recached after changing GAL
if( m_useGroups ) if( m_useGroups )
recacheAllItems(); recacheAllItems();
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
namespace KiGfx namespace KiGfx
{ {
class SHADER; class SHADER;
class VBO_ITEM;
/** /**
* @brief Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer. * @brief Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer.
...@@ -88,7 +89,7 @@ public: ...@@ -88,7 +89,7 @@ public:
*/ */
OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener = NULL, OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener = NULL,
wxEvtHandler* aPaintListener = NULL, bool isUseShaders = false, wxEvtHandler* aPaintListener = NULL, bool isUseShaders = false,
const wxString& aName = wxT("GLCanvas") ); const wxString& aName = wxT( "GLCanvas" ) );
virtual ~OPENGL_GAL(); virtual ~OPENGL_GAL();
...@@ -132,7 +133,7 @@ public: ...@@ -132,7 +133,7 @@ public:
// Screen methods // Screen methods
// -------------- // --------------
/// @brief Resizes the canvas. /// @brief Resizes the canvas.
virtual void ResizeScreen ( int aWidth, int aHeight ); virtual void ResizeScreen ( int aWidth, int aHeight );
/// @brief Shows/hides the GAL canvas /// @brief Shows/hides the GAL canvas
...@@ -335,19 +336,28 @@ private: ...@@ -335,19 +336,28 @@ private:
wxEvtHandler* paintListener; wxEvtHandler* paintListener;
// Display lists // Display lists
GLuint displayListsArcs; ///< Arc display list GLuint displayListsArcs; ///< Arc display list
GLuint displayListCircle; ///< Circle display list GLuint displayListCircle; ///< Circle display list
GLuint displayListSemiCircle; ///< Semi circle display list GLuint displayListSemiCircle; ///< Semi circle display list
std::deque<GLuint> displayListsGroup; ///< List of display lists used for groups std::deque<GLuint> displayListsGroup; ///< List of display lists used for groups
double curvePoints[12]; ///< Coefficients for curves // Vertex buffer objects related fields
std::deque<VECTOR2D> unitCirclePoints; ///< List of the points on a unit circle std::deque<VBO_ITEM*> vboItems; ///< Stores informations about VBO objects
VBO_ITEM* curVboItem;
GLuint curVboVertId;
GLuint curVboIndId;
int vboSize;
bool vboNeedsUpdate;
double curvePoints[12]; ///< Coefficients for curves
std::deque<VECTOR2D> unitCirclePoints; ///< List of the points on a unit circle
// Polygon tesselation // Polygon tesselation
GLUtesselator* tesselator; ///< Pointer to the tesselator GLUtesselator* tesselator; ///< Pointer to the tesselator
// Shader // Shader
std::deque<SHADER> shaderList; ///< List of the shaders std::deque<SHADER> shaderList; ///< List of the shaders
// Cursor // Cursor
int cursorSize; ///< Size of the cursor in pixels int cursorSize; ///< Size of the cursor in pixels
...@@ -368,6 +378,7 @@ private: ...@@ -368,6 +378,7 @@ private:
bool isCreated; bool isCreated;
bool isGlewInitialized; ///< Is GLEW initialized? bool isGlewInitialized; ///< Is GLEW initialized?
bool isFrameBufferInitialized; ///< Are the frame buffers initialized? bool isFrameBufferInitialized; ///< Are the frame buffers initialized?
bool isVboInitialized;
bool isShaderInitialized; ///< Was the shader initialized? bool isShaderInitialized; ///< Was the shader initialized?
bool isShaderEnabled; ///< Are the shaders enabled? bool isShaderEnabled; ///< Are the shaders enabled?
bool isUseShader; ///< Should the shaders be used? bool isUseShader; ///< Should the shaders be used?
...@@ -457,6 +468,15 @@ private: ...@@ -457,6 +468,15 @@ private:
*/ */
void deleteFrameBuffer( GLuint* aFrameBuffer, GLuint* aDepthBuffer, GLuint* aTexture ); void deleteFrameBuffer( GLuint* aFrameBuffer, GLuint* aDepthBuffer, GLuint* aTexture );
// TODO comment
void initVertexBufferObjects();
// TODO comment
void deleteVertexBufferObjects();
// TODO comment
void rebuildVbo();
/** /**
* @brief Draw a quad for the line. * @brief Draw a quad for the line.
* *
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file vbo_item.h
* @brief Class to handle an item held in a Vertex Buffer Object.
*/
// TODO comments
#ifndef VBO_ITEM_H_
#define VBO_ITEM_H_
#include <GL/gl.h>
namespace KiGfx
{
class VBO_ITEM
{
public:
VBO_ITEM();
~VBO_ITEM();
// TODO comments
void PushVertex( const GLfloat* aVertex );
void PushVertices( const GLfloat* aVertex, GLuint aSize );
/**
* Function GetVertices()
* Returns a pointer to the array containing all vertices.
* @return Pointer to vertices packed in format {X, Y, Z, R, G, B, A}.
*/
GLfloat* GetVertices() const;
GLuint* GetIndices() const;
/**
* Function GetSize()
* Returns information about number of vertices stored.
* @param Amount of vertices.
*/
int GetSize() const;
/**
* Function SetOffset()
* Sets data offset in the VBO.
* @param aOffset is the offset expressed as a number of vertices.
*/
void SetOffset( int aOffset );
/**
* Function GetOffset()
* Returns data offset in the VBO.
* @return Data offset expressed as a number of vertices.
*/
int GetOffset() const;
///< Functions for getting VBO ids.
//void SetVbo( int aVboId );
//int GetVbo();
///< Data organization information for vertices.
static const int VertStride = 7;
static const int VertSize = VertStride * sizeof(GLfloat);
static const int IndStride = 1;
static const int IndSize = IndStride * sizeof(GLuint);
static const int ColorOffset = 3 * sizeof(GLfloat);
private:
///< VBO ids in which the item is stored.
//int m_vboId; // not used yet
///< Contains vertices coordinates and colors.
///< Packed by 7 floats for each vertex: {X, Y, Z, R, G, B, A}
GLfloat* m_vertices;
GLuint* m_indices;
///< Offset and size of data in VBO.
int m_offset;
int m_size;
///< Shader data used for rendering.
int m_shader;
int m_shaderAttrib;
///< Flag telling if the item should be recached in VBO or not.
bool m_isDirty;
};
} // namespace KiGfx
#endif /* VBO_ITEM_H_ */
...@@ -166,7 +166,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) ...@@ -166,7 +166,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
// in order to be displayed // in order to be displayed
// Load zones // Load zones
for( int i = 0; i < m_Pcb->GetAreaCount(); ++i ) /*for( int i = 0; i < m_Pcb->GetAreaCount(); ++i )
{ {
view->Add( (KiGfx::VIEW_ITEM*) ( m_Pcb->GetArea( i ) ) ); view->Add( (KiGfx::VIEW_ITEM*) ( m_Pcb->GetArea( i ) ) );
} }
...@@ -175,7 +175,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) ...@@ -175,7 +175,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
for( BOARD_ITEM* drawing = m_Pcb->m_Drawings; drawing; drawing = drawing->Next() ) for( BOARD_ITEM* drawing = m_Pcb->m_Drawings; drawing; drawing = drawing->Next() )
{ {
view->Add( drawing ); view->Add( drawing );
} }*/
// Load tracks // Load tracks
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() ) for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
...@@ -184,7 +184,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) ...@@ -184,7 +184,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
} }
// Load modules and its additional elements // Load modules and its additional elements
for( MODULE* module = m_Pcb->m_Modules; module; module = module->Next() ) /*for( MODULE* module = m_Pcb->m_Modules; module; module = module->Next() )
{ {
// Load module's pads // Load module's pads
for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
...@@ -208,7 +208,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) ...@@ -208,7 +208,7 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
for( SEGZONE* zone = m_Pcb->m_Zone; zone; zone = zone->Next() ) for( SEGZONE* zone = m_Pcb->m_Zone; zone; zone = zone->Next() )
{ {
view->Add( zone ); view->Add( zone );
} }*/
// Apply layer coloring scheme & display options // Apply layer coloring scheme & display options
if( view->GetPainter() ) if( view->GetPainter() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment