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.h
|
|
|
|
* @brief Class to handle an item held in a Vertex Buffer Object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VBO_ITEM_H_
|
|
|
|
#define VBO_ITEM_H_
|
|
|
|
|
|
|
|
#include <GL/gl.h>
|
2013-05-15 14:48:10 +00:00
|
|
|
#include <gal/opengl/glm/glm.hpp>
|
|
|
|
#include <gal/color4d.h>
|
2013-04-30 13:59:32 +00:00
|
|
|
|
2013-05-16 08:35:16 +00:00
|
|
|
#include <list>
|
|
|
|
|
2013-04-30 13:59:32 +00:00
|
|
|
namespace KiGfx
|
|
|
|
{
|
|
|
|
|
|
|
|
class VBO_ITEM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VBO_ITEM();
|
|
|
|
~VBO_ITEM();
|
|
|
|
|
2013-05-14 08:38:25 +00:00
|
|
|
/**
|
|
|
|
* Function PushVertex()
|
|
|
|
* Adds a single vertex to the VBO_ITEM. Vertex contains information about coordinates and
|
|
|
|
* colors and has to follow the specified format {X,Y,Z,R,G,B,A}.
|
|
|
|
* @param aVertex is a vertex to be added.
|
|
|
|
*/
|
2013-04-30 13:59:32 +00:00
|
|
|
void PushVertex( const GLfloat* aVertex );
|
2013-05-14 08:38:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function PushVertices()
|
|
|
|
* Adds multiple vertices to the VBO_ITEM. This function is recommended over multiple calls to
|
|
|
|
* PushVertex, as it does less memory reallocations. Vertices contain information about
|
|
|
|
* coordinates and colors and has to follow the specified format {X,Y,Z,R,G,B,A}.
|
|
|
|
* @param aVertices are vertices to be added.
|
|
|
|
* @param aSize is an amount of vertices to be added.
|
|
|
|
*/
|
|
|
|
void PushVertices( const GLfloat* aVertices, GLuint aSize );
|
2013-04-30 13:59:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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}.
|
|
|
|
*/
|
2013-05-16 08:35:16 +00:00
|
|
|
GLfloat* GetVertices();
|
2013-04-30 13:59:32 +00:00
|
|
|
|
2013-05-16 08:35:16 +00:00
|
|
|
/**
|
|
|
|
* Function GetIndices()
|
|
|
|
* Returns a pointer to the array containing all indices of vertices.
|
|
|
|
* @return Pointer to indices.
|
|
|
|
*/
|
|
|
|
GLuint* GetIndices();
|
2013-04-30 13:59:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2013-05-15 14:48:10 +00:00
|
|
|
/**
|
|
|
|
* Function SetTransformMatrix()
|
|
|
|
* Sets transformation matrix for vertices that are added to VBO_ITEM. If you do not want to
|
|
|
|
* transform vertices at all, pass NULL as the argument.
|
|
|
|
* @param aMatrix is the new transform matrix or NULL if you do not want to use transformation
|
|
|
|
* matrix.
|
|
|
|
*/
|
|
|
|
void SetTransformMatrix( const glm::mat4* aMatrix );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ChangeColor()
|
|
|
|
* Colors all vertices to the specified color.
|
|
|
|
* @param aColor is the new color for vertices.
|
|
|
|
*/
|
|
|
|
void ChangeColor( const COLOR4D& aColor );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function UseColor()
|
|
|
|
* Sets color used for all added vertices.
|
|
|
|
* @param aColor is the color used for added vertices.
|
|
|
|
*/
|
|
|
|
void UseColor( const COLOR4D& aColor );
|
|
|
|
|
2013-04-30 13:59:32 +00:00
|
|
|
///< Functions for getting VBO ids.
|
|
|
|
//void SetVbo( int aVboId );
|
2013-05-14 08:38:25 +00:00
|
|
|
//int GetVbo() const;
|
2013-04-30 13:59:32 +00:00
|
|
|
|
2013-05-16 08:35:16 +00:00
|
|
|
///< Data organization information for vertices {X,Y,Z,R,G,B,A}.
|
2013-05-15 14:48:10 +00:00
|
|
|
// Each vertex consists of 7 floats
|
|
|
|
static const int VertStride = 7;
|
|
|
|
static const int VertSize = VertStride * sizeof(GLfloat);
|
|
|
|
|
|
|
|
static const int IndStride = 1;
|
|
|
|
static const int IndSize = IndStride * sizeof(GLuint);
|
|
|
|
|
2013-05-16 08:35:16 +00:00
|
|
|
// Offset of color data from the beginning of each vertex data
|
2013-05-15 14:48:10 +00:00
|
|
|
static const int ColorOffset = 3;
|
|
|
|
static const int ColorByteOffset = ColorOffset * sizeof(GLfloat);
|
|
|
|
static const int ColorStride = 4;
|
|
|
|
static const int ColorSize = ColorStride * sizeof(GLfloat);
|
2013-04-30 13:59:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///< VBO ids in which the item is stored.
|
2013-05-15 14:48:10 +00:00
|
|
|
//int m_vboId; // not used yet
|
2013-04-30 13:59:32 +00:00
|
|
|
|
|
|
|
///< Contains vertices coordinates and colors.
|
|
|
|
///< Packed by 7 floats for each vertex: {X, Y, Z, R, G, B, A}
|
2013-05-14 08:38:25 +00:00
|
|
|
GLfloat* m_vertices;
|
2013-04-30 13:59:32 +00:00
|
|
|
|
2013-05-13 09:14:35 +00:00
|
|
|
///< Indices of vertices
|
2013-05-14 08:38:25 +00:00
|
|
|
GLuint* m_indices;
|
2013-04-30 13:59:32 +00:00
|
|
|
|
2013-05-16 08:35:16 +00:00
|
|
|
///< Lists of blocks
|
|
|
|
std::list<GLfloat*> m_vertBlocks;
|
|
|
|
std::list<GLuint*> m_indBlocks;
|
|
|
|
///< Pointers to current blocks that can be used for storing data
|
|
|
|
GLfloat* m_vertPtr;
|
|
|
|
GLuint* m_indPtr;
|
|
|
|
///< How many vertices can be stored in the current buffer
|
|
|
|
int m_spaceLeft;
|
|
|
|
///< Number of vertices & indices stored in a single block
|
|
|
|
static const int BLOCK_SIZE = 8;
|
|
|
|
///< Creates a new block for storing vertices data
|
|
|
|
void useNewBlock();
|
|
|
|
///< Prepares a continuous block of data that can be copied to graphics card buffer.
|
|
|
|
void prepareFinal();
|
|
|
|
|
2013-04-30 13:59:32 +00:00
|
|
|
///< Offset and size of data in VBO.
|
2013-05-14 08:38:25 +00:00
|
|
|
int m_offset;
|
|
|
|
int m_size;
|
2013-04-30 13:59:32 +00:00
|
|
|
|
|
|
|
///< Shader data used for rendering.
|
2013-05-14 08:38:25 +00:00
|
|
|
int m_shader;
|
|
|
|
int m_shaderAttrib;
|
2013-04-30 13:59:32 +00:00
|
|
|
|
2013-05-15 14:48:10 +00:00
|
|
|
///< Color used for new vertices pushed.
|
|
|
|
GLfloat m_color[4];
|
|
|
|
|
2013-04-30 13:59:32 +00:00
|
|
|
///< Flag telling if the item should be recached in VBO or not.
|
2013-05-14 08:38:25 +00:00
|
|
|
bool m_isDirty;
|
2013-05-15 14:48:10 +00:00
|
|
|
|
|
|
|
///< Current transform matrix for every new vertex pushed.
|
|
|
|
const glm::mat4* m_transform;
|
2013-04-30 13:59:32 +00:00
|
|
|
};
|
|
|
|
} // namespace KiGfx
|
|
|
|
|
|
|
|
#endif /* VBO_ITEM_H_ */
|