From 15ae9e0b7c06d79baf38445a0581fc82a9cdc0b3 Mon Sep 17 00:00:00 2001 From: Olivier Lagrasse Date: Thu, 17 Dec 2009 17:51:25 +0000 Subject: [PATCH] - Fix a problem with color which made slow the render. - Add an alternate render with VBO. Uncomment #define WITH_VBO on Core.hpp to use it. You need glew installed. If you cannot compile and you do not want to install glew, please remove Render_alternate.hpp et Render_alternate.cpp entries from src/src.pro and/or src/CMakeLists.txt. - Fix some bugs. --- src/CMakeLists.txt | 2 + src/common/info.cpp | 30 +- src/common/info.hpp | 6 +- src/core/Core.cpp | 33 +- src/core/Core.hpp | 15 +- src/interface/Interface_graphic.cpp | 4 +- src/interface/main_window.ui | 51 +- src/render/Hook_event.cpp | 2 +- src/render/Render.hpp | 15 +- src/render/Render_alternate.cpp | 932 ++++++++++++++++++++++++++++ src/render/Render_alternate.hpp | 567 +++++++++++++++++ src/render/Render_opengl.cpp | 126 ++-- src/render/Render_opengl.hpp | 11 + src/render/vbo.cpp | 94 +-- src/render/vbo.hpp | 115 ++-- src/src.pro | 8 +- 16 files changed, 1727 insertions(+), 284 deletions(-) create mode 100755 src/render/Render_alternate.cpp create mode 100755 src/render/Render_alternate.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86eb187..3f0ec8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,6 +87,7 @@ SET(VITE_HDRS render/Geometry.hpp render/Hook_event.hpp render/Render_opengl.hpp + render/Render_alternate.hpp render/Render_svg.hpp render/render_stats.hpp render/render_stats_opengl.hpp @@ -166,6 +167,7 @@ SET(VITE_SRCS render/Hook_event.cpp render/Render.hpp render/Render_opengl.cpp + render/Render_alternate.cpp render/Render_svg.cpp render/render_stats_opengl.cpp render/render_stats_svg.cpp diff --git a/src/common/info.cpp b/src/common/info.cpp index 3bf5590..33fd91f 100644 --- a/src/common/info.cpp +++ b/src/common/info.cpp @@ -47,32 +47,6 @@ #include "common/common.hpp" #include "common/info.hpp" -// void (Interface_console:: *Info::Core::launch_action)(int, void*) = NULL; -// const int Info::Core::_STATE_UNKNOWN = -1; -// const int Info::Core::_STATE_DISPLAY_HELP = 0; -// const int Info::Core::_STATE_IN_AN_INTERVAL = 1; // 2^0 -// const int Info::Core::_STATE_OPEN_FILE = 2; // 2^1 -// const int Info::Core::_STATE_OPEN_FILE_IN_AN_INTERVAL = 3; -// const int Info::Core::_STATE_EXPORT_FILE = 4; // 2^2 -// const int Info::Core::_STATE_EXPORT_FILE_IN_INTERVAL = 5; -// const int Info::Core::_STATE_RELEASE_RENDER_AREA = 6; -// const int Info::Core::_STATE_RENDER_AREA_CHANGE_TRANSLATE = 7; -// const int Info::Core::_STATE_RENDER_AREA_CHANGE_SCALE = 8; -// const int Info::Core::_STATE_RENDER_AREA_CHANGE_CONTAINER_SCALE = 9; -// const int Info::Core::_DRAW_OPENGL = 10; -// const int Info::Core::_DRAW_SVG = 11; -// const int Info::Core::_STATE_LAUNCH_GRAPHICAL_INTERFACE = 12; -// const int Info::Core::_STATE_RENDER_AREA_REPLACE_SCALE = 13; -// const int Info::Core::_STATE_RENDER_AREA_REPLACE_TRANSLATE = 14; -// const int Info::Core::_STATE_RENDER_AREA_REPLACE_TRANSLATE_Y = 15; -// const int Info::Core::_STATE_RENDER_AREA_REGISTERED_TRANSLATE = 16; -// const int Info::Core::_STATE_RENDER_AREA_CHANGE_SCALE_Y = 17; -// const int Info::Core::_STATE_AJUST_SCROLL_BARS = 18; -// const int Info::Core::_STATE_REFRESH_SCROLL_BARS = 19; -// const int Info::Core::_STATE_ZOOM_BOX_VALUE = 20; -// const int Info::Core::_STATE_RENDER_DISPLAY_INFORMATION = 21; -// const int Info::Core::_STATE_RENDER_UPDATE = 22; - unsigned int Info::Screen::width = 800; unsigned int Info::Screen::height = 600; @@ -101,5 +75,5 @@ Element_pos Info::Render::_info_accurate = 0.0; bool Info::Render::_no_arrows = false; bool Info::Render::_no_events = false; -QLabel* Info::Render::_ui_render_min_value = NULL; -QLabel* Info::Render::_ui_render_max_value = NULL; +//QLabel* Info::Render::_ui_render_min_value = NULL; +//QLabel* Info::Render::_ui_render_max_value = NULL; diff --git a/src/common/info.hpp b/src/common/info.hpp index 80abd64..5199c88 100644 --- a/src/common/info.hpp +++ b/src/common/info.hpp @@ -48,7 +48,7 @@ #define INFO_HPP class Interface_console; -class QLabel; +//class QLabel; /*! * \brief Class used to store informations. @@ -253,13 +253,13 @@ public: * \brief This attribute is used to update the label which indicates * the minimum visible trace value. */ - static QLabel* _ui_render_min_value; + //static QLabel* _ui_render_min_value; /*! * \brief This attribute is used to update the label which indicates * the maximum visible trace value. */ - static QLabel* _ui_render_max_value; + //static QLabel* _ui_render_max_value; }; diff --git a/src/core/Core.cpp b/src/core/Core.cpp index c962507..727a5cc 100644 --- a/src/core/Core.cpp +++ b/src/core/Core.cpp @@ -45,8 +45,6 @@ *\brief This is the console interface C source code. */ -//#define WITH_OTF - #include #include @@ -66,12 +64,9 @@ /* -- */ - -#include "render/Render_opengl.hpp" //#include "render/render.hpp" #include "render/Render_svg.hpp" #include "render/Render.hpp" -//#include "render/Render_opengl_dl.hpp" /* -- */ #include "trace/values/Values.hpp" #include "trace/tree/Interval.hpp" @@ -101,6 +96,13 @@ #include "core/Core.hpp" #include "interface/parsing_thread.hpp" /* -- */ +#ifdef WITH_VBO +#include "render/Render_alternate.hpp" +#else +#include "render/Render_opengl.hpp" +#endif + + using namespace std; #define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " @@ -211,13 +213,19 @@ bool Core::draw_trace(const string & filename, const int format){ Parser *parser; DrawTrace drawing_ogl; + +#ifdef WITH_VBO + Render render(_render_opengl); +#else Render render(_render_opengl); +#endif + QTime time_elapsed; ostringstream buf_txt; int time_buf; time_buf = 0; - + // Get the parser in function of the extension of the file const unsigned int position_of_dot = filename.find_last_of('.'); @@ -254,6 +262,13 @@ bool Core::draw_trace(const string & filename, const int format){ if (NULL == _trace) { /* no trace is loaded, parse the file */ + + /* Init data */ + Info::Entity::x_min = 0; + Info::Entity::x_max = 0; + Info::Render::_x_min_visible = 0; + Info::Render::_x_max_visible = 0; + _trace = new Trace(); // Init of the thread @@ -633,12 +648,16 @@ void Core::launch_action(int state, void* arg) { if ( _STATE_OPEN_FILE == state) message << QObject::tr("Opening the file: ").toStdString ()+_file_opened << Message::endi; - + _main_window = new Interface_graphic (this);/* launch the window interface */ Message::set_interface (_main_window);/* define which interface will receive messages */ // format.setOverlay(true); +#ifdef WITH_VBO + _render_opengl = new Render_alternate (this, _main_window, format); +#else _render_opengl = new Render_opengl (this, _main_window, format); +#endif if ( NULL == _render_opengl){ message << QObject::tr("Cannot allocate memory for an OpengGL instance").toStdString () << Message::ende; diff --git a/src/core/Core.hpp b/src/core/Core.hpp index 3f524f6..8d32ffa 100644 --- a/src/core/Core.hpp +++ b/src/core/Core.hpp @@ -47,9 +47,18 @@ #ifndef CORE_HPP #define CORE_HPP + +//#define WITH_VBO + class Core; class Interface_graphic; + +#ifdef WITH_VBO +class Render_alternate; +#else class Render_opengl; +#endif + class Render_svg; class Trace; #include "render/Render.hpp" @@ -256,7 +265,11 @@ protected: * \brief Contains the OpenGL render instance. */ /* MOD */ - Render_opengl* _render_opengl; +#ifdef WITH_VBO + Render_alternate* _render_opengl; +#else + Render_opengl* _render_opengl; +#endif //Render* _render_opengl; /*! diff --git a/src/interface/Interface_graphic.cpp b/src/interface/Interface_graphic.cpp index 198264b..05221b4 100644 --- a/src/interface/Interface_graphic.cpp +++ b/src/interface/Interface_graphic.cpp @@ -195,8 +195,8 @@ void Interface_graphic::load_windows(){ CKFP(_ui_zoom_box = qFindChild(this, "zoom_box"), "Cannot find the zoom box in the .ui file"); - CKFP(Info::Render::_ui_render_min_value = qFindChild(this, "render_min_value"), "Cannot find the render_min_value label in the .ui file"); - CKFP(Info::Render::_ui_render_max_value = qFindChild(this, "render_max_value"), "Cannot find the render_max_value label in the .ui file"); + // CKFP(Info::Render::_ui_render_min_value = qFindChild(this, "render_min_value"), "Cannot find the render_min_value label in the .ui file"); + // CKFP(Info::Render::_ui_render_max_value = qFindChild(this, "render_max_value"), "Cannot find the render_max_value label in the .ui file"); /* Export window */ CKFP(_ui_export_ok_button = qFindChild(_ui_time_selection_export, "option_export_ok"), "Cannot find the ok push button in the export dialog .ui file"); diff --git a/src/interface/main_window.ui b/src/interface/main_window.ui index fb34001..992022d 100644 --- a/src/interface/main_window.ui +++ b/src/interface/main_window.ui @@ -28,55 +28,6 @@ - - - - - - - 0 - 0 - - - - - - - Qt::RichText - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - - - Qt::RichText - - - - - @@ -235,7 +186,7 @@ 0 0 1060 - 27 + 25 diff --git a/src/render/Hook_event.cpp b/src/render/Hook_event.cpp index 1eb0b26..9a61d15 100644 --- a/src/render/Hook_event.cpp +++ b/src/render/Hook_event.cpp @@ -253,7 +253,7 @@ void Hook_event::mouseDoubleClickEvent ( QMouseEvent * event ){ void Hook_event::mouseMoveEvent(QMouseEvent * event){ - // if (!_mouse_pressed) return; + if (!_mouse_pressed) return; _new_mouse_x = event->x(); _new_mouse_y = event->y(); diff --git a/src/render/Render.hpp b/src/render/Render.hpp index 04eef94..10e3bd1 100755 --- a/src/render/Render.hpp +++ b/src/render/Render.hpp @@ -52,6 +52,7 @@ #include "render/Ruler.hpp" #include "common/info.hpp" +#include /*! * \brief Structure used to store container information. @@ -242,16 +243,20 @@ public: } drawing_instance->end_draw_containers(); + } + static int bb; + /*! * \brief Creates and opens the display list for state draws. */ inline void start_draw_states(){ drawing_instance->start_draw_states(); - } + + /*! * \brief Draw a state of the trace. * \param start the beginning time of the state. @@ -262,18 +267,17 @@ public: * \param g the green color rate of the state. * \param b the blue color rate of the state. */ - inline void draw_state(const Element_pos start, const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b) { - // std::cout << __FILE__ << " " << __LINE__ << " -* " << trace_to_render_x(start) << " " << coeff_trace_render_x() << std::endl; + inline void draw_state(const Element_pos start, const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b) { + drawing_instance->set_color(r, g, b); - // drawing_instance->draw_quad(start, base, _z_state, end-start, height); + drawing_instance->draw_quad(trace_to_render_x(start - Info::Render::_x_min_visible), trace_to_render_y(base), _z_state, (end-start)*coeff_trace_render_x(), height*coeff_trace_render_y()); - } /*! @@ -449,7 +453,6 @@ public: */ inline void end_draw(){ // std::cerr << __FILE__ << __LINE__ << " " << Info::Render::_x_min_visible << " " << Info::Render::_x_max_visible << std::endl; - /* Now, draw ruler */ Element_pos graduation_diff; Element_pos coeff_prefix; diff --git a/src/render/Render_alternate.cpp b/src/render/Render_alternate.cpp new file mode 100755 index 0000000..479780a --- /dev/null +++ b/src/render/Render_alternate.cpp @@ -0,0 +1,932 @@ +/* +** This file is part of the ViTE project. +** +** This software is governed by the CeCILL-A license under French law +** and abiding by the rules of distribution of free software. You can +** use, modify and/or redistribute the software under the terms of the +** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following +** URL: "http://www.cecill.info". +** +** As a counterpart to the access to the source code and rights to copy, +** modify and redistribute granted by the license, users are provided +** only with a limited warranty and the software's author, the holder of +** the economic rights, and the successive licensors have only limited +** liability. +** +** In this respect, the user's attention is drawn to the risks associated +** with loading, using, modifying and/or developing or reproducing the +** software by the user in light of its specific status of free software, +** that may mean that it is complicated to manipulate, and that also +** therefore means that it is reserved for developers and experienced +** professionals having in-depth computer knowledge. Users are therefore +** encouraged to load and test the software's suitability as regards +** their requirements in conditions enabling the security of their +** systems and/or data to be ensured and, more generally, to use and +** operate it in the same conditions as regards security. +** +** The fact that you are presently reading this means that you have had +** knowledge of the CeCILL-A license and that you accept its terms. +** +** +** ViTE developers are (for version 0.* to 1.0): +** +** - COULOMB Kevin +** - FAVERGE Mathieu +** - JAZEIX Johnny +** - LAGRASSE Olivier +** - MARCOUEILLE Jule +** - NOISETTE Pascal +** - REDONDY Arthur +** - VUCHENER Clément +** +*/ +/*! + *\file Render_alternate.cpp + */ + + +#include "common/common.hpp" +#include "common/info.hpp" +/* -- */ +//#include "render/render.hpp" + +#include +#include "render/Hook_event.hpp" + +#include "render/Render_alternate.hpp" +/* -- */ + +#include "interface/resource.hpp" +//#include "interface/interface.hpp" +#include "render/Render.hpp" +#include "core/Core.hpp" +/* -- */ + +#include "vbo.hpp" + + +using namespace std; + + +#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " + +static bool _draw_container; +static bool _draw_ruler; +static bool _draw_arrow; +static bool _draw_event; +const int Render_alternate::DRAWING_TIMER_DEFAULT = 10; + +/*********************************** + * + * + * + * Constructor and destructor. + * + * + * + **********************************/ + +Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format) + : Hook_event((Render_opengl*)this, core, parent, format){ + + _arrows.clear(); + _circles.clear(); + _texts.clear(); + _vbos.clear(); + + + + setAutoFillBackground(false); +} + + +Render_alternate::~Render_alternate(){ +} + +/*********************************** + * + * + * + * Default QGLWidget functions. + * + * + * + **********************************/ + +void Render_alternate::initializeGL() { + glClearColor(0.5f, 0.5f, 0.55f, 1.0f); + + glEnable(GL_DEPTH_TEST); + + glClearStencil(0); +} + +void Render_alternate::resizeGL(int width, int height) { + glViewport(0, 0, width, height); + + /* update informations about widget size */ + Info::Screen::width = width; + Info::Screen::height = height; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + + + if(DRAWING_STATE_WAITING == _state){// A wait is drawn + glOrtho(-50, 50, -50, 50, 0, 1000); + }else if (DRAWING_STATE_DRAWING == _state){// A trace is drawn + glOrtho(0, Info::Render::width, 0, Info::Render::height, 0, -1000); + }else{ + message << tr("Undefined value for the drawing state attribute - Render area").toStdString() << Message::ende; + } + + + glMatrixMode(GL_MODELVIEW); +} + + +void Render_alternate::paintGL(){ + + resizeGL(Render_alternate::QGLWidget::width(), Render_alternate::QGLWidget::height()); + Render_alternate::QGLWidget::setFocus(Qt::ActiveWindowFocusReason);/* give the focus to the render area for mouse and keyboard events */ + + + glClearDepth(1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glLoadIdentity(); + + + if(DRAWING_STATE_WAITING == _state){/* A wait is drawn */ + + /* turn around y axis */ + _wait_angle+=0.1f; + if (_wait_angle>=360) _wait_angle=0.0f; + + glPushMatrix(); + + glScalef(15, 15, 0); + + glRotatef(-_wait_angle,0, 1, 0); + glRotatef(_wait_angle_y, 1, 0, 0); + + + glPopMatrix(); + + + }else if (DRAWING_STATE_DRAWING == _state){/* A trace is drawn */ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glPushMatrix(); + { + glTranslated(0.0, Info::Render::height, 100.0); + glRotated(180.0, 1.0, 0.0, 0.0); + + + glPushMatrix(); + { + + glTranslated(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, 0.0); + glScalef(_x_state_scale, _y_state_scale, 1.0); + + for (unsigned int i=0 ; + i<_vbos.size() ; + i++){ + _vbos[i]->display(); + } + } + glPopMatrix(); + + call_ruler(); + + + if (false == Info::Render::_no_arrows)/* display arrows */ + draw_stored_arrows(); + + if (false == Info::Render::_no_events)/* display events */ + draw_stored_circles(); + + } + glPopMatrix(); + + glPushMatrix(); + { + glTranslated(0.0, 0.0, 100.0);/* not accurate */ + + if (_mouse_pressed){ + + + glTranslated(0.0, 0.0, _z_container_under); + + Element_pos old_x, old_y, new_x, new_y; + + + + old_x = _mouse_x*(Info::Render::width/Info::Screen::width); + old_y = Info::Render::height - _mouse_y*(Info::Render::height/Info::Screen::height); + new_x = _new_mouse_x*(Info::Render::width/Info::Screen::width); + new_y = Info::Render::height - _new_mouse_y*(Info::Render::height/Info::Screen::height); + +#ifdef DEBUG_MODE_RENDER_OPENGL + + cerr << __FILE__ << " l." << __LINE__ << ":" << endl; + cerr << "Selection rectangle position: (" << old_x << ", " << old_y << ") - (" << new_x << ", " << new_y << ")" << endl; +#endif + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + /* Square for selection */ + glBegin(GL_QUADS); + { + glColor4d(0.9, 1.0, 0.9, _selection_rectangle_alpha);glVertex2d(old_x, old_y); + glColor4d(0.9, 0.9, 0.9, _selection_rectangle_alpha);glVertex2d(old_x, new_y); + glColor4d(0.9, 0.9, 0.9, _selection_rectangle_alpha);glVertex2d(new_x, new_y); + glColor4d(0.9, 0.9, 0.9, _selection_rectangle_alpha);glVertex2d(new_x, old_y); + } + glEnd(); + + glDisable(GL_BLEND); + + }/* end if (true==_mouse_pressed) */ + } + glPopMatrix(); + + + + }else{ + message << tr("Undefined value for the drawing state attribute - Render area").toStdString() << Message::ende; + } + + glFlush(); + + + /* Check the errors */ + GLenum glerror; + glerror = glGetError(); + if(glerror != GL_NO_ERROR) + message << tr("Render area : the following OpengGL error occured: ").toStdString() << (char *)gluErrorString(glerror) << Message::endw; + + + + if(DRAWING_STATE_WAITING == _state)/* A wait is drawn, do not take car about the ruler drawing */ + return; + + QFont arial_font = QFont("Arial", 10); + qglColor(Qt::white);//QColor(0, 0, 0)); + + + /* Draw container text */ + const unsigned int texts_size = _texts.size(); + for (unsigned int i=0 ; isetText(""); + // Info::Render::_ui_render_max_value->setText(""); + + Info::Entity::x_max = 0; + Info::Entity::x_min = 0; + // _state_x_max = 0; + _state_y_max = 0; + // _state_x_min = 0; + _state_y_min = 0; + + /* clear lists to store container texts */ + _text_pos.clear(); + _text_value.clear(); + + _arrows.clear(); + _circles.clear(); + _texts.clear(); + + for (unsigned int i=0 ; + i<_vbos.size() ; + i++){ + delete _vbos[i]; + } + _vbos.clear(); + + /* clear the event vector */ + // _events.clear(); + + /* clear the arrow vector */ + // _arrows.clear(); + + /* empty the selection stack */ + while(false == _previous_selection.empty()) + _previous_selection.pop(); + + if (NULL == _render_instance) + return true; + + /* Now, timer is set */ + if (_wait_timer == NULL){ + _wait_angle = 0.0f; + + /* _wait_timer = new QTimer(this); + connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL())); + _wait_timer->start(_wait_spf);*/ + } + + + return true;//_render_instance->display_unbuild(); +} + + + + + +/*********************************** + * + * + * + * Drawing function for the wait screen. + * + * + * + **********************************/ + + + +GLuint Render_alternate::draw_wait() { + GLuint object; + GLuint texture; + + glGenTextures(1, &texture);/* create the texture and link it with the list previously created */ + + QFile texture_file(QString(":/img/img/logo") + QDate::currentDate().toString("MMdd") + QString(".png")); + + if (true == texture_file.exists())/* The texture exists */ + texture = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D); + else/* use the default picture */ + texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D); + + + /* apply some parameters on the texture */ + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glEnable(GL_TEXTURE_2D); + + glEnable(GL_BLEND);/* enable blending for the alpha color */ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + + /* Now, timer is set */ + if (_wait_timer == NULL){ + _wait_angle = 0.0f; + /* + _wait_timer = new QTimer(this); + connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL())); + _wait_timer->start(_wait_spf);*/ + } + + return object; +} + + + + + +void Render_alternate::call_ruler(){ + Element_pos graduation_diff; + Element_pos coeff_prefix; + const Element_pos offset_x = _default_entity_x_translate; + const Element_pos offset_y = _ruler_y + _ruler_height+3.5; + + update_visible_interval_value(); + + graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible); + coeff_prefix = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible); + + set_color(1.0, 1.0, 1.0); + + for (Element_pos i = Info::Render::_x_min_visible ; i < Info::Render::_x_max_visible ; i+=graduation_diff){ + const Element_pos grad_div_by_5 = graduation_diff/5; + for (Element_pos j = (i+grad_div_by_5) ; j<(i+graduation_diff) ; j+= grad_div_by_5){ + draw_line( trace_to_render_x(j) + offset_x, offset_y , + trace_to_render_x(j) + offset_x, 2+offset_y, _z_ruler); + } + + draw_line( trace_to_render_x(i) + offset_x, offset_y-1 , + trace_to_render_x(i) + offset_x, 4+offset_y, _z_ruler); + } + + glBegin(GL_QUADS); + { + glColor4d(0.0, 0.0, 1.0, 0.8); + glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 0, _z_ruler_under ); + glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 8, _z_ruler_under ); + glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 8, _z_ruler_under ); + glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_under ); + } + glEnd(); + + glBegin(GL_QUADS); + { + glColor4d(0.0, 0.0, 0.0, 1.0); + glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 0, _z_ruler_over ); + glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 3, _z_ruler_over ); + glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 3, _z_ruler_over ); + glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_over ); + } + glEnd(); + + return; +} + + + +void Render_alternate::set_color(float r, float g, float b){ + _red = r; + _green = g; + _blue = b; +} + +void Render_alternate::draw_text(const Element_pos x, const Element_pos y, const Element_pos, const std::string s){ + if (_draw_ruler) return;/* do not draw text for ruler */ + + Container_text_ buf; + + buf.x = x; + buf.y = render_to_trace_y(y);/* Cancel previous transformation. */ + buf.value = s; + + _texts.push_back(buf); +} + + +void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, Element_pos w, Element_pos h){ + int state; + Element_pos data[8]; + + Element_pos offset_x; + const Element_pos offset_y = -_ruler_y - _ruler_height; + + offset_x = 0; + + if (!_draw_container) + offset_x = -_default_entity_x_translate; + + data[0] = x + offset_x; + data[1] = y + offset_y; + data[2] = x + offset_x; + data[3] = y + h + offset_y; + data[4] = x + w + offset_x; + data[5] = y + h + offset_y; + data[6] = x + w + offset_x; + data[7] = y + offset_y; + + state = Vbo::VBO_OK; + + if(NULL != _current_vbo) + state = _current_vbo->add(8, data); + + if (Vbo::VBO_OUT_OF_MEMORY == state){ + /* Store the current vbo */ + _vbos.push_back(_current_vbo); + + /* Create a new vbo */ + _current_vbo = NULL;/* DO NOT DEALLOCATE BEFORE! */ + _current_vbo = new Vbo(100000, _current_vbo->QUADS); + + if (NULL == _current_vbo) + message << tr("Cannot create a Vbo for states.").toStdString() << Message::ende; + } + + /* + glBegin(GL_QUADS); + { + glColor3d(_red, _green, _blue); + glVertex3d(x + offset_x , y + offset_y , z ); + glVertex3d(x + offset_x , y + h + offset_y, z ); + glColor3d(_red/1.5 , _green/1.5 , _blue/1.5); + glVertex3d(x + w + offset_x, y + h + offset_y, z ); + glVertex3d(x + w + offset_x, y + offset_y , z ); + } + glEnd();*/ +} + +void Render_alternate::draw_triangle(Element_pos , Element_pos , + Element_pos , Element_pos ){ +} + +void Render_alternate::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos z){ + if (_draw_ruler || _draw_arrow || _draw_event) return;/* do not draw line for ruler or for arrow or for event */ + + + const Element_pos offset_x = -_default_entity_x_translate; + const Element_pos offset_y = -_ruler_y - _ruler_height; + + glBegin(GL_LINES); + { + glColor3d(_red, _green, _blue); + glVertex3d(x1 + offset_x, y1 + offset_y, z); + glVertex3d(x2 + offset_x, y2 + offset_y, z); + } + glEnd(); +} + +void Render_alternate::draw_circle(Element_pos /*x*/, Element_pos /*y*/, Element_pos /*z*/, Element_pos /*r*/){ +} + + +void Render_alternate::start_draw(){ + /* Init GLEW */ + glewInit(); + _draw_ruler = false; + _draw_container = false; + _draw_arrow = false; + _draw_event = false; + + _current_vbo = NULL; + +} + +void Render_alternate::start_draw_containers(){ + _list_containers = glGenLists(1);/* create the list */ + if (_list_containers == 0) { + *Message::get_instance() << tr("Error when creating list.").toStdString() << Message::endw; + } + + glNewList(_list_containers, GL_COMPILE);/* open the list */ + _draw_container = true; +} + +void Render_alternate::draw_container(const Element_pos , const Element_pos , const Element_pos , const Element_pos ){ + +} + +void Render_alternate::draw_container_text(const Element_pos , const Element_pos , const std::string ){ +} + +void Render_alternate::end_draw_containers(){ + _draw_container = false; + glEndList();/* close the list */ +} + +void Render_alternate::start_draw_states(){ + _current_vbo = NULL; + _current_vbo = new Vbo((1<<20), _current_vbo->QUADS);/* Allocate 1 MiB */ + + if (NULL == _current_vbo) + message << tr("Cannot create a Vbo for states.").toStdString() << Message::ende; +} + +void Render_alternate::draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_col , const Element_col , const Element_col ){ +} + +void Render_alternate::end_draw_states(){ + + _vbos.push_back(_current_vbo); +} + +void Render_alternate::start_draw_arrows(){ + _draw_arrow = true; + +} + +void Render_alternate::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height, const Element_col red, const Element_col green, const Element_col blue){ + + Arrow_ buf; + const Element_pos offset_x = -_default_entity_x_translate; + const Element_pos offset_y = -_ruler_y - _ruler_height; + + buf.start_time = start_time + offset_x; + buf.end_time = end_time + offset_x; + buf.start_height = start_height + offset_y; + buf.end_height = end_height + offset_y; + buf.red = red; + buf.green = green; + buf.blue = blue; + + _arrows.push_back(buf); +} + +void Render_alternate::end_draw_arrows(){ + _draw_arrow = false; +} + +void Render_alternate::start_draw_events(){ + _draw_event = true; +} + +void Render_alternate::draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height){ + Event_ buf; + const Element_pos offset_x = -_default_entity_x_translate; + const Element_pos offset_y = -_ruler_y - _ruler_height; + + buf.time = time + offset_x; + buf.height = height + offset_y; + buf.container_height = container_height + offset_y; + buf.red = _red; + buf.green = _green; + buf.blue = _blue; + + _circles.push_back(buf); +} + + +void Render_alternate::end_draw_events(){ + _draw_event = false; +} + +void Render_alternate::start_draw_counter(){ +} + +void Render_alternate::draw_counter(const Element_pos , const Element_pos ){ +} + +void Render_alternate::end_draw_counter(){ +} + +void Render_alternate::start_ruler(){ + _draw_ruler = true; +} + +void Render_alternate::end_ruler(){ + _draw_ruler = false; +} + +void Render_alternate::end_draw(){ +} + + +void Render_alternate::draw_stored_texts(){ +} + +void Render_alternate::draw_stored_arrows(){ + + /* Only draw triangle. Lines are already in a display list */ + const Element_pos coeff = 180.0f/M_PI; + Element_pos angle; + Element_pos start_time, end_time, start_height, end_height; + Element_pos scaled_start_time, scaled_end_time, scaled_start_height, scaled_end_height; + + + + const unsigned int arrow_size = _arrows.size(); + for (unsigned int i=0 ; i + +#include "core/Core.hpp" +#include "render/Hook_event.hpp" +#include "render/Render_template.hpp" + +class Render_alternate; +class Interface_console; +struct Container_text_; +class Vbo; + +/*! + * \brief Structure used to store arrow information. + */ +struct Arrow_{ + /*! + * \brief Coordinates. + */ + Element_pos start_time, end_time, start_height, end_height; + /*! + * \brief Colors. + */ + Element_col red, green, blue; +}; + +/*! + * \brief Structure used to store event information. + */ +struct Event_{ + /*! + * \brief Coordinates and radius. + */ + Element_pos time, height, container_height; + /*! + * \brief Colors. + */ + Element_col red, green, blue; +}; + + +/*! + * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace. + */ +class Render_alternate : /*public QGLWidget,*/ public Hook_event, public Render_template +{ + Q_OBJECT + +protected: + + /*! + * \brief Contains the parent instance. + */ + Core* _core; + + /*! + * \brief The waiting screen display list. + */ + GLuint _wait_list; + + + /*! + * \brief The container GLu list. + */ + GLuint _list_containers; + + /*! + * \brief The state GLu list. + */ + GLuint _list_states; + + /*! + * \brief The counter GLu list. + */ + GLuint _list_counters; + + + /*! + * \brief The wait GLu list. + */ + // GLuint _wait_list; + + float _red, _green, _blue; + + std::vector _texts; + std::vector _arrows; + std::vector _circles; + + + /*********************************** + * + * The wait screen drawing. + * + **********************************/ + + /*********************************** + * The wait list Attributes. + **********************************/ + + + /*! + * \brief Rotation angle for the wait. + */ + 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. + */ + static const int DRAWING_TIMER_DEFAULT; + + /*! + * \brief Wait animation seconds per frame. + */ + int _wait_spf; + + + Vbo* _current_vbo; + std::vector _vbos; + + /*! + * \brief Timer to animate the wait. + */ + QTimer* _wait_timer; + +public: + + /*********************************** + * + * Constructor and destructor. + * + **********************************/ + + /*! + * \brief The default constructor + */ + Render_alternate(Core* core, QWidget *parent, const QGLFormat& format); + + /*! + * \brief The destructor + */ + virtual ~Render_alternate(); + + /*! + * \brief Set Statistics and Informations about input trace + */ + void set_total_width(Element_pos){} + + /*! + * \brief Set Statistics and Informations about input trace + */ + void set_total_time(Times){} + + /*! + * \brief display the scale + */ + void display_time_scale(){} + + + /*********************************** + * + * Default QGLWidget functions. + * + **********************************/ + + /*! + * \brief Call by the system to initialize the OpenGL render area. + */ + void initializeGL(); + + /*! + * \brief Call by the system when the render area was resized (occurs during a window resizement). + * \param width : the new width of the render area. + * \param height : the new height of the render area. + */ + void resizeGL(int width, int height); + + /*! + * \brief Call by the system each time the render area need to be updated. + */ + void paintGL(); + + //void paintEvent(QPaintEvent *event); + + /* void initializeOverlayGL(); + void resizeOverlayGL(int width, int height); + void paintOverlayGL();*/ + + + /*********************************** + * + * Building functions. + * + **********************************/ + + /*! + * \brief This function constructs the trace. + */ + // bool display_build() ; + + /*! + * \brief This function releases the trace. + */ + // bool display_unbuild() ; + + /*! + * \brief Proceeds with the initialization of the OpenGL draw functions. + */ + void start_draw(); + + /*! + * \brief Creates and opens the display list for container draws. + */ + void start_draw_containers(); + + /*! + * \brief Draw a container according to the parameters + * \param x the x position of the container + * \param y the y position of the container + * \param w the width of the container + * \param h the height of the container + */ + void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h); + + /*! + * \brief Draw the text of a container. + * \param x the x position of the text. + * \param y the y position of the text. + * \param value the string value of the text. + * + * This function stores text in a list. This list will be display each time the render area need to be updated. + */ + void draw_container_text(const Element_pos x, const Element_pos y, const std::string value); + + /*! + * \brief Closes the container display list. + */ + void end_draw_containers(); + + /*! + * \brief Creates and opens the display list for stater draws. + */ + void start_draw_states(); + + /*! + * \brief Draw a state of the trace. + * \param start the beginning time of the state. + * \param end the ending time of the state. + * \param base vertical position of the state. + * \param height the state height. + * \param r the red color rate of the state. + * \param g the green color rate of the state. + * \param b the blue color rate of the state. + */ + void draw_state(const Element_pos start , const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b); + + /*! + * \brief Closes the state display list. + */ + void end_draw_states(); + + /*! + * \brief Open the arrow display list. + */ + void start_draw_arrows(); + + /*! + * \brief Draw an arrow. + * \param start_time the beginning time of the arrow. + * \param end_time the ending time of the arrow. + * \param start_height vertical position of the begining time of the arrow. + * \param end_height vertical position of the ending time of the arrow. + * + * This function stores all the information of the arrow to display it each time the render area need to be updated. + */ + void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height,const Element_col red, const Element_col green, const Element_col blue); + + /*! + * \brief Closes the arrow display list. + */ + void end_draw_arrows(); + + /*! + * \brief Draw arrows contained in the Arrow_ vector + * \param arrows An arrow vector. + */ + // void draw_stored_arrows(std::vector &arrows); + + void start_draw_events(); + + /*! + * \brief Draw an event. + * \param time time when the event occurs. + * \param height vertical position of the event. + * \param container_height information to draw event. It corresponds to the container height when they are drawn horizontally. + * + * + * \brief Creates and opens the display list for container draws. + * + * This function stores all the information of the event to display it each time the render area need to be updated. + */ + void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height); + + void end_draw_events(); + + + /*! + * \brief Draw events contained in the Event_ vector + * \param events An event vector. + */ + // void draw_stored_events(std::vector &events); + + /*! + * \brief Creates and opens the display list for counter draws. + */ + void start_draw_counter(); + + /*! + * \brief Draw a point of the counter. + * \param x x position of the point. + * \param y y position of the point. + * + * Each time counter is increased, this function is called with the coordinates of the new point. + */ + void draw_counter(const Element_pos x, const Element_pos y); + + /*! + * \brief Closes the counter display list. + */ + void end_draw_counter(); + + /*! + * \brief Called before ruler drawing. + */ + void start_ruler(); + + /*! + * \brief Called after ruler drawing. + */ + void end_ruler(); + + + /*! + * \brief Do nothing (it is present for compatibility of the Render class). + */ + void end_draw(); + + + + /*********************************** + * + * Render OpenGL drawing functions. + * + **********************************/ + + /*! + * \brief Display a wait on the screen if there is no file opened. + * \return Asset value of the wait. + */ + GLuint draw_wait(); + + /*! + * \brief Draw the ruler display list. + */ + void call_ruler(); + + + + /*********************************** + * + * Building functions. + * + **********************************/ + + /*! + * \brief This function draws the trace. + */ + bool build(); + + /*! + * \brief This function releases the trace. + */ + bool unbuild(); + + /*********************************** + * + * Displaying functions. + * + **********************************/ + + // /*! +// * \brief Display on screen containers between container_begin and container_end. +// * \param container_begin integer value : id of the first container. +// * \param container_end integer value : id of the last container. +// */ +// void display_container(Element_count container_begin, Element_count container_end) =0; + +// /*! +// * \brief Display on screen states between timer_begin and time_end, +// * container_begin and container_end and with timer width between depth_begin and depth_end. +// * \param time_begin floating point value : time of the first state. +// * \param time_end floating point value : time of the last state. +// * \param container_begin integer value : id of the first container. +// * \param container_end integer value : id of the last container. +// * \param depth_begin floating point value : width of the narrowest state. +// * \param depth_end floating point value : width of the widest state. +// */ +// void display_state(Element_pos time_begin, Element_pos time_end, +// Element_count container_begin, Element_count container_end, +// Element_pos depth_begin, Element_pos depth_end) =0; + +// /*! +// * \brief Display on screen arrows between timer_begin and time_end, +// * container_begin and container_end and with timer width between depth_begin and depth_end. +// * \param time_begin floating point value : time of the smallest arrow time value. +// * \param time_end floating point value : time of the higher arrow time value. +// * \param container_begin integer value : id of the first container. +// * \param container_end integer value : id of the last container. +// * \param depth_begin floating point value : the narrowest difference between +// * the beginning time and the ending time of the arrow. +// * \param depth_end floating point value : width of the widest difference between +// * the beginning time and the ending time of the arrow. +// */ +// virtual void display_arrow(Element_pos time_begin, Element_pos time_end, +// Element_count container_begin, Element_count container_end, +// Element_pos depth_begin, Element_pos depth_end) =0; + +// /*! +// * \brief Display on screen events between timer_begin and time_end, +// * container_begin and container_end. +// * \param time_begin floating point value : time of the first event. +// * \param time_end floating point value : time of the last event. +// * \param container_begin integer value : id of the first container. +// * \param container_end integer value : id of the last container. +// */ +// virtual void display_event(Element_pos time_begin, Element_pos time_end, +// Element_count container_begin, Element_count container_end) =0; + +// /*! +// * \brief Display on screen counters between timer_begin and time_end, +// * container_begin and container_end. +// * \param time_begin floating point value : time of the smallest counter time value. +// * \param time_end floating point value : time of the higher counter time value. +// * \param container_begin integer value : id of the first container. +// * \param container_end integer value : id of the last container. +// */ +// virtual void display_counter(Element_pos time_begin, Element_pos time_end, +// Element_count container_begin, Element_count container_end) =0; + + /*! + * \brief Set the color for the further drawings. + * \param r the red value. Within [0 ; 1]. + * \param g the green value. Within [0 ; 1]. + * \param b the blue value. Within [0 ; 1]. + */ + void set_color(float r, float g, float b); + + /*! + * \brief Draw a text. + * \param x the horizontal position of the left bottom corner of the text. + * \param y the vertical position of the left bottom corner of the text. + * \param z the deep position of the text. + * \param s the text. + */ + virtual void draw_text(const Element_pos x, const Element_pos y, const Element_pos z, const std::string s); + + /*! + * \brief Draw a quad. + * \param x the horizontal position of the left bottom corner of the quad. + * \param y the vertical position of the left bottom corner of the quad. + * \param z the deep position of the quad. + * \param w the width of the quad. + * \param h the height of the quad. + */ + void draw_quad(Element_pos x, Element_pos y, Element_pos z, Element_pos w, Element_pos h); + + /*! + * \brief Draw a triangle. + * \param x the horizontal position of the triangle center. + * \param y the vertical position of the triangle center. + * \param size the edge size. + * \param r the rotation of triangle. (clockwise and in degree) + */ + void draw_triangle(Element_pos x, Element_pos y, + Element_pos size, Element_pos r); + + /*! + * \brief Draw a line. + * \param x1 the horizontal position of the first point. + * \param y1 the vertical position of the firt point. + * \param x2 the horizontal position of the second point. + * \param y2 the vertical position of the second point. + * \param z the deep position of the triangle. + */ + void draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos z); + + /*! + * \brief Draw a circle. + * \param x the horizontal position of the circle center. + * \param y the vertical position of the circle center. + * \param z the deep position of the circle. + * \param r the circle radius. + */ + void draw_circle(Element_pos x, Element_pos y, Element_pos z, Element_pos r); + + /* Temporary methods. Use to draw stored arrows and circles. It is to prevent scaling */ + void draw_stored_arrows(); + void draw_stored_circles(); + + void draw_stored_texts(); +}; + + + +#endif diff --git a/src/render/Render_opengl.cpp b/src/render/Render_opengl.cpp index 7629099..1f3578c 100644 --- a/src/render/Render_opengl.cpp +++ b/src/render/Render_opengl.cpp @@ -63,10 +63,6 @@ using namespace std; #define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " -static bool _draw_container; -static bool _draw_ruler; -static bool _draw_arrow; -static bool _draw_event; const int Render_opengl::DRAWING_TIMER_DEFAULT = 10; /*********************************** @@ -204,76 +200,47 @@ void Render_opengl::paintGL(){ glTranslated(0.0, Info::Render::height, 100.0); glRotated(180.0, 1.0, 0.0, 0.0); - - - // display_container(0, 0); glPushMatrix(); - { - - /* Translate containers and entities of the ruler height */ - // glTranslated(0.0, _ruler_height, 0.0); - // glTranslated(- _x_state_translate, -_y_state_translate, 0.0); - + { glTranslatef(0.0f, _ruler_y + _ruler_height -_y_state_translate, 0.0); - // glScalef( (Info::Render::width/Info::Container::x_max)*_x_scale_container_state, _y_state_scale*(Info::Render::height-_ruler_height)/Info::Container::y_max, 0.0f); - glScalef(_x_scale_container_state/0.20, _y_state_scale, 1.0); - if (glIsList(_list_containers) == GL_FALSE) *Message::get_instance() << tr("ERROR LIST not exist for containers.").toStdString() << Message::ende; else glCallList(_list_containers); - - } glPopMatrix(); - glPushMatrix(); { - - glTranslated(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, 0.0); - - - glScalef(_x_state_scale, _y_state_scale, 1.0); + glTranslated(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, _z_state); + glScalef(_x_state_scale, _y_state_scale, 1); - if (glIsList(_list_states) == GL_FALSE) + if (glIsList(_list_states) == GL_FALSE) *Message::get_instance() << tr("ERROR LIST not exist for states.").toStdString() << Message::ende; - else + else{ glCallList(_list_states); + glCallList(_list_counters); + } } glPopMatrix(); + if (false == Info::Render::_no_arrows)/* display arrows */ + draw_stored_arrows(); - // draw_stored_texts(); - call_ruler(); - - -// display_state(0, 0, 0, 0, 0, 0); - - if (false == Info::Render::_no_arrows)/* display arrows */ - draw_stored_arrows(); -// display_arrow(0, 0, 0, 0, 0, 0); - - if (false == Info::Render::_no_events)/* display events */ - draw_stored_circles(); -// display_event(0, 0, 0, 0); - -// display_counter(0, 0, 0, 0); - + if (false == Info::Render::_no_events)/* display events */ + draw_stored_circles(); /* Untranslate ruler */ - /* glTranslated(0.0, -_ruler_height, 0.0); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); call_ruler(); - glDisable(GL_BLEND);*/ + glDisable(GL_BLEND); } glPopMatrix(); - + glPushMatrix(); { glTranslated(0.0, 0.0, 100.0);/* not accurate */ @@ -334,6 +301,11 @@ void Render_opengl::paintGL(){ + + if(DRAWING_STATE_WAITING == _state)/* A wait is drawn, do not take car about the ruler drawing */ + return; + + QFont arial_font = QFont("Arial", 10); qglColor(Qt::white);//QColor(0, 0, 0)); @@ -486,8 +458,8 @@ bool Render_opengl::unbuild(){ Info::Container::x_min = 0; Info::Container::y_min = 0; - Info::Render::_ui_render_min_value->setText(""); - Info::Render::_ui_render_max_value->setText(""); + // Info::Render::_ui_render_min_value->setText(""); + // Info::Render::_ui_render_max_value->setText(""); Info::Entity::x_max = 0; Info::Entity::x_min = 0; @@ -619,6 +591,7 @@ void Render_opengl::call_ruler(){ graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible); coeff_prefix = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible); + set_color(1.0, 1.0, 1.0); for (Element_pos i = Info::Render::_x_min_visible ; i < Info::Render::_x_max_visible ; i+=graduation_diff){ const Element_pos grad_div_by_5 = graduation_diff/5; @@ -660,12 +633,11 @@ void Render_opengl::set_color(float r, float g, float b){ _red = r; _green = g; _blue = b; - - glColor3d(_red, _green, _blue); } void Render_opengl::draw_text(const Element_pos x, const Element_pos y, const Element_pos, const std::string s){ if (_draw_ruler) return;/* do not draw text for ruler */ + if (_draw_state) message << "Fatal error! Cannot put text in state lists!" << Message::ende; Container_text_ buf; @@ -677,23 +649,23 @@ void Render_opengl::draw_text(const Element_pos x, const Element_pos y, const El } -void Render_opengl::draw_quad(Element_pos x, Element_pos y, Element_pos z, Element_pos w, Element_pos h){ +void Render_opengl::draw_quad(Element_pos x, Element_pos y, Element_pos /*z*/, Element_pos w, Element_pos h){ Element_pos offset_x; - const Element_pos offset_y = -_ruler_y - _ruler_height; + Element_pos offset_y = -_ruler_y - _ruler_height; offset_x = 0; if (!_draw_container) offset_x = -_default_entity_x_translate; - - glBegin(GL_QUADS); + + glBegin(GL_QUADS); { glColor3d(_red, _green, _blue); - glVertex3d(x + offset_x , y + offset_y , z ); - glVertex3d(x + offset_x , y + h + offset_y, z ); - glColor3d(_red/1.5 , _green/1.5 , _blue/1.5); - glVertex3d(x + w + offset_x, y + h + offset_y, z ); - glVertex3d(x + w + offset_x, y + offset_y , z ); + glVertex2d(x + offset_x , y + offset_y); + glVertex2d(x + offset_x , y + h + offset_y); + glColor3d(_red/1.5 , _green/1.5 , _blue/1.5); + glVertex2d(x + w + offset_x, y + h + offset_y); + glVertex2d(x + w + offset_x, y + offset_y); } glEnd(); } @@ -704,7 +676,7 @@ void Render_opengl::draw_triangle(Element_pos , Element_pos , void Render_opengl::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos z){ if (_draw_ruler || _draw_arrow || _draw_event) return;/* do not draw line for ruler or for arrow or for event */ - + if (_draw_state) message << "Fatal error! Cannot put line in state lists!" << Message::ende; const Element_pos offset_x = -_default_entity_x_translate; const Element_pos offset_y = -_ruler_y - _ruler_height; @@ -724,10 +696,11 @@ void Render_opengl::draw_circle(Element_pos /*x*/, Element_pos /*y*/, Element_po void Render_opengl::start_draw(){ - _draw_ruler = false; _draw_container = false; - _draw_arrow = false; - _draw_event = false; + _draw_state = false; + _draw_ruler = false; + _draw_arrow = false; + _draw_event = false; } @@ -736,9 +709,9 @@ void Render_opengl::start_draw_containers(){ if (_list_containers == 0) { *Message::get_instance() << tr("Error when creating list.").toStdString() << Message::endw; } - + + _draw_container = true; glNewList(_list_containers, GL_COMPILE);/* open the list */ - _draw_container = true; } void Render_opengl::draw_container(const Element_pos , const Element_pos , const Element_pos , const Element_pos ){ @@ -758,7 +731,8 @@ void Render_opengl::start_draw_states(){ if (_list_states == 0) { *Message::get_instance() << tr("Error when creating list.").toStdString() << Message::endw; } - + + _draw_state = true; glNewList(_list_states, GL_COMPILE);/* open the list */ } @@ -766,7 +740,8 @@ void Render_opengl::draw_state(const Element_pos , const Element_pos , const Ele } void Render_opengl::end_draw_states(){ - + glEndList();/* close the states list */ + _draw_state = false; } void Render_opengl::start_draw_arrows(){ @@ -819,12 +794,19 @@ void Render_opengl::end_draw_events(){ } void Render_opengl::start_draw_counter(){ + _list_counters = glGenLists(1);/* create the list */ + if (_list_counters == 0) { + *Message::get_instance() << tr("Error when creating list").toStdString() << Message::ende; + } + + glNewList(_list_counters, GL_COMPILE);/* open the list */ } void Render_opengl::draw_counter(const Element_pos , const Element_pos ){ } void Render_opengl::end_draw_counter(){ + glEndList();/* close the list */ } void Render_opengl::start_ruler(){ @@ -836,7 +818,6 @@ void Render_opengl::end_ruler(){ } void Render_opengl::end_draw(){ - glEndList();/* close the states list */ } @@ -861,7 +842,7 @@ void Render_opengl::draw_stored_arrows(){ start_height = _arrows[i].start_height; end_height = _arrows[i].end_height; - set_color(_arrows[i].red, _arrows[i].green, _arrows[i].blue); + glColor3d(_arrows[i].red, _arrows[i].green, _arrows[i].blue); scaled_start_time = start_time * _x_state_scale; scaled_end_time = end_time * _x_state_scale; @@ -926,7 +907,7 @@ void Render_opengl::draw_stored_circles(){ glPushMatrix(); { - set_color(1.0 - _circles[i].red, 1.0 - _circles[i].green, 1.0 - _circles[i].blue); + glColor3d(1.0 - _circles[i].red, 1.0 - _circles[i].green, 1.0 - _circles[i].blue); glTranslated(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, @@ -946,7 +927,7 @@ void Render_opengl::draw_stored_circles(){ glEnd(); - set_color(_circles[i].red, _circles[i].green, _circles[i].blue); + glColor3d(_circles[i].red, _circles[i].green, _circles[i].blue); /* Draw the sub-circle */ glBegin(GL_POLYGON); @@ -975,8 +956,5 @@ void Render_opengl::draw_stored_circles(){ } glPopMatrix(); } - - set_color(1.0, 1.0, 1.0); - } diff --git a/src/render/Render_opengl.hpp b/src/render/Render_opengl.hpp index 308eb79..330271b 100644 --- a/src/render/Render_opengl.hpp +++ b/src/render/Render_opengl.hpp @@ -94,6 +94,15 @@ class Render_opengl : /*public QGLWidget,*/ public Hook_event, public Render_te { Q_OBJECT + + private: + + bool _draw_container; + bool _draw_state; + bool _draw_ruler; + bool _draw_arrow; + bool _draw_event; + protected: /*! @@ -166,6 +175,8 @@ protected: */ int _wait_spf; + + /*! * \brief Timer to animate the wait. */ diff --git a/src/render/vbo.cpp b/src/render/vbo.cpp index becd421..9d7853e 100644 --- a/src/render/vbo.cpp +++ b/src/render/vbo.cpp @@ -43,14 +43,15 @@ /*! *\file vbo.cpp */ - -#include "common/common.hpp" -/* -- */ -#include "render/vbo.hpp" -/* -- */ -using namespace std; + #include +#include +#include +#include "vbo.hpp" -#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " + +#define ERROR(m) printf("%s", m); + +using namespace std; const int Vbo::VBO_OK = 0; const int Vbo::VBO_OUT_OF_MEMORY = 1; @@ -70,7 +71,7 @@ Vbo::Vbo(){ } -Vbo::Vbo(int nb_verteces_per_object, int nb_object, GLenum object_type, GLenum client_state){ +Vbo::Vbo(int nb_object, Type object_type){ /* init class attributes */ @@ -79,13 +80,25 @@ Vbo::Vbo(int nb_verteces_per_object, int nb_object, GLenum object_type, GLenum c _id = 0; _nb_object = nb_object; - _nb_verteces_per_object = nb_verteces_per_object; + + switch (object_type){ + case TRIANGLES: + _nb_verteces_per_object = 3; + _object_type = GL_TRIANGLES; + break; + case QUADS: + _nb_verteces_per_object = 4; + _object_type = GL_QUADS; + break; + case LINES: + _nb_verteces_per_object = 2; + _object_type = GL_LINES; + } /* There is _nb_object*(number_of_vertices_per_object) elements. */ - _size = _nb_coordinates_per_vertex*nb_verteces_per_object*_nb_object; + _size = _nb_coordinates_per_vertex*_nb_verteces_per_object*_nb_object; - _object_type = object_type; - _client_state = client_state; + _client_state = GL_VERTEX_ARRAY; /* init OpenGL */ @@ -94,7 +107,7 @@ Vbo::Vbo(int nb_verteces_per_object, int nb_object, GLenum object_type, GLenum c glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */ - glBufferData(GL_ARRAY_BUFFER, _size*sizeof(Element_pos), NULL, GL_STREAM_DRAW);/* allocate memory space inside graphic card */ + glBufferData(GL_ARRAY_BUFFER, _size*sizeof(Data_type), NULL, GL_STREAM_DRAW);/* allocate memory space inside graphic card */ glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */ @@ -102,7 +115,7 @@ Vbo::Vbo(int nb_verteces_per_object, int nb_object, GLenum object_type, GLenum c 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 the graphic card */ _id = 0; } @@ -119,7 +132,7 @@ Vbo::~Vbo(){ * **********************************/ -int Vbo::fill_buffer(const unsigned int data_size, const Element_pos* const data){ +int Vbo::add(const unsigned int data_size, const Data_type* const data){ glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */ @@ -132,7 +145,7 @@ int Vbo::fill_buffer(const unsigned int data_size, const Element_pos* const dat if ( (_cur+data_size) <= _size){ - glBufferSubData(GL_ARRAY_BUFFER, _cur*sizeof(Element_pos), data_size*sizeof(Element_pos), data); + glBufferSubData(GL_ARRAY_BUFFER, _cur*sizeof(Data_type), data_size*sizeof(Data_type), data); _cur += data_size; }else{ @@ -148,7 +161,7 @@ int Vbo::fill_buffer(const unsigned int data_size, const Element_pos* const dat int Vbo::get_remaining_size() const{ - return (_size-_cur); + return (_size-_cur)/(_nb_verteces_per_object*_nb_coordinates_per_vertex); } @@ -164,7 +177,7 @@ int Vbo::get_remaining_size() const{ * **********************************/ -void Vbo::display_buffer() const{ +void Vbo::display() const{ glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */ @@ -212,48 +225,5 @@ void Vbo::display_buffer() const{ 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)){ - message << "Cannot unmap the vbo" << Message::ende; - } - else{ - _read_buf = NULL; - } - } - - glBindBuffer(GL_ARRAY_BUFFER, 0); - + } diff --git a/src/render/vbo.hpp b/src/render/vbo.hpp index f85e0e6..28fac02 100644 --- a/src/render/vbo.hpp +++ b/src/render/vbo.hpp @@ -47,6 +47,12 @@ #ifndef VBO_HPP #define VBO_HPP + +typedef double Data_type; + + + + /*! \def VBO_BUFFER_OFFSET(a) OpenGL special macro @@ -116,6 +122,13 @@ private: public: + enum Type{ + TRIANGLES, + QUADS, + LINES + }; + + /*********************************** * * Constructor and destructor. @@ -129,7 +142,7 @@ public: * \param object_type Defines how kind of OpenGL primitive object is made. * \param client_state Define how kind of OpenGL buffer object belongs to. */ - Vbo(int nb_verteces_per_object, int nb_object, GLenum object_type, GLenum client_state); + Vbo(int nb_object, Type object_type); /*! * \brief The destructor. @@ -173,7 +186,7 @@ public: *
  • VBO_UNDEFINED_ERROR: an error occurs but has not been identified. * */ - int fill_buffer(const unsigned int data_size, const Element_pos* const data); + int add(const unsigned int data_size, const Data_type* const data); /*! @@ -194,7 +207,7 @@ public: /*! * \brief Display the VBO list inside the OpenGL area. */ - void display_buffer() const; + void display() const; @@ -209,6 +222,12 @@ public: */ void display_info(); + + void *operator new(size_t s){ + std::cout << "Vbo: allocation de "<< s << " octets." << std::endl; + return malloc(s*sizeof(Vbo)); + } + }; @@ -222,23 +241,23 @@ public: * ****************/ -struct Vbo_container : public Vbo{ +// struct Vbo_container : public Vbo{ -public: +// public: - /*! - * \brief The default constructor. - */ - Vbo_container():Vbo(4, 8000, GL_QUADS, GL_VERTEX_ARRAY){ - } +// /*! +// * \brief The default constructor. +// */ +// Vbo_container():Vbo(4, 8000, GL_QUADS, GL_VERTEX_ARRAY){ +// } - /*! - * \brief The destructor. - */ - virtual ~Vbo_container(){ - } +// /*! +// * \brief The destructor. +// */ +// virtual ~Vbo_container(){ +// } -}; +// }; @@ -252,47 +271,47 @@ public: ****************/ -/*! - * \brief VBO uses for triangle arrows. - */ -struct Vbo_arrow_triangle : public Vbo{ +// /*! +// * \brief VBO uses for triangle arrows. +// */ +// struct Vbo_arrow_triangle : public Vbo{ -public: +// public: - /*! - * \brief The default constructor. - */ - Vbo_arrow_triangle():Vbo(3, 2000, GL_TRIANGLES, GL_VERTEX_ARRAY){ - } +// /*! +// * \brief The default constructor. +// */ +// Vbo_arrow_triangle():Vbo(3, 2000, GL_TRIANGLES, GL_VERTEX_ARRAY){ +// } - /*! - * \brief The destructor. - */ - virtual ~Vbo_arrow_triangle(){ - } -}; +// /*! +// * \brief The destructor. +// */ +// virtual ~Vbo_arrow_triangle(){ +// } +// }; -/*! - * \brief VBO uses for line arrows. - */ -struct Vbo_arrow_line : public Vbo{ +// /*! +// * \brief VBO uses for line arrows. +// */ +// struct Vbo_arrow_line : public Vbo{ -public: +// public: - /*! - * \brief The default constructor. - */ - Vbo_arrow_line():Vbo(2, 8000, GL_LINES, GL_VERTEX_ARRAY){ - } +// /*! +// * \brief The default constructor. +// */ +// Vbo_arrow_line():Vbo(2, 8000, GL_LINES, GL_VERTEX_ARRAY){ +// } - /*! - * \brief The destructor. - */ - virtual ~Vbo_arrow_line(){ - } -}; +// /*! +// * \brief The destructor. +// */ +// virtual ~Vbo_arrow_line(){ +// } +// }; #endif diff --git a/src/src.pro b/src/src.pro index 787bd2a..f209dfc 100644 --- a/src/src.pro +++ b/src/src.pro @@ -64,6 +64,8 @@ LIBS += general/otf/otflib/.libs/libotf.a -Lgeneral/otf/otflib/.libs # LIBS += -lglut #} +LIBS += -lGLEW + macx { QMAKESPEC = macx-g++ # QMAKE_LFLAGS += -F/System/Library/Frameworks/GLUT @@ -97,7 +99,8 @@ HEADERS += common/common.hpp \ render/render_stats.hpp \ render/render_stats_opengl.hpp \ render/render_stats_svg.hpp \ -# render/vbo.hpp \ + render/Render_alternate.hpp \ + render/vbo.hpp \ # Parser headers parser/Definition.hpp \ parser/Line.hpp \ @@ -202,7 +205,8 @@ SOURCES += common/Message.cpp \ render/Render_svg.cpp \ render/render_stats_opengl.cpp \ render/render_stats_svg.cpp \ -# render/vbo.cpp \ + render/Render_alternate.cpp \ + render/vbo.cpp \ # Statistics code files statistics/Stats_window.cpp \ statistics/Statistic.cpp \ -- GitLab