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 diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -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.
*/
......
......@@ -43,14 +43,15 @@
/*!
*\file vbo.cpp
*/
#include "common/common.hpp"
/* -- */
#include "render/vbo.hpp"
/* -- */
using namespace std;
#include <GL/glew.h>
#include <stdlib.h>
#include <iostream>
#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);
}
......@@ -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:
* <li><b>VBO_UNDEFINED_ERROR</b>: an error occurs but has not been identified.
* </ul>
*/
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
......@@ -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 \
......