KiCad PCB EDA Suite
KIGFX::VERTEX_MANAGER Class Reference

#include <vertex_manager.h>

Public Member Functions

 VERTEX_MANAGER (bool aCached)
 Constructor. More...
 
void Map ()
 Function Map() maps vertex buffer. More...
 
void Unmap ()
 Function Unmap() unmaps vertex buffer. More...
 
bool Reserve (unsigned int aSize)
 Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls. More...
 
bool Vertex (const VERTEX &aVertex)
 Function Vertex() adds a vertex with the given coordinates to the currently set item. More...
 
bool Vertex (GLfloat aX, GLfloat aY, GLfloat aZ)
 Function Vertex() adds a vertex with the given coordinates to the currently set item. More...
 
bool Vertices (const VERTEX aVertices[], unsigned int aSize)
 Function Vertices() adds one or more vertices to the currently set item. More...
 
void Color (const COLOR4D &aColor)
 Function Color() changes currently used color that will be applied to newly added vertices. More...
 
void Color (GLfloat aRed, GLfloat aGreen, GLfloat aBlue, GLfloat aAlpha)
 Function Color() changes currently used color that will be applied to newly added vertices. More...
 
void Shader (GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
 Function Shader() changes currently used shader and its parameters that will be applied to newly added vertices. More...
 
void Translate (GLfloat aX, GLfloat aY, GLfloat aZ)
 Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be translated by the given vector. More...
 
void Rotate (GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
 Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be rotated by the given angles. More...
 
void Scale (GLfloat aX, GLfloat aY, GLfloat aZ)
 Function Scale() multiplies the current matrix by a scaling matrix, so the newly vertices will be scaled by the given factors. More...
 
void PushMatrix ()
 Function PushMatrix() pushes the current transformation matrix stack. More...
 
void PopMatrix ()
 Function PopMatrix() pops the current transformation matrix stack. More...
 
void SetItem (VERTEX_ITEM &aItem) const
 Function SetItem() sets an item to start its modifications. More...
 
void FinishItem () const
 Function FinishItem() does the cleaning after adding an item. More...
 
void FreeItem (VERTEX_ITEM &aItem) const
 Function FreeItem() frees the memory occupied by the item, so it is no longer stored in the container. More...
 
void ChangeItemColor (const VERTEX_ITEM &aItem, const COLOR4D &aColor) const
 Function ChangeItemColor() changes the color of all vertices owned by an item. More...
 
void ChangeItemDepth (const VERTEX_ITEM &aItem, GLfloat aDepth) const
 Function ChangeItemDepth() changes the depth of all vertices owned by an item. More...
 
VERTEXGetVertices (const VERTEX_ITEM &aItem) const
 Function GetVertices() returns a pointer to the vertices owned by an item. More...
 
const glm::mat4 & GetTransformation () const
 
void SetShader (SHADER &aShader) const
 Function SetShader() sets a shader program that is going to be used during rendering. More...
 
void Clear () const
 Function Clear() removes all the stored vertices from the container. More...
 
void BeginDrawing () const
 Function BeginDrawing() prepares buffers and items to start drawing. More...
 
void DrawItem (const VERTEX_ITEM &aItem) const
 Function DrawItem() draws an item to the buffer. More...
 
void EndDrawing () const
 Function EndDrawing() finishes drawing operations. More...
 

Protected Member Functions

void putVertex (VERTEX &aTarget, GLfloat aX, GLfloat aY, GLfloat aZ) const
 Function putVertex() applies all transformation to the given coordinates and store them at the specified target. More...
 

Protected Attributes

std::shared_ptr< VERTEX_CONTAINERm_container
 Container for vertices, may be cached or noncached. More...
 
std::shared_ptr< GPU_MANAGERm_gpu
 GPU manager for data transfers and drawing operations. More...
 
bool m_noTransform
 State machine variables True in case there is no need to transform vertices. More...
 
glm::mat4 m_transform
 Currently used transform matrix. More...
 
std::stack< glm::mat4 > m_transformStack
 Stack of transformation matrices, used for Push/PopMatrix. More...
 
GLubyte m_color [ColorStride]
 Currently used color. More...
 
GLfloat m_shader [ShaderStride]
 Currently used shader and its parameters. More...
 
VERTEXm_reserved
 Currently reserved chunk to store vertices. More...
 
unsigned int m_reservedSpace
 Currently available reserved space. More...
 

Detailed Description

Definition at line 50 of file vertex_manager.h.

Constructor & Destructor Documentation

VERTEX_MANAGER::VERTEX_MANAGER ( bool  aCached)

Constructor.

Parameters
aCachedsays if vertices should be cached in GPU or system memory. For data that does not change every frame, it is better to store vertices in GPU memory.

Definition at line 40 of file vertex_manager.cpp.

References m_container, m_gpu, m_shader, KIGFX::VERTEX_CONTAINER::MakeContainer(), KIGFX::GPU_MANAGER::MakeManager(), and KIGFX::ShaderStride.

40  :
41  m_noTransform( true ), m_transform( 1.0f ), m_reserved( NULL ), m_reservedSpace( 0 )
42 {
43  m_container.reset( VERTEX_CONTAINER::MakeContainer( aCached ) );
44  m_gpu.reset( GPU_MANAGER::MakeManager( m_container.get() ) );
45 
46  // There is no shader used by default
47  for( unsigned int i = 0; i < ShaderStride; ++i )
48  m_shader[i] = 0.0f;
49 }
static VERTEX_CONTAINER * MakeContainer(bool aCached)
Function MakeContainer() Returns a pointer to a new container of an appropriate type.
GLfloat m_shader[ShaderStride]
Currently used shader and its parameters.
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
bool m_noTransform
State machine variables True in case there is no need to transform vertices.
glm::mat4 m_transform
Currently used transform matrix.
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:46
const size_t ShaderStride
Definition: vertex_common.h:72
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.
VERTEX * m_reserved
Currently reserved chunk to store vertices.
unsigned int m_reservedSpace
Currently available reserved space.

Member Function Documentation

void VERTEX_MANAGER::BeginDrawing ( ) const

Function BeginDrawing() prepares buffers and items to start drawing.

Definition at line 233 of file vertex_manager.cpp.

References m_gpu.

Referenced by KIGFX::OPENGL_GAL::BeginDrawing().

234 {
235  m_gpu->BeginDrawing();
236 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.
void VERTEX_MANAGER::ChangeItemColor ( const VERTEX_ITEM aItem,
const COLOR4D aColor 
) const

Function ChangeItemColor() changes the color of all vertices owned by an item.

Parameters
aItemis the item to change.
aColoris the new color to be applied.

Definition at line 175 of file vertex_manager.cpp.

References KIGFX::VERTEX::a, KIGFX::COLOR4D::a, KIGFX::VERTEX::b, KIGFX::COLOR4D::b, KIGFX::VERTEX::g, KIGFX::COLOR4D::g, KIGFX::VERTEX_ITEM::GetOffset(), KIGFX::VERTEX_ITEM::GetSize(), m_container, KIGFX::VERTEX::r, and KIGFX::COLOR4D::r.

Referenced by KIGFX::OPENGL_GAL::ChangeGroupColor().

176 {
177  unsigned int size = aItem.GetSize();
178  unsigned int offset = aItem.GetOffset();
179 
180  VERTEX* vertex = m_container->GetVertices( offset );
181 
182  for( unsigned int i = 0; i < size; ++i )
183  {
184  vertex->r = aColor.r * 255.0;
185  vertex->g = aColor.g * 255.0;
186  vertex->b = aColor.b * 255.0;
187  vertex->a = aColor.a * 255.0;
188  vertex++;
189  }
190 
191  m_container->SetDirty();
192 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
double g
Green component.
Definition: color4d.h:287
double b
Blue component.
Definition: color4d.h:288
double a
Alpha component.
Definition: color4d.h:289
unsigned int GetOffset() const
Function GetOffset() Returns data offset in the container.
Definition: vertex_item.h:65
unsigned int GetSize() const
Function GetSize() Returns information about number of vertices stored.
Definition: vertex_item.h:55
double r
Red component.
Definition: color4d.h:286
void VERTEX_MANAGER::ChangeItemDepth ( const VERTEX_ITEM aItem,
GLfloat  aDepth 
) const

Function ChangeItemDepth() changes the depth of all vertices owned by an item.

Parameters
aItemis the item to change.
aDepthis the new color to be applied.

Definition at line 195 of file vertex_manager.cpp.

References KIGFX::VERTEX_ITEM::GetOffset(), KIGFX::VERTEX_ITEM::GetSize(), m_container, and KIGFX::VERTEX::z.

Referenced by KIGFX::OPENGL_GAL::ChangeGroupDepth().

196 {
197  unsigned int size = aItem.GetSize();
198  unsigned int offset = aItem.GetOffset();
199 
200  VERTEX* vertex = m_container->GetVertices( offset );
201 
202  for( unsigned int i = 0; i < size; ++i )
203  {
204  vertex->z = aDepth;
205  vertex++;
206  }
207 
208  m_container->SetDirty();
209 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
unsigned int GetOffset() const
Function GetOffset() Returns data offset in the container.
Definition: vertex_item.h:65
unsigned int GetSize() const
Function GetSize() Returns information about number of vertices stored.
Definition: vertex_item.h:55
void VERTEX_MANAGER::Clear ( ) const

Function Clear() removes all the stored vertices from the container.

Definition at line 227 of file vertex_manager.cpp.

References m_container.

Referenced by KIGFX::OPENGL_GAL::BeginDrawing(), and KIGFX::OPENGL_GAL::ClearCache().

228 {
229  m_container->Clear();
230 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
void KIGFX::VERTEX_MANAGER::Color ( const COLOR4D aColor)
inline

Function Color() changes currently used color that will be applied to newly added vertices.

Parameters
aColoris the new color.

Definition at line 129 of file vertex_manager.h.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::COLOR4D::g, m_color, and KIGFX::COLOR4D::r.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::OPENGL_GAL::DrawArc(), KIGFX::OPENGL_GAL::DrawArcSegment(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::DrawLine(), KIGFX::OPENGL_GAL::drawPolygon(), KIGFX::OPENGL_GAL::drawPolyline(), KIGFX::OPENGL_GAL::DrawRectangle(), KIGFX::OPENGL_GAL::DrawSegment(), and KIGFX::OPENGL_GAL::drawSemiCircle().

130  {
131  m_color[0] = aColor.r * 255.0;
132  m_color[1] = aColor.g * 255.0;
133  m_color[2] = aColor.b * 255.0;
134  m_color[3] = aColor.a * 255.0;
135  }
GLubyte m_color[ColorStride]
Currently used color.
void KIGFX::VERTEX_MANAGER::Color ( GLfloat  aRed,
GLfloat  aGreen,
GLfloat  aBlue,
GLfloat  aAlpha 
)
inline

Function Color() changes currently used color that will be applied to newly added vertices.

It is the equivalent of glColor4f() function.

Parameters
aRedis the red component of the new color.
aGreenis the green component of the new color.
aBlueis the blue component of the new color.
aAlphais the alpha component of the new color.

Definition at line 146 of file vertex_manager.h.

References m_color.

147  {
148  m_color[0] = aRed * 255.0;
149  m_color[1] = aGreen * 255.0;
150  m_color[2] = aBlue * 255.0;
151  m_color[3] = aAlpha * 255.0;
152  }
GLubyte m_color[ColorStride]
Currently used color.
void VERTEX_MANAGER::DrawItem ( const VERTEX_ITEM aItem) const

Function DrawItem() draws an item to the buffer.

Parameters
aItemis the item to be drawn.

Definition at line 239 of file vertex_manager.cpp.

References KIGFX::VERTEX_ITEM::GetOffset(), KIGFX::VERTEX_ITEM::GetSize(), and m_gpu.

Referenced by KIGFX::OPENGL_GAL::DrawGroup().

240 {
241  int size = aItem.GetSize();
242  int offset = aItem.GetOffset();
243 
244  m_gpu->DrawIndices( offset, size );
245 }
unsigned int GetOffset() const
Function GetOffset() Returns data offset in the container.
Definition: vertex_item.h:65
unsigned int GetSize() const
Function GetSize() Returns information about number of vertices stored.
Definition: vertex_item.h:55
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.
void VERTEX_MANAGER::EndDrawing ( ) const

Function EndDrawing() finishes drawing operations.

Definition at line 248 of file vertex_manager.cpp.

References m_gpu.

Referenced by KIGFX::OPENGL_GAL::EndDrawing().

249 {
250  m_gpu->EndDrawing();
251 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.
void VERTEX_MANAGER::FinishItem ( ) const

Function FinishItem() does the cleaning after adding an item.

Definition at line 163 of file vertex_manager.cpp.

References m_container.

Referenced by KIGFX::OPENGL_GAL::EndGroup().

164 {
165  m_container->FinishItem();
166 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
void VERTEX_MANAGER::FreeItem ( VERTEX_ITEM aItem) const

Function FreeItem() frees the memory occupied by the item, so it is no longer stored in the container.

Parameters
aItemis the item to be freed

Definition at line 169 of file vertex_manager.cpp.

References m_container.

Referenced by KIGFX::VERTEX_ITEM::~VERTEX_ITEM().

170 {
171  m_container->Delete( &aItem );
172 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
const glm::mat4& KIGFX::VERTEX_MANAGER::GetTransformation ( ) const
inline

Definition at line 300 of file vertex_manager.h.

References m_transform.

Referenced by KIGFX::OPENGL_GAL::drawLineQuad().

301  {
302  return m_transform;
303  }
glm::mat4 m_transform
Currently used transform matrix.
VERTEX * VERTEX_MANAGER::GetVertices ( const VERTEX_ITEM aItem) const

Function GetVertices() returns a pointer to the vertices owned by an item.

Parameters
aItemis the owner of vertices that are going to be returned.
Returns
Pointer to the vertices or NULL if the item is not stored at the container.

Definition at line 212 of file vertex_manager.cpp.

References KIGFX::VERTEX_ITEM::GetOffset(), KIGFX::VERTEX_ITEM::GetSize(), and m_container.

Referenced by KIGFX::VERTEX_ITEM::GetVertices().

213 {
214  if( aItem.GetSize() == 0 )
215  return NULL; // The item is not stored in the container
216 
217  return m_container->GetVertices( aItem.GetOffset() );
218 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
unsigned int GetOffset() const
Function GetOffset() Returns data offset in the container.
Definition: vertex_item.h:65
unsigned int GetSize() const
Function GetSize() Returns information about number of vertices stored.
Definition: vertex_item.h:55
void VERTEX_MANAGER::Map ( )

Function Map() maps vertex buffer.

Definition at line 52 of file vertex_manager.cpp.

References m_container.

Referenced by KIGFX::OPENGL_GAL::BeginUpdate().

53 {
54  m_container->Map();
55 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
void KIGFX::VERTEX_MANAGER::PopMatrix ( )
inline

Function PopMatrix() pops the current transformation matrix stack.

It is the equivalent of the glPopMatrix() function.

Definition at line 236 of file vertex_manager.h.

References m_noTransform, m_transform, and m_transformStack.

Referenced by KIGFX::OPENGL_GAL::Restore().

237  {
238  wxASSERT( !m_transformStack.empty() );
239 
241  m_transformStack.pop();
242 
243  if( m_transformStack.empty() )
244  {
245  // We return back to the identity matrix, thus no vertex transformation is needed
246  m_noTransform = true;
247  }
248  }
bool m_noTransform
State machine variables True in case there is no need to transform vertices.
glm::mat4 m_transform
Currently used transform matrix.
std::stack< glm::mat4 > m_transformStack
Stack of transformation matrices, used for Push/PopMatrix.
void KIGFX::VERTEX_MANAGER::PushMatrix ( )
inline

Function PushMatrix() pushes the current transformation matrix stack.

It is the equivalent of the glPushMatrix() function.

Definition at line 223 of file vertex_manager.h.

References m_noTransform, m_transform, and m_transformStack.

Referenced by KIGFX::OPENGL_GAL::Save().

224  {
226 
227  // Every transformation starts with PushMatrix
228  m_noTransform = false;
229  }
bool m_noTransform
State machine variables True in case there is no need to transform vertices.
glm::mat4 m_transform
Currently used transform matrix.
std::stack< glm::mat4 > m_transformStack
Stack of transformation matrices, used for Push/PopMatrix.
void VERTEX_MANAGER::putVertex ( VERTEX aTarget,
GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
) const
protected

Function putVertex() applies all transformation to the given coordinates and store them at the specified target.

Parameters
aTargetis the place where the new vertex is going to be stored (it has to be allocated first).
aXis the X coordinate of the new vertex.
aYis the Y coordinate of the new vertex.
aZis the Z coordinate of the new vertex.

Definition at line 254 of file vertex_manager.cpp.

References KIGFX::VERTEX::a, KIGFX::VERTEX::b, KIGFX::VERTEX::g, m_color, m_noTransform, m_shader, m_transform, KIGFX::VERTEX::r, KIGFX::VERTEX::shader, KIGFX::ShaderStride, KIGFX::VERTEX::x, KIGFX::VERTEX::y, and KIGFX::VERTEX::z.

Referenced by Vertex(), and Vertices().

255 {
256  // Modify the vertex according to the currently used transformations
257  if( m_noTransform )
258  {
259  // Simply copy coordinates, when the transform matrix is the identity matrix
260  aTarget.x = aX;
261  aTarget.y = aY;
262  aTarget.z = aZ;
263  }
264  else
265  {
266  // Apply transformations
267  glm::vec4 transVertex( aX, aY, aZ, 1.0f );
268  transVertex = m_transform * transVertex;
269 
270  aTarget.x = transVertex.x;
271  aTarget.y = transVertex.y;
272  aTarget.z = transVertex.z;
273  }
274 
275  // Apply currently used color
276  aTarget.r = m_color[0];
277  aTarget.g = m_color[1];
278  aTarget.b = m_color[2];
279  aTarget.a = m_color[3];
280 
281  // Apply currently used shader
282  for( unsigned int j = 0; j < ShaderStride; ++j )
283  {
284  aTarget.shader[j] = m_shader[j];
285  }
286 }
GLfloat m_shader[ShaderStride]
Currently used shader and its parameters.
GLfloat shader[4]
Definition: vertex_common.h:53
bool m_noTransform
State machine variables True in case there is no need to transform vertices.
glm::mat4 m_transform
Currently used transform matrix.
GLubyte m_color[ColorStride]
Currently used color.
const size_t ShaderStride
Definition: vertex_common.h:72
bool VERTEX_MANAGER::Reserve ( unsigned int  aSize)

Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.

Parameters
aSizeis the number of vertices that should be available in the reserved space.
Returns
True if successful, false otherwise.

Definition at line 64 of file vertex_manager.cpp.

References DisplayError(), m_container, m_reserved, and m_reservedSpace.

Referenced by KIGFX::OPENGL_GAL::DrawArc(), KIGFX::OPENGL_GAL::drawBitmapChar(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::drawFilledSemiCircle(), KIGFX::OPENGL_GAL::drawLineQuad(), KIGFX::OPENGL_GAL::DrawRectangle(), and KIGFX::OPENGL_GAL::drawStrokedSemiCircle().

65 {
66  assert( m_reservedSpace == 0 && m_reserved == NULL );
67 
68  // flag to avoid hanging by calling DisplayError too many times:
69  static bool show_err = true;
70 
71  m_reserved = m_container->Allocate( aSize );
72 
73  if( m_reserved == NULL )
74  {
75  if( show_err )
76  {
77  DisplayError( NULL, wxT( "VERTEX_MANAGER::Reserve: Vertex allocation error" ) );
78  show_err = false;
79  }
80 
81  return false;
82  }
83 
84  m_reservedSpace = aSize;
85 
86  return true;
87 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
VERTEX * m_reserved
Currently reserved chunk to store vertices.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
unsigned int m_reservedSpace
Currently available reserved space.
void KIGFX::VERTEX_MANAGER::Rotate ( GLfloat  aAngle,
GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)
inline

Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be rotated by the given angles.

It is the equivalent of the glRotatef() function.

Parameters
aAngleis the angle of rotation, in radians.
aXis a multiplier for the X axis
aYis a multiplier for the Y axis
aZis a multiplier for the Z axis.

Definition at line 199 of file vertex_manager.h.

References m_transform.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::OPENGL_GAL::drawFilledSemiCircle(), KIGFX::OPENGL_GAL::DrawSegment(), KIGFX::OPENGL_GAL::drawStrokedSemiCircle(), and KIGFX::OPENGL_GAL::Rotate().

200  {
201  m_transform = glm::rotate( m_transform, aAngle, glm::vec3( aX, aY, aZ ) );
202  }
glm::mat4 m_transform
Currently used transform matrix.
void KIGFX::VERTEX_MANAGER::Scale ( GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)
inline

Function Scale() multiplies the current matrix by a scaling matrix, so the newly vertices will be scaled by the given factors.

It is the equivalent of the glScalef() function.

Parameters
aXis the X axis scaling factor.
aYis the Y axis scaling factor.
aZis the Z axis scaling factor.

Definition at line 213 of file vertex_manager.h.

References m_transform, and scale.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), and KIGFX::OPENGL_GAL::Scale().

214  {
215  m_transform = glm::scale( m_transform, glm::vec3( aX, aY, aZ ) );
216  }
glm::mat4 m_transform
Currently used transform matrix.
const int scale
void VERTEX_MANAGER::SetItem ( VERTEX_ITEM aItem) const

Function SetItem() sets an item to start its modifications.

After calling the function it is possible to add vertices using function Add().

Parameters
aItemis the item that is going to store vertices in the container.

Definition at line 157 of file vertex_manager.cpp.

References m_container.

Referenced by KIGFX::VERTEX_ITEM::VERTEX_ITEM().

158 {
159  m_container->SetItem( &aItem );
160 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
void VERTEX_MANAGER::SetShader ( SHADER aShader) const

Function SetShader() sets a shader program that is going to be used during rendering.

Parameters
aShaderis the object containing compiled and linked shader program.

Definition at line 221 of file vertex_manager.cpp.

References m_gpu.

Referenced by KIGFX::OPENGL_GAL::init().

222 {
223  m_gpu->SetShader( aShader );
224 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.
void KIGFX::VERTEX_MANAGER::Shader ( GLfloat  aShaderType,
GLfloat  aParam1 = 0.0f,
GLfloat  aParam2 = 0.0f,
GLfloat  aParam3 = 0.0f 
)
inline

Function Shader() changes currently used shader and its parameters that will be applied to newly added vertices.

Parameters depend on shader, for more information have a look at shaders source code.

See also
SHADER_TYPE
Parameters
aShaderTypeis the a shader type to be applied.
aParam1is the optional parameter for a shader.
aParam2is the optional parameter for a shader.
aParam3is the optional parameter for a shader.

Definition at line 166 of file vertex_manager.h.

References m_shader.

Referenced by KIGFX::OPENGL_GAL::DrawArc(), KIGFX::OPENGL_GAL::drawBitmapChar(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::drawFilledSemiCircle(), KIGFX::OPENGL_GAL::drawLineQuad(), KIGFX::OPENGL_GAL::drawPolygon(), KIGFX::OPENGL_GAL::DrawRectangle(), and KIGFX::OPENGL_GAL::drawStrokedSemiCircle().

168  {
169  m_shader[0] = aShaderType;
170  m_shader[1] = aParam1;
171  m_shader[2] = aParam2;
172  m_shader[3] = aParam3;
173  }
GLfloat m_shader[ShaderStride]
Currently used shader and its parameters.
void KIGFX::VERTEX_MANAGER::Translate ( GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)
inline

Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be translated by the given vector.

It is the equivalent of the glTranslatef() function.

Parameters
aXis the X coordinate of a translation vector.
aYis the X coordinate of a translation vector.
aZis the X coordinate of a translation vector.

Definition at line 184 of file vertex_manager.h.

References m_transform.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::OPENGL_GAL::DrawArc(), KIGFX::OPENGL_GAL::DrawArcSegment(), KIGFX::OPENGL_GAL::drawFilledSemiCircle(), KIGFX::OPENGL_GAL::DrawSegment(), KIGFX::OPENGL_GAL::drawStrokedSemiCircle(), and KIGFX::OPENGL_GAL::Translate().

185  {
186  m_transform = glm::translate( m_transform, glm::vec3( aX, aY, aZ ) );
187  }
glm::mat4 m_transform
Currently used transform matrix.
void VERTEX_MANAGER::Unmap ( )

Function Unmap() unmaps vertex buffer.

Definition at line 58 of file vertex_manager.cpp.

References m_container.

Referenced by KIGFX::OPENGL_GAL::EndUpdate().

59 {
60  m_container->Unmap();
61 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
bool KIGFX::VERTEX_MANAGER::Vertex ( const VERTEX aVertex)
inline

Function Vertex() adds a vertex with the given coordinates to the currently set item.

Color & shader parameters stored in aVertex are ignored, instead color & shader set by Color() and Shader() functions are used. Vertex coordinates will have the current transformation matrix applied.

Parameters
aVertexcontains vertex coordinates.
Returns
True if successful, false otherwise.

Definition at line 92 of file vertex_manager.h.

References KIGFX::VERTEX::x, KIGFX::VERTEX::y, and KIGFX::VERTEX::z.

Referenced by KIGFX::OPENGL_GAL::DrawArc(), KIGFX::OPENGL_GAL::drawBitmapChar(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::drawFilledSemiCircle(), KIGFX::OPENGL_GAL::drawLineQuad(), KIGFX::OPENGL_GAL::DrawRectangle(), KIGFX::OPENGL_GAL::drawStrokedSemiCircle(), and VertexCallback().

93  {
94  return Vertex( aVertex.x, aVertex.y, aVertex.z );
95  }
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
bool VERTEX_MANAGER::Vertex ( GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)

Function Vertex() adds a vertex with the given coordinates to the currently set item.

Vertex coordinates will have the current transformation matrix applied.

Parameters
aXis the X coordinate of the new vertex.
aYis the Y coordinate of the new vertex.
aZis the Z coordinate of the new vertex.
Returns
True if successful, false otherwise.

Definition at line 90 of file vertex_manager.cpp.

References DisplayError(), m_container, m_reserved, m_reservedSpace, and putVertex().

91 {
92  // flag to avoid hanging by calling DisplayError too many times:
93  static bool show_err = true;
94 
95  // Obtain the pointer to the vertex in the currently used container
96  VERTEX* newVertex;
97 
98  if( m_reservedSpace > 0 )
99  {
100  newVertex = m_reserved++;
101  --m_reservedSpace;
102 
103  if( m_reservedSpace == 0 )
104  m_reserved = NULL;
105  }
106  else
107  {
108  newVertex = m_container->Allocate( 1 );
109  }
110 
111  if( newVertex == NULL )
112  {
113  if( show_err )
114  {
115  DisplayError( NULL, wxT( "VERTEX_MANAGER::Vertex: Vertex allocation error" ) );
116  show_err = false;
117  }
118 
119  return false;
120  }
121 
122  putVertex( *newVertex, aX, aY, aZ );
123 
124  return true;
125 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
void putVertex(VERTEX &aTarget, GLfloat aX, GLfloat aY, GLfloat aZ) const
Function putVertex() applies all transformation to the given coordinates and store them at the specif...
VERTEX * m_reserved
Currently reserved chunk to store vertices.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
unsigned int m_reservedSpace
Currently available reserved space.
bool VERTEX_MANAGER::Vertices ( const VERTEX  aVertices[],
unsigned int  aSize 
)

Function Vertices() adds one or more vertices to the currently set item.

It takes advantage of allocating memory in advance, so should be faster than adding vertices one by one. Color & shader parameters stored in aVertices are ignored, instead color & shader set by Color() and Shader() functions are used. All the vertex coordinates will have the current transformation matrix applied.

Parameters
aVerticescontains vertices to be added
aSizeis the number of vertices to be added.
Returns
True if successful, false otherwise.

Definition at line 128 of file vertex_manager.cpp.

References DisplayError(), m_container, and putVertex().

129 {
130  // flag to avoid hanging by calling DisplayError too many times:
131  static bool show_err = true;
132 
133  // Obtain pointer to the vertex in currently used container
134  VERTEX* newVertex = m_container->Allocate( aSize );
135 
136  if( newVertex == NULL )
137  {
138  if( show_err )
139  {
140  DisplayError( NULL, wxT( "VERTEX_MANAGER::Vertices: Vertex allocation error" ) );
141  show_err = false;
142  }
143 
144  return false;
145  }
146 
147  // Put vertices in already allocated memory chunk
148  for( unsigned int i = 0; i < aSize; ++i )
149  {
150  putVertex( newVertex[i], aVertices[i].x, aVertices[i].y, aVertices[i].z );
151  }
152 
153  return true;
154 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
void putVertex(VERTEX &aTarget, GLfloat aX, GLfloat aY, GLfloat aZ) const
Function putVertex() applies all transformation to the given coordinates and store them at the specif...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71

Member Data Documentation

GLubyte KIGFX::VERTEX_MANAGER::m_color[ColorStride]
protected

Currently used color.

Definition at line 364 of file vertex_manager.h.

Referenced by Color(), and putVertex().

std::shared_ptr<VERTEX_CONTAINER> KIGFX::VERTEX_MANAGER::m_container
protected

Container for vertices, may be cached or noncached.

Definition at line 352 of file vertex_manager.h.

Referenced by ChangeItemColor(), ChangeItemDepth(), Clear(), FinishItem(), FreeItem(), GetVertices(), Map(), Reserve(), SetItem(), Unmap(), Vertex(), VERTEX_MANAGER(), and Vertices().

std::shared_ptr<GPU_MANAGER> KIGFX::VERTEX_MANAGER::m_gpu
protected

GPU manager for data transfers and drawing operations.

Definition at line 354 of file vertex_manager.h.

Referenced by BeginDrawing(), DrawItem(), EndDrawing(), SetShader(), and VERTEX_MANAGER().

bool KIGFX::VERTEX_MANAGER::m_noTransform
protected

State machine variables True in case there is no need to transform vertices.

Definition at line 358 of file vertex_manager.h.

Referenced by PopMatrix(), PushMatrix(), and putVertex().

VERTEX* KIGFX::VERTEX_MANAGER::m_reserved
protected

Currently reserved chunk to store vertices.

Definition at line 369 of file vertex_manager.h.

Referenced by Reserve(), and Vertex().

unsigned int KIGFX::VERTEX_MANAGER::m_reservedSpace
protected

Currently available reserved space.

Definition at line 372 of file vertex_manager.h.

Referenced by Reserve(), and Vertex().

GLfloat KIGFX::VERTEX_MANAGER::m_shader[ShaderStride]
protected

Currently used shader and its parameters.

Definition at line 366 of file vertex_manager.h.

Referenced by putVertex(), Shader(), and VERTEX_MANAGER().

glm::mat4 KIGFX::VERTEX_MANAGER::m_transform
protected

Currently used transform matrix.

Definition at line 360 of file vertex_manager.h.

Referenced by GetTransformation(), PopMatrix(), PushMatrix(), putVertex(), Rotate(), Scale(), and Translate().

std::stack<glm::mat4> KIGFX::VERTEX_MANAGER::m_transformStack
protected

Stack of transformation matrices, used for Push/PopMatrix.

Definition at line 362 of file vertex_manager.h.

Referenced by PopMatrix(), and PushMatrix().


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