~ Removed static variables in namespace WallpaperEngine::Irrlicht and moved to a context approach

This includes changes to old code to be compatible, the externs won't be used once the renderer is rewritten and the old code removed

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2019-09-05 17:24:16 +02:00
parent 1c50095ead
commit b8b3c2899d
22 changed files with 1072 additions and 906 deletions

View File

@ -48,14 +48,14 @@ add_executable(
src/WallpaperEngine/video/material.h
src/WallpaperEngine/texture.cpp
src/WallpaperEngine/texture.h
src/WallpaperEngine/Irrlicht/CContext.h
src/WallpaperEngine/Irrlicht/CContext.cpp
src/WallpaperEngine/Irrlicht/CImageLoaderTEX.h
src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp
src/WallpaperEngine/Irrlicht/CPkgReader.h
src/WallpaperEngine/Irrlicht/CPkgReader.cpp
src/WallpaperEngine/Irrlicht/CFileList.h
src/WallpaperEngine/Irrlicht/CFileList.cpp
src/WallpaperEngine/Irrlicht/Irrlicht.cpp
src/WallpaperEngine/Irrlicht/Irrlicht.h
src/WallpaperEngine/sound.cpp
src/WallpaperEngine/sound.h

View File

@ -8,20 +8,26 @@
#include <SDL_mixer.h>
#include <SDL.h>
#include <X11/Xlib.h>
#include "WallpaperEngine/Render/Shaders/Compiler.h"
#include "WallpaperEngine/project.h"
#include "WallpaperEngine/Irrlicht/Irrlicht.h"
#include "WallpaperEngine/Irrlicht/CImageLoaderTEX.h"
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Irrlicht/CContext.h"
int WinID = 0;
irr::SIrrlichtCreationParameters _irr_params;
irr::f32 g_Time = 0;
WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
int init_irrlicht()
{
IrrlichtContext = new WallpaperEngine::Irrlicht::CContext ();
// prepare basic configuration for irrlicht
_irr_params.AntiAlias = 8;
_irr_params.Bits = 16;
@ -38,31 +44,34 @@ int init_irrlicht()
_irr_params.WithAlphaChannel = false;
_irr_params.ZBufferBits = 24;
_irr_params.LoggingLevel = irr::ELL_DEBUG;
_irr_params.WindowId = reinterpret_cast<void*> (WinID);
WallpaperEngine::Irrlicht::device = irr::createDeviceEx (_irr_params);
Display* display = XOpenDisplay (NULL);
int screen = XDefaultScreen (display);
if (WallpaperEngine::Irrlicht::device == nullptr)
_irr_params.WindowId = reinterpret_cast<void*> (XRootWindow (display, screen));
IrrlichtContext->setDevice (irr::createDeviceEx (_irr_params));
if (IrrlichtContext->getDevice () == nullptr)
{
return 1;
}
WallpaperEngine::Irrlicht::device->setWindowCaption (L"Test game");
WallpaperEngine::Irrlicht::driver = WallpaperEngine::Irrlicht::device->getVideoDriver();
IrrlichtContext->getDevice ()->setWindowCaption (L"Test game");
// check for ps and vs support
if (
WallpaperEngine::Irrlicht::driver->queryFeature (irr::video::EVDF_PIXEL_SHADER_1_1) == false &&
WallpaperEngine::Irrlicht::driver->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false)
IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_PIXEL_SHADER_1_1) == false &&
IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("WARNING: Pixel shaders disabled because of missing driver/hardware support");
IrrlichtContext->getDevice ()->getLogger ()->log ("WARNING: Pixel shaders disabled because of missing driver/hardware support");
}
if (
WallpaperEngine::Irrlicht::driver->queryFeature (irr::video::EVDF_VERTEX_SHADER_1_1) == false &&
WallpaperEngine::Irrlicht::driver->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false)
IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_VERTEX_SHADER_1_1) == false &&
IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support");
IrrlichtContext->getDevice ()->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support");
}
return 0;
@ -71,11 +80,15 @@ int init_irrlicht()
void preconfigure_wallpaper_engine ()
{
// load the assets from wallpaper engine
WallpaperEngine::Irrlicht::device->getFileSystem ()->addFileArchive ("assets.zip", true, false);
IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive ("assets.zip", true, false);
// register custom loaders
WallpaperEngine::Irrlicht::driver->addExternalImageLoader (new WallpaperEngine::Irrlicht::CImageLoaderTex ());
WallpaperEngine::Irrlicht::device->getFileSystem ()->addArchiveLoader (new WallpaperEngine::Irrlicht::CArchiveLoaderPkg (WallpaperEngine::Irrlicht::device->getFileSystem ()));
IrrlichtContext->getDevice ()->getVideoDriver()->addExternalImageLoader (
new WallpaperEngine::Irrlicht::CImageLoaderTex (IrrlichtContext)
);
IrrlichtContext->getDevice ()->getFileSystem ()->addArchiveLoader (
new WallpaperEngine::Irrlicht::CArchiveLoaderPkg (IrrlichtContext)
);
}
void print_help (const char* route)
@ -178,21 +191,21 @@ int main (int argc, char* argv[])
// pkg mode
case 1:
path = stringPathFixes(path);
wallpaper_path = WallpaperEngine::Irrlicht::device->getFileSystem ()->getAbsolutePath (path.c_str ());
wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ());
project_path = wallpaper_path + "project.json";
scene_path = wallpaper_path + "scene.pkg";
WallpaperEngine::Irrlicht::device->getFileSystem ()->addFileArchive (scene_path, true, false); // add the pkg file to the lookup list
IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive (scene_path, true, false); // add the pkg file to the lookup list
break;
// folder mode
case 2:
path = stringPathFixes(path);
wallpaper_path = WallpaperEngine::Irrlicht::device->getFileSystem ()->getAbsolutePath (path.c_str ());
wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ());
project_path = wallpaper_path + "project.json";
// set our working directory
WallpaperEngine::Irrlicht::device->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path);
IrrlichtContext->getDevice ()->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path);
break;
default:
@ -205,7 +218,7 @@ int main (int argc, char* argv[])
if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags))
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Cannot initialize SDL audio system", irr::ELL_ERROR);
IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot initialize SDL audio system", irr::ELL_ERROR);
return -1;
}
@ -221,7 +234,10 @@ int main (int argc, char* argv[])
}
else
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Non-orthogonal cameras not supported yet!!", irr::ELL_ERROR);
IrrlichtContext->getDevice ()->getLogger ()->log (
"Non-orthogonal cameras not supported yet!!", irr::ELL_ERROR
);
return -2;
}
@ -232,11 +248,11 @@ int main (int argc, char* argv[])
int32_t minimumTime = 1000 / 90;
int32_t currentTime = 0;
while (WallpaperEngine::Irrlicht::device->run () && WallpaperEngine::Irrlicht::driver)
while (IrrlichtContext->getDevice ()->run () && IrrlichtContext && IrrlichtContext->getDevice ())
{
// if (device->isWindowActive ())
{
currentTime = WallpaperEngine::Irrlicht::device->getTimer ()->getTime ();
currentTime = IrrlichtContext->getDevice ()->getTimer ()->getTime ();
g_Time = currentTime / 1000.0f;
if (currentTime - lastTime > minimumTime)
@ -246,7 +262,7 @@ int main (int argc, char* argv[])
}
else
{
WallpaperEngine::Irrlicht::device->sleep (1, false);
IrrlichtContext->getDevice ()->sleep (1, false);
}
}
}

