Commit 960430bf authored by Olivier Lagrasse's avatar Olivier Lagrasse

Premiers tests sur les vbo

parent 5f6be819
......@@ -26,29 +26,103 @@ using namespace std;
**********************************/
Vbo::Vbo(){
}
Vbo::Vbo(int nb_verteces_per_object, int nb_object){
/* init class attributes */
_cur = 0;
_id = 0;
_nb_object = nb_object;
_nb_verteces_per_object = nb_verteces_per_object;
/*
* The is _nb_object*(number_of_vertices_per_object) elements.
* number_of_vertices_per_object is equal to 4 for container (a quad).
*/
_size = nb_verteces_per_object*_nb_object*sizeof(Element_pos);
/* init OpenGL */
// glGenBuffers(1, &_id);/* create the buffer an put its value to _id */
// glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
glGenBuffers(1, &_id);/* create the buffer an put its value to _id */
// glBufferData(GL_ARRAY_BUFFER, _size, NULL, GL_STATIC_DRAW);/* allocate memory space inside graphic card */
// glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
glBufferData(GL_ARRAY_BUFFER, _size, NULL, GL_STATIC_DRAW);/* allocate memory space inside graphic card */
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
}
Vbo::~Vbo(){
//glDeleteBuffers(1, &_id);/* release the buffer and free its memory inside graphic card */
glDeleteBuffers(1, &_id);/* release the buffer and free its memory inside graphic card */
}
/***********************************
*
*
*
* Buffer filling.
*
*
*
**********************************/
int Vbo::fill_buffer(int data_size, Element_pos* data){
glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
if ( (_cur+data_size) <= _size){
glBufferSubData(GL_ARRAY_BUFFER, _cur, data_size, data);
_cur += data_size;
}else{
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
return Vbo::VBO_OUT_OF_MEMORY;
}
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
return Vbo::VBO_OK;
}
int Vbo::get_remaining_size(){
return (_size-_cur);
}
/***********************************
*
*
*
* Buffer display.
*
*
*
**********************************/
void Vbo::display_buffer(){
glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
glVertexPointer(_nb_verteces_per_object, GL_DOUBLE, 0, BUFFER_OFFSET(0));/* give to OpenGL the VBO adress */
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_QUADS, 0, _cur);/* RENDERING */
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
}
......@@ -5,6 +5,7 @@
#ifndef VBO_HPP
#define VBO_HPP
#define BUFFER_OFFSET(a) ((char*)NULL + (a))/* OpenGL special macro */
class Vbo;
......@@ -22,20 +23,38 @@ class Vbo{
protected:
/*!
* \brief The vbo instance identity.
* \brief Number of verteces per objects.
*/
GLuint _id;
int _nb_verteces_per_object;
/*!
* \brief Number of objects (container, entity...) per vbo.
*/
int _nb_object;
/*!
* \brief The size of the vbo buffer. Must be defined on inherited classes.
*/
int _size;
/*!
* \brief The size of the vbo buffer. (10 000 verteces)
* \brief The vbo instance identity.
*/
static const int _size = 100;
GLuint _id;
/*!
* \brief Define the position indicator inside the VBO buffer. Must be lesser than _size !
*/
int _cur;
private:
/*!
* \brief The default constructor. Cannot be use for instantiation.
*/
Vbo();
public:
/***********************************
......@@ -44,10 +63,13 @@ public:
*
**********************************/
/*!
* \brief The default constructor.
/*!
* \brief Constructor.
* \arg nb_verteces_per_object Number of verteces per object.
* \arg nb_object Number of objects. Object can be a container or entity.
* \arg size The whole size of the vertex buffer.
*/
Vbo();
Vbo(int nb_verteces_per_object, int nb_object);
/*!
* \brief The destructor.
......@@ -79,6 +101,9 @@ public:
/*!
* \brief Fill the vertex buffer object.
* \arg data_size The vertex buffer data size.
* \arg data A vertex buffer to be display.
*
* \return The state of the buffer.
*
* This function is called for each vertex, so it is an inline function. It can return several number :
......@@ -88,7 +113,15 @@ public:
* <li><b>VBO_UNDEFINED_ERROR</b>: an error occurs but has not been identified.
* </ul>
*/
virtual int fill_buffer() = 0;
int fill_buffer(int data_size, Element_pos* data);
/*!
* \brief Return the remaining size of the buffer object.
*
* \return Number corresponding to the case number remaining.
*/
int get_remaining_size();
......@@ -101,7 +134,7 @@ public:
/*!
* \brief Display the VBO list inside the OpenGL area.
*/
virtual void display_buffer() = 0;
void display_buffer();
};
......
......@@ -22,8 +22,7 @@ using namespace std;
*
**********************************/
Vbo_container::Vbo_container(){
Vbo_container::Vbo_container():Vbo(4, 1000){
}
......@@ -32,17 +31,3 @@ Vbo_container::~Vbo_container(){
}
/***********************************
*
*
*
* Buffer display.
*
*
*
**********************************/
void Vbo_container::display_buffer(){
}
......@@ -18,7 +18,6 @@ class Vbo_container;
*/
class Vbo_container : public Vbo{
protected:
public:
......@@ -39,78 +38,7 @@ public:
*/
virtual ~Vbo_container();
/***********************************
*
* Buffer filling.
*
**********************************/
/*!
* \brief Fill the vertex buffer object.
* \return The state of the buffer.
*
* This function is called for each vertex, so it is an inline function. It can return several number :
* <ul>
* <li><b>VBO_OK</b>: data have been added to graphic card. No error.
* <li><b>VBO_OUT_OF_MEMORY</b>: buffer is full. Another VBO must be create.
* <li><b>VBO_UNDEFINED_ERROR</b>: an error occurs but has not been identified.
* </ul>
*/
int fill_buffer();
/***********************************
*
* Buffer display.
*
**********************************/
/*!
* \brief Display the VBO list inside the OpenGL area.
*/
void display_buffer();
};
/***********************************
*
*
*
* Buffer filling.
*
*
*
**********************************/
inline int Vbo_container::fill_buffer(){
Element_pos* data;
int data_size;
// glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
// if ( (_cur+data_size) < _size){
// glBufferSubData(GL_ARRAY_BUFFER, _cur, data_size, data);
// _cur += data_size;
// }else{
// return Vbo::VBO_OUT_OF_MEMORY;
// }
// glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
return Vbo::VBO_OK;
}
#endif
#endif
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