Commit 4b021d87 authored by Olivier Lagrasse's avatar Olivier Lagrasse

- Integration des vbo (actuellement pour les conteneurs)

- Message::endsi permet d'ecrire dans la zone d'information des 
selections
- Debut gestion des selections
parent 1f94d338
......@@ -41,6 +41,13 @@ class Interface{
*/
virtual void information(const std::string) const =0;
/*!
*\arg string : the string to be displayed.
*\brief The function takes strings and/or numbers then displayed it in the entity informative text area in the info window (use in graphic interface).
*/
virtual void selection_information(const std::string) const =0;
/*!
\brief Return the name of the file opened.
*/
......
......@@ -33,6 +33,7 @@ Interface_console::Interface_console(int argc, char ** argv){
app = new QApplication(argc, argv);/* create the Qt application */
_run_env[0] = QDir::currentPath();
_run_env[1] = argv[0];
......
......@@ -294,6 +294,13 @@ protected:
*/
void information(const std::string) const;
/*!
*\arg string : the string to be displayed.
*\brief Only use in graphic interface.
*/
void selection_information(const std::string) const{
}
};
......
......@@ -72,7 +72,8 @@ void Interface_graphic::load_windows(){
/* Load widget from the .ui file */
CKFP(_ui_render_area_layout = qFindChild<QVBoxLayout*>(this, "render_area_layout"), "Cannot find the render_area layout in the .ui file");
CKFP(_ui_fullscreen_menu = qFindChild<QAction*>(this, "fullscreen"), "Cannot find the fullscreen menu in the .ui file");
CKFP(_ui_info_trace_text = qFindChild<QTextEdit*>(this, "info_trace_text"), "Cannot find the info_trace_text QTextEdit widget in the .ui file");
CKFP(_ui_info_trace_text = qFindChild<QTextEdit*>(_ui_info_window, "info_trace_text"), "Cannot find the info_trace_text QTextEdit widget in the .ui file");
CKFP(_ui_info_selection_text = qFindChild<QTextEdit*>(_ui_info_window, "info_selection_text"), "Cannot find the info_selection_text QTextEdit widget in the .ui file");
CKFP(_ui_toolbar_check = qFindChild<QAction*>(this, "toolbar_menu"), "Cannot find the tool bar checker in the .ui file");
CKFP(_ui_toolbar = qFindChild<QToolBar*>(this, "toolBar"), "Cannot find the tool bar in the .ui file");
......@@ -130,6 +131,31 @@ void Interface_graphic::information(const string s) const{
/***********************************
*
*
*
* Selected Trace entity informative function.
*
*
*
**********************************/
void Interface_graphic::selection_information(const string s) const{
QString buf = s.c_str();
_ui_info_selection_text->clear();/* Clear the current text (if exists) */
_ui_info_selection_text->insertHtml("<font color='blue'>"+buf+"</font><br /><br />");
_ui_info_window->show();/* show info_window */
}
/***********************************
*
*
......@@ -246,12 +272,21 @@ void Interface_graphic::on_close_triggered(){
if(_is_rendering_trace == false)
return;
/*
* Clear the informative window texts and hide it.
*/
_ui_info_trace_text->clear();/* Clear the current text (if exists) */
_ui_info_selection_text->clear();/* Clear the current text (if exists) */
_ui_info_window->hide();/* Hide the informative window */
_core->launch_action(Interface_console::_STATE_RELEASE_RENDER_AREA);
_is_rendering_trace = false;
information(string("File closed."));
......
......@@ -105,6 +105,11 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
*/
QTextEdit* _ui_info_trace_text;
/*!
* \brief Text area which informs the user about the selected entity information.
*/
QTextEdit* _ui_info_selection_text;
/***********************************
......@@ -157,7 +162,7 @@ public:
/*!
* \arg string : the string to be displayed.
*\brief The function takes strings and/or numbers then displayed an info box containing it, then the application will be killed.
*\brief The function takes strings and/or numbers then displayed an info box containing it, then the program go on with an indeterminated behaviour.
*/
void error(const std::string) const;
......@@ -175,13 +180,19 @@ public:
*/
void information(const std::string) const;
/*!
* \brief Get the name of the current trace file.
/***********************************
*
* \return The name of the current trace file
*/
const std::string get_filename() const;
* Selected Trace entity informative function.
*
**********************************/
/*!
*\arg string : the string to be displayed.
*\brief The function takes strings and/or numbers then displayed it in the entity informative text area in the info window.
*/
void selection_information(const std::string) const;
......@@ -316,6 +327,14 @@ protected slots:
* This function can be used to display message for user to store its work before application closes.
*/
void closeEvent(QCloseEvent *event);
/*!
* \brief Get the name of the current trace file.
*
* \return The name of the current trace file
*/
const std::string get_filename() const;
};
......
......@@ -66,3 +66,17 @@ std::ostream &operator<<(std::ostream &out, Message::end_information_t) {
}
return out;
}
std::ostream &operator<<(std::ostream &out, Message::end_selection_information_t) {
Message *message = Message::get_instance();
Interface *interface = Message::get_interface();
if (interface) {
interface->selection_information(message->str());
message->str(""); // flush the stream
} else {
std::cerr << "Warning: no interface designed to display messages." << std::endl;
}
return out;
}
......@@ -23,6 +23,10 @@ public:
std::cerr <<"INFORMATION: " << s << std::endl;
}
void selection_information(const std::string& s) {
std::cerr <<"INFORMATION: " << s << std::endl;
}
std::string get_filename(){
return "filename ";
}
......@@ -41,6 +45,7 @@ public:
static const struct end_error_t { } ende;
static const struct end_warning_t { } endw;
static const struct end_information_t { } endi;
static const struct end_selection_information_t { } endsi;
static Message *get_instance();
static void kill();
......@@ -53,6 +58,7 @@ public:
std::ostream &operator<<(std::ostream &, Message::end_error_t);
std::ostream &operator<<(std::ostream &, Message::end_warning_t);
std::ostream &operator<<(std::ostream &, Message::end_information_t);
std::ostream &operator<<(std::ostream &, Message::end_selection_information_t);
#endif
This diff is collapsed.
......@@ -15,6 +15,8 @@ class Render_opengl;
#include "render.hpp"
#include "vbo.hpp"
#include "resource.hpp"
......@@ -132,6 +134,43 @@ class Render_opengl : public QGLWidget, public Render
/***********************************
*
* VBO tools attributes.
*
**********************************/
/*!
* \brief The VBO linked list which store all the VBO types (containers, states, etc.).
*/
struct List_vbo{
Vbo* data;
List_vbo* next;
}_list_vbo, _list_vbo_arrow;
/*!
* \brief Use to browser the VBO linked list: List_vbo.
*/
List_vbo* _list_vbo_browser;
/*!
* \brief Buffer uses to temporary store container values.
*/
Element_pos* _vbo_container_buf;
/*!
* \brief Size of the container value temporary storing buffer.
*/
unsigned int _vbo_container_size;
/*!
* \brief Cursor to browse the container value temporary storing buffer.
*/
unsigned int _vbo_container_cur;
/***********************************
*
* Default QGLWidget functions.
......@@ -214,6 +253,11 @@ class Render_opengl : public QGLWidget, public Render
*/
float _wait_angle;
/*!
* \brief Y rotation angle for the wait.
*/
float _wait_angle_y;
/*!
* \brief Time in ms between two frames for the waiting screen.
*/
......@@ -420,6 +464,18 @@ class Render_opengl : public QGLWidget, public Render
virtual ~Render_opengl();
/***********************************
*
* VBO linked list function.
*
**********************************/
/*!
* \brief Release the VBO linked list in _list_vbo.
*/
void vbo_list_release();
/***********************************
*
* Building functions.
......@@ -619,35 +675,95 @@ inline void Render_opengl::start_draw(){
/* clear the arrow vector */
_arrows.clear();
//vbo_list_release();/* Release all the vbo list */
}
inline void Render_opengl::start_draw_containers(){
// inline void Render_opengl::start_draw_containers(){
_list_containers = glGenLists(1);/* create the list */
if (_list_containers==0){
// _list_containers = glGenLists(1);/* create the list */
// if (_list_containers==0){
// _parent->warning("Error when creating list");
// // _parent->warning("Error when creating list");
// }
// glNewList(_list_containers, GL_COMPILE);/* open the list */
// }
inline void Render_opengl::start_draw_containers(){
/*
* Container start draw function is called once for each trace
* so a new container VBO is first created.
*/
/*
* Init the buffer which will received data from de Data Structure.
*/
_vbo_container_cur = 0;
_vbo_container_size = 2*4*10000;/* 2 coordinates (x and y) - 4 verteces per objects - 10 000 objects */
if (NULL == _vbo_container_buf){
_vbo_container_buf = new Element_pos[_vbo_container_size];
}else{
*Message::get_instance() << "VBO buffer container has not be desallocated." << Message::ende;
}
glNewList(_list_containers, GL_COMPILE);/* open the list */
/*
* Browse the VBO linked list to find the last List_vbo element and then to create our new Container VBO.
*/
for(_list_vbo_browser = &_list_vbo ;
NULL != _list_vbo_browser->next;
_list_vbo_browser = _list_vbo_browser->next){
if (NULL == _list_vbo_browser->data)/* A quick check */
*Message::get_instance() << "Corruption into the VBO linked list (Draw container)" << Message::ende;
}
if (NULL != _list_vbo_browser->data){/* It is not the first vbo of the linked list. So create a new VBO list structure. */
_list_vbo_browser->next = new List_vbo();/* Create a new vbo */
_list_vbo_browser = _list_vbo_browser->next;/* Set the browsing pointer on this new VBO */
}
_list_vbo_browser->data = new Vbo_container();/* Create a new container VBO using polymorphism */
_list_vbo_browser->next = NULL;/* init for a future creation */
}
inline void Render_opengl::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) {
float j=0.6;
if ( (_vbo_container_cur+8) < _vbo_container_size){
_vbo_container_buf[_vbo_container_cur++] = x;
_vbo_container_buf[_vbo_container_cur++] = y;
_vbo_container_buf[_vbo_container_cur++] = x;
_vbo_container_buf[_vbo_container_cur++] = y+h;
_vbo_container_buf[_vbo_container_cur++] = x+w;
_vbo_container_buf[_vbo_container_cur++] = y+h;
_vbo_container_buf[_vbo_container_cur++] = x+w;
_vbo_container_buf[_vbo_container_cur++] = y;
}else{/* Not enough place in the temporary buffer. Must empty it in the Video RAM (the VBO). */
/* MUST TAKE CARE IF FUNCTION RETURNS NOT ENOUGH MEMORY -> HAVE TO CREATE A NEW VBO */
_list_vbo_browser->data->fill_buffer(_vbo_container_cur, _vbo_container_buf);/* Write on VRAM all the buffer */
_vbo_container_cur = 0;/* Restart buffer filling */
/* Take care before calling the function again that there will not a recursive dramatic issue ! */
if ( (_vbo_container_cur+8) < _vbo_container_size)
draw_container(x, y, w, h);
else
*Message::get_instance() << "Cannot fill the temporary buffer: size " << _vbo_container_size << " is too few" << Message::ende;
}/* end else of if ( (_vbo_container_cur+8) < _vbo_container_size) */
glBegin(GL_QUADS);/* create a quads */
{
glColor3d(0, 0, j);glVertex2d(x, y);
glColor3d(0, 0, j-0.1);glVertex2d(x, y+h);
glColor3d(0, 0, j-0.1);glVertex2d(x+w, y+h);
glColor3d(0, 0, j);glVertex2d(x+w, y);
}
glEnd();
if ((x+w)>_container_x_max)
_container_x_max = x+w;
......@@ -673,6 +789,49 @@ inline void Render_opengl::draw_container(const Element_pos x, const Element_pos
}
// inline void Render_opengl::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) {
// float j=0.6;
// glBegin(GL_QUADS);/* create a quads */
// {
// glColor3d(0, 0, j);glVertex2d(x, y);
// glColor3d(0, 0, j-0.1);glVertex2d(x, y+h);
// glColor3d(0, 0, j-0.1);glVertex2d(x+w, y+h);
// glColor3d(0, 0, j);glVertex2d(x+w, y);
// }
// glEnd();
// if ((x+w)>_container_x_max)
// _container_x_max = x+w;
// if ((y+h)>_container_y_max)
// _container_y_max = y+h;
// if (_container_x_min > x)
// _container_x_min = x;
// if (_container_y_min > y)
// _container_y_min = y;
// #ifdef DEBUG_MODE_RENDER_AREA
// std::cerr << __FILE__ << " l." << __LINE__ << ":" << std::endl;
// std::cerr < "Container drawing:" << std::endl;
// std::cerr << "x: " << x << " y: " << y << " w: " << w << " h: " << h << " xmax-xmin: " << _container_x_max << " - " << _container_x_min << " ymax-ymin: " << _container_y_max << " - " << _container_y_min << std::endl;
// #endif
// }
inline void Render_opengl::draw_container_text(const Element_pos x, const Element_pos y, const std::string value){
_text_pos.push_back(x);
......@@ -682,11 +841,22 @@ inline void Render_opengl::draw_container_text(const Element_pos x, const Elemen
}
inline void Render_opengl::end_draw_containers(){
glEndList();/* close the list */
_list_vbo_browser->data->fill_buffer(_vbo_container_cur, _vbo_container_buf);/* Write on VRAM all the buffer */
// _list_vbo_browser->data->display_info();
_vbo_container_cur = 0;/* Restart buffer filling */
delete[] _vbo_container_buf;/* Release buffer */
_vbo_container_buf = NULL;
}
// inline void Render_opengl::end_draw_containers(){
// glEndList();/* close the list */
// }
......
......@@ -29,21 +29,23 @@ Vbo::Vbo(){
}
Vbo::Vbo(int nb_verteces_per_object, int nb_object){
Vbo::Vbo(int nb_verteces_per_object, int nb_object, GLenum object_type, GLenum client_state){
/* init class attributes */
_nb_coordinates_per_vertex = 2;/* 2 dimensions (x and y) */
_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);
/* There is _nb_object*(number_of_vertices_per_object) elements. */
_size = _nb_coordinates_per_vertex*nb_verteces_per_object*_nb_object;
_object_type = object_type;
_client_state = client_state;
/* init OpenGL */
......@@ -51,8 +53,8 @@ Vbo::Vbo(int nb_verteces_per_object, int nb_object){
glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
glBufferData(GL_ARRAY_BUFFER, _size, NULL, GL_STATIC_DRAW);/* allocate memory space inside graphic card */
glBufferData(GL_ARRAY_BUFFER, _size*sizeof(Element_pos), NULL, GL_STREAM_DRAW);/* allocate memory space inside graphic card */
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
}
......@@ -60,6 +62,7 @@ Vbo::Vbo(int nb_verteces_per_object, int nb_object){
Vbo::~Vbo(){
glDeleteBuffers(1, &_id);/* release the buffer and free its memory inside graphic card */
_id = 0;
}
......@@ -75,14 +78,22 @@ Vbo::~Vbo(){
*
**********************************/
int Vbo::fill_buffer(int data_size, Element_pos* data){
int Vbo::fill_buffer(const unsigned int data_size, const Element_pos* const data){
glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */
/* Take care:
*
* For performance, please use glMapBuffer() if data amount is more than 32Kbits,
* else use glBufferSubData().
*
*/
if ( (_cur+data_size) <= _size){
glBufferSubData(GL_ARRAY_BUFFER, _cur, data_size, data);
glBufferSubData(GL_ARRAY_BUFFER, _cur*sizeof(Element_pos), data_size*sizeof(Element_pos), data);
_cur += data_size;
}else{
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
return Vbo::VBO_OUT_OF_MEMORY;
......@@ -90,11 +101,12 @@ int Vbo::fill_buffer(int data_size, Element_pos* data){
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
return Vbo::VBO_OK;
}
int Vbo::get_remaining_size(){
int Vbo::get_remaining_size() const{
return (_size-_cur);
}
......@@ -111,18 +123,96 @@ int Vbo::get_remaining_size(){
*
**********************************/
void Vbo::display_buffer(){
void Vbo::display_buffer() const{
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 */
/* glVertexPointer(A, B, C, D)
*
* A: coordinate number to identify a vertex (2 in 2 dimension space, 3 in 3 dimension space).
* B: the coordinate type (GL_INT, GL_FLOAT, GL_DOUBLE, etc.)
* C: stride -> the case offset between two vertex group (and not coordinate !) . Use to interleaves to kind of objects (for example, verteces and colors).
* D: the vertex buffer address in the VRAM. Use 0 with the VBO_BUFFER_OFFSET macro to convert a number into an address.
*/
glVertexPointer(_nb_coordinates_per_vertex, GL_DOUBLE, 0, VBO_BUFFER_OFFSET(0));/* give to OpenGL the VBO address */
glDisableClientState(GL_VERTEX_ARRAY);
glEnableClientState(_client_state);
/* glDrawArrays(A, B, C)
*
* A: an OpenGL primitive (GL_LINES, GL_TRIANGLES, etc.)
* B: the first vertex index of the vertex buffer which will be printed.
* C: the whole number of verteces which will be drawn.
*
* Please take care that a vertex is represented by _nb_coordinates_per_vertex cases of the _cur array.
*/
glDrawArrays(_object_type, 0, _cur/_nb_coordinates_per_vertex);/* RENDERING */
glDisableClientState(_client_state);
glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */
}
/***********************************
*
*
*
* Debug tools.
*
*
*
**********************************/
void Vbo::display_info(){
GLvoid* _read_buf = NULL;
message << "*** Display VBO info ***" << Message::endi;
message << "Id: " << _id << Message::endi;
message << "Current position inside vbo: " << _cur << Message::endi;
message << "Coordinates per vertex: " << _nb_coordinates_per_vertex << Message::endi;
message << "Verteces per object: " << _nb_verteces_per_object << Message::endi;
message << "Max objects per vertex buffer: " << _nb_object << Message::endi;
message << "Max size of the vbo (verteces_per_object * nb_object * sizeof(Element_pos)) in Bytes: " << _size*sizeof(Element_pos) << Message::endi;
message << "Object type: " << _object_type << Message::endi;
message << "Client state: " << _client_state << Message::endi;
/* Now, read the video memory */
message << Message::endi << Message::endi << "Display memory data: " << Message::endi;
glBindBuffer(GL_ARRAY_BUFFER, _id);
_read_buf = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
if (NULL == _read_buf){
message << "Cannot access data" << Message::endi;
}
else{
for (unsigned int i = 0 ; i< _cur ; i++)
message << ((Element_pos*)_read_buf)[i] << Message::endi;
message << "End display memory data" << Message::endi;
if (GL_FALSE == glUnmapBuffer(GL_ARRAY_BUFFER)){