SimpleGL  1.1.0
A framework for platform independent rendering
batching.cpp
Go to the documentation of this file.
1 
8 #include "SimpleGL/batching.hpp"
9 
10 using namespace std;
11 using namespace glm;
12 
13 namespace sgl {
14 
15  Batch::Batch() {
16  /* Set MVP to identity */
17  transformation.model = Model::identity();
18  transformation.view = View::identity();
19  transformation.projection = Projection::identity();
20  transformation.changed = true;
21 
22  /* Initialize values */
23  drawing = false;
24  numVertices = 0;
25  }
26 
27  Batch::~Batch(void) {
28  /* Nothing to do here */
29  }
30 
31  void Batch::begin() {
32  /* Start drawing only if the batch isn't already drawing */
33  if (!drawing) {
34  drawing = true;
35  numVertices = 0;
36  }
37  }
38 
39  void Batch::end() {
40  /* End drawing only if the batch was drawing */
41  if (drawing) {
42  drawing = false;
43  flush();
44  }
45  }
46 
47  void Batch::vertex(float x, float y) {
48  vertex(vec2(x, y));
49  }
50 
51  void Batch::vertex(float x, float y, float z) {
52  vertex(vec3(x, y, z));
53  }
54 
55  void Batch::vertex(glm::vec2 vertex) {
56  Batch::vertex(vec3(vertex, 0.0f));
57  }
58 
59  void Batch::vertex(glm::vec3 vertex) {
60  vertices.push_back(vertex);
61  numVertices++;
62  }
63 
64  void Batch::color(float r, float g, float b) {
65  color(vec3(r, g, b));
66  }
67 
68  void Batch::color(float r, float g, float b, float a) {
69  color(vec4(r, g, b, a));
70  }
71 
72  void Batch::color(glm::vec3 color) {
73  Batch::color(vec4(color, 1.0f));
74  }
75 
76  void Batch::color(glm::vec4 color) {
77  colors.push_back(color);
78  }
79 
80  void Batch::texCoord(float s, float t) {
81  texCoord(vec2(s, t));
82  }
83 
84  void Batch::texCoord(glm::vec2 texCoord) {
85  texCoords.push_back(texCoord);
86  }
87 
88  void Batch::normal(float nx, float ny, float nz) {
89  normal(vec3(nx, ny, nz));
90  }
91 
92  void Batch::normal(glm::vec3 normal) {
93  normals.push_back(normal);
94  }
95 
96  void Batch::setModel(glm::mat4 model) {
97  transformation.model = model;
98  transformation.changed = true;
99  }
100 
101  glm::mat4 Batch::getModel() {
102  return transformation.model;
103  }
104 
105  void Batch::setView(glm::mat4 view) {
106  transformation.view = view;
107  transformation.changed = true;
108  }
109 
110  glm::mat4 Batch::getView() {
111  return transformation.view;
112  }
113 
114  void Batch::setProjection(glm::mat4 projection) {
115  transformation.projection = projection;
116  transformation.changed = true;
117  }
118 
119  glm::mat4 Batch::getProjection() {
120  return transformation.projection;
121  }
122 }
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18