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...
 

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...
 

Detailed Description

Definition at line 147 of file gpu_manager.h.

Constructor & Destructor Documentation

GPU_NONCACHED_MANAGER::GPU_NONCACHED_MANAGER ( VERTEX_CONTAINER aContainer)

Definition at line 219 of file gpu_manager.cpp.

219  :
220  GPU_MANAGER( aContainer )
221 {
222 }
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 225 of file gpu_manager.cpp.

226 {
227  // Nothing has to be prepared
228 }
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 237 of file gpu_manager.cpp.

238 {
239  // This is the default use case, nothing has to be done
240  // The real rendering takes place in the EndDrawing() function
241 }
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 231 of file gpu_manager.cpp.

232 {
233  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
234 }
void GPU_NONCACHED_MANAGER::EndDrawing ( )
overridevirtual

>

Function EndDrawing() Clears the container after drawing routines.

Implements KIGFX::GPU_MANAGER.

Definition at line 244 of file gpu_manager.cpp.

References 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_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.

245 {
246 #ifdef __WXDEBUG__
247  PROF_COUNTER totalRealTime;
248 #endif /* __WXDEBUG__ */
249 
250  if( m_container->GetSize() == 0 )
251  return;
252 
253  VERTEX* vertices = m_container->GetAllVertices();
254  GLfloat* coordinates = (GLfloat*) ( vertices );
255  GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET;
256 
257  // Prepare buffers
258  glEnableClientState( GL_VERTEX_ARRAY );
259  glEnableClientState( GL_COLOR_ARRAY );
260 
261  glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates );
262  glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors );
263 
264  if( m_shader != NULL ) // Use shader if applicable
265  {
266  GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof(GLfloat);
267 
268  m_shader->Use();
269  glEnableVertexAttribArray( m_shaderAttrib );
270  glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE,
271  VERTEX_SIZE, shaders );
272  }
273 
274  glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
275 
276 #ifdef __WXDEBUG__
277  wxLogTrace( "GAL_PROFILE", wxT( "Noncached manager size: %d" ), m_container->GetSize() );
278 #endif /* __WXDEBUG__ */
279 
280  // Deactivate vertex array
281  glDisableClientState( GL_COLOR_ARRAY );
282  glDisableClientState( GL_VERTEX_ARRAY );
283 
284  if( m_shader != NULL )
285  {
286  glDisableVertexAttribArray( m_shaderAttrib );
287  m_shader->Deactivate();
288  }
289 
290 #ifdef __WXDEBUG__
291  totalRealTime.Stop();
292  wxLogTrace( "GAL_PROFILE",
293  wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() );
294 #endif /* __WXDEBUG__ */
295 }
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:62
VERTEX * GetAllVertices() const
Returns pointer to the vertices stored in the container.
Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m}
Definition: vertex_common.h:50
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:95
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:89
static constexpr size_t SHADER_OFFSET
Definition: vertex_common.h:69
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:57
static constexpr size_t COLOR_OFFSET
Definition: vertex_common.h:64
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:92
static constexpr size_t SHADER_STRIDE
Definition: vertex_common.h:71
static VRML_COLOR colors[VRML_COLOR_LAST]
static constexpr size_t COLOR_STRIDE
Definition: vertex_common.h:66
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:95
int GetAttribute(const std::string &aAttributeName) const
Gets an attribute location.
Definition: shader.cpp:160
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:92
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:73

Member Data Documentation

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

Shader handling

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