mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Merge with feature/screenspacerenderable
This commit is contained in:
@@ -148,8 +148,7 @@ public:
|
||||
unsigned int _size;
|
||||
int _node;
|
||||
} _onScreenInformation;
|
||||
|
||||
std::shared_ptr<ScreenSpaceRenderable> ssr;
|
||||
|
||||
private:
|
||||
void setRenderer(std::unique_ptr<Renderer> renderer);
|
||||
RendererImplementation rendererFromString(const std::string& method);
|
||||
|
||||
@@ -102,7 +102,6 @@ protected:
|
||||
properties::FloatProperty _scale;
|
||||
properties::FloatProperty _alpha;
|
||||
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
const std::string _rendererPath;
|
||||
|
||||
@@ -40,12 +40,13 @@ ScreenSpaceFramebuffer::ScreenSpaceFramebuffer()
|
||||
_id = id();
|
||||
setName("ScreenSpaceFramebuffer" + std::to_string(_id));
|
||||
registerProperties();
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
addProperty(_size);
|
||||
OsEng.gui()._property.registerProperty(&_size);
|
||||
_size.set(glm::vec4(0, 0, resolution.x,resolution.y));
|
||||
|
||||
_scale.setValue(1.0f);
|
||||
}
|
||||
|
||||
ScreenSpaceFramebuffer::~ScreenSpaceFramebuffer(){}
|
||||
@@ -55,14 +56,8 @@ bool ScreenSpaceFramebuffer::initialize(){
|
||||
|
||||
createPlane();
|
||||
createShaders();
|
||||
|
||||
createFragmentbuffer();
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
@@ -82,7 +77,6 @@ bool ScreenSpaceFramebuffer::deinitialize(){
|
||||
}
|
||||
|
||||
_framebuffer->detachAll();
|
||||
|
||||
removeAllRenderFunctions();
|
||||
|
||||
return true;
|
||||
@@ -104,14 +98,11 @@ void ScreenSpaceFramebuffer::render(){
|
||||
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();
|
||||
@@ -134,29 +125,6 @@ bool ScreenSpaceFramebuffer::isReady() const{
|
||||
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);
|
||||
@@ -169,4 +137,19 @@ void ScreenSpaceFramebuffer::addRenderFunction(std::shared_ptr<std::function<voi
|
||||
void ScreenSpaceFramebuffer::removeAllRenderFunctions(){
|
||||
_renderFunctions.clear();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
int ScreenSpaceFramebuffer::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
}
|
||||
} //namespace openspace
|
||||
@@ -50,17 +50,17 @@ public:
|
||||
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;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::FramebufferObject> _framebuffer;
|
||||
std::vector<std::shared_ptr<std::function<void()>>> _renderFunctions;
|
||||
|
||||
int _id;
|
||||
};
|
||||
|
||||
} //namespace openspace
|
||||
|
||||
@@ -31,17 +31,17 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceImage::ScreenSpaceImage(std::string texturePath)
|
||||
:ScreenSpaceRenderable()
|
||||
,_texturePath("texturePath", "Texture path", texturePath)
|
||||
:ScreenSpaceRenderable()
|
||||
,_texturePath("texturePath", "Texture path", texturePath)
|
||||
|
||||
{
|
||||
_id = id();
|
||||
setName("ScreenSpaceImage" + std::to_string(_id));
|
||||
|
||||
addProperty(_texturePath);
|
||||
registerProperties();
|
||||
OsEng.gui()._property.registerProperty(&_texturePath);
|
||||
|
||||
|
||||
addProperty(_texturePath);
|
||||
OsEng.gui()._property.registerProperty(&_texturePath);
|
||||
_texturePath.onChange([this](){ loadTexture(); });
|
||||
}
|
||||
|
||||
@@ -52,13 +52,8 @@ bool ScreenSpaceImage::initialize(){
|
||||
|
||||
createPlane();
|
||||
createShaders();
|
||||
|
||||
loadTexture();
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
return isReady();
|
||||
}
|
||||
|
||||
@@ -69,7 +64,6 @@ bool ScreenSpaceImage::deinitialize(){
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
|
||||
_texturePath = "";
|
||||
_texture = nullptr;
|
||||
|
||||
@@ -119,7 +113,7 @@ void ScreenSpaceImage::loadTexture() {
|
||||
}
|
||||
|
||||
int ScreenSpaceImage::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
static int id = 0;
|
||||
return id++;
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,9 @@ public:
|
||||
ScreenSpaceImage(std::string texturePath);
|
||||
~ScreenSpaceImage();
|
||||
|
||||
void render() override;
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
void render() override;
|
||||
void update() override;
|
||||
bool isReady() const override;
|
||||
|
||||
|
||||
@@ -213,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,11 +54,22 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
|
||||
_rendererData.setValue("windowWidth", OsEng.windowWrapper().currentWindowResolution().x);
|
||||
_rendererData.setValue("windowHeight", OsEng.windowWrapper().currentWindowResolution().y);
|
||||
|
||||
_useEuclideanCoordinates = _useFlatScreen.value();
|
||||
_radius = _planeDepth;
|
||||
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
|
||||
_sphericalPosition.onChange([this](){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
});
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
}
|
||||
|
||||
ScreenSpaceRenderable::~ScreenSpaceRenderable(){}
|
||||
@@ -97,16 +108,8 @@ 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](){});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,21 +136,10 @@ void ScreenSpaceRenderable::registerProperties(){
|
||||
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) {
|
||||
if(!_shader) {
|
||||
|
||||
ghoul::Dictionary dict = ghoul::Dictionary();
|
||||
|
||||
@@ -197,7 +189,6 @@ glm::mat4 ScreenSpaceRenderable::translationMatrix(){
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user