Correct implementation of DeviceSource resize

previous commit was bad...
This commit is contained in:
Bruno
2021-05-25 20:20:43 +02:00
parent 0e48cf4505
commit 61fa062794
5 changed files with 29 additions and 11 deletions

View File

@@ -384,13 +384,14 @@ void DeviceSource::setDevice(const std::string &devicename)
pipeline << " ! videoconvert";
dettach();
// resize render buffer
if (renderbuffer_)
renderbuffer_->resize(best.width, best.height);
// open gstreamer
stream_->open( pipeline.str(), best.width, best.height);
stream_->play(true);
// will be ready after init and one frame rendered
ready_ = false;
}

View File

@@ -171,6 +171,31 @@ glm::vec3 FrameBuffer::resolution() const
return glm::vec3(attrib_.viewport.x, attrib_.viewport.y, 0.f);
}
void FrameBuffer::resize(int width, int height)
{
if (framebufferid_) {
if (attrib_.viewport.x != width || attrib_.viewport.y != height)
{
// de-init
glDeleteFramebuffers(1, &framebufferid_);
framebufferid_ = 0;
if (intermediate_framebufferid_)
glDeleteFramebuffers(1, &intermediate_framebufferid_);
intermediate_framebufferid_ = 0;
if (textureid_)
glDeleteTextures(1, &textureid_);
textureid_ = 0;
if (intermediate_textureid_)
glDeleteTextures(1, &intermediate_textureid_);
intermediate_textureid_ = 0;
// change resolution
attrib_.viewport = glm::ivec2(width, height);
}
}
}
void FrameBuffer::begin(bool clear)
{
if (!framebufferid_)

View File

@@ -69,6 +69,7 @@ public:
inline uint width() const { return attrib_.viewport.x; }
inline uint height() const { return attrib_.viewport.y; }
glm::vec3 resolution() const;
void resize(int width, int height);
float aspectRatio() const;
std::string info() const;

View File

@@ -425,14 +425,6 @@ void Source::render()
}
}
void Source::dettach()
{
// replace renderbuffer_
if (renderbuffer_)
delete renderbuffer_;
renderbuffer_ = nullptr;
}
void Source::attach(FrameBuffer *renderbuffer)
{
// invalid argument

View File

@@ -246,7 +246,6 @@ protected:
// NB: rendershader_ is applied at render()
FrameBuffer *renderbuffer_;
void attach(FrameBuffer *renderbuffer);
void dettach() ;
// the rendersurface draws the renderbuffer in the scene
// It is associated to the rendershader for mixing effects