Commit 2fde8f3e authored by Thibault Soucarre's avatar Thibault Soucarre
Browse files

using vbos for rendering links and events

parent 1c8ed651
......@@ -98,7 +98,7 @@ static bool _draw_counter;
**********************************/
Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format)
: Hook_event(this, core, parent, format), _containers(GL_QUADS), /*_states(GL_QUADS),*/ _circles(GL_POLYGON), _arrows(GL_LINE), _counters(GL_LINE), _ruler(GL_QUADS), /*_shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"),*/ _modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)){
: Hook_event(this, core, parent, format), _containers(GL_QUADS), /*_states(GL_QUADS),*/ _events(GL_POINTS), _events2(GL_LINES), _arrows(GL_LINE), _arrows2(GL_TRIANGLES), _counters(GL_LINE), _ruler(GL_QUADS), /*_shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"),*/ _modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)), _container_height(_DRAWING_CONTAINER_HEIGHT_DEFAULT){
setAutoFillBackground(false);
......@@ -229,7 +229,7 @@ void Render_alternate::paintGL(){
_counters.unlock();
_modelview = tmp;
/*drawing links*/
int n = _links.size()/4;
//int n = _links.size()/4;
if(false == Info::Render::_no_arrows){
//necessary for each link
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , _z_arrow));
......@@ -238,34 +238,35 @@ void Render_alternate::paintGL(){
//mvp = _projection * _modelview;
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//save current modelview
tmp2 = _modelview;
//tmp2 = _modelview;
_arrows.lock();
for(int i=0; i<n ; i++) {
/*for(int i=0; i<n ; i++) {
//change matrix to draw the current arrow
_modelview = glm::translate(_modelview, glm::vec3(_links[4*i+2], _links[4*i+3], 0));
_modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
_modelview = glm::scale(_modelview, glm::vec3(_links[4*i+1], _links[4*i+1/10], 1));
_modelview = glm::scale(_modelview, glm::vec3(_links[4*i+1], _links[4*i+1/10], 1));*/
//draw the arrow
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_LINES, 0, 2);
_modelview = tmp2;
}
glDrawArrays(GL_LINES, 0, _arrows.getNbVertex());
//_modelview = tmp2;
//}
_arrows.unlock();
_arrows2.lock();
_modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, 1/_y_state_scale, 1));
tmp2 = _modelview;
for(int i=0; i<n ; i++) {
_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*_links[4*i+2], _y_state_scale*_links[4*i+3], 0));
_modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_TRIANGLES, 0, 3);
_modelview = tmp2;
}
//_modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, 1/_y_state_scale, 1));
//tmp2 = _modelview;
//for(int i=0; i<n ; i++) {
//_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*_links[4*i+2], _y_state_scale*_links[4*i+3], 0));
// _modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
// mvp = _projection * _modelview;
// glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_TRIANGLES, 0, _arrows2.getNbVertex());
// _modelview = tmp2;
//}
_arrows2.unlock();
_modelview = tmp;
//_arrows.unlock();
//restore matrix with changes needed for all links
......@@ -290,37 +291,28 @@ void Render_alternate::paintGL(){
//}
/*drawing events*/
if(false == Info::Render::_no_events){
n = _events.size()/3;
//necessary for each event
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , _z_event));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
tmp2 = _modelview;
_circles.lock();
for(int i=0; i<n ; i++){
//change matrix to draw the current event
_modelview = glm::translate(_modelview, glm::vec3(_events[3*i], _events[3*i+1], _z_event));
_modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, Info::Screen::width/(_y_state_scale*Info::Screen::height), 1.0));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_POLYGON, 0, NB_STEPS);
_modelview = glm::scale(_modelview, glm::vec3(1.0, _events[3*i+2]*_y_state_scale*Info::Screen::height/Info::Screen::width, 1.0));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glLineWidth(3.0);
glDrawArrays(GL_LINES, NB_STEPS, 2);
glLineWidth(1.0);
//_circles.unlock();
//restore matrix with changes needed for all events
_modelview = tmp2;
}
_circles.unlock();
//restore basic matrix
_modelview = tmp;
_events.lock();
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SMOOTH);
glPointSize(5);
glDrawArrays(GL_POINTS, 0, _events.getNbVertex());
_events.unlock();
_events2.lock();
glDrawArrays(GL_LINES, 0, _events2.getNbVertex());
_events2.unlock();
}
//restore basic matrix
_modelview = tmp;
/*draw selection if necessary*/
if (_mouse_pressed && (Info::Render::_key_ctrl == false) && !_mouse_pressed_inside_container){
//allow transparency
......@@ -826,9 +818,23 @@ void Render_alternate::draw_arrow(const Element_pos start_time, const Element_po
l = sqrt(pow(x1-x0,2)+pow(y1-y0,2));
//calculate angle beetween arrow and horizontal axe
cosa = (x1-x0)/l;
sina = (y1-y0)/l;
sina = (y0-y1)/l;
alpha = acos(cosa);
if(sina<0) alpha*= -1;
Element_pos cos30 = cos(PI/6.0);
Element_pos sin30 = sin(PI/6.0);
cosa*=(_container_height/2.0);
sina*=(_container_height/2.0);
_arrows.add(x0, y0, 1, 1, 1);
_arrows.add(x1, y1, 1, 1, 1);
//_arrows2.add(x1, y1, 1, 1, 1);
_arrows2.add(x1, y1, 1, 1, 1);
_arrows2.add(x1 - cosa*cos30 - sina*sin30,
y1 + sina*cos30 - cosa*sin30,
1, 1, 1);
_arrows2.add(x1 - cosa*cos30 + sina*sin30,
y1 + sina*cos30 + cosa*sin(30),
1, 1, 1);
/*glm::mat4 m(1.0);
m = glm::translate(m, glm::vec3(x0, y0, 0));
m = glm::rotate(m, alpha, glm::vec3(0,0,1));
......@@ -849,21 +855,21 @@ void Render_alternate::draw_arrow(const Element_pos start_time, const Element_po
_arrows2.add(v4.x, v4.y, 1, 1, 1);
_arrows.add(x0, y0, 0, 1, 1);
_arrows.add(x1, y1, 0, 1, 1);*/
_links.push_back(alpha);
_links.push_back(l);
_links.push_back(x1);
_links.push_back(y1);
//_links.push_back(alpha);
//_links.push_back(l);
//_links.push_back(x1);
//_links.push_back(y1);
//_arrows.add(x0, y0, 1, 1, 1);
//_arrows.add(x1, y1, 1, 1, 1);
}
void Render_alternate::end_draw_arrows(){
//coordinates that we use for all arrows, we will change the angle and scale of using the modelview matrix
_arrows2.add(0,0,1,1,1);
_arrows2.add(-1.2, -0.4, 1, 1, 1);
_arrows2.add(-1.2, 0.4, 1, 1, 1);
_arrows.add(0,0,1,1,1);
_arrows.add(-1,0,1,1,1);
//_arrows2.add(0,0,1,1,1);
//_arrows2.add(-1.2, -0.4, 1, 1, 1);
//_arrows2.add(-1.2, 0.4, 1, 1, 1);
//_arrows.add(0,0,1,1,1);
//_arrows.add(-1,0,1,1,1);
//_arrows.add(0,0,1,1,1);
//_arrows.add(cos(PI/8), -sin(PI/8), 1, 1, 1);
//_arrows.add(1,0,1,1,1);
......@@ -883,28 +889,33 @@ void Render_alternate::draw_event(const Element_pos time, const Element_pos heig
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
_events.push_back(time + offset_x);
_events.push_back(height + offset_y);
_events.push_back(container_height);
//_events.push_back(time + offset_x);
//_events.push_back(height + offset_y);
//_events.push_back(container_height);
_events.add(time+offset_x, height + offset_y, 1, 1, 1);
_events2.add(time+offset_x, height + offset_y, 1, 1, 1);
_events2.add(time+offset_x, height+offset_y+container_height/2, 1, 1, 1);
}
void Render_alternate::end_draw_events(){
//As for arrows, we use the same coordinates for every events we draw. Position is changed using modelview matrix
set_color(1.0, 1.0, 1.0);
const float angle = 0;
/*const float angle = 0;
const float delta_angle = 2 * PI / NB_STEPS;
const float radius = 0.5;
for(int j = 0 ; j < NB_STEPS ; j ++){
_circles.add(radius*cos(angle + j*delta_angle), radius*sin(angle + j*delta_angle), _r, _g, _b);
}
_circles.add(0, 0, _r, _g, _b);
_circles.add(0, 0.5, _r, _g, _b);
}*/
//_circles.add(0, 0, _r, _g, _b);
//_circles.add(0, 0.5, _r, _g, _b);
//_circles.add(0, 0, _r, _g, _b);
//_circles.add(cos_table[j]/_x_state_scale, (sin_table[j]*Info::Screen::width)/(_y_state_scale*Info::Screen::height), _r, _g, _b);
// cos_table2[2*j]= cos_table[j]/_x_state_scale;
// sin_table2[2*j+1]= (sin_table[j]*Info::Screen::width)/(_y_state_scale*Info::Screen::height);
_circles.config();
_events.config();
_events2.config();
_draw_event = false;
cout << "end_draw_events" << endl;
}
......
......@@ -84,26 +84,36 @@ struct Variable_text_{
Element_pos value;
};
/*!
* \def _DRAWING_CONTAINER_HEIGHT_DEFAULT
* \brief The default height for basic containers.
*/
#define _DRAWING_CONTAINER_HEIGHT_DEFAULT 1.2f
/*!
* \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
*/
class Render_alternate : /*public QGLWidget,*/ public Hook_event, public Render
{
Q_OBJECT
private:
Shader _shader;
Element_pos _container_height;
Element_col _r;
Element_col _g;
Element_col _b;
std::vector<Element_pos> _links;
std::vector<Element_pos> _events;
//std::vector<Element_pos> _events;
std::vector<Container_text_> _texts;
std::map<long int, Variable_text_> _variable_texts;
glm::mat4 _modelview;
glm::mat4 _projection;
Vbo _containers;
//Vbo _states;
Vbo _circles;
Vbo _events;
Vbo _events2;
Vbo _arrows;
Vbo _arrows2;
Vbo _counters;
......@@ -117,165 +127,165 @@ private:
Element_pos vertical_line;
public:
/***********************************
*
* Constructor and destructor.
*
**********************************/
/***********************************
*
* Constructor and destructor.
*
**********************************/
/*!
* \brief The default constructor
*/
Render_alternate(Core* core, QWidget *parent, const QGLFormat& format);
/*!
* \brief The default constructor
*/
Render_alternate(Core* core, QWidget *parent, const QGLFormat& format);
/*!
* \brief The destructor
*/
virtual ~Render_alternate();
/*!
* \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_width(Element_pos){}
/*!
* \brief Set Statistics and Informations about input trace
*/
void set_total_time(Times){}
/*!
* \brief Set Statistics and Informations about input trace
*/
void set_total_time(Times){}
/*!
* \brief display the scale
*/
void display_time_scale(){}
/*!
* \brief display the scale
*/
void display_time_scale(){}
/***********************************
*
* Default QGLWidget functions.
*
**********************************/
/***********************************
*
* Default QGLWidget functions.
*
**********************************/
/*!
* \brief Call by the system to initialize the OpenGL render area.
*/
void initializeGL();
/*!
* \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 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();
/*!
* \brief Call by the system each time the render area need to be updated.
*/
void paintGL();
//void paintEvent(QPaintEvent *event);
//void paintEvent(QPaintEvent *event);
/* void initializeOverlayGL();
void resizeOverlayGL(int width, int height);
void paintOverlayGL();*/
/* void initializeOverlayGL();
void resizeOverlayGL(int width, int height);
void paintOverlayGL();*/
/***********************************
*
* Building functions.
*
**********************************/
/***********************************
*
* Building functions.
*
**********************************/
/*!
* \brief This function constructs the trace.
*/
// bool display_build() ;
/*!
* \brief This function constructs the trace.
*/
// bool display_build() ;
/*!
* \brief This function releases the trace.
*/
// bool display_unbuild() ;
/*!
* \brief This function releases the trace.
*/
// bool display_unbuild() ;
/*!
* \brief Proceeds with the initialization of the OpenGL draw functions.
*/
void start_draw();
/*!
* \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 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 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 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 Closes the container display list.
*/
void end_draw_containers();
/*!
* \brief Creates and opens the display list for stater draws.
*/
void start_draw_states();
/*!
* \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_pos r, const EntityValue* type);
/*!
* \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_pos r, const EntityValue* type);
/*!
* \brief Closes the state display list.
*/
void end_draw_states();
/*!
* \brief Closes the state display list.
*/
void end_draw_states();
/*!
* \brief Open the arrow display list.
*/
void start_draw_arrows();
/*!
* \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 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 Closes the arrow display list.
*/
void end_draw_arrows();
/*!
* \brief Draw arrows contained in the Arrow_ vector
* \param arrows An arrow vector.
*/
/*!
* \brief Draw arrows contained in the Arrow_ vector
* \param arrows An arrow vector.
*/
// void draw_stored_arrows(std::vector<Arrow_> &arrows);
void start_draw_events();
......@@ -523,7 +533,7 @@ public:
Element_pos get_vertical_line();
public slots:
/*!
/*!
* \brief slot connected to the simple click event
*/
void update_vertical_line();
......
......@@ -69,6 +69,7 @@ using namespace std;
**********************************/
Vbo::Vbo(){
_nbVertex=0;
}
Vbo::Vbo(GLenum mode){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment