2013-04-30 13:59:32 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-06-18 14:20:29 +00:00
|
|
|
#include <gal/opengl/vbo_container.h>
|
2013-04-30 13:59:32 +00:00
|
|
|
#include <gal/opengl/vbo_item.h>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
using namespace KiGfx;
|
|
|
|
|
2013-06-18 14:20:29 +00:00
|
|
|
VBO_ITEM::VBO_ITEM( VBO_CONTAINER* aContainer ) :
|
2013-04-30 13:59:32 +00:00
|
|
|
m_offset( 0 ),
|
|
|
|
m_size( 0 ),
|
2013-06-18 14:20:29 +00:00
|
|
|
m_container( aContainer ),
|
2013-06-19 08:50:46 +00:00
|
|
|
m_isDirty( true )
|
2013-04-30 13:59:32 +00:00
|
|
|
{
|
2013-06-18 14:20:29 +00:00
|
|
|
// The item's size is not known yet, so we just start an item in the container
|
|
|
|
aContainer->StartItem( this );
|
2013-04-30 13:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VBO_ITEM::~VBO_ITEM()
|
|
|
|
{
|
2013-06-18 14:20:29 +00:00
|
|
|
m_container->Free( this );
|
2013-04-30 13:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-19 08:50:46 +00:00
|
|
|
void VBO_ITEM::PushVertex( const VBO_VERTEX* aVertex )
|
2013-04-30 13:59:32 +00:00
|
|
|
{
|
2013-06-18 14:20:29 +00:00
|
|
|
m_container->Add( this, aVertex );
|
2013-04-30 13:59:32 +00:00
|
|
|
|
|
|
|
m_size++;
|
|
|
|
m_isDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-19 08:50:46 +00:00
|
|
|
void VBO_ITEM::PushVertices( const VBO_VERTEX* aVertices, GLuint aSize )
|
2013-04-30 13:59:32 +00:00
|
|
|
{
|
2013-05-16 08:35:16 +00:00
|
|
|
for( unsigned int i = 0; i < aSize; ++i )
|
2013-05-13 09:14:35 +00:00
|
|
|
{
|
2013-06-18 14:20:29 +00:00
|
|
|
PushVertex( &aVertices[i] );
|
2013-05-13 09:14:35 +00:00
|
|
|
}
|
2013-04-30 13:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-18 14:20:29 +00:00
|
|
|
VBO_VERTEX* VBO_ITEM::GetVertices()
|
2013-04-30 13:59:32 +00:00
|
|
|
{
|
2013-05-16 08:35:16 +00:00
|
|
|
if( m_isDirty )
|
2013-06-18 14:20:29 +00:00
|
|
|
Finish();
|
2013-05-16 08:35:16 +00:00
|
|
|
|
2013-06-26 08:43:58 +00:00
|
|
|
return m_container->GetVertices( m_offset );
|
2013-04-30 13:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-15 14:48:10 +00:00
|
|
|
void VBO_ITEM::ChangeColor( const COLOR4D& aColor )
|
|
|
|
{
|
2013-06-18 14:20:29 +00:00
|
|
|
VBO_VERTEX* vertexPtr = GetVertices();
|
2013-05-15 14:48:10 +00:00
|
|
|
|
2013-06-18 14:20:29 +00:00
|
|
|
for( unsigned int i = 0; i < m_size; ++i )
|
2013-05-15 14:48:10 +00:00
|
|
|
{
|
2013-06-30 20:45:31 +00:00
|
|
|
vertexPtr->r = aColor.r * 255;
|
|
|
|
vertexPtr->g = aColor.g * 255;
|
|
|
|
vertexPtr->b = aColor.b * 255;
|
|
|
|
vertexPtr->a = aColor.a * 255;
|
2013-05-15 14:48:10 +00:00
|
|
|
|
|
|
|
// Move on to the next vertex
|
2013-06-04 13:58:53 +00:00
|
|
|
vertexPtr++;
|
2013-05-15 14:48:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-26 14:31:52 +00:00
|
|
|
void VBO_ITEM::ChangeDepth( int aDepth )
|
|
|
|
{
|
|
|
|
VBO_VERTEX* vertexPtr = GetVertices();
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < m_size; ++i )
|
|
|
|
{
|
|
|
|
vertexPtr->z = aDepth;
|
|
|
|
|
|
|
|
// Move on to the next vertex
|
|
|
|
vertexPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-18 14:20:29 +00:00
|
|
|
void VBO_ITEM::Finish()
|
2013-05-16 08:35:16 +00:00
|
|
|
{
|
2013-06-18 14:20:29 +00:00
|
|
|
// The unknown-sized item has just ended, so we need to inform the container about it
|
|
|
|
m_container->EndItem();
|
2013-05-16 08:35:16 +00:00
|
|
|
|
|
|
|
m_isDirty = false;
|
|
|
|
}
|