Reuse PointStarVertexBuffer do draw objects as points

pull/1337/head
Hleb Valoshka 2022-01-09 23:57:22 +02:00
parent 96e282e161
commit 772fe24e1b
2 changed files with 19 additions and 43 deletions

View File

@ -80,7 +80,7 @@ void PointStarVertexBuffer::makeCurrent()
current->finish(); current->finish();
program->use(); program->use();
program->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix()); program->setMVPMatrices(renderer.getCurrentProjectionMatrix(), renderer.getCurrentModelViewMatrix());
if (pointSizeFromVertex) if (pointSizeFromVertex)
{ {
program->samplerParam("starTex") = 0; program->samplerParam("starTex") = 0;

View File

@ -1669,43 +1669,6 @@ void Renderer::draw(const Observer& observer,
enableDepthMask(); enableDepthMask();
} }
void renderPoint(const Renderer &renderer,
const Vector3f &position,
const Color &color,
float size,
bool useSprite,
const Matrices &m)
{
auto *prog = renderer.getShaderManager().getShader("star");
if (prog == nullptr)
return;
prog->use();
prog->samplerParam("starTex") = 0;
prog->setMVPMatrices(*m.projection, *m.modelview);
#ifndef GL_ES
glEnable(GL_POINT_SPRITE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
#endif
// Workaround for macOS to pass a single vertex coord
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
3, GL_FLOAT, GL_FALSE, sizeof(position), position.data());
glVertexAttrib(CelestiaGLProgram::ColorAttributeIndex, color);
glVertexAttrib1f(CelestiaGLProgram::PointSizeAttributeIndex, useSprite ? size : renderer.getScreenDpi() / 96.0f);
glDrawArrays(GL_POINTS, 0, 1);
glDisableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
#ifndef GL_ES
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDisable(GL_POINT_SPRITE);
#endif
}
void renderLargePoint(Renderer &renderer, void renderLargePoint(Renderer &renderer,
const Vector3f &position, const Vector3f &position,
const Color &color, const Color &color,
@ -1848,14 +1811,12 @@ void Renderer::renderObjectAsPoint(const Vector3f& position,
enableDepthTest(); enableDepthTest();
disableDepthMask(); disableDepthMask();
const bool useSprites = starStyle != PointStars; if (starStyle != PointStars)
if (useSprites)
gaussianDiscTex->bind(); gaussianDiscTex->bind();
if (pointSize > gl::maxPointSize) if (pointSize > gl::maxPointSize)
renderLargePoint(*this, center, {color, alpha}, pointSize, mvp); renderLargePoint(*this, center, {color, alpha}, pointSize, mvp);
else else
renderPoint(*this, center, {color, alpha}, pointSize, useSprites, mvp); pointStarVertexBuffer->addStar(position, {color, alpha}, pointSize);
// If the object is brighter than magnitude 1, add a halo around it to // If the object is brighter than magnitude 1, add a halo around it to
// make it appear more brilliant. This is a hack to compensate for the // make it appear more brilliant. This is a hack to compensate for the
@ -1869,7 +1830,7 @@ void Renderer::renderObjectAsPoint(const Vector3f& position,
if (glareSize > gl::maxPointSize) if (glareSize > gl::maxPointSize)
renderLargePoint(*this, center, {color, glareAlpha}, glareSize, mvp); renderLargePoint(*this, center, {color, glareAlpha}, glareSize, mvp);
else else
renderPoint(*this, center, {color, glareAlpha}, glareSize, true, mvp); glareVertexBuffer->addStar(position, {color, glareAlpha}, glareSize);
} }
} }
} }
@ -5980,6 +5941,8 @@ Renderer::renderSolarSystemObjects(const Observer &observer,
proj = Perspective(fov, aspectRatio, nearPlaneDistance, farPlaneDistance); proj = Perspective(fov, aspectRatio, nearPlaneDistance, farPlaneDistance);
Matrices m = { &proj, &m_modelMatrix }; Matrices m = { &proj, &m_modelMatrix };
setCurrentProjectionMatrix(proj);
Frustum intervalFrustum(degToRad(fov), Frustum intervalFrustum(degToRad(fov),
aspectRatio, aspectRatio,
nearPlaneDistance, nearPlaneDistance,
@ -6042,6 +6005,18 @@ Renderer::renderSolarSystemObjects(const Observer &observer,
i--; i--;
} }
PointStarVertexBuffer::enable();
glareVertexBuffer->startSprites();
glareVertexBuffer->render();
glareVertexBuffer->finish();
if (starStyle == PointStars)
pointStarVertexBuffer->startBasicPoints();
else
pointStarVertexBuffer->startSprites();
pointStarVertexBuffer->render();
pointStarVertexBuffer->finish();
PointStarVertexBuffer::disable();
// Render annotations in this interval // Render annotations in this interval
enableSmoothLines(); enableSmoothLines();
annotation = renderSortedAnnotations(annotation, annotation = renderSortedAnnotations(annotation,
@ -6054,4 +6029,5 @@ Renderer::renderSolarSystemObjects(const Observer &observer,
// reset the depth range // reset the depth range
glDepthRange(0, 1); glDepthRange(0, 1);
setDefaultProjectionMatrix();
} }