Skip to content

Commit

Permalink
Fix an off-by-one mistake; Add line loops to the tessellated rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Apr 16, 2023
1 parent 7054a74 commit 35951af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/core/StelPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2400,13 +2400,21 @@ void StelPainter::enableClientStates(bool vertex, bool texture, bool color, bool
normalArray.enabled = normal;
}

void StelPainter::drawFixedColorWideLineStripAsQuads(const ArrayDesc& vertexArray, int count, int offset, const Mat4f& projMat)
void StelPainter::drawFixedColorWideLineStripAsQuads(const ArrayDesc& vertexArray, int count, int offset,
const Mat4f& projMat, const DrawingMode mode)
{
if(count < 2) return;

GLint viewport[4] = {};
glGetIntegerv(GL_VIEWPORT, viewport);
const auto viewportSize = Vec2f(viewport[2], viewport[3]);

std::vector<Vec4f> newVertices(count*6);
std::vector<Vec4f> newVertices;
if(mode == LineStrip)
newVertices.reserve((count-1)*6);
else
newVertices.reserve(count*6);
newVertices.resize((count-1)*6);
assert(vertexArray.type == GL_FLOAT);
const auto lineVertData = static_cast<const float*>(vertexArray.pointer) + vertexArray.size*offset;
for(int n = 0; n < count-1; ++n)
Expand Down Expand Up @@ -2468,6 +2476,19 @@ void StelPainter::drawFixedColorWideLineStripAsQuads(const ArrayDesc& vertexArra
newVertices[6*n+4] = v0b;
newVertices[6*n+5] = v1b;
}
if(mode == LineLoop)
{
// Connect the ends
const auto lastN = newVertices.size()-1;
assert(lastN >= 2);
newVertices.push_back(newVertices[lastN-2]);
newVertices.push_back(newVertices[lastN]);
newVertices.push_back(newVertices[0]);

newVertices.push_back(newVertices[0]);
newVertices.push_back(newVertices[lastN]);
newVertices.push_back(newVertices[1]);
}
vao->bind();
verticesVBO->bind();

Expand Down Expand Up @@ -2523,9 +2544,9 @@ void StelPainter::drawFromArray(DrawingMode mode, int count, int offset, bool do
if(wideLineMode && projectedVertexArray.type == GL_FLOAT)
{
const bool fixedColor = !texCoordArray.enabled && !colorArray.enabled && !normalArray.enabled;
if(fixedColor && mode==LineStrip && !indices)
if(fixedColor && (mode != Lines) && !indices)
{
drawFixedColorWideLineStripAsQuads(projectedVertexArray, count, offset, m);
drawFixedColorWideLineStripAsQuads(projectedVertexArray, count, offset, m, mode);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/StelPainter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class StelPainter : protected QOpenGLFunctions
//! @return a descriptor of the new array
ArrayDesc projectArray(const ArrayDesc& array, int offset, int count, const unsigned short *indices=Q_NULLPTR);

void drawFixedColorWideLineStripAsQuads(const ArrayDesc& vertexArray, int count, int offset, const Mat4f& projMat);
void drawFixedColorWideLineStripAsQuads(const ArrayDesc& vertexArray, int count, int offset, const Mat4f& projMat, DrawingMode mode);

//! Project the passed triangle on the screen ensuring that it will look smooth, even for non linear distortion
//! by splitting it into subtriangles. The resulting vertex arrays are appended to the passed out* ones.
Expand Down

0 comments on commit 35951af

Please sign in to comment.