OGLplus (0.52.0) a C++ wrapper for OpenGL

screen.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_SCREEN_1107121519_HPP
14 #define OGLPLUS_SHAPES_SCREEN_1107121519_HPP
15 
16 #include <oglplus/shapes/draw.hpp>
17 #include <oglplus/math/vector.hpp>
18 #include <oglplus/math/sphere.hpp>
19 #include <oglplus/face_mode.hpp>
20 
22 
23 #include <oglplus/math/sphere.hpp>
24 
25 #include <cassert>
26 #include <cmath>
27 
28 namespace oglplus {
29 namespace shapes {
30 
32 class Screen
33  : public DrawingInstructionWriter
34  , public DrawMode
35 {
36 public:
39  {
40  return FaceOrientation::CW;
41  }
42 
44  template <typename T>
45  GLuint Normals(std::vector<T>& dest) const
46  {
47  unsigned k = 0;
48  dest.resize(12);
49 
50  for(unsigned i=0; i!=4; ++i)
51  {
52  dest[k++] = T(0);
53  dest[k++] = T(0);
54  dest[k++] = T(1);
55  }
56  assert(k == dest.size());
57  // 3 values per vertex
58  return 3;
59  }
60 
62  template <typename T>
63  GLuint Tangents(std::vector<T>& dest) const
64  {
65  unsigned k = 0;
66  dest.resize(12);
67 
68  for(unsigned i=0; i!=4; ++i)
69  {
70  dest[k++] = T(1);
71  dest[k++] = T(0);
72  dest[k++] = T(0);
73  }
74  assert(k == dest.size());
75  // 3 values per vertex
76  return 3;
77  }
78 
80  template <typename T>
81  GLuint Bitangents(std::vector<T>& dest) const
82  {
83  unsigned k = 0;
84  dest.resize(12);
85 
86  for(unsigned i=0; i!=4; ++i)
87  {
88  dest[k++] = T(0);
89  dest[k++] = T(1);
90  dest[k++] = T(0);
91  }
92  assert(k == dest.size());
93  // 3 values per vertex
94  return 3;
95  }
96 
98  template <typename T>
99  GLuint Positions(std::vector<T>& dest) const
100  {
101  unsigned k = 0;
102  dest.resize(8);
103 
104  dest[k++] = T(-1);
105  dest[k++] = T(-1);
106 
107  dest[k++] = T(-1);
108  dest[k++] = T(+1);
109 
110  dest[k++] = T(+1);
111  dest[k++] = T(-1);
112 
113  dest[k++] = T(+1);
114  dest[k++] = T(+1);
115 
116  assert(k == dest.size());
117  // 2 values per vertex
118  return 2;
119  }
120 
122  template <typename T>
123  GLuint TexCoordinates(std::vector<T>& dest) const
124  {
125  unsigned k = 0;
126  dest.resize(8);
127 
128  dest[k++] = T(0);
129  dest[k++] = T(0);
130 
131  dest[k++] = T(0);
132  dest[k++] = T(1);
133 
134  dest[k++] = T(1);
135  dest[k++] = T(0);
136 
137  dest[k++] = T(1);
138  dest[k++] = T(1);
139 
140  assert(k == dest.size());
141  // 2 values per vertex
142  return 2;
143  }
144 
145 #if OGLPLUS_DOCUMENTATION_ONLY
146 
155  typedef VertexAttribsInfo<Screen> VertexAttribs;
156 #else
157  typedef VertexAttribsInfo<
158  Screen,
159  std::tuple<
160  VertexPositionsTag,
161  VertexNormalsTag,
162  VertexTangentsTag,
163  VertexBitangentsTag,
164  VertexTexCoordinatesTag
165  >
166  > VertexAttribs;
167 #endif
168 
170  template <typename T>
171  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
172  {
173  bounding_sphere = oglplus::Sphere<T>(T(0), T(0), T(0), T(1));
174  }
175 
177  typedef std::vector<GLuint> IndexArray;
178 
180  IndexArray Indices(Default = Default()) const
181  {
182  return IndexArray();
183  }
184 
187  {
188  auto instructions = this->MakeInstructions();
189 
190  DrawOperation operation;
191  operation.method = DrawOperation::Method::DrawArrays;
193  operation.first = GLuint(0);
194  operation.count = 4;
196  operation.phase = 0;
197  this->AddInstruction(instructions, operation);
198 
199  return instructions;
200  }
201 };
202 
203 } // shapes
204 } // oglplus
205 
206 #endif // include guard
Implementation of shape draw instructions.
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering.
Definition: screen.hpp:186
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: screen.hpp:171
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: screen.hpp:99
GLuint Bitangents(std::vector< T > &dest) const
Makes vertex bi-tangents and returns number of values per vertex.
Definition: screen.hpp:81
Sphere utility class.
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
Definition: screen.hpp:180
GLuint first
The first element.
Definition: draw.hpp:111
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: screen.hpp:38
GLuint Normals(std::vector< T > &dest) const
Makes vertex normals and returns number of values per vertex.
Definition: screen.hpp:45
PrimitiveType mode
The primitive type to be used to draw.
Definition: draw.hpp:108
GLuint restart_index
Primitive restart index.
Definition: draw.hpp:126
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture-coorinates and returns number of values per vertex.
Definition: screen.hpp:123
static GLuint NoRestartIndex(void)
Special constant for disabling primitive restart.
Definition: draw.hpp:117
Structure containing information about how to draw a part of a shape.
Definition: draw.hpp:100
GLuint count
Count of elements.
Definition: draw.hpp:114
Class providing vertex attributes and instructions for rendering of a Screen.
Definition: screen.hpp:32
Method method
The method to be used to draw.
Definition: draw.hpp:106
VertexAttribsInfo< Screen > VertexAttribs
Vertex attribute information for this shape builder.
Definition: screen.hpp:155
Classes providing additional information about the shape builders.
GLuint phase
The phase of the drawing process.
Definition: draw.hpp:135
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
GLuint Tangents(std::vector< T > &dest) const
Makes vertex tangents and returns number of values per vertex.
Definition: screen.hpp:63
A vector class.
std::vector< GLuint > IndexArray
The type of index container returned by Indices()
Definition: screen.hpp:177

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).