cleaned up texture and texture reading classes
This commit is contained in:
@@ -64,7 +64,7 @@ FramePtr OpenGLExporter::TextureToFrame(const QVariant& texture)
|
|||||||
|
|
||||||
// Perform OpenGL read
|
// Perform OpenGL read
|
||||||
buffer_.Attach(texture_);
|
buffer_.Attach(texture_);
|
||||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, buffer_.buffer());
|
buffer_.Bind();
|
||||||
|
|
||||||
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(params_.format());
|
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(params_.format());
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ FramePtr OpenGLExporter::TextureToFrame(const QVariant& texture)
|
|||||||
format_info.gl_pixel_type,
|
format_info.gl_pixel_type,
|
||||||
frame->data());
|
frame->data());
|
||||||
|
|
||||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
buffer_.Release();
|
||||||
buffer_.Detach();
|
buffer_.Detach();
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
|
|||||||
@@ -156,39 +156,6 @@ void OpenGLTexture::Upload(const void *data)
|
|||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
uchar *OpenGLTexture::Download() const
|
|
||||||
{
|
|
||||||
if (!IsCreated()) {
|
|
||||||
qWarning() << "OpenGLTexture::Download() called while it wasn't created";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QOpenGLContext* context = QOpenGLContext::currentContext();
|
|
||||||
QOpenGLFunctions* f = context->functions();
|
|
||||||
|
|
||||||
GLuint read_fbo;
|
|
||||||
|
|
||||||
f->glGenFramebuffers(1, &read_fbo);
|
|
||||||
|
|
||||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, read_fbo);
|
|
||||||
|
|
||||||
context->extraFunctions()->glFramebufferTexture2D(
|
|
||||||
GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_, 0
|
|
||||||
);
|
|
||||||
|
|
||||||
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(format_);
|
|
||||||
|
|
||||||
uchar* data = new uchar[PixelService::GetBufferSize(format_, width_, height_)];
|
|
||||||
|
|
||||||
f->glReadPixels(0, 0, width_, height_, format_info.pixel_format, format_info.gl_pixel_type, data);
|
|
||||||
|
|
||||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
|
||||||
|
|
||||||
f->glDeleteFramebuffers(1, &read_fbo);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLTexture::CreateInternal(QOpenGLContext* create_ctx, GLuint* tex, const void *data)
|
void OpenGLTexture::CreateInternal(QOpenGLContext* create_ctx, GLuint* tex, const void *data)
|
||||||
{
|
{
|
||||||
QOpenGLFunctions* f = create_ctx->functions();
|
QOpenGLFunctions* f = create_ctx->functions();
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ public:
|
|||||||
|
|
||||||
void Upload(const void *data);
|
void Upload(const void *data);
|
||||||
|
|
||||||
uchar *Download() const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
|||||||
@@ -121,8 +121,6 @@ void OpenGLWorker::FrameToValue(StreamPtr stream, FramePtr frame, NodeValueTable
|
|||||||
buffer_.Detach();
|
buffer_.Detach();
|
||||||
|
|
||||||
footage_tex_ref = associated_tex_ref;
|
footage_tex_ref = associated_tex_ref;
|
||||||
|
|
||||||
functions_->glFinish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table->Push(NodeParam::kTexture, QVariant::fromValue(footage_tex_ref));
|
table->Push(NodeParam::kTexture, QVariant::fromValue(footage_tex_ref));
|
||||||
@@ -337,7 +335,6 @@ void OpenGLWorker::RunNodeAccelerated(const Node *node, const TimeRange &range,
|
|||||||
|
|
||||||
// Make sure all OpenGL functions are complete by this point before unlocking the shader (or another thread may
|
// Make sure all OpenGL functions are complete by this point before unlocking the shader (or another thread may
|
||||||
// change its parameters before our drawing in this thread is done)
|
// change its parameters before our drawing in this thread is done)
|
||||||
functions_->glFinish();
|
|
||||||
shader->Unlock();
|
shader->Unlock();
|
||||||
|
|
||||||
// Release any textures we bound before
|
// Release any textures we bound before
|
||||||
@@ -362,7 +359,7 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
|
|||||||
|
|
||||||
QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
|
||||||
buffer_.Attach(texture->texture());
|
buffer_.Attach(texture->texture());
|
||||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, buffer_.buffer());
|
buffer_.Bind();
|
||||||
|
|
||||||
f->glReadPixels(0,
|
f->glReadPixels(0,
|
||||||
0,
|
0,
|
||||||
@@ -372,7 +369,7 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
|
|||||||
format_info.gl_pixel_type,
|
format_info.gl_pixel_type,
|
||||||
buffer.data());
|
buffer.data());
|
||||||
|
|
||||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
buffer_.Release();
|
||||||
buffer_.Detach();
|
buffer_.Detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user