View File

@ -2,13 +2,15 @@
#include "FileSystem.h"
// engine includes
#include "WallpaperEngine/Irrlicht/Irrlicht.h"
#include "WallpaperEngine/Irrlicht/CContext.h"
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine::FileSystem
{
std::string loadFullFile (irr::io::path file)
{
irr::io::IReadFile* reader = WallpaperEngine::Irrlicht::device->getFileSystem ()->createAndOpenFile (file);
irr::io::IReadFile* reader = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile (file);
if (reader == NULL)
throw std::runtime_error ("Cannot open file " + std::string (file.c_str ()) + " for reading");

View File

@ -0,0 +1,14 @@
#include "CContext.h"
namespace WallpaperEngine::Irrlicht
{
void CContext::setDevice (irr::IrrlichtDevice* device)
{
this->m_device = device;
}
irr::IrrlichtDevice* CContext::getDevice ()
{
return this->m_device;
}
};

View File

@ -0,0 +1,16 @@
#pragma once
#include <irrlicht/irrlicht.h>
namespace WallpaperEngine::Irrlicht
{
class CContext
{
public:
void setDevice (irr::IrrlichtDevice* device);
irr::IrrlichtDevice* getDevice ();
private:
irr::IrrlichtDevice* m_device;
};
};

View File

@ -2,55 +2,50 @@
#include "CFileList.h"
using namespace WallpaperEngine::Irrlicht;
using namespace irr;
static const io::path emptyFileListEntry;
CFileList::CFileList(const io::path& path, bool ignoreCase, bool ignorePaths)
: IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path)
namespace WallpaperEngine::Irrlicht
{
Path.replace('\\', '/');
static const irr::io::path emptyFileListEntry;
CFileList::CFileList (const irr::io::path& path, bool ignoreCase, bool ignorePaths) :
m_ignorePaths (ignorePaths),
m_ignoreCase (ignoreCase),
m_path(path)
{
this->m_path.replace ('\\', '/');
}
CFileList::~CFileList ()
{
Files.clear();
this->m_files.clear ();
}
u32 CFileList::getFileCount() const
irr::u32 CFileList::getFileCount () const
{
return Files.size();
return this->m_files.size ();
}
void CFileList::sort ()
{
Files.sort();
this->m_files.sort ();
}
const io::path& CFileList::getFileName(u32 index) const
const irr::io::path& CFileList::getFileName (irr::u32 index) const
{
if (index >= Files.size())
return emptyFileListEntry;
return Files[index].Name;
return (index < this->m_files.size ()) ? this->m_files [index].Name : emptyFileListEntry;
}
//! Gets the full name of a file in the list, path included, based on an index.
const io::path& CFileList::getFullFileName(u32 index) const
const irr::io::path& CFileList::getFullFileName (irr::u32 index) const
{
if (index >= Files.size())
return emptyFileListEntry;
return Files[index].FullName;
return (index < this->m_files.size ()) ? this->m_files [index].FullName : emptyFileListEntry;
}
//! adds a file or folder
u32 CFileList::addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id)
irr::u32 CFileList::addItem (const irr::io::path& fullPath, irr::u32 offset, irr::u32 size, bool isDirectory, irr::u32 id)
{
SFileListEntry entry;
entry.ID = id ? id : Files.size();
entry.ID = id ? id : this->m_files.size ();
entry.Offset = offset;
entry.Size = size;
entry.Name = fullPath;
@ -65,53 +60,47 @@ u32 CFileList::addItem(const io::path& fullPath, u32 offset, u32 size, bool isDi
entry.Name.validate ();
}
if (IgnoreCase)
if (this->m_ignoreCase)
entry.Name.make_lower ();
entry.FullName = entry.Name;
core::deletePathFromFilename(entry.Name);
irr::core::deletePathFromFilename (entry.Name);
if (IgnorePaths)
if (this->m_ignorePaths)
entry.FullName = entry.Name;
//os::Printer::log(Path.c_str(), entry.FullName);
this->m_files.push_back (entry);
Files.push_back(entry);
return Files.size() - 1;
return this->m_files.size () - 1;
}
//! Returns the ID of a file in the file list, based on an index.
u32 CFileList::getID(u32 index) const
irr::u32 CFileList::getID (irr::u32 index) const
{
return index < Files.size() ? Files[index].ID : 0;
return (index < this->m_files.size ()) ? this->m_files [index].ID : 0;
}
bool CFileList::isDirectory(u32 index) const
bool CFileList::isDirectory (irr::u32 index) const
{
bool ret = false;
if (index < Files.size())
ret = Files[index].IsDirectory;
return ret;
return (index < this->m_files.size ()) ? this->m_files [index].IsDirectory : false;
}
//! Returns the size of a file
u32 CFileList::getFileSize(u32 index) const
irr::u32 CFileList::getFileSize (irr::u32 index) const
{
return index < Files.size() ? Files[index].Size : 0;
return (index < this->m_files.size ()) ? this->m_files [index].Size : 0;
}
//! Returns the size of a file
u32 CFileList::getFileOffset(u32 index) const
irr::u32 CFileList::getFileOffset (irr::u32 index) const
{
return index < Files.size() ? Files[index].Offset : 0;
return (index < this->m_files.size ()) ? this->m_files [index].Offset : 0;
}
//! Searches for a file or folder within the list, returns the index
s32 CFileList::findFile(const io::path& filename, bool isDirectory = false) const
irr::s32 CFileList::findFile (const irr::io::path& filename, bool isDirectory = false) const
{
SFileListEntry entry;
// we only need FullName to be set for the search
@ -129,18 +118,19 @@ s32 CFileList::findFile(const io::path& filename, bool isDirectory = false) cons
entry.FullName.validate ();
}
if (IgnoreCase)
if (this->m_ignoreCase)
entry.FullName.make_lower ();
if (IgnorePaths)
core::deletePathFromFilename(entry.FullName);
if (this->m_ignorePaths)
irr::core::deletePathFromFilename (entry.FullName);
return Files.binary_search(entry);
return this->m_files.binary_search (entry);
}
//! Returns the base path of the file list
const io::path& CFileList::getPath() const
const irr::io::path& CFileList::getPath () const
{
return Path;
return m_path;
}
};

View File

