KiCad PCB EDA Suite
KIGFX::VERTEX_MANAGER Class Reference

Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1.0 state machine using modern OpenGL methods. More...

#include <vertex_manager.h>

Public Member Functions

 VERTEX_MANAGER (bool aCached)
 
void Map ()
 Map vertex buffer. More...
 
void Unmap ()
 Unmap vertex buffer. More...
 
bool Reserve (unsigned int aSize)
 Allocate space for vertices, so it will be used with subsequent Vertex() calls. More...
 
bool Vertex (const VERTEX &aVertex)
 Add a vertex with the given coordinates to the currently set item. More...
 
bool Vertex (GLfloat aX, GLfloat aY, GLfloat aZ)
 Add a vertex with the given coordinates to the currently set item. More...
 
bool Vertex (const VECTOR2D &aXY, GLfloat aZ)
 Add a vertex with the given coordinates to the currently set item. More...
 
bool Vertices (const VERTEX aVertices[], unsigned int aSize)
 Add one or more vertices to the currently set item. More...
 
void Color (const COLOR4D &aColor)
 Changes currently used color that will be applied to newly added vertices. More...
 
void Color (GLfloat aRed, GLfloat aGreen, GLfloat aBlue, GLfloat aAlpha)
 Change 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)
 Change currently used shader and its parameters that will be applied to newly added vertices. More...
 
void Translate (GLfloat aX, GLfloat aY, GLfloat aZ)
 Multiply 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)
 Multiply 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)
 Multiply the current matrix by a scaling matrix, so the newly vertices will be scaled by the given factors. More...
 
void PushMatrix ()
 Push the current transformation matrix stack. More...
 
void PopMatrix ()
 Pop the current transformation matrix stack. More...
 
void SetItem (VERTEX_ITEM &aItem) const
 Set an item to start its modifications. More...
 
void FinishItem () const
 Clean after adding an item. More...
 
void FreeItem (VERTEX_ITEM &aItem) const
 Free 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
 Change the color of all vertices owned by an item. More...
 
void ChangeItemDepth (const VERTEX_ITEM &aItem, GLfloat aDepth) const
 Change the depth of all vertices owned by an item. More...
 
VERTEXGetVertices (const VERTEX_ITEM &aItem) const
 Return a pointer to the vertices owned by an item. More...
 
const glm::mat4 & GetTransformation () const
 
void SetShader (SHADER &aShader) const
 Set a shader program that is going to be used during rendering. More...
 
void Clear () const
 Remove all the stored vertices from the container. More...
 
void BeginDrawing () const
 Prepare buffers and items to start drawing. More...
 
void DrawItem (const VERTEX_ITEM &aItem) const
 Draw an item to the buffer. More...
 
void EndDrawing () const
 Finish drawing operations. More...
 
void EnableDepthTest (bool aEnabled)
 Enable/disable Z buffer depth test. More...
 

Protected Member Functions

void putVertex (VERTEX &aTarget, GLfloat aX, GLfloat aY, GLfloat aZ) const
 Apply 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 [COLOR_STRIDE]
 Currently used color. More...
 
GLfloat m_shader [SHADER_STRIDE]
 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

Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1.0 state machine using modern OpenGL methods.

Definition at line 53 of file vertex_manager.h.

Constructor & Destructor Documentation

◆ VERTEX_MANAGER()

VERTEX_MANAGER::VERTEX_MANAGER ( bool  aCached)
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 42 of file vertex_manager.cpp.

42  :
43  m_noTransform( true ),
44  m_transform( 1.0f ),
45  m_reserved( nullptr ),
46  m_reservedSpace( 0 )
47 {
48  m_container.reset( VERTEX_CONTAINER::MakeContainer( aCached ) );
49  m_gpu.reset( GPU_MANAGER::MakeManager( m_container.get() ) );
50 
51  // There is no shader used by default
52  for( unsigned int i = 0; i < SHADER_STRIDE; ++i )
53  m_shader[i] = 0.0f;
54 }
static VERTEX_CONTAINER * MakeContainer(bool aCached)
Return a pointer to a new container of an appropriate type.
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
GLfloat m_shader[SHADER_STRIDE]
Currently used shader and its parameters.
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:45
static constexpr size_t SHADER_STRIDE
Definition: vertex_common.h:81
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.

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

Member Function Documentation

◆ BeginDrawing()

void VERTEX_MANAGER::BeginDrawing ( ) const

Prepare buffers and items to start drawing.

Definition at line 238 of file vertex_manager.cpp.

