Scenery3d.hpp   Scenery3d.hpp 
/* /*
* Stellarium Scenery3d Plug-in * Stellarium Scenery3d Plug-in
* *
* Copyright (C) 2011-15 Simon Parzer, Peter Neubauer, Georg Zotti, Andrei Borza, Florian Schaukowitsch * Copyright (C) 2011 Simon Parzer, Peter Neubauer, Georg Zotti, Andrei Bor za
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _SCENERY3D_HPP_ #ifndef _SCENERY3D_HPP_
#define _SCENERY3D_HPP_ #define _SCENERY3D_HPP_
#include "StelGui.hpp" #include <QMap>
#include <QStringList>
#include <QFont>
#include <QtConcurrent>
#include "StelCore.hpp"
#include "StelPluginInterface.hpp"
#include "StelModule.hpp" #include "StelModule.hpp"
#include "StelPainter.hpp" #include "StelUtils.hpp"
#include "Landscape.hpp" #include "StelFader.hpp"
#include "SolarSystem.hpp" #include "StelActionMgr.hpp"
#include "StelProgressController.hpp"
#include "OBJ.hpp"
#include "Heightmap.hpp"
#include "Frustum.hpp"
#include "Polyhedron.hpp"
#include "S3DEnum.hpp"
#include "SceneInfo.hpp" #include "SceneInfo.hpp"
#include "ShaderManager.hpp" #include "S3DEnum.hpp"
#include <QMatrix4x4> class S3DRenderer;
class Scenery3dDialog;
class StoredViewDialog;
class QSettings;
class StelButton;
class S3DScene;
//! Main class of the module, inherits from StelModule.
//! Manages initialization, provides an interface to change Scenery3d prope
rties and handles user input
class Scenery3d : public StelModule
//predeclarations // toggle to switch it off completely.
class Scenery3dMgr; Q_PROPERTY(bool enableScene READ getEnableScene WRITE setEnableScen
class LandscapeMgr; e NOTIFY enableSceneChanged)
Q_PROPERTY(bool enablePixelLighting READ getEnablePixelLighting WRIT
E setEnablePixelLighting NOTIFY enablePixelLightingChanged)
Q_PROPERTY(bool enableShadows READ getEnableShadows WRITE setEnableS
hadows NOTIFY enableShadowsChanged)
Q_PROPERTY(bool useSimpleShadows READ getUseSimpleShadows WRITE setU
seSimpleShadows NOTIFY useSimpleShadowsChanged)
Q_PROPERTY(bool enableBumps READ getEnableBumps WRITE setEnableBumps
NOTIFY enableBumpsChanged)
Q_PROPERTY(S3DEnum::ShadowFilterQuality shadowFilterQuality READ get
ShadowFilterQuality WRITE setShadowFilterQuality NOTIFY shadowFilterQuality
Q_PROPERTY(bool enablePCSS READ getEnablePCSS WRITE setEnablePCSS NO
TIFY enablePCSSChanged)
Q_PROPERTY(S3DEnum::CubemappingMode cubemappingMode READ getCubemapp
ingMode WRITE setCubemappingMode NOTIFY cubemappingModeChanged)
Q_PROPERTY(bool useFullCubemapShadows READ getUseFullCubemapShadows
WRITE setUseFullCubemapShadows NOTIFY useFullCubemapShadowsChanged)
Q_PROPERTY(bool enableDebugInfo READ getEnableDebugInfo WRITE setEna
bleDebugInfo NOTIFY enableDebugInfoChanged)
Q_PROPERTY(bool enableLocationInfo READ getEnableLocationInfo WRITE
setEnableLocationInfo NOTIFY enableLocationInfoChanged)
Q_PROPERTY(bool enableTorchLight READ getEnableTorchLight WRITE setE
nableTorchLight NOTIFY enableTorchLightChanged)
Q_PROPERTY(float torchStrength READ getTorchStrength WRITE setTorchS
trength NOTIFY torchStrengthChanged)
Q_PROPERTY(float torchRange READ getTorchRange WRITE setTorchRange N
OTIFY torchRangeChanged)
Q_PROPERTY(bool enableLazyDrawing READ getEnableLazyDrawing WRITE se
tEnableLazyDrawing NOTIFY enableLazyDrawingChanged)
Q_PROPERTY(double lazyDrawingInterval READ getLazyDrawingInterval WR
ITE setLazyDrawingInterval NOTIFY lazyDrawingIntervalChanged)
Q_PROPERTY(bool onlyDominantFaceWhenMoving READ getOnlyDominantFaceW
henMoving WRITE setOnlyDominantFaceWhenMoving NOTIFY onlyDominantFaceWhenMo
Q_PROPERTY(bool secondDominantFaceWhenMoving READ getSecondDominantF
aceWhenMoving WRITE setSecondDominantFaceWhenMoving NOTIFY secondDominantFa
Q_PROPERTY(uint cubemapSize READ getCubemapSize WRITE setCubemapSize
NOTIFY cubemapSizeChanged)
Q_PROPERTY(uint shadowmapSize READ getShadowmapSize WRITE setShadowm
apSize NOTIFY shadowmapSizeChanged)
Q_PROPERTY(QString currentSceneID READ getCurrentSceneID NOTIFY curr
entSceneIDChanged STORED false)
Q_PROPERTY(QString loadingSceneID READ getLoadingSceneID NOTIFY load
ingSceneIDChanged STORED false)
//these properties are only valid after init() has been called
Q_PROPERTY(bool isGeometryShaderSupported READ getIsGeometryShaderSu
Q_PROPERTY(bool areShadowsSupported READ getAreShadowsSupported)
Q_PROPERTY(bool isShadowFilteringSupported READ getIsShadowFiltering
Q_PROPERTY(uint maximumFramebufferSize READ getMaximumFramebufferSiz
//! Representation of a complete 3D scenery
class Scenery3d : protected QOpenGLFunctions
public: public:
//! Initializes an empty Scenery3d object. Scenery3d();
Scenery3d(Scenery3dMgr *parent); virtual ~Scenery3d();
virtual ~Scenery3d();
//StelModule members
//! Loads the specified scene virtual void init();
bool loadScene(const SceneInfo& scene); virtual void deinit();
virtual void draw(StelCore* core);
//! Walk/Fly Navigation with Ctrl+Cursor and Ctrl+PgUp/Dn keys. virtual void update(double deltaTime);
//! Pressing Ctrl-Alt: 5x, Ctrl-Shift: 10x speedup; Ctrl-Shift-Alt: virtual double getCallOrder(StelModuleActionName actionName) const;
50x! virtual bool configureGui(bool show);
//! To allow fine control, zoom in. //! Walk/Fly Navigation with Ctrl+Cursor and Ctrl+PgUp/Dn keys.
//! If you release Ctrl key while pressing cursor key, movement will //! Pressing Ctrl-Alt: 5x, Ctrl-Shift: 10x speedup; Ctrl-Shift-Alt: 50x
continue. !
void handleKeys(QKeyEvent* e); //! To allow fine control, zoom in.
//! If you release Ctrl key while pressing cursor key, movement will co
//! Update method, called by Scenery3dMgr. ntinue.
//! Shifts observer position due to movement through the landscape. virtual void handleKeys(QKeyEvent* e);
void update(double deltaTime);
//! Draw observer grid coordinates as text. //! Sends the progressReport() signal, which eventually updates the pro
void drawCoordinatesText(); gress bar. Can be called from another thread.
//! Draw some text output. This can be filled as needed by developme void updateProgress(const QString& str, int val, int min, int max) cons
nt. t;
void drawDebug(); signals:
void enableSceneChanged(const bool val);
//! Draw scenery, called by Scenery3dMgr. void enablePixelLightingChanged(const bool val);
void draw(StelCore* core); void enableShadowsChanged(const bool val);
//! Performs initialization that requires an valid OpenGL context void useSimpleShadowsChanged(const bool val);
void init(); void enableBumpsChanged(const bool val);
void shadowFilterQualityChanged(const S3DEnum::ShadowFilterQuality val)
//! Gets the current scene's metadata ;
SceneInfo getCurrentScene() { return currentScene; } void enablePCSSChanged(const bool val);
void cubemappingModeChanged(const S3DEnum::CubemappingMode val);
bool getDebugEnabled() const { return debugEnabled; } void useFullCubemapShadowsChanged(const bool val);
void setDebugEnabled(bool debugEnabled) { this->debugEnabled = debug void enableDebugInfoChanged(const bool val);
Enabled; } void enableLocationInfoChanged(const bool val);
bool getPixelLightingEnabled() const { return shaderParameters.pixel void enableTorchLightChanged(const bool val);
Lighting; } void torchStrengthChanged(const float val);
void setPixelLightingEnabled(const bool val) { shaderParameters.pixe void torchRangeChanged(const float val);
lLighting = val; invalidateCubemap(); } void enableLazyDrawingChanged(const bool val);
bool getShadowsEnabled(void) const { return shaderParameters.shadows void lazyDrawingIntervalChanged(const double val);
; } void onlyDominantFaceWhenMovingChanged(const bool val);
void setShadowsEnabled(bool shadowsEnabled) { shaderParameters.shado void secondDominantFaceWhenMovingChanged(const bool val);
ws = shadowsEnabled; reinitShadowmapping = true; invalidateCubemap(); } void cubemapSizeChanged(const uint val);
bool getUseSimpleShadows() const {return simpleShadows; } void shadowmapSizeChanged(const uint val);
void setUseSimpleShadows(bool val) { simpleShadows = val; reinitShad
owmapping = true; invalidateCubemap(); } void currentSceneChanged(const SceneInfo& sceneInfo);
bool getBumpsEnabled(void) const { return shaderParameters.bump; } void currentSceneIDChanged(const QString& sceneID);
void setBumpsEnabled(bool bumpsEnabled) { shaderParameters.bump = bu void loadingSceneIDChanged(const QString& sceneID);
mpsEnabled; invalidateCubemap(); }
bool getTorchEnabled(void) const { return shaderParameters.torchLigh //! This signal is emitted from another thread than this QObject belong
t; } s to, so use QueuedConnection.
void setTorchEnabled(bool torchEnabled) { shaderParameters.torchLigh void progressReport(const QString& str, int val, int min, int max) cons
t = torchEnabled; invalidateCubemap(); } t;
S3DEnum::ShadowFilterQuality getShadowFilterQuality() const { return
shaderParameters.shadowFilterQuality; } public slots:
void setShadowFilterQuality(S3DEnum::ShadowFilterQuality quality) { //! Performs a relative translation of the viewer's position.
shaderParameters.shadowFilterQuality = quality; reinitShadowmapping=true; i //! The values should usually be given pre-adjusted with the delta time
nvalidateCubemap();} .
bool getPCSS() const { return shaderParameters.pcss; } //! Does nothing if no scene is currently loaded.
void setPCSS(bool val) { shaderParameters.pcss = val; reinitShadowma //!
pping = true; invalidateCubemap(); } //! The first component specifies movement in the "right" direction, th
bool getLocationInfoEnabled(void) const { return textEnabled; } e second
void setLocationInfoEnabled(bool locationinfoenabled) { this->textEn //! component in the "forward" directon, and the last value
abled = locationinfoenabled; } //! is used to adjust the height offset of the viewer (he is still
//! positioned according to the heightmap).
bool getLazyCubemapEnabled() const { return lazyDrawing; } void relativeMove(const Vec3d& move);
void setLazyCubemapEnabled(bool val) { lazyDrawing = val; }
double getLazyCubemapInterval() const { return lazyInterval; } //! Clears the shader cache, forcing a reload of shaders on use
void setLazyCubemapInterval(double val) { lazyInterval = val; } void reloadShaders();
//This has the be the most crazy method name in the plugin //! Display text message on screen, fade out automatically
void getLazyCubemapUpdateOnlyDominantFaceOnMoving(bool &val, bool &a void showMessage(const QString& message);
lsoSecondDominantFace) { val = updateOnlyDominantOnMoving; alsoSecondDomina
ntFace = updateSecondDominantOnMoving; } //! Shows the stored view dialog
void setLazyCubemapUpdateOnlyDominantFaceOnMoving(bool val, bool als void showStoredViewDialog();
oSecondDominantFace) { updateOnlyDominantOnMoving = val; updateSecondDomina
ntOnMoving = alsoSecondDominantFace; } //! Enables/Disables the plugin
void setEnableScene(const bool val);
//! Does a cubemap redraw at the next possible opportunity when lazy bool getEnableScene() const {return flagEnabled; }
-drawing is enabled.
inline void invalidateCubemap() { lastCubemapUpdate = 0.0; } void setEnablePixelLighting(const bool val);
bool getEnablePixelLighting(void) const;
S3DEnum::CubemappingMode getCubemappingMode() const { return cubemap
pingMode; } //! Use this to set/get the enableShadows flag.
//! Changes cubemapping mode and forces re-initialization on next dr //! If set to true, shadow mapping is enabled for the 3D scene.
aw call. void setEnableShadows(const bool enableShadows);
//! This may not set the actual mode to the parameter, call getCubem bool getEnableShadows(void) const;
appingMode to find out what was set.
void setCubemappingMode(S3DEnum::CubemappingMode mode) //! If true, only 1 shadow cascade is used, giving a speedup
{ void setUseSimpleShadows(const bool simpleShadows);
if(mode == S3DEnum::CM_CUBEMAP_GSACCEL && !isGeometryShaderC bool getUseSimpleShadows() const;
{ //! Use this to set/get the enableBumps flag.
//fallback to 6 Textures mode //! If set to true, bump mapping is enabled for the 3D scene.
mode = S3DEnum::CM_TEXTURES; void setEnableBumps(const bool enableBumps);
} bool getEnableBumps(void) const;
if(mode == S3DEnum::CM_CUBEMAP && isANGLEContext())
{ //! Returns the current shadow filter quality.
//Cubemap mode disabled on ANGLE because of an imple S3DEnum::ShadowFilterQuality getShadowFilterQuality(void) const;
mentation bug with Qt 5.4's version //! Sets the shadow filter quality
mode = S3DEnum::CM_TEXTURES; void setShadowFilterQuality(const S3DEnum::ShadowFilterQuality val);
cubemappingMode = mode; reinitCubemapping = true; void setEnablePCSS(const bool val);
} bool getEnablePCSS() const;
void setUseFullCubemapShadows(bool val) { fullCubemapShadows = val; //! Returns the current cubemapping mode
invalidateCubemap();} S3DEnum::CubemappingMode getCubemappingMode(void) const;
bool getUseFullCubemapShadows() const { return fullCubemapShadows; } //! Sets the cubemapping mode
void setCubemappingMode(const S3DEnum::CubemappingMode val);
uint getCubemapSize() const { return cubemapSize; }
//! Note: This may not set the size to the desired one because of ha bool getUseFullCubemapShadows() const;
rdware limits, call getCubemapSize to receive the value set after this call void setUseFullCubemapShadows(const bool useFullCubemapShadows);
void setCubemapSize(uint size) { cubemapSize = (size > maximumFrameb //! Set to true to show some rendering debug information
ufferSize ? maximumFramebufferSize : size); reinitCubemapping = true; } void setEnableDebugInfo(const bool debugEnabled);
uint getShadowmapSize() const { return shadowmapSize; } bool getEnableDebugInfo() const;
//! Note: This may not set the size to the desired one because of ha
rdware limits, call getShadowmapSize to receive the value set after this ca //! Set to true to show the current standing positin as text on screen.
ll. void setEnableLocationInfo(const bool enableLocationInfo);
void setShadowmapSize(uint size) { shadowmapSize = (size > maximumFr bool getEnableLocationInfo() const;
amebufferSize ? maximumFramebufferSize : size); reinitShadowmapping = true;
} //! Set to true to add an additional light source centered at the curre
float getTorchBrightness() const { return torchBrightness; } nt position, useful in night scenes.
void setTorchBrightness(float brightness) { torchBrightness = bright void setEnableTorchLight(const bool enableTorchLight);
ness; invalidateCubemap(); } bool getEnableTorchLight() const;
float getTorchRange() const { return torchRange; }
void setTorchRange(float range) { torchRange = range; invalidateCube //! Sets the strength of the additional illumination that can be toggle
map(); } d when pressing a button.
void setTorchStrength(const float torchStrength);
void setLoadCancel(bool val) { loadCancel = val; } float getTorchStrength() const;
//! Sets the observer position to the specified grid coordinates. //! Sets the range of the torchlight.
//! The height is assumed to be at the feet, so make sure to set the void setTorchRange(const float torchRange);
eye height with setEyeHeight before, if necessary. float getTorchRange() const;
void setGridPosition(Vec3d pos);
//! Gets the current position on the scene's grid (height at feet) //! Sets the state of the cubemap lazy-drawing mode
Vec3d getCurrentGridPosition() const; void setEnableLazyDrawing(const bool val);
bool getEnableLazyDrawing() const;
//! Sets the observer eye height.
void setEyeHeight(const float eyeheight) { eye_height = eyeheight; } //! When true, only the face which currently is most dominantly visible
//! Gets the current observer eye height (vertical difference from f is updated while moving.
eet to camera position). void setOnlyDominantFaceWhenMoving(const bool val);
float getEyeHeight() const { return eye_height; } bool getOnlyDominantFaceWhenMoving() const;
enum ShadowCaster { None, Sun, Moon, Venus }; void setSecondDominantFaceWhenMoving(const bool val);
bool getSecondDominantFaceWhenMoving() const;
//! Returns the shader manager this instance uses
ShaderMgr& getShaderManager() { return shaderManager; //! Forces a redraw of the cubemap
} void forceCubemapRedraw();
//! Loads the model into GL and sets the loaded scene to be the curr //! Sets the interval for cubemap lazy-drawing mode
ent one void setLazyDrawingInterval(const double val);
void finalizeLoad(); double getLazyDrawingInterval() const;
//these are some properties that determine the features supported in //! Sets the size used for cubemap rendering.
the current GL context //! For best compatibility and performance, this should be a power of 2
//available after init() is called .
bool isGeometryShaderCubemapSupported() { return supportsGSCubemappi void setCubemapSize(const uint val);
ng; } uint getCubemapSize() const;
bool areShadowsSupported() { return supportsShadows; }
bool isShadowFilteringSupported() { return supportsShadowFiltering; //! Sets the size used for shadowmap rendering.
} //! For best compatibility and performance, this should be a power of 2
bool isANGLEContext() { return isANGLE; } .
unsigned int getMaximumFramebufferSize() { return maximumFramebuffer void setShadowmapSize(const uint val);
Size; } uint getShadowmapSize() const;
//these properties are only valid after init() has been called
bool getIsGeometryShaderSupported() const;
bool getAreShadowsSupported() const;
bool getIsShadowFilteringSupported() const;
bool getIsANGLE() const;
uint getMaximumFramebufferSize() const;
//! Gets the SceneInfo of the scene that is currently being displayed.
//! Check SceneInfo::isValid to determine if a scene is displayed.
SceneInfo getCurrentScene() const;
//! Returns the ID of the currently loaded scene, or an null string if
nothing is displayed.
QString getCurrentSceneID() const;
//! Returns the ID of the currently loading scene, or null if nothing i
s being loaded
QString getLoadingSceneID() const;
//! Gets the SceneInfo of the scene that is currently in the process of
being loaded.
//! Check SceneInfo::isValid to determine if a scene is loaded.
SceneInfo getLoadingScene() const { return currentLoadScene; }
//! This starts the scene loading process. This is asynchronous, this m
ethod returns after metadata loading.
//! @param name a valid scene name
//! @return The loaded SceneInfo. Check SceneInfo::isValid to make sure
loading was successful.
SceneInfo loadScenery3dByName(const QString& name);
//! This starts the scene loading process. This is asynchronous, this m
ethod returns after metadata loading.
//! @param id a valid scene id/folder path
//! @return The loaded SceneInfo. Check SceneInfo::isValid to make sure
loading was successful.
SceneInfo loadScenery3dByID(const QString& id);
QString getDefaultScenery3dID() const { return defaultScenery3dID; }
void setDefaultScenery3dID(const QString& id);
//! Changes the current view to the given view. JD is updated only if v
iew contains valid data and setDate is true
void setView(const StoredView& view, const bool setDate);
//! Returns a StoredView that represents the current observer position
+ view direction.
//! Label and description are empty.
StoredView getCurrentView();
private slots:
void clearMessage();
void loadSceneCompleted();
void progressReceive(const QString& str, int val, int min, int max);
void loadScene(const SceneInfo& scene);
private: private:
Scenery3dMgr* parent; //! Loads config values from app settings
SceneInfo currentScene,loadingScene; void loadConfig();
ShaderMgr shaderManager; //! Creates all actions required by the plugin
PlanetP sun,moon,venus; void createActions();
//! Creates the toolbar buttons of the plugin
bool supportsGSCubemapping; //if the GL context supports geometry sh void createToolbarButtons() const;
ader cubemapping
bool supportsShadows; //if shadows are supported //! This is run asynchronously in a background thread, performing the a
bool supportsShadowFiltering; //if shadow filtering is supported ctual scene loading
bool isANGLE; //true if running on ANGLE S3DScene *loadSceneBackground(const SceneInfo &scene) const;
unsigned int maximumFramebufferSize;
GLuint defaultFBO; //the default background FBO handle // the other "main" objects
S3DRenderer* renderer;
float torchBrightness; // toggle light brightness Scenery3dDialog* scenery3dDialog;
float torchRange; // used to calculate attenuation like in the secon StoredViewDialog* storedViewDialog;
d form at
QSettings* conf;
bool textEnabled; // switchable value: display coordinates QString defaultScenery3dID;
bool debugEnabled; // switchable value: display debug graph bool cleanedUp;
ics and debug texts on screen
bool fixShadowData; //for debugging, fixes all shadow mapping relate Vec3d movementKeyInput;
d data (shadowmap contents, matrices, frustums, focus bodies...) at their c
urrent values StelCore* core;
bool simpleShadows; StelMovementMgr* mvMgr;
bool fullCubemapShadows; StelCore::ProjectionType oldProjectionType;
S3DEnum::CubemappingMode cubemappingMode;
bool reinitCubemapping,reinitShadowmapping; //screen messages (taken largely from AngleMeasure as of 2012-01-21)
LinearFader messageFader;
bool loadCancel; //true if loading process should be canceled QTimer* messageTimer;
Vec3f textColor;
unsigned int cubemapSize; // configurable values, typical QFont font;
ly 512/1024/2048/4096 QString currentMessage;
unsigned int shadowmapSize;
volatile bool loadCancel;
Vec3d absolutePosition; // current eyepoint in model (note: this StelProgressController* progressBar;
is actually the negated position, i.e. the value used to translate the vie SceneInfo currentLoadScene;
w matrix) S3DScene* currentScene;
Vec3d moveVector; // position change in scene coords QFutureWatcher<S3DScene*> currentLoadFuture;
Vec3f movement; // speed values for moving around the scener };
float eye_height; #include <QObject>
#include "StelPluginInterface.hpp"
StelCore* core;
LandscapeMgr* landscapeMgr; //! This class is used by Qt to manage a plug-in interface
StelProjectorP altAzProjector; class Scenery3dStelPluginInterface : public QObject, public StelPluginInter
QSharedPointer<OBJ> objModel, objModelLoad, groundModel, groundModel face
Load; {
Heightmap* heightmap; Q_OBJECT
Heightmap* heightmapLoad; Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
Vec3d mainViewUp; public:
Vec3d mainViewDir; virtual StelModule* getStelModule() const;
Vec3d viewPos; virtual StelPluginInfo getPluginInfo() const;
virtual QObjectList getExtensionList() const;
int drawnTriangles,drawnModels;
int materialSwitches, shaderSwitches;
/// ---- Cubemapping variables ----
bool requiresCubemap; //true if cubemapping is required (if projecti
on is anything else than Perspective)
bool cubemappingUsedLastFrame; //true if cubemapping was used for th
e last frame. Used to determine if a projection switch occured.
bool lazyDrawing; //if lazy-drawing mode is enabled
bool updateOnlyDominantOnMoving; //if movement updates only dominant
face directly
bool updateSecondDominantOnMoving; //if movement also updates the se
cond-most dominant face
bool needsMovementEndUpdate;
bool needsCubemapUpdate; //if the draw-call has to recreate the cube
map completely
bool needsMovementUpdate; //if the draw-call has to recreate either
the whole cubemap or the dominant face
double lazyInterval; //the lazy-drawing time interval
double lastCubemapUpdate; //when the last lazy draw happened (JDay)
qint64 lastCubemapUpdateRealTime; //when the last lazy draw happened
(real system time, QDateTime::currentMSecsSinceEpoch)
qint64 lastMovementEndRealTime; //the timepoint when the last moveme
nt was stopped
GLuint cubeMapCubeTex; //GL_TEXTURE_CUBE_MAP, used in CUBEMAP or CUB
GLuint cubeMapCubeDepth; //this is a depth-cubemap, only used in CUB
GLuint cubeMapTex[6]; //GL_TEXTURE_2D, for "legacy" TEXTURES mode
GLuint cubeRB; //renderbuffer for depth of a single face in TEXTURES
and CUBEMAP modes (attached to multiple FBOs)
int dominantFace,secondDominantFace;
//because of use that deviates very much from QOpenGLFramebufferObje
ct typical usage, we manage the FBOs ourselves
GLuint cubeFBO; //used in CUBEMAP_GSACCEL mode - only a single FBO e
xists, with a cubemap for color and one for depth
GLuint cubeSideFBO[6]; //used in TEXTURES and CUBEMAP mode, 6 textur
es/cube faces for color and a shared depth renderbuffer (we don't require t
he depth after rendering)
bool cubeMappingCreated; //true if any cubemapping objects have been
initialized and need to be cleaned up eventually
//cube geometry
QVector<Vec3f> cubeVertices, transformedCubeVertices;
QVector<Vec2f> cubeTexcoords;
QOpenGLBuffer cubeVertexBuffer;
QOpenGLBuffer transformedCubeVertexBuffer;
QOpenGLBuffer cubeIndexBuffer;
int cubeIndexCount;
//cube rendering matrices
QMatrix4x4 cubeRotation[6]; //rotational matrices for cube faces. Th
e cam position is added to this in each frame.
QMatrix4x4 cubeMVP[6]; //cube face MVP matrices
/// ---- Rendering information ----
//final model view matrix for shader upload
QMatrix4x4 modelViewMatrix;
//currently valid projection matrix for shader upload
QMatrix4x4 projectionMatrix;
// a struct which encapsulates lighting info
struct LightParameters
QMatrix4x4 shadowModelView;
ShadowCaster lightSource;
Vec3f lightDirectionV3f;
QVector3D lightDirectionWorld;
QVector3D ambient;
QVector3D directional;
QVector3D specular;
QVector3D emissive;
QVector3D torchDiffuse;
float torchAttenuation;
} lightInfo;
GlobalShaderParameters shaderParameters;
//Scene AABB
AABB sceneBoundingBox;
//Shadow Map FBO handles
QVector<GLuint> shadowFBOs;
//Holds the shadow textures
QVector<GLuint> shadowMapsArray;
//Holds the shadow transformation matrix per split (Crop/Projection/
QVector<QMatrix4x4> shadowCPM;
//Holds the xy-scaling of the orthographic light cam + pos of near/f
ar planes in view coords
//Needed for consistent shadow filter sizes and PCSS effect
QVector<QVector4D> shadowFrustumSize;
// Frustum of the view camera, constrainted to the shadowFarZ instea
d of the camFarZ
Frustum camFrustShadow;
//near/far planes for the orthographic light that fits the whole sce
float lightOrthoNear;
float lightOrthoFar;
//Array holding the split frustums
QVector<Frustum> frustumArray;
//Vector holding the convex split bodies for focused shadow mapping
QVector<Polyhedron> focusBodies;
float parallaxScale;
QFont debugTextFont;
QString lightMessage; // DEBUG/TEST ONLY. contains on-screen info on
ambient/directional light strength and source.
QString lightMessage2; // DEBUG/TEST ONLY. contains on-screen info o
n ambient/directional light strength and source.
QString lightMessage3; // DEBUG/TEST ONLY. contains on-screen info o
n ambient/directional light strength and source.
// --- initialization
//! Determines what features the current opengl context supports
void determineFeatureSupport();
//! Initializes cubemapping to the currently set parameters (6tex/cu
bemap/GS approaches)
bool initCubemapping();
//! Cleans up cubemapping related objects
void deleteCubemapping();
//! Re-initializes shadowmapping related objects
bool initShadowmapping();
//! Cleans up shadowmapping related objects
void deleteShadowmapping();
void calcCubeMVP();
// --- drawing methods ---
//! Basic setup for default perspective drawing. Standard OpenGL for
ward rendering.
void drawDirect();
//! When another projection than perspective is selected, rendering
is performed using a cubemap.
void drawWithCubeMap();
//! Performs the actual rendering of the shadow map
bool renderShadowMaps();
//! Creates shadowmaps for the specified cubemap face
void renderShadowMapsForFace(int face);
//! Generates a 6-sided cube map by drawing a view in each direction
void generateCubeMap();
//! Uses a geometry shader to render 6 faces in 1 pass
void renderIntoCubemapGeometryShader();
//! Uses 6 traditional rendering passes to render into a cubemap or
6 textures.
void renderIntoCubemapSixPasses();
//! Uses the StelPainter to draw a warped cube textured with our cub
void drawFromCubeMap();
//! This is the method that performs the actual drawing.
//! If shading is true, a suitable shader for each material is selec
ted and initialized. Submits 1 draw call for each StelModel.
//! @return false on shader errors
bool drawArrays(bool shading=true, bool blendAlphaAdditive=false);
// --- shading related stuff ---
//! Finds out the shadow caster and determines shadow parameters for
current frame
void calculateShadowCaster();
//! Calculates lighting related stuff and puts it in the lightInfo s
void calculateLighting();
//! Sets uniforms constant over the whole pass (=projection matrix,
lighting & shadow info)
void setupPassUniforms(QOpenGLShaderProgram *shader);
//! Sets up shader uniforms constant over the whole frame/side of cu
bemap (=modelview dependent stuff)
void setupFrameUniforms(QOpenGLShaderProgram *shader);
//! Sets up shader uniforms specific to one material
void setupMaterialUniforms(QOpenGLShaderProgram *shader, const OBJ::
Material& mat);
//! Finds the correct light source out of Sun, Moon, Venus, and retu
rns ambient and directional light components.
Scenery3d::ShadowCaster calculateLightSource(float &ambientBrightnes
s, float &diffuseBrightness, Vec3f &lightsourcePosition, float &emissiveFac
//! @return height at -absolutePosition, which is the current eye po
float groundHeight();
//Sets the scenes' AABB
void setSceneAABB(const AABB &bbox);
//Save the Frustum to be able to move away from it and analyze it
void saveFrusts();
//! Adjust the frustum to the loaded scene bounding box according to
Zhang et al.
void adjustShadowFrustum(const Vec3d viewPos, const Vec3d viewDir, c
onst Vec3d viewUp, const float fov, const float aspect);
//Computes the frustum splits
void computeFrustumSplits(const Vec3d viewPos, const Vec3d viewDir,
const Vec3d viewUp);
//Computes the focus body for given frustum
void computePolyhedron(Polyhedron& body, const Frustum& frustum, con
st Vec3f &shadowDir);
//Computes the crop matrix to focus the light
void computeCropMatrix(QMatrix4x4& cropMatrix, QVector4D &orthoScale
, Polyhedron &focusBody, const QMatrix4x4 &lightProj, const QMatrix4x4 &lig
//Computes the light projection values
void computeOrthoProjVals(const Vec3f shadowDir, float &orthoExtent,
float &orthoNear, float &orthoFar);
}; };
#endif #endif // _SCENERY3D_HPP_
 End of changes. 10 change blocks. 
451 lines changed or deleted 361 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from