Commit b965c6fd authored by Thibault Soucarre's avatar Thibault Soucarre

New version of Render_alternate that does not need to store colors for each...

New version of Render_alternate that does not need to store colors for each state. States aren't shaded
parent 7daeaaba
......@@ -267,7 +267,7 @@ 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, const StateType * type) {
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 EntityValue * value) {
drawing_instance->set_color(r, g, b);
......@@ -281,7 +281,7 @@ public:
_z_state,
(end-start)*coeff_trace_render_x(),
height*coeff_trace_render_y(),
type);
value);
}
/*!
......
......@@ -47,7 +47,7 @@
#ifndef RENDER_HPP
#define RENDER_HPP
class StateType;
class EntityValue;
/*!
* \brief This class provides an interface for render classes like OpenGL or SVG.
*/
......@@ -76,7 +76,7 @@ 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;
virtual void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const EntityValue* type) = 0;
/*!
* \brief Called when all state draws are finished.
......
......@@ -69,7 +69,7 @@
/* -- */
#include "core/Core.hpp"
#include "render/vbo.hpp"
#include "trace/StateType.hpp"
#include "trace/EntityValue.hpp"
#include <iostream>
#define PI 3.14159265
#define NB_STEPS 20
......@@ -198,21 +198,23 @@ void Render_alternate::paintGL(){
glDrawArrays(GL_QUADS, 0, _containers.getNbVertex());
_containers.unlock();
_modelview = tmp;
//glUseProgram(0);
/*drawing states*/
_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;
std::map<const StateType*, Vbo*>::iterator it_state;
std::map<const EntityValue*, 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(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniform1i(glGetUniformLocation(s->getProgramID(), "i"), 0);
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));
//glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0 , sizeof(GLuint), a);
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_QUADS, 0, it_state->second->getNbVertex());
it_state->second->unlock();
it_state++;
......@@ -671,10 +673,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;
_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);
_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){
}
......@@ -746,24 +748,25 @@ void Render_alternate::start_draw_states(){
_draw_states = true;
}
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 = new Shader();
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 EntityValue* value){
if(_states.count(value)==0){
Shader *s = new Shader(_r, _g, _b);
//Shader *s = new Shader();
s->charger();
std::pair<const StateType*, Shader*> p(type, s);
std::pair<const EntityValue*, Shader*> p(value, s);
_states_shaders.insert(p);
Vbo *v = new Vbo(GL_QUADS);
std::pair<const StateType*, Vbo*> p2(type, v);
std::pair<const EntityValue*, Vbo*> p2(value, v);
_states.insert(p2);
}
_current = _states[type];
draw_quad(x, y, z, w, h);
_current = _states[value];
draw_quad(x, y, z, w*0.98, h);
}
void Render_alternate::end_draw_states(){
_draw_states = false;
std::map<const StateType*, Vbo*>::iterator it;
std::map<const EntityValue*, Vbo*>::iterator it;
it = _states.begin();
while(it!=_states.end()){
it->second->config();
......
......@@ -108,8 +108,8 @@ private:
Vbo _counters;
Vbo _ruler;
Vbo *_current;
std::map<const StateType*, Vbo*> _states;
std::map<const StateType*, Shader*> _states_shaders;
std::map<const EntityValue*, Vbo*> _states;
std::map<const EntityValue*, Shader*> _states_shaders;
/*!
* \brief Offset of the vertical helper line
*/
......@@ -243,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_pos r, const StateType* type);
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.
......
......@@ -330,5 +330,5 @@ 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){
void Render_svg::draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const EntityValue* type){
}
......@@ -312,7 +312,7 @@ public:
*/
void call_ruler();
void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const StateType* type);
void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const EntityValue* type);
};
......
#include <GL/glew.h>
#include <iostream>
#include <sstream>
#include "Shader.hpp"
// Constructeurs et Destructeur
......@@ -28,7 +29,33 @@ Shader::Shader() : m_vertexID(0), m_fragmentID(0), m_programID(0),
{
}
Shader::Shader(Element_col r, Element_col g, Element_col b):m_vertexID(0), m_fragmentID(0), m_programID(0), m_vertex_code("#version 330 core \n in vec2 in_Vertex; \n uniform mat4 MVP; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n }"){
std::ostringstream os;
//std::cout << "rgb" << r << " " << g << " " << b << std::endl;
os << "#version 330 core \n out vec4 outColor; \n void main(){ \n if(true) { \n outColor = vec4(";
os << r;
os << ", ";
os << g;
os << ", ";
os << b;
os << ", 0.5); \n }";
os << "else { \n out_Color = vec4(";
os << 1;
os << ", ";
os << 1;
os << ", ";
os << 1;
os << ", 0.5); \n } \n \n }";
m_fragment_code=os.str();
/*std::cout << "code shaders" << std::endl;
std::cout << m_vertex_code << std::endl;
std::cout << m_fragment_code << std::endl;*/
}
/*layout (binding = 1, offset = 0) uniform atomic_uint c;
atomicCounterIncrement(c);
(atomicCounter(c)%4)<2*/
Shader::~Shader()
{
// Destruction du shader
......@@ -227,8 +254,8 @@ bool Shader::compilerShader(GLuint &shader, GLenum type, std::string code)
// S'il y a eu une erreur
if(erreurCompilation != GL_TRUE)
{
//if(erreurCompilation != GL_TRUE)
//{
// Récupération de la taille de l'erreur
GLint tailleErreur(0);
......@@ -247,24 +274,25 @@ bool Shader::compilerShader(GLuint &shader, GLenum type, std::string code)
// Affichage de l'erreur
std::cout << "Erreur Shader" << std::endl;
//std::cout << "Erreur Shader" << std::endl;
std::cout << erreur << std::endl;
std::cout << "compilation terminée" << std::endl;
//std::cout << "compilation terminée" << std::endl;
// Libération de la mémoire et retour du booléen false
delete[] erreur;
glDeleteShader(shader);
return false;
}
if(erreurCompilation != GL_TRUE){
glDeleteShader(shader);
return false;
}
//}
// Sinon c'est que tout s'est bien passé
else
return true;
else
return true;
}
......
......@@ -3,14 +3,12 @@
//#include <GL/glew.h>
#include "common/common.hpp"
// Includes communs
#include <iostream>
#include <string>
#include <fstream>
// Classe Shader
class Shader
......@@ -18,7 +16,8 @@ class Shader
public:
Shader();
Shader(Shader const &shaderACopier);
Shader(Element_col, Element_col, Element_col);
//Shader(Shader const &shaderACopier);
//Shader();
~Shader();
......
......@@ -105,12 +105,21 @@ int Vbo::add(Element_pos x, Element_pos y, Element_col r, Element_col g, Element
_nbVertex++;
}
int Vbo::add(Element_pos x, Element_pos y/*, bool b*/){
_vertex.push_back(x);
_vertex.push_back(y);
//_shaded.push_back(b);
_nbVertex++;
}
void Vbo::config(){
std::cout << "Configuration du VBO. Nombre de points : "<< _vertex.size()/2 << std::endl;
int vertex_size = _vertex.size() * sizeof(Element_pos);
int colors_size = _colors.size() * sizeof(Element_col);
//int shaded_size = _shaded.size() * sizeof(bool);
Element_pos * vertex = &_vertex[0];
Element_col * colors = &_colors[0];
//bool * shaded = &_shaded[0];
//Delete old vbo if necessary
if(glIsBuffer(_vboID) == GL_TRUE)
glDeleteBuffers(1, &_vboID);
......@@ -119,10 +128,11 @@ void Vbo::config(){
//Select our VBO
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
//Allocate memory inside graphic card
glBufferData(GL_ARRAY_BUFFER, vertex_size+colors_size, 0, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vertex_size+colors_size/*+shaded_size*/, 0, GL_STATIC_DRAW);
//Send datas
glBufferSubData(GL_ARRAY_BUFFER, 0 , vertex_size, vertex);
glBufferSubData(GL_ARRAY_BUFFER, vertex_size, colors_size, colors);
//glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded);
//Deselect our VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Clear RAM
......@@ -131,6 +141,7 @@ void Vbo::config(){
//Clear RAM and realoccate _vertex and _colors
std::vector<Element_pos>().swap(_vertex);
std::vector<Element_col>().swap(_colors);
//std::vector<boolean>().swap(_shaded);
//Delete old vao if necessary
if(glIsVertexArray(_vaoID))
glDeleteVertexArrays(1, &_vaoID);
......@@ -146,8 +157,13 @@ void Vbo::config(){
glVertexAttribPointer(0, 2, GL_DOUBLE, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(0);
//Send colors
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size));
glEnableVertexAttribArray(1);
if(colors_size>0){
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size));
glEnableVertexAttribArray(1);
}
/*if(shaded_size>0){
glVertexAttribPointer(2, 1, GL_BOOLEAN, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(2);*/
//Deselect VBO
glBindBuffer(GL_ARRAY_BUFFER,0);
}
......
......@@ -63,6 +63,7 @@ private:
GLuint _vaoID;
vector<Element_pos> _vertex;
vector<Element_col> _colors;
//vector<bool> _shaded;
GLenum _mode;
int _nbVertex;
......@@ -106,7 +107,7 @@ public:
int add(Element_pos x, Element_pos y, Element_col r, Element_col g, Element_col b);
int add(Element_pos x, Element_pos y/*, bool b*/);
void lock();
void unlock();
......
......@@ -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, const StateType * type) {
inline void draw_state(double starttime, double endtime, double r, double g, double b, const EntityValue * value) {
Element_pos y = _position + _container_v_space/2;
_draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b, type);
_draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b, value);
}
/*!
......@@ -262,7 +262,7 @@ struct DrawNode<D, StateChange> {
// Search the color
if(color==NULL){
if (state->get_value() &&
extra_fields!=NULL &&
extra_fields!=NULL &&
!extra_fields->empty() &&
((field = extra_fields->find(std::string("Color"))) != extra_fields->end())) {
/* Call the object state drawing function with the state color */
......@@ -272,9 +272,9 @@ struct DrawNode<D, StateChange> {
}
}
const StateType * type = state->get_type();
const EntityValue * value = state->get_value();
draw->draw_state(interval->_left.get_value(), state->get_end_time().get_value(),
color->get_red(), color->get_green(), color->get_blue(), type);
color->get_red(), color->get_green(), color->get_blue(), value);
}
......@@ -327,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(), state->get_type());
color->get_red(), color->get_green(), color->get_blue(), state->get_value());
}
}
......
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