239 {
240  m_gpu->BeginDrawing();
241 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.

References m_gpu.

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

◆ ChangeItemColor()

void VERTEX_MANAGER::ChangeItemColor ( const VERTEX_ITEM aItem,
const COLOR4D aColor 
) const

Change 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 180 of file vertex_manager.cpp.

181 {
182  unsigned int size = aItem.GetSize();
183  unsigned int offset = aItem.GetOffset();
184 
185  VERTEX* vertex = m_container->GetVertices( offset );
186 
187  for( unsigned int i = 0; i < size; ++i )
188  {
189  vertex->r = aColor.r * 255.0;
190  vertex->g = aColor.g * 255.0;
191  vertex->b = aColor.b * 255.0;
192  vertex->a = aColor.a * 255.0;
193  vertex++;
194  }
195 
196  m_container->SetDirty();
197 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
unsigned int GetSize() const
Return information about number of vertices stored.
Definition: vertex_item.h:58
double g
Green component.
Definition: color4d.h:372
double b
Blue component.
Definition: color4d.h:373
double a
Alpha component.
Definition: color4d.h:374
unsigned int GetOffset() const
Return data offset in the container.
Definition: vertex_item.h:68
double r
Red component.
Definition: color4d.h:371

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

◆ ChangeItemDepth()

void VERTEX_MANAGER::ChangeItemDepth ( const VERTEX_ITEM aItem,
GLfloat  aDepth 
) const

Change 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 200 of file vertex_manager.cpp.

201 {
202  unsigned int size = aItem.GetSize();
203  unsigned int offset = aItem.GetOffset();
204 
205  VERTEX* vertex = m_container->GetVertices( offset );
206 
207  for( unsigned int i = 0; i < size; ++i )
208  {
209  vertex->z = aDepth;
210  vertex++;
211  }
212 
213  m_container->SetDirty();
214 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
unsigned int GetSize() const
Return information about number of vertices stored.
Definition: vertex_item.h:58
unsigned int GetOffset() const
Return data offset in the container.
Definition: vertex_item.h:68

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

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

◆ Clear()

void VERTEX_MANAGER::Clear ( ) const

Remove all the stored vertices from the container.

Definition at line 232 of file vertex_manager.cpp.

233 {
234  m_container->Clear();
235 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.

References m_container.

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

◆ Color() [1/2]

void KIGFX::VERTEX_MANAGER::Color ( const COLOR4D aColor)
inline

Changes currently used color that will be applied to newly added vertices.

Parameters
aColoris the new color.

Definition at line 140 of file vertex_manager.h.

141  {
142  m_color[0] = aColor.r * 255.0;
143  m_color[1] = aColor.g * 255.0;
144  m_color[2] = aColor.b * 255.0;
145  m_color[3] = aColor.a * 255.0;
146  }
GLubyte m_color[COLOR_STRIDE]
Currently used color.

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(), KIGFX::OPENGL_GAL::drawSemiCircle(), and KIGFX::OPENGL_GAL::drawTriangulatedPolyset().

◆ Color() [2/2]

void KIGFX::VERTEX_MANAGER::Color ( GLfloat  aRed,
GLfloat  aGreen,
GLfloat  aBlue,
GLfloat  aAlpha 
)
inline

Change 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 158 of file vertex_manager.h.

159  {
160  m_color[0] = aRed * 255.0;
161  m_color[1] = aGreen * 255.0;
162  m_color[2] = aBlue * 255.0;
163  m_color[3] = aAlpha * 255.0;
164  }
GLubyte m_color[COLOR_STRIDE]
Currently used color.

References m_color.

◆ DrawItem()

void VERTEX_MANAGER::DrawItem ( const VERTEX_ITEM aItem) const

Draw an item to the buffer.

Parameters
aItemis the item to be drawn.

Definition at line 244 of file vertex_manager.cpp.

245 {
246  int size = aItem.GetSize();
247  int offset = aItem.GetOffset();
248 
249  m_gpu->DrawIndices( offset, size );
250 }
unsigned int GetSize() const
Return information about number of vertices stored.
Definition: vertex_item.h:58
unsigned int GetOffset() const
Return data offset in the container.
Definition: vertex_item.h:68
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.

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

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

◆ EnableDepthTest()

void VERTEX_MANAGER::EnableDepthTest ( bool  aEnabled)

Enable/disable Z buffer depth test.

Definition at line 293 of file vertex_manager.cpp.

294 {
295  m_gpu->EnableDepthTest( aEnabled );
296 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.

References m_gpu.

Referenced by KIGFX::OPENGL_GAL::DrawGrid(), and KIGFX::OPENGL_GAL::EnableDepthTest().

◆ EndDrawing()

void VERTEX_MANAGER::EndDrawing ( ) const

Finish drawing operations.

Definition at line 253 of file vertex_manager.cpp.

254 {
255  m_gpu->EndDrawing();
256 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.

References m_gpu.

Referenced by KIGFX::OPENGL_GAL::DrawGrid(), KIGFX::OPENGL_GAL::EndDiffLayer(), KIGFX::OPENGL_GAL::endDrawing(), and KIGFX::OPENGL_GAL::StartDiffLayer().

◆ FinishItem()

void VERTEX_MANAGER::FinishItem ( ) const

Clean after adding an item.

Definition at line 168 of file vertex_manager.cpp.

169 {
170  m_container->FinishItem();
171 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.

References m_container.

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

◆ FreeItem()

void VERTEX_MANAGER::FreeItem ( VERTEX_ITEM aItem) const

Free 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 174 of file vertex_manager.cpp.

175 {
176  m_container->Delete( &aItem );
177 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.

References m_container.

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

◆ GetTransformation()

const glm::mat4& KIGFX::VERTEX_MANAGER::GetTransformation ( ) const
inline

Definition at line 311 of file vertex_manager.h.

312  {
313  return m_transform;
314  }
glm::mat4 m_transform
Currently used transform matrix.

References m_transform.

Referenced by KIGFX::OPENGL_GAL::DrawBitmap(), and KIGFX::OPENGL_GAL::drawLineQuad().

◆ GetVertices()

VERTEX * VERTEX_MANAGER::GetVertices ( const VERTEX_ITEM aItem) const

Return 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 217 of file vertex_manager.cpp.

218 {
219  if( aItem.GetSize() == 0 )
220  return nullptr; // The item is not stored in the container
221 
222  return m_container->GetVertices( aItem.GetOffset() );
223 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
unsigned int GetSize() const
Return information about number of vertices stored.
Definition: vertex_item.h:58
unsigned int GetOffset() const
Return data offset in the container.
Definition: vertex_item.h:68

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

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

◆ Map()

void VERTEX_MANAGER::Map ( )

Map vertex buffer.

Definition at line 57 of file vertex_manager.cpp.

58 {
59  m_container->Map();
60 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.

References m_container.

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

◆ PopMatrix()

void KIGFX::VERTEX_MANAGER::PopMatrix ( )
inline

Pop the current transformation matrix stack.

It is the equivalent of the glPopMatrix() function.

Definition at line 252 of file vertex_manager.h.

253  {
254  wxASSERT( !m_transformStack.empty() );
255 
257  m_transformStack.pop();
258 
259  if( m_transformStack.empty() )
260  {
261  // We return back to the identity matrix, thus no vertex transformation is needed
262  m_noTransform = true;
263  }
264  }
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.

References m_noTransform, m_transform, and m_transformStack.

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

◆ PushMatrix()

void KIGFX::VERTEX_MANAGER::PushMatrix ( )
inline

Push the current transformation matrix stack.

It is the equivalent of the glPushMatrix() function.

Definition at line 239 of file vertex_manager.h.

240  {
242 
243  // Every transformation starts with PushMatrix
244  m_noTransform = false;
245  }
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.

References m_noTransform, m_transform, and m_transformStack.

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

◆ putVertex()

void VERTEX_MANAGER::putVertex ( VERTEX aTarget,
GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
) const
protected

Apply 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 259 of file vertex_manager.cpp.

260 {
261  // Modify the vertex according to the currently used transformations
262  if( m_noTransform )
263  {
264  // Simply copy coordinates, when the transform matrix is the identity matrix
265  aTarget.x = aX;
266  aTarget.y = aY;
267  aTarget.z = aZ;
268  }
269  else
270  {
271  // Apply transformations
272  glm::vec4 transVertex( aX, aY, aZ, 1.0f );
273  transVertex = m_transform * transVertex;
274 
275  aTarget.x = transVertex.x;
276  aTarget.y = transVertex.y;
277  aTarget.z = transVertex.z;
278  }
279 
280  // Apply currently used color
281  aTarget.r = m_color[0];
282  aTarget.g = m_color[1];
283  aTarget.b = m_color[2];
284  aTarget.a = m_color[3];
285 
286  // Apply currently used shader
287  for( unsigned int j = 0; j < SHADER_STRIDE; ++j )
288  {
289  aTarget.shader[j] = m_shader[j];
290  }
291 }
GLfloat shader[4]
Definition: vertex_common.h:64
GLfloat m_shader[SHADER_STRIDE]
Currently used shader and its parameters.
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[COLOR_STRIDE]
Currently used color.
static constexpr size_t SHADER_STRIDE
Definition: vertex_common.h:81

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::SHADER_STRIDE, KIGFX::VERTEX::x, KIGFX::VERTEX::y, and KIGFX::VERTEX::z.

Referenced by Vertex(), and Vertices().

◆ Reserve()

bool VERTEX_MANAGER::Reserve ( unsigned int  aSize)

Allocate 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 69 of file vertex_manager.cpp.

70 {
71  assert( m_reservedSpace == 0 && m_reserved == nullptr );
72 
73  // flag to avoid hanging by calling DisplayError too many times:
74  static bool show_err = true;
75 
76  m_reserved = m_container->Allocate( aSize );
77 
78  if( m_reserved == nullptr )
79  {
80  if( show_err )
81  {
82  DisplayError( nullptr, wxT( "VERTEX_MANAGER::Reserve: Vertex allocation error" ) );
83  show_err = false;
84  }
85 
86  return false;
87  }
88 
89  m_reservedSpace = aSize;
90 
91  return true;
92 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:271
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.
VERTEX * m_reserved
Currently reserved chunk to store vertices.
unsigned int m_reservedSpace
Currently available reserved space.

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

◆ Rotate()

void KIGFX::VERTEX_MANAGER::Rotate ( GLfloat  aAngle,
GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)
inline

Multiply 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 214 of file vertex_manager.h.

215  {
216  m_transform = glm::rotate( m_transform, aAngle, glm::vec3( aX, aY, aZ ) );
217  }
glm::mat4 m_transform
Currently used transform matrix.

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

◆ Scale()

void KIGFX::VERTEX_MANAGER::Scale ( GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)
inline

Multiply 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 229 of file vertex_manager.h.

230  {
231  m_transform = glm::scale( m_transform, glm::vec3( aX, aY, aZ ) );
232  }
glm::mat4 m_transform
Currently used transform matrix.
const int scale

References m_transform, and scale.

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

◆ SetItem()

void VERTEX_MANAGER::SetItem ( VERTEX_ITEM aItem) const

Set 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 162 of file vertex_manager.cpp.

163 {
164  m_container->SetItem( &aItem );
165 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.

References m_container.

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

◆ SetShader()

void VERTEX_MANAGER::SetShader ( SHADER aShader) const

Set a shader program that is going to be used during rendering.

Parameters
aShaderis the object containing compiled and linked shader program.

Definition at line 226 of file vertex_manager.cpp.

227 {
228  m_gpu->SetShader( aShader );
229 }
std::shared_ptr< GPU_MANAGER > m_gpu
GPU manager for data transfers and drawing operations.

References m_gpu.

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

◆ Shader()

void KIGFX::VERTEX_MANAGER::Shader ( GLfloat  aShaderType,
GLfloat  aParam1 = 0.0f,
GLfloat  aParam2 = 0.0f,
GLfloat  aParam3 = 0.0f 
)
inline

Change 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 179 of file vertex_manager.h.

181  {
182  m_shader[0] = aShaderType;
183  m_shader[1] = aParam1;
184  m_shader[2] = aParam2;
185  m_shader[3] = aParam3;
186  }
GLfloat m_shader[SHADER_STRIDE]
Currently used shader and its parameters.

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(), KIGFX::OPENGL_GAL::drawStrokedSemiCircle(), and KIGFX::OPENGL_GAL::drawTriangulatedPolyset().

◆ Translate()

void KIGFX::VERTEX_MANAGER::Translate ( GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)
inline

Multiply 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 198 of file vertex_manager.h.

199  {
200  m_transform = glm::translate( m_transform, glm::vec3( aX, aY, aZ ) );
201  }
glm::mat4 m_transform
Currently used transform matrix.

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

◆ Unmap()

void VERTEX_MANAGER::Unmap ( )

Unmap vertex buffer.

Definition at line 63 of file vertex_manager.cpp.

64 {
65  m_container->Unmap();
66 }
std::shared_ptr< VERTEX_CONTAINER > m_container
Container for vertices, may be cached or noncached.

References m_container.

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

◆ Vertex() [1/3]

bool KIGFX::VERTEX_MANAGER::Vertex ( const VERTEX aVertex)
inline

Add 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 90 of file vertex_manager.h.

91  {
92  return Vertex( aVertex.x, aVertex.y, aVertex.z );
93  }
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.

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(), KIGFX::OPENGL_GAL::drawTriangulatedPolyset(), Vertex(), and VertexCallback().

◆ Vertex() [2/3]

bool VERTEX_MANAGER::Vertex ( GLfloat  aX,
GLfloat  aY,
GLfloat  aZ 
)

Add 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 95 of file vertex_manager.cpp.

96 {
97  // flag to avoid hanging by calling DisplayError too many times:
98  static bool show_err = true;
99 
100  // Obtain the pointer to the vertex in the currently used container
101  VERTEX* newVertex;
102 
103  if( m_reservedSpace > 0 )
104  {
105  newVertex = m_reserved++;
106  --m_reservedSpace;
107 
108  if( m_reservedSpace == 0 )
109  m_reserved = nullptr;
110  }
111  else
112  {
113  newVertex = m_container->Allocate( 1 );
114  }
115 
116  if( newVertex == nullptr )
117  {
118  if( show_err )
119  {
120  DisplayError( nullptr, wxT( "VERTEX_MANAGER::Vertex: Vertex allocation error" ) );
121  show_err = false;
122  }
123 
124  return false;
125  }
126 
127  putVertex( *newVertex, aX, aY, aZ );
128 
129  return true;
130 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:271
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
Apply all transformation to the given coordinates and store them at the specified target.
VERTEX * m_reserved
Currently reserved chunk to store vertices.
unsigned int m_reservedSpace
Currently available reserved space.

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

◆ Vertex() [3/3]

bool KIGFX::VERTEX_MANAGER::Vertex ( const VECTOR2D aXY,
GLfloat  aZ 
)
inline

Add a vertex with the given coordinates to the currently set item.

Vertex coordinates will have the current transformation matrix applied.

Parameters
aXYare the XY coordinates of the new vertex.
aZis the Z coordinate of the new vertex.
Returns
True if successful, false otherwise.

Definition at line 116 of file vertex_manager.h.

117  {
118  return Vertex( aXY.x, aXY.y, aZ );
119  }
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.

References Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Vertices()

bool VERTEX_MANAGER::Vertices ( const VERTEX  aVertices[],
unsigned int  aSize 
)

Add 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 133 of file vertex_manager.cpp.

134 {
135  // flag to avoid hanging by calling DisplayError too many times:
136  static bool show_err = true;
137 
138  // Obtain pointer to the vertex in currently used container
139  VERTEX* newVertex = m_container->Allocate( aSize );
140 
141  if( newVertex == nullptr )
142  {
143  if( show_err )
144  {
145  DisplayError( nullptr, wxT( "VERTEX_MANAGER::Vertices: Vertex allocation error" ) );
146  show_err = false;
147  }
148 
149  return false;
150  }
151 
152  // Put vertices in already allocated memory chunk
153  for( unsigned int i = 0; i < aSize; ++i )
154  {
155  putVertex( newVertex[i], aVertices[i].x, aVertices[i].y, aVertices[i].z );
156  }
157 
158  return true;
159 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:271
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
Apply all transformation to the given coordinates and store them at the specified target.

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

Member Data Documentation

◆ m_color

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

Currently used color.

Definition at line 375 of file vertex_manager.h.

Referenced by Color(), and putVertex().

◆ m_container

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

Container for vertices, may be cached or noncached.

Definition at line 363 of file vertex_manager.h.

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

◆ m_gpu

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

GPU manager for data transfers and drawing operations.

Definition at line 365 of file vertex_manager.h.

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

◆ m_noTransform

bool KIGFX::VERTEX_MANAGER::m_noTransform
protected

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

Definition at line 369 of file vertex_manager.h.

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

◆ m_reserved

VERTEX* KIGFX::VERTEX_MANAGER::m_reserved
protected

Currently reserved chunk to store vertices.

Definition at line 380 of file vertex_manager.h.

Referenced by Reserve(), and Vertex().

◆ m_reservedSpace

unsigned int KIGFX::VERTEX_MANAGER::m_reservedSpace
protected

Currently available reserved space.

Definition at line 383 of file vertex_manager.h.

Referenced by Reserve(), and Vertex().

◆ m_shader

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

Currently used shader and its parameters.

Definition at line 377 of file vertex_manager.h.

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

◆ m_transform

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

Currently used transform matrix.

Definition at line 371 of file vertex_manager.h.

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

◆ m_transformStack

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

Stack of transformation matrices, used for Push/PopMatrix.

Definition at line 373 of file vertex_manager.h.

Referenced by PopMatrix(), and PushMatrix().


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