Compare commits

...

3 Commits

Author SHA1 Message Date
Almamu
822891008d fix: casts on old ffmpeg versions 2025-09-05 03:45:48 +02:00
Almamu
8012056342 chore: update to C++20 and take into account endianness 2025-09-05 03:28:25 +02:00
Almamu
896cfe2c4c chore: moved texture assets parsing into the data model too 2025-09-05 01:56:22 +02:00
45 changed files with 778 additions and 623 deletions

View File

@ -7,7 +7,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()
set_property(GLOBAL PROPERTY OS_FOLDERS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
set(OpenGL_GL_PREFERENCE "LEGACY")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@ -104,6 +104,8 @@ find_package(CEF REQUIRED)
# remove some switches that forbid us from using things that are commonplace in our codebase
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -fno-exceptions)
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -fno-rtti)
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -std=c++17)
list(APPEND CEF_CXX_COMPILER_FLAGS -std=c++20)
# remove the vulkan library from the files to copy so it doesn't fail after removing it
list(REMOVE_ITEM CEF_BINARY_FILES libvulkan.so.1)
@ -400,6 +402,8 @@ add_executable(
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
src/WallpaperEngine/Data/Assets/Types.h
src/WallpaperEngine/Data/Assets/Texture.h
src/WallpaperEngine/Data/Model/Types.h
src/WallpaperEngine/Data/Model/Project.h
src/WallpaperEngine/Data/Model/Wallpaper.h
@ -413,7 +417,12 @@ add_executable(
src/WallpaperEngine/Data/Model/Property.h
src/WallpaperEngine/Data/Utils/TypeCaster.cpp
src/WallpaperEngine/Data/Utils/TypeCaster.h
src/WallpaperEngine/Data/Utils/BinaryReader.cpp
src/WallpaperEngine/Data/Utils/BinaryReader.h
src/WallpaperEngine/Data/Utils/MemoryStream.h
src/WallpaperEngine/Data/Utils/SFINAE.h
src/WallpaperEngine/Data/Parsers/EffectParser.cpp
src/WallpaperEngine/Data/Parsers/EffectParser.h
src/WallpaperEngine/Data/Parsers/ProjectParser.cpp
src/WallpaperEngine/Data/Parsers/ProjectParser.h
src/WallpaperEngine/Data/Parsers/WallpaperParser.cpp
@ -430,18 +439,18 @@ add_executable(
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.h
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp
src/WallpaperEngine/Data/Parsers/PropertyParser.h
src/WallpaperEngine/Data/Parsers/TextureParser.cpp
src/WallpaperEngine/Data/Parsers/TextureParser.h
src/WallpaperEngine/Data/Builders/UserSettingBuilder.h
src/WallpaperEngine/Data/Builders/VectorBuilder.cpp
src/WallpaperEngine/Data/Builders/VectorBuilder.h
${WAYLAND_SOURCES}
${X11_SOURCES}
${DEMOMODE_SOURCES}
src/WallpaperEngine/Data/Dumpers/StringPrinter.cpp
src/WallpaperEngine/Data/Dumpers/StringPrinter.h
src/WallpaperEngine/Data/JSON.cpp
src/WallpaperEngine/Data/Parsers/EffectParser.cpp
src/WallpaperEngine/Data/Parsers/EffectParser.h)
${WAYLAND_SOURCES}
${X11_SOURCES}
${DEMOMODE_SOURCES})
target_link_libraries (linux-wallpaperengine PUBLIC
${OPENGL_LIBRARIES}

View File

@ -52,8 +52,8 @@ endfunction()
# SET_EXECUTABLE_TARGET_PROPERTIES() instead of calling this macro directly.
macro(REPLACED_SET_COMMON_TARGET_PROPERTIES target)
# Compile flags. (MODIFIED FOR C/C++ SEPARATION)
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C>:${CEF_COMPILER_FLAGS}>)
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${CEF_CXX_COMPILER_FLAGS}>)
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C>:${CEF_COMPILER_FLAGS} ${CEF_C_COMPILER_FLAGS}>)
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${CEF_COMPILER_FLAGS} ${CEF_CXX_COMPILER_FLAGS}>)
target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:${CEF_COMPILER_FLAGS_DEBUG} ${CEF_CXX_COMPILER_FLAGS_DEBUG}>)
target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:${CEF_COMPILER_FLAGS_RELEASE} ${CEF_CXX_COMPILER_FLAGS_RELEASE}>)

View File

@ -118,14 +118,14 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) :
.help ("Clamp mode to use when rendering the background, this applies to the previous --window or --screen-root output, or the default background if no other background is specified")
.choices("clamp", "border", "repeat")
.action([this, &lastScreen](const std::string& value) -> void {
WallpaperEngine::Assets::ITexture::TextureFlags flags;
TextureFlags flags;
if (value == "clamp") {
flags = WallpaperEngine::Assets::ITexture::TextureFlags::ClampUVs;
flags = TextureFlags_ClampUVs;
} else if (value == "border") {
flags = WallpaperEngine::Assets::ITexture::TextureFlags::ClampUVsBorder;
flags = TextureFlags_ClampUVsBorder;
} else if (value == "repeat") {
flags = WallpaperEngine::Assets::ITexture::TextureFlags::NoFlags;
flags = TextureFlags_NoFlags;
} else {
sLog.exception ("Invalid clamp mode: ", value);
}
@ -192,7 +192,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) :
screenshotGroup.add_argument ("--screenshot-delay")
.help ("Frames to wait before taking the screenshot")
.default_value (5)
.default_value <uint32_t> (5)
.store_into (this->settings.screenshot.delay);
auto& contentGroup = program.add_group ("Content options");
@ -263,7 +263,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) :
}
this->settings.audio.volume = std::max(0, std::min (this->settings.audio.volume, 128));
this->settings.screenshot.delay = std::max (0, std::min (this->settings.screenshot.delay, 5));
this->settings.screenshot.delay = std::max <uint32_t> (0, std::min <uint32_t> (this->settings.screenshot.delay, 5));
// use std::cout on this in case logging is disabled, this way it's easy to look at what is running
std::stringbuf buffer;

View File

@ -15,6 +15,7 @@
#include "WallpaperEngine/Data/Model/Project.h"
namespace WallpaperEngine::Application {
using namespace WallpaperEngine::Data::Assets;
/**
* Application information as parsed off the command line arguments
*/
@ -51,7 +52,7 @@ class CApplicationContext {
/** The scaling mode for different screens */
std::map<std::string, WallpaperEngine::Render::CWallpaperState::TextureUVsScaling> screenScalings;
/** The clamping mode for different screens */
std::map<std::string, WallpaperEngine::Assets::ITexture::TextureFlags> screenClamps;
std::map<std::string, TextureFlags> screenClamps;
} general;
/**
@ -68,7 +69,7 @@ class CApplicationContext {
struct {
/** The window size used in explicit window */
glm::ivec4 geometry;
WallpaperEngine::Assets::ITexture::TextureFlags clamp;
TextureFlags clamp;
WallpaperEngine::Render::CWallpaperState::TextureUVsScaling scalingMode;
} window;
} render;
@ -104,7 +105,7 @@ class CApplicationContext {
/** If an screenshot should be taken */
bool take;
/** The frames to wait until the screenshot is taken */
int delay;
uint32_t delay;
/** The path to where the screenshot must be saved */
std::filesystem::path path;
} screenshot;
@ -125,7 +126,7 @@ class CApplicationContext {
.pauseOnFullscreen = true,
.window = {
.geometry = {},
.clamp = WallpaperEngine::Assets::ITexture::TextureFlags::ClampUVs,
.clamp = TextureFlags_ClampUVs,
.scalingMode = WallpaperEngine::Render::CWallpaperState::TextureUVsScaling::DefaultUVs,
},
},

View File