@ -2,8 +2,6 @@
#include <irrlicht/irrlicht.h>
using namespace irr;
namespace WallpaperEngine::Irrlicht
{
//! An entry in a list of files, can be a folder or a file.
@ -12,23 +10,23 @@ namespace WallpaperEngine::Irrlicht
//! The name of the file
/** If this is a file or folder in the virtual filesystem and the archive
was created with the ignoreCase flag then the file name will be lower case. */
io::path Name;
irr::io::path Name;
//! The name of the file including the path
/** If this is a file or folder in the virtual filesystem and the archive was
created with the ignoreDirs flag then it will be the same as Name. */
io::path FullName;
irr::io::path FullName;
//! The size of the file in bytes
u32 Size;
irr::u32 Size;
//! The ID of the file in an archive
/** This is used to link the FileList entry to extra info held about this
file in an archive, which can hold things like data offset and CRC. */
u32 ID;
irr::u32 ID;
//! FileOffset inside an archive
u32 Offset;
irr::u32 Offset;
//! True if this is a folder, false if not.
bool IsDirectory;
@ -54,7 +52,7 @@ namespace WallpaperEngine::Irrlicht
//! Implementation of a file list
class CFileList : public io::IFileList
class CFileList : public irr::io::IFileList
{
public:
@ -62,7 +60,7 @@ namespace WallpaperEngine::Irrlicht
//! Constructor
/** \param path The path of this file archive */
CFileList(const io::path& path, bool ignoreCase, bool ignorePaths);
CFileList (const irr::io::path& path, bool ignoreCase, bool ignorePaths);
//! Destructor
virtual ~CFileList ();
@ -73,51 +71,51 @@ namespace WallpaperEngine::Irrlicht
\param offset The offset where the file is stored in an archive
\param size The size of the file in bytes.
\param id The ID of the file in the archive which owns it */
virtual u32 addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id=0);
virtual irr::u32 addItem (const irr::io::path& fullPath, irr::u32 offset, irr::u32 size, bool isDirectory, irr::u32 id=0);
//! Sorts the file list. You should call this after adding any items to the file list
virtual void sort ();
//! Returns the amount of files in the filelist.
virtual u32 getFileCount() const;
virtual irr::u32 getFileCount () const;
//! Gets the name of a file in the list, based on an index.
virtual const io::path& getFileName(u32 index) const;
virtual const irr::io::path& getFileName (irr::u32 index) const;
//! Gets the full name of a file in the list, path included, based on an index.
virtual const io::path& getFullFileName(u32 index) const;
virtual const irr::io::path& getFullFileName (irr::u32 index) const;
//! Returns the ID of a file in the file list, based on an index.
virtual u32 getID(u32 index) const;
virtual irr::u32 getID (irr::u32 index) const;
//! Returns true if the file is a directory
virtual bool isDirectory(u32 index) const;
virtual bool isDirectory (irr::u32 index) const;
//! Returns the size of a file
virtual u32 getFileSize(u32 index) const;
virtual irr::u32 getFileSize (irr::u32 index) const;
//! Returns the offest of a file
virtual u32 getFileOffset(u32 index) const;
virtual irr::u32 getFileOffset (irr::u32 index) const;
//! Searches for a file or folder within the list, returns the index
virtual s32 findFile(const io::path& filename, bool isFolder) const;
virtual irr::s32 findFile (const irr::io::path& filename, bool isFolder) const;
//! Returns the base path of the file list
virtual const io::path& getPath() const;
virtual const irr::io::path& getPath () const;
protected:
//! Ignore paths when adding or searching for files
bool IgnorePaths;
bool m_ignorePaths;
//! Ignore case when adding or searching for files
bool IgnoreCase;
bool m_ignoreCase;
//! Path to the file list
io::path Path;
irr::io::path m_path;
//! List of files
core::array<SFileListEntry> Files;
irr::core::array<SFileListEntry> m_files;
};
}

View File

