2023-07-02 14:21:25 +02:00
|
|
|
// Copyright [2023] Krzysztof Rudnicki
|
2023-04-02 17:59:15 +02:00
|
|
|
/*******************************************************************
|
|
|
|
|
** This code is part of Breakout.
|
|
|
|
|
**
|
|
|
|
|
** Breakout is free software: you can redistribute it and/or modify
|
|
|
|
|
** it under the terms of the CC BY 4.0 license as published by
|
|
|
|
|
** Creative Commons, either version 4 of the License, or (at your
|
|
|
|
|
** option) any later version.
|
|
|
|
|
******************************************************************/
|
2023-07-06 17:35:25 +02:00
|
|
|
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_HPP
|
|
|
|
|
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_HPP
|
2023-04-02 17:59:15 +02:00
|
|
|
|
|
|
|
|
#include "../dependencies/include/glad/glad.h"
|
|
|
|
|
|
2023-07-02 14:44:29 +02:00
|
|
|
#include "../breakout/shader.hpp"
|
2023-07-06 17:35:25 +02:00
|
|
|
#include "../breakout/texture.hpp"
|
2023-04-02 17:59:15 +02:00
|
|
|
|
|
|
|
|
// A static singleton ResourceManager class that hosts several
|
|
|
|
|
// functions to load Textures and Shaders. Each loaded texture
|
|
|
|
|
// and/or shader is also stored for future reference by string
|
2023-07-02 14:44:29 +02:00
|
|
|
// handles. All functions and resources are static and no
|
2023-04-02 17:59:15 +02:00
|
|
|
// public constructor is defined.
|
2023-07-02 14:44:29 +02:00
|
|
|
class ResourceManager {
|
2023-07-11 19:20:19 +02:00
|
|
|
public:
|
|
|
|
|
// resource storage
|
|
|
|
|
template <> static std::max<std::string, Shader>;
|
|
|
|
|
Shaders{};
|
|
|
|
|
template <> static std::max<std::string, Texture2D>;
|
|
|
|
|
Textures{};
|
|
|
|
|
// loads (and generates) a shader program from file loading vertex,
|
|
|
|
|
// fragment (and geometry) shader's source code.
|
|
|
|
|
// If gShaderFile is not nullptr, it also loads a geometry shader
|
|
|
|
|
static auto LoadShader(const char *vShaderFile, const char *fShaderFile,
|
|
|
|
|
const char *gShaderFile, const std::string &name)
|
|
|
|
|
-> Shader;
|
|
|
|
|
// retrieves a stored sader
|
|
|
|
|
static auto GetShader(const std::string &name) -> Shader;
|
|
|
|
|
// loads (and generates) a texture from file
|
|
|
|
|
static auto LoadTexture(const char *file, bool alpha, const std::string &name)
|
|
|
|
|
-> Texture2D;
|
|
|
|
|
// retrieves a stored texture
|
|
|
|
|
static auto GetTexture(const std::string &name) -> Texture2D;
|
|
|
|
|
// properly de-allocates all loaded resources
|
|
|
|
|
static void Clear();
|
2023-07-02 14:44:29 +02:00
|
|
|
|
2023-07-11 19:20:19 +02:00
|
|
|
private:
|
|
|
|
|
// private constructor,
|
|
|
|
|
// that is we do not want any actual resource manager objects.
|
|
|
|
|
// Its members and functions should be publicly available (static).
|
|
|
|
|
ResourceManager() = default;
|
|
|
|
|
// loads and generates a shader from file
|
|
|
|
|
static Shader ResourceManager::createShaderObject(
|
|
|
|
|
std::string vertexCode, std::string fragmentCode,
|
|
|
|
|
const char *gShaderFile, std::string geometryCode);
|
|
|
|
|
static std::string ResourceManager::loadFragmentCode(const char *fShaderFile);
|
|
|
|
|
static std::string ResourceManager::loadVertexCode(const char *vShaderFile);
|
|
|
|
|
static std::string ResourceManager::loadGeometryCode(const char *gShaderFile);
|
|
|
|
|
static auto loadShaderFromFile(const char *vShaderFile,
|
|
|
|
|
const char *fShaderFile,
|
|
|
|
|
const char *gShaderFile) -> Shader;
|
|
|
|
|
// loads a single texture from file
|
|
|
|
|
static Texture2D ResourceManager::createTextureObject();
|
|
|
|
|
static auto loadTextureFromFile(const char *file, bool alpha) -> Texture2D;
|
2023-04-02 17:59:15 +02:00
|
|
|
};
|
2023-07-02 14:44:29 +02:00
|
|
|
|
2023-07-06 17:35:25 +02:00
|
|
|
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_HPP
|