Commit 7c117fa9 authored by Thibault Soucarre's avatar Thibault Soucarre

change shaders for old versions of glsl

parent 24ef32c7
......@@ -180,7 +180,7 @@ void Render_alternate::paintGL(){
start_ruler();
call_ruler();
end_ruler();
_ruler.config();
_ruler.config(_glsl);
_ruler.lock();
_modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler));
mvp = _projection * _modelview;
......@@ -722,10 +722,20 @@ 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, 2);// , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y, 1);// , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h, 1);//, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h, 2);//, _r, _g, _b);
if(_glsl<330) {
_current->add(x+offset_x , y+offset_y, 2.0f);// , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y, 1.0f);// , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h, 1.0f);//, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h, 2.0f);//, _r, _g, _b);
}
else{
char c1 = 1;
char c2 = 2;
_current->add(x+offset_x , y+offset_y, c2);// , _r, _g, _b);
_current->add(x+offset_x+w, y+offset_y, c1);// , _r/2, _g/2, _b/2);
_current->add(x+offset_x+w, y+offset_y+h, c1);//, _r/2, _g/2, _b/2);
_current->add(x+offset_x , y+offset_y+h, c2);//, _r, _g, _b);
}
}
else if(_draw_ruler){
}
......@@ -789,7 +799,7 @@ void Render_alternate::draw_container_text(const Element_pos , const Element_pos
void Render_alternate::end_draw_containers(){
_draw_container = false;
_containers.config();
_containers.config(_glsl);
cout << "end_draw_containers" << endl;
}
......@@ -818,10 +828,10 @@ void Render_alternate::end_draw_states(){
std::map<const EntityValue*, Vbo*>::iterator it;
it = _states.begin();
while(it!=_states.end()){
it->second->config();
it->second->config(_glsl);
it++;
}
//_states.config();
//_states.config(_glsl);
cout << "end_draw_states" << endl;
}
......@@ -900,9 +910,9 @@ void Render_alternate::end_draw_arrows(){
//_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.config();
_arrows2.config();
_arrows3.config();
_arrows.config(_glsl);
_arrows2.config(_glsl);
_arrows3.config(_glsl);
_draw_arrow = false;
cout << "end_draw_arrows " << _links.size() << endl;
}
......@@ -940,8 +950,8 @@ void Render_alternate::end_draw_events(){
// 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);
_events.config();
_events2.config();
_events.config(_glsl);
_events2.config(_glsl);
_draw_event = false;
cout << "end_draw_events" << endl;
}
......@@ -955,7 +965,7 @@ void Render_alternate::draw_counter(const Element_pos , const Element_pos ){
void Render_alternate::end_draw_counter(){
_draw_counter = false;
_counters.config();
_counters.config(_glsl);
cout << "end_draw_counters" << endl;
}
......
......@@ -32,10 +32,10 @@ Shader::Shader(int glsl){
std::ostringstream os1, os2;
os1 << "#version ";
os1 << glsl;
os1 << " core \n in vec2 in_Vertex; \n in vec3 in_Color; \n uniform mat4 MVP; \n out vec3 color; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n color = in_Color; \n }";
os1 << " \n in vec2 in_Vertex; \n in vec3 in_Color; \n uniform mat4 MVP; \n out vec3 color; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n color = in_Color; \n }";
os2 << "#version ";
os2 << glsl;
os2 << " core \n in vec3 color; \n out vec4 out_Color; \n void main(){ \n out_Color = vec4(color, 0.5); \n }";
os2 << " \n in vec3 color; \n out vec4 out_Color; \n void main(){ \n out_Color = vec4(color, 0.5); \n }";
std::cout << os1 << std::endl;
std::cout << os2 << std::endl;
m_vertex_code = os1.str();
......@@ -48,10 +48,20 @@ Shader::Shader(int glsl, Element_col r, Element_col g, Element_col b):m_vertexID
//std::cout << "rgb" << r << " " << g << " " << b << std::endl;
os1 << "#version ";
os1 << glsl;
os1 << " core \n in vec2 in_Vertex; \n in int c; \n uniform mat4 MVP; \n out float shade; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n shade=intBitsToFloat(c); \n }";
os1 << " \n in vec2 in_Vertex; \n in ";
if(glsl<330)
os1 << "float s;";
else
os1 << "int c;";
os1 << "\n uniform mat4 MVP; \n out float shade; \n void main(){ \n gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0); \n";
if(glsl<330)
os1 << "shade=s; \n";
else
os1 << "shade=intBitsToFloat(c); \n";
os1 << "}";
os2 << "#version ";
os2 << glsl;
os2 << " core \n in float shade; \n out vec4 outColor; \n void main(){ \n outColor = vec4(";
os2 << " \n in float shade; \n out vec4 outColor; \n void main(){ \n outColor = vec4(";
os2 << r/2;
os2 << "*shade, ";
os2 << g/2;
......@@ -68,8 +78,8 @@ Shader::Shader(int glsl, Element_col r, Element_col g, Element_col b):m_vertexID
m_vertex_code = os1.str();
m_fragment_code = os2.str();
//std::cout << "code shaders" << std::endl;
//std::cout << m_vertex_code << std::endl;
//std::cout << m_fragment_code << std::endl;
std::cout << m_vertex_code << std::endl;
std::cout << m_fragment_code << std::endl;
}
......
......@@ -113,14 +113,30 @@ int Vbo::add(Element_pos x, Element_pos y, char b){
_nbVertex++;
}
void Vbo::config(){
int Vbo::add(Element_pos x, Element_pos y, float b){
_vertex.push_back(x);
_vertex.push_back(y);
_shaded2.push_back(b);
_nbVertex++;
}
void Vbo::config(int glsl){
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(char);
int shaded_size;
Element_pos * vertex = &_vertex[0];
Element_col * colors = &_colors[0];
char * shaded = &_shaded[0];
char * shaded;
float* shaded2;
if(glsl<330){
shaded_size = _shaded2.size() * sizeof(float);
shaded2 = &_shaded2[0];
}
else{
shaded_size = _shaded.size() * sizeof(char);
shaded = &_shaded[0];
}
//Delete old vbo if necessary
if(glIsBuffer(_vboID) == GL_TRUE)
glDeleteBuffers(1, &_vboID);
......@@ -133,7 +149,10 @@ void Vbo::config(){
//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);
if(glsl<330)
glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded2);
else
glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded);
//Deselect our VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Clear RAM
......@@ -143,6 +162,7 @@ void Vbo::config(){
std::vector<Element_pos>().swap(_vertex);
std::vector<Element_col>().swap(_colors);
std::vector<char>().swap(_shaded);
std::vector<float>().swap(_shaded2);
//Delete old vao if necessary
if(glIsVertexArray(_vaoID))
glDeleteVertexArrays(1, &_vaoID);
......@@ -163,8 +183,14 @@ void Vbo::config(){
glEnableVertexAttribArray(1);
}
if(shaded_size>0){
glVertexAttribPointer(1, 1, GL_BYTE, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(1);
if(glsl<330){
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(1);
}
else{
glVertexAttribPointer(1, 1, GL_BYTE, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glEnableVertexAttribArray(1);
}
}
//Deselect VBO
glBindBuffer(GL_ARRAY_BUFFER,0);
......
......@@ -64,6 +64,7 @@ private:
vector<Element_pos> _vertex;
vector<Element_col> _colors;
vector<char> _shaded;
vector<float> _shaded2;
GLenum _mode;
int _nbVertex;
......@@ -108,12 +109,13 @@ 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, char b);
int add(Element_pos x, Element_pos y, float b);
void lock();
void unlock();
int getNbVertex();
void setNbVertex(int);
void config();
void config(int glsl);
};
......
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