From 5651b71788487e986ea945d76cbaf647d4554813 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 14 Nov 2021 16:23:15 +0500 Subject: Added dynamic textures for Gal --- src/GalOgl.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/GalOgl.cpp') diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp index 4fb2794..e39f5f0 100644 --- a/src/GalOgl.cpp +++ b/src/GalOgl.cpp @@ -265,7 +265,7 @@ class TextureConfigOgl : public TextureConfig { public: Format format; - size_t width = 0, height = 0, depth = 0; + size_t width = 1, height = 1, depth = 1; bool interpolateLayers = false; Filtering min = Filtering::Nearest, max = Filtering::Nearest; @@ -292,10 +292,11 @@ public: GLenum type; GLuint texture; Format format; - size_t width = 0, height = 0, depth = 0; + size_t width, height, depth; virtual void SetData(std::vector&& data, size_t mipLevel = 0) override { - if (data.size() != width * height * depth * GalFormatGetSize(format)) + size_t expectedSize = width * height * depth * GalFormatGetSize(format); + if (data.size() != expectedSize) throw std::logic_error("Size of data is not valid for this texture"); glBindTexture(type, texture); @@ -405,6 +406,14 @@ public: glCheckError(); } + virtual void SetDynamicTexture(std::string_view name, std::shared_ptr texture) override { + Activate(); + glActiveTexture(GL_TEXTURE0); + auto tex = std::static_pointer_cast(texture); + glBindTexture(tex->type, tex->texture); + SetShaderParameter(name, 0); + } + virtual std::shared_ptr CreateInstance(std::vector, std::shared_ptr>>&& buffers) override { auto instance = std::make_shared(); @@ -590,6 +599,7 @@ public: config->width = width; config->height = height; + config->depth = 1; config->format = format; return std::static_pointer_cast(config); @@ -619,14 +629,15 @@ public: glGenTextures(1, &texture->texture); glCheckError(); + glBindTexture(texture->type, texture->texture); - glTexParameteri(texture->type, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(texture->type, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(texture->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(texture->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - + glTexParameteri(texture->type, GL_TEXTURE_MIN_FILTER, GalFilteringGetGlType(texConfig->min)); + glTexParameteri(texture->type, GL_TEXTURE_MAG_FILTER, GalFilteringGetGlType(texConfig->max)); + glTexParameteri(texture->type, GL_TEXTURE_WRAP_S, GalWrappingGetGlType(texConfig->wrap)); + glTexParameteri(texture->type, GL_TEXTURE_WRAP_T, GalWrappingGetGlType(texConfig->wrap)); glCheckError(); + glBindTexture(texture->type, 0); texture->SetData(std::vector(texture->width * texture->height * texture->depth * GalFormatGetSize(texture->format))); glCheckError(); -- cgit v1.2.3