Commit 5db8c995 authored by Thibault Soucarre's avatar Thibault Soucarre

Add two maps for drawing states, containing vbo and shaders. Shaders are default at the moment

parent 6f3d5c5f
......@@ -267,15 +267,21 @@ public:
* \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) {
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, const StateType * type) {
drawing_instance->set_color(r, g, b);
drawing_instance->draw_quad(trace_to_render_x(start - Info::Render::_x_min_visible),
/*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());
height*coeff_trace_render_y());*/
drawing_instance->draw_state(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(),
type);
}
/*!
......
......@@ -47,7 +47,7 @@
#ifndef RENDER_HPP
#define RENDER_HPP
class StateType;
/*!
* \brief This class provides an interface for render classes like OpenGL or SVG.
*/
......@@ -76,6 +76,8 @@ public:
*/
virtual void start_draw_states() = 0;
virtual void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const StateType* type) = 0;
/*!
* \brief Called when all state draws are finished.
*/
......
......@@ -66,10 +66,10 @@
#include "render/Render_alternate.hpp"
#include "render/GanttDiagram.hpp"
#include "render/Shader.hpp"
#include "render/text2D.hpp"
/* -- */
#include "core/Core.hpp"
#include "render/vbo.hpp"
#include "trace/StateType.hpp"
#include <iostream>
#define PI 3.14159265
#define NB_STEPS 20
......@@ -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),*/ _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)){
setAutoFillBackground(false);
......@@ -200,17 +200,24 @@ void Render_alternate::paintGL(){
_modelview = tmp;
/*drawing states*/
_states.lock();
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, _z_state));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1));
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_QUADS, 0, _states.getNbVertex());
_states.unlock();
//_modelview = tmp;
std::map<const StateType*, Vbo>::iterator it_state;
it_state = _states.begin();
while(it_state!=_states.end()){
Shader *s = &(_states_shaders[it_state->first]);
glUseProgram(s->getProgramID());
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
it_state->second.lock();
//_states.lock();
//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_QUADS, 0, it_state->second.getNbVertex());
it_state->second.unlock();
it_state++;
//_modelview = tmp;
}
/*drawing counters*/
_counters.lock();
glDrawArrays(GL_LINES, 0, _counters.getNbVertex());
......@@ -663,10 +670,10 @@ void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, El
}
else if(_draw_states){
offset_x = -_default_entity_x_translate;
_states.add(x+offset_x , y+offset_y , _r, _g, _b);
_states.add(x+offset_x+w, y+offset_y , _r/2, _g/2, _b/2);
_states.add(x+offset_x+w, y+offset_y+h, _r/2, _g/2, _b/2);
_states.add(x+offset_x , y+offset_y+h, _r, _g, _b);
_current->add(x+offset_x , y+offset_y , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h, _r, _g, _b);
}
else if(_draw_ruler){
}
......@@ -738,13 +745,29 @@ void Render_alternate::start_draw_states(){
_draw_states = true;
}
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::draw_state(const Element_pos x, const Element_pos y, const Element_pos z, const Element_pos w, const Element_pos h, const StateType* type){
if(!_states.count(type)){
Shader s;
std::pair<const StateType*, Shader> p(type, s);
_states_shaders.insert(p);
Vbo v(GL_QUADS);
std::pair<const StateType*, Vbo> p2(type, v);
_states.insert(p2);
}
_current = &(_states[type]);
draw_quad(x, y, z, w, h);
}
void Render_alternate::end_draw_states(){
_draw_states = false;
_states.config();
std::map<const StateType*, Vbo>::iterator it;
it = _states.begin();
while(it!=_states.end()){
it->second.config();
it++;
}
//_states.config();
cout << "end_draw_states" << endl;
}
......
......@@ -74,6 +74,7 @@
class Render_alternate;
class Interface_console;
class StateType;
struct Container_text_;
/*!
* \brief Structure used to store text for variables.
......@@ -101,11 +102,14 @@ private:
glm::mat4 _modelview;
glm::mat4 _projection;
Vbo _containers;
Vbo _states;
//Vbo _states;
Vbo _circles;
Vbo _arrows;
Vbo _counters;
Vbo _ruler;
Vbo *_current;
std::map<const StateType*, Vbo> _states;
std::map<const StateType*, Shader> _states_shaders;
/*!
* \brief Offset of the vertical helper line
*/
......@@ -239,7 +243,7 @@ public:
* \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);
void draw_state(const Element_pos start , const Element_pos end, const Element_pos base, const Element_pos height, const Element_pos r, const StateType* type);
/*!
* \brief Closes the state display list.
......
......@@ -329,3 +329,6 @@ void Render_svg::set_vertical_line(Element_pos l){
void Render_svg::call_ruler(){
}
void Render_svg::draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const StateType* type){
}
......@@ -311,6 +311,8 @@ public:
* \brief Draw the ruler display list.
*/
void call_ruler();
void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const StateType* type);
};
......
......@@ -69,7 +69,6 @@ private:
/*!
* \brief The default constructor. Cannot be use for instantiation.
*/
Vbo();
public:
......@@ -89,7 +88,7 @@ public:
/*!
* \brief Constructor.
*/
Vbo();
Vbo(GLenum mode);
/*!
......
......@@ -119,9 +119,9 @@ public:
* \param g Green value of the state color
* \param b Blue value of the state color
*/
inline void draw_state(double starttime, double endtime, double r, double g, double b) {
inline void draw_state(double starttime, double endtime, double r, double g, double b, const StateType * type) {
Element_pos y = _position + _container_v_space/2;
_draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b);
_draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b, type);
}
/*!
......@@ -142,7 +142,7 @@ public:
* \brief Function that display a purple square in the interval selected
*/
inline void draw_busy(Interval *I) {
draw_state(I->_left.get_value(), I->_right.get_value(), 0.2, 0.2, 0.2);
draw_state(I->_left.get_value(), I->_right.get_value(), 0.2, 0.2, 0.2, NULL);
}
};
......@@ -271,8 +271,10 @@ struct DrawNode<D, StateChange> {
color=new Color(0.7, 0.7, 0.75);
}
}
const StateType * type = state->get_type();
draw->draw_state(interval->_left.get_value(), state->get_end_time().get_value(),
color->get_red(), color->get_green(), color->get_blue());
color->get_red(), color->get_green(), color->get_blue(), type);
}
......@@ -325,7 +327,7 @@ struct DrawNode<D, StateChange> {
}
}
draw->draw_state(state->get_start_time().get_value(), max,
color->get_red(), color->get_green(), color->get_blue());
color->get_red(), color->get_green(), color->get_blue(), state->get_type());
}
}
......
Markdown is supported
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