@ -2,270 +2,340 @@
#include <irrlicht/irrlicht.h>
#include <lz4.h>
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
#include <string>
#include <stdexcept>
using namespace irr::video;
using namespace WallpaperEngine::Irrlicht;
namespace WallpaperEngine::Irrlicht
{
CImageLoaderTex::TextureMipmap::TextureMipmap ()
{
}
CImageLoaderTex::TextureMipmap::~TextureMipmap ()
{
if (this->compression == 1)
delete this->compressedData;
delete this->uncompressedData;
}
void CImageLoaderTex::TextureMipmap::decompressData ()
{
if (this->compression == 1)
{
this->uncompressedData = new char [this->uncompressedSize];
int result = LZ4_decompress_safe (
this->compressedData, this->uncompressedData,
this->compressedSize, this->uncompressedSize
);
if (!result)
{
throw std::runtime_error ("Cannot decompress texture data");
}
}
}
CImageLoaderTex::TextureContainer::TextureContainer () :
freeimageFormat (FREE_IMAGE_FORMAT::FIF_UNKNOWN)
{
}
CImageLoaderTex::TextureContainer::~TextureContainer ()
{
std::vector <TextureMipmap*>::const_iterator cur = this->mipmaps.begin ();
std::vector <TextureMipmap*>::const_iterator end = this->mipmaps.end ();
for (; cur != end; cur ++)
{
delete *cur;
}
}
CImageLoaderTex::CImageLoaderTex (CContext* context) :
m_context (context)
{
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderTex::isALoadableFileExtension (const io::path &filename) const
bool CImageLoaderTex::isALoadableFileExtension (const irr::io::path &filename) const
{
return core::hasFileExtension (filename, "tex");
return irr::core::hasFileExtension (filename, "tex");
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderTex::isALoadableFileFormat (io::IReadFile *file) const
bool CImageLoaderTex::isALoadableFileFormat (irr::io::IReadFile *file) const
{
return false;
}
// load in the image data
IImage *CImageLoaderTex::loadImage (io::IReadFile *input) const
CImageLoaderTex::TextureContainer* CImageLoaderTex::parseHeader (irr::io::IReadFile* input) const
{
if (!input)
return nullptr;
video::IImage *image = nullptr;
char buffer [1024];
if (input->read (buffer, 9) != 9)
if (input->read (buffer, 9) != 9 || memcmp (buffer, "TEXV0005", 9) != 0)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot read header\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
throw std::runtime_error ("unexpected container type");
}
if (memcmp (buffer, "TEXV0005", 9) != 0)
if (input->read (buffer, 9) != 9 || memcmp (buffer, "TEXI0001", 9) != 0)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: not really a tex\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
throw std::runtime_error ("unexpected sub-container type");
}
if (input->read (buffer, 9) != 9)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot read second header\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
}
TextureContainer* header = new TextureContainer;
if (memcmp (buffer, "TEXI0001", 9) != 0)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: not really a tex\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
}
u32 width;
u32 height;
u32 texture_width;
u32 texture_height;
u32 format;
u32 imageFormat = FREE_IMAGE_FORMAT::FIF_UNKNOWN;
u8 containerVersion = 0;
input->read (&format, 4);
input->read (&header->format, 4);
input->seek (4, true); // ignore bytes
input->read (&texture_width, 4);
input->read (&texture_height, 4);
input->read (&width, 4);
input->read (&height, 4);
input->read (&header->textureWidth, 4);
input->read (&header->textureHeight, 4);
input->read (&header->width, 4);
input->read (&header->height, 4);
input->seek (4, true); // ignore bytes
input->read (buffer, 9);
if (memcmp (buffer, "TEXB0003", 9) == 0)
{
containerVersion = 3;
header->containerVersion = ContainerVersion::TEXB0003;
input->seek (4, true);
input->read (&imageFormat, 4);
input->read (&header->freeimageFormat, 4);
}
else if (memcmp (buffer, "TEXB0002", 9) == 0)
{
containerVersion = 2;
header->containerVersion = ContainerVersion::TEXB0002;
input->seek (4, true);
}
else if (memcmp (buffer, "TEXB0001", 9) == 0)
{
containerVersion = 1;
header->containerVersion = ContainerVersion::TEXB0001;
input->seek (4, true);
}
else
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: Unknown container type\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
delete header;
throw std::runtime_error ("Unknown container type");
}
if (format == TextureFormat::A8)
if (header->format == TextureFormat::A8)
{
WallpaperEngine::Irrlicht::device->getLogger ()-> log ("LOAD TEX: A8 not supported\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
delete header;
throw std::runtime_error ("A8 format not supported yet");
}
if (format == TextureFormat::RA88)
if (header->format == TextureFormat::RA88)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: RA88 not supported\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
delete header;
throw std::runtime_error ("RA88 format not supported yet");
}
u32 mipmap_count = 0;
input->read (&header->mipmapCount, 4);
input->read (&mipmap_count, 4);
u32 mipmap_width = 0;
u32 mipmap_height = 0;
u32 mipmap_compression = 0;
u32 mipmap_uncompressed_size = 0;
u32 mipmap_compressed_size = 0;
input->read (&mipmap_width, 4);
input->read (&mipmap_height, 4);
if (containerVersion > 1)
for (irr::u32 i = 0; i < header->mipmapCount; i ++)
{
input->read (&mipmap_compression, 4);
input->read (&mipmap_uncompressed_size, 4);
header->mipmaps.push_back (
this->parseMipmap (header, input)
);
}
input->read (&mipmap_compressed_size, 4);
return header;
}
CImageLoaderTex::TextureMipmap* CImageLoaderTex::parseMipmap(TextureContainer* header, irr::io::IReadFile* input) const
{
TextureMipmap* mipmap = new TextureMipmap ();
input->read (&mipmap->width, 4);
input->read (&mipmap->height, 4);
if (header->containerVersion == ContainerVersion::TEXB0002 ||
header->containerVersion == ContainerVersion::TEXB0003)
{
input->read (&mipmap->compression, 4);
input->read (&mipmap->uncompressedSize, 4);
}
input->read (&mipmap->compressedSize, 4);
// TODO: BETTER POSITION FOR THIS
if (mipmap_compression == 0)
if (mipmap->compression == 0)
{
// this might be better named as mipmap_bytes_size instead of compressed_size
// as in uncompressed files this variable actually holds the file length
mipmap_uncompressed_size = mipmap_compressed_size;
mipmap->uncompressedSize = mipmap->compressedSize;
}
char *decompressedBuffer = new char [mipmap_uncompressed_size];
mipmap->uncompressedData = new char [mipmap->uncompressedSize];
if (mipmap_compression == 1)
if (mipmap->compression == 1)
{
char *compressedBuffer = new char [mipmap_compressed_size];
mipmap->compressedData = new char [mipmap->compressedSize];
input->read (compressedBuffer, mipmap_compressed_size);
input->read (mipmap->compressedData, mipmap->compressedSize);
int result = LZ4_decompress_safe (compressedBuffer, decompressedBuffer, mipmap_compressed_size, mipmap_uncompressed_size);
if (!result)
{
delete [] decompressedBuffer;
delete [] compressedBuffer;
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot decompress texture data\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
}
delete [] compressedBuffer;
mipmap->decompressData ();
}
else
{
input->read (decompressedBuffer, mipmap_uncompressed_size);
input->read (mipmap->uncompressedData, mipmap->uncompressedSize);
}
if (imageFormat == FREE_IMAGE_FORMAT::FIF_UNKNOWN)
{
image = WallpaperEngine::Irrlicht::driver->createImage (ECF_A8R8G8B8, irr::core::dimension2d<u32> (width, height));
return mipmap;
}
if (!image)
irr::video::IImage* CImageLoaderTex::parseFile (irr::io::IReadFile* input) const
{
delete [] decompressedBuffer;
delete image;
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot create destination image\n", input->getFileName ().c_str (), irr::ELL_ERROR);
irr::video::IImage *image = nullptr;
TextureContainer* header = nullptr;
TextureMipmap* mipmap = nullptr;
if (input == nullptr)
return nullptr;
header = this->parseHeader (input);
mipmap = *header->mipmaps.begin ();
if (header->freeimageFormat == FREE_IMAGE_FORMAT::FIF_UNKNOWN)
{
image = this->m_context->getDevice ()->getVideoDriver ()->createImage (
irr::video::ECF_A8R8G8B8, irr::core::dimension2d<irr::u32> (header->width, header->height)
);
if (image == nullptr)
{
delete header;
throw std::runtime_error ("cannot create destination image");
}
switch (format)
switch (header->format)
{
case TextureFormat::ARGB8888:
this->loadImageFromARGB8Data (image, decompressedBuffer, width, height, mipmap_width);
this->loadImageFromARGB8Data (
image, mipmap->uncompressedData, header->width, header->height, mipmap->width
);
break;
case TextureFormat::DXT5:
this->loadImageFromDXT5 (image, decompressedBuffer, width, height, mipmap_width, mipmap_height);
this->loadImageFromDXT5 (
image, mipmap->uncompressedData, header->width, header->height, mipmap->width, mipmap->height
);
break;
case TextureFormat::DXT1:
this->loadImageFromDXT1 (image, decompressedBuffer, width, height, mipmap_width, mipmap_height);
this->loadImageFromDXT1 (
image, mipmap->uncompressedData, header->width, header->height, mipmap->width, mipmap->height
);
break;
case TextureFormat::DXT3:
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: DXT3 textures not supported yet\n", input->getFileName ().c_str (), irr::ELL_ERROR);
delete [] decompressedBuffer;
delete image;
return nullptr;
delete header;
throw std::runtime_error ("DXT3 textures not supported yet");
}
}
else
{
// copy the buffer to a new address
char* filebuffer = new char [mipmap_uncompressed_size];
// generate a memory file for irrlicht to load the proper one as free image files
// that are used by wallpaperengine are usually supported formats in irrlicht
// TODO: FIND A WAY TO CALL THE PROPER LOADER DIRECTLY INSTEAD OF GENERATING A FILE?
char tmpname [TMP_MAX];
// copy file data to the final file buffer to be used
memcpy (filebuffer, decompressedBuffer, mipmap_uncompressed_size);
// generate temporal name
std::tmpnam (tmpname);
// store it in a std::string
std::string filename = tmpname;
irr::io::IReadFile* file;
irr::io::IReadFile* file = nullptr;
// free image format
switch (imageFormat)
switch (header->freeimageFormat)
{
case FREE_IMAGE_FORMAT::FIF_BMP:
// add extension to the file
filename += ".bmp";
file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
break;
case FREE_IMAGE_FORMAT::FIF_PNG:
// add extension to the file
filename += ".png";
file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
break;
case FREE_IMAGE_FORMAT::FIF_JPEG:
// add extension to the file
filename += ".jpg";
WallpaperEngine::Irrlicht::device->getFileSystem ()->createAndWriteFile ("/tmp/test.jpg", false)->write (filebuffer, mipmap_uncompressed_size);
file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
break;
case FREE_IMAGE_FORMAT::FIF_GIF:
filename += ".gif";
file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
break;
default:
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: detected unsupported free-image format\n", input->getFileName ().c_str (), irr::ELL_ERROR);
delete [] decompressedBuffer;
delete [] filebuffer;
return nullptr;
throw std::runtime_error ("Unsupported free image extension");
}
image = WallpaperEngine::Irrlicht::driver->createImageFromFile (file);
// create a copy of the file information for the filesystem module of irrlicht
// this will be freed automatically by irrlicht so we can freely delete the container
// data from memory without leaking memory
char* filebuffer = new char [mipmap->uncompressedSize];
if (!image)
memcpy (filebuffer, mipmap->uncompressedData, mipmap->uncompressedSize);
file = this->m_context->getDevice ()->getFileSystem ()->createMemoryReadFile (
filebuffer, mipmap->uncompressedSize, filename.c_str (), true
);
if (file == nullptr)
{
delete [] filebuffer;
delete header;
throw std::runtime_error ("cannot create temporal memory file");
}
image = this->m_context->getDevice ()->getVideoDriver ()->createImageFromFile (file);
if (image == nullptr)
{
// this takes care of freeing filebuffer
file->drop ();
delete [] decompressedBuffer;
delete image;
WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot create destination image\n", input->getFileName ().c_str (), irr::ELL_ERROR);
return nullptr;
delete header;
throw std::runtime_error ("cannot create destination image");
}
}
delete [] decompressedBuffer;
// delete container info as it's not needed anymore
delete header;
return image;
}
void CImageLoaderTex::loadImageFromARGB8Data (IImage* output, const char* input, u32 width, u32 height, u32 mipmap_width) const
// load in the image data
irr::video::IImage *CImageLoaderTex::loadImage (irr::io::IReadFile *input) const
{
u32 bytesPerPixel = output->getBytesPerPixel ();
try
{
return this->parseFile (input);
}
catch (std::runtime_error ex)
{
this->m_context->getDevice ()->getLogger ()->log (
ex.what (), input->getFileName ().c_str (), irr::ELL_ERROR
);
return nullptr;
}
}
void CImageLoaderTex::loadImageFromARGB8Data (irr::video::IImage* output, const char* input, irr::u32 width, irr::u32 height, irr::u32 mipmap_width) const
{
irr::u32 bytesPerPixel = output->getBytesPerPixel ();
char *imagedata = (char *) output->lock ();
for (u32 y = 0; y < height; y ++)
for (irr::u32 y = 0; y < height; y ++)
{
u32 baseDestination = y * output->getPitch ();
u32 baseOrigin = y * (mipmap_width * 4);
irr::u32 baseDestination = y * output->getPitch ();
irr::u32 baseOrigin = y * (mipmap_width * 4);
for (u32 x = 0; x < width; x ++)
for (irr::u32 x = 0; x < width; x ++)
{
imagedata [baseDestination + (x * bytesPerPixel) + 2] = input [baseOrigin + ((width - x) * 4) + 0]; // r
imagedata [baseDestination + (x * bytesPerPixel) + 1] = input [baseOrigin + ((width - x) * 4) + 1]; // g
@ -277,7 +347,7 @@ void CImageLoaderTex::loadImageFromARGB8Data (IImage* output, const char* input,
output->unlock ();
}
void CImageLoaderTex::loadImageFromDXT1 (IImage* output, const char* input, u32 destination_width, u32 destination_height, u32 origin_width, u32 origin_height) const
void CImageLoaderTex::loadImageFromDXT1 (irr::video::IImage* output, const char* input, irr::u32 destination_width, irr::u32 destination_height, irr::u32 origin_width, irr::u32 origin_height) const
{
char* decompressedBuffer = new char [origin_width * origin_height * 4];
@ -287,7 +357,7 @@ void CImageLoaderTex::loadImageFromDXT1 (IImage* output, const char* input, u32
delete [] decompressedBuffer;
}
void CImageLoaderTex::loadImageFromDXT5 (IImage* output, const char* input, u32 destination_width, u32 destination_height, u32 origin_width, u32 origin_height) const
void CImageLoaderTex::loadImageFromDXT5 (irr::video::IImage* output, const char* input, irr::u32 destination_width, irr::u32 destination_height, irr::u32 origin_width, irr::u32 origin_height) const
{
char* decompressedBuffer = new char [origin_width * origin_height * 4];
@ -547,3 +617,4 @@ void CImageLoaderTex::BlockDecompressImageDXT5(unsigned long width, unsigned lon
blockStorage += blockCountX * 16;
}
}
};

View File

@ -1,33 +1,123 @@
#pragma once
#include <irrlicht/irrlicht.h>
#include <vector>
using namespace irr;
using namespace irr::video;
#include <irrlicht/irrlicht.h>
#include "CContext.h"
namespace WallpaperEngine::Irrlicht
{
//! Surface Loader for PNG files
class CImageLoaderTex : public IImageLoader
class CImageLoaderTex : public irr::video::IImageLoader
{
public:
CImageLoaderTex (CContext* context);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".png")
virtual bool isALoadableFileExtension(const io::path& filename) const;
virtual bool isALoadableFileExtension(const irr::io::path& filename) const;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const;
virtual bool isALoadableFileFormat(irr::io::IReadFile* file) const;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* input) const;
virtual irr::video::IImage* loadImage(irr::io::IReadFile* input) const;
virtual void loadImageFromARGB8Data (IImage* output, const char* input, u32 width, u32 height, u32 mipmap_width) const;
virtual void loadImageFromARGB8Data (irr::video::IImage* output, const char* input, irr::u32 width, irr::u32 height, irr::u32 mipmap_width) const;
virtual void loadImageFromDXT1 (IImage* output, const char* input, u32 destination_width, u32 destination_height, u32 origin_width, u32 origin_height) const;
virtual void loadImageFromDXT5 (IImage* output, const char* input, u32 destination_width, u32 destination_height, u32 origin_width, u32 origin_height) const;
virtual void loadImageFromDXT1 (irr::video::IImage* output, const char* input, irr::u32 destination_width, irr::u32 destination_height, irr::u32 origin_width, irr::u32 origin_height) const;
virtual void loadImageFromDXT5 (irr::video::IImage* output, const char* input, irr::u32 destination_width, irr::u32 destination_height, irr::u32 origin_width, irr::u32 origin_height) const;
private:
enum ContainerVersion
{
UNKNOWN = -1,
TEXB0003 = 3,
TEXB0002 = 2,
TEXB0001 = 1
};
class TextureMipmap
{
public:
TextureMipmap ();
~TextureMipmap ();
/** Width of the mipmap */
irr::u32 width;
/** Height of the mipmap */
irr::u32 height;
/** If the mipmap data is compressed */
irr::u32 compression;
/** Uncompressed size of the mipmap */
irr::u32 uncompressedSize;
/** Compress size of the mipmap */
irr::u32 compressedSize;
/** Pointer to the compressed data */
char* compressedData = nullptr;
/** Pointer to the uncompressed data */
char* uncompressedData = nullptr;
/**
* Performs actual decompression of the compressed data
*/
void decompressData ();
};
class TextureContainer
{
public:
TextureContainer ();
~TextureContainer ();
/** The version of the texture container */
ContainerVersion containerVersion = ContainerVersion::UNKNOWN;
/** Real width of the texture */
irr::u32 width;
/** Real height of the texture */
irr::u32 height;
/** Texture width in memory (power of 2) */
irr::u32 textureWidth;
/** Texture height in memory (power of 2) */
irr::u32 textureHeight;
/** Texture data format */
irr::u32 format;
/** Free Image format */
irr::u32 freeimageFormat;
/** Number of mipmap levels for the texture */
irr::u32 mipmapCount;
/** List of mipmaps */
std::vector <TextureMipmap*> mipmaps;
};
/** Irrlicht context */
CContext* m_context;
/**
* Parses the container file and returns a texture ready to be used
*
* @param input The file to parse the data from
*
* @return The texture ready to be used
*/
irr::video::IImage* parseFile (irr::io::IReadFile* input) const;
/**
* Parses the container header and returns it's information
*
* @param input The file to parse the data from
*
* @return The container header data
*/
TextureContainer* parseHeader (irr::io::IReadFile* input) const;
/**
* Parses a mipmap level and returns it's information
*
* @param header The container header where this mipmap is contained
* @param input The file to parse the data from
*
* @return The mipmap info ready
*/
TextureMipmap* parseMipmap (TextureContainer* header, irr::io::IReadFile* input) const;
void BlockDecompressImageDXT1(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image) const;
void DecompressBlockDXT1(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image) const;
unsigned long PackRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) const;

View File

@ -1,43 +1,35 @@
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
#include "CPkgReader.h"
using namespace WallpaperEngine::Irrlicht;
namespace WallpaperEngine::Irrlicht
{
CArchiveLoaderPkg::CArchiveLoaderPkg(irr::io::IFileSystem* fs)
: FileSystem(fs)
CArchiveLoaderPkg::CArchiveLoaderPkg (CContext* context) :
m_context (context)
{
#ifdef _DEBUG
setDebugName("CArchiveLoaderWAD");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
bool CArchiveLoaderPkg::isALoadableFileFormat(const irr::io::path& filename) const
{
return irr::core::hasFileExtension (filename, "pkg");
}
//! Creates an archive from the filename
/** \param file File handle to check.
\return Pointer to newly created archive, or 0 upon error. */
irr::io::IFileArchive* CArchiveLoaderPkg::createArchive(const irr::io::path& filename, bool ignoreCase, bool ignorePaths) const
{
irr::io::IFileArchive *archive = nullptr;
irr::io::IReadFile* file = FileSystem->createAndOpenFile(filename);
irr::io::IReadFile* file = this->m_context->getDevice ()->getFileSystem ()->createAndOpenFile(filename);
if (file)
{
archive = createArchive (file, ignoreCase, ignorePaths);
archive = this->createArchive (file, ignoreCase, ignorePaths);
file->drop ();
}
return archive;
}
//! creates/loads an archive from the file.
//! \return Pointer to the created archive. Returns 0 if loading failed.
irr::io::IFileArchive* CArchiveLoaderPkg::createArchive(irr::io::IReadFile* file, bool ignoreCase, bool ignorePaths) const
{
irr::io::IFileArchive *archive = nullptr;
@ -51,11 +43,6 @@ irr::io::IFileArchive* CArchiveLoaderPkg::createArchive(irr::io::IReadFile* file
return archive;
}
//! Check if the file might be loaded by this class
/** Check might look into the file.
\param file File handle to check.
\return True if file seems to be loadable. */
bool CArchiveLoaderPkg::isALoadableFileFormat(irr::io::IReadFile* file) const
{
unsigned int size;
@ -88,23 +75,21 @@ bool CArchiveLoaderPkg::isALoadableFileFormat(irr::io::E_FILE_ARCHIVE_TYPE fileT
}
CPkgReader::CPkgReader (irr::io::IReadFile* file, bool ignoreCase, bool ignorePaths)
: CFileList((file ? file->getFileName() : irr::io::path("")), ignoreCase, ignorePaths), mFile(file)
: CFileList((file ? file->getFileName() : irr::io::path("")), ignoreCase, ignorePaths), m_file(file)
{
if (this->mFile)
if (this->m_file)
{
this->mFile->grab ();
this->m_file->grab ();
this->scanPkgHeader ();
}
}
CPkgReader::~CPkgReader()
{
if (this->mFile)
this->mFile->drop();
if (this->m_file)
this->m_file->drop();
}
//! get the archive type
irr::io::E_FILE_ARCHIVE_TYPE CPkgReader::getType() const
{
return irr::io::E_FILE_ARCHIVE_TYPE::EFAT_ZIP;
@ -121,26 +106,28 @@ void CPkgReader::scanPkgHeader ()
if (strcmp ("PKGV0002", headerVersion) != 0 && strcmp ("PKGV0001", headerVersion) != 0)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Unexpected package header... Aborting load", this->mFile->getFileName ().c_str (), irr::ELL_ERROR);
delete [] headerVersion;
this->m_context->getDevice ()->getLogger ()->log (
"unexpected package header", this->m_file->getFileName ().c_str (), irr::ELL_ERROR
);
return;
}
delete [] headerVersion;
irr::u32 entriesCount;
unsigned int entriesCount;
this->mFile->read (&entriesCount, 4);
this->m_file->read (&entriesCount, 4);
for (int i = 0; i < entriesCount; i ++)
for (irr::u32 i = 0; i < entriesCount; i ++)
{
char* filename = this->readSizedString ();
unsigned int offset, length;
irr::u32 offset, length;
this->mFile->read (&offset, 4);
this->mFile->read (&length, 4);
this->m_file->read (&offset, 4);
this->m_file->read (&length, 4);
this->addItem (filename, offset, length, false);
@ -148,9 +135,9 @@ void CPkgReader::scanPkgHeader ()
}
// after the header is read we have to update the actual offsets
for (int i = 0; i < this->Files.size (); i ++)
for (irr::u32 i = 0; i < this->m_files.size (); i ++)
{
this->Files [i].Offset += this->mFile->getPos ();
this->m_files [i].Offset += this->m_file->getPos ();
}
}
@ -159,7 +146,7 @@ char* CPkgReader::readSizedString ()
unsigned int size;
char* pointer;
this->mFile->read (&size, 4);
this->m_file->read (&size, 4);
// the string doesnt include the null terminator
size ++;
@ -167,7 +154,7 @@ char* CPkgReader::readSizedString ()
pointer = new char [size];
memset (pointer, 0, size);
this->mFile->read (pointer, size - 1);
this->m_file->read (pointer, size - 1);
return pointer;
}
@ -184,9 +171,10 @@ irr::io::IReadFile* CPkgReader::createAndOpenFile (const irr::io::path& filename
irr::io::IReadFile* CPkgReader::createAndOpenFile (irr::u32 index)
{
if (index > this->Files.size ())
if (index > this->m_files.size ())
return nullptr;
const SFileListEntry entry = Files [index];
return irr::io::createLimitReadFile (entry.FullName, mFile, entry.Offset, entry.Size);
const SFileListEntry entry = m_files [index];
return irr::io::createLimitReadFile (entry.FullName, m_file, entry.Offset, entry.Size);
}
}

View File

@ -2,10 +2,9 @@
#include <irrlicht/irrlicht.h>
#include <string>
#include "CContext.h"
#include "CFileList.h"
using namespace irr;
namespace WallpaperEngine::Irrlicht
{
//! Archiveloader capable of loading WAD Archives
@ -14,7 +13,7 @@ namespace WallpaperEngine::Irrlicht
public:
//! Constructor
CArchiveLoaderPkg(irr::io::IFileSystem *fs);
CArchiveLoaderPkg (CContext* context);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".zip")
@ -43,7 +42,7 @@ namespace WallpaperEngine::Irrlicht
virtual irr::io::IFileArchive *createArchive (irr::io::IReadFile *file, bool ignoreCase, bool ignorePaths) const;
private:
irr::io::IFileSystem *FileSystem;
CContext* m_context;
};
class CPkgReader : public virtual irr::io::IFileArchive, virtual CFileList
@ -73,7 +72,7 @@ namespace WallpaperEngine::Irrlicht
char *readSizedString ();
irr::io::IFileSystem *mFileSystem;
irr::io::IReadFile *mFile;
CContext* m_context;
irr::io::IReadFile *m_file;
};
}

View File

@ -1,8 +0,0 @@
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
namespace WallpaperEngine::Irrlicht
{
irr::video::IVideoDriver* driver = nullptr;
irr::IrrlichtDevice* device = nullptr;
irr::scene::ICameraSceneNode* camera = nullptr;
}

View File

@ -1,10 +0,0 @@
#pragma once
#include <irrlicht/irrlicht.h>
namespace WallpaperEngine::Irrlicht
{
extern irr::video::IVideoDriver* driver;
extern irr::IrrlichtDevice* device;
extern irr::scene::ICameraSceneNode* camera;
};

View File

@ -6,9 +6,6 @@
// filesystem
#include <WallpaperEngine/FileSystem/FileSystem.h>
// video engine
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
// shader compiler
#include <WallpaperEngine/Render/Shaders/Compiler.h>
#include <WallpaperEngine/Core/Core.h>
@ -242,7 +239,7 @@ namespace WallpaperEngine::Render::Shaders
std::string Compiler::precompile()
{
#define BREAK_IF_ERROR if (this->m_error == true) { WallpaperEngine::Irrlicht::device->getLogger ()->log ("ERROR PRE-COMPILING SHADER", irr::ELL_ERROR); WallpaperEngine::Irrlicht::device->getLogger ()->log (this->m_errorInfo.c_str (), irr::ELL_ERROR); return ""; }
#define BREAK_IF_ERROR if (this->m_error == true) { throw std::runtime_error ("ERROR PRE-COMPILING SHADER" + this->m_errorInfo); }
// parse the shader and find #includes and such things and translate them to the correct name
// also remove any #version definition to prevent errors
std::string::const_iterator it = this->m_content.begin ();
@ -441,12 +438,6 @@ namespace WallpaperEngine::Render::Shaders
}
}
if (this->m_recursive == false)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Compiled shader output for", this->m_file.c_str ());
WallpaperEngine::Irrlicht::device->getLogger ()->log (this->m_compiledContent.c_str ());
}
return this->m_compiledContent;
#undef BREAK_IF_ERROR
}
@ -462,8 +453,7 @@ namespace WallpaperEngine::Render::Shaders
if (combo == data.end () || defvalue == data.end ())
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Cannot parse combo information", irr::ELL_ERROR);
return;
throw std::runtime_error ("cannot parse combo information");
}
// check the combos
@ -488,7 +478,7 @@ namespace WallpaperEngine::Render::Shaders
}
else
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Cannot parse combo information, unknown type", irr::ELL_ERROR);
throw std::runtime_error ("cannot parse combo information, unknown type");
}
}
}
@ -504,7 +494,7 @@ namespace WallpaperEngine::Render::Shaders
if (material == data.end () || defvalue == data.end ())
{
if (type != "sampler2D")
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Cannot parse parameter info for ", name.c_str (), irr::ELL_ERROR);
throw std::runtime_error ("cannot parse parameter info for " + name);
return;
}

