2013-07-22 08:41:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-08-08 12:25:03 +00:00
|
|
|
* Copyright 2013-2017 CERN
|
2021-01-25 12:42:36 +00:00
|
|
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-12-21 23:42:21 +00:00
|
|
|
*
|
2013-07-22 08:41:12 +00:00
|
|
|
* @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 vertex_container.h
|
2020-12-21 23:42:21 +00:00
|
|
|
* Class to store vertices and handle transfers between system memory and GPU memory.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VERTEX_CONTAINER_H_
|
|
|
|
#define VERTEX_CONTAINER_H_
|
|
|
|
|
|
|
|
#include <gal/opengl/vertex_common.h>
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
namespace KIGFX
|
2013-07-22 08:41:12 +00:00
|
|
|
{
|
|
|
|
class VERTEX_ITEM;
|
|
|
|
class SHADER;
|
|
|
|
|
|
|
|
class VERTEX_CONTAINER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return a pointer to a new container of an appropriate type.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
|
|
|
static VERTEX_CONTAINER* MakeContainer( bool aCached );
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-07-22 08:41:12 +00:00
|
|
|
virtual ~VERTEX_CONTAINER();
|
|
|
|
|
2017-08-08 12:25:03 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return true if the container caches vertex data in RAM or video memory.
|
2017-08-08 12:25:03 +00:00
|
|
|
* Otherwise it is a single batch draw which is later discarded.
|
|
|
|
*/
|
|
|
|
virtual bool IsCached() const = 0;
|
|
|
|
|
2016-05-02 14:12:16 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Prepare the container for vertices updates.
|
2016-05-02 14:12:16 +00:00
|
|
|
*/
|
|
|
|
virtual void Map() {}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Finish the vertices updates stage.
|
2016-05-02 14:12:16 +00:00
|
|
|
*/
|
2017-08-08 12:25:03 +00:00
|
|
|
virtual void Unmap() {}
|
2016-05-02 14:12:16 +00:00
|
|
|
|
2013-07-22 08:41:12 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Set the item for the further actions.
|
|
|
|
*
|
2013-07-22 08:41:12 +00:00
|
|
|
* @param aItem is the item or NULL in case of finishing the item.
|
|
|
|
*/
|
|
|
|
virtual void SetItem( VERTEX_ITEM* aItem ) = 0;
|
|
|
|
|
2013-09-12 07:44:57 +00:00
|
|
|
/**
|
2017-08-21 11:30:35 +00:00
|
|
|
* Clean up after adding an item.
|
2013-09-12 07:44:57 +00:00
|
|
|
*/
|
|
|
|
virtual void FinishItem() {};
|
|
|
|
|
2013-07-22 08:41:12 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return allocated space for the requested number of vertices associated with the
|
|
|
|
* current item (set with SetItem()).
|
|
|
|
*
|
|
|
|
* The allocated space is added at the end of the chunk used by the current item and
|
|
|
|
* may serve to store new vertices.
|
|
|
|
*
|
2013-07-22 08:41:12 +00:00
|
|
|
* @param aSize is the number of vertices to be allocated.
|
|
|
|
* @return Pointer to the allocated space or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virtual VERTEX* Allocate( unsigned int aSize ) = 0;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Erase the data related to an item.
|
|
|
|
*
|
2013-09-12 07:44:57 +00:00
|
|
|
* @param aItem is the item to be erased.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
2013-09-12 07:44:57 +00:00
|
|
|
virtual void Delete( VERTEX_ITEM* aItem ) = 0;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Remove all data stored in the container and restores its original state.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
|
|
|
virtual void Clear() = 0;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return pointer to the vertices stored in the container.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
2017-08-21 11:30:35 +00:00
|
|
|
VERTEX* GetAllVertices() const
|
2013-07-22 08:41:12 +00:00
|
|
|
{
|
|
|
|
return m_vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return vertices stored at the specific offset.
|
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* @param aOffset is the offset.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
2017-08-21 11:30:35 +00:00
|
|
|
virtual VERTEX* GetVertices( unsigned int aOffset ) const
|
2013-07-22 08:41:12 +00:00
|
|
|
{
|
|
|
|
return &m_vertices[aOffset];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return amount of vertices currently stored in the container.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
2017-08-21 11:30:35 +00:00
|
|
|
virtual unsigned int GetSize() const
|
2013-07-22 08:41:12 +00:00
|
|
|
{
|
|
|
|
return m_currentSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Return information about the container cache state.
|
|
|
|
*
|
2017-08-21 11:30:35 +00:00
|
|
|
* @return True in case the vertices have to be reuploaded.
|
2013-07-22 08:41:12 +00:00
|
|
|
*/
|
2017-08-21 11:30:35 +00:00
|
|
|
bool IsDirty() const
|
2013-07-22 08:41:12 +00:00
|
|
|
{
|
2017-08-21 11:30:35 +00:00
|
|
|
return m_dirty;
|
2013-07-22 08:41:12 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 16:04:15 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Set the dirty flag, so vertices in the container are going to be reuploaded to the GPU on
|
2013-07-25 16:04:15 +00:00
|
|
|
* the next frame.
|
|
|
|
*/
|
2017-08-21 11:30:35 +00:00
|
|
|
void SetDirty()
|
2013-07-25 16:04:15 +00:00
|
|
|
{
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
2017-08-21 11:26:00 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Clear the dirty flag to prevent reuploading vertices to the GPU memory.
|
2017-08-21 11:26:00 +00:00
|
|
|
*/
|
|
|
|
void ClearDirty()
|
|
|
|
{
|
|
|
|
m_dirty = false;
|
|
|
|
}
|
|
|
|
|
2013-07-22 08:41:12 +00:00
|
|
|
protected:
|
2017-08-08 12:25:03 +00:00
|
|
|
VERTEX_CONTAINER( unsigned int aSize = DEFAULT_SIZE );
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2020-12-21 23:42:21 +00:00
|
|
|
/**
|
|
|
|
* Return size of the used memory space.
|
|
|
|
*
|
|
|
|
* @return Size of the used memory space (expressed as a number of vertices).
|
|
|
|
*/
|
|
|
|
unsigned int usedSpace() const
|
|
|
|
{
|
|
|
|
return m_currentSize - m_freeSpace;
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Free space left in the container, expressed in vertices
|
2013-07-22 08:41:12 +00:00
|
|
|
unsigned int m_freeSpace;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Current container size, expressed in vertices
|
2013-07-22 08:41:12 +00:00
|
|
|
unsigned int m_currentSize;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Store the initial size, so it can be resized to this on Clear()
|
2013-07-22 08:41:12 +00:00
|
|
|
unsigned int m_initialSize;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Actual storage memory
|
2013-07-22 08:41:12 +00:00
|
|
|
VERTEX* m_vertices;
|
|
|
|
|
2017-08-21 11:30:35 +00:00
|
|
|
// Status flags
|
2013-07-22 08:41:12 +00:00
|
|
|
bool m_failed;
|
|
|
|
bool m_dirty;
|
|
|
|
|
|
|
|
///< Default initial size of a container (expressed in vertices)
|
2017-08-08 12:25:03 +00:00
|
|
|
static constexpr unsigned int DEFAULT_SIZE = 1048576;
|
2013-07-22 08:41:12 +00:00
|
|
|
};
|
2013-10-14 14:13:35 +00:00
|
|
|
} // namespace KIGFX
|
2013-07-22 08:41:12 +00:00
|
|
|
|
|
|
|
#endif /* VERTEX_CONTAINER_H_ */
|