started porting renderer to new portable form
This commit is contained in:
@@ -24,8 +24,6 @@ add_subdirectory(output)
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
node/code.h
|
||||
node/code.cpp
|
||||
node/dependency.h
|
||||
node/dependency.cpp
|
||||
node/edge.h
|
||||
|
||||
@@ -20,11 +20,6 @@
|
||||
|
||||
#include "alphaover.h"
|
||||
|
||||
#include "render/gl/functions.h"
|
||||
#include "render/gl/shadergenerators.h"
|
||||
#include "render/rendertexture.h"
|
||||
#include "render/video/videorenderer.h"
|
||||
|
||||
AlphaOverBlend::AlphaOverBlend()
|
||||
{
|
||||
|
||||
@@ -45,71 +40,20 @@ QString AlphaOverBlend::Description()
|
||||
return tr("A blending node that composites one texture over another using its alpha channel.");
|
||||
}
|
||||
|
||||
NodeCode AlphaOverBlend::Code(NodeOutput *output)
|
||||
QString AlphaOverBlend::Code(NodeOutput *output)
|
||||
{
|
||||
if (output == texture_output()) {
|
||||
return NodeCode("AlphaOver",
|
||||
"void AlphaOver(const pixel *base_in, const pixel *blend_in, pixel *tex_out) {"
|
||||
" int i = get_global_id(0);"
|
||||
" tex_out[i].r = base_in.r - blend_in.a + blend_in.r;"
|
||||
" tex_out[i].g = base_in.g - blend_in.a + blend_in.g;"
|
||||
" tex_out[i].b = base_in.b - blend_in.a + blend_in.b;"
|
||||
" tex_out[i].a = base_in.a - blend_in.a + blend_in.a;"
|
||||
"}");
|
||||
return "#version 110"
|
||||
"\n"
|
||||
"varying vec2 olive_tex_coord;\n"
|
||||
"\n"
|
||||
"uniform sampler2D base_in;\n"
|
||||
"uniform sampler2D blend_in;\n"
|
||||
"\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = base_in - blend_in.a + blend_in;\n"
|
||||
"}\n";
|
||||
}
|
||||
|
||||
return Node::Code(output);
|
||||
}
|
||||
|
||||
void AlphaOverBlend::Release()
|
||||
{
|
||||
}
|
||||
|
||||
QVariant AlphaOverBlend::Value(NodeOutput *param, const rational &in, const rational &out)
|
||||
{
|
||||
// Find the current Renderer instance
|
||||
RenderInstance* renderer = VideoRendererProcessor::CurrentInstance();
|
||||
|
||||
// If nothing is available, don't return a texture
|
||||
if (renderer == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The only parameter should be texture output, but for future proofing we put this here
|
||||
if (param == texture_output()) {
|
||||
RenderTexturePtr base = base_input()->get_value(in, out).value<RenderTexturePtr>();
|
||||
RenderTexturePtr blend = blend_input()->get_value(in, out).value<RenderTexturePtr>();
|
||||
|
||||
if (base == nullptr && blend == nullptr) {
|
||||
return 0;
|
||||
} else if (base == nullptr) {
|
||||
return QVariant::fromValue(blend);
|
||||
} else if (blend == nullptr) {
|
||||
return QVariant::fromValue(base);
|
||||
}
|
||||
|
||||
// Attach framebuffer to the backbuffer of base
|
||||
renderer->buffer()->Attach(base);
|
||||
renderer->buffer()->Bind();
|
||||
|
||||
// Bind blend
|
||||
blend->Bind();
|
||||
|
||||
// Set compositing strategy to alpha over
|
||||
renderer->context()->functions()->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Draw blend on base
|
||||
olive::gl::Blit(renderer->default_pipeline());
|
||||
|
||||
// Release all
|
||||
blend->Release();
|
||||
renderer->buffer()->Release();
|
||||
renderer->buffer()->Detach();
|
||||
|
||||
// Return base texture which now has blend composited on top
|
||||
// NOTE: Blend texture will be implicitly deleted here (if it's not used anywhere else)
|
||||
return QVariant::fromValue(base);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define ALPHAOVER_H
|
||||
|
||||
#include "node/blend/blend.h"
|
||||
#include "render/gl/shaderptr.h"
|
||||
|
||||
class AlphaOverBlend : public BlendNode
|
||||
{
|
||||
@@ -33,12 +32,9 @@ public:
|
||||
virtual QString id() override;
|
||||
virtual QString Description() override;
|
||||
|
||||
virtual NodeCode Code(NodeOutput* output) override;
|
||||
|
||||
virtual void Release() override;
|
||||
virtual QString Code(NodeOutput* output) override;
|
||||
|
||||
protected:
|
||||
virtual QVariant Value(NodeOutput* param, const rational &in, const rational &out) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
Block::Block() :
|
||||
next_(nullptr)
|
||||
{
|
||||
previous_input_ = new NodeInput("prev_block");
|
||||
previous_input_ = new NodeInput("prev_in");
|
||||
previous_input_->set_data_type(NodeParam::kBlock);
|
||||
previous_input_->set_dependent(false);
|
||||
AddParameter(previous_input_);
|
||||
|
||||
block_output_ = new NodeOutput("block_out");
|
||||
block_output_ = new NodeOutput("this_out");
|
||||
AddParameter(block_output_);
|
||||
|
||||
buffer_output_ = new NodeOutput("buffer_out");
|
||||
@@ -277,3 +277,8 @@ bool Block::HasLinks()
|
||||
return !linked_clips_.isEmpty();
|
||||
}
|
||||
|
||||
bool Block::IsBlock()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,8 @@ public:
|
||||
const QVector<Block*>& linked_clips();
|
||||
bool HasLinks();
|
||||
|
||||
virtual bool IsBlock() override;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Refreshes internal cache of in/out points up to date
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#include "nodecode.h"
|
||||
|
||||
NodeCode::NodeCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NodeCode::NodeCode(const QString &function_name, const QString &code) :
|
||||
function_name_(function_name),
|
||||
code_(code)
|
||||
{
|
||||
}
|
||||
|
||||
bool NodeCode::IsValid()
|
||||
{
|
||||
return (!function_name_.isEmpty() && !code_.isEmpty());
|
||||
}
|
||||
|
||||
const QString &NodeCode::function_name()
|
||||
{
|
||||
return function_name_;
|
||||
}
|
||||
|
||||
const QString &NodeCode::code()
|
||||
{
|
||||
return code_;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef NODECODE_H
|
||||
#define NODECODE_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class NodeCode
|
||||
{
|
||||
public:
|
||||
NodeCode();
|
||||
NodeCode(const QString& function_name, const QString& code);
|
||||
|
||||
bool IsValid();
|
||||
|
||||
const QString& function_name();
|
||||
const QString& code();
|
||||
|
||||
private:
|
||||
QString function_name_;
|
||||
|
||||
QString code_;
|
||||
};
|
||||
|
||||
#endif // NODECODE_H
|
||||
@@ -20,10 +20,6 @@
|
||||
|
||||
#include "opacity.h"
|
||||
|
||||
#include "render/gl/functions.h"
|
||||
#include "render/rendertexture.h"
|
||||
#include "render/video/videorenderer.h"
|
||||
|
||||
OpacityNode::OpacityNode()
|
||||
{
|
||||
opacity_input_ = new NodeInput("opacity_in");
|
||||
@@ -61,65 +57,29 @@ QString OpacityNode::id()
|
||||
return "org.olivevideoeditor.Olive.opacity";
|
||||
}
|
||||
|
||||
QVariant OpacityNode::Value(NodeOutput *output, const rational &in, const rational &out)
|
||||
{
|
||||
Q_UNUSED(out)
|
||||
|
||||
// Find the current Renderer instance
|
||||
RenderInstance* renderer = VideoRendererProcessor::CurrentInstance();
|
||||
|
||||
// If nothing is available, don't return a texture
|
||||
if (renderer == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (output == texture_output_) {
|
||||
RenderTexturePtr input_tex = texture_input_->get_value(in).value<RenderTexturePtr>();
|
||||
|
||||
if (input_tex == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Attach texture's back buffer as frame buffer
|
||||
renderer->buffer()->AttachBackBuffer(input_tex);
|
||||
renderer->buffer()->Bind();
|
||||
|
||||
// Bind texture's front buffer to draw with
|
||||
input_tex->Bind();
|
||||
|
||||
// Set opacity to value
|
||||
ShaderPtr pipeline = renderer->default_pipeline();
|
||||
pipeline->bind();
|
||||
pipeline->setUniformValue("opacity", opacity_input_->get_value(in).toFloat()*0.01f);
|
||||
pipeline->release();
|
||||
|
||||
renderer->context()->functions()->glBlendFunc(GL_ONE, GL_ZERO);
|
||||
|
||||
// Blit
|
||||
olive::gl::Blit(pipeline);
|
||||
|
||||
// Reset to full opacity
|
||||
pipeline->bind();
|
||||
pipeline->setUniformValue("opacity", 1.0f);
|
||||
pipeline->release();
|
||||
|
||||
input_tex->Release();
|
||||
renderer->buffer()->Release();
|
||||
renderer->buffer()->Detach();
|
||||
|
||||
input_tex->SwapFrontAndBack();
|
||||
|
||||
return QVariant::fromValue(input_tex);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OpacityNode::Retranslate()
|
||||
{
|
||||
opacity_input_->set_name(tr("Opacity"));
|
||||
}
|
||||
|
||||
QString OpacityNode::Code(NodeOutput *output)
|
||||
{
|
||||
if (output == texture_output()) {
|
||||
return "#version 110"
|
||||
"\n"
|
||||
"varying vec2 olive_tex_coord;\n"
|
||||
"\n"
|
||||
"uniform sampler2D tex_in;\n"
|
||||
"uniform float opacity_in;\n"
|
||||
"\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = tex_in * (opacity_in * 0.01);\n"
|
||||
"}\n";
|
||||
}
|
||||
|
||||
return Node::Code(output);
|
||||
}
|
||||
|
||||
NodeInput *OpacityNode::texture_input()
|
||||
{
|
||||
return texture_input_;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define OPACITYNODE_H
|
||||
|
||||
#include "node/node.h"
|
||||
#include "render/gl/shaderptr.h"
|
||||
|
||||
class OpacityNode : public Node
|
||||
{
|
||||
@@ -36,10 +35,10 @@ public:
|
||||
|
||||
virtual QString id() override;
|
||||
|
||||
virtual QVariant Value(NodeOutput *output, const rational &in, const rational &out) override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual QString Code(NodeOutput* output) override;
|
||||
|
||||
NodeInput* texture_input();
|
||||
|
||||
NodeOutput* texture_output();
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
#include "core.h"
|
||||
#include "decoder/ffmpeg/ffmpegdecoder.h"
|
||||
#include "project/item/footage/footage.h"
|
||||
#include "render/gl/shadergenerators.h"
|
||||
#include "render/gl/functions.h"
|
||||
#include "render/pixelservice.h"
|
||||
#include "render/video/videorenderer.h"
|
||||
|
||||
VideoInput::VideoInput() :
|
||||
color_processor_(nullptr),
|
||||
@@ -68,6 +65,25 @@ NodeOutput *VideoInput::texture_output()
|
||||
return texture_output_;
|
||||
}
|
||||
|
||||
QString VideoInput::Code(NodeOutput *output)
|
||||
{
|
||||
if (output == texture_output()) {
|
||||
return "#version 110\n"
|
||||
"\n"
|
||||
"varying vec2 olive_tex_coord;\n"
|
||||
"\n"
|
||||
"uniform sampler2D footage_in;\n"
|
||||
"uniform mat4 matrix_in;\n"
|
||||
"\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = texture2D(olive_tex, vec2(vec4(olive_tex_coord, 0.0, 1.0) * matrix_in));\n"
|
||||
"}\n";
|
||||
}
|
||||
|
||||
return Node::Code(output);
|
||||
}
|
||||
|
||||
/*
|
||||
void VideoInput::Hash(QCryptographicHash *hash, NodeOutput *from, const rational &time)
|
||||
{
|
||||
Node::Hash(hash, from, time);
|
||||
@@ -253,3 +269,4 @@ QVariant VideoInput::Value(NodeOutput *output, const rational &in, const rationa
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#include "../media.h"
|
||||
#include "render/colormanager.h"
|
||||
#include "render/rendertexture.h"
|
||||
#include "render/gl/shadergenerators.h"
|
||||
|
||||
class VideoInput : public MediaInput
|
||||
{
|
||||
@@ -18,33 +16,24 @@ public:
|
||||
virtual QString Category() override;
|
||||
virtual QString Description() override;
|
||||
|
||||
virtual QString Code() override;
|
||||
|
||||
virtual void Release() override;
|
||||
|
||||
NodeInput* matrix_input();
|
||||
|
||||
NodeOutput* texture_output();
|
||||
|
||||
virtual void Hash(QCryptographicHash *hash, NodeOutput* from, const rational &time) override;
|
||||
virtual QString Code(NodeOutput* output) override;
|
||||
|
||||
//virtual void Hash(QCryptographicHash *hash, NodeOutput* from, const rational &time) override;
|
||||
|
||||
protected:
|
||||
virtual QVariant Value(NodeOutput* output, const rational& in, const rational& out) override;
|
||||
//virtual QVariant Value(NodeOutput* output, const rational& in, const rational& out) override;
|
||||
|
||||
private:
|
||||
NodeInput* matrix_input_;
|
||||
|
||||
NodeOutput* texture_output_;
|
||||
|
||||
RenderTexture internal_tex_;
|
||||
|
||||
ColorProcessorPtr color_processor_;
|
||||
|
||||
ShaderPtr pipeline_;
|
||||
|
||||
QOpenGLContext* ocio_ctx_;
|
||||
GLuint ocio_texture_;
|
||||
|
||||
};
|
||||
|
||||
#endif // VIDEOINPUT_H
|
||||
|
||||
+16
-2
@@ -72,6 +72,15 @@ void Node::RemoveParameter(NodeParam *param)
|
||||
delete param;
|
||||
}
|
||||
|
||||
QVariant Node::Value(NodeOutput *output, const rational &in, const rational &out)
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
Q_UNUSED(in)
|
||||
Q_UNUSED(out)
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void Node::InvalidateCache(const rational &start_range, const rational &end_range, NodeInput *from)
|
||||
{
|
||||
Q_UNUSED(from)
|
||||
@@ -141,6 +150,11 @@ void Node::SetCanBeDeleted(bool s)
|
||||
can_be_deleted_ = s;
|
||||
}
|
||||
|
||||
bool Node::IsBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
rational Node::LastProcessedTime()
|
||||
{
|
||||
rational t;
|
||||
@@ -278,11 +292,11 @@ QList<Node *> Node::GetImmediateDependencies()
|
||||
return node_list;
|
||||
}
|
||||
|
||||
NodeCode Node::Code(NodeOutput *output)
|
||||
QString Node::Code(NodeOutput *output)
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
|
||||
return NodeCode();
|
||||
return QString();
|
||||
}
|
||||
|
||||
QList<NodeDependency> Node::RunDependencies(NodeOutput *output, const rational &time)
|
||||
|
||||
+11
-4
@@ -26,7 +26,6 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "node/code.h"
|
||||
#include "node/dependency.h"
|
||||
#include "node/input.h"
|
||||
#include "node/output.h"
|
||||
@@ -128,7 +127,7 @@ public:
|
||||
/**
|
||||
* @brief Generate OpenCL hardware accelerated code for this Node
|
||||
*/
|
||||
virtual NodeCode Code(NodeOutput* output);
|
||||
virtual QString Code(NodeOutput* output);
|
||||
|
||||
/**
|
||||
* @brief Wrapper for Process()
|
||||
@@ -224,10 +223,18 @@ public:
|
||||
bool CanBeDeleted();
|
||||
|
||||
/**
|
||||
* @brief Set whether
|
||||
* @brief Set whether this Node can be deleted in the UI or not
|
||||
*/
|
||||
void SetCanBeDeleted(bool s);
|
||||
|
||||
/**
|
||||
* @brief Returns whether this Node is a "Block" type or not
|
||||
*
|
||||
* You shouldn't ever need to override this since all derivatives of Block will automatically have this set to true.
|
||||
* It's just a more convenient way of checking than dynamic_casting.
|
||||
*/
|
||||
virtual bool IsBlock();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Add a parameter to this node
|
||||
@@ -258,7 +265,7 @@ protected:
|
||||
* corresponding output if it's connected to one. If your node doesn't directly deal with time, the default behavior
|
||||
* of the NodeParam objects will handle everything related to it automatically.
|
||||
*/
|
||||
virtual QVariant Value(NodeOutput* output, const rational &in, const rational &out) = 0;
|
||||
virtual QVariant Value(NodeOutput* output, const rational &in, const rational &out);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the last timecode Process() was called with
|
||||
|
||||
@@ -196,6 +196,16 @@ QVariant TrackOutput::Value(NodeOutput *output, const rational &in, const ration
|
||||
if (output == track_output_) {
|
||||
// Set track output correctly
|
||||
return PtrToValue(this);
|
||||
} else if (output == buffer_output()) {
|
||||
ValidateCurrentBlock(in);
|
||||
|
||||
if (current_block_ != this) {
|
||||
// At this point, we must have found the correct block so we use its texture output to produce the image
|
||||
return current_block_->buffer_output()->get_value(in, out);
|
||||
}
|
||||
|
||||
// No texture is valid
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Run default node processing
|
||||
|
||||
@@ -70,16 +70,6 @@ NodeInput *ViewerOutput::length_input()
|
||||
return length_input_;
|
||||
}
|
||||
|
||||
RenderTexturePtr ViewerOutput::GetTexture(const rational &time)
|
||||
{
|
||||
return texture_input_->get_value(time).value<RenderTexturePtr>();
|
||||
}
|
||||
|
||||
QByteArray ViewerOutput::GetSamples(const rational &in, const rational &out)
|
||||
{
|
||||
return samples_input_->get_value(in, out).toByteArray();
|
||||
}
|
||||
|
||||
void ViewerOutput::InvalidateCache(const rational &start_range, const rational &end_range, NodeInput *from)
|
||||
{
|
||||
Node::InvalidateCache(start_range, end_range, from);
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
#include "node/node.h"
|
||||
#include "render/videoparams.h"
|
||||
#include "render/audio/audioparams.h"
|
||||
#include "render/rendertexture.h"
|
||||
#include "render/audioparams.h"
|
||||
|
||||
/**
|
||||
* @brief A bridge between a node system and a ViewerPanel
|
||||
@@ -46,9 +45,6 @@ public:
|
||||
NodeInput* samples_input();
|
||||
NodeInput* length_input();
|
||||
|
||||
RenderTexturePtr GetTexture(const rational& time);
|
||||
QByteArray GetSamples(const rational& in, const rational& out);
|
||||
|
||||
virtual void InvalidateCache(const rational &start_range, const rational &end_range, NodeInput *from = nullptr) override;
|
||||
|
||||
const VideoParams& video_params();
|
||||
|
||||
@@ -87,9 +87,6 @@ public:
|
||||
/// Resolves to `Block*`
|
||||
kBlock,
|
||||
|
||||
/// Resolves to `QList<Block*>`
|
||||
kBlockList,
|
||||
|
||||
/// Resolves to `Footage*`
|
||||
kFootage,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user