upgraded to ocio v2
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "openglrenderer.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFloat16>
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -44,16 +45,6 @@ const QVector<GLfloat> blit_texcoords = {
|
||||
1.0f, 1.0f
|
||||
};
|
||||
|
||||
const QVector<GLfloat> flipped_blit_texcoords = {
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
|
||||
0.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f
|
||||
};
|
||||
|
||||
OpenGLRenderer::OpenGLRenderer(QObject* parent) :
|
||||
Renderer(parent),
|
||||
context_(nullptr)
|
||||
@@ -110,33 +101,11 @@ void OpenGLRenderer::PostInit()
|
||||
|
||||
// Set up framebuffer used for various things
|
||||
functions_->glGenFramebuffers(1, &framebuffer_);
|
||||
|
||||
// Set up vertex array object
|
||||
vao_.create();
|
||||
|
||||
// Set up vertex buffer
|
||||
vert_vbo_.create();
|
||||
vert_vbo_.bind();
|
||||
vert_vbo_.allocate(blit_vertices.constData(), blit_vertices.size() * sizeof(GLfloat));
|
||||
vert_vbo_.release();
|
||||
|
||||
// Set up fragment buffer
|
||||
frag_vbo_.create();
|
||||
frag_vbo_.bind();
|
||||
frag_vbo_.allocate(blit_texcoords.constData(), blit_texcoords.size() * sizeof(GLfloat));
|
||||
frag_vbo_.release();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::Destroy()
|
||||
{
|
||||
if (context_) {
|
||||
// Delete buffers
|
||||
vert_vbo_.destroy();
|
||||
frag_vbo_.destroy();
|
||||
|
||||
// Delete vertex array object
|
||||
vao_.destroy();
|
||||
|
||||
// Delete framebuffer
|
||||
functions_->glDeleteFramebuffers(1, &framebuffer_);
|
||||
|
||||
@@ -181,12 +150,19 @@ QVariant OpenGLRenderer::CreateNativeTexture(VideoParams p, void *data, int line
|
||||
|
||||
functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize);
|
||||
|
||||
GLint current_tex;
|
||||
functions_->glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex);
|
||||
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
functions_->glTexImage2D(GL_TEXTURE_2D, 0, GetInternalFormat(p.format()),
|
||||
p.width(), p.height(), 0, GL_RGBA,
|
||||
p.effective_width(), p.effective_height(), 0, GL_RGBA,
|
||||
GetPixelType(p.format()), data);
|
||||
|
||||
functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, current_tex);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -215,8 +191,6 @@ QVariant OpenGLRenderer::CreateNativeShader(ShaderCode code)
|
||||
goto error;
|
||||
}
|
||||
|
||||
qDebug() << "Shader created successfully";
|
||||
|
||||
return Node::PtrToValue(program);
|
||||
|
||||
error:
|
||||
@@ -254,13 +228,12 @@ void OpenGLRenderer::UploadToTexture(Texture *texture, void *data, int linesize)
|
||||
|
||||
void OpenGLRenderer::DownloadFromTexture(Texture* texture, void *data, int linesize)
|
||||
{
|
||||
GLuint t = texture->id().value<GLuint>();
|
||||
const VideoParams& p = texture->params();
|
||||
|
||||
GLint current_tex;
|
||||
functions_->glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex);
|
||||
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, t);
|
||||
AttachTextureAsDestination(texture);
|
||||
|
||||
functions_->glPixelStorei(GL_PACK_ROW_LENGTH, linesize);
|
||||
|
||||
@@ -274,6 +247,8 @@ void OpenGLRenderer::DownloadFromTexture(Texture* texture, void *data, int lines
|
||||
|
||||
functions_->glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
|
||||
DetachTextureAsDestination();
|
||||
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, current_tex);
|
||||
}
|
||||
|
||||
@@ -315,23 +290,6 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Renderer::Texture *destinat
|
||||
shader->setUniformValue(variable_location, value.data.toFloat());
|
||||
break;
|
||||
case NodeInput::kVec2:
|
||||
/*if (corresponding_input && corresponding_input->IsArray()) {
|
||||
QVector<NodeValue> nv = value.value< QVector<NodeValue> >();
|
||||
QVector<QVector2D> a(nv.size());
|
||||
|
||||
for (int j=0;j<a.size();j++) {
|
||||
a[j] = nv.at(j).data().value<QVector2D>();
|
||||
}
|
||||
|
||||
shader->setUniformValueArray(variable_location, a.constData(), a.size());
|
||||
|
||||
int count_location = shader->uniformLocation(QStringLiteral("%1_count").arg(it.key()));
|
||||
if (count_location > -1) {
|
||||
shader->setUniformValue(count_location, a.size());
|
||||
}
|
||||
} else {
|
||||
|
||||
}*/
|
||||
shader->setUniformValue(variable_location, value.data.value<QVector2D>());
|
||||
break;
|
||||
case NodeInput::kVec3:
|
||||
@@ -349,8 +307,8 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Renderer::Texture *destinat
|
||||
case NodeInput::kColor:
|
||||
{
|
||||
Color color = value.data.value<Color>();
|
||||
|
||||
shader->setUniformValue(variable_location, color.red(), color.green(), color.blue(), color.alpha());
|
||||
shader->setUniformValue(variable_location,
|
||||
color.red(), color.green(), color.blue(), color.alpha());
|
||||
break;
|
||||
}
|
||||
case NodeInput::kBoolean:
|
||||
@@ -423,14 +381,6 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Renderer::Texture *destinat
|
||||
}
|
||||
}
|
||||
|
||||
// Set ove_resolution to the destination to the "logical" resolution of the destination
|
||||
shader->setUniformValue("ove_resolution",
|
||||
static_cast<GLfloat>(destination_params.width()),
|
||||
static_cast<GLfloat>(destination_params.height()));
|
||||
|
||||
// Set the viewport to the "physical" resolution of the destination
|
||||
functions_->glViewport(0, 0, destination_params.effective_width(), destination_params.effective_height());
|
||||
|
||||
// Bind all textures
|
||||
for (int i=0; i<textures_to_bind.size(); i++) {
|
||||
functions_->glActiveTexture(GL_TEXTURE0 + i);
|
||||
@@ -438,10 +388,37 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Renderer::Texture *destinat
|
||||
PrepareInputTexture(job.GetBilinearFiltering());
|
||||
}
|
||||
|
||||
// Set ove_resolution to the destination to the "logical" resolution of the destination
|
||||
shader->setUniformValue("ove_resolution",
|
||||
static_cast<GLfloat>(destination_params.width()),
|
||||
static_cast<GLfloat>(destination_params.height()));
|
||||
|
||||
// Set matrix to identity
|
||||
shader->setUniformValue("ove_mvpmat", job.GetMatrix());
|
||||
|
||||
// Set the viewport to the "physical" resolution of the destination
|
||||
functions_->glViewport(0, 0,
|
||||
destination_params.effective_width(),
|
||||
destination_params.effective_height());
|
||||
|
||||
// Bind vertex array object
|
||||
QOpenGLVertexArrayObject vao_;
|
||||
vao_.create();
|
||||
vao_.bind();
|
||||
|
||||
// Set buffers
|
||||
QOpenGLBuffer vert_vbo_;
|
||||
vert_vbo_.create();
|
||||
vert_vbo_.bind();
|
||||
vert_vbo_.allocate(blit_vertices.constData(), blit_vertices.size() * sizeof(GLfloat));
|
||||
vert_vbo_.release();
|
||||
|
||||
QOpenGLBuffer frag_vbo_;
|
||||
frag_vbo_.create();
|
||||
frag_vbo_.bind();
|
||||
frag_vbo_.allocate(blit_texcoords.constData(), blit_texcoords.size() * sizeof(GLfloat));
|
||||
frag_vbo_.release();
|
||||
|
||||
int vertex_location = shader->attributeLocation("a_position");
|
||||
vert_vbo_.bind();
|
||||
functions_->glEnableVertexAttribArray(vertex_location);
|
||||
@@ -493,21 +470,21 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Renderer::Texture *destinat
|
||||
DetachTextureAsDestination();
|
||||
}
|
||||
} else {
|
||||
// Always draw to output_tex
|
||||
// Always draw to output_tex, which gets swapped with input_tex every iteration
|
||||
AttachTextureAsDestination(output_tex.get());
|
||||
|
||||
if (iteration > 0) {
|
||||
// If this is not the first iteration, replace the iterative texture with the one we
|
||||
// last drew
|
||||
functions_->glActiveTexture(GL_TEXTURE0 + iterative_input);
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, input_tex->id().value<GLuint>());
|
||||
PrepareInputTexture(job.GetBilinearFiltering());
|
||||
}
|
||||
|
||||
// Swap so that the next iteration, the texture we draw now will be the input texture next
|
||||
std::swap(output_tex, input_tex);
|
||||
}
|
||||
|
||||
if (iteration > 0) {
|
||||
// If this is not the first iteration, replace the iterative texture with the one we
|
||||
// last drew
|
||||
functions_->glActiveTexture(GL_TEXTURE0 + iterative_input);
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, input_tex->id().value<GLuint>());
|
||||
PrepareInputTexture(job.GetBilinearFiltering());
|
||||
}
|
||||
|
||||
// Swap so that the next iteration, the texture we draw now will be the input texture next
|
||||
std::swap(output_tex, input_tex);
|
||||
|
||||
// Blit this texture through this shader
|
||||
functions_->glDrawArrays(GL_TRIANGLES, 0, blit_vertices.size() / 3);
|
||||
}
|
||||
@@ -526,41 +503,16 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Renderer::Texture *destinat
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
// Release vertex array object
|
||||
vao_.release();
|
||||
|
||||
// Release shader
|
||||
shader->release();
|
||||
|
||||
// Release vertex array object
|
||||
frag_vbo_.destroy();
|
||||
vert_vbo_.destroy();
|
||||
vao_.release();
|
||||
vao_.destroy();
|
||||
}
|
||||
|
||||
/*void OpenGLRenderer::Blit(Renderer::Texture *source, QVariant shader, Renderer::ShaderUniformMap parameters, Renderer::Texture *destination)
|
||||
{
|
||||
QOpenGLShaderProgram* program = Node::ValueToPtr<QOpenGLShaderProgram>(shader);
|
||||
|
||||
if (!program) {
|
||||
qCritical() << "Attempted to blit with a null shader";
|
||||
return;
|
||||
}
|
||||
|
||||
if (destination) {
|
||||
AttachTextureAsDestination(destination);
|
||||
}
|
||||
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, source->id().value<GLuint>());
|
||||
|
||||
program->bind();
|
||||
|
||||
qCritical() << "OpenGLRenderer::Blit is a stub!";
|
||||
|
||||
program->release();
|
||||
|
||||
functions_->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
if (destination) {
|
||||
DetachTextureAsDestination();
|
||||
}
|
||||
}*/
|
||||
|
||||
GLint OpenGLRenderer::GetInternalFormat(PixelFormat::Format format)
|
||||
{
|
||||
switch (format) {
|
||||
|
||||
@@ -86,12 +86,6 @@ private:
|
||||
|
||||
QOffscreenSurface surface_;
|
||||
|
||||
QOpenGLVertexArrayObject vao_;
|
||||
|
||||
QOpenGLBuffer vert_vbo_;
|
||||
|
||||
QOpenGLBuffer frag_vbo_;
|
||||
|
||||
GLuint framebuffer_;
|
||||
|
||||
};
|
||||
|
||||
@@ -20,11 +20,9 @@
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
#include <OpenColorIO/OpenColorIO.h>
|
||||
namespace OCIO = OCIO_NAMESPACE::v1;
|
||||
|
||||
#include <QFloat16>
|
||||
|
||||
#include "common/ocioutils.h"
|
||||
#include "render/colormanager.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
@@ -54,83 +52,62 @@ const int OCIO_LUT3D_ENTRY_COUNT = 3 * OCIO_LUT3D_PIXEL_COUNT;
|
||||
const int OCIO_LUT3D_ENTRY_COUNT_WITH_ALPHA = 4 * OCIO_LUT3D_PIXEL_COUNT;
|
||||
const int OCIO_LUT2D_EDGE_SIZE = 512;*/
|
||||
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture *destination)
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture *destination, bool flipped)
|
||||
{
|
||||
qDebug() << "BlitColorManaged is a partial stub";
|
||||
|
||||
QVariant shader = CreateNativeShader(ShaderCode(FileFunctions::ReadFileAsString(":/shaders/default.frag"), FileFunctions::ReadFileAsString(":/shaders/default.vert")));
|
||||
|
||||
ShaderJob job;
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), ShaderValue(QVariant::fromValue(source), NodeParam::kTexture));
|
||||
|
||||
if (flipped) {
|
||||
QMatrix4x4 mat;
|
||||
mat.scale(1, -1, 1);
|
||||
job.SetMatrix(mat);
|
||||
}
|
||||
|
||||
BlitToTexture(shader, job, destination);
|
||||
|
||||
DestroyNativeShader(shader);
|
||||
}
|
||||
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params, bool flipped)
|
||||
{
|
||||
qDebug() << "BlitColorManaged is a partial stub";
|
||||
|
||||
/*ColorContext color_ctx;
|
||||
|
||||
if (color_cache_.contains(color_processor->id())) {
|
||||
color_ctx = color_cache_.value(color_processor->id());
|
||||
} else {
|
||||
// Generate OCIO color context
|
||||
|
||||
// Generate OCIO shader descriptor
|
||||
// Create shader description
|
||||
const char* ocio_func_name = "OCIODisplay";
|
||||
OCIO::GpuShaderDesc shader_desc;
|
||||
shader_desc.setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_0);
|
||||
shader_desc.setFunctionName(ocio_func_name);
|
||||
shader_desc.setLut3DEdgeLen(OCIO_LUT3D_EDGE_SIZE);
|
||||
OCIO::GpuShaderDescRcPtr shader_desc = OCIO::GpuShaderDesc::CreateShaderDesc();
|
||||
shader_desc->setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_2);
|
||||
shader_desc->setFunctionName(ocio_func_name);
|
||||
shader_desc->setResourcePrefix("ocio_");
|
||||
|
||||
// Generate LUT
|
||||
QVector<float> lut_data(OCIO_LUT3D_ENTRY_COUNT);
|
||||
color_processor->GetProcessor()->getGpuLut3D(lut_data.data(), shader_desc);
|
||||
// Generate shader
|
||||
color_processor->GetProcessor()->getDefaultGPUProcessor()->extractGpuShaderInfo(shader_desc);
|
||||
|
||||
// Convert to half float RGBA
|
||||
QVector<qfloat16> texture_ready_lut_data(OCIO_LUT3D_ENTRY_COUNT_WITH_ALPHA);
|
||||
for (int i=0; i<OCIO_LUT3D_PIXEL_COUNT; i++) {
|
||||
texture_ready_lut_data[i*kRGBAChannels+0] = lut_data[i*kRGBChannels+0];
|
||||
texture_ready_lut_data[i*kRGBAChannels+1] = lut_data[i*kRGBChannels+1];
|
||||
texture_ready_lut_data[i*kRGBAChannels+2] = lut_data[i*kRGBChannels+2];
|
||||
texture_ready_lut_data[i*kRGBAChannels+3] = 1.0f;
|
||||
}
|
||||
|
||||
// Create LUT texture
|
||||
color_ctx.lut = CreateTexture(VideoParams(OCIO_LUT2D_EDGE_SIZE, OCIO_LUT2D_EDGE_SIZE, PixelFormat::PIX_FMT_RGBA32F),
|
||||
texture_ready_lut_data.data());
|
||||
|
||||
// Create shader
|
||||
QString frag_code;
|
||||
|
||||
frag_code.append(QStringLiteral("sampler2D texture;\n"
|
||||
"sampler2D lut;\n"
|
||||
"\n"
|
||||
"vec3 LUTLookup(sampler2D lut3d, vec3 in_coord)\n"
|
||||
"{\n"
|
||||
" return texture2D(lut3d, vec2());\n"
|
||||
"}\n"
|
||||
"\n"));
|
||||
|
||||
// Correct code for our GLSL set up
|
||||
QString ocio_code = color_processor->GetProcessor()->getGpuShaderText(shader_desc);
|
||||
ocio_code.replace(QStringLiteral("texture3D"), QStringLiteral("texture2D"));
|
||||
ocio_code.replace(QStringLiteral("sampler3D"), QStringLiteral("sampler2D"));
|
||||
|
||||
|
||||
|
||||
qDebug() << frag_code;
|
||||
|
||||
//qDebug() << "FIXME: GPU doesn't handle associated alpha yet";
|
||||
qDebug() << "Shader:" << shader_desc->getShaderText();
|
||||
}*/
|
||||
|
||||
qDebug() << "BlitColorManaged is a partial stub";
|
||||
|
||||
QVariant shader = CreateNativeShader(ShaderCode(FileFunctions::ReadFileAsString(":/shaders/default.frag"), FileFunctions::ReadFileAsString(":/shaders/default.vert")));
|
||||
|
||||
ShaderJob job;
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), ShaderValue(QVariant::fromValue(source), NodeParam::kTexture));
|
||||
|
||||
BlitToTexture(shader, job, destination);
|
||||
}
|
||||
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params)
|
||||
{
|
||||
qDebug() << "BlitColorManaged is a partial stub";
|
||||
|
||||
QVariant shader = CreateNativeShader(ShaderCode(FileFunctions::ReadFileAsString(":/shaders/default.frag"), FileFunctions::ReadFileAsString(":/shaders/default.vert")));
|
||||
|
||||
ShaderJob job;
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), ShaderValue(QVariant::fromValue(source), NodeParam::kTexture));
|
||||
if (flipped) {
|
||||
QMatrix4x4 mat;
|
||||
mat.scale(1, -1, 1);
|
||||
job.SetMatrix(mat);
|
||||
}
|
||||
|
||||
Blit(shader, job, params);
|
||||
|
||||
DestroyNativeShader(shader);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -135,8 +135,8 @@ public:
|
||||
Blit(shader, job, nullptr, params);
|
||||
}
|
||||
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture* destination);
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params);
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture* destination, bool flipped = false);
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params, bool flipped = false);
|
||||
|
||||
public slots:
|
||||
virtual void PostInit() = 0;
|
||||
|
||||
Reference in New Issue
Block a user