KiCad PCB EDA Suite
KIGFX::GPU_NONCACHED_MANAGER Class Reference

#include <gpu_manager.h>

Inheritance diagram for KIGFX::GPU_NONCACHED_MANAGER:
KIGFX::GPU_MANAGER

Public Member Functions

 GPU_NONCACHED_MANAGER (VERTEX_CONTAINER *aContainer)
 Prepare the stored data to be drawn. More...
 
virtual void BeginDrawing () override
 Make the GPU draw given range of vertices. More...
 
virtual void DrawIndices (const VERTEX_ITEM *aItem) override
 Clear the container after drawing routines. More...
 
virtual void EndDrawing () override
 Clear the container after drawing routines. More...
 
virtual void SetShader (SHADER &aShader)
 Allow using shaders with the stored data. More...
 
void EnableDepthTest (bool aEnabled)
 Enable/disable Z buffer depth test. More...
 

Static Public Member Functions

static GPU_MANAGERMakeManager (VERTEX_CONTAINER *aContainer)
 

Protected Attributes

bool m_isDrawing
 Container that stores vertices data. More...
 
VERTEX_CONTAINERm_container
 Shader handling. More...
 
SHADERm_shader
 Location of shader attributes (for glVertexAttribPointer) More...
 
int m_shaderAttrib
 true: enable Z test when drawing More...
 
bool m_enableDepthTest
 

Detailed Description

Definition at line 169 of file gpu_manager.h.

Constructor & Destructor Documentation

◆ GPU_NONCACHED_MANAGER()

GPU_NONCACHED_MANAGER::GPU_NONCACHED_MANAGER ( VERTEX_CONTAINER aContainer)

Prepare the stored data to be drawn.

Definition at line 254 of file gpu_manager.cpp.

254 :
255 GPU_MANAGER( aContainer )
256{
257}
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Drawing status flag.
Definition: gpu_manager.cpp:57

Member Function Documentation

◆ BeginDrawing()

void GPU_NONCACHED_MANAGER::BeginDrawing ( )
overridevirtual

Make the GPU draw given range of vertices.

Parameters
aOffsetis the beginning of the range.
aSizeis the number of vertices to be drawn.

Implements KIGFX::GPU_MANAGER.

Definition at line 260 of file gpu_manager.cpp.

261{
262 // Nothing has to be prepared
263}

◆ DrawIndices()

void GPU_NONCACHED_MANAGER::DrawIndices ( const VERTEX_ITEM aItem)
overridevirtual

Clear the container after drawing routines.

Implements KIGFX::GPU_MANAGER.

Definition at line 266 of file gpu_manager.cpp.

267{
268 wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
269}

◆ EnableDepthTest()

void GPU_MANAGER::EnableDepthTest ( bool  aEnabled)
inherited

Enable/disable Z buffer depth test.

Definition at line 332 of file gpu_manager.cpp.

333{
334 m_enableDepthTest = aEnabled;
335}

References KIGFX::GPU_MANAGER::m_enableDepthTest.

◆ EndDrawing()

void GPU_NONCACHED_MANAGER::EndDrawing ( )
overridevirtual

Clear the container after drawing routines.

Implements KIGFX::GPU_MANAGER.

Definition at line 272 of file gpu_manager.cpp.

273{
274#ifdef KICAD_GAL_PROFILE
275 PROF_COUNTER totalRealTime;
276#endif /* KICAD_GAL_PROFILE */
277
278 if( m_container->GetSize() == 0 )
279 return;
280
281 VERTEX* vertices = m_container->GetAllVertices();
282 GLfloat* coordinates = (GLfloat*) ( vertices );
283 GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET;
284
286 glEnable( GL_DEPTH_TEST );
287 else
288 glDisable( GL_DEPTH_TEST );
289
290 // Prepare buffers
291 glEnableClientState( GL_VERTEX_ARRAY );
292 glEnableClientState( GL_COLOR_ARRAY );
293
294 glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates );
295 glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors );
296
297 if( m_shader != nullptr ) // Use shader if applicable
298 {
299 GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof( GLfloat );
300
301 m_shader->Use();
302 glEnableVertexAttribArray( m_shaderAttrib );
303 glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, VERTEX_SIZE,
304 shaders );
305 }
306
307 glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
308
309#ifdef KICAD_GAL_PROFILE
310 wxLogTrace( traceGalProfile, wxT( "Noncached manager size: %d" ), m_container->GetSize() );
311#endif /* KICAD_GAL_PROFILE */
312
313 // Deactivate vertex array
314 glDisableClientState( GL_COLOR_ARRAY );
315 glDisableClientState( GL_VERTEX_ARRAY );
316
317 if( m_shader != nullptr )
318 {
319 glDisableVertexAttribArray( m_shaderAttrib );
321 }
322
324
325#ifdef KICAD_GAL_PROFILE
326 totalRealTime.Stop();
327 wxLogTrace( traceGalProfile, wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ),
328 totalRealTime.msecs() );
329#endif /* KICAD_GAL_PROFILE */
330}
int m_shaderAttrib
true: enable Z test when drawing
Definition: gpu_manager.h:95
VERTEX_CONTAINER * m_container
Shader handling.
Definition: gpu_manager.h:89
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:92
void Use()
Use the shader.
Definition: shader.h:126
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:135
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.
A thread-safe event counter.
Definition: profile.h:226
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
static constexpr size_t COLOR_OFFSET
Definition: vertex_common.h:74
static constexpr size_t VERTEX_SIZE
Definition: vertex_common.h:67
static constexpr size_t SHADER_OFFSET
Definition: vertex_common.h:79
static constexpr size_t COLOR_STRIDE
Definition: vertex_common.h:76
static constexpr size_t SHADER_STRIDE
Definition: vertex_common.h:81
static constexpr size_t COORD_STRIDE
Definition: vertex_common.h:72