View File

@ -1,11 +1,12 @@
#include <WallpaperEngine/FileSystem/FileSystem.h>
#include "WallpaperEngine/Irrlicht/CContext.h"
#include "WallpaperEngine/Render/Shaders/Compiler.h"
#include "effect.h"
#include "WallpaperEngine/Irrlicht/Irrlicht.h"
#include "WallpaperEngine/Core/Core.h"
extern irr::f32 g_Time;
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine
{
@ -97,7 +98,7 @@ namespace WallpaperEngine
this->m_fragShader = new WallpaperEngine::Render::Shaders::Compiler (fragpath, WallpaperEngine::Render::Shaders::Compiler::Type::Type_Pixel, &this->m_combos, false);
this->m_vertShader = new WallpaperEngine::Render::Shaders::Compiler (vertpath, WallpaperEngine::Render::Shaders::Compiler::Type::Type_Vertex, &this->m_combos, false);
this->m_materialType = WallpaperEngine::Irrlicht::driver->getGPUProgrammingServices ()
this->m_materialType = IrrlichtContext->getDevice ()->getVideoDriver ()->getGPUProgrammingServices ()
->addHighLevelShaderMaterial (
this->m_vertShader->precompile ().c_str (), "main", irr::video::EVST_VS_2_0,
this->m_fragShader->precompile ().c_str (), "main", irr::video::EPST_PS_2_0,
@ -336,7 +337,7 @@ namespace WallpaperEngine
}
else
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Unknown type for combo value", name.c_str (), irr::ELL_ERROR);
IrrlichtContext->getDevice ()->getLogger ()->log ("Unknown type for combo value", name.c_str (), irr::ELL_ERROR);
}
}
}

