mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-06 07:50:00 +01:00
Implementation of FrameBuffer resolution parameters, and saving in
session file of rendering resolution.
This commit is contained in:
@@ -6,10 +6,27 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
const char* FrameBuffer::aspect_ratio_name[4] = { "4:3", "3:2", "16:10", "16:9" };
|
||||
glm::vec2 FrameBuffer::aspect_ratio_size[4] = { glm::vec2(4.f,3.f), glm::vec2(3.f,2.f), glm::vec2(16.f,10.f), glm::vec2(16.f,9.f) };
|
||||
const char* FrameBuffer::resolution_name[4] = { "720p", "1080p", "1440", "4K" };
|
||||
float FrameBuffer::resolution_height[4] = { 720.f, 1080.f, 1440.f, 2160.f };
|
||||
|
||||
FrameBuffer::FrameBuffer(ResolutionAspectRatio aspect_ratio, ResolutionHeight height): textureid_(0), framebufferid_(0), usedepth_(false)
|
||||
{
|
||||
float width = aspect_ratio_size[aspect_ratio].x * resolution_height[height] / aspect_ratio_size[aspect_ratio].y;
|
||||
attrib_.viewport = glm::ivec2( int(width), resolution_height[height] );
|
||||
attrib_.clear_color = glm::vec4(0.f);
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(glm::vec3 resolution): textureid_(0), framebufferid_(0), usedepth_(false)
|
||||
{
|
||||
attrib_.viewport = glm::ivec2(resolution);
|
||||
attrib_.clear_color = glm::vec4(0.f);
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(uint width, uint height, bool useDepthBuffer): textureid_(0), framebufferid_(0), usedepth_(useDepthBuffer)
|
||||
{
|
||||
attrib_.viewport.x = width;
|
||||
attrib_.viewport.y = height;
|
||||
attrib_.viewport = glm::ivec2(width, height);
|
||||
attrib_.clear_color = glm::vec4(0.f);
|
||||
}
|
||||
|
||||
@@ -68,6 +85,12 @@ float FrameBuffer::aspectRatio() const
|
||||
return static_cast<float>(width()) / static_cast<float>(height());
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 FrameBuffer::resolution() const
|
||||
{
|
||||
return glm::vec3(attrib_.viewport.x, attrib_.viewport.y, 0.f);
|
||||
}
|
||||
|
||||
void FrameBuffer::bind()
|
||||
{
|
||||
if (!framebufferid_)
|
||||
@@ -97,7 +120,6 @@ void FrameBuffer::release()
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
|
||||
bool FrameBuffer::blit(FrameBuffer *other)
|
||||
{
|
||||
if (!framebufferid_)
|
||||
|
||||
@@ -7,6 +7,29 @@
|
||||
class FrameBuffer {
|
||||
|
||||
public:
|
||||
// size descriptions
|
||||
static const char* aspect_ratio_name[4];
|
||||
static glm::vec2 aspect_ratio_size[4];
|
||||
static const char* resolution_name[4];
|
||||
static float resolution_height[4];
|
||||
|
||||
typedef enum {
|
||||
AR_4_3 = 0,
|
||||
AR_3_2,
|
||||
AR_16_10,
|
||||
AR_16_9
|
||||
} ResolutionAspectRatio;
|
||||
|
||||
typedef enum {
|
||||
RES_720 = 0,
|
||||
RES_1080,
|
||||
RES_1440,
|
||||
RES_2160
|
||||
} ResolutionHeight;
|
||||
|
||||
|
||||
FrameBuffer(ResolutionAspectRatio aspect_ratio = AR_16_9, ResolutionHeight height = RES_720);
|
||||
FrameBuffer(glm::vec3 resolution);
|
||||
FrameBuffer(uint width, uint height, bool useDepthBuffer = false);
|
||||
~FrameBuffer();
|
||||
|
||||
@@ -29,7 +52,9 @@ public:
|
||||
// width & height
|
||||
inline uint width() const { return attrib_.viewport.x; }
|
||||
inline uint height() const { return attrib_.viewport.y; }
|
||||
glm::vec3 resolution() const;
|
||||
float aspectRatio() const;
|
||||
|
||||
// texture index for draw
|
||||
uint texture() const;
|
||||
|
||||
|
||||
@@ -88,6 +88,10 @@ static void saveSession(const std::string& filename, Session *session)
|
||||
XMLElement *geometry = xmlDoc.NewElement( "Geometry" );
|
||||
geometry->InsertEndChild( SessionVisitor::NodeToXML(*session->config(View::GEOMETRY), &xmlDoc));
|
||||
views->InsertEndChild(geometry);
|
||||
|
||||
XMLElement *render = xmlDoc.NewElement( "Rendering" );
|
||||
render->InsertEndChild( SessionVisitor::NodeToXML(*session->config(View::RENDERING), &xmlDoc));
|
||||
views->InsertEndChild(render);
|
||||
}
|
||||
|
||||
// save file to disk
|
||||
@@ -401,6 +405,9 @@ void Mixer::swap()
|
||||
mixing_.scene.root()->copyTransform( session_->config(View::MIXING) );
|
||||
geometry_.scene.root()->copyTransform( session_->config(View::GEOMETRY) );
|
||||
|
||||
// set resolution
|
||||
session_->setResolution( session_->config(View::RENDERING)->scale_ );
|
||||
|
||||
// no current source
|
||||
current_source_ = session_->end();
|
||||
current_source_index_ = -1;
|
||||
|
||||
3
Scene.h
3
Scene.h
@@ -93,7 +93,6 @@ public:
|
||||
*/
|
||||
class Primitive : public Node {
|
||||
|
||||
|
||||
public:
|
||||
Primitive(Shader *s = nullptr) : Node(), shader_(s), vao_(0), drawMode_(0), drawCount_(0) {}
|
||||
virtual ~Primitive();
|
||||
@@ -157,8 +156,6 @@ private:
|
||||
*/
|
||||
class Group : public Node {
|
||||
|
||||
friend class Scene;
|
||||
|
||||
public:
|
||||
Group() : Node() {}
|
||||
virtual ~Group();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
Session::Session()
|
||||
{
|
||||
config_[View::RENDERING] = new Group;
|
||||
config_[View::RENDERING]->scale_ = render_.resolution();
|
||||
config_[View::GEOMETRY] = new Group;
|
||||
config_[View::MIXING] = new Group;
|
||||
}
|
||||
@@ -71,6 +72,12 @@ SourceList::iterator Session::deleteSource(Source *s)
|
||||
}
|
||||
|
||||
|
||||
void Session::setResolution(glm::vec3 resolution)
|
||||
{
|
||||
render_.setResolution(resolution);
|
||||
config_[View::RENDERING]->scale_ = resolution;
|
||||
}
|
||||
|
||||
SourceList::iterator Session::begin()
|
||||
{
|
||||
return sources_.begin();
|
||||
@@ -128,3 +135,4 @@ int Session::index(SourceList::iterator it) const
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
Session.h
25
Session.h
@@ -12,28 +12,29 @@ public:
|
||||
~Session();
|
||||
|
||||
// add or remove sources
|
||||
SourceList::iterator addSource(Source *s);
|
||||
SourceList::iterator deleteSource(Source *s);
|
||||
SourceList::iterator addSource (Source *s);
|
||||
SourceList::iterator deleteSource (Source *s);
|
||||
|
||||
// management of list of sources
|
||||
SourceList::iterator begin();
|
||||
SourceList::iterator end();
|
||||
SourceList::iterator find(int index);
|
||||
SourceList::iterator find(Source *s);
|
||||
SourceList::iterator find(std::string name);
|
||||
SourceList::iterator find(Node *node);
|
||||
SourceList::iterator begin ();
|
||||
SourceList::iterator end ();
|
||||
SourceList::iterator find (int index);
|
||||
SourceList::iterator find (Source *s);
|
||||
SourceList::iterator find (std::string name);
|
||||
SourceList::iterator find (Node *node);
|
||||
|
||||
uint numSource() const;
|
||||
int index(SourceList::iterator it) const;
|
||||
int index (SourceList::iterator it) const;
|
||||
|
||||
// update all sources
|
||||
void update(float dt);
|
||||
void update (float dt);
|
||||
|
||||
// result of render
|
||||
inline FrameBuffer *frame() const { return render_.frameBuffer(); }
|
||||
inline FrameBuffer *frame () const { return render_.frameBuffer(); }
|
||||
void setResolution(glm::vec3 resolution);
|
||||
|
||||
// configuration for group nodes of views
|
||||
inline Group *config(View::Mode m) const { return config_.at(m); }
|
||||
inline Group *config (View::Mode m) const { return config_.at(m); }
|
||||
|
||||
protected:
|
||||
RenderView render_;
|
||||
|
||||
@@ -85,13 +85,17 @@ void SessionCreator::loadConfig(XMLElement *viewsNode)
|
||||
// ok, ready to read views
|
||||
SessionCreator::XMLToNode( viewsNode->FirstChildElement("Mixing"), *session_->config(View::MIXING));
|
||||
SessionCreator::XMLToNode( viewsNode->FirstChildElement("Geometry"), *session_->config(View::GEOMETRY));
|
||||
SessionCreator::XMLToNode( viewsNode->FirstChildElement("Rendering"), *session_->config(View::RENDERING));
|
||||
}
|
||||
}
|
||||
|
||||
void SessionCreator::XMLToNode(tinyxml2::XMLElement *xml, Node &n)
|
||||
{
|
||||
if (xml != nullptr){
|
||||
XMLElement *node = xml->FirstChildElement("Node");
|
||||
if (node) {
|
||||
if ( !node || std::string(node->Name()).find("Node") == std::string::npos )
|
||||
return;
|
||||
|
||||
XMLElement *scaleNode = node->FirstChildElement("scale");
|
||||
tinyxml2::XMLElementToGLM( scaleNode->FirstChildElement("vec3"), n.scale_);
|
||||
XMLElement *translationNode = node->FirstChildElement("translation");
|
||||
|
||||
@@ -14,7 +14,6 @@ using namespace tinyxml2;
|
||||
Settings::Application Settings::application;
|
||||
static string settingsFilename = "";
|
||||
|
||||
|
||||
void Settings::Save()
|
||||
{
|
||||
XMLDocument xmlDoc;
|
||||
|
||||
@@ -1154,6 +1154,13 @@ void Navigator::RenderMainPannel()
|
||||
ImGuiToolkit::ButtonSwitch( ICON_FA_TACHOMETER_ALT " Metrics", &Settings::application.stats);
|
||||
ImGuiToolkit::ButtonSwitch( ICON_FA_LIST " Logs", &Settings::application.logs, "Ctrl + L");
|
||||
|
||||
// ImGui::Text(" ");
|
||||
// ImGui::Text("Rendering");
|
||||
// ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
||||
// if ( ImGui::Combo("Aspect ratio", &Settings::application.output.resolution, Settings::resolution_name, IM_ARRAYSIZE(Settings::resolution_name) ) ){
|
||||
// Settings::application.output.update();
|
||||
// }
|
||||
|
||||
ImGui::Text(" ");
|
||||
ImGui::Text("Appearance");
|
||||
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
||||
|
||||
24
View.cpp
24
View.cpp
@@ -182,21 +182,20 @@ uint MixingView::textureMixingQuadratic()
|
||||
RenderView::RenderView() : View(RENDERING), frame_buffer_(nullptr)
|
||||
{
|
||||
// application default
|
||||
glm::vec3 resolution(1280.f, 720.f, 0.f);
|
||||
glm::vec3 default_resolution(1280.f, 720.f, 0.f);
|
||||
|
||||
// read default settings
|
||||
if ( Settings::application.views[View::RENDERING].name.empty() ) {
|
||||
// no settings found: store application default
|
||||
Settings::application.views[View::RENDERING].name = "Render";
|
||||
// store default setting
|
||||
Settings::application.views[View::RENDERING].default_scale = resolution;
|
||||
Settings::application.views[View::RENDERING].default_scale = default_resolution;
|
||||
}
|
||||
else
|
||||
resolution = Settings::application.views[View::RENDERING].default_scale;
|
||||
default_resolution = Settings::application.views[View::RENDERING].default_scale;
|
||||
|
||||
// set resolution to settings or default
|
||||
setResolution( int(resolution.x), int(resolution.y));
|
||||
|
||||
setResolution( default_resolution );
|
||||
}
|
||||
|
||||
RenderView::~RenderView()
|
||||
@@ -206,14 +205,25 @@ RenderView::~RenderView()
|
||||
}
|
||||
|
||||
|
||||
void RenderView::setResolution(uint width, uint height)
|
||||
void RenderView::setResolution(glm::vec3 resolution)
|
||||
{
|
||||
if (resolution.x < 100.f || resolution.y < 100)
|
||||
resolution = Settings::application.views[View::RENDERING].default_scale;
|
||||
|
||||
if (frame_buffer_)
|
||||
delete frame_buffer_;
|
||||
|
||||
frame_buffer_ = new FrameBuffer(width, height);
|
||||
frame_buffer_ = new FrameBuffer(resolution);
|
||||
}
|
||||
|
||||
//void RenderView::setResolution(glm::vec3 resolution)
|
||||
//{
|
||||
// if (frame_buffer_)
|
||||
// delete frame_buffer_;
|
||||
|
||||
// frame_buffer_ = new FrameBuffer(resolution);
|
||||
//}
|
||||
|
||||
void RenderView::draw()
|
||||
{
|
||||
static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, SCENE_DEPTH, 0.f);
|
||||
|
||||
7
View.h
7
View.h
@@ -4,7 +4,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "Scene.h"
|
||||
class FrameBuffer;
|
||||
#include "FrameBuffer.h"
|
||||
class Source;
|
||||
|
||||
class View
|
||||
@@ -57,7 +57,10 @@ public:
|
||||
|
||||
void draw () override;
|
||||
|
||||
void setResolution (uint width, uint height);
|
||||
void setResolution (FrameBuffer::ResolutionAspectRatio aspect_ratio, FrameBuffer::ResolutionHeight height) {}
|
||||
void setResolution (glm::vec3 resolution);
|
||||
glm::vec3 resolution() const { return frame_buffer_->resolution(); }
|
||||
|
||||
inline FrameBuffer *frameBuffer () const { return frame_buffer_; }
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user