Skip to content

Commit cbd67e6

Browse files
committed
Deleting as much legacy stellar code as possible
1 parent 197b77b commit cbd67e6

File tree

11 files changed

+65
-351
lines changed

11 files changed

+65
-351
lines changed

src/celengine/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ set(CELENGINE_SOURCES
8585
perspectiveprojectionmode.h
8686
planetgrid.cpp
8787
planetgrid.h
88-
pointstarrenderer.cpp
89-
pointstarrenderer.h
90-
pointstarvertexbuffer.cpp
91-
pointstarvertexbuffer.h
9288
projectionmode.cpp
9389
projectionmode.h
9490
rectangle.h
@@ -129,6 +125,10 @@ set(CELENGINE_SOURCES
129125
starname.h
130126
staroctree.cpp
131127
staroctree.h
128+
starrenderer.cpp
129+
starrenderer.h
130+
starvertexbuffer.cpp
131+
starvertexbuffer.h
132132
stellarclass.cpp
133133
stellarclass.h
134134
surface.h

src/celengine/render.cpp

Lines changed: 17 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#include "rectangle.h"
4242
#include "framebuffer.h"
4343
#include "planetgrid.h"
44-
#include "pointstarvertexbuffer.h"
45-
#include "pointstarrenderer.h"
44+
#include "starvertexbuffer.h"
45+
#include "starrenderer.h"
4646
#include "orbitsampler.h"
4747
#include "rendcontext.h"
4848
#include "textlayout.h"
@@ -60,7 +60,6 @@
6060
#include <celrender/boundariesrenderer.h>
6161
#include <celrender/cometrenderer.h>
6262
#include <celrender/eclipticlinerenderer.h>
63-
#include <celrender/largestarrenderer.h>
6463
#include <celrender/linerenderer.h>
6564
#include <celrender/galaxyrenderer.h>
6665
#include <celrender/globularrenderer.h>
@@ -233,7 +232,7 @@ Renderer::Renderer() :
233232
#endif
234233
labelMode(NoLabels),
235234
renderFlags(DefaultRenderFlags),
236-
pointStarVertexBuffer(nullptr),
235+
starVertexBuffer(nullptr),
237236
textureResolution(medres),
238237
frameCount(0),
239238
lastOrbitCacheFlush(0),
@@ -248,14 +247,13 @@ Renderer::Renderer() :
248247
m_eclipticLineRenderer(std::make_unique<EclipticLineRenderer>(*this)),
249248
m_galaxyRenderer(std::make_unique<GalaxyRenderer>(*this)),
250249
m_globularRenderer(std::make_unique<GlobularRenderer>(*this)),
251-
m_largeStarRenderer(std::make_unique<LargeStarRenderer>(*this)),
252250
m_hollowMarkerRenderer(std::make_unique<LineRenderer>(*this, 1.0f, LineRenderer::PrimType::Lines, LineRenderer::StorageType::Static)),
253251
m_nebulaRenderer(std::make_unique<NebulaRenderer>(*this)),
254252
m_openClusterRenderer(std::make_unique<OpenClusterRenderer>(*this)),
255253
m_ringRenderer(std::make_unique<RingRenderer>(*this)),
256254
m_skyGridRenderer(std::make_unique<SkyGridRenderer>(*this))
257255
{
258-
pointStarVertexBuffer = new PointStarVertexBuffer(*this, 2048);
256+
starVertexBuffer = new StarVertexBuffer(*this, 2048);
259257

260258
for (int i = 0; i < (int) FontCount; i++)
261259
{
@@ -267,7 +265,7 @@ Renderer::Renderer() :
267265

268266
Renderer::~Renderer()
269267
{
270-
delete pointStarVertexBuffer;
268+
delete starVertexBuffer;
271269
delete shaderManager;
272270

273271
m_atmosphereRenderer->deinitGL();
@@ -1620,122 +1618,6 @@ calculateQuadCenter(const Eigen::Quaternionf &cameraOrientation,
16201618
return position + direction * (radius / (m * Vector3f::UnitZ()).dot(direction));
16211619
}
16221620

1623-
void
1624-
Renderer::calculatePointSize(float appMag,
1625-
float size,
1626-
float &discSize,
1627-
float &alpha,
1628-
float &glareSize,
1629-
float &glareAlpha) const
1630-
{
1631-
alpha = std::max(0.0f, (faintestMag - appMag) * brightnessScale + brightnessBias);
1632-
1633-
discSize = size;
1634-
if (starStyle == ScaledDiscStars)
1635-
{
1636-
if (alpha > 1.0f)
1637-
{
1638-
float discScale = std::min(MaxScaledDiscStarSize, std::pow(2.0f, 0.3f * (satPoint - appMag)));
1639-
discSize *= std::max(1.0f, discScale);
1640-
1641-
glareAlpha = std::min(0.5f, discScale / 4.0f);
1642-
glareSize = discSize * 3.0f;
1643-
1644-
alpha = 1.0f;
1645-
}
1646-
else
1647-
{
1648-
glareSize = glareAlpha = 0.0f;
1649-
}
1650-
}
1651-
else
1652-
{
1653-
if (alpha > 1.0f)
1654-
{
1655-
float discScale = std::min(100.0f, satPoint - appMag + 2.0f);
1656-
glareAlpha = std::min(GlareOpacity, (discScale - 2.0f) / 4.0f);
1657-
glareSize = 2.0f * discScale * size;
1658-
alpha = 1.0f;
1659-
}
1660-
else
1661-
{
1662-
glareSize = glareAlpha = 0.0f;
1663-
}
1664-
}
1665-
}
1666-
1667-
// If the an object occupies a pixel or less of screen space, we don't
1668-
// render its mesh at all and just display a starlike point instead.
1669-
// Switching between the particle and mesh renderings of an object is
1670-
// jarring, however . . . so we'll blend in the particle view of the
1671-
// object to smooth things out, making it dimmer as the disc size exceeds the
1672-
// max disc size.
1673-
void Renderer::renderObjectAsPoint(const Vector3f& position,
1674-
float radius,
1675-
float appMag,
1676-
float discSizeInPixels,
1677-
const Color &color,
1678-
bool useHalos,
1679-
bool emissive,
1680-
const Matrices &mvp)
1681-
{
1682-
const bool useScaledDiscs = starStyle == ScaledDiscStars;
1683-
float maxDiscSize = useScaledDiscs ? MaxScaledDiscStarSize : 1.0f;
1684-
float maxBlendDiscSize = maxDiscSize + 3.0f;
1685-
1686-
if (discSizeInPixels < maxBlendDiscSize || useHalos)
1687-
{
1688-
float fade = 1.0f;
1689-
if (discSizeInPixels > maxDiscSize)
1690-
{
1691-
fade = std::min(1.0f, (maxBlendDiscSize - discSizeInPixels) /
1692-
(maxBlendDiscSize - maxDiscSize));
1693-
}
1694-
1695-
float scale = static_cast<float>(screenDpi) / 96.0f;
1696-
float pointSize, alpha, glareSize, glareAlpha;
1697-
calculatePointSize(appMag, BaseStarDiscSize * scale, pointSize, alpha, glareSize, glareAlpha);
1698-
1699-
if (useScaledDiscs && discSizeInPixels > MaxScaledDiscStarSize)
1700-
glareAlpha = std::min(glareAlpha, (MaxScaledDiscStarSize - discSizeInPixels) / MaxScaledDiscStarSize + 1.0f);
1701-
1702-
alpha *= fade;
1703-
if (!emissive)
1704-
glareAlpha *= fade;
1705-
1706-
if (glareSize != 0.0f)
1707-
glareSize = std::max(glareSize, pointSize * discSizeInPixels / scale * 3.0f);
1708-
1709-
Renderer::PipelineState ps;
1710-
ps.blending = true;
1711-
ps.blendFunc = {GL_SRC_ALPHA, GL_ONE};
1712-
ps.depthTest = true;
1713-
setPipelineState(ps);
1714-
1715-
if (starStyle != PointStars)
1716-
gaussianDiscTex->bind();
1717-
1718-
if (pointSize > gl::maxPointSize)
1719-
m_largeStarRenderer->render(position, {color, alpha}, pointSize, mvp);
1720-
else
1721-
pointStarVertexBuffer->addStar(position, {color, alpha}, pointSize);
1722-
1723-
// If the object is brighter than magnitude 1, add a halo around it to
1724-
// make it appear more brilliant. This is a hack to compensate for the
1725-
// limited dynamic range of monitors.
1726-
//
1727-
// TODO: Stars look fine but planets look unrealistically bright
1728-
// with halos.
1729-
if (useHalos && glareAlpha > 0.0f)
1730-
{
1731-
Eigen::Vector3f center = calculateQuadCenter(getCameraOrientationf(), position, radius);
1732-
gaussianGlareTex->bind();
1733-
if (glareSize > gl::maxPointSize)
1734-
m_largeStarRenderer->render(center, {color, glareAlpha}, glareSize, mvp);
1735-
}
1736-
}
1737-
}
1738-
17391621

17401622
static void renderSphereUnlit(const RenderInfo& ri,
17411623
const math::Frustum& frustum,
@@ -2662,7 +2544,7 @@ void Renderer::renderPlanet(Body& body,
26622544
float discSizeInPixels = body.getRadius() /
26632545
(max(nearPlaneDistance, altitude) * pixelSize);
26642546

2665-
float maxDiscSize = (starStyle == ScaledDiscStars) ? MaxScaledDiscStarSize : 1.0f;
2547+
float maxDiscSize = 1.0f;
26662548
if (discSizeInPixels >= maxDiscSize && body.hasVisibleGeometry())
26672549
{
26682550
auto bodyFeaturesManager = GetBodyFeaturesManager();
@@ -3711,24 +3593,17 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
37113593
float exposure,
37123594
const Observer& observer)
37133595
{
3714-
#ifndef GL_ES
3715-
// Disable multisample rendering when drawing point stars
3716-
bool toggleAA = (starStyle == Renderer::PointStars && isMSAAEnabled());
3717-
if (toggleAA)
3718-
disableMSAA();
3719-
#endif
3720-
37213596
Vector3d obsPos = observer.getPosition().toLy();
37223597

3723-
PointStarRenderer starRenderer;
3598+
StarRenderer starRenderer;
37243599

37253600
starRenderer.renderer = this;
37263601
starRenderer.starDB = &starDB;
37273602
starRenderer.observer = &observer;
37283603
starRenderer.obsPos = obsPos;
37293604
starRenderer.viewNormal = getCameraOrientationf().conjugate() * -Vector3f::UnitZ();
37303605
starRenderer.renderList = &renderList;
3731-
starRenderer.starVertexBuffer = pointStarVertexBuffer;
3606+
starRenderer.starVertexBuffer = starVertexBuffer;
37323607
starRenderer.cosFOV = std::cos(math::degToRad(calcMaxFOV(fov, getAspectRatio())) / 2.0f);
37333608

37343609
starRenderer.pixelSize = pixelSize;
@@ -3745,11 +3620,8 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
37453620
starRenderer.starVertexBuffer->setTexture(gaussianDiscTex);
37463621
starRenderer.starVertexBuffer->setPointScale(screenDpi / 96.0f);
37473622

3748-
PointStarVertexBuffer::enable();
3749-
if (starStyle == PointStars)
3750-
starRenderer.starVertexBuffer->startBasicPoints();
3751-
else
3752-
starRenderer.starVertexBuffer->startSprites();
3623+
StarVertexBuffer::enable();
3624+
starRenderer.starVertexBuffer->startSprites();
37533625

37543626
Renderer::PipelineState ps;
37553627
ps.blending = true;
@@ -3764,7 +3636,7 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
37643636
astro::exposureToFaintestMag(exposure));
37653637

37663638
starRenderer.starVertexBuffer->finish();
3767-
PointStarVertexBuffer::disable();
3639+
StarVertexBuffer::disable();
37683640

37693641
#ifndef GL_ES
37703642
if (toggleAA)
@@ -4211,19 +4083,6 @@ void Renderer::markersToAnnotations(const celestia::MarkerList& markers,
42114083
}
42124084

42134085

4214-
void Renderer::setStarStyle(StarStyle style)
4215-
{
4216-
starStyle = style;
4217-
markSettingsChanged();
4218-
}
4219-
4220-
4221-
Renderer::StarStyle Renderer::getStarStyle() const
4222-
{
4223-
return starStyle;
4224-
}
4225-
4226-
42274086
void Renderer::loadTextures(Body* body)
42284087
{
42294088
Surface& surface = body->getSurface();
@@ -5219,14 +5078,14 @@ Renderer::renderSolarSystemObjects(const Observer &observer,
52195078
ps.depthTest = true;
52205079
setPipelineState(ps);
52215080

5222-
PointStarVertexBuffer::enable();
5081+
StarVertexBuffer::enable();
52235082
if (starStyle == PointStars)
5224-
pointStarVertexBuffer->startBasicPoints();
5083+
starVertexBuffer->startBasicPoints();
52255084
else
5226-
pointStarVertexBuffer->startSprites();
5227-
pointStarVertexBuffer->render();
5228-
pointStarVertexBuffer->finish();
5229-
PointStarVertexBuffer::disable();
5085+
starVertexBuffer->startSprites();
5086+
starVertexBuffer->render();
5087+
starVertexBuffer->finish();
5088+
StarVertexBuffer::disable();
52305089

52315090
// Render annotations in this interval
52325091
annotation = renderSortedAnnotations(annotation,

src/celengine/render.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RendererWatcher;
3434
class FrameTree;
3535
class ReferenceMark;
3636
class CurvePlot;
37-
class PointStarVertexBuffer;
37+
class StarVertexBuffer;
3838
class Observer;
3939
class Surface;
4040
class TextureFont;
@@ -76,9 +76,9 @@ struct LightSource
7676
struct SecondaryIlluminator
7777
{
7878
const Body* body;
79-
Eigen::Vector3d position_v; // viewer relative position
80-
float radius; // radius in km
81-
float reflectedIrradiance; // albedo times total irradiance from direct sources
79+
Eigen::Vector3d position_v; // viewer relative position
80+
float radius; // radius in km
81+
float reflectedIrradiance; // albedo times total irradiance from direct sources
8282
};
8383

8484

@@ -562,15 +562,6 @@ class Renderer
562562
float discSizeInPixels,
563563
const Matrices&);
564564

565-
void renderObjectAsPoint(const Eigen::Vector3f& center,
566-
float radius,
567-
float appMag,
568-
float discSizeInPixels,
569-
const Color& color,
570-
bool useHalos,
571-
bool emissive,
572-
const Matrices&);
573-
574565
void locationsToAnnotations(const Body& body,
575566
const Eigen::Vector3d& bodyPosition,
576567
const Eigen::Quaterniond& bodyOrientation);
@@ -683,7 +674,7 @@ class Renderer
683674

684675
Eigen::Quaterniond m_cameraOrientation;
685676
Eigen::Matrix3d m_cameraTransform{ Eigen::Matrix3d::Identity() };
686-
PointStarVertexBuffer* pointStarVertexBuffer;
677+
StarVertexBuffer* starVertexBuffer;
687678
std::vector<RenderListEntry> renderList;
688679
std::vector<SecondaryIlluminator> secondaryIlluminators;
689680
std::vector<DepthBufferPartition> depthPartitions;
@@ -760,7 +751,6 @@ class Renderer
760751
std::unique_ptr<celestia::render::EclipticLineRenderer> m_eclipticLineRenderer;
761752
std::unique_ptr<celestia::render::GalaxyRenderer> m_galaxyRenderer;
762753
std::unique_ptr<celestia::render::GlobularRenderer> m_globularRenderer;
763-
std::unique_ptr<celestia::render::LargeStarRenderer> m_largeStarRenderer;
764754
std::unique_ptr<celestia::render::LineRenderer> m_hollowMarkerRenderer;
765755
std::unique_ptr<celestia::render::NebulaRenderer> m_nebulaRenderer;
766756
std::unique_ptr<celestia::render::OpenClusterRenderer> m_openClusterRenderer;
@@ -824,7 +814,7 @@ class Renderer
824814

825815
static Color SelectionCursorColor;
826816

827-
friend class PointStarRenderer;
817+
friend class StarRenderer;
828818
};
829819

830820

src/celengine/pointstarrenderer.cpp renamed to src/celengine/starrenderer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// pointstarrenderer.cpp
1+
// starrenderer.cpp
22
//
33
// Copyright (C) 2001-2019, the Celestia Development Team
44
// Original version by Chris Laurel <[email protected]>
@@ -12,9 +12,9 @@
1212
#include <celengine/star.h>
1313
#include <celengine/univcoord.h>
1414
#include <cmath>
15-
#include "pointstarvertexbuffer.h"
15+
#include "starvertexbuffer.h"
1616
#include "render.h"
17-
#include "pointstarrenderer.h"
17+
#include "starrenderer.h"
1818

1919
#include <fmt/format.h>
2020

@@ -32,12 +32,12 @@ static Vector3d astrocentricPosition(const UniversalCoord& pos,
3232
return pos.offsetFromKm(star.getPosition(t));
3333
}
3434

35-
PointStarRenderer::PointStarRenderer() :
35+
StarRenderer::StarRenderer() :
3636
ObjectRenderer<Star, float>(StarDistanceLimit)
3737
{
3838
}
3939

40-
void PointStarRenderer::process(const Star& star, float distance, float irradiance)
40+
void StarRenderer::process(const Star& star, float distance, float irradiance)
4141
{
4242
if (distance > distanceLimit)
4343
return;

0 commit comments

Comments
 (0)