View File

@ -5,9 +5,11 @@
#include <WallpaperEngine/object3d.h>
#include <WallpaperEngine/image.h>
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
#include <WallpaperEngine/Irrlicht/CContext.h>
#include <WallpaperEngine/Core/Core.h>
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine
{
image::image (json json_data, WallpaperEngine::object* parent) : object3d (object3d::Type::Type_Material, parent)
@ -153,8 +155,8 @@ namespace WallpaperEngine
0, 1, 2, 3
};
WallpaperEngine::Irrlicht::driver->setMaterial (this->getMaterial ());
WallpaperEngine::Irrlicht::driver->drawVertexPrimitiveList (this->m_vertices, 4, indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT);
IrrlichtContext->getDevice ()->getVideoDriver ()->setMaterial (this->getMaterial ());
IrrlichtContext->getDevice ()->getVideoDriver ()->drawVertexPrimitiveList (this->m_vertices, 4, indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT);
}
}

View File

@ -6,7 +6,6 @@
#include "WallpaperEngine/FileSystem/FileSystem.h"
#include "project.h"
#include "WallpaperEngine/Irrlicht/Irrlicht.h"
namespace WallpaperEngine
{

View File

@ -1,11 +1,9 @@
//
// Created by almamu on 17/05/19.
//
#include <SDL_rwops.h>
#include <SDL_mixer.h>
#include "sound.h"
#include "WallpaperEngine/Irrlicht/Irrlicht.h"
#include "WallpaperEngine/Irrlicht/CContext.h"
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine
{
@ -31,7 +29,7 @@ namespace WallpaperEngine
{
SDL_RWops* sdlRwops = nullptr;
Mix_Music* music = nullptr;
irr::io::IReadFile* readfile = WallpaperEngine::Irrlicht::device->getFileSystem ()->createAndOpenFile ((*cur).c_str ());
irr::io::IReadFile* readfile = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile ((*cur).c_str ());
int filesize = readfile->getSize ();
char* filebuffer = new char [filesize];
@ -43,7 +41,7 @@ namespace WallpaperEngine
if (music == nullptr)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Cannot load audio", Mix_GetError (), irr::ELL_ERROR);
IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot load audio", Mix_GetError (), irr::ELL_ERROR);
}
this->m_bufferReader.push_back (sdlRwops);
@ -58,7 +56,7 @@ namespace WallpaperEngine
{
if (Mix_PlayMusic ((*mixcur), -1) == -1)
{
WallpaperEngine::Irrlicht::device->getLogger ()->log ("Cannot play audio", Mix_GetError (), irr::ELL_ERROR);
IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot play audio", Mix_GetError (), irr::ELL_ERROR);
}
}
}

View File

@ -2,13 +2,15 @@
#include <stdexcept>
#include <lz4.h>
#include "WallpaperEngine/Irrlicht/Irrlicht.h"
#include <WallpaperEngine/Irrlicht/CContext.h>
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine
{
texture::texture (irr::io::path& file)
{
this->m_texture = WallpaperEngine::Irrlicht::driver->getTexture (file);
this->m_texture = IrrlichtContext->getDevice ()->getVideoDriver ()->getTexture (file);
}
irr::video::ITexture* texture::getIrrTexture ()

View File

@ -1,5 +1,7 @@
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
#include <WallpaperEngine/video/material.h>
#include <WallpaperEngine/Irrlicht/CContext.h>
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine
{
@ -56,8 +58,10 @@ namespace WallpaperEngine
0, 1, 2, 3
};
WallpaperEngine::Irrlicht::driver->setMaterial (m_material);
WallpaperEngine::Irrlicht::driver->drawVertexPrimitiveList (m_vertices, 4, indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT);
IrrlichtContext->getDevice ()->getVideoDriver ()->setMaterial (m_material);
IrrlichtContext->getDevice ()->getVideoDriver ()->drawVertexPrimitiveList (
m_vertices, 4, indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT
);
}
}
}

