Compare commits
2
Commits
6972128ad2
...
55af11d831
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55af11d831 | ||
|
|
26cd35d679 |
@@ -13,9 +13,7 @@ file(GLOB_RECURSE GAME_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
|
|||||||
|
|
||||||
add_executable(${GAME} ${GAME_SOURCES})
|
add_executable(${GAME} ${GAME_SOURCES})
|
||||||
target_include_directories(${GAME} PRIVATE
|
target_include_directories(${GAME} PRIVATE
|
||||||
"src"
|
"src")
|
||||||
"${CMAKE_SOURCE_DIR}/src"
|
|
||||||
"${CMAKE_SOURCE_DIR}/vendor/ruc/src")
|
|
||||||
target_link_libraries(${GAME} ${ENGINE})
|
target_link_libraries(${GAME} ${ENGINE})
|
||||||
|
|
||||||
target_precompile_headers(${GAME} REUSE_FROM ${ENGINE})
|
target_precompile_headers(${GAME} REUSE_FROM ${ENGINE})
|
||||||
@@ -25,5 +23,5 @@ target_precompile_headers(${GAME} REUSE_FROM ${ENGINE})
|
|||||||
# Add 'make run' target
|
# Add 'make run' target
|
||||||
add_custom_target(run
|
add_custom_target(run
|
||||||
COMMAND ${GAME}
|
COMMAND ${GAME}
|
||||||
WORKING_DIRECTORY ".."
|
WORKING_DIRECTORY "..")
|
||||||
)
|
add_dependencies(run ${ENGINE})
|
||||||
|
|||||||
+1
-3
@@ -1,14 +1,12 @@
|
|||||||
file(GLOB_RECURSE ENGINE_SOURCES "${ENGINE}/*.cpp")
|
file(GLOB_RECURSE ENGINE_SOURCES "${ENGINE}/*.cpp")
|
||||||
|
|
||||||
add_library(${ENGINE} ${ENGINE_SOURCES})
|
add_library(${ENGINE} ${ENGINE_SOURCES})
|
||||||
target_include_directories(${ENGINE} PRIVATE
|
target_include_directories(${ENGINE} PUBLIC
|
||||||
"."
|
"."
|
||||||
"../vendor/entt/src"
|
"../vendor/entt/src"
|
||||||
"../vendor/glad/include"
|
|
||||||
"../vendor/glfw/include"
|
"../vendor/glfw/include"
|
||||||
"../vendor/glm"
|
"../vendor/glm"
|
||||||
"../vendor/json/include"
|
"../vendor/json/include"
|
||||||
"../vendor/lua"
|
|
||||||
"../vendor/ruc/src"
|
"../vendor/ruc/src"
|
||||||
"../vendor/sol2/include"
|
"../vendor/sol2/include"
|
||||||
"../vendor/stb")
|
"../vendor/stb")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <climits> // UINT_MAX
|
#include <climits> // UINT_MAX
|
||||||
|
#include <cstdint> // uint8_t, uint32_t
|
||||||
#include <memory> // std::shared_ptr
|
#include <memory> // std::shared_ptr
|
||||||
#include <utility> // std::move
|
#include <utility> // std::move
|
||||||
|
|
||||||
@@ -21,34 +22,27 @@ namespace Inferno {
|
|||||||
Texture::Texture(const std::string& path)
|
Texture::Texture(const std::string& path)
|
||||||
: m_path(std::move(path))
|
: m_path(std::move(path))
|
||||||
{
|
{
|
||||||
int width;
|
unsigned char* data = nullptr;
|
||||||
int height;
|
int width = 0;
|
||||||
int channels;
|
int height = 0;
|
||||||
|
int channels = 0;
|
||||||
|
|
||||||
// Load image data
|
// Load image data
|
||||||
stbi_set_flip_vertically_on_load(1);
|
stbi_set_flip_vertically_on_load(1);
|
||||||
unsigned char* data = stbi_load(path.c_str(), &width, &height, &channels, STBI_default);
|
data = stbi_load(path.c_str(), &width, &height, &channels, STBI_default);
|
||||||
|
VERIFY(data, "failed to load image: '{}'", path);
|
||||||
|
|
||||||
VERIFY(data, "Failed to load image: '{}'", path);
|
init(data, width, height, channels);
|
||||||
|
|
||||||
m_width = width;
|
|
||||||
m_height = height;
|
|
||||||
|
|
||||||
if (channels == 4) {
|
|
||||||
m_internalFormat = GL_RGBA8;
|
|
||||||
m_dataFormat = GL_RGBA;
|
|
||||||
}
|
|
||||||
else if (channels == 3) {
|
|
||||||
m_internalFormat = GL_RGB8;
|
|
||||||
m_dataFormat = GL_RGB;
|
|
||||||
}
|
|
||||||
|
|
||||||
create(data);
|
|
||||||
|
|
||||||
// Clean resources
|
// Clean resources
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Texture::Texture(unsigned char* data, uint32_t width, uint32_t height, uint8_t channels)
|
||||||
|
{
|
||||||
|
init(data, width, height, channels);
|
||||||
|
}
|
||||||
|
|
||||||
Texture::~Texture()
|
Texture::~Texture()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &m_id);
|
glDeleteTextures(1, &m_id);
|
||||||
@@ -70,6 +64,25 @@ void Texture::unbind() const
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
void Texture::init(unsigned char* data, uint32_t width, uint32_t height, uint8_t channels)
|
||||||
|
{
|
||||||
|
m_width = width;
|
||||||
|
m_height = height;
|
||||||
|
|
||||||
|
if (channels == 4) {
|
||||||
|
m_internalFormat = GL_RGBA8;
|
||||||
|
m_dataFormat = GL_RGBA;
|
||||||
|
}
|
||||||
|
else if (channels == 3) {
|
||||||
|
m_internalFormat = GL_RGB8;
|
||||||
|
m_dataFormat = GL_RGB;
|
||||||
|
}
|
||||||
|
|
||||||
|
create(data);
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::create(unsigned char* data)
|
void Texture::create(unsigned char* data)
|
||||||
{
|
{
|
||||||
m_id = UINT_MAX;
|
m_id = UINT_MAX;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint8_t, uint32_t
|
||||||
#include <memory> // std::shared_ptr
|
#include <memory> // std::shared_ptr
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <unordered_map> // std::unordered_map
|
#include <unordered_map> // std::unordered_map
|
||||||
@@ -18,6 +18,7 @@ namespace Inferno {
|
|||||||
class Texture {
|
class Texture {
|
||||||
public:
|
public:
|
||||||
Texture(const std::string& path);
|
Texture(const std::string& path);
|
||||||
|
Texture(unsigned char* data, uint32_t width, uint32_t height, uint8_t channels = 3);
|
||||||
virtual ~Texture();
|
virtual ~Texture();
|
||||||
|
|
||||||
void bind(uint32_t unit = 0) const;
|
void bind(uint32_t unit = 0) const;
|
||||||
@@ -31,6 +32,7 @@ public:
|
|||||||
inline uint32_t dataFormat() const { return m_dataFormat; }
|
inline uint32_t dataFormat() const { return m_dataFormat; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void init(unsigned char* data, uint32_t width, uint32_t height, uint8_t channels);
|
||||||
void create(unsigned char* data);
|
void create(unsigned char* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -47,7 +49,7 @@ private:
|
|||||||
class TextureManager final : public ruc::Singleton<TextureManager> {
|
class TextureManager final : public ruc::Singleton<TextureManager> {
|
||||||
public:
|
public:
|
||||||
TextureManager(s);
|
TextureManager(s);
|
||||||
virtual ~TextureManager();
|
~TextureManager();
|
||||||
|
|
||||||
void add(const std::string& path, std::shared_ptr<Texture> texture);
|
void add(const std::string& path, std::shared_ptr<Texture> texture);
|
||||||
std::shared_ptr<Texture> load(const std::string& path);
|
std::shared_ptr<Texture> load(const std::string& path);
|
||||||
|
|||||||
Vendored
+1
-1
@@ -18,7 +18,7 @@ list(REMOVE_ITEM LUA "${CMAKE_CURRENT_SOURCE_DIR}/lua/lua/lua.c") # Do not co
|
|||||||
set(ENGINE_SOURCES ${GLAD} ${LUA})
|
set(ENGINE_SOURCES ${GLAD} ${LUA})
|
||||||
|
|
||||||
add_library(${ENGINE}-dependencies ${ENGINE_SOURCES})
|
add_library(${ENGINE}-dependencies ${ENGINE_SOURCES})
|
||||||
target_include_directories(${ENGINE}-dependencies PRIVATE
|
target_include_directories(${ENGINE}-dependencies PUBLIC
|
||||||
"glad/include"
|
"glad/include"
|
||||||
"lua")
|
"lua")
|
||||||
target_link_libraries(${ENGINE}-dependencies glfw ruc)
|
target_link_libraries(${ENGINE}-dependencies glfw ruc)
|
||||||
|
|||||||
Reference in New Issue
Block a user