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)
 
virtual void BeginDrawing () override
 > More...
 
virtual void DrawIndices (unsigned int aOffset, unsigned int aSize) override
 > More...
 
virtual void DrawAll () override
 > More...
 
virtual void EndDrawing () override
 > More...
 
virtual void SetShader (SHADER &aShader)
 Function SetShader() Allows using shaders with the stored data. More...
 
void EnableDepthTest (bool aEnabled)
 Function EnableDepthTest() Enables/disables Z buffer depth test. More...
 

Static Public Member Functions

static GPU_MANAGERMakeManager (VERTEX_CONTAINER *aContainer)
 

Protected Attributes

bool m_isDrawing
 

Drawing status flag.

More...
 
VERTEX_CONTAINERm_container
 

Container that stores vertices data.

More...
 
SHADERm_shader
 

Shader handling

More...
 
int m_shaderAttrib
 

Location of shader attributes (for glVertexAttribPointer)

More...
 
bool m_enableDepthTest
 

true: enable Z test when drawing

More...
 

Detailed Description

Definition at line 156 of file gpu_manager.h.

Constructor & Destructor Documentation

GPU_NONCACHED_MANAGER::GPU_NONCACHED_MANAGER ( VERTEX_CONTAINER aContainer)

Definition at line 224 of file gpu_manager.cpp.

224  :
225  GPU_MANAGER( aContainer )
226 {
227 }
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:51

Member Function Documentation

void GPU_NONCACHED_MANAGER::BeginDrawing ( )
overridevirtual

>

Function BeginDrawing() Prepares the stored data to be drawn.

Implements KIGFX::GPU_MANAGER.

Definition at line 230 of file gpu_manager.cpp.

231 {
232  // Nothing has to be prepared
233 }
void GPU_NONCACHED_MANAGER::DrawAll ( )
overridevirtual

>

Function DrawIndices() Makes the GPU draw all the vertices stored in the container.

Implements KIGFX::GPU_MANAGER.

Definition at line 242 of file gpu_manager.cpp.

243 {
244  // This is the default use case, nothing has to be done
245  // The real rendering takes place in the EndDrawing() function
246 }
void GPU_NONCACHED_MANAGER::DrawIndices ( unsigned int  aOffset,
unsigned int  aSize 
)
overridevirtual

>

Function DrawIndices() Makes 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 236 of file gpu_manager.cpp.

237 {
238  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
239 }
void GPU_MANAGER::EnableDepthTest ( bool  aEnabled)
inherited

Function EnableDepthTest() Enables/disables Z buffer depth test.

Definition at line 309 of file gpu_manager.cpp.

References KIGFX::GPU_MANAGER::m_enableDepthTest.

310 {
311  m_enableDepthTest = aEnabled;
312 }
bool m_enableDepthTest
true: enable Z test when drawing
Definition: gpu_manager.h:104
void GPU_NONCACHED_MANAGER::EndDrawing ( )
overridevirtual

>

Function EndDrawing() Clears the container after drawing routines.

Implements KIGFX::GPU_MANAGER.

Definition at line 249 of file gpu_manager.cpp.

References KIGFX::VERTEX_CONTAINER::Clear(), KIGFX::COLOR_OFFSET, KIGFX::COLOR_STRIDE, colors, 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(), KIGFX::SHADER::Use(), and KIGFX::VERTEX_SIZE.