View File

@ -1,5 +1,7 @@
#include <WallpaperEngine/Irrlicht/Irrlicht.h>
#include <WallpaperEngine/video/renderer.h>
#include <WallpaperEngine/Irrlicht/CContext.h>
extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
namespace WallpaperEngine
{
@ -31,19 +33,19 @@ namespace WallpaperEngine
znear,
zfar
);
WallpaperEngine::Irrlicht::camera = WallpaperEngine::Irrlicht::device->getSceneManager ()->addCameraSceneNode (0, position, lookat);
WallpaperEngine::Irrlicht::camera->setProjectionMatrix (orthoProjection);
s_camera = IrrlichtContext->getDevice ()->getSceneManager ()->addCameraSceneNode (0, position, lookat);
s_camera->setProjectionMatrix (orthoProjection);
WallpaperEngine::Irrlicht::driver->setTransform (irr::video::ETS_PROJECTION, orthoProjection);
WallpaperEngine::Irrlicht::driver->setTransform (irr::video::ETS_VIEW, identity);
WallpaperEngine::Irrlicht::driver->setTransform (irr::video::ETS_WORLD, identity);
IrrlichtContext->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_PROJECTION, orthoProjection);
IrrlichtContext->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_VIEW, identity);
IrrlichtContext->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_WORLD, identity);
}
void renderer::render ()
{
if (WallpaperEngine::Irrlicht::driver == nullptr) return;
if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) return;
WallpaperEngine::Irrlicht::driver->beginScene(true, true, irr::video::SColor(0, 0, 0, 0));
IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene(true, true, irr::video::SColor(0, 0, 0, 0));
std::vector<node*>::const_iterator cur = s_nodes.begin ();
std::vector<node*>::const_iterator end = s_nodes.end ();
@ -53,9 +55,10 @@ namespace WallpaperEngine
(*cur)->render ();
}
WallpaperEngine::Irrlicht::driver->endScene ();
IrrlichtContext->getDevice ()->getVideoDriver ()->endScene ();
}
std::vector<node*> renderer::s_nodes;
irr::scene::ICameraSceneNode* renderer::s_camera;
}
};

View File

@ -20,6 +20,7 @@ namespace WallpaperEngine
private:
static std::vector<node*> s_nodes;
static irr::scene::ICameraSceneNode* s_camera;
};
}
}