Merge pull request #711 from MihailRis/fixes

0.30.1 fixes
This commit is contained in:
MihailRis 2025-12-01 02:04:03 +03:00 committed by GitHub
commit ecba496f12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 23 additions and 80 deletions

View File

@ -12,7 +12,7 @@
#include "logic/scripting/scripting.hpp" #include "logic/scripting/scripting.hpp"
#include "core_defs.hpp" #include "core_defs.hpp"
static void load_configs(Input& input, const io::path& root) { static void load_configs(Input* input, const io::path& root) {
auto configFolder = root / "config"; auto configFolder = root / "config";
} }
@ -26,7 +26,7 @@ static std::vector<io::path> default_content_sources {
ContentControl::ContentControl( ContentControl::ContentControl(
const Project& project, const Project& project,
EnginePaths& paths, EnginePaths& paths,
Input& input, Input* input,
std::function<void()> postContent std::function<void()> postContent
) )
: paths(paths), : paths(paths),

View File

@ -19,7 +19,7 @@ public:
ContentControl( ContentControl(
const Project& project, const Project& project,
EnginePaths& paths, EnginePaths& paths,
Input& input, Input* input,
std::function<void()> postContent std::function<void()> postContent
); );
~ContentControl(); ~ContentControl();
@ -49,7 +49,7 @@ public:
const std::vector<io::path>& getContentSources() const; const std::vector<io::path>& getContentSources() const;
private: private:
EnginePaths& paths; EnginePaths& paths;
Input& input; Input* input;
std::unique_ptr<Content> content; std::unique_ptr<Content> content;
std::function<void()> postContent; std::function<void()> postContent;
std::vector<std::string> basePacks; std::vector<std::string> basePacks;

View File

@ -10,7 +10,7 @@
#include "coders/toml.hpp" #include "coders/toml.hpp"
// All in-game definitions (blocks, items, etc..) // All in-game definitions (blocks, items, etc..)
void corecontent::setup(Input& input, ContentBuilder& builder) { void corecontent::setup(Input* input, ContentBuilder& builder) {
{ {
Block& block = builder.blocks.create(CORE_AIR); Block& block = builder.blocks.create(CORE_AIR);
block.replaceable = true; block.replaceable = true;
@ -28,8 +28,8 @@ void corecontent::setup(Input& input, ContentBuilder& builder) {
} }
auto bindsFile = "res:bindings.toml"; auto bindsFile = "res:bindings.toml";
if (io::is_regular_file(bindsFile)) { if (input && io::is_regular_file(bindsFile)) {
input.getBindings().read( input->getBindings().read(
toml::parse(bindsFile, io::read_string(bindsFile)), BindType::BIND toml::parse(bindsFile, io::read_string(bindsFile)), BindType::BIND
); );
} }

View File

@ -32,5 +32,5 @@ class Input;
class ContentBuilder; class ContentBuilder;
namespace corecontent { namespace corecontent {
void setup(Input& input, ContentBuilder& builder); void setup(Input* input, ContentBuilder& builder);
} }

View File

@ -163,9 +163,9 @@ void Engine::initialize(CoreParameters coreParameters) {
langs::locale_by_envlocale(platform::detect_locale()) langs::locale_by_envlocale(platform::detect_locale())
); );
} }
content = std::make_unique<ContentControl>(*project, *paths, *input, [this]() { content = std::make_unique<ContentControl>(
onContentLoad(); *project, *paths, input.get(), [this]() { onContentLoad(); }
}); );
scripting::initialize(this); scripting::initialize(this);
if (!isHeadless()) { if (!isHeadless()) {

View File

@ -3,7 +3,6 @@
#include <GL/glew.h> #include <GL/glew.h>
#include "Texture.hpp" #include "Texture.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "gl_util.hpp"
static debug::Logger logger("gl-framebuffer"); static debug::Logger logger("gl-framebuffer");
@ -20,35 +19,21 @@ Framebuffer::Framebuffer(uint fbo, uint depth, std::unique_ptr<Texture> texture)
} }
static std::unique_ptr<Texture> create_texture(int width, int height, int format) { static std::unique_ptr<Texture> create_texture(int width, int height, int format) {
GLuint texture; GLuint tex;
glGenTextures(1, &texture); glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D( glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, nullptr);
GL_TEXTURE_2D,
0,
format,
width,
height,
0,
format,
GL_UNSIGNED_BYTE,
nullptr
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D( glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0 return std::make_unique<Texture>(tex, width, height);
);
return std::make_unique<Texture>(texture, width, height);
} }
Framebuffer::Framebuffer(uint width, uint height, bool alpha) Framebuffer::Framebuffer(uint width, uint height, bool alpha)
: width(width), height(height) : width(width), height(height)
{ {
width = std::max<uint>(1, width);
height = std::max<uint>(1, height);
glGenFramebuffers(1, &fbo); glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo);
@ -60,17 +45,11 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha)
// Setup depth attachment // Setup depth attachment
glGenRenderbuffers(1, &depth); glGenRenderbuffers(1, &depth);
glBindRenderbuffer(GL_RENDERBUFFER, depth); glBindRenderbuffer(GL_RENDERBUFFER, depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
glFramebufferRenderbuffer( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth
);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
if (status != GL_FRAMEBUFFER_COMPLETE) { logger.error() << "framebuffer is not complete!";
auto logLine = logger.error();
logLine << "framebuffer is not complete: ";
logLine << gl::to_string(status);
logLine << " (" << status << ")";
} }
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -99,7 +78,7 @@ void Framebuffer::resize(uint width, uint height) {
glBindFramebuffer(GL_FRAMEBUFFER, fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glBindRenderbuffer(GL_RENDERBUFFER, depth); glBindRenderbuffer(GL_RENDERBUFFER, depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
texture = create_texture(width, height, format); texture = create_texture(width, height, format);

View File

@ -45,40 +45,4 @@ namespace gl {
} }
return 0; return 0;
} }
/// TODO: extend
inline const char* to_string(GLenum item) {
switch (item) {
case GL_INVALID_ENUM:
return "invalid enum";
case GL_INVALID_VALUE:
return "invalid value";
case GL_INVALID_OPERATION:
return "invalid operation";
case GL_STACK_OVERFLOW:
return "stack overflow";
case GL_STACK_UNDERFLOW:
return "stack underflow";
case GL_OUT_OF_MEMORY:
return "out of memory";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "invalid framebuffer operation";
case GL_FRAMEBUFFER_UNDEFINED:
return "framebuffer undefined";
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
return "framebuffer incomplete attachment";
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
return "framebuffer incomplete missing attachment";
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
return "framebuffer incomplete draw buffer";
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
return "framebuffer incomplete read buffer";
case GL_FRAMEBUFFER_UNSUPPORTED:
return "framebuffer unsupported";
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
return "framebuffer incomplete multisample";
default:
return "unknown";
}
}
} }

View File

@ -22,6 +22,6 @@ void gui::Canvas::draw(const DrawContext& pctx, const Assets& assets) {
void gui::Canvas::setSize(const glm::vec2& size) { void gui::Canvas::setSize(const glm::vec2& size) {
UINode::setSize(size); UINode::setSize(size);
data->extend(size.x, size.y); data->extend(std::max<int>(1, size.x), std::max<int>(1, size.y));
texture->reload(*data); texture->reload(*data);
} }