mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 14:29:42 -05:00
solve merge conflict
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 186 KiB |
+1
-1
Submodule ext/ghoul updated: 849cc67bdc...f31ddda5d7
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
|
||||
namespace ghoul {
|
||||
@@ -51,6 +52,7 @@ class Scene;
|
||||
class Renderer;
|
||||
class RaycasterManager;
|
||||
class ScreenLog;
|
||||
class ScreenSpaceRenderable;
|
||||
|
||||
class RenderEngine {
|
||||
public:
|
||||
@@ -100,6 +102,10 @@ public:
|
||||
|
||||
void setDisableRenderingOnMaster(bool enabled);
|
||||
|
||||
void registerScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRenderable> s);
|
||||
void unregisterScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRenderable> s);
|
||||
std::shared_ptr<ScreenSpaceRenderable> screenSpaceRenderable(std::string name);
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> buildRenderProgram(
|
||||
std::string name,
|
||||
std::string vsPath,
|
||||
@@ -135,6 +141,7 @@ public:
|
||||
// Temporary fade functionality
|
||||
void startFading(int direction, float fadeDuration);
|
||||
|
||||
void sortScreenspaceRenderables();
|
||||
// This is temporary until a proper screenspace solution is found ---abock
|
||||
struct {
|
||||
glm::vec2 _position;
|
||||
@@ -142,6 +149,7 @@ public:
|
||||
int _node;
|
||||
} _onScreenInformation;
|
||||
|
||||
std::shared_ptr<ScreenSpaceRenderable> ssr;
|
||||
private:
|
||||
void setRenderer(std::unique_ptr<Renderer> renderer);
|
||||
RendererImplementation rendererFromString(const std::string& method);
|
||||
@@ -171,6 +179,7 @@ private:
|
||||
int _fadeDirection;
|
||||
|
||||
std::vector<ghoul::opengl::ProgramObject*> _programs;
|
||||
std::vector<std::shared_ptr<ScreenSpaceRenderable>> _screenSpaceRenderables;
|
||||
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _fontInfo = nullptr;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _fontDate = nullptr;
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __SCREENSPACERENDERABLE_H__
|
||||
#define __SCREENSPACERENDERABLE_H__
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <modules/onscreengui/include/gui.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <openspace/util/camera.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
namespace openspace {
|
||||
/**
|
||||
* @brief The base class for screen scape images and screen space framebuffers
|
||||
* @details This base class handles general functionality specific to planes that
|
||||
* are rendered infront of the camera. It implements protected methods and properties for converting
|
||||
* the planes from spherical to euclidean coordinates and back. It also specifies the interface
|
||||
* that it's children needs to implement.
|
||||
*/
|
||||
class ScreenSpaceRenderable : public properties::PropertyOwner {
|
||||
public:
|
||||
ScreenSpaceRenderable();
|
||||
~ScreenSpaceRenderable();
|
||||
|
||||
virtual void render() = 0;
|
||||
virtual bool initialize() = 0;
|
||||
virtual bool deinitialize() = 0;
|
||||
virtual void update() = 0;
|
||||
virtual bool isReady() const = 0;
|
||||
bool isEnabled() const;
|
||||
|
||||
glm::vec2 euclideanPosition() const {return _euclideanPosition.value();};
|
||||
glm::vec2 sphericalPosition() const {return _sphericalPosition.value();};
|
||||
float depth() const {return _depth.value();};
|
||||
|
||||
protected:
|
||||
void createPlane();
|
||||
void useEuclideanCoordinates(bool b);
|
||||
|
||||
/**
|
||||
* @brief Converts vec2 polar coordinates to euclidean
|
||||
*
|
||||
* @param polar the coordinates theta and phi
|
||||
* @param radius the radius position value of the plane
|
||||
*
|
||||
* @return glm::vec2 with the x and y position value of the plane
|
||||
*/
|
||||
glm::vec2 toEuclidean(glm::vec2 polar, float radius);
|
||||
|
||||
/**
|
||||
* @brief Converts vec2 euclidean coordinates to sperical
|
||||
*
|
||||
* @param euclidean the coordinates x and y
|
||||
* @return glm::vec2 with the spherical coordinates theta and phi.
|
||||
*/
|
||||
glm::vec2 toSpherical(glm::vec2 euclidean);
|
||||
void registerProperties();
|
||||
void createShaders();
|
||||
glm::mat4 scaleMatrix();
|
||||
glm::mat4 rotationMatrix();
|
||||
glm::mat4 translationMatrix();
|
||||
void draw(glm::mat4 modelTransform);
|
||||
|
||||
properties::BoolProperty _enabled;
|
||||
properties::BoolProperty _useFlatScreen;
|
||||
properties::Vec2Property _euclideanPosition;
|
||||
properties::Vec2Property _sphericalPosition;
|
||||
properties::FloatProperty _depth;
|
||||
properties::FloatProperty _scale;
|
||||
properties::FloatProperty _alpha;
|
||||
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
const std::string _rendererPath;
|
||||
ghoul::Dictionary _rendererData;
|
||||
const std::string _vertexPath;
|
||||
const std::string _fragmentPath;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
|
||||
bool _useEuclideanCoordinates;
|
||||
const float _planeDepth = -2.0;
|
||||
glm::vec2 _originalViewportSize;
|
||||
|
||||
float _radius;
|
||||
};
|
||||
} // namespace openspace
|
||||
#endif // __SCREENSPACERENDERABLE_H__
|
||||
@@ -38,6 +38,8 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrail.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimage.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/dynamicephemeris.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/spiceephemeris.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/staticephemeris.h
|
||||
@@ -58,6 +60,8 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrail.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/dynamicephemeris.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/spiceephemeris.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/staticephemeris.cpp
|
||||
@@ -83,6 +87,8 @@ set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/screnspace_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/screnspace_vs.glsl
|
||||
)
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
#include <modules/base/rendering/screenspaceframebuffer.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/onscreengui/include/gui.h>
|
||||
#include <openspace/util/camera.h>
|
||||
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#include <openspace/rendering/abufferrenderer.h>
|
||||
#include <openspace/rendering/framebufferrenderer.h>
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceFramebuffer::ScreenSpaceFramebuffer()
|
||||
:ScreenSpaceRenderable()
|
||||
,_size("size", "Size", glm::vec4(0), glm::vec4(0), glm::vec4(2000))
|
||||
,_framebuffer(nullptr)
|
||||
{
|
||||
_id = id();
|
||||
setName("ScreenSpaceFramebuffer" + std::to_string(_id));
|
||||
registerProperties();
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
addProperty(_size);
|
||||
OsEng.gui()._property.registerProperty(&_size);
|
||||
_size.set(glm::vec4(0, 0, resolution.x,resolution.y));
|
||||
|
||||
}
|
||||
|
||||
ScreenSpaceFramebuffer::~ScreenSpaceFramebuffer(){}
|
||||
|
||||
bool ScreenSpaceFramebuffer::initialize(){
|
||||
_originalViewportSize = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
createPlane();
|
||||
createShaders();
|
||||
|
||||
createFragmentbuffer();
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool ScreenSpaceFramebuffer::deinitialize(){
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
_framebuffer->detachAll();
|
||||
|
||||
removeAllRenderFunctions();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenSpaceFramebuffer::render(){
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
glm::vec4 size = _size.value();
|
||||
|
||||
float xratio = _originalViewportSize.x / (size.z-size.x);
|
||||
float yratio = _originalViewportSize.y / (size.w-size.y);;
|
||||
|
||||
if(!_renderFunctions.empty()){
|
||||
glViewport (-size.x*xratio, -size.y*yratio, _originalViewportSize.x*xratio, _originalViewportSize.y*yratio);
|
||||
GLint defaultFBO = _framebuffer->getActiveObject();
|
||||
_framebuffer->activate();
|
||||
|
||||
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
for(auto renderFunction : _renderFunctions){
|
||||
|
||||
(*renderFunction)();
|
||||
|
||||
}
|
||||
_framebuffer->deactivate();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
|
||||
glViewport (0, 0, resolution.x, resolution.y);
|
||||
|
||||
glm::mat4 rotation = rotationMatrix();
|
||||
glm::mat4 translation = translationMatrix();
|
||||
glm::mat4 scale = scaleMatrix();
|
||||
scale = glm::scale(scale, glm::vec3((1.0/xratio), -(1.0/yratio), 1.0f));
|
||||
glm::mat4 modelTransform = rotation*translation*scale;
|
||||
draw(modelTransform);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSpaceFramebuffer::update(){}
|
||||
|
||||
bool ScreenSpaceFramebuffer::isReady() const{
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if(!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
}
|
||||
|
||||
int ScreenSpaceFramebuffer::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
}
|
||||
|
||||
void ScreenSpaceFramebuffer::createFragmentbuffer(){
|
||||
_framebuffer = std::make_unique<ghoul::opengl::FramebufferObject>();
|
||||
_framebuffer->activate();
|
||||
_texture = std::make_unique<ghoul::opengl::Texture>(glm::uvec3(_originalViewportSize.x, _originalViewportSize.y, 1));
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
_framebuffer->attachTexture(_texture.get(), GL_COLOR_ATTACHMENT0);
|
||||
_framebuffer->deactivate();
|
||||
|
||||
// GLuint depthrenderbuffer;
|
||||
// glGenRenderbuffers(1, &depthrenderbuffer);
|
||||
// glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
|
||||
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, _originalViewportSize.x, _originalViewportSize.y);
|
||||
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
|
||||
|
||||
// GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
||||
// glDrawBuffers(1, DrawBuffers);
|
||||
}
|
||||
|
||||
void ScreenSpaceFramebuffer::setSize(glm::vec4 size){
|
||||
_size.set(size);
|
||||
}
|
||||
|
||||
void ScreenSpaceFramebuffer::addRenderFunction(std::shared_ptr<std::function<void()>> renderFunction){
|
||||
_renderFunctions.push_back(renderFunction);
|
||||
}
|
||||
|
||||
void ScreenSpaceFramebuffer::removeAllRenderFunctions(){
|
||||
_renderFunctions.clear();
|
||||
}
|
||||
} //namespace openspace
|
||||
@@ -0,0 +1,67 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __SCREENSPACEFRAMEBUFFER_H__
|
||||
#define __SCREENSPACEFRAMEBUFFER_H__
|
||||
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <modules/base/rendering/screenspaceimage.h>
|
||||
|
||||
namespace openspace {
|
||||
/**
|
||||
* @brief Creates a texture by rendering to a framebuffer, this is then used on a screen space plane.
|
||||
* @details This class lets you ass renderfunctions that should render to a framebuffer with an attached texture.
|
||||
* The texture is then used on a screen space plane that works both in fisheye and flat screens.
|
||||
*/
|
||||
class ScreenSpaceFramebuffer : public ScreenSpaceRenderable {
|
||||
public:
|
||||
ScreenSpaceFramebuffer();
|
||||
~ScreenSpaceFramebuffer();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
void render() override;
|
||||
void update() override;
|
||||
bool isReady() const override;
|
||||
|
||||
void setSize(glm::vec4);
|
||||
void addRenderFunction(std::shared_ptr<std::function<void()>> renderFunction);
|
||||
void removeAllRenderFunctions();
|
||||
private:
|
||||
void createFragmentbuffer();
|
||||
static int id();
|
||||
|
||||
std::unique_ptr<ghoul::opengl::FramebufferObject> _framebuffer;
|
||||
|
||||
int _id;
|
||||
|
||||
std::vector<std::shared_ptr<std::function<void()>>> _renderFunctions;
|
||||
properties::Vec4Property _size;
|
||||
|
||||
};
|
||||
|
||||
} //namespace openspace
|
||||
#endif //__SCREENSPACEFRAMEBUFFER_H__
|
||||
@@ -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. *
|
||||
****************************************************************************************/
|
||||
#include <modules/base/rendering/screenspaceimage.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ScreenSpaceImage";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceImage::ScreenSpaceImage(std::string texturePath)
|
||||
:ScreenSpaceRenderable()
|
||||
,_texturePath("texturePath", "Texture path", texturePath)
|
||||
|
||||
{
|
||||
_id = id();
|
||||
setName("ScreenSpaceImage" + std::to_string(_id));
|
||||
|
||||
addProperty(_texturePath);
|
||||
registerProperties();
|
||||
OsEng.gui()._property.registerProperty(&_texturePath);
|
||||
|
||||
_texturePath.onChange([this](){ loadTexture(); });
|
||||
}
|
||||
|
||||
ScreenSpaceImage::~ScreenSpaceImage(){}
|
||||
|
||||
bool ScreenSpaceImage::initialize(){
|
||||
_originalViewportSize = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
createPlane();
|
||||
createShaders();
|
||||
|
||||
loadTexture();
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool ScreenSpaceImage::deinitialize(){
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
|
||||
_texturePath = "";
|
||||
_texture = nullptr;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenSpaceImage::render(){
|
||||
glm::mat4 rotation = rotationMatrix();
|
||||
glm::mat4 translation = translationMatrix();
|
||||
glm::mat4 scale = scaleMatrix();
|
||||
glm::mat4 modelTransform = rotation*translation*scale;
|
||||
|
||||
draw(modelTransform);
|
||||
}
|
||||
|
||||
void ScreenSpaceImage::update(){}
|
||||
|
||||
|
||||
bool ScreenSpaceImage::isReady() const{
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if(!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
}
|
||||
|
||||
void ScreenSpaceImage::loadTexture() {
|
||||
if (_texturePath.value() != "") {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath.value()));
|
||||
if (texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ScreenSpaceImage::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __SCREENSPACEIMAGE_H__
|
||||
#define __SCREENSPACEIMAGE_H__
|
||||
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
/**
|
||||
* @brief Creates a textured plane rendered in screenspace
|
||||
* @details The plane gets the same ratio as the texture. Implements
|
||||
* the interface that ScreenSpaceImage speciefies.
|
||||
*
|
||||
* @param texturePath Path to the image that should be used as texture
|
||||
*/
|
||||
class ScreenSpaceImage : public ScreenSpaceRenderable {
|
||||
|
||||
public:
|
||||
ScreenSpaceImage(std::string texturePath);
|
||||
~ScreenSpaceImage();
|
||||
|
||||
void render() override;
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
void update() override;
|
||||
bool isReady() const override;
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
static int id();
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
int _id;
|
||||
};
|
||||
|
||||
} //namespace openspace
|
||||
#endif //__SCREENSPACEIMAGE_H__
|
||||
@@ -0,0 +1,50 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
//#version __CONTEXT__
|
||||
uniform sampler2D texture1;
|
||||
uniform float OcclusionDepth;
|
||||
uniform float Alpha;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_position;
|
||||
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
|
||||
|
||||
Fragment getFragment(){
|
||||
Fragment frag;
|
||||
|
||||
// power scale coordinates for depth. w value is set to 1.0.
|
||||
float depth = (1.0 + log(abs(OcclusionDepth) + 1/pow(k, 1.0))/log(k)) / 27.0;
|
||||
frag.color = texture(texture1, vs_st);
|
||||
frag.color.a = (frag.color.a != 0.0f) ? Alpha : frag.color.a;
|
||||
if(frag.color.a == 0.0f){
|
||||
discard;
|
||||
}
|
||||
frag.depth = denormalizeFloat(depth);
|
||||
|
||||
return frag;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ModelTransform;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_position;
|
||||
|
||||
void main(){
|
||||
vs_st = in_st;
|
||||
vs_position = ViewProjectionMatrix*ModelTransform*in_position;
|
||||
gl_Position = vec4(vs_position);
|
||||
}
|
||||
@@ -34,6 +34,9 @@
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
#include <openspace/properties/property.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <modules/base/rendering/screenspaceimage.h>
|
||||
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
@@ -129,6 +132,16 @@ namespace {
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
void addScreenSpaceRenderable(std::string texturePath){
|
||||
std::string filepath ="${OPENSPACE_DATA}/"+texturePath;
|
||||
if( ! FileSys.fileExists(filepath)) {
|
||||
LWARNING("Could not find image '" << filepath << "'");
|
||||
return;
|
||||
}
|
||||
OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared<ScreenSpaceImage>(filepath));
|
||||
}
|
||||
|
||||
|
||||
namespace gui {
|
||||
|
||||
GUI::GUI()
|
||||
@@ -392,6 +405,14 @@ void GUI::renderMainWindow() {
|
||||
|
||||
ImGui::Checkbox("Help", &_help._isEnabled);
|
||||
|
||||
static const int bufferSize = 256;
|
||||
static char buffer[bufferSize];
|
||||
ImGui::InputText("", buffer, bufferSize);
|
||||
|
||||
if(ImGui::SmallButton("Add Image")){
|
||||
addScreenSpaceRenderable(std::string(buffer));
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -8,7 +8,7 @@ return {
|
||||
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
|
||||
-- of all entities that will be visible during an instance of OpenSpace
|
||||
-- Scene = "${SCENE}/default_nh.scene",
|
||||
Scene = "${SCENE}/default.scene",
|
||||
Scene = "${SCENE}/default.scene",
|
||||
-- Scene = "${SCENE}/default-modified.scene",
|
||||
-- Scene = "${SCENE}/rosetta.scene",
|
||||
-- Scene = "${SCENE}/dawn.scene",
|
||||
@@ -59,6 +59,7 @@ return {
|
||||
File = "${BASE_PATH}/Properties.txt"
|
||||
},
|
||||
DownloadRequestURL = "http://openspace.itn.liu.se/request.cgi",
|
||||
RenderingMethod = "ABuffer"
|
||||
--RenderingMethod = "ABuffer" -- alternative: "Framebuffer"
|
||||
|
||||
}
|
||||
@@ -64,6 +64,7 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/renderable.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/renderengine.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/renderengine_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/screenspacerenderable.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scene/ephemeris.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scene/scene.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scene/scene_lua.inl
|
||||
@@ -134,6 +135,8 @@ set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderable.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderer.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderengine.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/volume.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/screenspacerenderable.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/volumeraycaster.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/ephemeris.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/scene.h
|
||||
|
||||
@@ -243,4 +243,4 @@ void OrbitalMouseController::update(const double& dt){
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
+19
-14
@@ -32,6 +32,7 @@
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <modules/iswa/rendering/iswacygnet.h>
|
||||
#include <modules/iswa/rendering/iswamanager.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
@@ -62,33 +63,37 @@ properties::Property* property(const std::string& uri) {
|
||||
else {
|
||||
// The URI consists of the following form at this stage:
|
||||
// <node name>.{<property owner>.}^(0..n)<property id>
|
||||
|
||||
|
||||
const size_t nodeNameSeparator = uri.find(properties::PropertyOwner::URISeparator);
|
||||
if (nodeNameSeparator == std::string::npos) {
|
||||
LERROR("Malformed URI '" << uri << "': At least one '" << nodeNameSeparator
|
||||
const size_t nameSeparator = uri.find(properties::PropertyOwner::URISeparator);
|
||||
if (nameSeparator == std::string::npos) {
|
||||
LERROR("Malformed URI '" << uri << "': At least one '" << nameSeparator
|
||||
<< "' separator must be present.");
|
||||
return nullptr;
|
||||
}
|
||||
const std::string nodeName = uri.substr(0, nodeNameSeparator);
|
||||
const std::string remainingUri = uri.substr(nodeNameSeparator + 1);
|
||||
const std::string nameUri = uri.substr(0, nameSeparator);
|
||||
const std::string remainingUri = uri.substr(nameSeparator + 1);
|
||||
|
||||
SceneGraphNode* node = sceneGraphNode("iSWA");
|
||||
if(node){
|
||||
std::shared_ptr<ISWACygnet> cygnet = static_cast <ISWAManager*>(node->renderable())->iSWACygnet(nodeName);
|
||||
std::shared_ptr<ISWACygnet> cygnet = static_cast <ISWAManager*>(node->renderable())->iSWACygnet(nameUri);
|
||||
if(cygnet){
|
||||
return cygnet->property(remainingUri);
|
||||
}
|
||||
}
|
||||
|
||||
node = sceneGraphNode(nodeName);
|
||||
if (!node) {
|
||||
LERROR("Node '" << nodeName << "' did not exist");
|
||||
return nullptr;
|
||||
node = sceneGraphNode(nameUri);
|
||||
if (node) {
|
||||
properties::Property* property = node->property(remainingUri);
|
||||
return property;
|
||||
}
|
||||
|
||||
std::shared_ptr<ScreenSpaceRenderable> ssr = OsEng.renderEngine().screenSpaceRenderable(nameUri);
|
||||
if(ssr){
|
||||
properties::Property* property = ssr->property(remainingUri);
|
||||
return property;
|
||||
}
|
||||
|
||||
properties::Property* property = node->property(remainingUri);
|
||||
return property;
|
||||
LERROR("Node, iSWACygnet or ScreenSpaceRenderable' " << nameUri << "' did not exist");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
#include <openspace/rendering/framebufferrenderer.h>
|
||||
#include <openspace/rendering/raycastermanager.h>
|
||||
|
||||
#include <modules/base/rendering/screenspaceimage.h>
|
||||
#include <modules/base/rendering/screenspaceframebuffer.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
@@ -53,6 +56,7 @@
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
@@ -94,6 +98,7 @@ namespace {
|
||||
const std::string RenderFsPath = "${SHADERS}/render.frag";
|
||||
}
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
const std::string RenderEngine::PerformanceMeasurementSharedData =
|
||||
@@ -208,6 +213,18 @@ bool RenderEngine::initialize() {
|
||||
|
||||
ghoul::io::TextureReader::ref().addReader(std::make_shared<ghoul::io::TextureReaderCMAP>());
|
||||
|
||||
//For testing screenspacerenderables
|
||||
|
||||
|
||||
std::shared_ptr<ScreenSpaceFramebuffer> ssfb = std::make_shared<ScreenSpaceFramebuffer>();
|
||||
ssfb->addRenderFunction(std::make_shared<std::function<void()>>([this](){renderInformation();}));
|
||||
ssfb->addRenderFunction(std::make_shared<std::function<void()>>([this](){ssr->render();}));
|
||||
registerScreenSpaceRenderable(ssfb);
|
||||
|
||||
|
||||
ssr = std::make_shared<ScreenSpaceImage>("${OPENSPACE_DATA}/test2.jpg");
|
||||
registerScreenSpaceRenderable(ssr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -367,6 +384,9 @@ void RenderEngine::postSynchronizationPreDraw() {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto screenspacerenderable : _screenSpaceRenderables) {
|
||||
screenspacerenderable->update();
|
||||
}
|
||||
//Allow focus node to update camera (enables camera-following)
|
||||
//FIX LATER: THIS CAUSES MASTER NODE TO BE ONE FRAME AHEAD OF SLAVES
|
||||
//if (const SceneGraphNode* node = OsEng.ref().interactionHandler().focusNode()){
|
||||
@@ -393,6 +413,11 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
|
||||
renderScreenLog();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto screenSpaceRenderable : _screenSpaceRenderables) {
|
||||
if(screenSpaceRenderable->isEnabled())
|
||||
screenSpaceRenderable->render();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::postDraw() {
|
||||
@@ -1114,6 +1139,33 @@ void RenderEngine::setDisableRenderingOnMaster(bool enabled) {
|
||||
_disableMasterRendering = enabled;
|
||||
}
|
||||
|
||||
void RenderEngine::registerScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRenderable> s){
|
||||
s->initialize();
|
||||
_screenSpaceRenderables.push_back(s);
|
||||
}
|
||||
|
||||
void RenderEngine::unregisterScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRenderable> s){
|
||||
auto it = std::find(
|
||||
_screenSpaceRenderables.begin(),
|
||||
_screenSpaceRenderables.end(),
|
||||
s
|
||||
);
|
||||
|
||||
if (it != _screenSpaceRenderables.end()) {
|
||||
s->deinitialize();
|
||||
_screenSpaceRenderables.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ScreenSpaceRenderable> RenderEngine::screenSpaceRenderable(std::string name){
|
||||
for(auto s : _screenSpaceRenderables){
|
||||
if(s->name() == name){
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RenderEngine::RendererImplementation RenderEngine::rendererFromString(const std::string& impl) {
|
||||
const std::map<std::string, RenderEngine::RendererImplementation> RenderingMethods = {
|
||||
{ "ABuffer", RendererImplementation::ABuffer },
|
||||
@@ -1428,4 +1480,11 @@ void RenderEngine::renderScreenLog() {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::sortScreenspaceRenderables(){
|
||||
std::sort(_screenSpaceRenderables.begin(), _screenSpaceRenderables.end(),
|
||||
[](std::shared_ptr<ScreenSpaceRenderable> j, std::shared_ptr<ScreenSpaceRenderable> i){
|
||||
return i->depth() > j->depth();
|
||||
});
|
||||
}
|
||||
|
||||
}// namespace openspace
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceRenderable::ScreenSpaceRenderable()
|
||||
: _enabled("enabled", "Is Enabled", true)
|
||||
, _useFlatScreen("flatScreen", "Flat Screen", false)
|
||||
, _euclideanPosition("euclideanPosition", "Euclidean coordinates", glm::vec2(0),glm::vec2(-4),glm::vec2(4))
|
||||
, _sphericalPosition("sphericalPosition", "Spherical coordinates", glm::vec2(0),glm::vec2(-M_PI),glm::vec2(M_PI))
|
||||
, _depth("depth", "Depth", 0, 0, 1)
|
||||
, _scale("scale", "Scale" , 0.5, 0, 2)
|
||||
, _alpha("alpha", "Alpha" , 1, 0, 1)
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
,_rendererPath("${SHADERS}/framebuffer/renderframebuffer.frag")
|
||||
,_vertexPath("${MODULE_BASE}/shaders/screnspace_vs.glsl")
|
||||
,_fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl")
|
||||
,_texture(nullptr)
|
||||
,_shader(nullptr)
|
||||
{
|
||||
addProperty(_enabled);
|
||||
addProperty(_useFlatScreen);
|
||||
addProperty(_euclideanPosition);
|
||||
addProperty(_sphericalPosition);
|
||||
addProperty(_depth);
|
||||
addProperty(_scale);
|
||||
addProperty(_alpha);
|
||||
|
||||
_rendererData = ghoul::Dictionary();
|
||||
_rendererData.setValue("fragmentRendererPath", _rendererPath);
|
||||
_rendererData.setValue("windowWidth", OsEng.windowWrapper().currentWindowResolution().x);
|
||||
_rendererData.setValue("windowHeight", OsEng.windowWrapper().currentWindowResolution().y);
|
||||
|
||||
_useEuclideanCoordinates = _useFlatScreen.value();
|
||||
_radius = _planeDepth;
|
||||
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
|
||||
}
|
||||
|
||||
ScreenSpaceRenderable::~ScreenSpaceRenderable(){}
|
||||
|
||||
|
||||
bool ScreenSpaceRenderable::isEnabled() const {
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::createPlane() {
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
// x y z w s t
|
||||
-1, -1, 0.0f, 1, 0, 1,
|
||||
1, 1, 0.0f, 1, 1, 0,
|
||||
-1, 1, 0.0f, 1, 0, 0,
|
||||
-1, -1, 0.0f, 1, 0, 1,
|
||||
1, -1, 0.0f, 1, 1, 1,
|
||||
1, 1, 0.0f, 1, 1, 0,
|
||||
};
|
||||
|
||||
glBindVertexArray(_quad); // bind array
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::useEuclideanCoordinates(bool b){
|
||||
_useEuclideanCoordinates = b;
|
||||
if(_useEuclideanCoordinates){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
_sphericalPosition.onChange([this](){});
|
||||
} else {
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
_sphericalPosition.onChange([this](){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
});
|
||||
_euclideanPosition.onChange([this](){});
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 ScreenSpaceRenderable::toEuclidean(glm::vec2 polar, float r){
|
||||
float x = r*sin(polar[0])*sin(polar[1]);
|
||||
float y = r*cos(polar[1]);
|
||||
|
||||
return glm::vec2(x, y);
|
||||
}
|
||||
|
||||
glm::vec2 ScreenSpaceRenderable::toSpherical(glm::vec2 euclidean){
|
||||
_radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(_planeDepth,2));
|
||||
float theta = atan2(-_planeDepth,euclidean[0])-M_PI/2.0;
|
||||
float phi = acos(euclidean[1]/_radius);
|
||||
|
||||
return glm::vec2(theta, phi);
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::registerProperties(){
|
||||
OsEng.gui()._property.registerProperty(&_enabled);
|
||||
OsEng.gui()._property.registerProperty(&_useFlatScreen);
|
||||
OsEng.gui()._property.registerProperty(&_euclideanPosition);
|
||||
OsEng.gui()._property.registerProperty(&_sphericalPosition);
|
||||
OsEng.gui()._property.registerProperty(&_depth);
|
||||
OsEng.gui()._property.registerProperty(&_scale);
|
||||
OsEng.gui()._property.registerProperty(&_alpha);
|
||||
|
||||
if(_useEuclideanCoordinates){
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
_sphericalPosition.onChange([this](){});
|
||||
}else{
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::createShaders(){
|
||||
if(_shader == nullptr) {
|
||||
|
||||
ghoul::Dictionary dict = ghoul::Dictionary();
|
||||
|
||||
dict.setValue("rendererData", _rendererData);
|
||||
dict.setValue("fragmentPath", _fragmentPath);
|
||||
_shader = ghoul::opengl::ProgramObject::Build("ScreenSpaceProgram",
|
||||
_vertexPath,
|
||||
"${SHADERS}/render.frag",
|
||||
dict
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::scaleMatrix(){
|
||||
glm::mat4 scale(1.0);
|
||||
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
//to scale the plane
|
||||
float textureRatio = (float(_texture->height())/float(_texture->width()));
|
||||
float scalingRatioX = _originalViewportSize[0]/ resolution[0];
|
||||
float scalingRatioY = _originalViewportSize[1]/ resolution[1];
|
||||
scale = glm::scale(scale, glm::vec3(_scale.value() * scalingRatioX,
|
||||
_scale.value() * scalingRatioY * textureRatio,
|
||||
1));
|
||||
return scale;
|
||||
}
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::rotationMatrix(){
|
||||
glm::mat4 rotation(1.0);
|
||||
if(!_useEuclideanCoordinates){
|
||||
glm::vec2 position = _sphericalPosition.value();
|
||||
|
||||
float theta = position.x;
|
||||
float phi = position.y - M_PI/2.0;
|
||||
|
||||
rotation = glm::rotate(rotation, position.x, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation = glm::rotate(rotation, (float) (position.y - M_PI/2.0) , glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
return rotation;
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::translationMatrix(){
|
||||
glm::mat4 translation(1.0);
|
||||
if(!_useEuclideanCoordinates){
|
||||
translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, _planeDepth));
|
||||
}else{
|
||||
|
||||
translation = glm::translate(glm::mat4(1.f), glm::vec3(_euclideanPosition.value(), _planeDepth));
|
||||
}
|
||||
|
||||
return translation;
|
||||
}
|
||||
|
||||
|
||||
void ScreenSpaceRenderable::draw(glm::mat4 modelTransform){
|
||||
float occlusionDepth = 1-_depth.value();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
_shader->activate();
|
||||
_shader->setUniform("OcclusionDepth", occlusionDepth);
|
||||
_shader->setUniform("Alpha", _alpha);
|
||||
_shader->setUniform("ModelTransform",modelTransform);
|
||||
_shader->setUniform("ViewProjectionMatrix", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
_shader->deactivate();
|
||||
}
|
||||
}// namespace openspace
|
||||
@@ -30,11 +30,14 @@
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
// test files
|
||||
#include <test_common.inl>
|
||||
//#include <test_spicemanager.inl>
|
||||
#include <test_scenegraphloader.inl>
|
||||
//#include <test_luaconversions.inl>
|
||||
//#include <test_powerscalecoordinates.inl>
|
||||
#include <test_screenspaceimage.inl>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
#define private public
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// make private variables public, only for testing!!
|
||||
#include <modules/base/rendering/screenspaceimage.h>
|
||||
|
||||
/*
|
||||
* For each test the following is run:
|
||||
* Constructor() -> setUp() -> test -> tearDown() -> Deconstructor()
|
||||
*/
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ScreenSpaceRenderableTest : public testing::Test{
|
||||
protected:
|
||||
|
||||
ScreenSpaceRenderableTest() :
|
||||
_ssr(texturePath)
|
||||
{
|
||||
_sharedSsr = std::make_shared<ScreenSpaceImage>("${OPENSPACE_DATA}/test3.jpg");
|
||||
}
|
||||
|
||||
~ScreenSpaceRenderableTest(){}
|
||||
|
||||
|
||||
void reset() {}
|
||||
|
||||
// These variables are shared by all tests
|
||||
std::string texturePath = "${OPENSPACE_DATA}/test2.jpg";
|
||||
ScreenSpaceImage _ssr;
|
||||
std::shared_ptr<ScreenSpaceRenderable> _sharedSsr;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(ScreenSpaceRenderableTest, initialize){
|
||||
bool isReady = _ssr.isReady();
|
||||
ASSERT_TRUE(!isReady) << "ScreenSpaceImage is ready before initialize";
|
||||
|
||||
// cannot test initialize, crashes at createplane becasue of opengl functions. needs mocking
|
||||
//_ssr.initialize();
|
||||
//isReady = _ssr.isReady();
|
||||
//ASSERT_TRUE(!isReady) << "ScreenSpaceImage is not ready after initialize";
|
||||
//_ssr.deinitialize();
|
||||
//isReady = _ssr.isReady();
|
||||
//ASSERT_TRUE(!isReady) << "ScreenSpaceImage is still ready after deinitialize";
|
||||
}
|
||||
}//namespace openspace
|
||||
Reference in New Issue
Block a user