summaryrefslogtreecommitdiffstats
path: root/src/GalOgl.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-11-28 12:16:29 +0100
committerLaG1924 <lag1924@gmail.com>2021-11-28 12:16:29 +0100
commit8286ddda96a5f2925d342d0ce115aa00ae5d94ec (patch)
treeaa46a01fb6230a5c994046c7b4823ae1b35c2c37 /src/GalOgl.cpp
parentChanged shaders to use SPB (diff)
downloadAltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.gz
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.bz2
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.lz
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.xz
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.zst
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.zip
Diffstat (limited to 'src/GalOgl.cpp')
-rw-r--r--src/GalOgl.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp
index 961c6ef..ff43ed8 100644
--- a/src/GalOgl.cpp
+++ b/src/GalOgl.cpp
@@ -321,7 +321,7 @@ size_t GalFormatGetSize(Format format) {
return 0;
}
-GLenum GalFormatGetGlInternalFormat(Format format) {
+GLenum GalFormatGetGlLinearInternalFormat(Format format) {
switch (format) {
case Format::D24S8:
return GL_DEPTH24_STENCIL8;
@@ -335,6 +335,20 @@ GLenum GalFormatGetGlInternalFormat(Format format) {
return 0;
}
+GLenum GalFormatGetGlInternalFormat(Format format) {
+ switch (format) {
+ case Format::D24S8:
+ return GL_DEPTH24_STENCIL8;
+ case Format::R8G8B8:
+ return GL_SRGB;
+ case Format::R8G8B8A8:
+ return GL_SRGB_ALPHA;
+ default:
+ return 0;
+ }
+ return 0;
+}
+
GLenum GalFormatGetGlFormat(Format format) {
switch (format) {
case Format::D24S8:
@@ -580,6 +594,7 @@ struct TextureConfigOgl : public TextureConfig {
Format format;
size_t width = 1, height = 1, depth = 1;
bool interpolateLayers = false;
+ bool linear = true;
GLenum type;
Filtering min = Filtering::Nearest, max = Filtering::Nearest;
@@ -597,6 +612,10 @@ struct TextureConfigOgl : public TextureConfig {
wrap = wrapping;
}
+ virtual void SetLinear(bool isLinear) override {
+ linear = isLinear;
+ }
+
};
struct TextureOgl : public Texture {
@@ -605,12 +624,15 @@ struct TextureOgl : public Texture {
GlResource texture;
Format format;
size_t width, height, depth;
+ bool linear;
virtual void SetData(std::vector<std::byte>&& data, size_t mipLevel = 0) override {
size_t expectedSize = width * height * depth * GalFormatGetSize(format);
if (data.size() != expectedSize && !data.empty())
throw std::logic_error("Size of data is not valid for this texture");
+ GLenum internalFormat = linear ? GalFormatGetGlLinearInternalFormat(format) : GalFormatGetGlInternalFormat(format);
+
oglState.BindTexture(type, texture);
switch (type) {
@@ -630,13 +652,13 @@ struct TextureOgl : public Texture {
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
case GL_PROXY_TEXTURE_CUBE_MAP:
- glTexImage2D(type, mipLevel, GalFormatGetGlInternalFormat(format), width, height, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
+ glTexImage2D(type, mipLevel, internalFormat, width, height, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
break;
case GL_TEXTURE_3D:
case GL_PROXY_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
case GL_PROXY_TEXTURE_2D_ARRAY:
- glTexImage3D(type, mipLevel, GalFormatGetGlInternalFormat(format), width, height, depth, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
+ glTexImage3D(type, mipLevel, internalFormat, width, height, depth, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
break;
default:
throw std::runtime_error("Unknown texture type");
@@ -1136,6 +1158,7 @@ struct ImplOgl : public Impl {
texture->width = texConfig->width;
texture->height = texConfig->height;
texture->depth = texConfig->depth;
+ texture->linear = texConfig->linear;
GLuint newTex;
glGenTextures(1, &newTex);