Working on texture loading

TODO:
add mutex and combine loaded texture files
	-resizing is handled by the thread, hopefully this isn't an issue
load the loaded textures into the palette
main
Brett 2023-03-01 00:52:27 -05:00
parent 8f57ab7567
commit f10b119db1
29 changed files with 246 additions and 32 deletions

BIN
assets/textures/1592234267606.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
assets/textures/1592244663459.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

BIN
assets/textures/BEEETSLAP2.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
assets/textures/BEEETSLAP4.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

View File

@ -9,7 +9,7 @@
19 685 1675834610617266094 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/vulkan.c.o 7ac098ea2e755b71
2 377 1675835240591243670 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/window.c.o a716fdf6afcb3ac2
19 807 1675834610745269744 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/x11_init.c.o 7a310a4749a2e05
0 98 1676692075130989618 build.ninja 190f84590f6ee728
0 98 1677646232987812125 build.ninja 190f84590f6ee728
2 434 1675915441258513581 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/format.cpp.o 342a5daa6ca9681d
18 706 1675834610629266436 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/init.c.o 6051295f860fb367
909 1200 1676342906918621193 libraries/BLT/libBLT.a 163b10f2e7f6635
@ -38,3 +38,96 @@
2 316 1675881681815231506 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o ac1bd7bf33d73c31
1 1096 1676342796027625557 CMakeFiles/FinalProject.dir/src/render/gl.cpp.o d59ba6eec5836ace
706 883 1675834610809271567 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/linux_joystick.c.o afc8940b6e7eeae1
2 95 1677649373135226320 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftwinfnt.c.o f3fe63e530ab7f66
96 403 1677649373439235016 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/context.c.o 67b8270a9d8c8b86
3 478 1677649373515237186 CMakeFiles/FinalProject.dir/src/render/ui/debug.cpp.o 9b5b6b6b3f0368f8
403 551 1677649373583239133 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/init.c.o 6051295f860fb367
478 734 1677649373771244508 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/input.c.o cb7dfd07cdb7c2ab
551 747 1677649373783244853 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/monitor.c.o 239e3c995f2fc57c
734 858 1677649373895248053 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/vulkan.c.o 7ac098ea2e755b71
747 922 1677649373959249883 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/window.c.o a716fdf6afcb3ac2
3 1028 1677649374067252971 CMakeFiles/FinalProject.dir/src/util/settings.cpp.o c4b57a0cc73f7657
2 1060 1677649374099253889 CMakeFiles/FinalProject.dir/src/render/camera.cpp.o 74696c090eadc64c
858 1084 1677649374123254573 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/x11_init.c.o 7a310a4749a2e05
923 1095 1677649374131254802 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/x11_monitor.c.o 7b77fa660f2cb562
1060 1159 1677649374199256749 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/xkb_unicode.c.o 86b8813c62a6792d
1084 1165 1677649374203256861 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/posix_time.c.o d8774ad87358fe12
3 1168 1677649374203256861 CMakeFiles/FinalProject.dir/src/render/window.cpp.o fe3bf24074ba9c2f
1095 1169 1677649374207256976 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/posix_thread.c.o 1da38a427ecbe82e
3 1233 1677649374271258806 CMakeFiles/FinalProject.dir/src/world/chunk/storage.cpp.o 86aa0a8ddf11de85
2 1277 1677649374315260064 CMakeFiles/FinalProject.dir/src/render/gl.cpp.o ccad926a95c7d624
4 1286 1677649374323260293 CMakeFiles/FinalProject.dir/src/world/chunk/world.cpp.o 2444998966663b23
1169 1298 1677649374335260638 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/linux_joystick.c.o afc8940b6e7eeae1
1168 1300 1677649374339260750 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/osmesa_context.c.o c49ca4e889b3908b
1160 1304 1677649374343260865 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/glx_context.c.o cc5282d2f93e112a
1166 1348 1677649374387262123 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/egl_context.c.o e777fb0716cc9fd8
4 1465 1677649374503265440 CMakeFiles/FinalProject.dir/src/world/registry.cpp.o 6515e540120cf543
1029 1503 1677649374539266469 libraries/glfw-3.3.8/src/CMakeFiles/glfw.dir/x11_window.c.o f99a7b64357948e7
3 1522 1677649374559267041 CMakeFiles/FinalProject.dir/src/render/ui/text.cpp.o 3f3d3a73c649dbc9
2 1551 1677649374587267842 CMakeFiles/FinalProject.dir/src/main.cpp.o aca4a00492403aa
1503 1580 1677649374615268643 libraries/glfw-3.3.8/src/libglfw3.a fd552f215cfdce3e
1233 1610 1677649374647269557 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o ac1bd7bf33d73c31
1610 1651 1677649374691270819 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftbdf.c.o bee13becfa6b57c0
1580 1656 1677649374695270930 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftbbox.c.o 8a62fa0cfa4d95cb
1656 1710 1677649374747272417 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftcid.c.o c5d515ae6d477f99
1710 1764 1677649374803274019 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftfstype.c.o e63d4e616c6a179c
1651 1775 1677649374815274363 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftbitmap.c.o 8ce02b3a42c98959
1465 1789 1677649374827274708 libraries/BLT/CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o 18383112b14888b9
1278 1809 1677649374847275277 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/format.cpp.o 342a5daa6ca9681d
1764 1821 1677649374859275620 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftgasp.c.o 765695940f7927ce
1304 1829 1677649374867275849 libraries/BLT/CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o a93fa48842fb10a4
1789 1840 1677649374879276194 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftgxval.c.o 3ce33c8355865f1e
1829 1873 1677649374911277107 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftotval.c.o 2befc05d4fd3d014
1300 1878 1677649374915277224 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/system.cpp.o d9d07699ecf3c7f6
1810 1881 1677649374919277336 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftinit.c.o 9bf07f1afe4c5120
1775 1887 1677649374927277567 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftglyph.c.o c0170043ef27b5f5
1840 1892 1677649374931277679 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftpatent.c.o 6617c5fd2e75a2f9
1821 1923 1677649374963278597 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftmm.c.o cf1be7fdfe3293b
1873 1924 1677649374963278597 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftpfr.c.o ba3859c14ff3f825
1881 1943 1677649374983279166 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftsynth.c.o f15a6ee99e365112
1887 1943 1677649374983279166 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/fttype1.c.o 7445b24b2c7b8b76
1923 1959 1677649374999279626 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/bzip2/ftbzip2.c.o c17349c766699177
1959 2033 1677649375071281685 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/gzip/ftgzip.c.o 2c2048d1c33c9c8e
1878 2116 1677649375155284084 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftstroke.c.o b06d184e6ee0c3cf
2033 2123 1677649375163284316 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/lzw/ftlzw.c.o a201a733bc3b4ec8
1286 2165 1677649375203285458 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/loader.cpp.o 7528e7ecb90e9c26
1943 2187 1677649375223286031 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/cid/type1cid.c.o be0bd83f7173b535
1924 2248 1677649375287287862 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/cache/ftcache.c.o 656d9fc7811ee06
1892 2301 1677649375339289347 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/bdf/bdf.c.o ddb0f432e836cc5a
2 2310 1677649375347289575 CMakeFiles/FinalProject.dir/src/render/textures.cpp.o 4b76c6f5e8fb67cf
2116 2355 1677649375391290833 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/pcf/pcf.c.o 310cd7429a066580
1523 2364 1677649375399291062 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/autofit/autofit.c.o dfd2d84933895bc9
1551 2408 1677649375443292323 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftbase.c.o fbb6e43e2ee99b37
2248 2429 1677649375467293009 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/psnames/psnames.c.o 9dd17fefb41a7747
2187 2453 1677649375491293693 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/pshinter/pshinter.c.o 3c5f25dbf5470a11
2408 2478 1677649375515294382 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/svg/svg.c.o 3c521ba5d5506f6d
2123 2512 1677649375551295411 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/pfr/pfr.c.o dc7ddf024affda22
1943 2531 1677649375567295868 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/cff/cff.c.o 4c729d49aae7bc8
2301 2550 1677649375587296441 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/raster/raster.c.o 4ad85cadbb69f690
2550 2591 1677649375631297699 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/base/ftdebug.c.o b73c3b9b7d19e4d5
2531 2592 1677649375631297699 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/builds/unix/ftsystem.c.o 646b9527782db911
2364 2598 1677649375635297811 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/smooth/smooth.c.o c331096b07abb778
2310 2626 1677649375663298611 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/sdf/sdf.c.o 38ad17921be0aede
2512 2663 1677649375699299641 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/winfonts/winfnt.c.o 99de1f5432d0d5a2
1298 2663 1677649375699299641 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o 13e8110c601a4029
2478 2696 1677649375735300670 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/type42/type42.c.o b7bf5e77154bf28e
2453 2936 1677649375975307536 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/type1/type1.c.o 41bca485020c6b18
1348 2988 1677649376023308906 libraries/BLT/CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o f6cc949795fe632a
2165 2996 1677649376035309249 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/psaux/psaux.c.o 9b8069e5249a1b7d
2988 3059 1677649376087310736 libraries/BLT/libBLT.a b8f809e0bb7338ed
2429 3502 1677649376539323661 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/truetype/truetype.c.o 4890f2f4fad4ba77
2355 3521 1677649376559324233 libraries/freetype-2.13.0/CMakeFiles/freetype.dir/src/sfnt/sfnt.c.o b6a300408588c21f
3521 3621 1677649376643326637 libraries/freetype-2.13.0/libfreetyped.a 3cbc64a6495debe0
3621 3788 1677649376823331785 FinalProject de45775e2c99866f
2 956 1677649423704671928 CMakeFiles/FinalProject.dir/src/world/registry.cpp.o 6515e540120cf543
956 1138 1677649423884677070 FinalProject de45775e2c99866f
2 1002 1677649491354604396 CMakeFiles/FinalProject.dir/src/world/registry.cpp.o 6515e540120cf543
1002 1173 1677649491526609307 FinalProject de45775e2c99866f
2 965 1677649590285204977 CMakeFiles/FinalProject.dir/src/world/registry.cpp.o 6515e540120cf543
965 1155 1677649590473209388 FinalProject de45775e2c99866f
2 814 1677649714444173863 CMakeFiles/FinalProject.dir/src/world/chunk/storage.cpp.o 86aa0a8ddf11de85
3 1062 1677649714692179896 CMakeFiles/FinalProject.dir/src/world/registry.cpp.o 6515e540120cf543
2 1123 1677649714756181454 CMakeFiles/FinalProject.dir/src/main.cpp.o aca4a00492403aa
3 1156 1677649714788182233 CMakeFiles/FinalProject.dir/src/world/chunk/world.cpp.o 2444998966663b23
2 1561 1677649715192192069 CMakeFiles/FinalProject.dir/src/render/textures.cpp.o 4b76c6f5e8fb67cf
1561 1734 1677649715364196256 FinalProject de45775e2c99866f

