diff --git a/frontend/gtkmm/GraphicsView.cc b/frontend/gtkmm/GraphicsView.cc index 5201be6259..e8d6cb9b84 100644 --- a/frontend/gtkmm/GraphicsView.cc +++ b/frontend/gtkmm/GraphicsView.cc @@ -5,10 +5,14 @@ #include #include #include +#include +#include using namespace cadabra; +// LIBGL_ALWAYS_SOFTWARE=true cadabra2-gtk // a=server.send("hello", "graphics_view", 0, 123, False) +// https://github.com/nitronoid/qt_filament/ static constexpr uint8_t RESOURCES_BAKEDCOLOR_DATA[] = { #include "bakedcolor.inc" @@ -31,7 +35,7 @@ GraphicsView::GraphicsView(filament::Engine *engine_) } GraphicsView::GLView::GLView(filament::Engine *engine_) - : engine(engine_) + : engine(engine_), zoom(1.0) { } @@ -96,26 +100,33 @@ void GraphicsView::GLView::first_render() scene = engine->createScene(); view = engine->createView(); + view->setViewport(filament::Viewport(0, 0, 400, 400)); scene->addEntity(renderable); camera = utils::EntityManager::get().create(); cam = engine->createCamera(camera); view->setCamera(cam); view->setScene(scene); - skybox = filament::Skybox::Builder().color({0.1, 0.125, 0.25, 1.0}).build(*engine); +// skybox = filament::Skybox::Builder().color({0.1, 0.125, 0.25, 1.0}).build(*engine); + skybox = filament::Skybox::Builder().color({4.0, 4.0, 4.0, 1.0}).build(*engine); scene->setSkybox(skybox); + filament::PBRNeutralToneMapper tone_mapper; + auto color_grading = filament::ColorGrading::Builder().toneMapper(&tone_mapper).build(*engine); + view->setColorGrading(color_grading); renderer = engine->createRenderer(); + view->setPostProcessingEnabled(true); filament::Renderer::ClearOptions co; co.clear=true; co.discard=true; - co.clearColor=filament::math::float4({1.0,1.0,0.0,0.5}); +// co.clearColor=filament::math::float4({1.0,1.0,0.0,0.5}); + co.clearColor=filament::math::float4({1.0,1.0,1.0,1.0}); renderer->setClearOptions(co); // view->setClearTargets(filament::backend::TargetBufferFlags::COLOR | filament::backend::TargetBufferFlags::DEPTH); } -bool GraphicsView::GLView::on_render(const Glib::RefPtr< Gdk::GLContext > &context) -//bool GraphicsView::GLView::on_draw(const Cairo::RefPtr& context) +//bool GraphicsView::GLView::on_render(const Glib::RefPtr< Gdk::GLContext > &context) +bool GraphicsView::GLView::on_draw(const Cairo::RefPtr& context) { static bool first=true; @@ -128,7 +139,9 @@ bool GraphicsView::GLView::on_render(const Glib::RefPtr< Gdk::GLContext > &conte std::cerr << "first render" << std::endl; first_render(); } - + + setup_camera(); + if(renderer->beginFrame(swapChain) || true /* always render */) { std::cerr << "filament rendering" << std::endl; renderer->render(view); @@ -172,3 +185,33 @@ bool GraphicsView::on_button_release_event(GdkEventButton *event) return true; } + +void GraphicsView::GLView::setup_camera() + { + // Get the width and height of our window, scaled by the pixel ratio + const auto pixel_ratio = 1.0; // FIXME: devicePixelRatio(); + const uint32_t w = static_cast(get_width() * pixel_ratio); + const uint32_t h = static_cast(get_height() * pixel_ratio); + + // Set our view-port size + view->setViewport({0, 0, w, h}); + + // setup view matrix + const filament::math::float3 eye(0.f, 0.f, 1.f); + const filament::math::float3 target(0.f, 0.f, 0.f); + const filament::math::float3 up(0.f, 1.f, 0.f); + cam->lookAt(eye, target, up); + + // setup projection matrix + const float aspect = float(w) / h; + std::cerr << "aspect = " << aspect << ", zoom = " << zoom << std::endl; + cam->setProjection(filament::Camera::Projection::ORTHO, + -aspect * zoom, + aspect * zoom, + -zoom, + zoom, + 0, + 10.0); + } + + diff --git a/frontend/gtkmm/GraphicsView.hh b/frontend/gtkmm/GraphicsView.hh index 904001a26c..4c13014a7a 100644 --- a/frontend/gtkmm/GraphicsView.hh +++ b/frontend/gtkmm/GraphicsView.hh @@ -36,14 +36,17 @@ namespace cadabra { virtual bool on_button_press_event(GdkEventButton *event) override; virtual bool on_button_release_event(GdkEventButton *event) override; - class GLView : public /* Gtk::DrawingArea */ Gtk::GLArea { + class GLView : + public Gtk::DrawingArea { +// public Gtk::GLArea { public: GLView(filament::Engine *); - virtual bool on_render (const Glib::RefPtr< Gdk::GLContext > &context); - //virtual bool on_draw(const Cairo::RefPtr& cr) override; + //virtual bool on_render (const Glib::RefPtr< Gdk::GLContext > &context); + virtual bool on_draw(const Cairo::RefPtr& cr) override; private: void first_render(); + void setup_camera(); // Filament things. The engine is owned by the NotebookWindow and passed // in on creation of GraphicsView. The swapchain, on the other hand, is @@ -62,6 +65,8 @@ namespace cadabra { utils::Entity camera; utils::Entity renderable; filament::Renderer *renderer; + + float zoom; }; private: diff --git a/frontend/gtkmm/NotebookWindow.cc b/frontend/gtkmm/NotebookWindow.cc index 2e3a6895be..5801ef6595 100644 --- a/frontend/gtkmm/NotebookWindow.cc +++ b/frontend/gtkmm/NotebookWindow.cc @@ -766,7 +766,8 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) // filament::Engine::Config engineConfig = {}; // engineConfig.stereoscopicEyeCount = 0; // engineConfig.stereoscopicType = filament::Engine::StereoscopicType::NONE; - filament_engine = filament::Engine::create(filament::Engine::Backend::OPENGL); // VULKAN); +// filament_engine = filament::Engine::create(filament::Engine::Backend::OPENGL); + filament_engine = filament::Engine::create(filament::Engine::Backend::VULKAN); } NotebookWindow::~NotebookWindow()