Add GStreamer support for video textures and update related files

- Introduced GStreamerTexture class for handling video frames.
- Updated texture loading methods to include FromGStreamer.
- Modified effect handling to support GStreamer textures.
- Updated launch configuration and added new sample scripts.
This commit is contained in:
Diego Lopes
2026-03-20 21:54:43 -04:00
parent e538df3673
commit 52dc6fc757
13 changed files with 391 additions and 48 deletions

View File

@@ -1,4 +1,5 @@
#include "texture.h"
#include "gstreamer_texture.h"
#include "stb_image.h"
#include <stdexcept>
@@ -128,7 +129,12 @@ std::unique_ptr<TextureCubeMap> Texture::CreateCubeMap(uint32_t size, TextureFor
return tex;
}
std::unique_ptr<Texture2D> Texture::LoadFromFile(const std::string &filepath)
std::unique_ptr<GStreamerTexture> Texture::FromGStreamer(const std::string &pipeline)
{
return std::make_unique<GStreamerTexture>(pipeline);
}
std::unique_ptr<Texture2D> Texture::FromFile(const std::string &filepath)
{
int width, height, channels;
stbi_set_flip_vertically_on_load(true);
@@ -161,6 +167,10 @@ Texture::Texture(GLenum target)
: m_target(target)
{
glGenTextures(1, &m_id);
glBindTexture(m_target, m_id);
glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(m_target, 0);
}
Texture::~Texture()
@@ -213,41 +223,80 @@ void TextureCubeMap::LoadFaceDataFromFile(Face face, const std::string &filepath
stbi_image_free(data);
}
void Texture1D::LoadData(TextureFormatType format, const void *data) const
void Texture1D::LoadData(TextureFormatType format, const void *data)
{
const TextureFormat& fmt = textureFormatMap[static_cast<int>(format)];
glTexImage1D(
m_target,
0,
fmt.internalFormat,
m_width, 0,
fmt.format, fmt.type,
data
);
if (!m_hasInitialData) {
// Initialize texture storage with null data to allocate GPU memory
glTexImage1D(
m_target,
0,
fmt.internalFormat,
m_width, 0,
fmt.format, fmt.type,
nullptr
);
m_hasInitialData = true;
} else {
// Update existing texture data
glTexSubImage1D(
m_target,
0,
0, m_width,
fmt.format, fmt.type,
data
);
}
}
void Texture2D::LoadData(TextureFormatType format, const void *data) const
void Texture2D::LoadData(TextureFormatType format, const void *data)
{
const TextureFormat& fmt = textureFormatMap[static_cast<int>(format)];
glTexImage2D(
m_target,
0,
fmt.internalFormat,
m_width, m_height, 0,
fmt.format, fmt.type,
data
);
if (!m_hasInitialData) {
// Initialize texture storage and optionally upload data
glTexImage2D(
m_target,
0,
fmt.internalFormat,
m_width, m_height, 0,
fmt.format, fmt.type,
data
);
m_hasInitialData = true;
} else {
// Update existing texture data
glTexSubImage2D(
m_target,
0,
0, 0, m_width, m_height,
fmt.format, fmt.type,
data
);
}
}
void Texture3D::LoadData(TextureFormatType format, const void *data) const
void Texture3D::LoadData(TextureFormatType format, const void *data)
{
const TextureFormat& fmt = textureFormatMap[static_cast<int>(format)];
glTexImage3D(
m_target,
0,
fmt.internalFormat,
m_width, m_height, m_depth, 0,
fmt.format, fmt.type,
data
);
if (!m_hasInitialData) {
// Initialize texture storage with null data to allocate GPU memory
glTexImage3D(
m_target,
0,
fmt.internalFormat,
m_width, m_height, m_depth, 0,
fmt.format, fmt.type,
nullptr
);
m_hasInitialData = true;
} else {
// Update existing texture data
glTexSubImage3D(
m_target,
0,
0, 0, 0, m_width, m_height, m_depth,
fmt.format, fmt.type,
data
);
}
}