Skip to content

Commit

Permalink
Points draw with GLES fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Denvi committed Sep 13, 2015
1 parent 9471d48 commit c6d5d34
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 33 deletions.
28 changes: 16 additions & 12 deletions frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void frmMain::onSerialPortReadyRead()
// Get probe Z coordinate
// "[PRB:0.000,0.000,0.000:0];ok"
QRegExp rx(".*PRB:([^,]*),([^,]*),([^]^:]*)");
double z = std::numeric_limits<double>::quiet_NaN();
double z = NAN;
if (rx.indexIn(response) != -1) {
qDebug() << "probing coordinates:" << rx.cap(1) << rx.cap(2) << rx.cap(3);
z = toMetric(rx.cap(3).toDouble());
Expand Down Expand Up @@ -1235,7 +1235,10 @@ void frmMain::loadFile(QString fileName)
stripped = GcodePreprocessorUtils::removeComment(command);
args = GcodePreprocessorUtils::splitCommand(stripped);

gp.addCommand(args);
PointSegment *ps = gp.addCommand(args);
//Quantum line (if disable pointsegment check some points will have NAN number on raspberry)
if (ps && (std::isnan(ps->point()->x()) || std::isnan(ps->point()->y()) || std::isnan(ps->point()->z())))
qDebug() << "nan point segment added:" << *ps->point();

m_programModel.setData(m_programModel.index(m_programModel.rowCount() - 1, 1), command);
m_programModel.setData(m_programModel.index(m_programModel.rowCount() - 2, 2), tr("In queue"));
Expand Down Expand Up @@ -2447,7 +2450,7 @@ void frmMain::updateHeightMapInterpolationDrawer(bool reset)
double x = interpolationStepX * j + borderRect.x();
double y = interpolationStepY * i + borderRect.y();

row.append(reset ? std::numeric_limits<double>::quiet_NaN() : Interpolation::bicubicInterpolate(borderRect, &m_heightMapModel, x, y));
row.append(reset ? NAN : Interpolation::bicubicInterpolate(borderRect, &m_heightMapModel, x, y));
}
interpolationData->append(row);
}
Expand Down Expand Up @@ -2620,15 +2623,15 @@ void frmMain::loadHeightMap(QString fileName)
m_settingsLoading = true;

// Storing previous values
ui->txtHeightMapBorderX->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapBorderY->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapBorderWidth->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapBorderHeight->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapBorderX->setValue(NAN);
ui->txtHeightMapBorderY->setValue(NAN);
ui->txtHeightMapBorderWidth->setValue(NAN);
ui->txtHeightMapBorderHeight->setValue(NAN);

ui->txtHeightMapGridX->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapGridY->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapGridZBottom->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapGridZTop->setValue(std::numeric_limits<double>::quiet_NaN());
ui->txtHeightMapGridX->setValue(NAN);
ui->txtHeightMapGridY->setValue(NAN);
ui->txtHeightMapGridZBottom->setValue(NAN);
ui->txtHeightMapGridZTop->setValue(NAN);

QList<QString> list = textStream.readLine().split(";");
ui->txtHeightMapBorderX->setValue(list[0].toDouble());
Expand Down Expand Up @@ -2743,7 +2746,7 @@ void frmMain::on_chkHeightMapUse_clicked(bool checked)
QByteArray headerState = ui->tblProgram->horizontalHeader()->saveState();
ui->tblProgram->setModel(NULL);

// Update program if not cached
// Update heightmap-modificated program if not cached
if (m_programHeightmapModel.rowCount() == 0) {

// Modifying linesegments
Expand Down Expand Up @@ -2807,6 +2810,7 @@ void frmMain::on_chkHeightMapUse_clicked(bool checked)
} else {
// Get command codes
// codes = GcodePreprocessorUtils::splitCommand(command);
// from cache
codes = m_programModel.data(m_programModel.index(i, 5)).toStringList();
newCommandPrefix.clear();

Expand Down
6 changes: 3 additions & 3 deletions gcodeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ void GcodeParser::reset()
foreach (PointSegment *ps, this->m_points) delete ps;
this->m_points.clear();
// The unspoken home location.
m_currentPoint.setX(std::numeric_limits<double>::quiet_NaN());
m_currentPoint.setY(std::numeric_limits<double>::quiet_NaN());
m_currentPoint.setZ(std::numeric_limits<double>::quiet_NaN());
m_currentPoint.setX(NAN);
m_currentPoint.setY(NAN);
m_currentPoint.setZ(NAN);
this->m_points.append(new PointSegment(&this->m_currentPoint, -1));
}

