mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 11:18:22 -05:00
Merge remote-tracking branch 'origin/feature/volumerendering' into develop
This commit is contained in:
@@ -34,8 +34,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
#include <openspace/rendering/volume.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#include <openspace/rendering/raycasterlistener.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace ghoul {
|
||||
|
||||
@@ -54,7 +57,7 @@ class RenderableVolume;
|
||||
class Camera;
|
||||
class Scene;
|
||||
|
||||
class ABufferRenderer : public Renderer {
|
||||
class ABufferRenderer : public Renderer, public RaycasterListener {
|
||||
public:
|
||||
ABufferRenderer();
|
||||
virtual ~ABufferRenderer();
|
||||
@@ -69,42 +72,52 @@ public:
|
||||
void update();
|
||||
void render(float blackoutFactor, bool doPerformanceMeasurements) override;
|
||||
|
||||
|
||||
/**
|
||||
* Update render data
|
||||
* Responsible for calling renderEngine::setRenderData
|
||||
*/
|
||||
virtual void updateRendererData() override;
|
||||
|
||||
virtual void raycastersChanged(VolumeRaycaster* entity, bool attached) override;
|
||||
private:
|
||||
|
||||
void clear();
|
||||
void updateResolution();
|
||||
ghoul::Dictionary createResolveDictionary();
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> createResolveProgram(const ghoul::Dictionary& dict);
|
||||
void updateRaycastData();
|
||||
void updateResolveDictionary();
|
||||
|
||||
Camera* _camera;
|
||||
Scene* _scene;
|
||||
glm::ivec2 _resolution;
|
||||
|
||||
bool _dirtyResolution;
|
||||
bool _dirtyRendererData;
|
||||
bool _dirtyRaycastData;
|
||||
bool _dirtyResolveDictionary;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _resolveProgram;
|
||||
|
||||
/**
|
||||
* When a volume is attached or detached from the scene graph,
|
||||
* the resolve program needs to be recompiled.
|
||||
* The #_volumes vector keeps track of which volumes that can
|
||||
* be rendered using the current resolve program.
|
||||
* The #_volumes map keeps track of which volumes that can
|
||||
* be rendered using the current resolve program, along with their raycast data
|
||||
* (id, namespace, etc)
|
||||
*/
|
||||
std::vector<Volume*> _volumes;
|
||||
std::map<VolumeRaycaster*, RaycastData> _raycastData;
|
||||
std::map<VolumeRaycaster*, std::unique_ptr<ghoul::opengl::ProgramObject>> _boundsPrograms;
|
||||
std::vector<std::string> _helperPaths;
|
||||
|
||||
GLuint _screenQuad;
|
||||
GLuint _anchorPointerTexture;
|
||||
GLuint _anchorPointerTextureInitializer;
|
||||
GLuint _atomicCounterBuffer;
|
||||
GLuint _fragmentBuffer;
|
||||
GLuint _fragmentTexture;
|
||||
GLuint _vertexPositionBuffer;
|
||||
int _nAaSamples;
|
||||
ghoul::Dictionary _resolveDictionary;
|
||||
|
||||
GLuint _screenQuad;
|
||||
GLuint _anchorPointerTexture;
|
||||
GLuint _anchorPointerTextureInitializer;
|
||||
GLuint _atomicCounterBuffer;
|
||||
GLuint _fragmentBuffer;
|
||||
GLuint _fragmentTexture;
|
||||
GLuint _vertexPositionBuffer;
|
||||
int _nAaSamples;
|
||||
|
||||
ghoul::Dictionary _rendererData;
|
||||
}; // ABufferRenderer
|
||||
|
||||
@@ -32,8 +32,9 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <openspace/rendering/volume.h>
|
||||
#include <openspace/rendering/raycasterlistener.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace ghoul {
|
||||
class Dictionary;
|
||||
@@ -53,13 +54,16 @@ class RenderableVolume;
|
||||
class Camera;
|
||||
class Scene;
|
||||
|
||||
class FramebufferRenderer : public Renderer {
|
||||
class FramebufferRenderer : public Renderer, public RaycasterListener {
|
||||
public:
|
||||
FramebufferRenderer();
|
||||
virtual ~FramebufferRenderer();
|
||||
|
||||
void initialize() override;
|
||||
void deinitialize() override;
|
||||
|
||||
void updateResolution();
|
||||
void updateRaycastData();
|
||||
|
||||
void setCamera(Camera* camera) override;
|
||||
void setScene(Scene* scene) override;
|
||||
@@ -73,11 +77,34 @@ public:
|
||||
* Responsible for calling renderEngine::setRenderData
|
||||
*/
|
||||
virtual void updateRendererData() override;
|
||||
|
||||
virtual void raycastersChanged(VolumeRaycaster* entity, bool attached) override;
|
||||
private:
|
||||
|
||||
std::map<VolumeRaycaster*, RaycastData> _raycastData;
|
||||
std::map<VolumeRaycaster*, std::unique_ptr<ghoul::opengl::ProgramObject>> _exitPrograms;
|
||||
std::map<VolumeRaycaster*, std::unique_ptr<ghoul::opengl::ProgramObject>> _raycastPrograms;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _resolveProgram;
|
||||
|
||||
GLuint _screenQuad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
GLuint _mainColorTexture;
|
||||
GLuint _mainDepthTexture;
|
||||
GLuint _exitColorTexture;
|
||||
GLuint _mainFramebuffer;
|
||||
GLuint _exitDepthTexture;
|
||||
GLuint _exitFramebuffer;
|
||||
|
||||
bool _dirtyRaycastData;
|
||||
bool _dirtyResolution;
|
||||
|
||||
Camera* _camera;
|
||||
Scene* _scene;
|
||||
glm::vec2 _resolution;
|
||||
glm::vec2 _resolution;
|
||||
int _nAaSamples;
|
||||
|
||||
ghoul::Dictionary _rendererData;
|
||||
}; // FramebufferRenderer
|
||||
} // openspace
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RAYCASTERLISTENER_H__
|
||||
#define __RAYCASTERLISTENER_H__
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class VolumeRaycaster;
|
||||
|
||||
class RaycasterListener {
|
||||
public:
|
||||
virtual void raycastersChanged(VolumeRaycaster* raycaster, bool attached) = 0;
|
||||
}; // RaycasterListener
|
||||
|
||||
} // openspace
|
||||
|
||||
#endif // __RAYCASTERLISTENER_H__
|
||||
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RAYCASTERMANAGER_H__
|
||||
#define __RAYCASTERMANAGER_H__
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class VolumeRaycaster;
|
||||
class RaycasterListener;
|
||||
|
||||
class RaycasterManager {
|
||||
public:
|
||||
RaycasterManager();
|
||||
~RaycasterManager();
|
||||
void attachRaycaster(VolumeRaycaster* raycaster);
|
||||
void detachRaycaster(VolumeRaycaster* raycaster);
|
||||
bool isAttached(VolumeRaycaster* raycaster);
|
||||
const std::vector<VolumeRaycaster*>& raycasters();
|
||||
|
||||
void addListener(RaycasterListener* listener);
|
||||
void removeListener(RaycasterListener* listener);
|
||||
private:
|
||||
std::vector<VolumeRaycaster*> _raycasters;
|
||||
std::vector<RaycasterListener*> _listeners;
|
||||
}; // Volume
|
||||
|
||||
} // openspace
|
||||
|
||||
#endif // __RAYCASTERMANAGER_H__
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
@@ -29,7 +30,6 @@
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/util/powerscaledscalar.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/rendering/volume.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
@@ -45,8 +45,7 @@ namespace ghoul {
|
||||
namespace openspace {
|
||||
|
||||
// Forward declare to minimize dependencies
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
|
||||
class Camera;
|
||||
class PowerScaledCoordinate;
|
||||
|
||||
@@ -67,9 +66,9 @@ public:
|
||||
void setBoundingSphere(const PowerScaledScalar& boundingSphere);
|
||||
const PowerScaledScalar& getBoundingSphere();
|
||||
|
||||
virtual void render(const RenderData& data) = 0;
|
||||
virtual void render(const RenderData& data);
|
||||
virtual void render(const RenderData& data, RendererTasks& rendererTask);
|
||||
virtual void update(const UpdateData& data);
|
||||
virtual std::vector<Volume*> volumesToRender(const RenderData& data) const;
|
||||
|
||||
bool isVisible() const;
|
||||
|
||||
@@ -80,12 +79,12 @@ public:
|
||||
bool getBody(std::string& body);
|
||||
void setBody(std::string& body);
|
||||
|
||||
protected:
|
||||
void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const PowerScaledCoordinate& position);
|
||||
void onEnabledChange(std::function<void(bool)> callback);
|
||||
|
||||
static void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const PowerScaledCoordinate& position);
|
||||
|
||||
private:
|
||||
properties::BoolProperty _enabled;
|
||||
|
||||
PowerScaledScalar boundingSphere_;
|
||||
std::string _startTime;
|
||||
std::string _endTime;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
|
||||
namespace ghoul {
|
||||
namespace fontrendering {
|
||||
class Font;
|
||||
@@ -48,6 +49,7 @@ class Camera;
|
||||
class SyncBuffer;
|
||||
class Scene;
|
||||
class Renderer;
|
||||
class RaycasterManager;
|
||||
class ScreenLog;
|
||||
|
||||
class RenderEngine {
|
||||
@@ -75,6 +77,7 @@ public:
|
||||
Camera* camera() const;
|
||||
Renderer* renderer() const;
|
||||
RendererImplementation rendererImplementation() const;
|
||||
RaycasterManager& raycasterManager();
|
||||
|
||||
// sgct wrapped functions
|
||||
bool initializeGL();
|
||||
@@ -148,6 +151,8 @@ private:
|
||||
|
||||
Camera* _mainCamera;
|
||||
Scene* _sceneGraph;
|
||||
RaycasterManager* _raycasterManager;
|
||||
|
||||
std::unique_ptr<Renderer> _renderer;
|
||||
RendererImplementation _rendererImplementation;
|
||||
ghoul::Dictionary _rendererData;
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __VOLUMERAYCASTER_H__
|
||||
#define __VOLUMERAYCASTER_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class Texture;
|
||||
class ProgramObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderData;
|
||||
class RaycastData;
|
||||
|
||||
class VolumeRaycaster {
|
||||
public:
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~VolumeRaycaster() {};
|
||||
|
||||
/**
|
||||
* Render the volume's entry points (front face of the bounding geometry)
|
||||
*/
|
||||
virtual void renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject* program) = 0;
|
||||
|
||||
/**
|
||||
* Render the volume's exit points (back face of the bounding geometry)
|
||||
*/
|
||||
virtual void renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject* program) = 0;
|
||||
|
||||
/**
|
||||
* Prepare the volume for the ABuffer's resolve step.
|
||||
* Make sure textures are up to date, bind them to texture units, set program uniforms etc.
|
||||
*/
|
||||
virtual void preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject* program) {};
|
||||
|
||||
/**
|
||||
* Clean up for the volume after the ABuffer's resolve step.
|
||||
* Make sure texture units are deinitialized, etc.
|
||||
*/
|
||||
virtual void postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject* program) {};
|
||||
|
||||
/**
|
||||
* Return a path the file to use as vertex shader
|
||||
*
|
||||
* The shader preprocessor will have acceess to
|
||||
* A #{namespace} variable (unique per helper file)
|
||||
*/
|
||||
virtual std::string getBoundsVsPath() const = 0;
|
||||
|
||||
/*
|
||||
* Return a path to a file with the functions, uniforms and fragment shader in variables
|
||||
* required to generate the fragment color and depth.
|
||||
*
|
||||
* Should define the function:
|
||||
* Fragment getFragment()
|
||||
*
|
||||
* The shader preprocessor will have acceess to
|
||||
* A #{namespace} variable (unique per helper file)
|
||||
*/
|
||||
virtual std::string getBoundsFsPath() const = 0 ;
|
||||
|
||||
/**
|
||||
* Return a path to a file with all the uniforms, functions etc
|
||||
* required to perform ray casting through this volume.
|
||||
*
|
||||
* The header should define the following two functions:
|
||||
* vec4 sample#{id}(vec3 samplePos, vec3 dir, float occludingAlpha, inout float maxStepSize)
|
||||
* (return color of sample)
|
||||
* float stepSize#{id}(vec3 samplePos, vec3 dir)
|
||||
* (return the preferred step size at this sample position)
|
||||
*
|
||||
* The shader preprocessor will have acceess to
|
||||
* An #{id} variable (unique per volume)
|
||||
* A #{namespace} variable (unique per helper file)
|
||||
*/
|
||||
virtual std::string getRaycastPath() const = 0;
|
||||
|
||||
/**
|
||||
* Return a path to a glsl file with helper functions required for the
|
||||
* transformation and raycast steps.
|
||||
* This file will be included once per shader program generated,
|
||||
* regardless of how many volumes say they require the file.
|
||||
* Ideal to avoid redefinitions of helper functions.
|
||||
*
|
||||
* The shader preprocessor will have access to the #{namespace} variable (unique per helper file)
|
||||
* which should be a prefix to all symbols defined by the helper
|
||||
*/
|
||||
virtual std::string getHelperPath() const = 0;
|
||||
|
||||
}; // Raycaster
|
||||
|
||||
} // openspace
|
||||
|
||||
#endif // __VOLUMERAYCASTER_H__
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Volume;
|
||||
class SceneGraphNode;
|
||||
|
||||
// Notifications:
|
||||
@@ -83,12 +82,8 @@ public:
|
||||
/*
|
||||
* Render visible SceneGraphNodes using the provided camera
|
||||
*/
|
||||
void render(const RenderData& data);
|
||||
void render(const RenderData& data, RendererTasks& tasks);
|
||||
|
||||
/*
|
||||
* Return a vector of volumes to render and their acciciated render data
|
||||
*/
|
||||
std::vector<std::pair<Volume*, RenderData>> volumesToRender(const RenderData& data) const;
|
||||
/*
|
||||
* Returns the root SceneGraphNode
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
void update(const UpdateData& data);
|
||||
void evaluate(const Camera* camera, const psc& parentPosition = psc());
|
||||
void render(const RenderData& data);
|
||||
void render(const RenderData& data, RendererTasks& tasks);
|
||||
void updateCamera(Camera* camera) const;
|
||||
|
||||
//void addNode(SceneGraphNode* child);
|
||||
@@ -90,7 +90,6 @@ public:
|
||||
void setRenderable(Renderable* renderable);
|
||||
const Renderable* renderable() const;
|
||||
Renderable* renderable();
|
||||
std::vector<std::pair<Volume*, RenderData>> volumesToRender(const RenderData& data) const;
|
||||
|
||||
// @TODO Remove once the scalegraph is in effect ---abock
|
||||
void setEphemeris(Ephemeris* eph) {
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class VolumeRaycaster;
|
||||
|
||||
struct InitializeData {
|
||||
|
||||
};
|
||||
@@ -47,6 +49,21 @@ struct RenderData {
|
||||
bool doPerformanceMeasurement;
|
||||
};
|
||||
|
||||
struct RaycasterTask {
|
||||
VolumeRaycaster* raycaster;
|
||||
RenderData renderData;
|
||||
};
|
||||
|
||||
struct RendererTasks {
|
||||
std::vector<RaycasterTask> raycasterTasks;
|
||||
};
|
||||
|
||||
struct RaycastData {
|
||||
int id;
|
||||
std::string namespaceName;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // __UPDATESTRUCTURES_H__
|
||||
|
||||
Reference in New Issue
Block a user