Remove screenspacerenderables

This commit is contained in:
Sebastian Piwell
2016-04-04 13:49:21 -04:00
parent d610171441
commit 3fbfb9bb33
10 changed files with 89 additions and 13 deletions

View File

@@ -104,6 +104,7 @@ public:
void registerScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRenderable> s);
void unregisterScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRenderable> s);
void unregisterScreenSpaceRenderable(std::string name);
std::shared_ptr<ScreenSpaceRenderable> screenSpaceRenderable(std::string name);
std::unique_ptr<ghoul::opengl::ProgramObject> buildRenderProgram(

View File

@@ -30,6 +30,7 @@
#include <openspace/properties/vectorproperty.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <ghoul/opengl/texture.h>
#include <modules/onscreengui/include/gui.h>
#include <openspace/rendering/renderengine.h>
@@ -88,6 +89,8 @@ protected:
*/
glm::vec2 toSpherical(glm::vec2 euclidean);
void registerProperties();
void unregisterProperties();
void createShaders();
glm::mat4 scaleMatrix();
glm::mat4 rotationMatrix();
@@ -101,6 +104,7 @@ protected:
properties::FloatProperty _depth;
properties::FloatProperty _scale;
properties::FloatProperty _alpha;
properties::TriggerProperty _delete;
GLuint _quad;
GLuint _vertexPositionBuffer;
@@ -115,7 +119,8 @@ protected:
const float _planeDepth = -2.0;
glm::vec2 _originalViewportSize;
float _radius;
float _radius;
bool _toDelete;
};
} // namespace openspace
#endif // __SCREENSPACERENDERABLE_H__

View File

