mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
BugFix FrameBuffer alpha (disabled for SessionSource and RenderSource)
and bugfix RenderPreview UV coordinates.
This commit is contained in:
@@ -20,16 +20,16 @@ glm::vec3 FrameBuffer::getResolutionFromParameters(int ar, int h)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBuffer::FrameBuffer(glm::vec3 resolution): textureid_(0), framebufferid_(0), usedepth_(false)
|
FrameBuffer::FrameBuffer(glm::vec3 resolution, bool useAlpha, bool useDepthBuffer): textureid_(0), framebufferid_(0), usealpha_(useAlpha), usedepth_(useDepthBuffer)
|
||||||
{
|
{
|
||||||
attrib_.viewport = glm::ivec2(resolution);
|
attrib_.viewport = glm::ivec2(resolution);
|
||||||
attrib_.clear_color = glm::vec4(0.f,0.f,0.f,1.f);
|
attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, usealpha_ ? 0.f : 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBuffer::FrameBuffer(uint width, uint height, bool useDepthBuffer): textureid_(0), framebufferid_(0), usedepth_(useDepthBuffer)
|
FrameBuffer::FrameBuffer(uint width, uint height, bool useAlpha, bool useDepthBuffer): textureid_(0), framebufferid_(0), usealpha_(useAlpha), usedepth_(useDepthBuffer)
|
||||||
{
|
{
|
||||||
attrib_.viewport = glm::ivec2(width, height);
|
attrib_.viewport = glm::ivec2(width, height);
|
||||||
attrib_.clear_color = glm::vec4(0.f,0.f,0.f,1.f);
|
attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, usealpha_ ? 0.f : 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBuffer::init()
|
void FrameBuffer::init()
|
||||||
@@ -50,9 +50,16 @@ void FrameBuffer::init()
|
|||||||
// generate texture
|
// generate texture
|
||||||
glGenTextures(1, &textureid_);
|
glGenTextures(1, &textureid_);
|
||||||
glBindTexture(GL_TEXTURE_2D, textureid_);
|
glBindTexture(GL_TEXTURE_2D, textureid_);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, attrib_.viewport.x, attrib_.viewport.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
if (usealpha_)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, attrib_.viewport.x, attrib_.viewport.y,
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
else
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, attrib_.viewport.x, attrib_.viewport.y,
|
||||||
|
0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
// attach the texture to FBO color attachment point
|
// attach the texture to FBO color attachment point
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ public:
|
|||||||
static float resolution_height[4];
|
static float resolution_height[4];
|
||||||
static glm::vec3 getResolutionFromParameters(int ar, int h);
|
static glm::vec3 getResolutionFromParameters(int ar, int h);
|
||||||
|
|
||||||
FrameBuffer(glm::vec3 resolution);
|
FrameBuffer(glm::vec3 resolution, bool useAlpha = false, bool useDepthBuffer = false);
|
||||||
FrameBuffer(uint width, uint height, bool useDepthBuffer = false);
|
FrameBuffer(uint width, uint height, bool useAlpha = false, bool useDepthBuffer = false);
|
||||||
~FrameBuffer();
|
~FrameBuffer();
|
||||||
|
|
||||||
// bind the FrameBuffer as current to draw into
|
// bind the FrameBuffer as current to draw into
|
||||||
@@ -50,7 +50,7 @@ private:
|
|||||||
RenderingAttrib attrib_;
|
RenderingAttrib attrib_;
|
||||||
uint textureid_;
|
uint textureid_;
|
||||||
uint framebufferid_;
|
uint framebufferid_;
|
||||||
bool usedepth_;
|
bool usealpha_, usedepth_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ void MediaSource::init()
|
|||||||
|
|
||||||
// create Frame buffer matching size of media player
|
// create Frame buffer matching size of media player
|
||||||
float height = float(mediaplayer()->width()) / mediaplayer()->aspectRatio();
|
float height = float(mediaplayer()->width()) / mediaplayer()->aspectRatio();
|
||||||
renderbuffer_ = new FrameBuffer(mediaplayer()->width(), (uint)height);
|
renderbuffer_ = new FrameBuffer(mediaplayer()->width(), (uint)height, true);
|
||||||
|
|
||||||
// create the surfaces to draw the frame buffer in the views
|
// create the surfaces to draw the frame buffer in the views
|
||||||
// TODO Provide the source custom effect shader
|
// TODO Provide the source custom effect shader
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ static const std::vector<glm::vec3> square_points {
|
|||||||
|
|
||||||
Surface::Surface(Shader *s) : Primitive(s), textureindex_(0)
|
Surface::Surface(Shader *s) : Primitive(s), textureindex_(0)
|
||||||
{
|
{
|
||||||
// geometry
|
// geometry for a trianglulated simple rectangle surface with UV
|
||||||
|
// (0,0) B +---+ D (1,0)
|
||||||
|
// |\ |
|
||||||
|
// | \ |
|
||||||
|
// | \|
|
||||||
|
// (0,1) A +---+ C (1,1)
|
||||||
|
|
||||||
points_ = std::vector<glm::vec3> { glm::vec3( -1.f, -1.f, 0.f ), glm::vec3( -1.f, 1.f, 0.f ),
|
points_ = std::vector<glm::vec3> { glm::vec3( -1.f, -1.f, 0.f ), glm::vec3( -1.f, 1.f, 0.f ),
|
||||||
glm::vec3( 1.f, -1.f, 0.f ), glm::vec3( 1.f, 1.f, 0.f ) };
|
glm::vec3( 1.f, -1.f, 0.f ), glm::vec3( 1.f, 1.f, 0.f ) };
|
||||||
colors_ = std::vector<glm::vec4> { glm::vec4( 1.f, 1.f, 1.f , 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ),
|
colors_ = std::vector<glm::vec4> { glm::vec4( 1.f, 1.f, 1.f , 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ),
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ void SessionSource::init()
|
|||||||
sessionsurface_->setTextureIndex( session_->frame()->texture() );
|
sessionsurface_->setTextureIndex( session_->frame()->texture() );
|
||||||
|
|
||||||
// create Frame buffer matching size of session
|
// create Frame buffer matching size of session
|
||||||
renderbuffer_ = new FrameBuffer(session_->frame()->resolution());
|
renderbuffer_ = new FrameBuffer( session_->frame()->resolution());
|
||||||
renderbuffer_->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f));
|
|
||||||
|
|
||||||
// create the surfaces to draw the frame buffer in the views
|
// create the surfaces to draw the frame buffer in the views
|
||||||
rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_);
|
rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_);
|
||||||
|
|||||||
@@ -238,8 +238,7 @@ void RenderSource::init()
|
|||||||
sessionsurface_->setTextureIndex( session->frame()->texture() );
|
sessionsurface_->setTextureIndex( session->frame()->texture() );
|
||||||
|
|
||||||
// create Frame buffer matching size of session
|
// create Frame buffer matching size of session
|
||||||
renderbuffer_ = new FrameBuffer( session->frame()->resolution() );
|
renderbuffer_ = new FrameBuffer( session->frame()->resolution());
|
||||||
renderbuffer_->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f));
|
|
||||||
|
|
||||||
// create the surfaces to draw the frame buffer in the views
|
// create the surfaces to draw the frame buffer in the views
|
||||||
rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_);
|
rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_);
|
||||||
|
|||||||
@@ -618,7 +618,7 @@ void UserInterface::RenderPreview()
|
|||||||
float width = ImGui::GetContentRegionAvail().x;
|
float width = ImGui::GetContentRegionAvail().x;
|
||||||
|
|
||||||
ImVec2 imagesize ( width, width / ar);
|
ImVec2 imagesize ( width, width / ar);
|
||||||
ImGui::Image((void*)(intptr_t)output->texture(), imagesize, ImVec2(0.f, 0.f), ImVec2(1.f, -1.f));
|
ImGui::Image((void*)(intptr_t)output->texture(), imagesize, ImVec2(0.f, 1.f), ImVec2(1.f, 0.f));
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
3
View.cpp
3
View.cpp
@@ -202,12 +202,11 @@ void RenderView::setResolution(glm::vec3 resolution)
|
|||||||
delete frame_buffer_;
|
delete frame_buffer_;
|
||||||
|
|
||||||
frame_buffer_ = new FrameBuffer(resolution);
|
frame_buffer_ = new FrameBuffer(resolution);
|
||||||
frame_buffer_->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderView::draw()
|
void RenderView::draw()
|
||||||
{
|
{
|
||||||
static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, -SCENE_DEPTH, 0.f);
|
static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, -SCENE_DEPTH, 1.f);
|
||||||
glm::mat4 P = glm::scale( projection, glm::vec3(1.f / frame_buffer_->aspectRatio(), 1.f, 1.f));
|
glm::mat4 P = glm::scale( projection, glm::vec3(1.f / frame_buffer_->aspectRatio(), 1.f, 1.f));
|
||||||
frame_buffer_->begin();
|
frame_buffer_->begin();
|
||||||
scene.root()->draw(glm::identity<glm::mat4>(), P);
|
scene.root()->draw(glm::identity<glm::mat4>(), P);
|
||||||
|
|||||||
Reference in New Issue
Block a user