summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Gal.hpp3
-rw-r--r--src/GalOgl.cpp29
-rw-r--r--src/Render.cpp6
-rw-r--r--src/RenderConfigs.hpp8
-rw-r--r--src/RendererWorld.cpp4
-rw-r--r--src/TextureAtlas.cpp1
6 files changed, 39 insertions, 12 deletions
diff --git a/src/Gal.hpp b/src/Gal.hpp
index 234e49a..8d7394a 100644
--- a/src/Gal.hpp
+++ b/src/Gal.hpp
@@ -158,6 +158,8 @@ namespace Gal {
virtual void SetWrapping(Wrapping wrapping) = 0;
+ virtual void SetLinear(bool isLinear) = 0;
+
};
struct Texture {
@@ -261,6 +263,7 @@ namespace Gal {
template<typename T>
void Resize() {
Resize(sizeof(T));
+ *Get<T>() = T{};
}
virtual std::byte* GetDataPtr() = 0;
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);
diff --git a/src/Render.cpp b/src/Render.cpp
index 682b60a..4fc0616 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -144,6 +144,7 @@ void Render::PrepareToRendering() {
auto gal = Gal::GetImplementation();
gal->GetDefaultFramebuffer()->SetViewport(0, 0, width, height);
+ gal->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->gamma = Settings::ReadDouble("gamma", 2.2);
std::string vertexSource, pixelSource;
{
@@ -503,7 +504,6 @@ void Render::InitEvents() {
renderWorld = true;
SetState(State::Playing);
GetGameState()->GetPlayer()->isFlying = Settings::ReadBool("flight", false);
- PUSH_EVENT("SetMinLightLevel", (float)Settings::ReadDouble("brightness", 0.2f));
});
listener.RegisterHandler("ConnectionFailed", [this](const Event& eventData) {
@@ -597,8 +597,8 @@ void Render::InitEvents() {
else
SDL_GL_SetSwapInterval(0);
- float brightness = Settings::ReadDouble("brightness", 0.2f);
- PUSH_EVENT("SetMinLightLevel", brightness);
+
+ Gal::GetImplementation()->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->gamma = Settings::ReadDouble("gamma", 2.2);
PrepareToRendering();
});
diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp
index da7fd96..1e6a978 100644
--- a/src/RenderConfigs.hpp
+++ b/src/RenderConfigs.hpp
@@ -5,8 +5,12 @@
struct GlobalShaderParameters {
glm::mat4 projView;
glm::uvec2 viewportSize;
- float globalTime;
- float dayTime;
+ glm::float32 globalTime;
+ glm::float32 dayTime;
+ glm::float32 gamma;
+ glm::uint32 paddingF0 = 0xF0F0F0F0;
+ glm::uint32 paddingF1 = 0xF1F1F1F1;
+ glm::uint32 paddingF2 = 0xF2F2F2F2;
};
std::shared_ptr<Gal::Shader> LoadVertexShader(std::string_view assetPath);
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index c6d490a..846788b 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -256,10 +256,6 @@ RendererWorld::RendererWorld(std::shared_ptr<Gal::Framebuffer> target) {
sections.erase(it);
});
- listener->RegisterHandler("SetMinLightLevel", [this](const Event& eventData) {
-
- });
-
for (int i = 0; i < numOfWorkers; i++)
workers.push_back(std::thread(&RendererWorld::WorkerFunction, this, i));
diff --git a/src/TextureAtlas.cpp b/src/TextureAtlas.cpp
index 7e44a86..9ad018e 100644
--- a/src/TextureAtlas.cpp
+++ b/src/TextureAtlas.cpp
@@ -89,6 +89,7 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) {
texConfig->SetWrapping(Gal::Wrapping::Clamp);
texConfig->SetMinFilter(Gal::Filtering::Nearest);
texConfig->SetMaxFilter(Gal::Filtering::Nearest);
+ texConfig->SetLinear(false);
texture = gal->BuildTexture(texConfig);