2013-07-22 08:41:12 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GPU_MANAGER_H_
|
|
|
|
#define GPU_MANAGER_H_
|
|
|
|
|
|
|
|
#include <gal/opengl/vertex_common.h>
|
|
|
|
#include <boost/scoped_array.hpp>
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
namespace KIGFX
|
2013-07-22 08:41:12 +00:00
|
|
|
{
|
|
|
|
class SHADER;
|
|
|
|
class VERTEX_CONTAINER;
|
|
|
|
class CACHED_CONTAINER;
|
|
|
|
class NONCACHED_CONTAINER;
|
|
|
|
|
2017-08-08 12:25:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Class to handle uploading vertices and indices to GPU in drawing purposes.
|
|
|
|
*/
|
|
|
|
|
2013-07-22 08:41:12 +00:00
|
|
|
class GPU_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static GPU_MANAGER* MakeManager( VERTEX_CONTAINER* aContainer );
|
|
|
|
|
|
|
|
virtual ~GPU_MANAGER();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function BeginDrawing()
|
|
|
|
* Prepares the stored data to be drawn.
|
|
|
|
*/
|
|
|
|
virtual void BeginDrawing() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DrawIndices()
|
|
|
|
* Makes the GPU draw given range of vertices.
|
|
|
|
* @param aOffset is the beginning of the range.
|
|
|
|
* @param aSize is the number of vertices to be drawn.
|
|
|
|
*/
|
|
|
|
virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DrawIndices()
|
|
|
|
* Makes the GPU draw all the vertices stored in the container.
|
|
|
|
*/
|
|
|
|
virtual void DrawAll() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function EndDrawing()
|
|
|
|
* Clears the container after drawing routines.
|
|
|
|
*/
|
|
|
|
virtual void EndDrawing() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetShader()
|
|
|
|
* Allows using shaders with the stored data.
|
|
|
|
* @param aShader is the object that allows using shaders.
|
|
|
|
*/
|
|
|
|
virtual void SetShader( SHADER& aShader );
|
|
|
|
|
2018-10-14 22:09:59 +00:00
|
|
|
/**
|
|
|
|
* Function EnableDepthTest()
|
|
|
|
* Enables/disables Z buffer depth test.
|
|
|
|
*/
|
|
|
|
void EnableDepthTest( bool aEnabled );
|
|
|
|
|
2013-07-22 08:41:12 +00:00
|
|
|
protected:
|
|
|
|
GPU_MANAGER( VERTEX_CONTAINER* aContainer );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> Drawing status flag.
|
2013-10-14 14:13:35 +00:00
|
|
|
bool m_isDrawing;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> Container that stores vertices data.
|
2013-07-22 08:41:12 +00:00
|
|
|
VERTEX_CONTAINER* m_container;
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> Shader handling
|
2013-07-22 08:41:12 +00:00
|
|
|
SHADER* m_shader;
|
2013-10-14 18:40:36 +00:00
|
|
|
|
|
|
|
///> Location of shader attributes (for glVertexAttribPointer)
|
|
|
|
int m_shaderAttrib;
|
2018-10-14 22:09:59 +00:00
|
|
|
|
|
|
|
///> true: enable Z test when drawing
|
|
|
|
bool m_enableDepthTest;
|
2013-07-22 08:41:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GPU_CACHED_MANAGER : public GPU_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GPU_CACHED_MANAGER( VERTEX_CONTAINER* aContainer );
|
|
|
|
~GPU_CACHED_MANAGER();
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::BeginDrawing()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void BeginDrawing() override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::DrawIndices()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::DrawAll()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawAll() override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::EndDrawing()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void EndDrawing() override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2016-05-02 14:12:16 +00:00
|
|
|
///> Maps vertex buffer stored in GPU memory.
|
|
|
|
void Map();
|
|
|
|
|
|
|
|
///> Unmaps vertex buffer.
|
|
|
|
void Unmap();
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2016-05-02 14:12:16 +00:00
|
|
|
protected:
|
2015-08-03 19:12:00 +00:00
|
|
|
///> Resizes the indices buffer to aNewSize if necessary
|
|
|
|
void resizeIndices( unsigned int aNewSize );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> Buffers initialization flag
|
2013-10-14 14:13:35 +00:00
|
|
|
bool m_buffersInitialized;
|
2013-10-14 18:40:36 +00:00
|
|
|
|
|
|
|
///> Pointer to the current indices buffer
|
2013-07-22 08:41:12 +00:00
|
|
|
boost::scoped_array<GLuint> m_indices;
|
2013-10-14 18:40:36 +00:00
|
|
|
|
|
|
|
///> Pointer to the first free cell in the indices buffer
|
2013-10-14 14:13:35 +00:00
|
|
|
GLuint* m_indicesPtr;
|
2013-10-14 18:40:36 +00:00
|
|
|
|
2014-09-13 17:31:40 +00:00
|
|
|
///> Handle to indices buffer
|
|
|
|
GLuint m_indicesBuffer;
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> Number of indices stored in the indices buffer
|
2013-10-14 14:13:35 +00:00
|
|
|
unsigned int m_indicesSize;
|
2015-08-03 19:12:00 +00:00
|
|
|
|
|
|
|
///> Current indices buffer size
|
|
|
|
unsigned int m_indicesCapacity;
|
2013-07-22 08:41:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GPU_NONCACHED_MANAGER : public GPU_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GPU_NONCACHED_MANAGER( VERTEX_CONTAINER* aContainer );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::BeginDrawing()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void BeginDrawing() override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::DrawIndices()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::DrawAll()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawAll() override;
|
2013-07-22 08:41:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
///> @copydoc GPU_MANAGER::EndDrawing()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void EndDrawing() override;
|
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 /* GPU_MANAGER_H_ */
|