23
23
using namespace gl ;
24
24
using namespace std ;
25
25
26
- void generateGridIndices (unsigned short rows, unsigned short cols, unsigned short *indices)
26
+ void generateGridIndices (std::vector<unsigned int >& indices,
27
+ unsigned short rows, unsigned short cols)
27
28
{
28
- unsigned short idx = 0 ;
29
- for (unsigned short r = 0 ; r < rows-1 ; ++r){
30
- for (unsigned short c = 0 ; c < cols*2 ; ++c){
31
- unsigned short i = c + (r * (cols*2 ));
32
-
33
- if (c == cols * 2 - 1 ) {
34
- *indices++ = idx;
35
- }else {
36
- *indices++ = idx;
37
- if (i%2 == 0 ){
38
- idx += cols;
39
- } else {
40
- idx -= (r%2 == 0 ) ? (cols-1 ) : (cols+1 );
41
- }
29
+ const int numDegens = 2 * (rows - 2 );
30
+ const int verticesPerStrip = 2 * cols;
31
+
32
+ // reserve the size of vector
33
+ indices.reserve (verticesPerStrip + numDegens);
34
+
35
+ for (int r = 0 ; r < (rows-1 ); ++r) {
36
+ if (r > 0 ) {
37
+ // repeat first vertex for degenerate triangle
38
+ indices.push_back (r*rows);
39
+ }
40
+
41
+ for (int c = 0 ; c < cols; ++c) {
42
+ // One part of the strip
43
+ indices.push_back (r*rows + c);
44
+ indices.push_back ((r+1 )*rows + c);
45
+ }
46
+
47
+ if (r < (rows-2 )) {
48
+ // repeat last vertex for degenerate triangle
49
+ indices.push_back (((r + 1 ) * rows) + (cols - 1 ));
42
50
}
43
51
}
44
52
}
45
- }
46
53
47
54
namespace forge
48
55
{
@@ -51,36 +58,36 @@ namespace opengl
51
58
52
59
void surface_impl::bindResources (const int pWindowId)
53
60
{
54
- if (mVAOMap .find (pWindowId) == mVAOMap .end ()) {
55
- GLuint vao = 0 ;
56
- /* create a vertex array object
57
- * with appropriate bindings */
58
- glGenVertexArrays (1 , &vao);
59
- glBindVertexArray (vao);
60
- // attach plot vertices
61
- glEnableVertexAttribArray (mSurfPointIndex );
62
- glBindBuffer (GL_ARRAY_BUFFER, mVBO );
63
- glVertexAttribPointer (mSurfPointIndex , 3 , mDataType , GL_FALSE, 0 , 0 );
64
- glEnableVertexAttribArray (mSurfColorIndex );
65
- glBindBuffer (GL_ARRAY_BUFFER, mCBO );
66
- glVertexAttribPointer (mSurfColorIndex , 3 , GL_FLOAT, GL_FALSE, 0 , 0 );
67
- glEnableVertexAttribArray (mSurfAlphaIndex );
68
- glBindBuffer (GL_ARRAY_BUFFER, mABO );
69
- glVertexAttribPointer (mSurfAlphaIndex , 1 , GL_FLOAT, GL_FALSE, 0 , 0 );
70
- // attach indices
71
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, mIBO );
72
- glBindVertexArray (0 );
73
- /* store the vertex array object corresponding to
74
- * the window instance in the map */
75
- mVAOMap [pWindowId] = vao;
76
- }
61
+ if (mVAOMap .find (pWindowId) == mVAOMap .end ()) {
62
+ GLuint vao = 0 ;
63
+ /* create a vertex array object
64
+ * with appropriate bindings */
65
+ glGenVertexArrays (1 , &vao);
66
+ glBindVertexArray (vao);
67
+ // attach plot vertices
68
+ glEnableVertexAttribArray (mSurfPointIndex );
69
+ glBindBuffer (GL_ARRAY_BUFFER, mVBO );
70
+ glVertexAttribPointer (mSurfPointIndex , 3 , mDataType , GL_FALSE, 0 , 0 );
71
+ glEnableVertexAttribArray (mSurfColorIndex );
72
+ glBindBuffer (GL_ARRAY_BUFFER, mCBO );
73
+ glVertexAttribPointer (mSurfColorIndex , 3 , GL_FLOAT, GL_FALSE, 0 , 0 );
74
+ glEnableVertexAttribArray (mSurfAlphaIndex );
75
+ glBindBuffer (GL_ARRAY_BUFFER, mABO );
76
+ glVertexAttribPointer (mSurfAlphaIndex , 1 , GL_FLOAT, GL_FALSE, 0 , 0 );
77
+ // attach indices
78
+ glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, mIBO );
79
+ glBindVertexArray (0 );
80
+ /* store the vertex array object corresponding to
81
+ * the window instance in the map */
82
+ mVAOMap [pWindowId] = vao;
83
+ }
77
84
78
- glBindVertexArray (mVAOMap [pWindowId]);
85
+ glBindVertexArray (mVAOMap [pWindowId]);
79
86
}
80
87
81
88
void surface_impl::unbindResources () const
82
89
{
83
- glBindVertexArray (0 );
90
+ glBindVertexArray (0 );
84
91
}
85
92
86
93
glm::mat4 surface_impl::computeTransformMat (const glm::mat4& pView, const glm::mat4& pOrient)
@@ -120,11 +127,11 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform)
120
127
glUniform1i (mSurfPVAIndex , mIsPVAOn );
121
128
122
129
bindResources (pWindowId);
123
- glDrawElements (GL_TRIANGLE_STRIP, mIBOSize , GL_UNSIGNED_SHORT , (void *)0 );
130
+ glDrawElements (GL_TRIANGLE_STRIP, mIBOSize , GL_UNSIGNED_INT , (void *)0 );
124
131
unbindResources ();
125
132
mSurfProgram .unbind ();
126
133
127
- if (mMarkerType != FG_MARKER_NONE) {
134
+ if (mMarkerType != FG_MARKER_NONE) {
128
135
glEnable (GL_PROGRAM_POINT_SIZE);
129
136
mMarkerProgram .bind ();
130
137
@@ -135,7 +142,7 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform)
135
142
glUniform4fv (mMarkerColIndex , 1 , mColor );
136
143
137
144
bindResources (pWindowId);
138
- glDrawElements (GL_POINTS, mIBOSize , GL_UNSIGNED_SHORT , (void *)0 );
145
+ glDrawElements (GL_POINTS, mIBOSize , GL_UNSIGNED_INT , (void *)0 );
139
146
unbindResources ();
140
147
141
148
mMarkerProgram .unbind ();
@@ -201,10 +208,13 @@ surface_impl::surface_impl(unsigned pNumXPoints, unsigned pNumYPoints,
201
208
202
209
#undef SURF_CREATE_BUFFERS
203
210
204
- mIBOSize = (2 * mNumYPoints ) * (mNumXPoints - 1 );
205
- std::vector<ushort > indices (mIBOSize );
206
- generateGridIndices (mNumXPoints , mNumYPoints , indices.data ());
207
- mIBO = createBuffer<ushort >(GL_ELEMENT_ARRAY_BUFFER, mIBOSize , indices.data (), GL_STATIC_DRAW);
211
+ std::vector<unsigned int > indices;
212
+
213
+ generateGridIndices (indices, mNumXPoints , mNumYPoints );
214
+
215
+ mIBOSize = indices.size ();
216
+
217
+ mIBO = createBuffer<uint >(GL_ELEMENT_ARRAY_BUFFER, mIBOSize , indices.data (), GL_STATIC_DRAW);
208
218
209
219
CheckGL (" End surface_impl::surface_impl" );
210
220
}
@@ -256,7 +266,7 @@ void scatter3_impl::renderGraph(const int pWindowId, const glm::mat4& transform)
256
266
glUniform4fv (mMarkerColIndex , 1 , mColor );
257
267
258
268
bindResources (pWindowId);
259
- glDrawElements (GL_POINTS, mIBOSize , GL_UNSIGNED_SHORT , (void *)0 );
269
+ glDrawElements (GL_POINTS, mIBOSize , GL_UNSIGNED_INT , (void *)0 );
260
270
unbindResources ();
261
271
262
272
mMarkerProgram .unbind ();
0 commit comments