4 #include <ivorium_config.hpp>
11 _position_buffer( 0 ),
12 _texcoord_buffer( 0 ),
15 #if IV_ENABLE_TRANSFORM_FEEDBACK
16 , _tf_triangles_cnt( 0 )
31 return this->_indices_cnt;
39 glGenVertexArrays( 1, &this->_vao );
47 if( !this->_position_buffer )
50 glGenBuffers( 1, &this->_position_buffer );
53 glBindBuffer( GL_ARRAY_BUFFER, this->_position_buffer );
54 glBindVertexArray( this->_vao );
57 glBindVertexArray( 0 );
58 glBindBuffer( GL_ARRAY_BUFFER, 0 );
62 glBindBuffer( GL_ARRAY_BUFFER, this->_position_buffer );
63 glBufferData( GL_ARRAY_BUFFER,
sizeof(
float ) * length, data, GL_STATIC_DRAW );
64 glBindBuffer( GL_ARRAY_BUFFER, 0 );
74 if( !this->_texcoord_buffer )
77 glGenBuffers( 1, &this->_texcoord_buffer );
80 glBindBuffer( GL_ARRAY_BUFFER, this->_texcoord_buffer );
81 glBindVertexArray( this->_vao );
84 glBindVertexArray( 0 );
85 glBindBuffer( GL_ARRAY_BUFFER, 0 );
89 glBindBuffer( GL_ARRAY_BUFFER, this->_texcoord_buffer );
90 glBufferData( GL_ARRAY_BUFFER,
sizeof(
float ) * length, data, GL_STATIC_DRAW );
91 glBindBuffer( GL_ARRAY_BUFFER, 0 );
101 this->_draw_mode = draw_mode;
103 #if IV_ENABLE_TRANSFORM_FEEDBACK
105 size_t triangles = 0;
106 if( draw_mode == GL_TRIANGLE_STRIP )
109 for(
size_t i = 0; i < length; i++ )
124 this->_tf_triangles_cnt = triangles;
129 if( !this->_indices_buffer )
132 glGenBuffers( 1, &this->_indices_buffer );
135 glBindVertexArray( this->_vao );
136 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->_indices_buffer );
137 glBindVertexArray( 0 );
138 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
141 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->_indices_buffer );
142 glBufferData( GL_ELEMENT_ARRAY_BUFFER,
sizeof( GLuint ) * length, data, GL_STATIC_DRAW );
143 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
145 this->_indices_cnt = length;
147 #if IV_ENABLE_TRANSFORM_FEEDBACK
148 if( this->_tf_buffer )
149 glDeleteBuffers( 1, &this->_tf_buffer );
151 glGenBuffers( 1, &this->_tf_buffer );
152 glBindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER, this->_tf_buffer );
153 glBufferData( GL_TRANSFORM_FEEDBACK_BUFFER,
sizeof(
float ) * this->_tf_triangles_cnt * 3 * 4,
nullptr, GL_DYNAMIC_READ );
154 glBindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER, 0 );
156 this->_tf_data.resize( this->_tf_triangles_cnt * 3 * 4 );
166 glDeleteVertexArrays( 1, &this->_vao );
170 if( this->_position_buffer )
172 glDeleteBuffers( 1, &this->_position_buffer );
173 this->_position_buffer = 0;
176 if( this->_texcoord_buffer )
178 glDeleteBuffers( 1, &this->_texcoord_buffer );
179 this->_texcoord_buffer = 0;
182 if( this->_indices_buffer )
184 glDeleteBuffers( 1, &this->_indices_buffer );
185 this->_indices_buffer = 0;
188 #if IV_ENABLE_TRANSFORM_FEEDBACK
189 if( this->_tf_buffer )
191 glDeleteBuffers( 1, &this->_tf_buffer );
192 this->_tf_buffer = 0;
196 this->_indices_cnt = 0;
197 this->_draw_mode = GL_TRIANGLE_STRIP;
205 this->_position_buffer = 0;
206 this->_texcoord_buffer = 0;
207 this->_indices_buffer = 0;
208 this->_indices_cnt = 0;
209 #if IV_ENABLE_TRANSFORM_FEEDBACK
210 this->_tf_buffer = 0;
212 this->_draw_mode = GL_TRIANGLE_STRIP;
220 #if IV_ENABLE_TRANSFORM_FEEDBACK
224 glBindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0, this->_tf_buffer );
225 glBeginTransformFeedback( GL_TRIANGLES );
229 glBindVertexArray( this->_vao );
230 glDrawElements( this->_draw_mode, this->_indices_cnt, GL_UNSIGNED_INT,
nullptr );
231 glBindVertexArray( 0 );
233 #if IV_ENABLE_TRANSFORM_FEEDBACK
237 glEndTransformFeedback();
240 glBindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0 );
241 glBindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER, this->_tf_buffer );
244 size_t tf_buffer_length =
sizeof( float ) * this->_tf_triangles_cnt * 3 * 4;
245 #if IV_GLPLATFORM_GLFW
247 glGetBufferSubData( GL_TRANSFORM_FEEDBACK_BUFFER, 0, tf_buffer_length, (
void*)this->_tf_data.data() );
249 #elif IV_GLPLATFORM_GLFM
251 void * buff = glMapBufferRange( GL_TRANSFORM_FEEDBACK_BUFFER, 0, tf_buffer_length, GL_MAP_READ_BIT );
253 memcpy( (
void*)this->_tf_data.data(), buff, tf_buffer_length );
257 glUnmapBuffer( GL_TRANSFORM_FEEDBACK_BUFFER );
261 #error "Unknown OpenGL platform."
265 glBindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER, 0 );
267 for(
size_t i = 0; i < this->_tf_triangles_cnt; i++ )
272 " (", this->_tf_data[ i*12 + 0 ],
", ", this->_tf_data[ i*12 + 1 ],
", ", this->_tf_data[ i*12 + 2 ],
", ", this->_tf_data[ i*12 + 3 ],
")",
Context::Endl(),
273 " (", this->_tf_data[ i*12 + 4 ],
", ", this->_tf_data[ i*12 + 5 ],
", ", this->_tf_data[ i*12 + 6 ],
", ", this->_tf_data[ i*12 + 7 ],
")",
Context::Endl(),
274 " (", this->_tf_data[ i*12 + 8 ],
", ", this->_tf_data[ i*12 + 9 ],
", ", this->_tf_data[ i*12 + 10 ],
", ", this->_tf_data[ i*12 + 11 ],
")",