removed all dependence on NodeOutputs
If Nodes only have the one output, we don't need to do so much differentiation between them. Previous iteration used outputs as like a distinct function within a Node (e.g. length output would return one result, buffer output would produce a different result - each run different code to produce their results). Now in this iteration, it's more accurate to say a Node is just one function (which seems more appropriate for a node system anyway).
This commit is contained in:
@@ -83,12 +83,12 @@ bool OpenGLBackend::TraverseCompiling(Node *n)
|
||||
{
|
||||
foreach (NodeParam* param, n->parameters()) {
|
||||
if (param->type() == NodeParam::kInput && param->IsConnected()) {
|
||||
NodeOutput* connected_output = static_cast<NodeInput*>(param)->get_connected_output();
|
||||
Node* connected_output = static_cast<NodeInput*>(param)->get_connected_node();
|
||||
|
||||
// Check if we have a shader or not
|
||||
if (shader_cache_.GetShader(connected_output) == nullptr) {
|
||||
// Since we don't have a shader, compile one now
|
||||
QString node_code = connected_output->parentNode()->Code(connected_output);
|
||||
QString node_code = connected_output->Code();
|
||||
|
||||
// If the node has no code, it mustn't be GPU accelerated
|
||||
if (!node_code.isEmpty()) {
|
||||
@@ -126,7 +126,7 @@ bool OpenGLBackend::TraverseCompiling(Node *n)
|
||||
}
|
||||
}
|
||||
|
||||
if (!TraverseCompiling(connected_output->parentNode())) {
|
||||
if (!TraverseCompiling(connected_output)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,27 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
OpenGLShaderCache::OpenGLShaderCache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString OpenGLShaderCache::GenerateShaderID(NodeOutput *output)
|
||||
{
|
||||
// Creates a unique identifier for this specific node and this specific output
|
||||
return QString("%1:%2").arg(output->parentNode()->id(), output->id());
|
||||
}
|
||||
|
||||
void OpenGLShaderCache::Clear()
|
||||
{
|
||||
compiled_nodes_.clear();
|
||||
}
|
||||
|
||||
void OpenGLShaderCache::AddShader(NodeOutput *output, OpenGLShaderPtr shader)
|
||||
void OpenGLShaderCache::AddShader(Node *output, OpenGLShaderPtr shader)
|
||||
{
|
||||
compiled_nodes_.insert(GenerateShaderID(output), shader);
|
||||
}
|
||||
|
||||
OpenGLShaderPtr OpenGLShaderCache::GetShader(NodeOutput *output)
|
||||
OpenGLShaderPtr OpenGLShaderCache::GetShader(Node *output)
|
||||
{
|
||||
return compiled_nodes_.value(GenerateShaderID(output));
|
||||
}
|
||||
|
||||
bool OpenGLShaderCache::HasShader(NodeOutput *output)
|
||||
QString OpenGLShaderCache::GenerateShaderID(Node *output)
|
||||
{
|
||||
return output->id();
|
||||
}
|
||||
|
||||
bool OpenGLShaderCache::HasShader(Node *output)
|
||||
{
|
||||
return compiled_nodes_.contains(GenerateShaderID(output));
|
||||
}
|
||||
|
||||
@@ -12,18 +12,18 @@
|
||||
class OpenGLShaderCache
|
||||
{
|
||||
public:
|
||||
OpenGLShaderCache();
|
||||
OpenGLShaderCache() = default;
|
||||
|
||||
void Clear();
|
||||
|
||||
void AddShader(NodeOutput* output, OpenGLShaderPtr shader);
|
||||
void AddShader(Node* output, OpenGLShaderPtr shader);
|
||||
|
||||
OpenGLShaderPtr GetShader(NodeOutput* output);
|
||||
OpenGLShaderPtr GetShader(Node* output);
|
||||
|
||||
bool HasShader(NodeOutput* output);
|
||||
bool HasShader(Node* output);
|
||||
|
||||
private:
|
||||
QString GenerateShaderID(NodeOutput* output);
|
||||
QString GenerateShaderID(Node *output);
|
||||
|
||||
QMap<QString, OpenGLShaderPtr> compiled_nodes_;
|
||||
|
||||
|
||||
@@ -63,11 +63,6 @@ QVariant OpenGLWorker::FrameToValue(FramePtr frame)
|
||||
return QVariant::fromValue(footage_tex);
|
||||
}
|
||||
|
||||
bool OpenGLWorker::OutputIsAccelerated(NodeOutput* output)
|
||||
{
|
||||
return shader_cache_->HasShader(output);
|
||||
}
|
||||
|
||||
void OpenGLWorker::CloseInternal()
|
||||
{
|
||||
buffer_.Destroy();
|
||||
@@ -83,10 +78,13 @@ void OpenGLWorker::ParametersChangedEvent()
|
||||
}
|
||||
}
|
||||
|
||||
NodeValueTable OpenGLWorker::RunNodeAccelerated(NodeOutput *out)
|
||||
void OpenGLWorker::RunNodeAccelerated(Node *node, const NodeValueDatabase *input_params, NodeValueTable *output_params)
|
||||
{
|
||||
OpenGLShaderPtr shader = shader_cache_->GetShader(out);
|
||||
Node* node = out->parentNode();
|
||||
OpenGLShaderPtr shader = shader_cache_->GetShader(node);
|
||||
|
||||
if (shader == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the output texture
|
||||
OpenGLTexturePtr output = std::make_shared<OpenGLTexture>();
|
||||
@@ -109,35 +107,42 @@ NodeValueTable OpenGLWorker::RunNodeAccelerated(NodeOutput *out)
|
||||
// This variable is used in the shader, let's set it to our value
|
||||
|
||||
NodeInput* input = static_cast<NodeInput*>(param);
|
||||
|
||||
// Get value from database at this input
|
||||
const NodeValueTable& input_data = (*input_params)[input];
|
||||
|
||||
// Try to get a value from it
|
||||
QVariant value = input_data.Get(input->data_type());
|
||||
|
||||
switch (input->data_type()) {
|
||||
case NodeInput::kInt:
|
||||
shader->setUniformValue(variable_location, input->value().toInt());
|
||||
shader->setUniformValue(variable_location, value.toInt());
|
||||
break;
|
||||
case NodeInput::kFloat:
|
||||
shader->setUniformValue(variable_location, input->value().toFloat());
|
||||
shader->setUniformValue(variable_location, value.toFloat());
|
||||
break;
|
||||
case NodeInput::kVec2:
|
||||
shader->setUniformValue(variable_location, input->value().value<QVector2D>());
|
||||
shader->setUniformValue(variable_location, value.value<QVector2D>());
|
||||
break;
|
||||
case NodeInput::kVec3:
|
||||
shader->setUniformValue(variable_location, input->value().value<QVector3D>());
|
||||
shader->setUniformValue(variable_location, value.value<QVector3D>());
|
||||
break;
|
||||
case NodeInput::kVec4:
|
||||
shader->setUniformValue(variable_location, input->value().value<QVector4D>());
|
||||
shader->setUniformValue(variable_location, value.value<QVector4D>());
|
||||
break;
|
||||
case NodeInput::kMatrix:
|
||||
shader->setUniformValue(variable_location, input->value().value<QMatrix4x4>());
|
||||
shader->setUniformValue(variable_location, value.value<QMatrix4x4>());
|
||||
break;
|
||||
case NodeInput::kColor:
|
||||
shader->setUniformValue(variable_location, input->value().value<QColor>());
|
||||
shader->setUniformValue(variable_location, value.value<QColor>());
|
||||
break;
|
||||
case NodeInput::kBoolean:
|
||||
shader->setUniformValue(variable_location, input->value().toBool());
|
||||
shader->setUniformValue(variable_location, value.toBool());
|
||||
break;
|
||||
case NodeInput::kTexture:
|
||||
case NodeInput::kFootage:
|
||||
{
|
||||
OpenGLTexturePtr texture = input->value().value<OpenGLTexturePtr>();
|
||||
OpenGLTexturePtr texture = value.value<OpenGLTexturePtr>();
|
||||
|
||||
functions_->glActiveTexture(GL_TEXTURE0 + input_texture_count);
|
||||
|
||||
@@ -192,7 +197,7 @@ NodeValueTable OpenGLWorker::RunNodeAccelerated(NodeOutput *out)
|
||||
|
||||
functions_->glFinish();
|
||||
|
||||
return QVariant::fromValue(output);
|
||||
output_params->Push(NodeParam::kTexture, QVariant::fromValue(output));
|
||||
}
|
||||
|
||||
void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
|
||||
|
||||
@@ -47,9 +47,7 @@ protected:
|
||||
|
||||
virtual QVariant FrameToValue(FramePtr frame) override;
|
||||
|
||||
virtual bool OutputIsAccelerated(NodeOutput *output) override;
|
||||
|
||||
virtual NodeValueTable RunNodeAccelerated(NodeOutput *output) override;
|
||||
virtual void RunNodeAccelerated(Node *node, const NodeValueDatabase *input_params, NodeValueTable* output_params) override;
|
||||
|
||||
virtual void TextureToBuffer(const QVariant& texture, QByteArray& buffer) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user