250 {
251 #ifdef __WXDEBUG__
252  PROF_COUNTER totalRealTime;
253 #endif /* __WXDEBUG__ */
254 
255  if( m_container->GetSize() == 0 )
256  return;
257 
258  VERTEX* vertices = m_container->GetAllVertices();
259  GLfloat* coordinates = (GLfloat*) ( vertices );
260  GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET;
261 
262  if( m_enableDepthTest )
263  glEnable( GL_DEPTH_TEST );
264  else
265  glDisable( GL_DEPTH_TEST );
266 
267  // Prepare buffers
268  glEnableClientState( GL_VERTEX_ARRAY );
269  glEnableClientState( GL_COLOR_ARRAY );
270 
271  glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates );
272  glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors );
273 
274  if( m_shader != NULL ) // Use shader if applicable
275  {
276  GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof(GLfloat);
277 
278  m_shader->Use();
279  glEnableVertexAttribArray( m_shaderAttrib );
280  glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE,
281  VERTEX_SIZE, shaders );
282  }
283 
284  glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
285 
286 #ifdef __WXDEBUG__
287  wxLogTrace( "GAL_PROFILE", wxT( "Noncached manager size: %d" ), m_container->GetSize() );
288 #endif /* __WXDEBUG__ */
289 
290  // Deactivate vertex array
291  glDisableClientState( GL_COLOR_ARRAY );
292  glDisableClientState( GL_VERTEX_ARRAY );
293 
294  if( m_shader != NULL )
295  {
296  glDisableVertexAttribArray( m_shaderAttrib );
297  m_shader->Deactivate();
298  }
299 
300  m_container->Clear();
301 
302 #ifdef __WXDEBUG__
303  totalRealTime.Stop();
304  wxLogTrace( "GAL_PROFILE",
305  wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() );
306 #endif /* __WXDEBUG__ */
307 }
void Stop()
save the time when this function was called, and set the counter stane to stop
Definition: profile.h:82
static constexpr size_t COORD_STRIDE
Definition: vertex_common.h:68
virtual void Clear()=0
Removes all data stored in the container and restores its original state.
VERTEX * GetAllVertices() const
Returns pointer to the vertices stored in the container.
Data structure for vertices {X,Y,Z,R,G,B,A,shader&param}
Definition: vertex_common.h:56
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:101
void Use()
Use the shader.
Definition: shader.h:130
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:45
VERTEX_CONTAINER * m_container
Container that stores vertices data.
Definition: gpu_manager.h:95
static constexpr size_t SHADER_OFFSET
Definition: vertex_common.h:75
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:139
virtual unsigned int GetSize() const
Function GetSize() returns amount of vertices currently stored in the container.
double msecs() const
Definition: profile.h:124
static constexpr size_t VERTEX_SIZE
Definition: vertex_common.h:63
static constexpr size_t COLOR_OFFSET
Definition: vertex_common.h:70
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:98
static constexpr size_t SHADER_STRIDE
Definition: vertex_common.h:77
bool m_enableDepthTest
true: enable Z test when drawing
Definition: gpu_manager.h:104
static VRML_COLOR colors[VRML_COLOR_LAST]
static constexpr size_t COLOR_STRIDE
Definition: vertex_common.h:72
GPU_MANAGER * GPU_MANAGER::MakeManager ( VERTEX_CONTAINER aContainer)
staticinherited

Definition at line 42 of file gpu_manager.cpp.

References KIGFX::VERTEX_CONTAINER::IsCached().

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

43 {
44  if( aContainer->IsCached() )
45  return new GPU_CACHED_MANAGER( aContainer );
46  else
47  return new GPU_NONCACHED_MANAGER( aContainer );
48 }
virtual bool IsCached() const =0
Returns true if the container caches vertex data in RAM or video memory.
void GPU_MANAGER::SetShader ( SHADER aShader)
virtualinherited

Function SetShader() Allows using shaders with the stored data.

Parameters
aShaderis the object that allows using shaders.

Definition at line 62 of file gpu_manager.cpp.

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

63 {
64  m_shader = &aShader;
65  m_shaderAttrib = m_shader->GetAttribute( "attrShaderParams" );
66 
67  if( m_shaderAttrib == -1 )
68  {
69  DisplayError( NULL, wxT( "Could not get the shader attribute location" ) );
70  }
71 }
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:101
int GetAttribute(const std::string &aAttributeName) const
Gets an attribute location.
Definition: shader.cpp:161
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:98
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245

Member Data Documentation

VERTEX_CONTAINER* KIGFX::GPU_MANAGER::m_container
protectedinherited
bool KIGFX::GPU_MANAGER::m_enableDepthTest
protectedinherited

true: enable Z test when drawing

Definition at line 104 of file gpu_manager.h.

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

bool KIGFX::GPU_MANAGER::m_isDrawing
protectedinherited
SHADER* KIGFX::GPU_MANAGER::m_shader
protectedinherited

Shader handling

Definition at line 98 of file gpu_manager.h.

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

int KIGFX::GPU_MANAGER::m_shaderAttrib
protectedinherited

Location of shader attributes (for glVertexAttribPointer)

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