Commit dcf9a4b1 authored by Thibault Soucarre's avatar Thibault Soucarre

Delete shaders map in render_alternate. Shader is now an attribute of class Vbo

parent 75002fc4
#include <string>
#include <map>
#include <iostream>
/* -- */
#include "trace/values/Value.hpp"
#include "trace/values/Color.hpp"
......@@ -25,8 +26,10 @@ Palette::~Palette() {
Color *Palette::get_color(const std::string &state_name) {
if(_pairs.find(state_name) != _pairs.end() /*&& is_visible(state_name)*/)
return _pairs[state_name];
else
else{
std::cout << state_name << " non trouvé" << std::endl;
return NULL;
}
}
bool Palette::is_visible(const std::string &state_name){
......
......@@ -300,6 +300,7 @@ void Settings_window::add_table_line(QTableWidget *table,
table->setCellWidget(row, 1, color_widget);
table->setCellWidget(row, 2, cb);
row ++;
}
void Settings_window::fill_table( QTableWidget *table,
......@@ -331,7 +332,17 @@ void Settings_window::fill_table( QTableWidget *table,
}
map<string, Color *>::const_iterator it;
for(it = colors_trace.begin();
it!= colors_trace.end();
it++){
if(p->get_color(it->first) == NULL){
std::cout << " Coucou " << pname << it->first << std::endl;
p->add_state(it->first, *(it->second), true);
Session::getSession().add_state_to_palette(pname, palette_list->currentText().toStdString(), it->first, *(it->second), true);
}
if(it->second == NULL)
std::cout << "Problème" << std::endl;
}
colors_settings.insert( colors_trace.begin(), colors_trace.end() );
for(it = colors_settings.begin();
......
......@@ -101,13 +101,13 @@ static bool _draw_counter;
Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format)
: Hook_event(this, core, parent, format),
_glsl(0),
_containers(GL_QUADS),
_containers(NULL),
/*_states(GL_QUADS),*/
//_arrows(GL_LINE),
//_arrows2(GL_TRIANGLES),
_counters(GL_LINE),
_ruler(GL_QUADS),
_wait(GL_QUADS),
_counters(NULL),
_ruler(NULL),
_wait(NULL),
_modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)),
_container_height(_DRAWING_CONTAINER_HEIGHT_DEFAULT)
{
......@@ -152,9 +152,8 @@ void Render_alternate::initializeGL() {
std::cout << _glsl << std::endl;
_shader = new Shader(_glsl);
_wait_shader = new Shader(_glsl, 0);
//_wait_shader = new Shader(_glsl, 0);
_shader->charger();
_wait_shader->charger();
draw_wait();
setAutoFillBackground(false);
if(_core == NULL)
......@@ -187,7 +186,7 @@ void Render_alternate::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*Draw the home screen*/
if(DRAWING_STATE_WAITING == _state){
glUseProgram(_wait_shader->getProgramID());
glUseProgram(_wait.get_shader()->getProgramID());
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_wait.lock();
......@@ -206,7 +205,7 @@ void Render_alternate::paintGL(){
//select shader program
glUseProgram(_shader->getProgramID());
std::cout << "paintGL" << std::endl;
glm::mat4 tmp = _modelview;
glm::mat4 tmp = _modelview;
glm::mat4 tmp2 = _modelview;
glm::mat4 mvp;
start_ruler();
......@@ -228,6 +227,8 @@ void Render_alternate::paintGL(){
_modelview = tmp;
/* drawing containers*/
Shader*s = _containers.get_shader();
glUseProgram(s->getProgramID());
_containers.lock();
_modelview = glm::translate(_modelview, glm::vec3(0.0, _ruler_y + _ruler_height - _y_state_translate, _z_container));
_modelview = glm::scale(_modelview, glm::vec3(_x_scale_container_state/0.20, _y_state_scale, 1.0));
......@@ -244,7 +245,7 @@ void Render_alternate::paintGL(){
std::map<EntityValue*, Vbo*>::iterator it_state;
it_state = _states.begin();
while(it_state!=_states.end()){
Shader *s = _states_shaders[it_state->first];
Shader *s = it_state->second->get_shader();
glUseProgram(s->getProgramID());
it_state->second->lock();
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
......@@ -253,10 +254,11 @@ void Render_alternate::paintGL(){
it_state->second->unlock();
it_state++;
}
glUseProgram(_shader->getProgramID());
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
/*drawing counters*/
glUseProgram(_counters.get_shader()->getProgramID());
glUniformMatrix4fv(glGetUniformLocation(_counters.get_shader()->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
_counters.lock();
glDrawArrays(GL_LINES, 0, _counters.getNbVertex());
_counters.unlock();
......@@ -271,10 +273,10 @@ void Render_alternate::paintGL(){
//draw the lines
std::map<EntityValue*, std::pair<Vbo *, Vbo*> >::iterator it_arrow = _arrows.begin();
while(it_arrow != _arrows.end()){
Shader*s = _arrows_shaders[it_arrow->first];
Shader *s = it_arrow->second.first->get_shader();
glUseProgram(s->getProgramID());
it_arrow->second.first->lock();
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
if(it_arrow->first == NULL || it_arrow->first->get_visible())
glDrawArrays(GL_LINES, 0, it_arrow->second.first->getNbVertex());
it_arrow->second.first->unlock();
......@@ -296,7 +298,7 @@ void Render_alternate::paintGL(){
tmp2 = _modelview;
_arrows3.lock();
while(it_link != _links.end()){
Shader *s = _arrows_shaders[it_link->first];
Shader *s = _arrows[it_link->first].first->get_shader();
glUseProgram(s->getProgramID());
std::vector<Element_pos> v = it_link->second;
int n = v.size()/3;
......@@ -307,18 +309,18 @@ void Render_alternate::paintGL(){
}
for(int i=0 ; i<n ; i++){
_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale * v[3*i], _y_state_scale * v[3*i+1], 0));
_modelview = glm::rotate(_modelview, v[3*i+2], glm::vec3(0, 0, 1));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
_modelview = glm::rotate(_modelview, v[3*i+2], glm::vec3(0, 0, 1));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_TRIANGLES, 0, _arrows3.getNbVertex());
_modelview = tmp2;
glDrawArrays(GL_TRIANGLES, 0, _arrows3.getNbVertex());
_modelview = tmp2;
}
it_link++;
}
_arrows3.unlock();
}
_modelview = tmp;
_modelview = tmp;
}
/*drawing events*/
......@@ -328,10 +330,10 @@ void Render_alternate::paintGL(){
mvp = _projection * _modelview;
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it_event = _events.begin();
while(it_event != _events.end()){
Shader *s = _events_shaders[it_event->first];
Shader *s = it_event->second.first->get_shader();
glUseProgram(s->getProgramID());
it_event->second.first->lock();
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
if(it_event->first==NULL || it_event->first->get_visible()){
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SMOOTH);
......@@ -641,6 +643,9 @@ bool Render_alternate::unbuild(){
GLuint Render_alternate::draw_wait() {
Shader *s = new Shader(_glsl, 0);
s->charger();
_wait.set_shader(s);
glGenTextures(1, &_textureID);
QFile texture_file(QString(":/img/img/logo") + QDate::currentDate().toString("MMdd") + QString(".png"));
glBindTexture(GL_TEXTURE_2D, _textureID);
......@@ -759,8 +764,8 @@ void Render_alternate::draw_line(Element_pos x1, Element_pos y1, Element_pos x2,
const Element_pos offset_y = -_ruler_y - _ruler_height;
if(_draw_counter){
_counters.add(x1+offset_x,y1+offset_y,_r,_g,_b);
_counters.add(x2+offset_x,y2+offset_y,_r,_g,_b);
_counters.add(x1+offset_x,y1+offset_y);//,_r,_g,_b);
_counters.add(x2+offset_x,y2+offset_y);//,_r,_g,_b);
}
else if(_draw_ruler){
_ruler.add(x1+offset_x, y1, _r, _g, _b);
......@@ -781,6 +786,9 @@ void Render_alternate::start_draw(){
void Render_alternate::start_draw_containers(){
_draw_container = true;
Shader *s = new Shader(_glsl);
s->charger();
_containers.set_shader(s);
}
void Render_alternate::draw_container(const Element_pos , const Element_pos , const Element_pos , const Element_pos ){
......@@ -804,9 +812,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons
Shader *s = new Shader(_glsl, _r, _g, _b, true);
s->charger();
//assert(value); // TODO: check why busy state exists and uncomment this assert
std::pair<EntityValue*, Shader*> p(value, s);
_states_shaders.insert(p);
Vbo *v = new Vbo(GL_QUADS);
Vbo *v = new Vbo(s);
std::pair<EntityValue*, Vbo*> p2(value, v);
_states.insert(p2);
}
......@@ -836,16 +842,14 @@ void Render_alternate::start_draw_arrows(){
if(_arrows.count(value) == 0){
Shader *s = new Shader(_glsl, _r, _g, _b, false);
s->charger();
std::pair<EntityValue*, Shader*> p(value, s);
_arrows_shaders.insert(p);
Vbo* v1 = new Vbo(GL_LINES);
Vbo* v2 = new Vbo(GL_POINTS);
std::pair<Vbo*, Vbo*> p2(v1, v2);
std::pair<EntityValue*, std::pair<Vbo*, Vbo*> > p3(value, p2);
_arrows.insert(p3);
Vbo* v1 = new Vbo(s);
Vbo* v2 = new Vbo(s);
std::pair<Vbo*, Vbo*> p1(v1, v2);
std::pair<EntityValue*, std::pair<Vbo*, Vbo*> > p2(value, p1);
_arrows.insert(p2);
std::vector<Element_pos> v;
std::pair<EntityValue*, std::vector<Element_pos> > p4(value, v);
_links.insert(p4);
std::pair<EntityValue*, std::vector<Element_pos> > p3(value, v);
_links.insert(p3);
}
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
......@@ -904,13 +908,11 @@ void Render_alternate::draw_event(const Element_pos time, const Element_pos heig
if(_events.count(value) == 0){
Shader *s = new Shader(_glsl, _r, _g, _b, false);
s->charger();
std::pair<EntityValue*, Shader*> p(value, s);
_events_shaders.insert(p);
Vbo* v1 = new Vbo(GL_POINTS);
Vbo* v2 = new Vbo(GL_LINES);
std::pair<Vbo*, Vbo*> p2(v1, v2);
std::pair<EntityValue*, std::pair<Vbo*, Vbo*> > p3(value, p2);
_events.insert(p3);
Vbo* v1 = new Vbo(s);
Vbo* v2 = new Vbo(s);
std::pair<Vbo*, Vbo*> p1(v1, v2);
std::pair<EntityValue*, std::pair<Vbo*, Vbo*> > p2(value, p1);
_events.insert(p2);
}
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
......@@ -943,6 +945,9 @@ void Render_alternate::end_draw_events(){
void Render_alternate::start_draw_counter(){
_draw_counter = true;
Shader *s = new Shader(_glsl, 1, 1, 1, false);
s->charger();
_counters.set_shader(s);
}
void Render_alternate::draw_counter(const Element_pos , const Element_pos ){
......@@ -1055,19 +1060,19 @@ void Render_alternate::clear_text (){
}
void Render_alternate::change_color(std::string entity, Element_col r, Element_col g, Element_col b){
std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin();
while(it != _states_shaders.end()){
std::map<EntityValue*, Vbo*>::iterator it;
it = _states.begin();
while(it != _states.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
if(it->first && (it->first->get_name() == entity)){
Color *c = new Color(r, g, b);
it->first->set_used_color(c);
Shader* s = it->second;
delete s;
s = new Shader(_glsl, r, g, b, true);
it->second->delete_shader();
Shader *s = new Shader(_glsl, r, g, b, true);
s->charger();
it->second->set_shader(s);
break;
}
it++;
......@@ -1075,19 +1080,20 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c
}
void Render_alternate::change_event_color(std::string event, Element_col r, Element_col g, Element_col b){
std::map<EntityValue*, Shader*>::iterator it;
it = _events_shaders.begin();
while(it != _events_shaders.end()){
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it;
it = _events.begin();
while(it != _events.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
if(it->first && (it->first->get_name() == event)){
Color *c = new Color(r, g, b);
it->first->set_used_color(c);
Shader* s = it->second;
delete s;
s = new Shader(_glsl, r, g, b, false);
it->second.first->delete_shader();
Shader *s = new Shader(_glsl, r, g, b, false);
s->charger();
it->second.first->set_shader(s);
it->second.second->set_shader(s);
break;
}
it++;
......@@ -1096,9 +1102,9 @@ void Render_alternate::change_event_color(std::string event, Element_col r, Elem
void Render_alternate::change_link_color(std::string link, Element_col r, Element_col g, Element_col b){
std::cout << "change_link_color" << " " << link << std::endl;
std::map<EntityValue*, Shader*>::iterator it;
it = _arrows_shaders.begin();
while(it != _arrows_shaders.end()){
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it;
it = _arrows.begin();
while(it != _arrows.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
......@@ -1106,22 +1112,21 @@ void Render_alternate::change_link_color(std::string link, Element_col r, Elemen
std::cout << "xd lol" << std::endl;
Color *c = new Color(r, g, b);
it->first->set_used_color(c);
Shader* s = it->second;
delete s;
s = new Shader(_glsl, r, g, b, false);
it->second.first->delete_shader();
Shader *s = new Shader(_glsl, r, g, b, false);
s->charger();
it->second.first->set_shader(s);
it->second.second->set_shader(s);
break;
}
else if(it->first)
std::cout << it->first->get_name().get_name() << std::endl;
it++;
}
}
void Render_alternate::change_visible(std::string entity, bool visible){
std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin();
while(it != _states_shaders.end()){
std::map<EntityValue*, Vbo*>::iterator it;
it = _states.begin();
while(it != _states.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
......@@ -1134,9 +1139,9 @@ void Render_alternate::change_visible(std::string entity, bool visible){
}
void Render_alternate::change_event_visible(std::string event, bool visible){
std::map<EntityValue*, Shader*>::iterator it;
it = _events_shaders.begin();
while(it != _states_shaders.end()){
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it;
it = _events.begin();
while(it != _events.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
......@@ -1149,9 +1154,9 @@ std::map<EntityValue*, Shader*>::iterator it;
}
void Render_alternate::change_link_visible(std::string link, bool visible){
std::map<EntityValue*, Shader*>::iterator it;
it = _arrows_shaders.begin();
while(it != _arrows_shaders.end()){
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it;
it = _arrows.begin();
while(it != _arrows.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
......@@ -1165,53 +1170,55 @@ std::map<EntityValue*, Shader*>::iterator it;
void Render_alternate::reload_states(){
std::map<EntityValue*, Shader*>::iterator it = _states_shaders.begin();
while(it != _states_shaders.end()){
std::map<EntityValue*, Vbo*>::iterator it = _states.begin();
while(it != _states.end()){
if(it->first){
it->first->reload_file_color();
it->first->set_visible(true);
Shader* s = it->second;
delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->second->delete_shader();
Shader* s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->first->get_used_color()->get_green(),
it->first->get_used_color()->get_blue(),
true);
s->charger();
it->second->set_shader(s);
}
it++;
}
}
void Render_alternate::reload_links(){
std::map<EntityValue*, Shader*>::iterator it = _arrows_shaders.begin();
while(it != _arrows_shaders.end()){
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it = _arrows.begin();
while(it != _arrows.end()){
if(it->first){
it->first->reload_file_color();
it->first->set_visible(true);
Shader* s = it->second;
delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->second.first->delete_shader();
Shader* s = s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->first->get_used_color()->get_green(),
it->first->get_used_color()->get_blue(),
false);
s->charger();
it->second.first->set_shader(s);
it->second.second->set_shader(s);
}
it++;
}
}
void Render_alternate::reload_events(){
std::map<EntityValue*, Shader*>::iterator it = _events_shaders.begin();
while(it != _events_shaders.end()){
std::map<EntityValue*, std::pair<Vbo*, Vbo*> >::iterator it = _events.begin();
while(it != _events.end()){
if(it->first){
it->first->reload_file_color();
it->first->set_visible(true);
Shader* s = it->second;
delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->second.first->delete_shader();
Shader* s = s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->first->get_used_color()->get_green(),
it->first->get_used_color()->get_blue(),
false);
s->charger();
it->second.first->set_shader(s);
it->second.second->set_shader(s);
}
it++;
}
......
......@@ -101,7 +101,7 @@ class Render_alternate : /*public QGLWidget,*/ public Hook_event, public Render
private:
int _glsl; //version of OpenGL Shading Language
Shader* _shader;
Shader* _wait_shader;
//Shader* _wait_shader;
Element_pos _container_height;
Element_col _r;
Element_col _g;
......@@ -125,13 +125,13 @@ private:
Vbo *_current;
GLuint _textureID;
std::map<EntityValue*, Vbo*> _states;
std::map<EntityValue*, Shader*> _states_shaders;
//std::map<EntityValue*, Shader*> _states_shaders;
//first element of the pair contains the points, second contains the lines
std::map<EntityValue*, std::pair<Vbo*, Vbo*> > _events;
std::map<EntityValue*, Shader*> _events_shaders;
//std::map<EntityValue*, Shader*> _events_shaders;
//first element of the pair contains the line of the arrow, second contains the position of the head
std::map<EntityValue*, std::pair<Vbo*, Vbo*> > _arrows;
std::map<EntityValue*, Shader*> _arrows_shaders;
//std::map<EntityValue*, Shader*> _arrows_shaders;
std::map<EntityValue*, std::vector<Element_pos> > _links;
/*!
* \brief Offset of the vertical helper line
......
......@@ -51,6 +51,7 @@
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "vbo.hpp"
#include "Shader.hpp"
#define ERROR(m) printf("%s", m);
......@@ -72,8 +73,8 @@ Vbo::Vbo(){
_nbVertex=0;
}
Vbo::Vbo(GLenum mode){
_mode = mode;
Vbo::Vbo(Shader *s){
_shader = s;
_nbVertex = 0;
}
......@@ -246,4 +247,15 @@ void Vbo::setNbVertex(int n){
_nbVertex = n;
}
Shader * Vbo::get_shader(){
return _shader;
}
void Vbo::delete_shader(){
delete _shader;
_shader = NULL;
}
void Vbo::set_shader(Shader *s){
_shader = s;
}
......@@ -52,7 +52,7 @@ using namespace std;
//macro used by OpenGL
#define BUFFER_OFFSET(a) ((char*)NULL + (a))
class Shader;
/*!
* \brief Manage the Vertex Buffer Object.
*/
......@@ -61,12 +61,13 @@ class Vbo{
private:
GLuint _vboID;
GLuint _vaoID;
Shader *_shader;
vector<Element_pos> _vertex;
vector<Element_col> _colors;
vector<char> _shaded;
vector<float> _shaded2;
vector<Element_pos> _texture_coord;
GLenum _mode;
//GLenum _mode;
int _nbVertex;
/*!
......@@ -75,12 +76,6 @@ private:
public:
enum Type{
TRIANGLES,
QUADS,
LINES
};
/***********************************
*
......@@ -92,7 +87,7 @@ public:
* \brief Constructor.
*/
Vbo();
Vbo(GLenum mode);
Vbo(Shader *s);
/*!
* \brief The destructor.
......@@ -119,6 +114,9 @@ public:
int getNbVertex();
void setNbVertex(int);
void config(int glsl);
Shader * get_shader();
void delete_shader();
void set_shader(Shader *s);
};
......
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