From 26b2f2cfe68c5427a1b21ccf97290a38a3a87d42 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Mon, 1 Aug 2011 22:29:17 +1000 Subject: [PATCH] Fixed random graph color problem on certain video chips --- Graphs/gLineChart.cpp | 29 +++++++++++++---------- Graphs/gLineChart.h | 1 + Graphs/glcommon.cpp | 4 ++-- Graphs/graphwindow.cpp | 20 +++++++++++----- SleepLib/loader_plugins/resmed_loader.cpp | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Graphs/gLineChart.cpp b/Graphs/gLineChart.cpp index 040a9ff7..a30a3729 100644 --- a/Graphs/gLineChart.cpp +++ b/Graphs/gLineChart.cpp @@ -14,8 +14,7 @@ gLineChart::gLineChart(ChannelID code,QColor col,bool square_plot, bool disable_accel) :gLayer(code),m_square_plot(square_plot),m_disable_accel(disable_accel) { - color.clear(); - color.push_back(col); + m_line_color=col; m_report_empty=false; } gLineChart::~gLineChart() @@ -100,7 +99,7 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) // Draw bounding box { - glColor3f (0.0, 0.0, 0.0); + w.qglColor(Qt::black); glLineWidth (1); glBegin (GL_LINE_LOOP); glVertex2f (start_px, start_py); @@ -118,9 +117,6 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) return; } - // Selected the plot line color - QColor & col=color[0]; - int num_points=0; int visible_points=0; int total_points=0; @@ -194,7 +190,7 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) double ZR=ZD/sr; double ZQ=ZR/XR; double ZW=ZR/(width*ZQ); - const int num_averages=15; // Max n umber of samples taken from samples per pixel for better min/max values + const int num_averages=20; // Max n umber of samples taken from samples per pixel for better min/max values visible_points+=ZR*ZQ; if (accel && n>0) { sam=1; @@ -279,7 +275,7 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) // In accel mode, each pixel has a min/max Y value. // m_drawlist's index is the pixel index for the X pixel axis. - int z=floor(px); // Hmmm... round may screw this up. + int z=round(px); // Hmmm... round may screw this up. if (zmaxz) maxz=z; // maxz=Last pixel if (minz<0) { @@ -305,11 +301,16 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) qDebug() << "gLineChart::Plot() maxz exceeded graph width" << "maxz = " << maxz << "width =" << width << "scrx =" <=maxverts) break; } @@ -429,14 +430,13 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) GetTextExtent(b,x,y); DrawText(b,scrx-w.GetRightMargin()-x-15,scry-w.GetBottomMargin()-10); */ - glColor4ub(col.red(),col.green(),col.blue(),255); // Crop to inside the margins. glScissor(w.GetLeftMargin(),w.GetBottomMargin(),width,height+2); glEnable(GL_SCISSOR_TEST); - glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); bool antialias=pref["UseAntiAliasing"].toBool(); + glDisable(GL_TEXTURE_2D); if (antialias) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -448,6 +448,8 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_SHORT, 0, vertarray); + //glColor4ub(m_line_color.red(),m_line_color.green(),m_line_color.blue(),255); + w.qglColor(m_line_color); glDrawArrays(GL_LINES, 0, vertcnt>>1); glDisableClientState(GL_VERTEX_ARRAY); @@ -457,5 +459,6 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) } glDisable(GL_SCISSOR_TEST); } + glFinish(); } diff --git a/Graphs/gLineChart.h b/Graphs/gLineChart.h index c3cb3a7e..a9f7dbeb 100644 --- a/Graphs/gLineChart.h +++ b/Graphs/gLineChart.h @@ -31,6 +31,7 @@ protected: bool m_report_empty; bool m_square_plot; bool m_disable_accel; + QColor m_line_color; }; #endif // GLINECHART_H diff --git a/Graphs/glcommon.cpp b/Graphs/glcommon.cpp index 52702c51..3abdbc5d 100644 --- a/Graphs/glcommon.cpp +++ b/Graphs/glcommon.cpp @@ -177,7 +177,7 @@ void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color) void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor color) { - glDisable(GL_TEXTURE_2D); + //glDisable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -196,7 +196,7 @@ void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor colo glVertex2i(x,y+radius); glEnd(); - glEnable(GL_TEXTURE_2D); + //glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); } diff --git a/Graphs/graphwindow.cpp b/Graphs/graphwindow.cpp index 7012424f..cc530b7e 100644 --- a/Graphs/graphwindow.cpp +++ b/Graphs/graphwindow.cpp @@ -757,6 +757,8 @@ void gGraphWindow::OnMouseLeftRelease(QMouseEvent * event) if (qx+mx>rmax_x) { qx=rmax_x-mx; } + glFlush(); + glFinish(); SetXBounds(qx,qx+mx); did_draw=true; } else { @@ -775,13 +777,15 @@ void gGraphWindow::OnMouseLeftRelease(QMouseEvent * event) m_mouseLDown=false; m_drag_foobar=false; if (!did_draw) { - if (r!=m_mouseRBrect) + if (r!=m_mouseRBrect) { updateGL(); + } } else { if (pref["LinkGraphMovement"].toBool()) { for (QList::iterator g=link_zoom.begin();g!=link_zoom.end();g++) { (*g)->SetXBounds(min_x,max_x); } + glFinish(); } } LastGraphLDown=NULL; @@ -801,7 +805,7 @@ void gGraphWindow::initializeGL() setAutoBufferSwap(false); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); m_scrX=width(); m_scrY=height(); @@ -846,6 +850,8 @@ void gGraphWindow::Render(int w, int h) (*l)->Plot(*this,w,h); } DrawTextQueue(*this); + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); } void gGraphWindow::paintGL() @@ -857,27 +863,29 @@ void gGraphWindow::paintGL() if (m_scrY<=0) return; InitGraphs(); - glDisable(GL_DEPTH_TEST); + //glDisable(GL_DEPTH_TEST); Render(m_scrX,m_scrY); if (m_mouseLDown) { if (m_mouseRBrect.width()>0) - glDisable(GL_DEPTH_TEST); - glColor4ub(50,50,200,64); + //glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); + glColor4ub(140,50,200,64); glVertex2f(m_mouseRBrect.x(),m_mouseRBrect.y()); glVertex2f(m_mouseRBrect.x()+m_mouseRBrect.width(),m_mouseRBrect.y()); + glColor4ub(50,50,200,64); glVertex2f(m_mouseRBrect.x()+m_mouseRBrect.width(),m_mouseRBrect.y()+m_mouseRBrect.height()); glVertex2f(m_mouseRBrect.x(),m_mouseRBrect.y()+m_mouseRBrect.height()); glEnd(); glDisable(GL_BLEND); + //glFinish(); //RoundedRectangle(m_mouseRBrect.x(),m_mouseRBrect.y(),m_mouseRBrect.width(),m_mouseRBrect.height(),5,QColor(50,50,200,64)); //glEnable(GL_DEPTH_TEST); } - glEnable(GL_DEPTH_TEST); + //glEnable(GL_DEPTH_TEST); swapBuffers(); // Dump to screen. diff --git a/SleepLib/loader_plugins/resmed_loader.cpp b/SleepLib/loader_plugins/resmed_loader.cpp index 72278e0c..9a12683a 100644 --- a/SleepLib/loader_plugins/resmed_loader.cpp +++ b/SleepLib/loader_plugins/resmed_loader.cpp @@ -395,7 +395,7 @@ int ResmedLoader::Open(QString & path,Profile *profile) sess->max(a[i]); sess->avg(a[i]); sess->wavg(a[i]); - //sess->p90(a[i]); + sess->p90(a[i]); sess->cph(a[i]); } }