References KIGFX::VERTEX_CONTAINER::Clear(), KIGFX::COLOR_OFFSET, KIGFX::COLOR_STRIDE, KIGFX::COORD_STRIDE, KIGFX::SHADER::Deactivate(), KIGFX::VERTEX_CONTAINER::GetAllVertices(), KIGFX::VERTEX_CONTAINER::GetSize(), KIGFX::GPU_MANAGER::m_container, KIGFX::GPU_MANAGER::m_enableDepthTest, KIGFX::GPU_MANAGER::m_shader, KIGFX::GPU_MANAGER::m_shaderAttrib, KIGFX::SHADER_OFFSET, KIGFX::SHADER_STRIDE, traceGalProfile, KIGFX::SHADER::Use(), and KIGFX::VERTEX_SIZE.

◆ MakeManager()

GPU_MANAGER * GPU_MANAGER::MakeManager ( VERTEX_CONTAINER aContainer)
staticinherited

Definition at line 48 of file gpu_manager.cpp.

49{
50 if( aContainer->IsCached() )
51 return new GPU_CACHED_MANAGER( aContainer );
52 else
53 return new GPU_NONCACHED_MANAGER( aContainer );
54}
virtual bool IsCached() const =0
Return true if the container caches vertex data in RAM or video memory.

References KIGFX::VERTEX_CONTAINER::IsCached().

Referenced by KIGFX::VERTEX_MANAGER::VERTEX_MANAGER().

◆ SetShader()

void GPU_MANAGER::SetShader ( SHADER aShader)
virtualinherited

Allow using shaders with the stored data.

Parameters
aShaderis the object that allows using shaders.

Definition at line 72 of file gpu_manager.cpp.

73{
74 m_shader = &aShader;
75 m_shaderAttrib = m_shader->GetAttribute( "a_shaderParams" );
76
77 if( m_shaderAttrib == -1 )
78 {
79 DisplayError( nullptr, wxT( "Could not get the shader attribute location" ) );
80 }
81}
int GetAttribute(const std::string &aAttributeName) const
Get an attribute location.
Definition: shader.cpp:172
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280

References DisplayError(), KIGFX::SHADER::GetAttribute(), KIGFX::GPU_MANAGER::m_shader, and KIGFX::GPU_MANAGER::m_shaderAttrib.

Member Data Documentation

◆ m_container

VERTEX_CONTAINER* KIGFX::GPU_MANAGER::m_container
protectedinherited

Shader handling.

Definition at line 89 of file gpu_manager.h.

Referenced by KIGFX::GPU_CACHED_MANAGER::EndDrawing(), and EndDrawing().

◆ m_enableDepthTest

bool KIGFX::GPU_MANAGER::m_enableDepthTest
protectedinherited

◆ m_isDrawing

bool KIGFX::GPU_MANAGER::m_isDrawing
protectedinherited

Container that stores vertices data.

Definition at line 86 of file gpu_manager.h.

Referenced by KIGFX::GPU_CACHED_MANAGER::BeginDrawing(), KIGFX::GPU_CACHED_MANAGER::DrawIndices(), and KIGFX::GPU_CACHED_MANAGER::EndDrawing().

◆ m_shader

SHADER* KIGFX::GPU_MANAGER::m_shader
protectedinherited

Location of shader attributes (for glVertexAttribPointer)

Definition at line 92 of file gpu_manager.h.

Referenced by KIGFX::GPU_CACHED_MANAGER::EndDrawing(), EndDrawing(), and KIGFX::GPU_MANAGER::SetShader().

◆ m_shaderAttrib

int KIGFX::GPU_MANAGER::m_shaderAttrib
protectedinherited

true: enable Z test when drawing

Definition at line 95 of file gpu_manager.h.

Referenced by KIGFX::GPU_CACHED_MANAGER::EndDrawing(), EndDrawing(), and KIGFX::GPU_MANAGER::SetShader().


The documentation for this class was generated from the following files: