GLVis  v4.2
Accurate and flexible finite element visualization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
types.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-443271.
4 //
5 // This file is part of the GLVis visualization tool and library. For more
6 // information and source code availability see https://glvis.org.
7 //
8 // GLVis is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef GLVIS_TYPES_HPP
13 #define GLVIS_TYPES_HPP
14 
15 #include <vector>
16 #include <array>
17 #include <iostream>
18 #include <memory>
19 #include <iterator>
20 #include <algorithm>
21 
22 #ifdef __INTEL_COMPILER
23 // for some reason, icpc is choking on GLM's constexpr stuff - force it to use
24 // only C++98 features as a workaround.
25 #define GLM_FORCE_CXX98
26 #endif
27 #include <glm/mat4x4.hpp>
28 #include <glm/vec3.hpp>
29 #include <glm/gtc/matrix_access.hpp>
30 #include <glm/gtc/matrix_transform.hpp>
31 #include <glm/gtc/matrix_inverse.hpp>
32 #include <glm/gtc/type_ptr.hpp>
33 
34 #include "platform_gl.hpp"
35 
36 using namespace std;
37 
38 class VisualizationScene;
39 
40 namespace gl3
41 {
42 
43 namespace resource
44 {
45 // RAII scope guard for OpenGL handles.
46 template<void(*GLFinalizer)(GLuint)>
47 class Handle
48 {
49  GLuint hnd;
50 public:
51  Handle() : hnd{0} {}
52  Handle(GLuint h) : hnd{h} {}
53  ~Handle() { if (hnd) { GLFinalizer(hnd); } }
54  Handle(Handle&& other)
55  : hnd{other.hnd} { other.hnd = 0; }
56  Handle& operator = (Handle&& other) noexcept
57  {
58  if (this != &other)
59  {
60  hnd = other.hnd;
61  other.hnd = 0;
62  }
63  return *this;
64  }
65  operator GLuint() const { return hnd; }
66 };
67 
68 inline void boCleanup(GLuint vbo_hnd)
69 {
70  glDeleteBuffers(1, &vbo_hnd);
71 }
72 
73 inline void dspListCleanup(GLuint dlist)
74 {
75  glDeleteLists(dlist, 1);
76 }
77 
78 inline void prgmCleanup(GLuint prgm)
79 {
80  glDeleteProgram(prgm);
81 }
82 
83 inline void shdrCleanup(GLuint shdr)
84 {
85  glDeleteShader(shdr);
86 }
87 
88 inline void vaoCleanup(GLuint vao)
89 {
90  glDeleteVertexArrays(1, &vao);
91 }
92 
93 inline void texCleanup(GLuint tex)
94 {
95  glDeleteTextures(1, &tex);
96 }
97 
98 inline void fboCleanup(GLuint fbo)
99 {
100  glDeleteFramebuffers(1, &fbo);
101 }
102 
103 inline void rboCleanup(GLuint rbo)
104 {
105  glDeleteRenderbuffers(1, &rbo);
106 }
107 
116 
117 } // end namespace resource
118 
119 struct GlMatrix
120 {
121  glm::mat4 mtx;
122 
124  void rotate(float angle, double x, double y, double z)
125  {
126  mtx = glm::rotate(mtx, glm::radians(angle), glm::vec3(x,y,z));
127  }
128 
129  void mult(glm::mat4 rhs)
130  {
131  mtx = mtx * rhs;
132  }
133 
135  void translate(double x, double y, double z)
136  {
137  mtx = glm::translate(mtx, glm::vec3(x, y, z));
138  }
139 
141  void scale(double x, double y, double z)
142  {
143  mtx = glm::scale(mtx, glm::vec3(x, y, z));
144  }
145 
147  void ortho(double left,
148  double right,
149  double bottom,
150  double top,
151  double z_near,
152  double z_far)
153  {
154  mtx = glm::ortho(left, right, bottom, top, z_near, z_far);
155  }
156 
158  void perspective(double fov, double aspect, double z_near, double z_far)
159  {
160  mtx = glm::perspective(glm::radians(fov), aspect, z_near, z_far);
161  }
162 
164  void identity()
165  {
166  mtx = glm::mat4(1.0);
167  }
168 };
169 
171 {
179 };
180 
181 inline std::array<uint8_t, 4> ColorU8(float rgba[])
182 {
183  return
184  {
185  (rgba[0] >= 1.0) ? (uint8_t) 255 : (uint8_t)(rgba[0] * 256.),
186  (rgba[1] >= 1.0) ? (uint8_t) 255 : (uint8_t)(rgba[1] * 256.),
187  (rgba[2] >= 1.0) ? (uint8_t) 255 : (uint8_t)(rgba[2] * 256.),
188  (rgba[3] >= 1.0) ? (uint8_t) 255 : (uint8_t)(rgba[3] * 256.),
189  };
190 }
191 
192 inline std::array<uint8_t, 4> ColorU8(float r, float g, float b, float a)
193 {
194  return
195  {
196  (r >= 1.0) ? (uint8_t) 255 : (uint8_t)(r * 256.),
197  (g >= 1.0) ? (uint8_t) 255 : (uint8_t)(g * 256.),
198  (b >= 1.0) ? (uint8_t) 255 : (uint8_t)(b * 256.),
199  (a >= 1.0) ? (uint8_t) 255 : (uint8_t)(a * 256.),
200  };
201 }
202 
203 struct alignas(16) Vertex
204 {
205  std::array<float, 3> coord;
206 
207  static Vertex create(double * d)
208  {
209  return Vertex {(float) d[0], (float) d[1], (float) d[2]};
210  }
211  static const int layout = LAYOUT_VTX;
212 };
213 
214 struct alignas(16) VertexColor
215 {
216  std::array<float, 3> coord;
217  std::array<uint8_t, 4> color;
218 
219  static const int layout = LAYOUT_VTX_COLOR;
220 };
221 
222 struct alignas(16) VertexTex
223 {
224  std::array<float, 3> coord;
225  std::array<float, 2> texCoord;
226 
227  static const int layout = LAYOUT_VTX_TEXTURE0;
228 };
229 
230 struct alignas(16) VertexNorm
231 {
232  std::array<float, 3> coord;
233  std::array<float, 3> norm;
234 
235  static const int layout = LAYOUT_VTX_NORMAL;
236 };
237 
238 struct alignas(16) VertexNormColor
239 {
240  std::array<float, 3> coord;
241  std::array<float, 3> norm;
242  std::array<uint8_t, 4> color;
243 
244  static const int layout = LAYOUT_VTX_NORMAL_COLOR;
245 };
246 
247 struct alignas(16) VertexNormTex
248 {
249  std::array<float, 3> coord;
250  std::array<float, 3> norm;
251  std::array<float, 2> texCoord;
252 
253  static const int layout = LAYOUT_VTX_NORMAL_TEXTURE0;
254 };
255 
256 
257 
258 class GlDrawable;
259 
262 {
263  GlDrawable * parent_buf;
264  GLenum render_as;
265  int count;
266 
267  bool is_line;
268 
269  bool use_norm;
270  bool use_color;
271  bool use_tex;
272 
273  struct FFState
274  {
275  std::array<float, 3> coords;
276  std::array<float, 3> norm;
277  std::array<uint8_t, 4> color;
278  std::array<float, 2> texcoord;
279  };
280 
281  FFState saved[3];
282  FFState curr;
283 
284  void saveVertex(const FFState& v);
285 
286 public:
288  : parent_buf(buf)
289  , count(0)
290  , is_line(false)
291  , use_norm(false)
292  , use_color(false)
293  , use_tex(false) { }
294 
295  void glBegin(GLenum e)
296  {
297  if (e == GL_LINES || e == GL_LINE_STRIP || e == GL_LINE_LOOP)
298  {
299  is_line = true;
300  }
301  else
302  {
303  is_line = false;
304  }
305  render_as = e;
306  count = 0;
307  }
308 
309  void glEnd()
310  {
311  // create degenerate primitives if necessary
312  if (render_as == GL_LINES && count % 2 != 0)
313  {
314  saveVertex(curr);
315  }
316  if (render_as == GL_TRIANGLES)
317  {
318  for (int i = 0; i < count % 3; i++)
319  {
320  saveVertex(curr);
321  }
322  }
323  if (render_as == GL_LINE_LOOP && count > 2)
324  {
325  // link first and last vertex
326  saveVertex(saved[0]);
327  saveVertex(saved[1]);
328  }
329  count = 0;
330  }
331 
332  void glVertex3d(double x, double y, double z)
333  {
334  curr.coords = { (float) x, (float) y, (float) z };
335  if (render_as == GL_LINES || render_as == GL_TRIANGLES)
336  {
337  // Lines and triangles are stored as-is
338  saveVertex(curr);
339  }
340  else if (is_line)
341  {
342  // LINE_LOOP and LINE_STRIP: each vertex creates a new line with the
343  // previous vertex
344  if (count == 0)
345  {
346  saved[0] = curr;
347  }
348  else
349  {
350  saveVertex(saved[1]);
351  saveVertex(curr);
352  }
353  saved[1] = curr;
354  }
355  else if (render_as == GL_QUADS)
356  {
357  if (count % 4 == 3)
358  {
359  // split on 0-2 diagonal
360  saveVertex(saved[0]);
361  saveVertex(saved[1]);
362  saveVertex(saved[2]);
363  saveVertex(saved[0]);
364  saveVertex(saved[2]);
365  saveVertex(curr);
366  count -= 4;
367  }
368  else
369  {
370  saved[count] = curr;
371  }
372  }
373  else if (render_as != GL_NONE)
374  {
375  // TriangleStrip, TriangleFan, Polygon
376  if (count >= 2)
377  {
378  saveVertex(saved[0]);
379  saveVertex(saved[1]);
380  saveVertex(curr);
381  if (render_as == GL_TRIANGLE_STRIP)
382  {
383  // pop earliest vertex
384  saved[0] = saved[1];
385  }
386  saved[1] = curr;
387  }
388  else
389  {
390  saved[count] = curr;
391  }
392  }
393  count++;
394  }
395 
396  void glVertex3dv(const double * d)
397  {
398  glVertex3d(d[0], d[1], d[2]);
399  }
400 
401  void glNormal3d(double nx, double ny, double nz)
402  {
403  use_norm = true;
404  curr.norm = { (float) nx, (float) ny, (float) nz };
405  }
406 
407  void glNormal3dv(const double * d) { glNormal3d(d[0], d[1], d[2]); }
408 
409  void glColor4f(float r, float g, float b, float a)
410  {
411  if (count == 0)
412  {
413  use_color = true;
414  use_tex = false;
415  }
416  curr.color =
417  {
418  (r >= 1.0) ? (uint8_t) 255 : (uint8_t)(r * 256.),
419  (g >= 1.0) ? (uint8_t) 255 : (uint8_t)(g * 256.),
420  (b >= 1.0) ? (uint8_t) 255 : (uint8_t)(b * 256.),
421  (a >= 1.0) ? (uint8_t) 255 : (uint8_t)(a * 256.),
422  };
423  }
424 
425  void glColor3f(float r, float g, float b) { glColor4f(r, g, b, 1.f); }
426 
427  void glColor4fv(float * cv) { glColor4f(cv[0], cv[1], cv[2], cv[3]); }
428 
429  void glTexCoord2f(float coord_u, float coord_v)
430  {
431  if (count == 0)
432  {
433  use_tex = true;
434  use_color = false;
435  }
436  curr.texcoord = { coord_u, coord_v };
437  }
438 };
439 
441 {
442 private:
443  int handle;
444 public:
445  IVertexBuffer() : handle(0) { }
446  virtual ~IVertexBuffer() { }
447 
448  int getHandle() const { return handle; }
449  void setHandle(int dev_hnd) { handle = dev_hnd; }
451  virtual void clear() = 0;
453  virtual size_t count() const = 0;
455  virtual GLenum getShape() const = 0;
457  virtual size_t getStride() const = 0;
458 
459  virtual const void* getData() const = 0;
460 };
461 
462 template<typename T>
464 {
465 private:
466  GLenum primitive;
467  std::vector<T> vertex_data;
468 
469 public:
470  typedef typename std::vector<T>::const_iterator ConstIterator;
471 
472  VertexBuffer(GLenum shape) : primitive(shape) { }
474 
475  virtual void clear() { vertex_data.clear(); }
476  virtual size_t count() const { return vertex_data.size(); }
477 
478  virtual GLenum getShape() const { return primitive; }
479  virtual size_t getStride() const { return sizeof(T); }
480 
481  ConstIterator begin() const { return vertex_data.begin(); };
482  ConstIterator end() const { return vertex_data.end(); };
483 
484  virtual const void* getData() const { return vertex_data.data(); }
485 
487  void addVertex(const T& vertex)
488  {
489  vertex_data.emplace_back(vertex);
490  }
491 
493  void addVertices(const std::vector<T>& verts)
494  {
495  vertex_data.insert(vertex_data.end(), verts.begin(), verts.end());
496  }
497 };
498 
500 {
501 public:
502  virtual const std::vector<int>& getIndices() const = 0;
503 };
504 
505 template<typename T>
507 {
508 private:
509  GLenum primitive;
510  std::vector<T> vertex_data;
511  std::vector<int> vertex_indices;
512 
513 public:
514  typedef typename std::vector<T>::const_iterator ConstIterator;
515  IndexedVertexBuffer(GLenum shape) : primitive(shape) { }
517  virtual void clear()
518  {
519  vertex_data.clear();
520  vertex_indices.clear();
521  }
522 
523  virtual size_t count() const { return vertex_data.size(); }
524 
525  virtual GLenum getShape() const { return primitive; }
526  virtual size_t getStride() const { return sizeof(T); }
527 
528  ConstIterator begin() const { return vertex_data.begin(); };
529  ConstIterator end() const { return vertex_data.end(); };
530 
531  virtual const void* getData() const { return vertex_data.data(); }
532 
533  const std::vector<int>& getIndices() const { return vertex_indices; }
534 
535  void addVertices(const std::vector<T>& verts, const std::vector<int>& ids)
536  {
537  int index_offset = vertex_data.size();
538  std::copy(verts.begin(), verts.end(), std::back_inserter(vertex_data));
539  int old_end = vertex_indices.size();
540  std::copy(ids.begin(), ids.end(), std::back_inserter(vertex_indices));
541  for (size_t i = old_end; i < vertex_indices.size(); i++)
542  {
543  vertex_indices[i] += index_offset;
544  }
545  }
546 };
547 
548 class TextBuffer : public IVertexBuffer
549 {
550 public:
551  struct Entry
552  {
553  float rx, ry, rz;
554  int ox, oy;
555  std::string text;
556  Entry() = default;
557  Entry(float x, float y, float z, int ox, int oy, const std::string& txt)
558  : rx(x), ry(y), rz(z), ox(ox), oy(oy), text(txt) { }
559  };
560  typedef std::vector<Entry>::iterator Iterator;
561  typedef std::vector<Entry>::const_iterator ConstIterator;
562 private:
563  std::vector<Entry> vertex_data;
564  size_t num_chars;
565 
566 public:
567  TextBuffer() : num_chars(0) { }
569 
572  void addText(float x, float y, float z, int ox, int oy,
573  const std::string& text)
574  {
575  vertex_data.emplace_back(x, y, z, ox, oy, text);
576  num_chars += text.length();
577  }
578 
580  Iterator begin() { return vertex_data.begin(); }
581  ConstIterator begin() const { return vertex_data.begin(); }
582 
584  Iterator end() { return vertex_data.end(); }
585  ConstIterator end() const { return vertex_data.end(); }
586 
587  virtual void clear() { vertex_data.clear(); num_chars = 0; }
588  virtual size_t count() const { return num_chars * 6; };
589  virtual GLenum getShape() const { return GL_TRIANGLES; };
590  virtual size_t getStride() const { return sizeof(float) * 8; };
591  virtual const void* getData() const { return nullptr; }
592 };
593 
595 {
596 private:
597  const static size_t NUM_SHAPES = 2;
598  std::unique_ptr<IVertexBuffer> buffers[NUM_LAYOUTS][NUM_SHAPES];
599  std::unique_ptr<IIndexedBuffer> indexed_buffers[NUM_LAYOUTS][NUM_SHAPES];
600  TextBuffer text_buffer;
601 
602  friend class GlBuilder;
603  friend class MeshRenderer;
604  friend class ::VisualizationScene; // needed for glTF export
605 
606  template<typename Vert>
607  VertexBuffer<Vert> * getBuffer(GLenum shape)
608  {
609  int idx = -1;
610  if (shape == GL_LINES)
611  {
612  idx = 0;
613  }
614  else if (shape == GL_TRIANGLES)
615  {
616  idx = 1;
617  }
618  else
619  {
620  return nullptr;
621  }
622  if (!buffers[Vert::layout][idx])
623  {
624  buffers[Vert::layout][idx].reset(new VertexBuffer<Vert>(shape));
625  }
626  VertexBuffer<Vert> * buf = static_cast<VertexBuffer<Vert>*>
627  (buffers[Vert::layout][idx].get());
628  return buf;
629  }
630 
631  template<typename Vert>
632  IndexedVertexBuffer<Vert> * getIndexedBuffer(GLenum shape)
633  {
634  int idx = -1;
635  if (shape == GL_LINES)
636  {
637  idx = 0;
638  }
639  else if (shape == GL_TRIANGLES)
640  {
641  idx = 1;
642  }
643  else
644  {
645  return nullptr;
646  }
647  if (!indexed_buffers[Vert::layout][idx])
648  {
649  indexed_buffers[Vert::layout][idx]
650  .reset(new IndexedVertexBuffer<Vert>(shape));
651  }
652  return static_cast<IndexedVertexBuffer<Vert>*>
653  (indexed_buffers[Vert::layout][idx].get());
654  }
655 public:
656 
658  void addText(float x, float y, float z, const std::string& text)
659  {
660  text_buffer.addText(x, y, z, 0, 0, text);
661  }
662 
665  void addText(float x, float y, float z, int ox, int oy,
666  const std::string& text)
667  {
668  text_buffer.addText(x, y, z, ox, oy, text);
669  }
670 
671  template<typename Vert>
672  void addLine(const Vert& v1, const Vert& v2)
673  {
674  getBuffer<Vert>(GL_LINES)->addVertex(v1);
675  getBuffer<Vert>(GL_LINES)->addVertex(v2);
676  }
677 
678  template<typename Vert>
679  void addLines(const std::vector<Vert>& verts)
680  {
681  getBuffer<Vert>(GL_LINES)->addVertices(verts);
682  }
683 
684  template<typename Vert>
685  void addTriangle(const Vert& v1, const Vert& v2, const Vert& v3)
686  {
687  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v1);
688  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v2);
689  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v3);
690  }
691 
692  template<typename Vert>
693  void addQuad(const Vert& v1, const Vert& v2, const Vert& v3, const Vert& v4)
694  {
695  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v1);
696  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v2);
697  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v3);
698  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v1);
699  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v3);
700  getBuffer<Vert>(GL_TRIANGLES)->addVertex(v4);
701  }
702 
703  template<typename Vert>
704  void addTriangleIndexed(const std::vector<Vert>& verts,
705  const std::vector<int>& inds)
706  {
707  getIndexedBuffer<Vert>(GL_TRIANGLES)->addVertices(verts, inds);
708  }
709 
710  template<typename Vert>
711  void addQuadIndexed(const std::vector<Vert>& verts,
712  const std::vector<int>& inds)
713  {
714  std::vector<int> new_inds;
715  for (size_t i = 0; i < inds.size() / 4; i++)
716  {
717  new_inds.emplace_back(inds[4*i]);
718  new_inds.emplace_back(inds[4*i + 1]);
719  new_inds.emplace_back(inds[4*i + 2]);
720  new_inds.emplace_back(inds[4*i]);
721  new_inds.emplace_back(inds[4*i + 2]);
722  new_inds.emplace_back(inds[4*i + 3]);
723  }
724  getIndexedBuffer<Vert>(GL_TRIANGLES)->addVertices(verts, new_inds);
725  }
726 
727  void addCone(float x, float y, float z,
728  float vx, float vy, float vz,
729  float cone_scale = 0.075);
730 
732  {
733  return GlBuilder(this);
734  }
735 
737  void clear()
738  {
739  for (int i = 0; i < NUM_LAYOUTS; i++)
740  {
741  for (size_t j = 0; j < NUM_SHAPES; j++)
742  {
743  if (buffers[i][j])
744  {
745  buffers[i][j]->clear();
746  }
747  if (indexed_buffers[i][j])
748  {
749  indexed_buffers[i][j]->clear();
750  }
751  }
752  }
753  text_buffer.clear();
754  }
755 };
756 
757 }
758 
759 #endif // GLVIS_TYPES_HPP
virtual size_t count() const
Gets the number of vertices contained in the buffer.
Definition: types.hpp:588
std::array< float, 3 > coord
Definition: types.hpp:205
void glColor4fv(float *cv)
Definition: types.hpp:427
Entry(float x, float y, float z, int ox, int oy, const std::string &txt)
Definition: types.hpp:557
void identity()
Sets the matrix to the identity matrix.
Definition: types.hpp:164
virtual const void * getData() const
Definition: types.hpp:591
virtual void clear()
Clears the data stored in the vertex buffer.
Definition: types.hpp:475
virtual GLenum getShape() const
Gets the primitive type contained by the vertex buffer.
Definition: types.hpp:478
void addLines(const std::vector< Vert > &verts)
Definition: types.hpp:679
void translate(double x, double y, double z)
Applies a translation transform to the matrix.
Definition: types.hpp:135
void addText(float x, float y, float z, int ox, int oy, const std::string &text)
Adds a string at the given position in object coordinates with an offset in pixels.
Definition: types.hpp:665
void glVertex3d(double x, double y, double z)
Definition: types.hpp:332
ConstIterator end() const
Definition: types.hpp:529
virtual size_t getStride() const
Gets the stride between vertices.
Definition: types.hpp:590
std::array< float, 2 > texCoord
Definition: types.hpp:251
void glColor3f(float r, float g, float b)
Definition: types.hpp:425
virtual void clear()
Clears the data stored in the vertex buffer.
Definition: types.hpp:587
void glEnd()
Definition: types.hpp:309
virtual GLenum getShape() const
Gets the primitive type contained by the vertex buffer.
Definition: types.hpp:589
void addLine(const Vert &v1, const Vert &v2)
Definition: types.hpp:672
void shdrCleanup(GLuint shdr)
Definition: types.hpp:83
void prgmCleanup(GLuint prgm)
Definition: types.hpp:78
static Vertex create(double *d)
Definition: types.hpp:207
void fboCleanup(GLuint fbo)
Definition: types.hpp:98
void addText(float x, float y, float z, int ox, int oy, const std::string &text)
Definition: types.hpp:572
void glNormal3dv(const double *d)
Definition: types.hpp:407
std::array< uint8_t, 4 > color
Definition: types.hpp:217
std::vector< T >::const_iterator ConstIterator
Definition: types.hpp:470
const std::vector< int > & getIndices() const
Definition: types.hpp:533
GlBuilder(GlDrawable *buf)
Definition: types.hpp:287
std::array< uint8_t, 4 > ColorU8(float rgba[])
Definition: types.hpp:181
IndexedVertexBuffer(GLenum shape)
Definition: types.hpp:515
std::array< float, 3 > coord
Definition: types.hpp:216
void glBegin(GLenum e)
Definition: types.hpp:295
virtual size_t count() const
Gets the number of vertices contained in the buffer.
Definition: types.hpp:523
ConstIterator begin() const
Definition: types.hpp:581
void addText(float x, float y, float z, const std::string &text)
Adds a string at the given position in object coordinates.
Definition: types.hpp:658
void vaoCleanup(GLuint vao)
Definition: types.hpp:88
array_layout
Definition: types.hpp:170
virtual size_t getStride() const
Gets the stride between vertices.
Definition: types.hpp:526
Handle(Handle &&other)
Definition: types.hpp:54
virtual GLenum getShape() const
Gets the primitive type contained by the vertex buffer.
Definition: types.hpp:525
void addVertices(const std::vector< T > &verts)
Add vertices to a buffer.
Definition: types.hpp:493
ConstIterator end() const
Definition: types.hpp:585
std::vector< T >::const_iterator ConstIterator
Definition: types.hpp:514
std::array< float, 3 > coord
Definition: types.hpp:232
void setHandle(int dev_hnd)
Definition: types.hpp:449
Handle(GLuint h)
Definition: types.hpp:52
void glNormal3d(double nx, double ny, double nz)
Definition: types.hpp:401
std::array< float, 3 > coord
Definition: types.hpp:249
virtual size_t count() const
Gets the number of vertices contained in the buffer.
Definition: types.hpp:476
std::array< float, 2 > texCoord
Definition: types.hpp:225
void addTriangleIndexed(const std::vector< Vert > &verts, const std::vector< int > &inds)
Definition: types.hpp:704
int getHandle() const
Definition: types.hpp:448
GlBuilder createBuilder()
Definition: types.hpp:731
glm::mat4 mtx
Definition: types.hpp:121
void addVertex(const T &vertex)
Add a vertex to the buffer.
Definition: types.hpp:487
virtual ~IVertexBuffer()
Definition: types.hpp:446
void ortho(double left, double right, double bottom, double top, double z_near, double z_far)
Sets the matrix to an orthographic projection.
Definition: types.hpp:147
void dspListCleanup(GLuint dlist)
Definition: types.hpp:73
Iterator end()
Gets an iterator pointing to the last text entry.
Definition: types.hpp:584
Iterator begin()
Gets an iterator referencing the first text entry.
Definition: types.hpp:580
void scale(double x, double y, double z)
Applies a scale transform to the matrix.
Definition: types.hpp:141
void rotate(float angle, double x, double y, double z)
Applies a rotation transform to the matrix.
Definition: types.hpp:124
void glTexCoord2f(float coord_u, float coord_v)
Definition: types.hpp:429
std::array< uint8_t, 4 > color
Definition: types.hpp:242
ConstIterator end() const
Definition: types.hpp:482
std::array< float, 3 > coord
Definition: types.hpp:224
void perspective(double fov, double aspect, double z_near, double z_far)
Sets the matrix to a perspective projection.
Definition: types.hpp:158
ConstIterator begin() const
Definition: types.hpp:481
Crude fixed-function OpenGL emulation helper.
Definition: types.hpp:261
std::array< float, 3 > coord
Definition: types.hpp:240
void addQuadIndexed(const std::vector< Vert > &verts, const std::vector< int > &inds)
Definition: types.hpp:711
void texCleanup(GLuint tex)
Definition: types.hpp:93
virtual size_t getStride() const
Gets the stride between vertices.
Definition: types.hpp:479
virtual const void * getData() const
Definition: types.hpp:531
void mult(glm::mat4 rhs)
Definition: types.hpp:129
std::vector< Entry >::iterator Iterator
Definition: types.hpp:560
void addVertices(const std::vector< T > &verts, const std::vector< int > &ids)
Definition: types.hpp:535
void addTriangle(const Vert &v1, const Vert &v2, const Vert &v3)
Definition: types.hpp:685
std::array< float, 3 > norm
Definition: types.hpp:233
void glVertex3dv(const double *d)
Definition: types.hpp:396
std::array< float, 3 > norm
Definition: types.hpp:241
void glColor4f(float r, float g, float b, float a)
Definition: types.hpp:409
std::vector< Entry >::const_iterator ConstIterator
Definition: types.hpp:561
void addQuad(const Vert &v1, const Vert &v2, const Vert &v3, const Vert &v4)
Definition: types.hpp:693
void boCleanup(GLuint vbo_hnd)
Definition: types.hpp:68
ConstIterator begin() const
Definition: types.hpp:528
void clear()
Clears the drawable object.
Definition: types.hpp:737
std::array< float, 3 > norm
Definition: types.hpp:250
virtual const void * getData() const
Definition: types.hpp:484
std::string text
Definition: types.hpp:555
void rboCleanup(GLuint rbo)
Definition: types.hpp:103
VertexBuffer(GLenum shape)
Definition: types.hpp:472
virtual void clear()
Clears the data stored in the vertex buffer.
Definition: types.hpp:517