diff --git a/.gitignore b/.gitignore
index bef7478..5def830 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
cmake-build-debug
assets.zip
.idea
-assets/
\ No newline at end of file
+assets/
+lib/
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ba0366a..92bd29a 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,6 +1,6 @@
-
+
@@ -8,285 +8,127 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
- GL_INVA
- GLSL TEST
- arb
- include
- if
- version
- define
- main
- #
- preproces
- m_token
- device
- getAb
- Compiled shader output for
- getFileSystem
- string
- ::resolve
- append
- new wp::image
- new wp::object
- mater
- do_decompres
- nier_
- IShaderConstantSetCallBack
- Failed reso
- changeWorkingDirectory
- ::fileResolver
- "."
- ->render
- Failed
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- DEFINITION_ORDER
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
+
-
+
+
+
@@ -298,26 +140,99 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
@@ -344,61 +259,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -424,351 +301,16 @@
- file://$PROJECT_DIR$/wallpaperengine/video/renderer.cpp
- 52
-
+ file://$PROJECT_DIR$/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp
+ 34
+
+
+
+ file://$PROJECT_DIR$/src/WallpaperEngine/Render/Shaders/Compiler.cpp
+ 601
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b7bf56..0d85d5f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,9 +6,13 @@ set(CMAKE_CXX_FLAGS "-fpermissive")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
set(OpenGL_GL_PREFERENCE "LEGACY")
+add_compile_definitions(DEBUG=1)
+
find_package(X11 REQUIRED)
find_package(Xrandr REQUIRED)
find_package(OpenGL REQUIRED)
+find_package(GLFW3 3.1 REQUIRED)
+find_package(GLEW REQUIRED)
find_package(GLUT REQUIRED)
find_package(ZLIB REQUIRED)
find_package(Irrlicht REQUIRED)
@@ -17,12 +21,23 @@ find_package(SDL_mixer REQUIRED)
find_package(LZ4 REQUIRED)
find_package(FFmpeg REQUIRED)
-include_directories(${X11_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} ${FFMPEG_INCLUDE_DIR} src include)
+include_directories(${X11_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${glfw3_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} ${FFMPEG_INCLUDE_DIR} src include)
add_executable(
wallengine
main.cpp
+ src/WallpaperEngine/Assets/CContainer.h
+ src/WallpaperEngine/Assets/CContainer.cpp
+ src/WallpaperEngine/Assets/CCombinedContainer.h
+ src/WallpaperEngine/Assets/CCombinedContainer.cpp
+ src/WallpaperEngine/Assets/CDirectory.h
+ src/WallpaperEngine/Assets/CDirectory.cpp
+ src/WallpaperEngine/Assets/CPackage.h
+ src/WallpaperEngine/Assets/CPackage.cpp
+ src/WallpaperEngine/Assets/CTexture.h
+ src/WallpaperEngine/Assets/CTexture.cpp
+
src/WallpaperEngine/Core/Core.h
src/WallpaperEngine/Core/Core.cpp
@@ -163,4 +178,4 @@ add_executable(
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h
)
-target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES} ${FFMPEG_LIBRARIES})
\ No newline at end of file
+target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW3_LIBRARY} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES} ${FFMPEG_LIBRARIES})
\ No newline at end of file
diff --git a/CMakeModules/FindGLFW3.cmake b/CMakeModules/FindGLFW3.cmake
new file mode 100644
index 0000000..134dea7
--- /dev/null
+++ b/CMakeModules/FindGLFW3.cmake
@@ -0,0 +1,47 @@
+# Locate the glfw3 library
+#
+# This module defines the following variables:
+#
+# GLFW3_LIBRARY the name of the library;
+# GLFW3_INCLUDE_DIR where to find glfw include files.
+# GLFW3_FOUND true if both the GLFW3_LIBRARY and GLFW3_INCLUDE_DIR have been found.
+#
+# To help locate the library and include file, you can define a
+# variable called GLFW3_ROOT which points to the root of the glfw library
+# installation.
+#
+# default search dirs
+#
+# Cmake file from: https://github.com/daw42/glslcookbook
+
+set( _glfw3_HEADER_SEARCH_DIRS
+ "/usr/include"
+ "/usr/local/include"
+ "${CMAKE_SOURCE_DIR}/includes" )
+set( _glfw3_LIB_SEARCH_DIRS
+ "/usr/lib"
+ "/usr/local/lib"
+ "${CMAKE_SOURCE_DIR}/lib")
+
+# Check environment for root search directory
+set( _glfw3_ENV_ROOT $ENV{GLFW3_ROOT} )
+if( NOT GLFW3_ROOT AND _glfw3_ENV_ROOT )
+ set(GLFW3_ROOT ${_glfw3_ENV_ROOT} )
+endif()
+
+# Put user specified location at beginning of search
+if( GLFW3_ROOT )
+ list( INSERT _glfw3_HEADER_SEARCH_DIRS 0 "${GLFW3_ROOT}/include" )
+ list( INSERT _glfw3_LIB_SEARCH_DIRS 0 "${GLFW3_ROOT}/lib" )
+endif()
+
+# Search for the header
+FIND_PATH(GLFW3_INCLUDE_DIR "GLFW/glfw3.h"
+ PATHS ${_glfw3_HEADER_SEARCH_DIRS} )
+
+# Search for the library
+FIND_LIBRARY(GLFW3_LIBRARY NAMES glfw3 glfw
+ PATHS ${_glfw3_LIB_SEARCH_DIRS} )
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLFW3 DEFAULT_MSG
+ GLFW3_LIBRARY GLFW3_INCLUDE_DIR)
diff --git a/main.cpp b/main.cpp
index dfd798d..bd9e714 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,15 +1,28 @@
#include
#include
#include
+#include
#include
#include
+#include
+#include
+
+#include
+#include
+
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Irrlicht/CContext.h"
#include "WallpaperEngine/Render/CWallpaper.h"
#include "WallpaperEngine/Render/CScene.h"
#include "WallpaperEngine/Render/CVideo.h"
+#include "WallpaperEngine/Assets/CPackage.h"
+#include "WallpaperEngine/Assets/CDirectory.h"
+#include "WallpaperEngine/Assets/CCombinedContainer.h"
+
+#include "WallpaperEngine/Core/Types/FloatColor.h"
+
enum BACKGROUND_RUN_MODE
{
RUN_MODE_UNKNOWN = 0,
@@ -19,7 +32,9 @@ enum BACKGROUND_RUN_MODE
};
WallpaperEngine::Irrlicht::CContext* IrrlichtContext = nullptr;
-irr::f32 g_Time;
+double g_Time;
+
+using namespace WallpaperEngine::Core::Types;
void print_help (const char* route)
{
@@ -117,6 +132,157 @@ int main (int argc, char* argv[])
return 0;
}
+ // first of all, initialize the window
+ if (glfwInit () == GLFW_FALSE)
+ {
+ fprintf (stderr, "Failed to initialize GLFW\n");
+ return 1;
+ }
+
+ // set some window hints (opengl version to be used)
+ glfwWindowHint (GLFW_SAMPLES, 4);
+ glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 2);
+ glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
+
+ // create the window!
+ // TODO: DO WE NEED TO PASS MONITOR HERE OR ANYTHING?
+ // TODO: FIGURE OUT HOW TO PUT THIS WINDOW IN THE BACKGROUND
+ GLFWwindow* window = glfwCreateWindow (1920, 1080, "WallpaperEngine", NULL, NULL);
+
+ if (window == nullptr)
+ {
+ fprintf (stderr, "Failed to open a GLFW window");
+ glfwTerminate ();
+ return 2;
+ }
+
+ glfwMakeContextCurrent (window);
+
+ int windowWidth = 1920;
+ int windowHeight = 1080;
+
+ // get the real framebuffer size
+ glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
+
+ if (glewInit () != GLEW_OK)
+ {
+ fprintf (stderr, "Failed to initialize GLEW");
+ glfwTerminate ();
+ return 3;
+ }
+
+ std::string project_path = path + "project.json";
+ auto containers = new WallpaperEngine::Assets::CCombinedContainer ();
+
+ // add containers to the list
+ containers->add (new WallpaperEngine::Assets::CDirectory ("./assets/"));
+ // the background's path is required to load project.json regardless of the type of background we're using
+ containers->add (new WallpaperEngine::Assets::CDirectory (path));
+
+ if (mode == RUN_MODE_PACKAGE)
+ {
+ std::string scene_path = path + "scene.pkg";
+
+ // add the package to the list
+ containers->add (new WallpaperEngine::Assets::CPackage (scene_path));
+ }
+ else if (mode == RUN_MODE_DIRECTORY)
+ {
+ // nothing to do here anymore
+ }
+
+ // parse the project.json file
+ auto project = WallpaperEngine::Core::CProject::fromFile ("project.json", containers);
+ WallpaperEngine::Render::CWallpaper* wallpaper;
+
+ if (project->getType () == "scene")
+ {
+ WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as ();
+ wallpaper = new WallpaperEngine::Render::CScene (scene, containers);
+ // TODO: BUILD THE SCENE
+ }
+ else if (project->getType () == "video")
+ {
+ // TODO: BUILD THE VIDEO OBJECT
+ }
+ else
+ {
+ throw std::runtime_error ("Unsupported wallpaper type");
+ }
+
+ if (shouldEnableAudio == true)
+ {
+ int mixer_flags = MIX_INIT_MP3 | MIX_INIT_FLAC | MIX_INIT_OGG;
+
+ if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags))
+ {
+ // Mix_GetError is an alias for SDL_GetError, so calling it directly will yield the correct result
+ // it doesn't matter if SDL_Init or Mix_Init failed, both report the errors through the same functions
+ IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot initialize SDL audio system", SDL_GetError(),irr::ELL_ERROR);
+ return 2;
+ }
+
+ // initialize audio engine
+ Mix_OpenAudio (22050, AUDIO_S16SYS, 2, 640);
+ }
+
+ // TODO: FIGURE OUT THE REQUIRED INPUT MODE, AS SOME WALLPAPERS USE THINGS LIKE MOUSE POSITION
+ // glfwSetInputMode (window, GLFW_STICKY_KEYS, GL_TRUE);
+
+ // set the scene clear color
+ auto sceneInformation = project->getWallpaper ()->as ();
+ FloatColor clearColor = sceneInformation->getClearColor ();
+
+ glClearColor (clearColor.r, clearColor.g, clearColor.b, clearColor.a);
+
+ // enable depth text
+ glEnable (GL_DEPTH_TEST);
+ glDepthFunc (GL_LESS);
+
+ // cull anything that doesn't look at the camera (might be useful to disable in the future)
+ //glEnable (GL_CULL_FACE);
+
+ clock_t minimumTime = 1000 / maximumFPS;
+ clock_t startTime = 0;
+ clock_t endTime = 0;
+
+ while (glfwWindowShouldClose (window) == 0)
+ {
+ // calculate the current time value
+ g_Time += static_cast (endTime - startTime) / CLOCKS_PER_SEC;
+ // get the start time of the frame
+ startTime = clock ();
+
+ // do not use any framebuffer for now
+ glBindFramebuffer (GL_FRAMEBUFFER, 0);
+ // ensure we render over the whole screen
+ glViewport (0, 0, 1920, 1080);
+
+ // clear window
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ // render the scene
+ wallpaper->render ();
+
+ // do buffer swapping
+ glfwSwapBuffers (window);
+ // poll for events (like closing the window)
+ glfwPollEvents ();
+ // get the end time of the frame
+ endTime = clock ();
+
+ // ensure the frame time is correct to not overrun FPS
+ if ((endTime - startTime) < minimumTime)
+ usleep (static_cast ((static_cast (endTime - startTime) / CLOCKS_PER_SEC) * 1000));
+ }
+
+ // terminate gl
+ glfwTerminate ();
+ // terminate SDL
+ SDL_Quit ();
+
+ return 0;
+/*
try
{
IrrlichtContext = new WallpaperEngine::Irrlicht::CContext (screens, isRootWindow);
@@ -147,22 +313,6 @@ int main (int argc, char* argv[])
IrrlichtContext->getDevice ()->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path);
}
- if (shouldEnableAudio == true)
- {
- int mixer_flags = MIX_INIT_MP3 | MIX_INIT_FLAC | MIX_INIT_OGG;
-
- if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags))
- {
- // Mix_GetError is an alias for SDL_GetError, so calling it directly will yield the correct result
- // it doesn't matter if SDL_Init or Mix_Init failed, both report the errors through the same functions
- IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot initialize SDL audio system", SDL_GetError(),irr::ELL_ERROR);
- return 2;
- }
-
- // initialize audio engine
- Mix_OpenAudio (22050, AUDIO_S16SYS, 2, 640);
- }
-
WallpaperEngine::Core::CProject* project = WallpaperEngine::Core::CProject::fromFile (project_path);
WallpaperEngine::Render::CWallpaper* wallpaper;
@@ -206,5 +356,5 @@ int main (int argc, char* argv[])
}
SDL_Quit ();
- return 0;
+ return 0;*/
}
\ No newline at end of file
diff --git a/src/WallpaperEngine/Assets/CCombinedContainer.cpp b/src/WallpaperEngine/Assets/CCombinedContainer.cpp
new file mode 100644
index 0000000..ad710e8
--- /dev/null
+++ b/src/WallpaperEngine/Assets/CCombinedContainer.cpp
@@ -0,0 +1,31 @@
+#include "CCombinedContainer.h"
+
+using namespace WallpaperEngine::Assets;
+
+void CCombinedContainer::add (CContainer* container)
+{
+ this->m_containers.emplace_back (container);
+}
+
+void* CCombinedContainer::readFile (std::string filename, uint32_t* length)
+{
+ auto cur = this->m_containers.begin ();
+ auto end = this->m_containers.end ();
+
+ for (; cur != end; cur ++)
+ {
+ try
+ {
+ // try to read the file on the current container, if the file doesn't exists
+ // an exception will be thrown
+ return (*cur)->readFile (filename, length);
+ }
+ catch (std::exception& ex)
+ {
+ // not found in this container, next try
+ }
+ }
+
+ // no container was able to load the file, abort!
+ throw std::runtime_error ("Cannot find the file in any of the containers");
+}
\ No newline at end of file
diff --git a/src/WallpaperEngine/Assets/CCombinedContainer.h b/src/WallpaperEngine/Assets/CCombinedContainer.h
new file mode 100644
index 0000000..d5b2f79
--- /dev/null
+++ b/src/WallpaperEngine/Assets/CCombinedContainer.h
@@ -0,0 +1,32 @@
+//
+// Created by almamu on 8/8/21.
+//
+
+#pragma once
+
+#include
+#include
+
+#include "CContainer.h"
+
+namespace WallpaperEngine::Assets
+{
+ class CCombinedContainer : public CContainer
+ {
+ public:
+ CCombinedContainer () {}
+ ~CCombinedContainer () {}
+
+ /**
+ * Adds a container to the list
+ *
+ * @param container
+ */
+ void add (CContainer* container);
+
+ void* readFile (std::string filename, uint32_t* length) override;
+
+ private:
+ std::vector m_containers;
+ };
+};
\ No newline at end of file
diff --git a/src/WallpaperEngine/Assets/CContainer.cpp b/src/WallpaperEngine/Assets/CContainer.cpp
new file mode 100644
index 0000000..cec2788
--- /dev/null
+++ b/src/WallpaperEngine/Assets/CContainer.cpp
@@ -0,0 +1,50 @@
+#include "CContainer.h"
+
+#include
+#include
+
+using namespace WallpaperEngine::Assets;
+
+void* CContainer::readTexture (std::string filename, uint32_t* length)
+{
+ // get the texture's filename (usually .tex)
+ filename = "materials/" + filename + ".tex";
+
+ return this->readFile (filename, length);
+}
+
+std::string CContainer::readVertexShader (const std::string& filename)
+{
+ return this->readFileAsString ("shaders/" + filename + ".vert");
+}
+
+std::string CContainer::readFragmentShader (const std::string& filename)
+{
+ return this->readFileAsString ("shaders/" + filename + ".frag");
+}
+
+std::string CContainer::readIncludeShader (const std::string& filename)
+{
+ return this->readFileAsString ("shaders/" + filename);
+}
+
+std::string CContainer::readFileAsString (std::string filename)
+{
+ uint32_t length = 0;
+
+ // read file contents and allocate a buffer for a string
+ void* contents = this->readFile (std::move (filename), &length);
+ char* buffer = new char [length + 1];
+
+ // ensure there's a 0 at the end
+ memset (buffer, 0, length + 1);
+ // copy over the data
+ memcpy (buffer, contents, length);
+ // now build the std::string to use
+ std::string result = buffer;
+
+ // free the intermediate buffer used to generate the std::string
+ delete[] buffer;
+
+ return result;
+}
\ No newline at end of file
diff --git a/src/WallpaperEngine/Assets/CContainer.h b/src/WallpaperEngine/Assets/CContainer.h
new file mode 100644
index 0000000..6969a0d
--- /dev/null
+++ b/src/WallpaperEngine/Assets/CContainer.h
@@ -0,0 +1,75 @@
+//
+// Created by almamu on 8/8/21.
+//
+
+#pragma once
+
+#include
+
+namespace WallpaperEngine::Assets
+{
+ class CContainer
+ {
+ public:
+ /**
+ * Reads the given file from the container and returns it's data
+ * Additionally sets a length parameter to return back the file's length
+ *
+ * @param filename The file to read
+ * @param length The file's length after it's been read, null for not getting anything back
+ *
+ * @return
+ */
+ virtual void* readFile (std::string filename, uint32_t* length = nullptr) = 0;
+
+ /**
+ * Wrapper for readFile, appends the texture extension at the end of the filename
+ *
+ * @param filename The texture name (without the .tex)
+ * @param length The file's length after it's been read
+ *
+ * @return
+ */
+ void* readTexture (std::string filename, uint32_t* length);
+
+ /**
+ * Wrapper for readFile, appends the .vert extension at the end and opens the given shader file
+ *
+ * @param filename
+ * @param length
+ *
+ * @return The shader code as an string to be used
+ */
+ std::string readVertexShader (const std::string& filename);
+
+ /**
+ * Wrapper for readFile, appends the .frag extension at the end and opens the given shader file
+ *
+ * @param filename
+ * @param length
+ *
+ * @return The shader code as an string to be used
+ */
+ std::string readFragmentShader (const std::string& filename);
+
+ /**
+ * Wrapper for readFile, appends the .h extension at the end and opens the given shader file
+ *
+ * @param filename
+ * @param length
+ *
+ * @return The shader code as an string to be used
+ */
+ std::string readIncludeShader (const std::string& filename);
+
+ private:
+ /**
+ * Reads a file as string
+ *
+ * @param filename
+ *
+ * @return The file's contents as string
+ */
+ std::string readFileAsString (std::string filename);
+ };
+}
\ No newline at end of file
diff --git a/src/WallpaperEngine/Assets/CDirectory.cpp b/src/WallpaperEngine/Assets/CDirectory.cpp
new file mode 100644
index 0000000..73a55bf
--- /dev/null
+++ b/src/WallpaperEngine/Assets/CDirectory.cpp
@@ -0,0 +1,58 @@
+#include "CDirectory.h"
+
+using namespace WallpaperEngine::Assets;
+
+CDirectory::CDirectory (std::string basepath) :
+ m_basepath (std::move (basepath))
+{
+ // TODO: ENSURE THE BASEPATH ENDS WITH A LEADING /
+}
+
+CDirectory::~CDirectory ()
+{
+
+}
+
+void* CDirectory::readFile (std::string filename, uint32_t* length)
+{
+ std::string final = this->m_basepath + filename;
+
+ // first check the cache, if the file is there already just return the data in there
+ auto it = this->m_cache.find (final);
+
+ if (it != this->m_cache.end ())
+ {
+ *length = (*it).second.length;
+ return (*it).second.address;
+ }
+
+ FILE* fp = fopen (final.c_str (), "rb");
+
+ if (fp == nullptr)
+ throw std::runtime_error ("Cannot find requested file");
+
+ // go to the end, get the position and return to the beginning
+ fseek (fp, 0, SEEK_END);
+ long size = ftell (fp);
+ fseek (fp, 0, SEEK_SET);
+
+ // now read the whole file
+ char* contents = new char[size];
+
+ if (fread (contents, size, 1, fp) != 1)
+ {
+ delete[] contents;
+ throw std::runtime_error ("Unexpected error when reading the file");
+ }
+
+ // store it in the cache too
+ this->m_cache.insert (std::make_pair (
+ std::move (final),
+ CFileEntry (contents, size)
+ ));
+
+ if (length != nullptr)
+ *length = size;
+
+ return contents;
+}
\ No newline at end of file
diff --git a/src/WallpaperEngine/Assets/CDirectory.h b/src/WallpaperEngine/Assets/CDirectory.h
new file mode 100644
index 0000000..ae6158d
--- /dev/null
+++ b/src/WallpaperEngine/Assets/CDirectory.h
@@ -0,0 +1,26 @@
+//
+// Created by almamu on 8/8/21.
+//
+#pragma once
+
+#include
+#include
+#include