media now plays in node graph

This commit is contained in:
itsmattkc
2019-08-04 19:45:06 +10:00
parent 298ae2f36c
commit f55094c5df
15 changed files with 484 additions and 229 deletions
+3
View File
@@ -24,6 +24,9 @@ set(OLIVE_SOURCES
#render/memorybuffer.cpp
render/pixelformat.h
render/pixelformat.cpp
render/pixelservice.h
render/pixelservice.cpp
render/sampleformat.h
render/texturebuffer.h
render/texturebuffer.cpp
PARENT_SCOPE
-63
View File
@@ -19,66 +19,3 @@
***/
#include "pixelformat.h"
#include <QCoreApplication>
const int kRGBAChannels = 4;
PixelService::PixelService()
{
}
PixelFormatInfo PixelService::GetPixelFormatInfo(const olive::PixelFormat &format)
{
PixelFormatInfo info;
switch (format) {
case olive::PIX_FMT_RGBA8:
info.name = tr("8-bit");
info.internal_format = GL_RGBA8;
info.pixel_type = GL_UNSIGNED_BYTE;
break;
case olive::PIX_FMT_RGBA16:
info.name = tr("16-bit Integer");
info.internal_format = GL_RGBA16;
info.pixel_type = GL_UNSIGNED_SHORT;
break;
case olive::PIX_FMT_RGBA16F:
info.name = tr("Half-Float (16-bit)");
info.internal_format = GL_RGBA16F;
info.pixel_type = GL_HALF_FLOAT;
break;
case olive::PIX_FMT_RGBA32F:
info.name = tr("Full-Float (32-bit)");
info.internal_format = GL_RGBA32F;
info.pixel_type = GL_FLOAT;
break;
default:
qFatal("Invalid pixel format requested");
}
info.pixel_format = GL_RGBA;
info.bytes_per_pixel = BytesPerPixel(format);
return info;
}
int PixelService::GetBufferSize(const olive::PixelFormat &format, const int &width, const int &height)
{
return BytesPerPixel(format) * width * height;
}
int PixelService::BytesPerPixel(const olive::PixelFormat &format)
{
switch (format) {
case olive::PIX_FMT_RGBA8:
return 1 * kRGBAChannels;
case olive::PIX_FMT_RGBA16:
case olive::PIX_FMT_RGBA16F:
return 2 * kRGBAChannels;
case olive::PIX_FMT_RGBA32F:
return 4 * kRGBAChannels;
default:
qFatal("Invalid pixel format requested");
}
}
+1 -63
View File
@@ -21,34 +21,13 @@
#ifndef BITDEPTHS_H
#define BITDEPTHS_H
#include <QString>
#include <QVector>
#include <QOpenGLExtraFunctions>
/**
* @brief A struct of information pertaining to each enum PixelFormat.
*
* Primarily this is a means of retrieving OpenGL texture information for different pixel formats/bit depths. Both
* RAM and VRAM buffers will need a PixelFormat. To keep consistency between the OpenGL code and CPU code when using
* a given PixelFormat, the PixelFormatInfo struct contains all necessary variables that you'll need to plug into
* OpenGL.
*
* Use the static function PixelService::GetPixelFormatInfo to generate a PixelFormatInfo object.
*/
struct PixelFormatInfo {
QString name;
GLint internal_format;
GLenum pixel_format;
GLenum pixel_type;
int bytes_per_pixel;
};
namespace olive {
/**
* @brief Olive's internal supported pixel formats.
*/
enum PixelFormat {
PIX_FMT_INVALID = -1,
PIX_FMT_RGBA8,
PIX_FMT_RGBA16,
PIX_FMT_RGBA16F,
@@ -58,45 +37,4 @@ enum PixelFormat {
}
class PixelService : public QObject {
public:
PixelService();
/**
* @brief Return a PixelFormatInfo containing information for a certain format
*
* \see PixelFormatInfo
*/
static PixelFormatInfo GetPixelFormatInfo(const olive::PixelFormat& format);
/**
* @brief Returns the minimum buffer size (in bytes) necessary for a given format, width, and height.
*
* @param format
*
* The format of the data the buffer should contain. Must be a member of the olive::PixelFormat enum.
*
* @param width
*
* The width (in pixels) of the buffer.
*
* @param height
*
* The height (in pixels) of the buffer.
*/
static int GetBufferSize(const olive::PixelFormat &format, const int& width, const int& height);
/**
* @brief Returns the number of bytes per pixel for a certain format
*
* Different formats use different sizes of data for pixels. Use this function to determine how many bytes a pixel
* requires for a certain format. The number of bytes will always be a multiple of 4 since all formats use RGBA and
* are at least 1 bpc.
*/
static int BytesPerPixel(const olive::PixelFormat& format);
private:
};
#endif // BITDEPTHS_H
+89
View File
@@ -0,0 +1,89 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "pixelservice.h"
#include <QCoreApplication>
const int kRGBAChannels = 4;
PixelService::PixelService()
{
}
PixelFormatInfo PixelService::GetPixelFormatInfo(const olive::PixelFormat &format)
{
PixelFormatInfo info;
switch (format) {
case olive::PIX_FMT_RGBA8:
info.name = tr("8-bit");
info.internal_format = GL_RGBA8;
info.pixel_type = GL_UNSIGNED_BYTE;
break;
case olive::PIX_FMT_RGBA16:
info.name = tr("16-bit Integer");
info.internal_format = GL_RGBA16;
info.pixel_type = GL_UNSIGNED_SHORT;
break;
case olive::PIX_FMT_RGBA16F:
info.name = tr("Half-Float (16-bit)");
info.internal_format = GL_RGBA16F;
info.pixel_type = GL_HALF_FLOAT;
break;
case olive::PIX_FMT_RGBA32F:
info.name = tr("Full-Float (32-bit)");
info.internal_format = GL_RGBA32F;
info.pixel_type = GL_FLOAT;
break;
default:
qFatal("Invalid pixel format requested");
}
info.pixel_format = GL_RGBA;
info.bytes_per_pixel = BytesPerPixel(format);
return info;
}
int PixelService::GetBufferSize(const olive::PixelFormat &format, const int &width, const int &height)
{
return BytesPerPixel(format) * width * height;
}
int PixelService::BytesPerPixel(const olive::PixelFormat &format)
{
return BytesPerChannel(format) * kRGBAChannels;
}
int PixelService::BytesPerChannel(const olive::PixelFormat &format)
{
switch (format) {
case olive::PIX_FMT_RGBA8:
return 1;
case olive::PIX_FMT_RGBA16:
case olive::PIX_FMT_RGBA16F:
return 2;
case olive::PIX_FMT_RGBA32F:
return 4;
default:
qFatal("Invalid pixel format requested");
}
}
+93
View File
@@ -0,0 +1,93 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef PIXELSERVICE_H
#define PIXELSERVICE_H
#include <QString>
#include <QOpenGLExtraFunctions>
#include "pixelformat.h"
/**
* @brief A struct of information pertaining to each enum PixelFormat.
*
* Primarily this is a means of retrieving OpenGL texture information for different pixel formats/bit depths. Both
* RAM and VRAM buffers will need a PixelFormat. To keep consistency between the OpenGL code and CPU code when using
* a given PixelFormat, the PixelFormatInfo struct contains all necessary variables that you'll need to plug into
* OpenGL.
*
* Use the static function PixelService::GetPixelFormatInfo to generate a PixelFormatInfo object.
*/
struct PixelFormatInfo {
QString name;
GLint internal_format;
GLenum pixel_format;
GLenum pixel_type;
int bytes_per_pixel;
};
class PixelService : public QObject {
public:
PixelService();
/**
* @brief Return a PixelFormatInfo containing information for a certain format
*
* \see PixelFormatInfo
*/
static PixelFormatInfo GetPixelFormatInfo(const olive::PixelFormat& format);
/**
* @brief Returns the minimum buffer size (in bytes) necessary for a given format, width, and height.
*
* @param format
*
* The format of the data the buffer should contain. Must be a member of the olive::PixelFormat enum.
*
* @param width
*
* The width (in pixels) of the buffer.
*
* @param height
*
* The height (in pixels) of the buffer.
*/
static int GetBufferSize(const olive::PixelFormat &format, const int& width, const int& height);
/**
* @brief Returns the number of bytes per pixel for a certain format
*
* Different formats use different sizes of data for pixels. Use this function to determine how many bytes a pixel
* requires for a certain format. The number of bytes will always be a multiple of 4 since all formats use RGBA and
* are at least 1 bpc.
*/
static int BytesPerPixel(const olive::PixelFormat& format);
/**
* @brief Returns the number of bytes per channel for a certain format
*/
static int BytesPerChannel(const olive::PixelFormat& format);
private:
};
#endif // PIXELSERVICE_H
+41
View File
@@ -0,0 +1,41 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef SAMPLEFORMAT_H
#define SAMPLEFORMAT_H
namespace olive {
/**
* @brief Olive's internal supported sample formats
*/
enum SampleFormat {
SAMPLE_FMT_INVALID = -1,
SAMPLE_FMT_U8,
SAMPLE_FMT_S16,
SAMPLE_FMT_S32,
SAMPLE_FMT_FLT,
SAMPLE_FMT_DBL,
SAMPLE_FMT_COUNT
};
}
#endif // SAMPLEFORMAT_H
+32 -2
View File
@@ -23,6 +23,8 @@
#include <QOpenGLFunctions>
#include <QOpenGLExtraFunctions>
#include "render/pixelservice.h"
TextureBuffer::TextureBuffer() :
ctx_(nullptr),
buffer_(0),
@@ -39,7 +41,7 @@ bool TextureBuffer::IsCreated()
return (ctx_ != nullptr);
}
void TextureBuffer::Create(QOpenGLContext *ctx, const olive::PixelFormat &format, int width, int height)
void TextureBuffer::Create(QOpenGLContext *ctx, const olive::PixelFormat &format, int width, int height, void* data)
{
// free any previous textures
Destroy();
@@ -47,6 +49,11 @@ void TextureBuffer::Create(QOpenGLContext *ctx, const olive::PixelFormat &format
// set context to new context provided
ctx_ = ctx;
// Store frame metadata
width_ = width;
height_ = height;
format_ = format;
QOpenGLFunctions* f = ctx->functions();
// create framebuffer object
@@ -73,7 +80,7 @@ void TextureBuffer::Create(QOpenGLContext *ctx, const olive::PixelFormat &format
0,
bit_depth.pixel_format,
bit_depth.pixel_type,
nullptr
data
);
// set texture filtering to bilinear
@@ -107,6 +114,29 @@ void TextureBuffer::Destroy()
}
}
void TextureBuffer::Upload(void *data)
{
if (!IsCreated()) {
return;
}
BindTexture();
PixelFormatInfo info = PixelService::GetPixelFormatInfo(format_);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
width_,
height_,
info.pixel_format,
info.pixel_type,
data);
ReleaseTexture();
}
void TextureBuffer::BindBuffer() const
{
if (ctx_ == nullptr) {
+7 -1
View File
@@ -40,9 +40,11 @@ public:
~TextureBuffer();
bool IsCreated();
void Create(QOpenGLContext* ctx, const olive::PixelFormat& format, int width, int height);
void Create(QOpenGLContext* ctx, const olive::PixelFormat& format, int width, int height, void *data = nullptr);
void Destroy();
void Upload(void *data);
const GLuint& buffer() const;
const GLuint& texture() const;
@@ -55,6 +57,10 @@ private:
QOpenGLContext* ctx_;
GLuint buffer_;
GLuint texture_;
int width_;
int height_;
olive::PixelFormat format_;
};
#endif // FRAMEBUFFEROBJECT_H