@@ -43,7 +43,7 @@ ScreenSpaceFramebuffer::ScreenSpaceFramebuffer()
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
addProperty(_size);
OsEng.gui()._property.registerProperty(&_size);
OsEng.gui()._screenSpaceProperty.registerProperty(&_size);
_size.set(glm::vec4(0, 0, resolution.x,resolution.y));
_scale.setValue(1.0f);
@@ -62,6 +62,8 @@ bool ScreenSpaceFramebuffer::initialize(){
}
bool ScreenSpaceFramebuffer::deinitialize(){
unregisterProperties();
glDeleteVertexArrays(1, &_quad);
_quad = 0;
@@ -114,7 +116,10 @@ void ScreenSpaceFramebuffer::render(){
}
}
void ScreenSpaceFramebuffer::update(){}
void ScreenSpaceFramebuffer::update(){
if(_toDelete)
OsEng.renderEngine().unregisterScreenSpaceRenderable(name());
}
bool ScreenSpaceFramebuffer::isReady() const{
bool ready = true;

View File

@@ -41,7 +41,7 @@ ScreenSpaceImage::ScreenSpaceImage(std::string texturePath)
registerProperties();
addProperty(_texturePath);
OsEng.gui()._property.registerProperty(&_texturePath);
OsEng.gui()._screenSpaceProperty.registerProperty(&_texturePath);
_texturePath.onChange([this](){ loadTexture(); });
}
@@ -58,6 +58,8 @@ bool ScreenSpaceImage::initialize(){
}
bool ScreenSpaceImage::deinitialize(){
unregisterProperties();
glDeleteVertexArrays(1, &_quad);
_quad = 0;
@@ -85,7 +87,10 @@ void ScreenSpaceImage::render(){
draw(modelTransform);
}
void ScreenSpaceImage::update(){}
void ScreenSpaceImage::update(){
if(_toDelete)
OsEng.renderEngine().unregisterScreenSpaceRenderable(name());
}
bool ScreenSpaceImage::isReady() const{

View File

@@ -71,6 +71,7 @@ public:
GuiOriginComponent _origin;
GuiPerformanceComponent _performance;
GuiPropertyComponent _property;
GuiPropertyComponent _screenSpaceProperty;
GuiTimeComponent _time;
bool _isEnabled;

View File

@@ -44,6 +44,7 @@ class GuiPropertyComponent : public GuiComponent {
public:
//void registerProperty(const std::string& propertyDescription);
void registerProperty(properties::Property* prop);
void unregisterProperties(std::string owner);
void render();
protected:

View File

@@ -203,6 +203,7 @@ void GUI::initialize() {
//io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; // @TODO implement? ---abock
_property.initialize();
_screenSpaceProperty.initialize();
_performance.initialize();
_help.initialize();
}
@@ -249,6 +250,7 @@ void GUI::initializeGL() {
_property.initializeGL();
_screenSpaceProperty.initializeGL();
_performance.initializeGL();
_help.initializeGL();
}
@@ -260,6 +262,7 @@ void GUI::deinitializeGL() {
glDeleteBuffers(1, &vbo);
_property.deinitializeGL();
_screenSpaceProperty.deinitializeGL();
_performance.deinitializeGL();
_help.deinitializeGL();
}
@@ -288,6 +291,8 @@ void GUI::endFrame() {
if (_property.isEnabled())
_property.render();
if (_screenSpaceProperty.isEnabled())
_screenSpaceProperty.render();
if (_performance.isEnabled())
_performance.render();
if (_help.isEnabled())
@@ -387,6 +392,7 @@ void GUI::renderMainWindow() {
ImGui::Begin("OpenSpace GUI", nullptr);
ImGui::Checkbox("Properties", &_property._isEnabled);
ImGui::Checkbox("ScreenSpace Properties", &_screenSpaceProperty._isEnabled);
ImGui::Checkbox("Performance", &_performance._isEnabled);
_origin.render();
_time.render();

View File

@@ -195,7 +195,7 @@ namespace {
std::string name = prop->guiName();
bool pressed = ImGui::Button((ownerName + "." + name).c_str());
if (pressed)
executeScript(prop->fullyQualifiedIdentifier(), "0");
executeScript(prop->fullyQualifiedIdentifier(), "nil");
}
//void renderBoolProperty(Property* prop, const std::string& ownerName) {
@@ -383,6 +383,37 @@ void GuiPropertyComponent::registerProperty(properties::Property* prop) {
//handleProperty(dictionary);
}
void GuiPropertyComponent::unregisterProperties(std::string owner){
auto it = _propertiesByOwner.find(owner);
if(it != _propertiesByOwner.end()){
for(prop : it->second){
std::string className = prop->className();
if (className == "BoolProperty")
_boolProperties.insert(prop);
else if (className == "IntProperty")
_intProperties.insert(prop);
else if (className == "FloatProperty")
_floatProperties.insert(prop);
else if (className == "StringProperty")
_stringProperties.insert(prop);
else if (className == "Vec2Property")
_vec2Properties.insert(prop);
else if (className == "Vec3Property")
_vec3Properties.insert(prop);
else if (className == "Vec4Property")
_vec4Properties.insert(prop);
else if (className == "OptionProperty")
_optionProperties.insert(prop);
else if (className == "TriggerProperty")
_triggerProperties.insert(prop);
else if (className == "SelectionProperty")
_selectionProperties.insert(prop);
}
it->second.clear();
_propertiesByOwner.erase(it);
}
}
void GuiPropertyComponent::handleProperty(const ghoul::Dictionary& dictionary) {
//static const std::string TypeKey = "Type";
//static const std::string IdentifierKey = "Identifier";

View File

@@ -1157,6 +1157,12 @@ void RenderEngine::unregisterScreenSpaceRenderable(std::shared_ptr<ScreenSpaceRe
}
}
void RenderEngine::unregisterScreenSpaceRenderable(std::string name){
auto s = screenSpaceRenderable(name);
if(s)
unregisterScreenSpaceRenderable(s);
}
std::shared_ptr<ScreenSpaceRenderable> RenderEngine::screenSpaceRenderable(std::string name){
for(auto s : _screenSpaceRenderables){
if(s->name() == name){

View File

@@ -33,6 +33,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
, _depth("depth", "Depth", 0, 0, 1)
, _scale("scale", "Scale" , 0.5, 0, 2)
, _alpha("alpha", "Alpha" , 1, 0, 1)
,_delete("delete", "Delete")
, _quad(0)
, _vertexPositionBuffer(0)
,_rendererPath("${SHADERS}/framebuffer/renderframebuffer.frag")
@@ -40,6 +41,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
,_fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl")
,_texture(nullptr)
,_shader(nullptr)
,_toDelete(false)
{
addProperty(_enabled);
addProperty(_useFlatScreen);
@@ -48,6 +50,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
addProperty(_depth);
addProperty(_scale);
addProperty(_alpha);
addProperty(_delete);
_rendererData = ghoul::Dictionary();
_rendererData.setValue("fragmentRendererPath", _rendererPath);
@@ -70,11 +73,18 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
_useFlatScreen.onChange([this](){
useEuclideanCoordinates(_useFlatScreen.value());
});
_delete.onChange([this](){_toDelete=true;});
}
ScreenSpaceRenderable::~ScreenSpaceRenderable(){}
//deinitialzie(){
// unregisterProperies
// }
bool ScreenSpaceRenderable::isEnabled() const {
return _enabled;
}
@@ -129,13 +139,18 @@ glm::vec2 ScreenSpaceRenderable::toSpherical(glm::vec2 euclidean){
}
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);
OsEng.gui()._screenSpaceProperty.registerProperty(&_enabled);
OsEng.gui()._screenSpaceProperty.registerProperty(&_useFlatScreen);
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(&_depth);
OsEng.gui()._screenSpaceProperty.registerProperty(&_scale);
OsEng.gui()._screenSpaceProperty.registerProperty(&_alpha);
OsEng.gui()._screenSpaceProperty.registerProperty(&_delete);
}
void ScreenSpaceRenderable::unregisterProperties(){
OsEng.gui()._screenSpaceProperty.unregisterProperties(name());
}
void ScreenSpaceRenderable::createShaders(){