Commit c19c0090 authored by Nicolas P. Rougier's avatar Nicolas P. Rougier

Merge pull request #32 from cforfang/VAO2

Use VAOs internally when FREETYPE_GL_USE_VAO is defined.
parents 683bae3b c1f64e14
......@@ -310,6 +310,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -218,6 +218,7 @@ int main( int argc, char **argv )
glutKeyboardFunc( keyboard );
glutIdleFunc( idle );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -32,7 +32,9 @@
* ========================================================================= */
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "vertex-buffer.h"
#include "markup.h"
#include "shader.h"
......
......@@ -705,6 +705,7 @@ main( int argc, char **argv )
glutSpecialFunc( on_special_key_press );
glutReshapeWindow( 600,400 );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -150,6 +150,7 @@ int main( int argc, char **argv )
//glutTimerFunc( 1000/60, timer, 1000/60 ); // not working on some systems (bug in GLUT)
glutIdleFunc(display);
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -272,6 +272,7 @@ main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -431,6 +431,7 @@ main( int argc, char **argv )
glutKeyboardFunc( keyboard );
glutTimerFunc( 1000.0/60, timer, 60 );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -256,6 +256,7 @@ main( int argc, char **argv )
glutPassiveMotionFunc( mouse_motion );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -156,6 +156,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -129,6 +129,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -186,6 +186,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -173,6 +173,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -192,6 +192,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -139,6 +139,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -106,6 +106,7 @@ int main( int argc, char **argv )
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
......
......@@ -39,7 +39,6 @@
#include "platform.h"
#include "vertex-buffer.h"
/**
* Buffer status
*/
......@@ -113,6 +112,10 @@ vertex_buffer_new( const char *format )
self->attributes[i]->stride = stride;
}
#ifdef FREETYPE_GL_USE_VAO
self->VAO_id = 0;
#endif
self->vertices = vector_new( stride );
self->vertices_id = 0;
self->GPU_vsize = 0;
......@@ -137,7 +140,6 @@ vertex_buffer_delete( vertex_buffer_t *self )
assert( self );
for( i=0; i<MAX_VERTEX_ATTRIBUTE; ++i )
{
if( self->attributes[i] )
......@@ -146,6 +148,13 @@ vertex_buffer_delete( vertex_buffer_t *self )
}
}
#ifdef FREETYPE_GL_USE_VAO
if( self->VAO_id )
{
glDeleteVertexArrays( 1, &self->VAO_id );
}
self->VAO_id = 0;
#endif
vector_delete( self->vertices );
self->vertices = 0;
......@@ -323,12 +332,53 @@ vertex_buffer_render_setup ( vertex_buffer_t *self, GLenum mode )
{
size_t i;
#ifdef FREETYPE_GL_USE_VAO
// Unbind so no existing VAO-state is overwritten,
// (e.g. the GL_ELEMENT_ARRAY_BUFFER-binding).
glBindVertexArray( 0 );
#endif
if( self->state != CLEAN )
{
vertex_buffer_upload( self );
self->state = CLEAN;
}
#ifdef FREETYPE_GL_USE_VAO
if( self->VAO_id == 0 )
{
// Generate and set up VAO
glGenVertexArrays( 1, &self->VAO_id );
glBindVertexArray( self->VAO_id );
glBindBuffer( GL_ARRAY_BUFFER, self->vertices_id );
for( i=0; i<MAX_VERTEX_ATTRIBUTE; ++i )
{
vertex_attribute_t *attribute = self->attributes[i];
if( attribute == 0 )
{
continue;
}
else
{
vertex_attribute_enable( attribute );
}
}
glBindBuffer( GL_ARRAY_BUFFER, 0 );
if( self->indices->size )
{
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, self->indices_id );
}
}
// Bind VAO for drawing
glBindVertexArray( self->VAO_id );
#else
glBindBuffer( GL_ARRAY_BUFFER, self->vertices_id );
for( i=0; i<MAX_VERTEX_ATTRIBUTE; ++i )
......@@ -348,6 +398,8 @@ vertex_buffer_render_setup ( vertex_buffer_t *self, GLenum mode )
{
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, self->indices_id );
}
#endif
self->mode = mode;
}
......@@ -355,8 +407,12 @@ vertex_buffer_render_setup ( vertex_buffer_t *self, GLenum mode )
void
vertex_buffer_render_finish ( vertex_buffer_t *self )
{
#ifdef FREETYPE_GL_USE_VAO
glBindVertexArray( 0 );
#else
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
#endif
}
......@@ -395,7 +451,6 @@ vertex_buffer_render ( vertex_buffer_t *self, GLenum mode )
vertex_buffer_render_setup( self, mode );
if( icount )
{
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, self->indices_id );
glDrawElements( mode, icount, GL_UNSIGNED_INT, 0 );
}
else
......
......@@ -42,7 +42,6 @@ extern "C" {
#include "vector.h"
#include "vertex-attribute.h"
/**
* @file vertex-buffer.h
* @author Nicolas Rougier (Nicolas.Rougier@inria.fr)
......@@ -65,6 +64,11 @@ typedef struct vertex_buffer_t
/** Vector of vertices. */
vector_t * vertices;
#ifdef FREETYPE_GL_USE_VAO
/** GL identity of the Vertex Array Object */
GLuint VAO_id;
#endif
/** GL identity of the vertices buffer. */
GLuint vertices_id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment