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 (unsigned int aOffset, unsigned int aSize) override
 Make the GPU draw all the vertices stored in the container. More...
 
virtual void DrawAll () 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 153 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 240 of file gpu_manager.cpp.

240  :
241  GPU_MANAGER( aContainer )
242 {
243 }
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Drawing status flag.
Definition: gpu_manager.cpp:54

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 246 of file gpu_manager.cpp.

247 {
248  // Nothing has to be prepared
249 }

◆ DrawAll()

void GPU_NONCACHED_MANAGER::DrawAll ( )
overridevirtual

Clear the container after drawing routines.

Implements KIGFX::GPU_MANAGER.

Definition at line 258 of file gpu_manager.cpp.

259 {
260  // This is the default use case, nothing has to be done
261  // The real rendering takes place in the EndDrawing() function
262 }

◆ DrawIndices()

void GPU_NONCACHED_MANAGER::DrawIndices ( unsigned int  aOffset,
unsigned int  aSize 
)
overridevirtual

Make the GPU draw all the vertices stored in the container.

Implements KIGFX::GPU_MANAGER.

Definition at line 252 of file gpu_manager.cpp.

253 {
254  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
255 }

◆ EnableDepthTest()

void GPU_MANAGER::EnableDepthTest ( bool  aEnabled)
inherited

Enable/disable Z buffer depth test.

Definition at line 325 of file gpu_manager.cpp.

326 {
327  m_enableDepthTest = aEnabled;
328 }

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 265 of file gpu_manager.cpp.

266 {
267 #ifdef KICAD_GAL_PROFILE
268  PROF_COUNTER totalRealTime;
269 #endif /* KICAD_GAL_PROFILE */
270 
271  if( m_container->GetSize() == 0 )
272  return;
273 
274  VERTEX* vertices = m_container->GetAllVertices();
275  GLfloat* coordinates = (GLfloat*) ( vertices );
276  GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET;
277 
278  if( m_enableDepthTest )
279  glEnable( GL_DEPTH_TEST );
280  else
281  glDisable( GL_DEPTH_TEST );
282 
283  // Prepare buffers
284  glEnableClientState( GL_VERTEX_ARRAY );
285  glEnableClientState( GL_COLOR_ARRAY );
286 
287  glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates );
288  glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors );
289 
290  if( m_shader != nullptr ) // Use shader if applicable
291  {
292  GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof( GLfloat );
293 
294  m_shader->Use();
295  glEnableVertexAttribArray( m_shaderAttrib );
296  glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, VERTEX_SIZE,
297  shaders );
298  }
299 
300  glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
301 
302 #ifdef KICAD_GAL_PROFILE
303  wxLogTrace( traceGalProfile, wxT( "Noncached manager size: %d" ), m_container->GetSize() );
304 #endif /* KICAD_GAL_PROFILE */
305 
306  // Deactivate vertex array
307  glDisableClientState( GL_COLOR_ARRAY );
308  glDisableClientState( GL_VERTEX_ARRAY );
309 
310  if( m_shader != nullptr )
311  {
312  glDisableVertexAttribArray( m_shaderAttrib );
313  m_shader->Deactivate();
314  }
315 
316  m_container->Clear();
317 
318 #ifdef KICAD_GAL_PROFILE
319  totalRealTime.Stop();
320  wxLogTrace( traceGalProfile, wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ),
321  totalRealTime.msecs() );
322 #endif /* KICAD_GAL_PROFILE */
323 }
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition: profile.h:85
static constexpr size_t COORD_STRIDE
Definition: vertex_common.h:72
virtual void Clear()=0
Remove all data stored in the container and restores its original state.
double msecs(bool aSinceLast=false)
Definition: profile.h:146
int m_shaderAttrib
true: enable Z test when drawing
Definition: gpu_manager.h:98
void Use()
Use the shader.
Definition: shader.h:126
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
A small class to help profiling.
Definition: profile.h:45
VERTEX_CONTAINER * m_container
Shader handling.
Definition: gpu_manager.h:92
VERTEX * GetAllVertices() const
Return pointer to the vertices stored in the container.
static constexpr size_t SHADER_OFFSET
Definition: vertex_common.h:79
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:135
static constexpr size_t VERTEX_SIZE
Definition: vertex_common.h:67
static constexpr size_t COLOR_OFFSET
Definition: vertex_common.h:74
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:95
static constexpr size_t SHADER_STRIDE
Definition: vertex_common.h:81
virtual unsigned int GetSize() const
Return amount of vertices currently stored in the container.
static constexpr size_t COLOR_STRIDE
Definition: vertex_common.h:76

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, PROF_COUNTER::msecs(), KIGFX::SHADER_OFFSET, KIGFX::SHADER_STRIDE, PROF_COUNTER::Stop(), traceGalProfile, KIGFX::SHADER::Use(), and KIGFX::VERTEX_SIZE.

◆ MakeManager()

GPU_MANAGER * GPU_MANAGER::MakeManager ( VERTEX_CONTAINER aContainer)
staticinherited

Definition at line 45 of file gpu_manager.cpp.

46 {
47  if( aContainer->IsCached() )
48  return new GPU_CACHED_MANAGER( aContainer );
49  else
50  return new GPU_NONCACHED_MANAGER( aContainer );
51 }
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 69 of file gpu_manager.cpp.

70 {
71  m_shader = &aShader;
72  m_shaderAttrib = m_shader->GetAttribute( "attrShaderParams" );
73 
74  if( m_shaderAttrib == -1 )
75  {
76  DisplayError( nullptr, wxT( "Could not get the shader attribute location" ) );
77  }
78 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:271
int GetAttribute(const std::string &aAttributeName) const
Get an attribute location.
Definition: shader.cpp:172
int m_shaderAttrib
true: enable Z test when drawing
Definition: gpu_manager.h:98
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:95

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

◆ m_enableDepthTest

bool KIGFX::GPU_MANAGER::m_enableDepthTest
protectedinherited

◆ m_isDrawing

bool KIGFX::GPU_MANAGER::m_isDrawing
protectedinherited

◆ m_shader

SHADER* KIGFX::GPU_MANAGER::m_shader
protectedinherited

Location of shader attributes (for glVertexAttribPointer)

Definition at line 95 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 98 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: