41#ifdef KICAD_GAL_PROFILE
59 m_container( aContainer ),
62 m_enableDepthTest( true )
79 DisplayError(
nullptr, wxT(
"Could not get the shader attribute location" ) );
87 m_buffersInitialized( false ),
88 m_indicesCapacity( 0 ),
92 m_indexBufMaxSize( 0 ),
121 unsigned int offset = aItem->
GetOffset();
122 unsigned int size = aItem->
GetSize();
130 m_vranges.emplace_back( offset, offset + size - 1,
false );
136 m_vranges.emplace_back( offset, offset + size - 1,
true );
158 glEnable( GL_DEPTH_TEST );
160 glDisable( GL_DEPTH_TEST );
163 glEnableClientState( GL_VERTEX_ARRAY );
164 glEnableClientState( GL_COLOR_ARRAY );
188 while( n < n_ranges )
196 glDrawElements( GL_TRIANGLES, icnt, GL_UNSIGNED_INT,
m_indices.get() );
208 for( GLuint i = cur->
m_start; i <= cur->m_end; i++ )
219 glDrawElements( GL_TRIANGLES, icnt, GL_UNSIGNED_INT,
m_indices.get() );
226 "Cached manager size: VBO size %u iranges %zu max elt size %u drawcalls %u\n",
230 glBindBuffer( GL_ARRAY_BUFFER, 0 );
234 glDisableClientState( GL_COLOR_ARRAY );
235 glDisableClientState( GL_VERTEX_ARRAY );
272 wxASSERT_MSG(
false, wxT(
"Not implemented yet" ) );
278#ifdef KICAD_GAL_PROFILE
286 GLfloat* coordinates = (GLfloat*) ( vertices );
287 GLubyte* colors = (GLubyte*) ( vertices ) +
COLOR_OFFSET;
290 glEnable( GL_DEPTH_TEST );
292 glDisable( GL_DEPTH_TEST );
295 glEnableClientState( GL_VERTEX_ARRAY );
296 glEnableClientState( GL_COLOR_ARRAY );
303 GLfloat* shaders = (GLfloat*) ( vertices ) +
SHADER_OFFSET /
sizeof( GLfloat );
313#ifdef KICAD_GAL_PROFILE
318 glDisableClientState( GL_COLOR_ARRAY );
319 glDisableClientState( GL_VERTEX_ARRAY );
329#ifdef KICAD_GAL_PROFILE
330 totalRealTime.
Stop();
331 wxLogTrace(
traceGalProfile, wxT(
"GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ),
332 totalRealTime.
msecs() );
Class to store VERTEX instances with caching.
virtual unsigned int GetBufferHandle() const =0
Return handle to the vertex buffer.
virtual unsigned int AllItemsSize() const
virtual bool IsMapped() const =0
Return true if vertex buffer is currently mapped.
virtual void Unmap() override=0
Finish the vertices updates stage.
int m_totalHuge
Number of regular VRANGEs (small items) pooled into single draw call.
std::vector< VRANGE > m_vranges
Number of huge VRANGEs (i.e. large zones) with separate draw calls.
unsigned int m_indexBufMaxSize
Size of the current VRANGE.
unsigned int m_indicesCapacity
Ranges of visible vertex indices to render.
~GPU_CACHED_MANAGER()
Prepare the stored data to be drawn.
unsigned int m_curVrangeSize
GPU_CACHED_MANAGER(VERTEX_CONTAINER *aContainer)
virtual void DrawIndices(const VERTEX_ITEM *aItem) override
Clear the container after drawing routines.
virtual void BeginDrawing() override
Make the GPU draw given range of vertices.
int m_totalNormal
Current size of index buffer.
boost::scoped_array< GLuint > m_indices
Current indices buffer size.
unsigned int m_indexBufSize
Maximum size taken by the index buffer for all frames rendered so far.
void resizeIndices(unsigned int aNewSize)
< Resizes the indices buffer to aNewSize if necessary
virtual void EndDrawing() override
Map vertex buffer stored in GPU memory.
Class to handle uploading vertices and indices to GPU in drawing purposes.
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Drawing status flag.
int m_shaderAttrib
true: enable Z test when drawing
virtual void SetShader(SHADER &aShader)
Allow using shaders with the stored data.
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
VERTEX_CONTAINER * m_container
Shader handling.
bool m_isDrawing
Container that stores vertices data.
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
virtual void BeginDrawing() override
Make the GPU draw given range of vertices.
GPU_NONCACHED_MANAGER(VERTEX_CONTAINER *aContainer)
Prepare the stored data to be drawn.
virtual void EndDrawing() override
Clear the container after drawing routines.
virtual void DrawIndices(const VERTEX_ITEM *aItem) override
Clear the container after drawing routines.
Provide the access to the OpenGL shaders.
void Use()
Use the shader.
int GetAttribute(const std::string &aAttributeName) const
Get an attribute location.
void Deactivate()
Deactivate the shader and use the default OpenGL program.
virtual unsigned int GetSize() const
Return amount of vertices currently stored in the container.
virtual void Clear()=0
Remove all data stored in the container and restores its original state.
VERTEX * GetAllVertices() const
Return pointer to the vertices stored in the container.
virtual bool IsCached() const =0
Return true if the container caches vertex data in RAM or video memory.
void ClearDirty()
Clear the dirty flag to prevent reuploading vertices to the GPU memory.
unsigned int GetOffset() const
Return data offset in the container.
unsigned int GetSize() const
Return information about number of vertices stored.
A small class to help profiling.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
double msecs(bool aSinceLast=false)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
The Cairo implementation of the graphics abstraction layer.
static constexpr size_t COLOR_OFFSET
static constexpr size_t COORD_OFFSET
static constexpr size_t VERTEX_SIZE
static constexpr size_t SHADER_OFFSET
static constexpr size_t COLOR_STRIDE
static constexpr size_t SHADER_STRIDE
static constexpr size_t COORD_STRIDE
Class to store instances of VERTEX without caching.
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
Class to handle an item held in a container.