Commit 07ff843c authored by Mathieu Faverge's avatar Mathieu Faverge

Add checkGLError function to detect problem in QT5 rendering

parent 03e52d2d
......@@ -399,10 +399,6 @@ void Settings_window::fill_table_links( const string &palette_name ) {
"link_types", palette_name );
}
void Settings_window::on_palette_list_currentIndexChanged(const QString & text) {
_changed=true;
fill_table_states(text.toStdString());
......
......@@ -77,6 +77,13 @@
using namespace std;
extern "C" {
void checkGlError(){
int rc = glGetError();
assert(rc == GL_NO_ERROR );
}
}
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
......@@ -138,13 +145,22 @@ void Render_alternate::initializeGL() {
if(err!=GLEW_OK){
std::cout << "ERROR : GlewInit failed" << std::endl;
}
#ifdef USE_QT5
// Reset the error code set to GL_INVALID_ENUM by glewInit()
glGetError();
#endif
checkGlError();
glClearColor(0.5f, 0.5f, 0.55f, 0.0f);
glEnable(GL_DEPTH_TEST);
checkGlError();
glClearStencil(0);
checkGlError();
// Check for OpenGL version support
std::cout << "init" << std::endl;
const GLubyte * version = glGetString(GL_SHADING_LANGUAGE_VERSION);
checkGlError();
if (version==NULL)
std::cout << "ERROR : could not detect your GLSL version" << std::endl;
else
......@@ -167,6 +183,7 @@ void Render_alternate::initializeGL() {
void Render_alternate::resizeGL(int width, int height) {
glViewport(0, 0, width, height);
checkGlError();
/* update informations about widget size */
Info::Screen::width = width;
......@@ -183,28 +200,49 @@ void Render_alternate::resizeGL(int width, int height) {
void Render_alternate::paintGL(){
checkGlError();
glClearDepth(1.0);
checkGlError();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
checkGlError();
/*Draw the home screen*/
if(DRAWING_STATE_WAITING == _state){
glUseProgram(_wait.get_shader()->getProgramID());
checkGlError();
glEnable(GL_BLEND);
checkGlError();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
checkGlError();
_wait.lock();
glBindTexture(GL_TEXTURE_2D, _textureID);
checkGlError();
std::cout << "draw wait\n";
glDrawArrays(GL_QUADS, 0, _wait.getNbVertex());
// GL_QUADS is deprecated for Opengl greater than 3., so an invalide enum is returned by glGetError and needs to be reset
// TODO: fix that by replacing by GL_TRIANGLES
glDrawArrays((GLenum)GL_QUADS, 0, _wait.getNbVertex()); glGetError();
checkGlError();
glBindTexture(GL_TEXTURE_2D, 0);
checkGlError();
_wait.unlock();
glUseProgram(0);
checkGlError();
return;
}
/*Else, draw the trace*/
resizeGL(Render_alternate::QGLWidget::width(), Render_alternate::QGLWidget::height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
checkGlError();
//select shader program
glUseProgram(_shader->getProgramID());
checkGlError();
std::cout << "paintGL" << std::endl;
glm::mat4 tmp = _modelview;
glm::mat4 tmp2 = _modelview;
......@@ -217,13 +255,17 @@ void Render_alternate::paintGL(){
_modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
checkGlError();
/*The first 8 elements of the vbo are the coordinates of the quads, others elements are coordinates of the graduation*/
glDrawArrays(GL_QUADS, 0, 8);
glDrawArrays(GL_QUADS, 0, 8); glGetError();
checkGlError();
_modelview = tmp;
_modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler_over));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
checkGlError();
glDrawArrays(GL_LINES, 8, _ruler.getNbVertex()-8);
checkGlError();
_ruler.unlock();
_modelview = tmp;
......@@ -235,7 +277,7 @@ void Render_alternate::paintGL(){
_modelview = glm::scale(_modelview, glm::vec3(_x_scale_container_state/0.20, _y_state_scale, 1.0));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_QUADS, 0, _containers.getNbVertex());
glDrawArrays(GL_QUADS, 0, _containers.getNbVertex()); glGetError();
_containers.unlock();
_modelview = tmp;
glUseProgram(0);
......@@ -250,11 +292,13 @@ void Render_alternate::paintGL(){
glUseProgram(s->getProgramID());
it_state->second->lock();
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
if(it_state->first==NULL || it_state->first->get_visible())
glDrawArrays(GL_QUADS, 0, it_state->second->getNbVertex());
if(it_state->first==NULL || it_state->first->get_visible()) {
glDrawArrays(GL_QUADS, 0, it_state->second->getNbVertex()); glGetError();
}
it_state->second->unlock();
it_state++;
}
checkGlError();
/*drawing counters*/
glUseProgram(_counters.get_shader()->getProgramID());
......@@ -264,6 +308,7 @@ void Render_alternate::paintGL(){
glDrawArrays(GL_LINES, 0, _counters.getNbVertex());
_counters.unlock();
_modelview = tmp;
checkGlError();
/*drawing links*/
if(false == Info::Render::_no_arrows){
......@@ -323,6 +368,7 @@ void Render_alternate::paintGL(){
}
_modelview = tmp;
}
checkGlError();
/*drawing events*/
if(false == Info::Render::_no_events){
......@@ -387,13 +433,14 @@ void Render_alternate::paintGL(){
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, selection_colors);
glEnableVertexAttribArray(1);
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_QUADS, 0, 4); glGetError();
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisable(GL_BLEND);
_modelview = tmp;
}
}
draw_vertical_line();
checkGlError();
//deselect shader
glUseProgram(0);
......@@ -417,6 +464,7 @@ void Render_alternate::paintGL(){
QString().setNum((*it).second.value),
arial_font);
}
checkGlError();
qglColor(Qt::white);
......@@ -501,6 +549,7 @@ void Render_alternate::paintGL(){
}
checkGlError();
}
/***********************************
*
......@@ -1026,15 +1075,23 @@ void Render_alternate::draw_vertical_line(){
Info::Render::height};
double colors[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
mvp = _projection * _modelview;
checkGlError();
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
checkGlError();
glVertexAttribPointer(0, 2, GL_DOUBLE, GL_FALSE, 0, vertex);
checkGlError();
glEnableVertexAttribArray(0);
checkGlError();
glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, 0, colors);
checkGlError();
glEnableVertexAttribArray(1);
checkGlError();
glDrawArrays(GL_LINES, 0, 2);
checkGlError();
glDisableVertexAttribArray(0);
checkGlError();
glDisableVertexAttribArray(1);
checkGlError();
}
/*!
......
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