Commit 15ae9e0b authored by Olivier Lagrasse's avatar Olivier Lagrasse

- 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.
parent a6f33bcf
......@@ -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
......
......@@ -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;
......@@ -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;
};
......
......@@ -45,8 +45,6 @@
*\brief This is the console interface C source code.
*/
//#define WITH_OTF
#include <queue>
#include <string>
......@@ -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_alternate> render(_render_opengl);
#else
Render<Render_opengl> 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;
......
......@@ -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>* _render_opengl;
/*!
......
......@@ -195,8 +195,8 @@ void Interface_graphic::load_windows(){
CKFP(_ui_zoom_box = qFindChild<QComboBox*>(this, "zoom_box"), "Cannot find the zoom box in the .ui file");
CKFP(Info::Render::_ui_render_min_value = qFindChild<QLabel*>(this, "render_min_value"), "Cannot find the render_min_value label in the .ui file");
CKFP(Info::Render::_ui_render_max_value = qFindChild<QLabel*>(this, "render_max_value"), "Cannot find the render_max_value label in the .ui file");
// CKFP(Info::Render::_ui_render_min_value = qFindChild<QLabel*>(this, "render_min_value"), "Cannot find the render_min_value label in the .ui file");
// CKFP(Info::Render::_ui_render_max_value = qFindChild<QLabel*>(this, "render_max_value"), "Cannot find the render_max_value label in the .ui file");
/* Export window */
CKFP(_ui_export_ok_button = qFindChild<QPushButton*>(_ui_time_selection_export, "option_export_ok"), "Cannot find the ok push button in the export dialog .ui file");
......
......@@ -28,55 +28,6 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="render_min_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="render_max_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......@@ -235,7 +186,7 @@
<x>0</x>
<y>0</y>
<width>1060</width>
<height>27</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuHelp">
......
......@@ -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();
......
......@@ -52,6 +52,7 @@
#include "render/Ruler.hpp"
#include "common/info.hpp"
#include <GL/glut.h>
/*!
* \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;
......
/*
** 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 <GL/glew.h>
#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 ; i<texts_size ; i++){
const QFontMetrics metric(arial_font);
const QString text_elided = metric.elidedText(_texts[i].value.c_str(), Qt::ElideRight, _x_scale_container_state*Info::Screen::width/3.);
renderText ( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),
text_elided,
arial_font);
}
/* Draw ruler text */
std::ostringstream buf_txt;
Element_pos graduation_diff;
Element_pos coeff_prefix;
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);
// painter.setFont(QFont("Arial", 14));
arial_font.setPointSize(14);
buf_txt.str("");/* flush the buffer */
buf_txt << "min: " << (double)Info::Render::_x_min_visible;
renderText (render_to_screen_x(trace_to_render_x(Info::Render::_x_min_visible)),
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
buf_txt.str("");/* flush the buffer */
buf_txt << "max: " << (double)Info::Render::_x_max_visible;
renderText (render_to_screen_x(trace_to_render_x(Info::Render::_x_max_visible))-130,
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
buf_txt.str("");
buf_txt << Ruler::get_common_part_string(Info::Render::_x_min_visible, coeff_prefix) << "--";
renderText (render_to_screen_x(
trace_to_render_x(
(Info::Render::_x_min_visible +
Info::Render::_x_max_visible) / 2)),
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
arial_font.setPointSize(10);
for (Element_pos i = Info::Render::_x_min_visible ;
i < Info::Render::_x_max_visible ;
i+=graduation_diff){
buf_txt.str("");/* flush the buffer */
buf_txt << Ruler::get_variable_part(i, coeff_prefix, 2);
renderText (render_to_screen_x(trace_to_render_x(i)+1),
render_to_screen_y(8),
buf_txt.str().c_str(),
arial_font);
}
}
/***********************************