@ -421,7 +421,6 @@ void CWallpaperApplication::show () {
std::vector<uint8_t> pixels(width * height * 3);
bool initialized = false;
int frame = 0;
int elapsed_frames = 0;
#endif /* DEMOMODE */
while (this->m_context.state.general.keepRunning) {
@ -447,12 +446,10 @@ void CWallpaperApplication::show () {
}
#if DEMOMODE
elapsed_frames ++;
// wait for a full render cycle before actually starting
// this gives some extra time for video and web decoders to set themselves up
// because of size changes
if (elapsed_frames > this->m_context.settings.render.maximumFPS) {
if (m_videoDriver->getFrameCounter () > this->m_context.settings.render.maximumFPS) {
if (!initialized) {
width = this->m_renderContext->getWallpapers ().begin ()->second->getWidth ();
height = this->m_renderContext->getWallpapers ().begin ()->second->getHeight ();

View File

@ -1,6 +1,9 @@
#include "CContainer.h"
#include "CAssetLoadException.h"
#include "CTexture.h"
#include "WallpaperEngine/Data/Utils/BinaryReader.h"
#include "WallpaperEngine/Data/Utils/MemoryStream.h"
#include "WallpaperEngine/Data/Parsers/TextureParser.h"
#include "WallpaperEngine/Logging/CLog.h"
#include <cstring>
@ -8,6 +11,8 @@
#include <utility>
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Data::Utils;
using namespace WallpaperEngine::Data::Parsers;
std::filesystem::path CContainer::resolveRealFile (const std::filesystem::path& filename) const {
throw CAssetLoadException (filename, "Cannot resolve physical file in this container");
@ -17,8 +22,13 @@ std::shared_ptr <const ITexture> CContainer::readTexture (const std::filesystem:
// get the texture's filename (usually .tex)
std::filesystem::path texture = "materials" / std::filesystem::path (filename.string ().append (".tex"));
const auto textureContents = this->readFile (texture, nullptr);
const auto result = std::make_shared<CTexture> (textureContents);
uint32_t length = 0;
const auto textureContents = this->readFile (texture, &length);
// TODO: MAKE PROPER USE OF I/OSTREAMS IN THE CLASS INSTEAD OF INSTANTIATING THINGS HERE...
auto buffer = MemoryStream (reinterpret_cast<char*> (const_cast<unsigned char*> (&textureContents.get () [0])), length);
auto istream = std::istream (&buffer);
auto binaryReader = BinaryReader (istream);
const auto result = std::make_shared<CTexture> (TextureParser::parse (binaryReader));
#if !NDEBUG
glObjectLabel (GL_TEXTURE, result->getTextureID (0), -1, texture.c_str ());

View File

@ -6,6 +6,7 @@
#include <string>
namespace WallpaperEngine::Assets {
class ITexture;
/**
* File container, provides access to files for backgrounds

View File

@ -10,10 +10,8 @@
using namespace WallpaperEngine::Assets;
CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resolution () {
CTexture::CTexture (TextureUniquePtr header) : m_header (std::move(header)) {
// ensure the header is parsed
const void* fileData = buffer.get ();
this->m_header = parseHeader (static_cast<const char*> (fileData));
this->setupResolution ();
GLint internalFormat = this->setupInternalFormat();
@ -39,7 +37,7 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
uint32_t bufferSize = (*cur)->uncompressedSize;
GLenum textureFormat = GL_RGBA;
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
int fileChannels;
dataptr = handle = stbi_load_from_memory (
@ -50,11 +48,11 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
&fileChannels,
4);
} else {
if (this->m_header->format == TextureFormat::R8) {
if (this->m_header->format == TextureFormat_R8) {
// red textures are 1-byte-per-pixel, so it's alignment has to be set manually
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
textureFormat = GL_RED;
} else if (this->m_header->format == TextureFormat::RG88) {
} else if (this->m_header->format == TextureFormat_RG88) {
textureFormat = GL_RG;
}
}
@ -78,7 +76,7 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
}
// stbi_image buffer won't be used anymore, so free memory
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
stbi_image_free (handle);
}
}
@ -87,10 +85,12 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
void CTexture::setupResolution () {
if (this->isAnimated ()) {
this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->gifWidth,
this->m_header->gifHeight};
this->m_resolution = {
this->m_header->textureWidth, this->m_header->textureHeight,
this->m_header->gifWidth, this->m_header->gifHeight
};
} else {
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
// wpengine-texture format always has one mipmap
// get first image size
auto element = this->m_header->images.find (0)->second.begin ();
@ -99,14 +99,16 @@ void CTexture::setupResolution () {
this->m_resolution = {(*element)->width, (*element)->height, this->m_header->width, this->m_header->height};
} else {
// set the texture resolution
this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->width,
this->m_header->height};
this->m_resolution = {
this->m_header->textureWidth, this->m_header->textureHeight,
this->m_header->width, this->m_header->height
};
}
}
}
GLint CTexture::setupInternalFormat () {
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
return GL_RGBA8;
// set some extra information too as it's used for image sizing
// this ensures that a_TexCoord uses the full image instead of just part of it
@ -118,12 +120,12 @@ GLint CTexture::setupInternalFormat () {
} else {
// detect the image format and hand it to openGL to be used
switch (this->m_header->format) {
case TextureFormat::DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
case TextureFormat::DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case TextureFormat::DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case TextureFormat::ARGB8888: return GL_RGBA8; break;
case TextureFormat::R8: return GL_R8; break;
case TextureFormat::RG88: return GL_RG8; break;
case TextureFormat_DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
case TextureFormat_DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case TextureFormat_DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case TextureFormat_ARGB8888: return GL_RGBA8; break;
case TextureFormat_R8: return GL_R8; break;
case TextureFormat_RG88: return GL_RG8; break;
default: sLog.exception ("Cannot determine texture format");
}
}
@ -138,7 +140,7 @@ void CTexture::setupOpenGLParameters (uint32_t textureID) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->m_header->images [textureID].size () - 1);
// setup texture wrapping and filtering
if (this->m_header->flags & TextureFlags::ClampUVs) {
if (this->m_header->flags & TextureFlags_ClampUVs) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} else {
@ -146,7 +148,7 @@ void CTexture::setupOpenGLParameters (uint32_t textureID) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
if (this->m_header->flags & TextureFlags::NoInterpolation) {
if (this->m_header->flags & TextureFlags_NoInterpolation) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
} else {
@ -167,298 +169,46 @@ GLuint CTexture::getTextureID (uint32_t imageIndex) const {
uint32_t CTexture::getTextureWidth (uint32_t imageIndex) const {
if (imageIndex >= this->m_header->imageCount)
return this->getHeader ()->textureWidth;
return this->getHeader ().textureWidth;
return (*this->m_header->images [imageIndex].begin ())->width;
}
uint32_t CTexture::getTextureHeight (uint32_t imageIndex) const {
if (imageIndex >= this->m_header->imageCount)
return this->getHeader ()->textureHeight;
return this->getHeader ().textureHeight;
return (*this->m_header->images [imageIndex].begin ())->height;
}
uint32_t CTexture::getRealWidth () const {
return this->isAnimated () ? this->getHeader ()->gifWidth : this->getHeader ()->width;
return this->isAnimated () ? this->getHeader ().gifWidth : this->getHeader ().width;
}
uint32_t CTexture::getRealHeight () const {
return this->isAnimated () ? this->getHeader ()->gifHeight : this->getHeader ()->height;
return this->isAnimated () ? this->getHeader ().gifHeight : this->getHeader ().height;
}
ITexture::TextureFormat CTexture::getFormat () const {
return this->getHeader ()->format;
TextureFormat CTexture::getFormat () const {
return this->getHeader ().format;
}
ITexture::TextureFlags CTexture::getFlags () const {
return this->getHeader ()->flags;
uint32_t CTexture::getFlags () const {
return this->getHeader ().flags;
}
const CTexture::TextureHeader* CTexture::getHeader () const {
return this->m_header.get ();
const Texture& CTexture::getHeader () const {
return *this->m_header;
}
const glm::vec4* CTexture::getResolution () const {
return &this->m_resolution;
}
const std::vector<std::shared_ptr<ITexture::TextureFrame>>& CTexture::getFrames () const {
return this->getHeader ()->frames;
const std::vector<FrameSharedPtr>& CTexture::getFrames () const {
return this->getHeader ().frames;
}
bool CTexture::isAnimated () const {
return this->getHeader ()->isAnimated ();
}
void CTexture::TextureMipmap::decompressData () {
if (this->compression != 1) {
return;
}
this->uncompressedData = std::unique_ptr <char[]> (new char [this->uncompressedSize]);
const int result = LZ4_decompress_safe (
this->compressedData.get (), this->uncompressedData.get (), this->compressedSize,
this->uncompressedSize);
if (!result)
sLog.exception ("Cannot decompress texture data, LZ4_decompress_safe returned an error");
}
CTexture::TextureFrame::TextureFrame () :
frameNumber (0),
frametime (0.0f),
x (0),
y (0),
width1 (0),
width2 (0),
height1 (0),
height2 (0) {}
CTexture::TextureHeader::TextureHeader () :
flags (NoFlags),
width (0),
height (0),
textureWidth (0),
textureHeight (0),
gifWidth (0),
gifHeight (0),
format (TextureFormat::UNKNOWN),
imageCount (0),
isVideoMp4 (false) {}
std::unique_ptr<CTexture::TextureHeader> CTexture::parseHeader (const char* fileData) {
// check the magic value on the header first
if (strncmp (fileData, "TEXV0005", 9) != 0)
sLog.exception ("unexpected texture container type: ", std::string_view (fileData, 9));
// jump to the next value
fileData += 9;
// check the sub-magic value on the header
if (strncmp (fileData, "TEXI0001", 9) != 0)
sLog.exception ("unexpected texture sub-container type: ", std::string_view (fileData, 9));
// jump through the string again
fileData += 9;
auto header = std::make_unique <TextureHeader> ();
const auto* pointer = reinterpret_cast<const uint32_t*> (fileData);
header->format = static_cast<TextureFormat> (*pointer++);
header->flags = static_cast<TextureFlags> (*pointer++);
header->textureWidth = *pointer++;
header->textureHeight = *pointer++;
header->width = *pointer++;
header->height = *pointer++;
pointer++; // ignore some more bytes
// now we're going to parse some more data that is string
// so get the current position back as string
fileData = reinterpret_cast<const char*> (pointer);
// get the position of what comes after the texture data
pointer = reinterpret_cast<const uint32_t*> (fileData + 9);
header->imageCount = *pointer++;
if (strncmp (fileData, "TEXB0004", 9) == 0) {
header->containerVersion = ContainerVersion::TEXB0004;
header->freeImageFormat = static_cast<FreeImageFormat> (*pointer++);
header->isVideoMp4 = *pointer++ == 1;
if (header->freeImageFormat == FIF_UNKNOWN && header->isVideoMp4) {
header->freeImageFormat = FIF_MP4;
}
// default to TEXB0003 behavior if no mp4 video is there
if (header->freeImageFormat != FIF_MP4) {
header->containerVersion = ContainerVersion::TEXB0003;
}
} else if (strncmp (fileData, "TEXB0003", 9) == 0) {
header->containerVersion = ContainerVersion::TEXB0003;
header->freeImageFormat = static_cast<FreeImageFormat> (*pointer++);
} else if (strncmp (fileData, "TEXB0002", 9) == 0) {
header->containerVersion = ContainerVersion::TEXB0002;
} else if (strncmp (fileData, "TEXB0001", 9) == 0) {
header->containerVersion = ContainerVersion::TEXB0001;
} else {
sLog.exception ("unknown texture format type: ", std::string_view (fileData, 9));
}
for (uint32_t image = 0; image < header->imageCount; image++) {
// read the number of mipmaps available for this image
uint32_t mipmapCount = *pointer++;
std::vector<std::shared_ptr<TextureMipmap>> mipmaps;
fileData = reinterpret_cast<const char*> (pointer);
for (uint32_t i = 0; i < mipmapCount; i++)
mipmaps.emplace_back (parseMipmap (header.get (), &fileData));
// add the pixmaps back
header->images.emplace (image, mipmaps);
pointer = reinterpret_cast<const uint32_t*> (fileData);
}
// gifs have extra information after the mipmaps
if (header->isAnimated ()) {
if (strncmp (fileData, "TEXS0002", 9) == 0) {
header->animatedVersion = AnimatedVersion::TEXS0002;
} else if (strncmp (fileData, "TEXS0003", 9) == 0) {
header->animatedVersion = AnimatedVersion::TEXS0003;
} else {
sLog.exception ("found animation information of unknown type: ", std::string_view (fileData, 9));
}
// get an integer pointer back to read the frame count
pointer = reinterpret_cast<const uint32_t*> (fileData + 9);
uint32_t framecount = *pointer++;
if (header->animatedVersion == AnimatedVersion::TEXS0003) {
// ignore two extra integers as those are width and height of the git
header->gifWidth = *pointer++;
header->gifHeight = *pointer++;
}
// get back the pointer into filedata
fileData = reinterpret_cast<const char*> (pointer);
while (framecount > 0) {
// add the frame to the list
header->frames.push_back (parseAnimation (&fileData));
framecount--;
}
// ensure gif width and height is right for TEXS0002
if (header->animatedVersion == AnimatedVersion::TEXS0002) {
auto first = *header->frames.begin ();
header->gifWidth = first->width1;
header->gifHeight = first->height1;
}
}
return header;
}
std::shared_ptr<CTexture::TextureFrame> CTexture::parseAnimation (const char** originalFileData) {
const char* fileData = *originalFileData;
// get back the pointer into integer
const auto* pointer = reinterpret_cast<const uint32_t*> (fileData);
// start reading frame information
auto frame = std::make_shared <TextureFrame> ();
frame->frameNumber = *pointer++;
// reinterpret the pointer into float
const auto* fPointer = reinterpret_cast<const float*> (pointer);
frame->frametime = *fPointer++;
frame->x = *fPointer++;
frame->y = *fPointer++;
frame->width1 = *fPointer++;
frame->width2 = *fPointer++;
frame->height2 = *fPointer++;
frame->height1 = *fPointer++;
// get back the pointer into fileData so it can be reused later
*originalFileData = reinterpret_cast<const char*> (fPointer);
return frame;
}
std::shared_ptr<CTexture::TextureMipmap> CTexture::parseMipmap (const TextureHeader* header, const char** originalFileData) {
auto mipmap = std::make_shared <TextureMipmap> ();
// get the current position
const char* fileData = *originalFileData;
// get an integer pointer
const auto* pointer = reinterpret_cast<const uint32_t*> (fileData);
// TEXB004 have some extra data (and even json) that we have to take into account
if (header->containerVersion == ContainerVersion::TEXB0004) {
// ignore various params, RePKG doesn't really use them
// and could be related to the editor really, so just ignore them
pointer++;
pointer++;
fileData = reinterpret_cast<const char*> (pointer);
while (*fileData != 0) {
mipmap->json += *fileData++;
}
// skip the null terminator
fileData ++;
pointer = reinterpret_cast<const uint32_t*> (fileData);
// this is another param to ignore
pointer++;
}
mipmap->width = *pointer++;
mipmap->height = *pointer++;
if (header->containerVersion == ContainerVersion::TEXB0002 ||
header->containerVersion == ContainerVersion::TEXB0003 ||
header->containerVersion == ContainerVersion::TEXB0004) {
mipmap->compression = *pointer++;
mipmap->uncompressedSize = *pointer++;
}
mipmap->compressedSize = *pointer++;
// get back a normal char pointer
fileData = reinterpret_cast<const char*> (pointer);
if (mipmap->compression == 0) {
// this might be better named as mipmap_bytes_size instead of compressedSize
// as in uncompressed files this variable actually holds the file length
mipmap->uncompressedSize = mipmap->compressedSize;
}
mipmap->uncompressedData = std::unique_ptr<char[]>(new char [mipmap->uncompressedSize]);
if (mipmap->compression == 1) {
mipmap->compressedData = std::unique_ptr<char[]>(new char [mipmap->compressedSize]);
memcpy (mipmap->compressedData.get (), fileData, mipmap->compressedSize);
mipmap->decompressData ();
// advance to the end of the mipmap
fileData += mipmap->compressedSize;
} else {
memcpy (mipmap->uncompressedData.get (), fileData, mipmap->uncompressedSize);
// advance to the end of the mipmap
fileData += mipmap->uncompressedSize;
}
// ensure the pointer is updated with the latest position when reading the data
*originalFileData = fileData;
return mipmap;
}
bool CTexture::TextureHeader::isAnimated () const {
return this->flags & TextureFlags::IsGif;
return this->getHeader ().isAnimated ();
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "ITexture.h"
#include "WallpaperEngine/Data/Assets/Texture.h"
#include <GL/glew.h>
#include <glm/vec4.hpp>
@ -11,144 +12,14 @@
#include <vector>
namespace WallpaperEngine::Assets {
using namespace WallpaperEngine::Data::Assets;
/**
* A normal texture file in WallpaperEngine's format
*/
class CTexture final : public ITexture {
/**
* Different texture container versions supported
*/
enum ContainerVersion : int {
UNKNOWN = -1,
TEXB0004 = 4,
TEXB0003 = 3,
TEXB0002 = 2,
TEXB0001 = 1
};
/**
* Different texture animation versions supported
*/
enum AnimatedVersion : int {
TEXSUNKN = -1,
TEXS0002 = 0,
TEXS0003 = 1,
};
enum FreeImageFormat : int {
FIF_UNKNOWN = -1,
FIF_BMP = 0,
FIF_ICO = 1,
FIF_JPEG = 2,
FIF_JNG = 3,
FIF_KOALA = 4,
FIF_LBM = 5,
FIF_IFF = FIF_LBM,
FIF_MNG = 6,
FIF_PBM = 7,
FIF_PBMRAW = 8,
FIF_PCD = 9,
FIF_PCX = 10,
FIF_PGM = 11,
FIF_PGMRAW = 12,
FIF_PNG = 13,
FIF_PPM = 14,
FIF_PPMRAW = 15,
FIF_RAS = 16,
FIF_TARGA = 17,
FIF_TIFF = 18,
FIF_WBMP = 19,
FIF_PSD = 20,
FIF_CUT = 21,
FIF_XBM = 22,
FIF_XPM = 23,
FIF_DDS = 24,
FIF_GIF = 25,
FIF_HDR = 26,
FIF_FAXG3 = 27,
FIF_SGI = 28,
FIF_EXR = 29,
FIF_J2K = 30,
FIF_JP2 = 31,
FIF_PFM = 32,
FIF_PICT = 33,
FIF_RAW = 34,
FIF_WEBP = 35,
FIF_MP4 = FIF_WEBP,
FIF_JXR = 36
};
/**
* Texture mipmap data
*/
class TextureMipmap {
public:
/** Width of the mipmap */
uint32_t width = 0;
/** Height of the mipmap */
uint32_t height = 0;
/** If the mipmap data is compressed */
uint32_t compression = 0;
/** Uncompressed size of the mipmap */
uint32_t uncompressedSize = 0;
/** Compress size of the mipmap */
uint32_t compressedSize = 0;
/** Pointer to the compressed data */
std::unique_ptr<char[]> compressedData = nullptr;
/** Pointer to the uncompressed data */
std::unique_ptr<char[]> uncompressedData = nullptr;
/** JSON data */
std::string json {};
/**
* Performs actual decompression of the compressed data
*/
void decompressData ();
};
/**
* Texture header data
*/
class TextureHeader {
public:
TextureHeader ();
~TextureHeader () = default;
[[nodiscard]] bool isAnimated () const;
/** The version of the texture container */
ContainerVersion containerVersion = ContainerVersion::UNKNOWN;
/** The version of the animated data */
AnimatedVersion animatedVersion = AnimatedVersion::TEXSUNKN;
/** Flags with extra texture information */
TextureFlags flags = TextureFlags::NoFlags;
/** Real width of the texture */
uint32_t width = 0;
/** Real height of the texture */
uint32_t height = 0;
/** Texture width in memory (power of 2) */
uint32_t textureWidth = 0;
/** Texture height in memory (power of 2) */
uint32_t textureHeight = 0;
/** Gif width */
uint32_t gifWidth = 0;
/** Gif height */
uint32_t gifHeight = 0;
/** Texture data format */
TextureFormat format = TextureFormat::UNKNOWN;
/** Free Image format */
FreeImageFormat freeImageFormat = FreeImageFormat::FIF_UNKNOWN;
/** Indicates if we have an MP4 video */
bool isVideoMp4 = false;
/** The amount of images in the texture file */
uint32_t imageCount = 0;
/** List of mipmaps */
std::map<uint32_t, std::vector<std::shared_ptr<TextureMipmap>>> images {};
/** List of animation frames */
std::vector<std::shared_ptr<TextureFrame>> frames {};
};
public:
explicit CTexture (const std::shared_ptr<const uint8_t[]>& fileData);
explicit CTexture (TextureUniquePtr header);
[[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
[[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
@ -156,39 +27,16 @@ class CTexture final : public ITexture {
[[nodiscard]] uint32_t getRealWidth () const override;
[[nodiscard]] uint32_t getRealHeight () const override;
[[nodiscard]] TextureFormat getFormat () const override;
[[nodiscard]] TextureFlags getFlags () const override;
[[nodiscard]] uint32_t getFlags () const override;
[[nodiscard]] const glm::vec4* getResolution () const override;
[[nodiscard]] const std::vector<std::shared_ptr<TextureFrame>>& getFrames () const override;
[[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
[[nodiscard]] bool isAnimated () const override;
private:
/**
* @return The texture header
*/
[[nodiscard]] const TextureHeader* getHeader () const;
/**
* Tries to parse a header off the given data pointer
*
* @param fileData The point at which to start reading data off from
* @return
*/
static std::unique_ptr<TextureHeader> parseHeader (const char* fileData);
/**
* Tries to parse an animation frame off the given data pointer
*
* @param originalFileData The point at which to start reading data off from
* @return
*/
static std::shared_ptr<TextureFrame> parseAnimation (const char** originalFileData);
/**
* Tries to parse mipmap information off the given data pointer
*
* @param header The file header
* @param fileData The point at which to start reading data off from
* @return
*/
static std::shared_ptr<TextureMipmap> parseMipmap (const TextureHeader* header, const char** fileData);
[[nodiscard]] const Texture& getHeader () const;
/**
* Calculate's texture's resolution vec4
@ -204,7 +52,7 @@ class CTexture final : public ITexture {
void setupOpenGLParameters (uint32_t textureID);
/** The texture header */
std::unique_ptr<TextureHeader> m_header = nullptr;
TextureUniquePtr m_header;
/** OpenGL's texture ID */
GLuint* m_textureID = nullptr;
/** Resolution vector of the texture */

View File

@ -6,7 +6,11 @@
#include <GL/glew.h>
#include <glm/vec4.hpp>
#include "WallpaperEngine/Data/Assets/Texture.h"
#include "WallpaperEngine/Data/Model/Types.h"
namespace WallpaperEngine::Assets {
using namespace WallpaperEngine::Data::Assets;
/**
* Base interface that describes the minimum information required for a texture
* to be displayed by the engine
@ -15,62 +19,6 @@ class ITexture {
public:
virtual ~ITexture () = default;
/**
* Texture frame information for animated textures
*/
class TextureFrame final {
public:
TextureFrame ();
virtual ~TextureFrame () = default;
/** The image index of this frame */
uint32_t frameNumber = 0;
/** The amount of time this frame spends being displayed */
float frametime = 0.0f;
/** The x position of the frame in the texture */
float x = 0.0f;
/** The y position of the frame in the texture */
float y = 0.0f;
/** The width of the frame in the texture */
float width1 = 0.0f;
float width2 = 0.0f;
/** The height of the frame in the texture */
float height1 = 0.0f;
float height2 = 0.0f;
};
/**
* Data formats for textures in memory
*/
enum TextureFormat : uint32_t {
UNKNOWN = 0xFFFFFFFF,
ARGB8888 = 0,
RGB888 = 1,
RGB565 = 2,
DXT5 = 4,
DXT3 = 6,
DXT1 = 7,
RG88 = 8,
R8 = 9,
RG1616f = 10,
R16f = 11,
BC7 = 12,
RGBa1010102 = 13,
RGBA16161616f = 14,
RGB161616f = 15,
};
/**
* Different settings of the textures
*/
enum TextureFlags : uint32_t {
NoFlags = 0,
NoInterpolation = 1,
ClampUVs = 2,
IsGif = 4,
ClampUVsBorder = 8,
};
/**
* @param imageIndex For animated textures, the frame to get the ID of
* @return The OpenGL texture to use when rendering
@ -101,11 +49,11 @@ class ITexture {
/**
* @return The texture's settings
*/
[[nodiscard]] virtual TextureFlags getFlags () const = 0;
[[nodiscard]] virtual uint32_t getFlags () const = 0;
/**
* @return The list of frames this texture has
*/
[[nodiscard]] virtual const std::vector<std::shared_ptr<TextureFrame>>& getFrames () const = 0;
[[nodiscard]] virtual const std::vector<FrameSharedPtr>& getFrames () const = 0;
/**
* @return The texture's resolution vector
*/

View File

@ -252,7 +252,7 @@ bool CAudioStream::doQueue (AVPacket* pkt) {
MyAVPacketList entry {pkt};
#if FF_API_FIFO_OLD_API
if (av_fifo_space (this->m_queue->packetList) < sizeof (entry))
if (av_fifo_space (this->m_queue->packetList) < static_cast <int> (sizeof (entry)))
if (av_fifo_grow (this->m_queue->packetList, sizeof (entry)) < 0)
return false;
@ -281,7 +281,7 @@ void CAudioStream::dequeuePacket (AVPacket* output) {
#if FF_API_FIFO_OLD_API
int ret = -1;
if (av_fifo_size (this->m_queue->packetList) >= sizeof (entry))
if (av_fifo_size (this->m_queue->packetList) >= static_cast <int> (sizeof (entry)))
ret = av_fifo_generic_read (this->m_queue->packetList, &entry, sizeof (entry), nullptr);
#else
int ret = av_fifo_read (this->m_queue->packetList, &entry, 1);

View File

@ -0,0 +1,170 @@
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include "Types.h"
namespace WallpaperEngine::Data::Assets {
enum ContainerVersion {
ContainerVersion_UNKNOWN = 0,
ContainerVersion_TEXB0001 = 1,
ContainerVersion_TEXB0002 = 2,
ContainerVersion_TEXB0003 = 3,
ContainerVersion_TEXB0004 = 4,
};
enum AnimatedVersion {
AnimatedVersion_UNKNOWN = 0,
AnimatedVersion_TEXS0002 = 2,
AnimatedVersion_TEXS0003 = 3,
};
enum FIF {
FIF_UNKNOWN = -1,
FIF_BMP = 0,
FIF_ICO = 1,
FIF_JPEG = 2,
FIF_JNG = 3,
FIF_KOALA = 4,
FIF_LBM = 5,
FIF_IFF = FIF_LBM,
FIF_MNG = 6,
FIF_PBM = 7,
FIF_PBMRAW = 8,
FIF_PCD = 9,
FIF_PCX = 10,
FIF_PGM = 11,
FIF_PGMRAW = 12,
FIF_PNG = 13,
FIF_PPM = 14,
FIF_PPMRAW = 15,
FIF_RAS = 16,
FIF_TARGA = 17,
FIF_TIFF = 18,
FIF_WBMP = 19,
FIF_PSD = 20,
FIF_CUT = 21,
FIF_XBM = 22,
FIF_XPM = 23,
FIF_DDS = 24,
FIF_GIF = 25,
FIF_HDR = 26,
FIF_FAXG3 = 27,
FIF_SGI = 28,
FIF_EXR = 29,
FIF_J2K = 30,
FIF_JP2 = 31,
FIF_PFM = 32,
FIF_PICT = 33,
FIF_RAW = 34,
FIF_WEBP = 35,
FIF_MP4 = FIF_WEBP,
FIF_JXR = 36
};
enum TextureFormat {
TextureFormat_UNKNOWN = 0xFFFFFFFF,
TextureFormat_ARGB8888 = 0,
TextureFormat_RGB888 = 1,
TextureFormat_RGB565 = 2,
TextureFormat_DXT5 = 4,
TextureFormat_DXT3 = 6,
TextureFormat_DXT1 = 7,
TextureFormat_RG88 = 8,
TextureFormat_R8 = 9,
TextureFormat_RG1616f = 10,
TextureFormat_R16f = 11,
TextureFormat_BC7 = 12,
TextureFormat_RGBa1010102 = 13,
TextureFormat_RGBA16161616f = 14,
TextureFormat_RGB161616f = 15,
};
enum TextureFlags {
TextureFlags_NoFlags = 0,
TextureFlags_NoInterpolation = 1,
TextureFlags_ClampUVs = 2,
TextureFlags_IsGif = 4,
TextureFlags_ClampUVsBorder = 8,
TextureFlags_All =
TextureFlags_NoInterpolation | TextureFlags_ClampUVs |
TextureFlags_IsGif | TextureFlags_ClampUVsBorder,
};
struct Mipmap {
/** Width of the mipmap */
uint32_t width = 0;
/** Height of the mipmap */
uint32_t height = 0;
/** If the mipmap data is compressed */
uint32_t compression = 0;
/** Uncompressed size of the mipmap */
int uncompressedSize = 0;
/** Compress size of the mipmap */
int compressedSize = 0;
/** Pointer to the compressed data */
std::unique_ptr<char[]> compressedData = nullptr;
/** Pointer to the uncompressed data */
std::unique_ptr<char[]> uncompressedData = nullptr;
/** JSON data */
std::string json {};
};
struct Frame {
/** The image index of this frame */
uint32_t frameNumber = 0;
/** The amount of time this frame spends being displayed */
float frametime = 0.0f;
/** The x position of the frame in the texture */
float x = 0.0f;
/** The y position of the frame in the texture */
float y = 0.0f;
/** The width of the frame in the texture */
float width1 = 0.0f;
float width2 = 0.0f;
/** The height of the frame in the texture */
float height1 = 0.0f;
float height2 = 0.0f;
};
struct Texture {
/** The version of the texture container */
ContainerVersion containerVersion = ContainerVersion_UNKNOWN;
/** The version of the animated data */
AnimatedVersion animatedVersion = AnimatedVersion_UNKNOWN;
/** Flags with extra texture information @see TextureFlags */
uint32_t flags = TextureFlags_NoFlags;
/** Real width of the texture */
uint32_t width = 0;
/** Real height of the texture */
uint32_t height = 0;
/** Texture width in memory (power of 2) */
uint32_t textureWidth = 0;
/** Texture height in memory (power of 2) */
uint32_t textureHeight = 0;
/** Gif width */
uint32_t gifWidth = 0;
/** Gif height */
uint32_t gifHeight = 0;
/** Texture data format */
TextureFormat format = TextureFormat_UNKNOWN;
/** Free Image format */
FIF freeImageFormat = FIF_UNKNOWN;
/** Indicates if we have an MP4 video */
bool isVideoMp4 = false;
/** The amount of images in the texture file */
uint32_t imageCount = 0;
/** List of mipmaps */
std::map<uint32_t, MipmapList> images {};
/** List of animation frames */
std::vector<FrameSharedPtr> frames {};
[[nodiscard]] bool isAnimated () const {
return (flags & TextureFlags_IsGif) == TextureFlags_IsGif;
}
};
}

View File

@ -0,0 +1,15 @@
#pragma once
#include <memory>
#include <vector>
namespace WallpaperEngine::Data::Assets {
struct Mipmap;
struct Frame;
struct Texture;
using MipmapSharedPtr = std::shared_ptr <Mipmap>;
using FrameSharedPtr = std::shared_ptr <Frame>;
using TextureUniquePtr = std::unique_ptr <Texture>;
using MipmapList = std::vector <MipmapSharedPtr>;
}

View File

@ -40,13 +40,17 @@ class VectorBuilder {
if (first == nullptr) {
sLog.exception ("Invalid vector format: " + str + " (too few values, expected: 2, 3 or 4)");
} else if (second == nullptr) {
return 2;
} else if (third == nullptr) {
return 3;
} else {
return 4;
}
if (second == nullptr) {
return 2;
}
if (third == nullptr) {
return 3;
}
return 4;
}
/**
@ -64,6 +68,9 @@ class VectorBuilder {
*/
template <int length, typename type, glm::qualifier qualifier>
[[nodiscard]] static glm::vec<length, type, qualifier> parse (const std::string& str) {
// ensure a valid type is used, only 1 to 4 vectors are supported
static_assert (length >= 1 && length <= 4, "Invalid vector length");
const char* p = str.c_str ();
// get up to 4 spaces
@ -79,21 +86,22 @@ class VectorBuilder {
} else if constexpr (length == 2) {
if (first == nullptr) {
sLog.exception ("Invalid vector format: " + str + " (too few values, expected: ", length, ")");
} else if (second != nullptr) {
}
if (second != nullptr) {
sLog.exception ("Invalid vector format: " + str + " (too many values, expected: ", length, ")");
}
} else if constexpr (length == 3) {
if (first == nullptr || second == nullptr) {
sLog.exception ("Invalid vector format: " + str + " (too few values, expected: ", length, ")");
} else if (third != nullptr) {
}
if (third != nullptr) {
sLog.exception ("Invalid vector format: " + str + " (too many values, expected: ", length, ")");
}
} else if constexpr (length == 4) {
if (first == nullptr || second == nullptr || third == nullptr) {
sLog.exception ("Invalid vector format: " + str + " (too few values, expected: ", length, ")");
}
} else {
sLog.exception ("Invalid vector length: ", length);
}
// lengths validated, values can be used directly without issues
@ -112,7 +120,7 @@ class VectorBuilder {
convert <type> (first + 1),
convert <type> (second + 1)
};
} else {
} else if constexpr (length == 4) {
return {
convert <type> (p),
convert <type> (first + 1),

View File

@ -35,7 +35,7 @@ struct ObjectData {
*/
class Object : public TypeCaster, public ObjectData {
public:
explicit Object (ObjectData data) noexcept : ObjectData (std::move (data)), TypeCaster () {};
explicit Object (ObjectData data) noexcept : TypeCaster (), ObjectData (std::move (data)) {};
~Object () override = default;
};

View File

@ -27,7 +27,7 @@ struct ComboData {
class Property : public DynamicValue, public TypeCaster, public PropertyData {
public:
explicit Property (PropertyData data) : PropertyData (std::move(data)), TypeCaster (), DynamicValue () {}
explicit Property (PropertyData data) : DynamicValue (), TypeCaster (), PropertyData (std::move(data)) {}
using DynamicValue::update;
virtual void update(const std::string& value) = 0;

View File

@ -8,6 +8,11 @@
#include "WallpaperEngine/Assets/CContainer.h"
namespace WallpaperEngine::Assets {
class CContainer;
}
namespace WallpaperEngine::Data::Model {
struct Project;
class Wallpaper;

View File

@ -19,7 +19,7 @@ struct WallpaperData {
class Wallpaper : public TypeCaster, public WallpaperData {
public:
explicit Wallpaper (WallpaperData data) noexcept : WallpaperData (std::move(data)), TypeCaster () {};
explicit Wallpaper (WallpaperData data) noexcept : TypeCaster (), WallpaperData (std::move(data)) {};
~Wallpaper () override = default;
};

View File

@ -0,0 +1,257 @@
#include <cstring>
#include <lz4.h>
#include "TextureParser.h"
#include "WallpaperEngine/Data/Assets/Texture.h"
#include "WallpaperEngine/Logging/CLog.h"
using namespace WallpaperEngine::Data::Assets;
using namespace WallpaperEngine::Data::Parsers;
TextureUniquePtr TextureParser::parse (BinaryReader& file) {
char magic[9] = { 0 };
file.next (magic, 9);
if (strncmp (magic, "TEXV0005", 9) != 0)
sLog.exception ("unexpected texture container type: ", std::string_view (magic, 9));
file.next (magic, 9);
if (strncmp (magic, "TEXI0001", 9) != 0)
sLog.exception ("unexpected texture sub-container type: ", std::string_view (magic, 9));
auto result = std::make_unique<Texture> ();
result->format = parseTextureFormat (file.nextUInt32 ());
result->flags = parseTextureFlags (file.nextUInt32 ());
result->textureWidth = file.nextUInt32 ();
result->textureHeight = file.nextUInt32 ();
result->width = file.nextUInt32 ();
result->height = file.nextUInt32 ();
// ignore some more bytes
file.nextUInt32 ();
file.next (magic, 9);
result->imageCount = file.nextUInt32 ();
if (strncmp (magic, "TEXB0004", 9) == 0) {
result->containerVersion = ContainerVersion_TEXB0004;
result->freeImageFormat = parseFIF (file.nextUInt32 ());
result->isVideoMp4 = file.nextUInt32 () == 1;
if (result->freeImageFormat == FIF_UNKNOWN && result->isVideoMp4) {
result->freeImageFormat = FIF_MP4;
}
// default to TEXB0003 format here
if (result->freeImageFormat != FIF_MP4) {
result->containerVersion = ContainerVersion_TEXB0003;
}
} else if (strncmp (magic, "TEXB0003", 9) == 0) {
result->containerVersion = ContainerVersion_TEXB0003;
result->freeImageFormat = parseFIF (file.nextUInt32 ());
} else if (strncmp (magic, "TEXB0002", 9) == 0) {
result->containerVersion = ContainerVersion_TEXB0002;
} else if (strncmp (magic, "TEXB0001", 9) == 0) {
result->containerVersion = ContainerVersion_TEXB0001;
} else {
sLog.exception ("unknown texture format type: ", std::string_view (magic, 9));
}
for (uint32_t image = 0; image < result->imageCount; image++) {
uint32_t mipmapCount = file.nextUInt32 ();
MipmapList mipmaps;
for (uint32_t mipmap = 0; mipmap < mipmapCount; mipmap++) {
mipmaps.emplace_back (parseMipmap (file, *result));
}
result->images.emplace (image, mipmaps);
}
if (!result->isAnimated ()) {
return result;
}
// image is animated, keep parsing the rest of the image info
file.next (magic, 9);
if (strncmp (magic, "TEXS0002", 9) == 0) {
result->animatedVersion = AnimatedVersion_TEXS0002;
} else if (strncmp (magic, "TEXS0003", 9) == 0) {
result->animatedVersion = AnimatedVersion_TEXS0003;
} else {
sLog.exception ("found animation information of unknown type: ", std::string_view (magic, 9));
}
uint32_t frameCount = file.nextUInt32 ();
if (result->animatedVersion == AnimatedVersion_TEXS0003) {
result->gifWidth = file.nextUInt32 ();
result->gifHeight = file.nextUInt32 ();
}
while (frameCount-- > 0) {
result->frames.push_back (parseFrame (file, *result));
}
// ensure gif width and height is right for TEXS0002
if (result->animatedVersion == AnimatedVersion_TEXS0002) {
result->gifWidth = (*result->frames.begin ())->width1;
result->gifHeight = (*result->frames.begin ())->height1;
}
return result;
}
MipmapSharedPtr TextureParser::parseMipmap (BinaryReader& file, Texture& header) {
auto result = std::make_shared<Mipmap> ();
// TEXB0004 has some extra data in the header that has to be handled
if (header.containerVersion == ContainerVersion_TEXB0004) {
// some integers that we can ignore as they only seem to affect
// the editor
file.nextUInt32 ();
file.nextUInt32 ();
// this format includes some json in the header that we might need
// to parse at some point...
result->json = file.nextNullTerminatedString ();
// last ignorable integer
file.nextUInt32 ();
}
result->width = file.nextUInt32 ();
result->height = file.nextUInt32 ();
if (header.containerVersion == ContainerVersion_TEXB0004 ||
header.containerVersion == ContainerVersion_TEXB0003 ||
header.containerVersion == ContainerVersion_TEXB0002) {
result->compression = file.nextUInt32 ();
result->uncompressedSize = file.nextInt ();
}
result->compressedSize = file.nextInt ();
if (result->compression == 0) {
// this might be better named as mipmap_bytes_size instead of compressedSize
// as in uncompressed files this variable actually holds the file length
result->uncompressedSize = result->compressedSize;
}
result->uncompressedData = std::unique_ptr<char[]> (new char [result->uncompressedSize]);
if (result->compression == 1) {
result->compressedData = std::unique_ptr<char[]> (new char [result->compressedSize]);
// read the compressed data into the buffer
file.next (result->compressedData.get (), result->compressedSize);
// finally decompress it
int bytes = LZ4_decompress_safe (
result->compressedData.get (), result->uncompressedData.get (), result->compressedSize,
result->uncompressedSize
);
if (bytes < 0)
sLog.exception ("Cannot decompress texture data, LZ4_decompress_safe returned an error");
} else {
file.next (result->uncompressedData.get (), result->uncompressedSize);
}
return result;
}
FrameSharedPtr TextureParser::parseFrame (BinaryReader& file, Texture& header) {
auto result = std::make_shared<Frame> ();
result->frameNumber = file.nextUInt32 ();
result->frametime = file.nextFloat ();
result->x = file.nextFloat ();
result->y = file.nextFloat ();
result->width1 = file.nextFloat ();
result->width2 = file.nextFloat ();
result->height2 = file.nextFloat ();
result->height1 = file.nextFloat ();
return result;
}
TextureFormat TextureParser::parseTextureFormat (uint32_t value) {
switch (value) {
case TextureFormat_UNKNOWN:
case TextureFormat_ARGB8888:
case TextureFormat_RGB888:
case TextureFormat_RGB565:
case TextureFormat_DXT5:
case TextureFormat_DXT3:
case TextureFormat_DXT1:
case TextureFormat_RG88:
case TextureFormat_R8:
case TextureFormat_RG1616f:
case TextureFormat_R16f:
case TextureFormat_BC7:
case TextureFormat_RGBa1010102:
case TextureFormat_RGBA16161616f:
case TextureFormat_RGB161616f:
return static_cast<TextureFormat> (value);
default:
sLog.exception ("unknown texture format: ", value);
}
}
uint32_t TextureParser::parseTextureFlags (uint32_t value) {
if (value < TextureFlags_All) {
return value;
}
sLog.exception ("unknown texture flags: ", value);
}
FIF TextureParser::parseFIF (uint32_t value) {
switch (value) {
case FIF_UNKNOWN:
case FIF_BMP:
case FIF_ICO:
case FIF_JPEG:
case FIF_JNG:
case FIF_KOALA:
case FIF_LBM:
case FIF_MNG:
case FIF_PBM:
case FIF_PBMRAW:
case FIF_PCD:
case FIF_PCX:
case FIF_PGM:
case FIF_PGMRAW:
case FIF_PNG:
case FIF_PPM:
case FIF_PPMRAW:
case FIF_RAS:
case FIF_TARGA:
case FIF_TIFF:
case FIF_WBMP:
case FIF_PSD:
case FIF_CUT:
case FIF_XBM:
case FIF_XPM:
case FIF_DDS:
case FIF_GIF:
case FIF_HDR:
case FIF_FAXG3:
case FIF_SGI:
case FIF_EXR:
case FIF_J2K:
case FIF_JP2:
case FIF_PFM:
case FIF_PICT:
case FIF_RAW:
case FIF_WEBP:
case FIF_JXR:
return static_cast<FIF> (value);
default:
sLog.exception ("unknown free image format: ", value);
}
}

View File

@ -0,0 +1,25 @@
#pragma once
#include "WallpaperEngine/Data/Assets/Texture.h"
#include <iostream>
#include "WallpaperEngine/Data/Model/Types.h"
#include "WallpaperEngine/Data/Utils/BinaryReader.h"
namespace WallpaperEngine::Data::Parsers {
using namespace WallpaperEngine::Data::Utils;
using namespace WallpaperEngine::Data::Assets;
class TextureParser {
public:
static TextureUniquePtr parse (BinaryReader& file);
static MipmapSharedPtr parseMipmap (BinaryReader& file, Texture& header);
static FrameSharedPtr parseFrame (BinaryReader& file, Texture& header);
private:
static TextureFormat parseTextureFormat (uint32_t value);
static uint32_t parseTextureFlags (uint32_t value);
static FIF parseFIF (uint32_t value);
};
}

View File

@ -0,0 +1,77 @@
#include <iostream>
#include <bit>
#include "BinaryReader.h"
#include <cstring>
using namespace WallpaperEngine::Data::Utils;
BinaryReader::BinaryReader (std::istream& file) : m_input (file) { }
uint32_t BinaryReader::nextUInt32 () {
char buffer[4];
this->m_input.read (buffer, 4);
if constexpr (std::endian::native == std::endian::little) {
return (buffer [3] & 0xFF) << 24 |
(buffer [2] & 0xFF) << 16 |
(buffer [1] & 0xFF) << 8 |
(buffer [0] & 0xFF);
} else {
return (buffer [0] & 0xFF) << 24 |
(buffer [1] & 0xFF) << 16 |
(buffer [2] & 0xFF) << 8 |
(buffer [3] & 0xFF);
}
}
int BinaryReader::nextInt () {
char buffer[4];
this->m_input.read (buffer, 4);
if constexpr (std::endian::native == std::endian::little) {
return (buffer [3] & 0xFF) << 24 |
(buffer [2] & 0xFF) << 16 |
(buffer [1] & 0xFF) << 8 |
(buffer [0] & 0xFF);
} else {
return (buffer [0] & 0xFF) << 24 |
(buffer [1] & 0xFF) << 16 |
(buffer [2] & 0xFF) << 8 |
(buffer [3] & 0xFF);
}
}
float BinaryReader::nextFloat () {
float result;
static_assert (std::endian::native == std::endian::little, "Only little endian is supported for floats");
this->m_input.read (reinterpret_cast<char*>(&result), sizeof (result));
return result;
}
std::string BinaryReader::nextNullTerminatedString () {
std::string output;
while (const auto c = this->next ()) {
output += c;
}
return output;
}
void BinaryReader::next (char* out, size_t size) {
this->m_input.read (out, size);
}
char BinaryReader::next () {
char buffer;
this->m_input.read (&buffer, 1);
return buffer;
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
#include <iosfwd>
namespace WallpaperEngine::Data::Utils {
class BinaryReader {
public:
explicit BinaryReader (std::istream& file);
uint32_t nextUInt32 ();
int nextInt ();
float nextFloat ();
std::string nextNullTerminatedString ();
void next(char* out, size_t size);
char next ();
private:
std::istream& m_input;
};
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <iostream>
namespace WallpaperEngine::Data::Utils {
struct MemoryStream : std::streambuf
{
MemoryStream (char* p, size_t size)
{
this->setg(p, p, p + size); // set start end end pointers
}
};
}

View File

@ -7,10 +7,10 @@ using namespace WallpaperEngine;
using namespace WallpaperEngine::Render;
CCamera::CCamera (Wallpapers::CScene& scene, const SceneData::Camera& camera) :
m_camera (camera),
m_scene (scene),
m_width (0),
m_height (0) {
m_height (0),
m_camera (camera),
m_scene (scene) {
// get the lookat position
// TODO: ENSURE THIS IS ONLY USED WHEN NOT DOING AN ORTOGRAPHIC CAMERA AS IT THROWS OFF POINTS
this->m_lookat = glm::lookAt (this->getEye (), this->getCenter (), this->getUp ());

View File

@ -3,7 +3,7 @@
using namespace WallpaperEngine::Render;
CFBO::CFBO (std::string name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
CFBO::CFBO (std::string name, TextureFormat format, uint32_t flags, float scale,
uint32_t realWidth, uint32_t realHeight, uint32_t textureWidth, uint32_t textureHeight) :
m_scale (scale),
m_name (std::move (name)),
@ -25,10 +25,10 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, ITexture::TextureF
glObjectLabel (GL_TEXTURE, this->m_texture, -1, this->m_name.c_str ());
#endif /* DEBUG */
// set filtering parameters, otherwise the texture is not rendered
if (flags & TextureFlags::ClampUVs) {
if (flags & TextureFlags_ClampUVs) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} else if (flags & TextureFlags::ClampUVsBorder) {
} else if (flags & TextureFlags_ClampUVsBorder) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
} else {
@ -36,7 +36,7 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, ITexture::TextureF
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
if (flags & TextureFlags::NoInterpolation) {
if (flags & TextureFlags_NoInterpolation) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
} else {
@ -61,7 +61,7 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, ITexture::TextureF
this->m_resolution = {textureWidth, textureHeight, realWidth, realHeight};
// create the textureframe entries
auto frame = std::make_shared<TextureFrame> ();
auto frame = std::make_shared<Frame> ();
frame->frameNumber = 0;
frame->frametime = 0;
@ -89,11 +89,11 @@ const float& CFBO::getScale () const {
return this->m_scale;
}
ITexture::TextureFormat CFBO::getFormat () const {
TextureFormat CFBO::getFormat () const {
return this->m_format;
}
ITexture::TextureFlags CFBO::getFlags () const {
uint32_t CFBO::getFlags () const {
return this->m_flags;
}
@ -125,7 +125,7 @@ uint32_t CFBO::getRealHeight () const {
return this->m_resolution.w;
}
const std::vector<std::shared_ptr<ITexture::TextureFrame>>& CFBO::getFrames () const {
const std::vector<FrameSharedPtr>& CFBO::getFrames () const {
return this->m_frames;
}

View File

@ -9,7 +9,7 @@ using namespace WallpaperEngine::Assets;
namespace WallpaperEngine::Render {
class CFBO final : public ITexture {
public:
CFBO (std::string name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
CFBO (std::string name, TextureFormat format, uint32_t flags, float scale,
uint32_t realWidth, uint32_t realHeight, uint32_t textureWidth, uint32_t textureHeight);
~CFBO () override;
@ -17,8 +17,8 @@ class CFBO final : public ITexture {
[[nodiscard]] const std::string& getName () const;
[[nodiscard]] const float& getScale () const;
[[nodiscard]] ITexture::TextureFormat getFormat () const override;
[[nodiscard]] ITexture::TextureFlags getFlags () const override;
[[nodiscard]] TextureFormat getFormat () const override;
[[nodiscard]] uint32_t getFlags () const override;
[[nodiscard]] GLuint getFramebuffer () const;
[[nodiscard]] GLuint getDepthbuffer () const;
[[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
@ -26,7 +26,7 @@ class CFBO final : public ITexture {
[[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override;
[[nodiscard]] uint32_t getRealWidth () const override;
[[nodiscard]] uint32_t getRealHeight () const override;
[[nodiscard]] const std::vector<std::shared_ptr<TextureFrame>>& getFrames () const override;
[[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
[[nodiscard]] const glm::vec4* getResolution () const override;
[[nodiscard]] bool isAnimated () const override;
@ -37,9 +37,9 @@ class CFBO final : public ITexture {
glm::vec4 m_resolution = {};
float m_scale = 0;
std::string m_name = "";
ITexture::TextureFormat m_format = UNKNOWN;
ITexture::TextureFlags m_flags = NoFlags;
TextureFormat m_format = TextureFormat_UNKNOWN;
uint32_t m_flags = TextureFlags_NoFlags;
/** Placeholder for frames, FBOs only have ONE */
std::vector<std::shared_ptr<TextureFrame>> m_frames = {};
std::vector<FrameSharedPtr> m_frames = {};
};
} // namespace WallpaperEngine::Render

View File

@ -9,11 +9,11 @@ CFBOProvider::CFBOProvider (const CFBOProvider* parent) :
m_parent (parent) {}
std::shared_ptr<CFBO> CFBOProvider::create(const FBO& base, ITexture::TextureFlags flags, glm::vec2 size) {
std::shared_ptr<CFBO> CFBOProvider::create(const FBO& base, uint32_t flags, glm::vec2 size) {
return this->m_fbos[base.name] = std::make_shared <CFBO> (
base.name,
// TODO: PROPERLY DETERMINE FBO FORMAT BASED ON THE STRING
ITexture::TextureFormat::ARGB8888,
TextureFormat_ARGB8888,
flags,
base.scale,
size.x / base.scale,
@ -24,12 +24,12 @@ std::shared_ptr<CFBO> CFBOProvider::create(const FBO& base, ITexture::TextureFla
}
std::shared_ptr<CFBO> CFBOProvider::create (
const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
const std::string& name, TextureFormat format, uint32_t flags, float scale,
glm::vec2 realSize, glm::vec2 textureSize
) {
return this->m_fbos[name] = std::make_shared <CFBO> (
name,
ITexture::TextureFormat::ARGB8888,
TextureFormat_ARGB8888,
flags,
scale,
realSize.x,

View File

@ -12,9 +12,9 @@ class CFBOProvider {
public:
CFBOProvider (const CFBOProvider* parent);
std::shared_ptr<CFBO> create (const FBO& base, ITexture::TextureFlags flags, glm::vec2 size);
std::shared_ptr<CFBO> create (const FBO& base, uint32_t flags, glm::vec2 size);
std::shared_ptr<CFBO> create (
const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
const std::string& name, TextureFormat format, uint32_t flags, float scale,
glm::vec2 realSize, glm::vec2 textureSize);
std::shared_ptr<CFBO> alias (const std::string& newName, const std::string& original);
[[nodiscard]] std::shared_ptr<CFBO> find (const std::string& name) const;

View File

@ -15,7 +15,7 @@ using namespace WallpaperEngine::Render;
CWallpaper::CWallpaper (
const Wallpaper& wallpaperData, CRenderContext& context,CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
const uint32_t& clampMode
) :
CContextAware (context),
CFBOProvider (nullptr),
@ -245,11 +245,11 @@ void CWallpaper::setPause (bool newState) {}
void CWallpaper::setupFramebuffers () {
const uint32_t width = this->getWidth ();
const uint32_t height = this->getHeight ();
const ITexture::TextureFlags clamp = this->m_state.getClampingMode ();
const uint32_t clamp = this->m_state.getClampingMode ();
// create framebuffer for the scene
this->m_sceneFBO = this->create (
"_rt_FullFrameBuffer", ITexture::TextureFormat::ARGB8888, clamp, 1.0, {width,
"_rt_FullFrameBuffer", TextureFormat_ARGB8888, clamp, 1.0, {width,
height}, {width, height});
this->alias ("_rt_MipMappedFrameBuffer", "_rt_FullFrameBuffer");
@ -275,17 +275,22 @@ std::shared_ptr<const CFBO> CWallpaper::getFBO () const {
std::unique_ptr<CWallpaper> CWallpaper::fromWallpaper (
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
WebBrowser::CWebBrowserContext* browserContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
const uint32_t& clampMode
) {
if (wallpaper.is<Scene> ()) {
return std::make_unique <WallpaperEngine::Render::Wallpapers::CScene> (
wallpaper, context, audioContext, scalingMode, clampMode);
} else if (wallpaper.is<Video> ()) {
}
if (wallpaper.is<Video> ()) {
return std::make_unique<WallpaperEngine::Render::Wallpapers::CVideo> (
wallpaper, context, audioContext, scalingMode, clampMode);
} else if (wallpaper.is<Web> ()) {
}
if (wallpaper.is<Web> ()) {
return std::make_unique<WallpaperEngine::Render::Wallpapers::CWeb> (
wallpaper, context, audioContext, *browserContext, scalingMode, clampMode);
} else
sLog.exception ("Unsupported wallpaper type");
}
sLog.exception ("Unsupported wallpaper type");
}

View File

@ -128,13 +128,13 @@ class CWallpaper : public Helpers::CContextAware, public CFBOProvider {
static std::unique_ptr<CWallpaper> fromWallpaper (
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
WebBrowser::CWebBrowserContext* browserContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const uint32_t& clampMode);
protected:
CWallpaper (
const Wallpaper& wallpaperData, CRenderContext& context,
CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const uint32_t& clampMode);
/**
* Renders a frame of the wallpaper

View File

@ -6,7 +6,7 @@
using namespace WallpaperEngine::Render;
CWallpaperState::CWallpaperState (
const TextureUVsScaling& textureUVsMode, const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode) :
const TextureUVsScaling& textureUVsMode, const uint32_t& clampMode) :
m_textureUVsMode (textureUVsMode) {}
bool CWallpaperState::hasChanged (
@ -140,7 +140,7 @@ CWallpaperState::TextureUVsScaling CWallpaperState::getTextureUVsScaling () cons
return this->m_textureUVsMode;
}
WallpaperEngine::Assets::ITexture::TextureFlags CWallpaperState::getClampingMode () const {
uint32_t CWallpaperState::getClampingMode () const {
return this->m_clampingMode;
}

View File

@ -7,6 +7,7 @@
#include "WallpaperEngine/Assets/ITexture.h"
namespace WallpaperEngine::Render {
using namespace WallpaperEngine::Data::Assets;
/**
* Represents current wallpaper state
*/
@ -21,7 +22,7 @@ class CWallpaperState {
};
CWallpaperState (
const TextureUVsScaling& textureUVsMode, const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const TextureUVsScaling& textureUVsMode, const uint32_t& clampMode);
/**
* Checks if any of the given values has changed
@ -79,7 +80,7 @@ class CWallpaperState {
/**
* @return The texture clamping mode.
*/
[[nodiscard]] WallpaperEngine::Assets::ITexture::TextureFlags getClampingMode () const;
[[nodiscard]] uint32_t getClampingMode () const;
/**
* Sets the texture scaling mode
@ -134,6 +135,6 @@ class CWallpaperState {
// Texture scaling mode
TextureUVsScaling m_textureUVsMode = TextureUVsScaling::DefaultUVs;
WallpaperEngine::Assets::ITexture::TextureFlags m_clampingMode = WallpaperEngine::Assets::ITexture::TextureFlags::NoFlags;
uint32_t m_clampingMode = TextureFlags_NoFlags;
};
} // namespace WallpaperEngine::Render

View File

@ -20,9 +20,9 @@ void CustomGLFWErrorHandler (int errorCode, const char* reason) {
CGLFWOpenGLDriver::CGLFWOpenGLDriver (
const char* windowTitle, CApplicationContext& context, CWallpaperApplication& app
) :
m_mouseInput (*this),
CVideoDriver (app, m_mouseInput),
m_context (context) {
m_context (context),
m_mouseInput (*this) {
glfwSetErrorCallback (CustomGLFWErrorHandler);
// initialize glfw

View File

@ -232,12 +232,12 @@ void CWaylandOpenGLDriver::onLayerClose (Output::CWaylandOutputViewport* viewpor
}
CWaylandOpenGLDriver::CWaylandOpenGLDriver (CApplicationContext& context, CWallpaperApplication& app) :
m_mouseInput (*this),
CVideoDriver (app, m_mouseInput),
m_output (context, *this),
m_requestedExit (false),
m_frameCounter (0),
m_context (context) {
m_context (context),
m_mouseInput (*this) {
m_waylandContext.display = wl_display_connect (nullptr);
if (!m_waylandContext.display)

View File

@ -22,10 +22,6 @@ class CApplicationContext;
class CWallpaperApplication;
} // namespace WallpaperEngine::Application
namespace WallpaperEngine::Input::Drivers {
class CWaylandMouseInput;
}
struct zwlr_layer_shell_v1;
struct zwlr_layer_surface_v1;

View File

@ -104,7 +104,7 @@ CImage::CImage (Wallpapers::CScene& scene, const Image& image) :
// TODO: create a dummy texture of correct size, fbo constructors should be enough, but this should be properly
// handled
this->m_texture = std::make_shared<CFBO> (
"", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::NoFlags, 1, size.x,
"", TextureFormat_ARGB8888, TextureFlags_NoFlags, 1, size.x,
size.y, size.x, size.y);
}
@ -116,10 +116,10 @@ CImage::CImage (Wallpapers::CScene& scene, const Image& image) :
nameB << "_rt_imageLayerComposite_" << this->getImage ().id << "_b";
this->m_currentMainFBO = this->m_mainFBO =
scene.create (nameA.str (), ITexture::TextureFormat::ARGB8888, this->m_texture->getFlags (), 1,
scene.create (nameA.str (), TextureFormat_ARGB8888, this->m_texture->getFlags (), 1,
{size.x, size.y}, {size.x, size.y});
this->m_currentSubFBO = this->m_subFBO =
scene.create (nameB.str (), ITexture::TextureFormat::ARGB8888, this->m_texture->getFlags (), 1,
scene.create (nameB.str (), TextureFormat_ARGB8888, this->m_texture->getFlags (), 1,
{size.x, size.y}, {size.x, size.y});
// build a list of vertices, these might need some change later (or maybe invert the camera)

View File

@ -40,12 +40,12 @@ CPass::CPass (
) :
Helpers::CContextAware (image),
m_image (image),
m_fboProvider (std::move(fboProvider)),
m_pass (pass),
m_blendingmode (pass.blending),
m_binds (binds.has_value () ? binds.value ().get () : DEFAULT_BINDS),
m_override (override.has_value () ? override.value ().get () : DEFAULT_OVERRIDE),
m_fboProvider (std::move(fboProvider)),
m_target (target) {
m_target (target),
m_blendingmode (pass.blending) {
this->setupShaders ();
}
@ -417,9 +417,9 @@ void CPass::setupShaders () {
// TODO: THE VALUES ARE THE SAME AS THE ENUMERATION, SO MAYBE IT HAS TO BE SPECIFIED FOR THE TEXTURE 0 OF ALL
// ELEMENTS?
if (texture0 != nullptr) {
if (texture0->getFormat () == ITexture::TextureFormat::RG88) {
if (texture0->getFormat () == TextureFormat_RG88) {
this->m_combos.insert_or_assign ("TEX0FORMAT", 8);
} else if (texture0->getFormat () == ITexture::TextureFormat::R8) {
} else if (texture0->getFormat () == TextureFormat_R8) {
this->m_combos.insert_or_assign ("TEX0FORMAT", 9);
}
}

View File

@ -19,17 +19,17 @@ CShader::CShader (
const TextureMap& textures, const TextureMap& overrideTextures,
const ShaderConstantMap& constants
) :
m_file (std::move (filename)),
m_combos (combos),
m_overrideCombos (overrideCombos),
m_passTextures (textures),
m_overrideTextures (overrideTextures),
m_vertex (
CGLSLContext::UnitType_Vertex, filename, container.readVertexShader (filename),
container, constants, textures, overrideTextures, combos, overrideCombos),
m_fragment (
CGLSLContext::UnitType_Fragment, filename, container.readFragmentShader (filename),
container, constants, textures, overrideTextures, combos, overrideCombos) {
container, constants, textures, overrideTextures, combos, overrideCombos),
m_file (std::move (filename)),
m_combos (combos),
m_overrideCombos (overrideCombos),
m_passTextures (textures),
m_overrideTextures (overrideTextures) {
// link shaders between them
this->m_vertex.linkToUnit (&this->m_fragment);
this->m_fragment.linkToUnit (&this->m_vertex);

View File

@ -57,17 +57,15 @@ CShaderUnit::CShaderUnit (
const ComboMap& combos, const ComboMap& overrideCombos
) :
m_type (type),
m_link (nullptr),
m_container (container),
m_file (std::move (file)),
m_constants (constants),
m_content (std::move(content)),
m_passTextures (passTextures),
m_overrideTextures (overrideTextures),
m_combos (combos),
m_overrideCombos (overrideCombos),
m_discoveredCombos (),
m_usedCombos () {
m_constants (constants),
m_passTextures (passTextures),
m_overrideTextures (overrideTextures),
m_link (nullptr),
m_container (container) {
// pre-process the shader so the units are clear
this->preprocess ();
}

View File

@ -22,7 +22,7 @@ using JSON = WallpaperEngine::Data::JSON::JSON;
CScene::CScene (
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
const uint32_t& clampMode
) :
CWallpaper (wallpaper, context, audioContext, scalingMode, clampMode) {
// caller should check this, if not a std::bad_cast is good to throw
@ -51,7 +51,7 @@ CScene::CScene (
const uint32_t sceneHeight = this->m_camera->getHeight ();
this->_rt_shadowAtlas =
this->create ("_rt_shadowAtlas", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0,
this->create ("_rt_shadowAtlas", TextureFormat_ARGB8888, TextureFlags_ClampUVs, 1.0,
{sceneWidth, sceneHeight}, {sceneWidth, sceneHeight});
this->alias ("_alias_lightCookie", "_rt_shadowAtlas");
@ -71,12 +71,12 @@ CScene::CScene (
// create extra framebuffers for the bloom effect
this->_rt_4FrameBuffer =
this->create ("_rt_4FrameBuffer", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0,
this->create ("_rt_4FrameBuffer", TextureFormat_ARGB8888, TextureFlags_ClampUVs, 1.0,
{sceneWidth / 4, sceneHeight / 4}, {sceneWidth / 4, sceneHeight / 4});
this->_rt_8FrameBuffer =
this->create ("_rt_8FrameBuffer", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0,
this->create ("_rt_8FrameBuffer", TextureFormat_ARGB8888, TextureFlags_ClampUVs, 1.0,
{sceneWidth / 8, sceneHeight / 8}, {sceneWidth / 8, sceneHeight / 8});
this->_rt_Bloom = this->create ("_rt_Bloom", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs,
this->_rt_Bloom = this->create ("_rt_Bloom", TextureFormat_ARGB8888, TextureFlags_ClampUVs,
1.0, {sceneWidth / 8, sceneHeight / 8}, {sceneWidth / 8, sceneHeight / 8});
//

View File

@ -17,7 +17,7 @@ class CScene final : public CWallpaper {
CScene (
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const uint32_t& clampMode);
[[nodiscard]] CCamera& getCamera () const;

View File

@ -17,7 +17,7 @@ void* get_proc_address (void* ctx, const char* name) {
CVideo::CVideo (
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
const uint32_t& clampMode
) :
CWallpaper (wallpaper, context, audioContext, scalingMode, clampMode) {
double volume = this->getContext ().getApp ().getContext ().settings.audio.volume * 100.0 / 128.0;

View File

@ -11,7 +11,7 @@ class CVideo final : public CWallpaper {
CVideo (
const Wallpaper& video, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const uint32_t& clampMode);
const Video& getVideo () const;

View File

@ -16,7 +16,7 @@ using namespace WallpaperEngine::WebBrowser::CEF;
CWeb::CWeb (
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
const uint32_t& clampMode
) :
CWallpaper (wallpaper, context, audioContext, scalingMode, clampMode),
m_browserContext (browserContext) {

View File

@ -29,7 +29,7 @@ class CWeb : public CWallpaper
const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext,
const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const uint32_t& clampMode);
~CWeb() override;
[[nodiscard]] int getWidth () const override { return this->m_width; }