Expand Down
16 changes: 8 additions & 8 deletions gcodepreprocessorutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ QVector3D GcodePreprocessorUtils::updatePointWithCommand(QString command, QVecto
*/
QVector3D GcodePreprocessorUtils::updatePointWithCommand(QList<QString> commandArgs, QVector3D initial, bool absoluteMode)
{
double x = std::numeric_limits<double>::quiet_NaN();
double y = std::numeric_limits<double>::quiet_NaN();
double z = std::numeric_limits<double>::quiet_NaN();
double x = NAN;
double y = NAN;
double z = NAN;
char c;

for (int i = 0; i < commandArgs.length(); i++) {
Expand Down Expand Up @@ -185,10 +185,10 @@ QVector3D GcodePreprocessorUtils::updatePointWithCommand(QVector3D initial, doub

QVector3D GcodePreprocessorUtils::updateCenterWithCommand(QList<QString> commandArgs, QVector3D initial, QVector3D nextPoint, bool absoluteIJKMode, bool clockwise)
{
double i = std::numeric_limits<double>::quiet_NaN();
double j = std::numeric_limits<double>::quiet_NaN();
double k = std::numeric_limits<double>::quiet_NaN();
double r = std::numeric_limits<double>::quiet_NaN();
double i = NAN;
double j = NAN;
double k = NAN;
double r = NAN;
char c;

foreach (QString t, commandArgs)
Expand Down Expand Up @@ -301,7 +301,7 @@ double GcodePreprocessorUtils::parseCoord(QList<QString> argList, char c)
{
if (t.length() > 0 && t[0].toUpper() == c) return t.mid(1).toDouble();
}
return std::numeric_limits<double>::quiet_NaN();
return NAN;
}

//static public List<String> convertArcsToLines(Point3d start, Point3d end) {
Expand Down
8 changes: 4 additions & 4 deletions gcodeviewparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ GcodeViewParse::GcodeViewParse(QObject *parent) :
currentLine = 0;
debug = true;

m_min = QVector3D(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
m_max = QVector3D(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
m_min = QVector3D(NAN, NAN, NAN);
m_max = QVector3D(NAN, NAN, NAN);
}

GcodeViewParse::~GcodeViewParse()
Expand Down Expand Up @@ -72,8 +72,8 @@ void GcodeViewParse::reset()
foreach (LineSegment *ls, lines) delete ls;
lines.clear();
currentLine = 0;
m_min = QVector3D(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
m_max = QVector3D(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
m_min = QVector3D(NAN, NAN, NAN);
m_max = QVector3D(NAN, NAN, NAN);
}

QList<LineSegment *> GcodeViewParse::getLinesFromParser(GcodeParser *gp, double arcSegmentLength)
Expand Down
2 changes: 1 addition & 1 deletion grbl_control.pro
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contains(QT_CONFIG, opengles.) {
target.path = /home/pi
}

#DEFINES += sNan=\"std::numeric_limits<double>::quiet_NaN()\"
#DEFINES += sNan=\"NAN\"
DEFINES += sNan=\"65536\"

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
Expand Down
2 changes: 1 addition & 1 deletion heightmaptablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void HeightMapTableModel::resize(int cols, int rows)
for (int i = 0; i < rows; i++) {
QVector<double> row;
for (int j = 0; j < cols; j++) {
row.append(std::numeric_limits<double>::quiet_NaN());
row.append(NAN);
}
m_data.append(row);
}
Expand Down
9 changes: 7 additions & 2 deletions shaderdrawable.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#define sNan std::numeric_limits<double>::quiet_NaN();
//#define sNan NAN;

#include "shaderdrawable.h"

Expand Down Expand Up @@ -145,12 +145,17 @@ void ShaderDrawable::draw(QOpenGLShaderProgram *shaderProgram)

glLineWidth(m_lineWidth);
glDrawArrays(GL_LINES, 0, m_lines.count());
#ifdef GLES
shaderProgram->setUniformValue("point_size", (GLfloat)m_pointSize);
#else
glPointSize(m_pointSize);
#endif
glDrawArrays(GL_POINTS, m_lines.count(), m_points.count());

#ifndef GLES
#ifndef GLES
m_vao.release();
#else
shaderProgram->setUniformValue("point_size", (GLfloat)0.0);
m_vbo.release();
#endif
}
Expand Down
7 changes: 7 additions & 0 deletions shaders/fshader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ precision mediump float;
//Dash grid (px) = factor * pi;
const float factor = 2.0;

uniform float point_size;

varying vec4 v_color;
varying vec2 v_position;
varying vec2 v_start;
Expand All @@ -25,6 +27,11 @@ void main()
if (cos(coord / factor) > 0.0) discard;
}

if (point_size > 0.0) {
vec2 coord = gl_PointCoord.st - vec2(0.5, 0.5);
if (length(coord) > 0.5) discard;
}

// Set fragment color from texture
gl_FragColor = v_color;
}
4 changes: 4 additions & 0 deletions shaders/vshader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ precision mediump float;

uniform mat4 mvp_matrix;
uniform mat4 mv_matrix;
uniform float point_size;

attribute vec4 a_position;
attribute vec4 a_color;
Expand Down Expand Up @@ -33,4 +34,7 @@ void main()

// Value will be automatically interpolated to fragments inside polygon faces
v_color = a_color;

// Set point size
gl_PointSize = point_size;
}
4 changes: 2 additions & 2 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class Util
if (!std::isnan(v1) && !std::isnan(v2)) return qMin<double>(v1, v2);
else if (!std::isnan(v1)) return v1;
else if (!std::isnan(v2)) return v2;
else return std::numeric_limits<double>::quiet_NaN();
else return NAN;
}

static double nMax(double v1, double v2)
{
if (!std::isnan(v1) && !std::isnan(v2)) return qMax<double>(v1, v2);
else if (!std::isnan(v1)) return v1;
else if (!std::isnan(v2)) return v2;
else return std::numeric_limits<double>::quiet_NaN();
else return NAN;
}
};

Expand Down

0 comments on commit c6d5d34

Please sign in to comment.