Binary file not shown.

View File

@ -1,3 +1,3 @@
Start testing: Feb 15 10:00 EST
Start testing: Mar 01 00:48 EST
----------------------------------------------------------
End testing: Feb 15 10:00 EST
End testing: Mar 01 00:48 EST

View File

@ -11,7 +11,7 @@
#include <render/window.h>
#include <vector>
#include <unordered_map>
#include <blt/std/math.h>
#include <blt/math/math.h>
#include <blt/std/string.h>
#include <string>

View File

@ -31,8 +31,8 @@ namespace fp::texture {
*/
explicit file_texture(const std::string& path, const std::string& name = ""): m_Name(name.empty() ? path : name), m_Path(path) {}
static file_texture* load(file_texture* texture) {
stbi_load(texture->m_Path.c_str(), &texture->width, &texture->height, &texture->channels, 4);
static file_texture* load(file_texture*& texture) {
texture->m_Data = stbi_load(texture->m_Path.c_str(), &texture->width, &texture->height, &texture->channels, 0);
return texture;
}
@ -51,12 +51,26 @@ namespace fp::texture {
texture->m_Data = output_Data;
texture->width = target_width;
texture->height = target_height;
return texture;
}
unsigned char* data() {
return m_Data;
}
[[nodiscard]] int getChannels() const {
return channels;
}
[[nodiscard]] int getWidth() const {
return width;
}
[[nodiscard]] int getHeight() const {
return height;
}
[[nodiscard]] const std::string& getName() {
return m_Name;
}
@ -77,6 +91,7 @@ namespace fp::texture {
m_width(width), m_height(height), textureBindType(bind_type), textureColorMode(color_mode) {
glGenTextures(1, &textureID);
}
public:
void bind() const {
glBindTexture(textureBindType, textureID);
@ -119,12 +134,21 @@ namespace fp::texture {
glTexStorage2D(textureBindType, std::stoi(fp::settings::get("MIPMAP_LEVELS")), colorMode, width, height);
}
void upload(void* data, int level = 0, int x_offset = 0, int y_offset = 0, int sub_width = -1, int sub_height = -1) const {
void upload(
void* data, GLint dataColorMode = GL_RGBA, int level = 0, int x_offset = 0, int y_offset = 0, int sub_width = -1,
int sub_height = -1
) const {
if (sub_width < 0)
sub_width = m_width;
if (sub_height < 0)
sub_height = m_height;
glTexSubImage2D(textureBindType, level, x_offset, y_offset, sub_width, sub_height, textureColorMode, GL_UNSIGNED_BYTE, data);
bind();
glTexSubImage2D(textureBindType, level, x_offset, y_offset, sub_width, sub_height, dataColorMode, GL_UNSIGNED_BYTE, data);
unbind();
}
void upload(file_texture* texture) const {
upload(texture->data(), texture->getChannels() == 4 ? GL_RGBA : GL_RGB);
}
};
@ -137,24 +161,31 @@ namespace fp::texture {
bind();
glTexStorage3D(textureBindType, std::stoi(fp::settings::get("MIPMAP_LEVELS")), colorMode, width, height, layers);
}
void upload(void* data, int index, int level = 0, int x_offset = 0, int y_offset = 0, int sub_width = -1, int sub_height = -1) const {
void upload(
void* data, int index, GLint dataColorMode = GL_RGBA, int level = 0, int x_offset = 0, int y_offset = 0, int sub_width = -1,
int sub_height = -1
) const {
if (sub_width < 0)
sub_width = m_width;
if (sub_height < 0)
sub_height = m_height;
glTexSubImage3D(textureBindType, level, x_offset, y_offset, index, sub_width, sub_height, 1, textureColorMode, GL_UNSIGNED_BYTE, data);
bind();
glTexSubImage3D(textureBindType, level, x_offset, y_offset, index, sub_width, sub_height, 1, dataColorMode, GL_UNSIGNED_BYTE, data);
unbind();
}
};
typedef int texture_index;
class palette {
private:
union negDInt {
int i = -1;
texture_index i = -1;
};
// as of GL3.0 this limit is 256. (4.5 extends it to 2048.)
static constexpr int MAX_ARRAY_LAYERS = 256;
gl_texture2D_array* texture_array = nullptr;
std::unordered_map<std::string, negDInt> textureIndices;
@ -166,17 +197,14 @@ namespace fp::texture {
void generateGLTexture() {
delete texture_array;
auto texture_size = std::stoi(fp::settings::get("TEXTURE_SIZE"));
texture_array = new gl_texture2D_array(texture_size, texture_size, (int)textures.size());
texture_array = new gl_texture2D_array(texture_size, texture_size, (int) textures.size());
for (const auto t : textures)
texture_array->upload(t->data(), textureIndices[t->getName()].i);
texture_array->upload(t->data(), textureIndices[t->getName()].i, t->getChannels() == 4 ? GL_RGBA : GL_RGB);
texture_array->setDefaults();
texture_array->generateMipmaps();
}
void registerTexture(file_texture* texture) {
auto texture_size = std::stoi(fp::settings::get("TEXTURE_SIZE"));
texture = file_texture::resize(texture, texture_size, texture_size);
textureIndices[texture->getName()].i = (int) textures.size();
textures.push_back(texture);
}
@ -184,8 +212,8 @@ namespace fp::texture {
bool hasTexture(const std::string& name) {
return textureIndices[name].i >= 0;
}
int getTexture(const std::string& name) {
texture_index getTexture(const std::string& name) {
return textureIndices[name].i;
}

View File

@ -7,7 +7,7 @@
#ifndef FINALPROJECT_TEXT_H
#define FINALPROJECT_TEXT_H
#include <blt/std/math.h>
#include <blt/math/math.h>
#include <string>
namespace fp::text {

View File

@ -21,7 +21,7 @@
#define EGL_EGLEXT_PROTOTYPES
#endif
#include <GLFW/glfw3.h>
#include <blt/std/math.h>
#include <blt/math/math.h>
namespace fp::window {
/**

View File

@ -7,7 +7,7 @@
#ifndef FINALPROJECT_STORAGE_H
#define FINALPROJECT_STORAGE_H
#include <blt/std/math.h>
#include <blt/math/math.h>
#include <vector>
#include "blt/std/logging.h"
#include <world/chunk/typedefs.h>

View File

@ -7,28 +7,52 @@
#ifndef FINALPROJECT_REGISTRY_H
#define FINALPROJECT_REGISTRY_H
#include <string>
#include <render/textures.h>
namespace fp {
typedef unsigned char block_type;
}
namespace fp::registry {
/**
* Bit masked enum description how the block should be treated by the renderer
*/
enum block_visibility {
// has no transparency
OPAQUE = 0,
TRANSLUCENT = 1,
TRANSPARENT = 2,
// opaque but texture has alpha which should be treated as 100% transparent
// this allows us to insert it into the opaque blocks render but requires us to include its neighbour's mesh
TRANSPARENT_TEXTURE = 1,
// texture is partially see-through
TRANSLUCENT = 2,
// block should be treated as 100% transparent everywhere
TRANSPARENT = 4,
};
struct block_properties {
// how should we handle this block? Blocks with transparent textures can be added to OPAQUE blocks
block_visibility visibility = OPAQUE;
// does this block produce light?
bool produces_light = false;
// WebGL doesn't default to empty textures, use index 0 to store an empty texture
std::string textureName = "Air";
};
constexpr block_type AIR = 0;
constexpr block_type STONE = 1;
void registerBlock(block_type id, block_properties properties);
void registerTexture(texture::file_texture* texture);
void setupThreads(int count = 8);
void generatePalette();
block_properties get(block_type id);
unsigned int getTextureID(const std::string& name);
texture::texture_index getTextureIndex(const std::string& name);
/**
@ -39,5 +63,19 @@ namespace fp::registry {
registerBlock(STONE, {});
}
inline void registerDefaultTextures() {
setupThreads();
registerTexture(new texture::file_texture{"assets/textures/1676004600027876.jpg", "Stone"});
registerTexture(new texture::file_texture{"assets/textures/1668750351593692.jpg", "Dirt"});
registerTexture(new texture::file_texture{"assets/textures/1638777414645.jpg", "Dolph"});
registerTexture(new texture::file_texture{"assets/textures/1603423355849.jpg", "Sit"});
registerTexture(new texture::file_texture{"assets/textures/1603422678312.jpg", "Loser"});
registerTexture(new texture::file_texture{"assets/textures/1592244663459.png", "Frog"});
registerTexture(new texture::file_texture{"assets/textures/1592234267606.png", "Explode"});
generatePalette();
}
}
#endif //FINALPROJECT_REGISTRY_H

@ -1 +1 @@
Subproject commit d72441f1703fa44d397b960e4e9e761f07786505
Subproject commit 61ae482e5d7dcf6a472a841645998f0e42b423bd

View File

@ -29,6 +29,8 @@ void loop(){
world->update();
world->render(*chunk_shader);
fp::text::drawText("Hello There", 0, 0, fp::text::FONT_18, {0,0,0, 1.0});
fp::camera::update();
fp::debug::render();
fp::text::render();
@ -49,6 +51,7 @@ int main() {
fp::window::init();
fp::text::init();
fp::registry::registerDefaultBlocks();
fp::registry::registerDefaultTextures();
chunk_shader = new fp::shader(shader_chunk_vert, shader_chunk_frag);
world = new fp::world();

View File

@ -5,7 +5,7 @@
*/
#include <render/camera.h>
#include <render/gl.h>
#include <blt/std/math.h>
#include <blt/math/math.h>
#include <cmath>
#include "util/math.h"
@ -73,9 +73,9 @@ void updateViewMatrix(){
viewMatrix.m23(float(z.w()));
// view matrix are inverted, dot product to simulate translate matrix multiplication
viewMatrix.m03(-float(blt::vec<4>::dot(x, blt::vec<4>{position.x(), position.y(), position.z(), 0})));
viewMatrix.m13(-float(blt::vec<4>::dot(y, blt::vec<4>{position.x(), position.y(), position.z(), 0})));
viewMatrix.m23(-float(blt::vec<4>::dot(z, blt::vec<4>{position.x(), position.y(), position.z(), 0})));
viewMatrix.m03(-float(blt::vec<float, 4>::dot(x, blt::vec<float, 4>{position.x(), position.y(), position.z(), 0})));
viewMatrix.m13(-float(blt::vec<float, 4>::dot(y, blt::vec<float, 4>{position.x(), position.y(), position.z(), 0})));
viewMatrix.m23(-float(blt::vec<float, 4>::dot(z, blt::vec<float, 4>{position.x(), position.y(), position.z(), 0})));
viewMatrix.m33(1);
fp::shader::updateViewMatrix(viewMatrix);

View File

@ -6,7 +6,7 @@
#include <render/ui/debug.h>
#include <render/ui/text.h>
#include <render/window.h>
#include <blt/std/math.h>
#include <blt/math/averages.h>
namespace fp::debug {
const float spacing = 5;

View File

@ -5,13 +5,65 @@
*/
#include <world/registry.h>
#include <unordered_map>
#include <utility>
#include <thread>
#include <mutex>
#include <queue>
std::unordered_map<fp::block_type, fp::registry::block_properties> blocks;
fp::texture::palette base_palette;
std::queue<fp::texture::file_texture*>* texture_loader_queues;
std::thread** texture_loader_threads;
int thread_count = 0;
void fp::registry::registerBlock(fp::block_type id, fp::registry::block_properties properties) {
blocks[id] = properties;
blocks[id] = std::move(properties);
}
fp::registry::block_properties fp::registry::get(fp::block_type id) {
return blocks.at(id);
}
void fp::registry::registerTexture(fp::texture::file_texture* texture) {
base_palette.registerTexture(texture);
}
unsigned int fp::registry::getTextureID(const std::string& name) {
return base_palette.getTextureID();
}
fp::texture::texture_index fp::registry::getTextureIndex(const std::string& name) {
return base_palette.getTexture(name);
}
void fp::registry::generatePalette() {
for (int i = 0; i < thread_count; i++) {
texture_loader_threads[i]->join();
delete texture_loader_threads[i];
}
BLT_INFO("Finished loading all textures!");
delete[] texture_loader_queues;
delete[] texture_loader_threads;
base_palette.generateGLTexture();
BLT_INFO("Palette generated!");
}
void fp::registry::setupThreads(int count) {
BLT_DEBUG("Setting up texture loading threads (%d)", count);
thread_count = count;
texture_loader_queues = new std::queue<fp::texture::file_texture*>[count];
texture_loader_threads = new std::thread*[count];
for (int i = 0; i < count; i++){
texture_loader_threads[i] = new std::thread([](int thread_id) -> void {
while (!texture_loader_queues[thread_id].empty()) {
auto& top = texture_loader_queues[thread_id].front();
auto texture_size = std::stoi(fp::settings::get("TEXTURE_SIZE"));
auto t = texture::file_texture::resize(texture::file_texture::load(top), texture_size, texture_size);
texture_loader_queues[thread_id].pop();
}
}, i);
}
}