00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _RENDER_H_
00011 #define _RENDER_H_
00012
00013 #include <vector>
00014 #include <string>
00015 #include <celengine/observer.h>
00016 #include <celengine/universe.h>
00017 #include <celengine/selection.h>
00018 #include <celengine/glcontext.h>
00019 #include <celengine/starcolors.h>
00020 #include <celengine/rendcontext.h>
00021 #include <celtxf/texturefont.h>
00022
00023
00024 struct RenderListEntry
00025 {
00026 const Star* star;
00027 Body* body;
00028 Point3f position;
00029 Vec3f sun;
00030 float distance;
00031 float radius;
00032 float nearZ;
00033 float farZ;
00034 float discSizeInPixels;
00035 float appMag;
00036 bool isCometTail;
00037 int depthBucket;
00038 int solarSysIndex;
00039 };
00040
00041 static const unsigned int MaxSolarSystems = 16;
00042
00043
00044 class Renderer
00045 {
00046 public:
00047 Renderer();
00048 ~Renderer();
00049
00050 struct DetailOptions
00051 {
00052 DetailOptions();
00053 unsigned int ringSystemSections;
00054 unsigned int orbitPathSamplePoints;
00055 unsigned int shadowTextureSize;
00056 unsigned int eclipseTextureSize;
00057 };
00058
00059 bool init(GLContext*, int, int, DetailOptions&);
00060 void shutdown() {};
00061 void resize(int, int);
00062
00063 float calcPixelSize(float fov, float windowHeight);
00064 void setFaintestAM45deg(float);
00065 float getFaintestAM45deg();
00066
00067 void setRenderMode(int);
00068 void autoMag(float& faintestMag);
00069 void render(const Observer&,
00070 const Universe&,
00071 float faintestVisible,
00072 const Selection& sel);
00073
00074 enum {
00075 NoLabels = 0x000,
00076 StarLabels = 0x001,
00077 PlanetLabels = 0x002,
00078 MoonLabels = 0x004,
00079 ConstellationLabels = 0x008,
00080 GalaxyLabels = 0x010,
00081 AsteroidLabels = 0x020,
00082 SpacecraftLabels = 0x040,
00083 LocationLabels = 0x080,
00084 CometLabels = 0x100,
00085 NebulaLabels = 0x200,
00086 OpenClusterLabels = 0x400,
00087 I18nConstellationLabels = 0x800,
00088 BodyLabelMask = (PlanetLabels | MoonLabels | AsteroidLabels | SpacecraftLabels | CometLabels),
00089 };
00090
00091 enum {
00092 ShowNothing = 0x0000,
00093 ShowStars = 0x0001,
00094 ShowPlanets = 0x0002,
00095 ShowGalaxies = 0x0004,
00096 ShowDiagrams = 0x0008,
00097 ShowCloudMaps = 0x0010,
00098 ShowOrbits = 0x0020,
00099 ShowCelestialSphere = 0x0040,
00100 ShowNightMaps = 0x0080,
00101 ShowAtmospheres = 0x0100,
00102 ShowSmoothLines = 0x0200,
00103 ShowEclipseShadows = 0x0400,
00104 ShowStarsAsPoints = 0x0800,
00105 ShowRingShadows = 0x1000,
00106 ShowBoundaries = 0x2000,
00107 ShowAutoMag = 0x4000,
00108 ShowCometTails = 0x8000,
00109 ShowMarkers = 0x10000,
00110 ShowPartialTrajectories = 0x20000,
00111 ShowNebulae = 0x40000,
00112 ShowOpenClusters = 0x80000,
00113 };
00114
00115 enum StarStyle
00116 {
00117 FuzzyPointStars = 0,
00118 PointStars = 1,
00119 ScaledDiscStars = 2,
00120 StarStyleCount = 3,
00121 };
00122
00123 int getRenderFlags() const;
00124 void setRenderFlags(int);
00125 int getLabelMode() const;
00126 void setLabelMode(int);
00127 void addLabelledStar(Star*, const std::string&);
00128 void clearLabelledStars();
00129 float getAmbientLightLevel() const;
00130 void setAmbientLightLevel(float);
00131 float getMinimumOrbitSize() const;
00132 void setMinimumOrbitSize(float);
00133 float getMinimumFeatureSize() const;
00134 void setMinimumFeatureSize(float);
00135 float getDistanceLimit() const;
00136 void setDistanceLimit(float);
00137 int getOrbitMask() const;
00138 void setOrbitMask(int);
00139 int getScreenDpi() const;
00140 void setScreenDpi(int);
00141 const ColorTemperatureTable* getStarColorTable() const;
00142 void setStarColorTable(const ColorTemperatureTable*);
00143
00144 bool getFragmentShaderEnabled() const;
00145 void setFragmentShaderEnabled(bool);
00146 bool fragmentShaderSupported() const;
00147 bool getVertexShaderEnabled() const;
00148 void setVertexShaderEnabled(bool);
00149 bool vertexShaderSupported() const;
00150
00151 GLContext* getGLContext() { return context; }
00152
00153 float getSaturationMagnitude() const;
00154 void setSaturationMagnitude(float);
00155 float getBrightnessBias() const;
00156 void setBrightnessBias(float);
00157 void setStarStyle(StarStyle);
00158 StarStyle getStarStyle() const;
00159 void setResolution(unsigned int resolution);
00160 unsigned int getResolution();
00161
00162 void loadTextures(Body*);
00163
00164 typedef struct {
00165 std::string text;
00166 Color color;
00167 Point3f position;
00168 } Label;
00169
00170 void addLabel(std::string, Color, const Point3f&, float depth = -1);
00171 void addSortedLabel(std::string, Color, const Point3f&);
00172 void clearLabels();
00173
00174 void setFont(TextureFont*);
00175 TextureFont* getFont() const;
00176
00177 public:
00178
00179
00180
00181 struct Particle
00182 {
00183 Point3f center;
00184 float size;
00185 Color color;
00186 float pad0, pad1, pad2;
00187 };
00188
00189 struct RenderProperties
00190 {
00191 RenderProperties() :
00192 surface(NULL),
00193 atmosphere(NULL),
00194 rings(NULL),
00195 radius(1.0f),
00196 semiAxes(1.0f, 1.0f, 1.0f),
00197 model(InvalidResource),
00198 orientation(1.0f),
00199 locations(NULL)
00200 {};
00201
00202 Surface* surface;
00203 const Atmosphere* atmosphere;
00204 RingSystem* rings;
00205 float radius;
00206 Vec3f semiAxes;
00207 ResourceHandle model;
00208 Quatf orientation;
00209 std::vector<EclipseShadow>* eclipseShadows;
00210 std::vector<Location*>* locations;
00211 };
00212
00213 class StarVertexBuffer
00214 {
00215 public:
00216 StarVertexBuffer(unsigned int _capacity);
00217 ~StarVertexBuffer();
00218 void start(bool _usePoints);
00219 void render();
00220 void finish();
00221 void addStar(const Point3f&, const Color&, float);
00222 void setBillboardOrientation(const Quatf&);
00223
00224 private:
00225 unsigned int capacity;
00226 unsigned int nStars;
00227 float* vertices;
00228 float* texCoords;
00229 unsigned char* colors;
00230 Vec3f v0, v1, v2, v3;
00231 bool usePoints;
00232 };
00233
00234 struct LightSource
00235 {
00236 Point3d position;
00237 Color color;
00238 float luminosity;
00239 float radius;
00240 };
00241
00242
00243 class PointStarVertexBuffer
00244 {
00245 public:
00246 PointStarVertexBuffer(unsigned int _capacity);
00247 ~PointStarVertexBuffer();
00248 void start(const GLContext&);
00249 void render();
00250 void finish();
00251 void addStar(const Point3f& f, const Color&, float);
00252
00253 private:
00254 struct StarVertex
00255 {
00256 Point3f position;
00257 float size;
00258 unsigned char color[4];
00259 float pad;
00260 };
00261
00262 unsigned int capacity;
00263 unsigned int nStars;
00264 StarVertex* vertices;
00265 const GLContext* context;
00266 };
00267
00268 private:
00269 struct SkyVertex
00270 {
00271 float x, y, z;
00272 unsigned char color[4];
00273 };
00274
00275 struct SkyContourPoint
00276 {
00277 Vec3f v;
00278 Vec3f eyeDir;
00279 float centerDist;
00280 float eyeDist;
00281 float cosSkyCapAltitude;
00282 };
00283
00284 template <class OBJ> struct ObjectLabel
00285 {
00286 OBJ* obj;
00287 std::string label;
00288
00289 ObjectLabel() :
00290 obj (NULL),
00291 label("")
00292 {};
00293
00294 ObjectLabel(OBJ* _obj, const std::string& _label) :
00295 obj (_obj),
00296 label(_label)
00297 {};
00298
00299 ObjectLabel(const ObjectLabel& objLbl) :
00300 obj (objLbl.obj),
00301 label(objLbl.label)
00302 {};
00303
00304 ObjectLabel& operator = (const ObjectLabel& objLbl)
00305 {
00306 obj = objLbl.obj;
00307 label = objLbl.label;
00308 return *this;
00309 };
00310 };
00311
00312 typedef ObjectLabel<Star> StarLabel;
00313 typedef ObjectLabel<DeepSkyObject> DSOLabel;
00314
00315 private:
00316 void setFieldOfView(float);
00317 void renderStars(const StarDatabase& starDB,
00318 float faintestVisible,
00319 const Observer& observer);
00320 void renderDeepSkyObjects(const Universe&,
00321 const Observer&,
00322 float faintestMagNight);
00323 void renderCelestialSphere(const Observer& observer);
00324 void renderPlanetarySystem(const Star& sun,
00325 const PlanetarySystem& solSystem,
00326 const Observer& observer,
00327 double now,
00328 unsigned int solarSysIndex,
00329 bool showLabels = false);
00330
00331 void renderObject(Point3f pos,
00332 float distance,
00333 double now,
00334 Quatf cameraOrientation,
00335 float nearPlaneDistance,
00336 float farPlaneDistance,
00337 RenderProperties& obj,
00338 const LightingState&);
00339
00340 void renderPlanet(Body& body,
00341 Point3f pos,
00342 float distance,
00343 float appMag,
00344 double now,
00345 Quatf orientation,
00346 const vector<LightSource>& lightSources,
00347 float, float);
00348
00349 void renderStar(const Star& star,
00350 Point3f pos,
00351 float distance,
00352 float appMag,
00353 Quatf orientation,
00354 double now,
00355 float, float);
00356
00357 void renderCometTail(const Body& body,
00358 Point3f pos,
00359 float distance,
00360 float appMag,
00361 double now,
00362 Quatf orientation,
00363 const vector<LightSource>& lightSources,
00364 float, float);
00365
00366 void renderBodyAsParticle(Point3f center,
00367 float appMag,
00368 float _faintestMag,
00369 float discSizeInPixels,
00370 Color color,
00371 const Quatf& orientation,
00372 float renderDistance,
00373 bool useHaloes);
00374
00375 void renderEllipsoidAtmosphere(const Atmosphere& atmosphere,
00376 Point3f center,
00377 const Quatf& orientation,
00378 Vec3f semiAxes,
00379 const Vec3f& sunDirection,
00380 Color ambientColor,
00381 float fade,
00382 bool lit);
00383
00384 void renderLocations(const vector<Location*>& locations,
00385 const Quatf& cameraOrientation,
00386 const Point3f& position,
00387 const Quatf& orientation,
00388 float scale);
00389
00390 bool testEclipse(const Body& receiver,
00391 const Body& caster,
00392 const DirectionalLight& light,
00393 double now,
00394 vector<EclipseShadow>& shadows);
00395
00396 void labelStars(const std::vector<StarLabel>& labelledStars,
00397 const StarDatabase&,
00398 const Observer&);
00399 void labelConstellations(const AsterismList& asterisms,
00400 const Observer& observer);
00401 void renderParticles(const std::vector<Particle>& particles,
00402 Quatf orientation);
00403 void renderLabels();
00404 std::vector<Label>::iterator renderSortedLabels(std::vector<Label>::iterator,
00405 float depth);
00406 void renderMarkers(const MarkerList&,
00407 const UniversalCoord& position,
00408 const Quatf& orientation,
00409 double jd);
00410
00411 void renderOrbit(Body*, double);
00412 void renderOrbits(PlanetarySystem*, const Selection&, double,
00413 const Point3d&, const Point3d&);
00414 void renderForegroundOrbits(const PlanetarySystem* system,
00415 const Point3f ¢er,
00416 float distance,
00417 float discSizeInPixels,
00418 const Selection& sel,
00419 double t);
00420
00421 private:
00422 GLContext* context;
00423
00424 int windowWidth;
00425 int windowHeight;
00426 float fov;
00427 int screenDpi;
00428 float corrFac;
00429 float pixelSize;
00430 float faintestAutoMag45deg;
00431 TextureFont* font;
00432
00433 int renderMode;
00434 int labelMode;
00435 int renderFlags;
00436 int orbitMask;
00437 float ambientLightLevel;
00438 bool fragmentShaderEnabled;
00439 bool vertexShaderEnabled;
00440 float brightnessBias;
00441
00442 float brightnessScale;
00443 float faintestMag;
00444 float faintestPlanetMag;
00445 float saturationMagNight;
00446 float saturationMag;
00447 StarStyle starStyle;
00448
00449 Color ambientColor;
00450 std::string displayedSurface;
00451
00452 StarVertexBuffer* starVertexBuffer;
00453 std::vector<RenderListEntry> renderList;
00454 std::vector<Particle> glareParticles;
00455 std::vector<Label> labels;
00456 std::vector<Label> depthSortedLabels;
00457 std::vector<EclipseShadow> eclipseShadows[MaxLights];
00458 std::vector<const Star*> nearStars;
00459
00460 std::vector<LightSource> lightSourceLists[MaxSolarSystems];
00461
00462 std::vector<StarLabel> labelledStars;
00463 std::vector<DSOLabel> labelledDSOs;
00464
00465 double modelMatrix[16];
00466 double projMatrix[16];
00467
00468 bool useCompressedTextures;
00469 bool useVertexPrograms;
00470 bool useRescaleNormal;
00471 bool usePointSprite;
00472 bool useClampToBorder;
00473 unsigned int textureResolution;
00474
00475 DetailOptions detailOptions;
00476
00477 public:
00478 struct OrbitSample
00479 {
00480 double t;
00481 Point3f pos;
00482 };
00483
00484 private:
00485 struct CachedOrbit
00486 {
00487 Body* body;
00488 std::vector<OrbitSample> trajectory;
00489 bool keep;
00490 };
00491 std::vector<CachedOrbit*> orbitCache;
00492
00493 float minOrbitSize;
00494 float distanceLimit;
00495 float minFeatureSize;
00496 uint32 locationFilter;
00497
00498 SkyVertex* skyVertices;
00499 uint32* skyIndices;
00500 SkyContourPoint* skyContour;
00501
00502 const ColorTemperatureTable* colorTemp;
00503 };
00504
00505 #endif // _RENDER_H_