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 148 of file gpu_manager.h.

Constructor & Destructor Documentation

GPU_NONCACHED_MANAGER::GPU_NONCACHED_MANAGER ( VERTEX_CONTAINER aContainer)

Definition at line 225 of file gpu_manager.cpp.

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

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

232 {
233  // Nothing has to be prepared
234 }
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 243 of file gpu_manager.cpp.

244 {
245  // This is the default use case, nothing has to be done
246  // The real rendering takes place in the EndDrawing() function
247 }
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 237 of file gpu_manager.cpp.

238 {
239  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
240 }
void GPU_NONCACHED_MANAGER::EndDrawing ( )
overridevirtual

>

Function EndDrawing() Clears the container after drawing routines.

Implements KIGFX::GPU_MANAGER.

Definition at line 250 of file gpu_manager.cpp.

References KIGFX::ColorOffset, colors, KIGFX::ColorStride, KIGFX::CoordStride, 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::ShaderOffset, KIGFX::ShaderStride, PROF_COUNTER::Stop(), KIGFX::SHADER::Use(), and KIGFX::VertexSize.

251 {
252 #ifdef __WXDEBUG__
253  PROF_COUNTER totalRealTime;
254 #endif /* __WXDEBUG__ */
255 
256  if( m_container->GetSize() == 0 )
257  return;
258 
259  VERTEX* vertices = m_container->GetAllVertices();
260  GLfloat* coordinates = (GLfloat*) ( vertices );
261  GLubyte* colors = (GLubyte*) ( vertices ) + ColorOffset;
262 
263  // Prepare buffers
264  glEnableClientState( GL_VERTEX_ARRAY );
265  glEnableClientState( GL_COLOR_ARRAY );
266 
267  glVertexPointer( CoordStride, GL_FLOAT, VertexSize, coordinates );
268  glColorPointer( ColorStride, GL_UNSIGNED_BYTE, VertexSize, colors );
269 
270  if( m_shader != NULL ) // Use shader if applicable
271  {
272  GLfloat* shaders = (GLfloat*) ( vertices ) + ShaderOffset / sizeof(GLfloat);
273 
274  m_shader->Use();
275  glEnableVertexAttribArray( m_shaderAttrib );
276  glVertexAttribPointer( m_shaderAttrib, ShaderStride, GL_FLOAT, GL_FALSE,
277  VertexSize, shaders );
278  }
279 
280  glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
281 
282 #ifdef __WXDEBUG__
283  wxLogTrace( "GAL_PROFILE", wxT( "Noncached manager size: %d" ), m_container->GetSize() );
284 #endif /* __WXDEBUG__ */
285 
286  // Deactivate vertex array
287  glDisableClientState( GL_COLOR_ARRAY );
288  glDisableClientState( GL_VERTEX_ARRAY );
289 
290  if( m_shader != NULL )
291  {
292  glDisableVertexAttribArray( m_shaderAttrib );
293  m_shader->Deactivate();
294  }
295 
296 #ifdef __WXDEBUG__
297  totalRealTime.Stop();
298  wxLogTrace( "GAL_PROFILE",
299  wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() );
300 #endif /* __WXDEBUG__ */
301 }
const size_t VertexSize
Definition: vertex_common.h:57
void Stop()
save the time when this function was called, and set the counter stane to stop
Definition: profile.h:82
const size_t CoordStride
Definition: vertex_common.h:61
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:96
void Use()
Use the shader.
Definition: shader.h:130
const size_t ShaderOffset
Definition: vertex_common.h:70
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:90
virtual VERTEX * GetAllVertices() const
Function GetAllVertices() returns all the vertices stored in the container.
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:139
const size_t ShaderStride
Definition: vertex_common.h:72
virtual unsigned int GetSize() const
Function GetSize() returns amount of vertices currently stored in the container.
double msecs() const
Definition: profile.h:121
const size_t ColorStride
Definition: vertex_common.h:67
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:93
const size_t ColorOffset
Definition: vertex_common.h:64
static VRML_COLOR colors[VRML_COLOR_LAST]
GPU_MANAGER * GPU_MANAGER::MakeManager ( VERTEX_CONTAINER aContainer)
staticinherited

Definition at line 46 of file gpu_manager.cpp.

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

47 {
48  if( typeid( *aContainer ) == typeid( CACHED_CONTAINER ) )
49  return new GPU_CACHED_MANAGER( aContainer );
50  else if( typeid( *aContainer ) == typeid( NONCACHED_CONTAINER ) )
51  return new GPU_NONCACHED_MANAGER( aContainer );
52 
53  wxASSERT_MSG( false, wxT( "Not handled container type" ) );
54  return NULL;
55 }
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 69 of file gpu_manager.cpp.

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

70 {
71  m_shader = &aShader;
72  m_shaderAttrib = m_shader->GetAttribute( "attrShaderParams" );
73 
74  if( m_shaderAttrib == -1 )
75  {
76  DisplayError( NULL, wxT( "Could not get the shader attribute location" ) );
77  }
78 }
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:96
int GetAttribute(const std::string &aAttributeName) const
Gets an attribute location.
Definition: shader.cpp:160
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:93
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69

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 93 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 96 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: