BugFix FrameBuffer alpha (disabled for SessionSource and RenderSource)

and bugfix RenderPreview UV coordinates.
This commit is contained in:
brunoherbelin
2020-05-22 23:08:09 +02:00
parent 9f4cb4dce3
commit ecbca0b5e6
8 changed files with 29 additions and 19 deletions

View File

@@ -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

View File

@@ -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_;
}; };

View File

@@ -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

View File

@@ -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 ),

View File

@@ -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_);

View File

@@ -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_);

View File

@@ -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();
} }

View File

@@ -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);