implemented opencolorio
This commit is contained in:
@@ -369,19 +369,27 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) {
|
||||
// alpha is not premultiplied, we'll need to multiply it for the rest of the pipeline
|
||||
params.ctx->functions()->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ZERO);
|
||||
|
||||
textureID = draw_clip(c->fbo[0], textureID, true);
|
||||
textureID = draw_clip(c->fbo[fbo_switcher], textureID, true);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
fbo_switcher = true;
|
||||
fbo_switcher = !fbo_switcher;
|
||||
}
|
||||
|
||||
#ifdef OLIVE_OCIO
|
||||
// convert to linear colorspace
|
||||
bool linear_convert = true;
|
||||
if (linear_convert)
|
||||
if (olive::CurrentConfig.enable_color_management)
|
||||
{
|
||||
params.ocio_shader->bind();
|
||||
|
||||
params.ocio_shader->setUniformValue("tex1", 0);
|
||||
params.ocio_shader->setUniformValue("tex2", 2);
|
||||
|
||||
textureID = draw_clip(c->fbo[fbo_switcher], textureID, true);
|
||||
|
||||
params.ocio_shader->release();
|
||||
|
||||
fbo_switcher = !fbo_switcher;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -718,3 +726,7 @@ void close_active_clips(SequencePtr s) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateOCIOGLState(const ComposeSequenceParams& params)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -390,4 +390,6 @@ int64_t playhead_to_timestamp(Clip *c, long playhead);
|
||||
*/
|
||||
void close_active_clips(SequencePtr s);
|
||||
|
||||
void UpdateOCIOGLState(const ComposeSequenceParams ¶ms);
|
||||
|
||||
#endif // RENDERFUNCTIONS_H
|
||||
|
||||
+124
-2
@@ -22,9 +22,10 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QImage>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
|
||||
#ifdef OLIVE_OCIO
|
||||
#include <OpenColorIO/OpenColorIO.h>
|
||||
namespace OCIO = OCIO_NAMESPACE;
|
||||
@@ -33,6 +34,7 @@ namespace OCIO = OCIO_NAMESPACE;
|
||||
#include "rendering/renderfunctions.h"
|
||||
#include "project/sequence.h"
|
||||
#include "project/effectloaders.h"
|
||||
#include "io/config.h"
|
||||
|
||||
RenderThread::RenderThread() :
|
||||
gizmos(nullptr),
|
||||
@@ -93,8 +95,8 @@ void RenderThread::run() {
|
||||
back_buffer_2.Create(ctx, seq->width, seq->height);
|
||||
}
|
||||
|
||||
// If there's no blending mode shader, create it now
|
||||
if (blend_mode_program == nullptr) {
|
||||
// create shader program to make blending modes work
|
||||
delete_shaders();
|
||||
|
||||
blend_mode_program = new QOpenGLShaderProgram();
|
||||
@@ -105,6 +107,14 @@ void RenderThread::run() {
|
||||
blend_mode_program->link();
|
||||
}
|
||||
|
||||
// If there's no OpenColorIO shader, create it now
|
||||
if (olive::CurrentConfig.enable_color_management
|
||||
&& (ocio_shader == nullptr || ocio_loaded_config != olive::CurrentConfig.ocio_config_path)) {
|
||||
destroy_ocio();
|
||||
|
||||
set_up_ocio();
|
||||
}
|
||||
|
||||
// draw frame
|
||||
paint();
|
||||
|
||||
@@ -132,8 +142,117 @@ const GLuint &RenderThread::get_texture()
|
||||
return front_buffer_switcher ? front_buffer_2.texture() : front_buffer_1.texture();
|
||||
}
|
||||
|
||||
const char * g_fragShaderText = ""
|
||||
"\n"
|
||||
"uniform sampler2D tex1;\n"
|
||||
"uniform sampler3D tex2;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 col = texture2D(tex1, gl_TexCoord[0].st);\n"
|
||||
" gl_FragColor = OCIODisplay(col, tex2);\n"
|
||||
"}\n";
|
||||
|
||||
void RenderThread::set_up_ocio()
|
||||
{
|
||||
functions.initializeOpenGLFunctions();
|
||||
|
||||
//
|
||||
// SETUP LUT TEXTURE
|
||||
//
|
||||
|
||||
// Create LUT texture
|
||||
ctx->functions()->glGenTextures(1, &ocio_lut_texture);
|
||||
|
||||
// Bind texture to GL_TEXTURE_3D and GL_TEXTURE2
|
||||
ctx->functions()->glActiveTexture(GL_TEXTURE2);
|
||||
ctx->functions()->glBindTexture(GL_TEXTURE_3D, ocio_lut_texture);
|
||||
|
||||
// Set texture parameters
|
||||
ctx->functions()->glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
ctx->functions()->glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
ctx->functions()->glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
ctx->functions()->glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
ctx->functions()->glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// Allocate storage for texture
|
||||
functions.glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB,
|
||||
OCIO_LUT3D_EDGE_SIZE, OCIO_LUT3D_EDGE_SIZE, OCIO_LUT3D_EDGE_SIZE,
|
||||
0, GL_RGB,GL_FLOAT, ocio_lut_data);
|
||||
|
||||
//
|
||||
// SET UP OCIO DISPLAY
|
||||
//
|
||||
|
||||
OCIO::ConstConfigRcPtr config;
|
||||
|
||||
// Set current config to the file specified in Config
|
||||
if (QFileInfo::exists(olive::CurrentConfig.ocio_config_path)) {
|
||||
|
||||
config = OCIO::Config::CreateFromFile(olive::CurrentConfig.ocio_config_path.toUtf8());
|
||||
OCIO::SetCurrentConfig(config);
|
||||
ocio_loaded_config = olive::CurrentConfig.ocio_config_path;
|
||||
|
||||
} else {
|
||||
|
||||
config = OCIO::GetCurrentConfig();
|
||||
|
||||
}
|
||||
|
||||
const char* display = config->getDefaultDisplay();
|
||||
|
||||
OCIO::DisplayTransformRcPtr transform = OCIO::DisplayTransform::Create();
|
||||
transform->setInputColorSpaceName(OCIO::ROLE_SCENE_LINEAR);
|
||||
transform->setDisplay(display);
|
||||
transform->setView(config->getDefaultView(display));
|
||||
|
||||
//
|
||||
// GET OCIO PROCESSOR
|
||||
//
|
||||
|
||||
OCIO::ConstProcessorRcPtr processor = OCIO::GetCurrentConfig()->getProcessor(transform);
|
||||
|
||||
//
|
||||
// SET UP GLSL SHADER
|
||||
//
|
||||
|
||||
OCIO::GpuShaderDesc shaderDesc;
|
||||
shaderDesc.setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_0);
|
||||
shaderDesc.setFunctionName("OCIODisplay");
|
||||
shaderDesc.setLut3DEdgeLen(OCIO_LUT3D_EDGE_SIZE);
|
||||
|
||||
//
|
||||
// COMPUTE 3D LUT
|
||||
//
|
||||
|
||||
processor->getGpuLut3D(ocio_lut_data, shaderDesc);
|
||||
|
||||
glBindTexture(GL_TEXTURE_3D, ocio_lut_texture);
|
||||
functions.glTexSubImage3D(GL_TEXTURE_3D, 0,
|
||||
0, 0, 0,
|
||||
OCIO_LUT3D_EDGE_SIZE, OCIO_LUT3D_EDGE_SIZE, OCIO_LUT3D_EDGE_SIZE,
|
||||
GL_RGB,GL_FLOAT, ocio_lut_data);
|
||||
|
||||
QString shader_text = processor->getGpuShaderText(shaderDesc);
|
||||
shader_text.append("\n");
|
||||
shader_text.append(g_fragShaderText);
|
||||
|
||||
ocio_shader = new QOpenGLShaderProgram();
|
||||
ocio_shader->addShaderFromSourceCode(QOpenGLShader::Fragment, shader_text);
|
||||
ocio_shader->link();
|
||||
|
||||
// Reset active texture to 0 for the rest of the pipeline
|
||||
ctx->functions()->glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void RenderThread::destroy_ocio()
|
||||
{
|
||||
// Destroy LUT texture
|
||||
ctx->functions()->glDeleteTextures(1, &ocio_lut_texture);
|
||||
ocio_lut_texture = 0;
|
||||
|
||||
delete ocio_shader;
|
||||
ocio_shader = nullptr;
|
||||
}
|
||||
|
||||
void RenderThread::paint() {
|
||||
@@ -147,6 +266,7 @@ void RenderThread::paint() {
|
||||
params.wait_for_mutexes = true;
|
||||
params.playback_speed = 1;
|
||||
params.blend_mode_program = blend_mode_program;
|
||||
params.ocio_shader = ocio_shader;
|
||||
params.backend_buffer1 = back_buffer_1.buffer();
|
||||
params.backend_buffer2 = back_buffer_2.buffer();
|
||||
params.backend_attachment1 = back_buffer_1.texture();
|
||||
@@ -279,6 +399,8 @@ void RenderThread::delete_ctx() {
|
||||
if (ctx != nullptr) {
|
||||
delete_shaders();
|
||||
delete_buffers();
|
||||
|
||||
destroy_ocio();
|
||||
}
|
||||
|
||||
delete ctx;
|
||||
|
||||
@@ -28,16 +28,17 @@
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLFunctions_2_0>
|
||||
|
||||
#include "project/sequence.h"
|
||||
#include "project/effect.h"
|
||||
#include "rendering/framebufferobject.h"
|
||||
|
||||
// copied from source code to OCIODisplay
|
||||
const int LUT3D_EDGE_SIZE = 32;
|
||||
const int OCIO_LUT3D_EDGE_SIZE = 32;
|
||||
|
||||
// copied from source code to OCIODisplay, expanded from 3*LUT3D_EDGE_SIZE*LUT3D_EDGE_SIZE*LUT3D_EDGE_SIZE
|
||||
const int NUM_3D_ENTRIES = 98304;
|
||||
const int OCIO_NUM_3D_ENTRIES = 98304;
|
||||
|
||||
class RenderThread : public QThread {
|
||||
Q_OBJECT
|
||||
@@ -96,9 +97,11 @@ private:
|
||||
FramebufferObject back_buffer_1;
|
||||
FramebufferObject back_buffer_2;
|
||||
|
||||
float ocio_lut_data[NUM_3D_ENTRIES];
|
||||
// OpenColorIO variables
|
||||
float ocio_lut_data[OCIO_NUM_3D_ENTRIES];
|
||||
GLuint ocio_lut_texture;
|
||||
QOpenGLShaderProgram* ocio_shader;
|
||||
QString ocio_loaded_config;
|
||||
|
||||
SequencePtr seq;
|
||||
int divider;
|
||||
@@ -110,6 +113,8 @@ private:
|
||||
QString save_fn;
|
||||
GLvoid *pixel_buffer;
|
||||
int pixel_buffer_linesize;
|
||||
|
||||
QOpenGLFunctions_2_0 functions;
|
||||
};
|
||||
|
||||
#endif // RENDERTHREAD_H
|
||||
|
||||
Reference in New Issue
Block a user