From 90756f8b344022bd2ff4e2f30820698d60dfa2af Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 20 Jul 2015 13:56:45 +0200 Subject: [PATCH] Added FilterMode, MipmapLevel and Anisotropy to settings screen --- src/CMakeLists.txt | 3 +- src/common/event.h | 4 ++ src/common/restext.cpp | 3 + src/graphics/core/device.h | 7 +- src/graphics/core/nulldevice.cpp | 12 +++- src/graphics/core/nulldevice.h | 58 +++++++-------- src/graphics/engine/engine.cpp | 38 +++++----- src/graphics/opengl/gl21device.cpp | 24 +++++-- src/graphics/opengl/gl21device.h | 5 +- src/graphics/opengl/gl33device.cpp | 20 ++++-- src/graphics/opengl/gl33device.h | 5 +- src/graphics/opengl/gldevice.cpp | 27 ++++--- src/graphics/opengl/gldevice.h | 4 +- src/ui/enumslider.cpp | 74 +++++++++++++++++++ src/ui/enumslider.h | 48 +++++++++++++ src/ui/interface.cpp | 6 +- src/ui/interface.h | 3 +- src/ui/maindialog.cpp | 112 +++++++++++++++++++++++++++-- src/ui/slider.cpp | 12 ++-- src/ui/slider.h | 4 +- src/ui/window.cpp | 21 +++++- src/ui/window.h | 3 +- 22 files changed, 408 insertions(+), 85 deletions(-) create mode 100644 src/ui/enumslider.cpp create mode 100644 src/ui/enumslider.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c929325..d74bcc5a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -213,6 +213,7 @@ set(BASE_SOURCES ui/displaytext.cpp ui/edit.cpp ui/editvalue.cpp + ui/enumslider.cpp ui/gauge.cpp ui/group.cpp ui/image.cpp @@ -309,4 +310,4 @@ endif() if(COLOBOT_LINT_BUILD) add_fake_header_sources("src") -endif() \ No newline at end of file +endif() diff --git a/src/common/event.h b/src/common/event.h index 3954c992..b5533ba0 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -243,6 +243,10 @@ enum EventType EVENT_INTERFACE_AUTOSAVE_ENABLE = 780, EVENT_INTERFACE_AUTOSAVE_INTERVAL = 781, EVENT_INTERFACE_AUTOSAVE_SLOTS = 782, + // new + EVENT_INTERFACE_TEXTURE_FILTER = 783, + EVENT_INTERFACE_TEXTURE_MIPMAP = 784, + EVENT_INTERFACE_TEXTURE_ANISOTROPY = 785, EVENT_INTERFACE_KINFO1 = 500, EVENT_INTERFACE_KINFO2 = 501, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index f8813fe6..7a3ed74d 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -213,6 +213,9 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_AUTOSAVE_ENABLE] = TR("Autosave\\Enables autosave"); stringsEvent[EVENT_INTERFACE_AUTOSAVE_INTERVAL] = TR("Autosave interval\\How often your game will autosave"); stringsEvent[EVENT_INTERFACE_AUTOSAVE_SLOTS] = TR("Autosave slots\\How many autosave slots you'll have"); + stringsEvent[EVENT_INTERFACE_TEXTURE_FILTER] = TR("Texture filtering\\Texture filtering"); + stringsEvent[EVENT_INTERFACE_TEXTURE_MIPMAP] = TR("Mipmap level\\Mipmap level"); + stringsEvent[EVENT_INTERFACE_TEXTURE_ANISOTROPY]= TR("Anisotropy level\\Anisotropy level"); stringsEvent[EVENT_INTERFACE_KDEF] = TR("Standard controls\\Standard key functions"); assert(INPUT_SLOT_MAX < EVENT_INTERFACE_KEY_END-EVENT_INTERFACE_KEY); diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 3d358a08..cad9efca 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -435,8 +435,13 @@ public: //! Deletes framebuffer virtual void DeleteFramebuffer(std::string name) = 0; + + //! Checks if anisotropy is supported + virtual bool IsAnisotropySupported() = 0; + + //! Returns max anisotropy level supported + virtual int GetMaxAnisotropyLevel() = 0; }; } // namespace Gfx - diff --git a/src/graphics/core/nulldevice.cpp b/src/graphics/core/nulldevice.cpp index a7d90906..0db938cd 100644 --- a/src/graphics/core/nulldevice.cpp +++ b/src/graphics/core/nulldevice.cpp @@ -382,6 +382,14 @@ void CNullDevice::DeleteFramebuffer(std::string name) { } +bool CNullDevice::IsAnisotropySupported() +{ + return false; +} + +int CNullDevice::GetMaxAnisotropyLevel() +{ + return 1; +} + } // namespace Gfx - - diff --git a/src/graphics/core/nulldevice.h b/src/graphics/core/nulldevice.h index cc48542a..af4210ac 100644 --- a/src/graphics/core/nulldevice.h +++ b/src/graphics/core/nulldevice.h @@ -40,58 +40,58 @@ class CNullDevice : public CDevice public: CNullDevice(); virtual ~CNullDevice(); - + virtual void DebugHook(); virtual void DebugLights(); - + virtual bool Create(); virtual void Destroy(); virtual void ConfigChanged(const DeviceConfig &newConfig); - + virtual void BeginScene(); virtual void EndScene(); - + virtual void Clear(); - + virtual void SetTransform(TransformType type, const Math::Matrix &matrix); virtual const Math::Matrix& GetTransform(TransformType type); virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix); - + virtual void SetMaterial(const Material &material); virtual const Material& GetMaterial(); - + virtual int GetMaxLightCount(); virtual void SetLight(int index, const Light &light); virtual const Light& GetLight(int index); virtual void SetLightEnabled(int index, bool enabled); virtual bool GetLightEnabled(int index); - + virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms); virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms); virtual Texture CreateDepthTexture(int width, int height, int depth); virtual void DestroyTexture(const Texture &texture); virtual void DestroyAllTextures(); - + virtual int GetMaxTextureStageCount(); virtual void SetTexture(int index, const Texture &texture); virtual void SetTexture(int index, unsigned int textureId); virtual Texture GetTexture(int index); virtual void SetTextureEnabled(int index, bool enabled); virtual bool GetTextureEnabled(int index); - + virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms); virtual TextureStageParams GetTextureStageParams(int index); - + virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT); virtual void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms); - + virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount); - + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); @@ -100,50 +100,50 @@ public: virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); virtual void DrawStaticBuffer(unsigned int bufferId); virtual void DestroyStaticBuffer(unsigned int bufferId); - + virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); virtual void SetViewport(int x, int y, int width, int height); - + virtual void SetRenderState(RenderState state, bool enabled); virtual bool GetRenderState(RenderState state); virtual void SetColorMask(bool red, bool green, bool blue, bool alpha); - + virtual void SetDepthTestFunc(CompFunc func); virtual CompFunc GetDepthTestFunc(); - + virtual void SetDepthBias(float factor, float units); virtual float GetDepthBias(); - + virtual void SetAlphaTestFunc(CompFunc func, float refValue); virtual void GetAlphaTestFunc(CompFunc &func, float &refValue); - + virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend); virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend); - + virtual void SetClearColor(const Color &color); virtual Color GetClearColor(); - + virtual void SetGlobalAmbient(const Color &color); virtual Color GetGlobalAmbient(); - + virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density); virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density); - + virtual void SetCullMode(CullMode mode); virtual CullMode GetCullMode(); - + virtual void SetShadeModel(ShadeModel model); virtual ShadeModel GetShadeModel(); virtual void SetShadowColor(float value); - + virtual void SetFillMode(FillMode mode) ; virtual FillMode GetFillMode(); virtual void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height); - + virtual void* GetFrameBufferPixels() const; virtual CFramebuffer* GetFramebuffer(std::string name); @@ -151,7 +151,10 @@ public: virtual CFramebuffer* CreateFramebuffer(std::string name, const FramebufferParams& params); virtual void DeleteFramebuffer(std::string name); - + + virtual bool IsAnisotropySupported(); + virtual int GetMaxAnisotropyLevel(); + private: Math::Matrix m_matrix; Material m_material; @@ -160,4 +163,3 @@ private: } // namespace Gfx - diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 6748ef3b..a7d56993 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -169,17 +169,7 @@ CEngine::CEngine(CApplication *app) m_lastFrameTime = GetSystemUtils()->CreateTimeStamp(); m_currentFrameTime = GetSystemUtils()->CreateTimeStamp(); - TexFilter filter = TEX_FILTER_BILINEAR; - bool mipmaps = false; - int value; - if (GetConfigFile().GetIntProperty("Setup", "FilterMode", value)) - { - if (value == 1) filter = TEX_FILTER_NEAREST; - else if (value == 2) filter = TEX_FILTER_BILINEAR; - else if (value == 3) filter = TEX_FILTER_TRILINEAR, mipmaps = true; - } - if (GetConfigFile().GetIntProperty("Setup", "ShadowMapping", value)) { m_shadowMapping = (value > 0); @@ -190,12 +180,10 @@ CEngine::CEngine(CApplication *app) m_shadowColor = 0.5f; m_defaultTexParams.format = TEX_IMG_AUTO; - m_defaultTexParams.mipmap = mipmaps; - m_defaultTexParams.filter = filter; + m_defaultTexParams.filter = TEX_FILTER_BILINEAR; m_terrainTexParams.format = TEX_IMG_AUTO; - m_terrainTexParams.mipmap = mipmaps; - m_terrainTexParams.filter = filter; + m_terrainTexParams.filter = TEX_FILTER_BILINEAR; // Compute bias matrix for shadow mapping Math::Matrix temp1, temp2; @@ -2838,8 +2826,14 @@ float CEngine::GetGadgetQuantity() void CEngine::SetTextureFilterMode(TexFilter value) { - m_defaultTexParams.filter = value; - m_terrainTexParams.filter = value; + bool changed = m_defaultTexParams.filter != value || m_terrainTexParams.filter != value; + m_defaultTexParams.filter = m_terrainTexParams.filter = value; + m_defaultTexParams.mipmap = m_terrainTexParams.mipmap = (value == TEX_FILTER_TRILINEAR); + if(changed) + { + FlushTextureCache(); + LoadAllTextures(); + } } TexFilter CEngine::GetTextureFilterMode() @@ -2852,7 +2846,13 @@ void CEngine::SetTextureMipmapLevel(int value) if (value < 1) value = 1; if (value > 16) value = 16; + bool changed = m_textureMipmapLevel != value; m_textureMipmapLevel = value; + if(changed) + { + FlushTextureCache(); + LoadAllTextures(); + } } int CEngine::GetTextureMipmapLevel() @@ -2865,7 +2865,13 @@ void CEngine::SetTextureAnisotropyLevel(int value) if (value < 1) value = 1; if (value > 16) value = 16; + bool changed = m_textureAnisotropy != value; m_textureAnisotropy = value; + if(changed) + { + FlushTextureCache(); + LoadAllTextures(); + } } int CEngine::GetTextureAnisotropyLevel() diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index 22abc23f..344c4ad6 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -203,7 +203,7 @@ bool CGL21Device::Create() float level; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &level); m_maxAnisotropy = static_cast(level); - + GetLogger()->Info("Anisotropic filtering available\n"); GetLogger()->Info("Maximum anisotropy: %d\n", m_maxAnisotropy); } @@ -345,7 +345,7 @@ bool CGL21Device::Create() // create default framebuffer object FramebufferParams framebufferParams; - + framebufferParams.width = m_config.size.x; framebufferParams.height = m_config.size.y; framebufferParams.depth = m_config.depthSize; @@ -355,7 +355,7 @@ bool CGL21Device::Create() m_framebufferSupport = DetectFramebufferSupport(); if (m_framebufferSupport != FBS_NONE) GetLogger()->Debug("Framebuffer supported\n"); - + GetLogger()->Info("CDevice created successfully\n"); return true; @@ -571,7 +571,7 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p if (!Math::IsPowerOfTwo(result.size.x) || !Math::IsPowerOfTwo(result.size.y)) GetLogger()->Warn("Creating non-power-of-2 texture (%dx%d)!\n", result.size.x, result.size.y); - + result.originalSize = result.size; glActiveTexture(GL_TEXTURE0); @@ -748,7 +748,7 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p Texture CGL21Device::CreateDepthTexture(int width, int height, int depth) { Texture result; - + result.alpha = false; result.size.x = width; result.size.y = height; @@ -1141,7 +1141,7 @@ void CGL21Device::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode return; glActiveTexture(GL_TEXTURE0 + index); - + if (wrapS == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); else if (wrapS == TEX_WRAP_CLAMP_TO_BORDER) @@ -1207,7 +1207,7 @@ void CGL21Device::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, glClientActiveTexture(GL_TEXTURE1); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord2)); - + glColor4fv(color.Array()); glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount); @@ -1761,4 +1761,14 @@ void CGL21Device::DeleteFramebuffer(std::string name) } } +bool CGL21Device::IsAnisotropySupported() +{ + return m_anisotropyAvailable; +} + +int CGL21Device::GetMaxAnisotropyLevel() +{ + return m_maxAnisotropy; +} + } // namespace Gfx diff --git a/src/graphics/opengl/gl21device.h b/src/graphics/opengl/gl21device.h index dd23a726..5b517a4b 100644 --- a/src/graphics/opengl/gl21device.h +++ b/src/graphics/opengl/gl21device.h @@ -147,6 +147,9 @@ public: virtual void DeleteFramebuffer(std::string name) override; + virtual bool IsAnisotropySupported() override; + virtual int GetMaxAnisotropyLevel() override; + private: //! Updates position for given light based on transformation matrices void UpdateLightPosition(int index); @@ -254,7 +257,7 @@ private: //! true enables texture GLint uni_TextureEnabled[3]; - + // Alpha test parameters //! true enables alpha test GLint uni_AlphaTestEnabled; diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 4f81e9ff..c1271692 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -209,7 +209,7 @@ bool CGL33Device::Create() float level; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &level); m_maxAnisotropy = static_cast(level); - + GetLogger()->Info("Anisotropic filtering available\n"); GetLogger()->Info("Maximum anisotropy: %d\n", m_maxAnisotropy); } @@ -295,7 +295,7 @@ bool CGL33Device::Create() uni_PrimaryTextureEnabled = glGetUniformLocation(m_shaderProgram, "uni_PrimaryTextureEnabled"); uni_SecondaryTextureEnabled = glGetUniformLocation(m_shaderProgram, "uni_SecondaryTextureEnabled"); uni_ShadowTextureEnabled = glGetUniformLocation(m_shaderProgram, "uni_ShadowTextureEnabled"); - + uni_FogEnabled = glGetUniformLocation(m_shaderProgram, "uni_FogEnabled"); uni_FogRange = glGetUniformLocation(m_shaderProgram, "uni_FogRange"); uni_FogColor = glGetUniformLocation(m_shaderProgram, "uni_FogColor"); @@ -600,7 +600,7 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p result.size.x = data->surface->w; result.size.y = data->surface->h; - + result.originalSize = result.size; glActiveTexture(GL_TEXTURE0); @@ -1140,7 +1140,7 @@ void CGL33Device::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode return; glActiveTexture(GL_TEXTURE0 + index); - + if (wrapS == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); else if (wrapS == TEX_WRAP_CLAMP_TO_BORDER) @@ -1306,7 +1306,7 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, i unsigned int CGL33Device::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { unsigned int id = 0; - + id = ++m_lastVboId; VertexBufferInfo info; @@ -1954,4 +1954,14 @@ inline void CGL33Device::BindVAO(GLuint vao) m_currentVAO = vao; } +bool CGL33Device::IsAnisotropySupported() +{ + return m_anisotropyAvailable; +} + +int CGL33Device::GetMaxAnisotropyLevel() +{ + return m_maxAnisotropy; +} + } // namespace Gfx diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index 4505f6ce..5cd62d36 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -146,6 +146,9 @@ public: virtual void DeleteFramebuffer(std::string name) override; + virtual bool IsAnisotropySupported() override; + virtual int GetMaxAnisotropyLevel() override; + private: //! Updates position for given light based on transformation matrices void UpdateLightPosition(int index); @@ -290,7 +293,7 @@ private: GLint uni_DiffuseColor; //! Specular color GLint uni_SpecularColor; - + struct { //! true enables light diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 1e93b0cb..753f7d66 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -222,7 +222,7 @@ bool CGLDevice::Create() float level; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &level); m_maxAnisotropy = static_cast(level); - + GetLogger()->Info("Anisotropic filtering available\n"); GetLogger()->Info("Maximum anisotropy: %d\n", m_maxAnisotropy); } @@ -230,7 +230,7 @@ bool CGLDevice::Create() { GetLogger()->Info("Anisotropic filtering not available\n"); } - + GetLogger()->Info("Auto-detecting VBO support\n"); // detecting VBO ARB extension @@ -541,7 +541,7 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par if (!Math::IsPowerOfTwo(result.size.x) || !Math::IsPowerOfTwo(result.size.y)) GetLogger()->Warn("Creating non-power-of-2 texture (%dx%d)!\n", result.size.x, result.size.y); - + result.originalSize = result.size; // Use & enable 1st texture stage @@ -728,7 +728,7 @@ Texture CGLDevice::CreateDepthTexture(int width, int height, int depth) result.id = 0; return result; } - + result.alpha = false; result.size.x = width; result.size.y = height; @@ -1151,7 +1151,7 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr if (m_multitextureAvailable) glActiveTexture(GL_TEXTURE0 + index); - + if (wrapS == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); else if (wrapS == TEX_WRAP_CLAMP_TO_BORDER) @@ -1349,7 +1349,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve info.vertexType = VERTEX_TYPE_COL; info.vertexCount = vertexCount; info.bufferId = 0; - + if(m_vertexBufferType == VBT_VBO_CORE) { glGenBuffers(1, &info.bufferId); @@ -1498,7 +1498,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) return; glEnable(GL_VERTEX_ARRAY); - + if(m_vertexBufferType == VBT_VBO_CORE) glBindBuffer(GL_ARRAY_BUFFER, (*it).second.bufferId); else @@ -1578,7 +1578,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glBindBuffer(GL_ARRAY_BUFFER, 0); else glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); - + glDisable(GL_VERTEX_ARRAY); } else @@ -1893,5 +1893,14 @@ void CGLDevice::DeleteFramebuffer(std::string name) } } -} // namespace Gfx +bool CGLDevice::IsAnisotropySupported() +{ + return m_anisotropyAvailable; +} +int CGLDevice::GetMaxAnisotropyLevel() +{ + return m_maxAnisotropy; +} + +} // namespace Gfx diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 6cb9c52a..5ebe927f 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -166,6 +166,9 @@ public: virtual void DeleteFramebuffer(std::string name) override; + virtual bool IsAnisotropySupported() override; + virtual int GetMaxAnisotropyLevel() override; + private: //! Updates internal modelview matrix void UpdateModelviewMatrix(); @@ -254,4 +257,3 @@ private: } // namespace Gfx - diff --git a/src/ui/enumslider.cpp b/src/ui/enumslider.cpp new file mode 100644 index 00000000..656b6645 --- /dev/null +++ b/src/ui/enumslider.cpp @@ -0,0 +1,74 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ +#include "ui/enumslider.h" + +#include "common/stringutils.h" + +namespace Ui { + +CEnumSlider::CEnumSlider() : CSlider() +{ +} + +void CEnumSlider::SetPossibleValues(const std::vector& values) +{ + m_values = values; +} + +void CEnumSlider::SetPossibleValues(const std::map& values) +{ + m_values.clear(); + for(auto it = values.begin(); it != values.end(); ++it) { + m_values.push_back(it->first); + } + m_labels = values; +} + +void CEnumSlider::SetVisibleValue(float value) +{ + for(unsigned int i = 0; i < m_values.size(); i++) + { + if(value == m_values[i]) + { + m_visibleValue = static_cast(i) / (m_values.size()-1); + } + } +} + +int CEnumSlider::GetVisibleValueIndex() +{ + return round(m_visibleValue * (m_values.size()-1)); +} + +float CEnumSlider::GetVisibleValue() +{ + return m_values[GetVisibleValueIndex()]; +} + +std::string CEnumSlider::GetLabel() +{ + float value = GetVisibleValueIndex(); + if(m_labels.find(value) != m_labels.end()) + { + return m_labels.at(value); + } + return StrUtils::ToString(GetVisibleValue()); +} + +} diff --git a/src/ui/enumslider.h b/src/ui/enumslider.h new file mode 100644 index 00000000..612105ef --- /dev/null +++ b/src/ui/enumslider.h @@ -0,0 +1,48 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ +#pragma once + +#include "ui/slider.h" + +#include +#include + +namespace Ui { + +class CEnumSlider : public CSlider +{ +public: + CEnumSlider(); + + void SetPossibleValues(const std::vector& values); + void SetPossibleValues(const std::map& values); + + void SetVisibleValue(float value); + float GetVisibleValue(); + int GetVisibleValueIndex(); + +protected: + std::string GetLabel(); + +protected: + std::vector m_values; + std::map m_labels; +}; + +} diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index bd59852a..1eda5bbd 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -200,6 +200,11 @@ CSlider* CInterface::CreateSlider(Math::Point pos, Math::Point dim, int icon, Ev return CreateControl(pos, dim, icon, eventMsg); } +CEnumSlider* CInterface::CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +{ + return CreateControl(pos, dim, icon, eventMsg); +} + // Creates a new list. // if expand is less then zero, then the list would try to use expand's absolute value, // and try to scale items to some size, so that dim of the list would not change after @@ -348,4 +353,3 @@ void CInterface::SetFocus(CControl* control) } // namespace Ui - diff --git a/src/ui/interface.h b/src/ui/interface.h index 3747d3e0..9334abfc 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -39,6 +39,7 @@ #include "ui/label.h" #include "ui/edit.h" #include "ui/editvalue.h" +#include "ui/enumslider.h" #include "ui/scroll.h" #include "ui/slider.h" #include "ui/list.h" @@ -75,6 +76,7 @@ public: CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CEnumSlider* CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); @@ -104,4 +106,3 @@ protected: } - diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 30f4791f..357720dd 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1067,8 +1067,6 @@ void CMainDialog::ChangePhase(Phase phase) { pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_GROUND); pc->SetState(STATE_SHADOW); - // TODO: video 8 MB? - //if ( m_engine->IsVideo8MB() ) pc->ClearState(STATE_ENABLE); } pos.y -= 0.048f; pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_DIRTY); @@ -1076,8 +1074,6 @@ void CMainDialog::ChangePhase(Phase phase) pos.y -= 0.048f; pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_SKY); pc->SetState(STATE_SHADOW); - // TODO: video 8 MB? - //if ( m_engine->IsVideo8MB() ) pc->ClearState(STATE_ENABLE); pos.y -= 0.048f; pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_LENS); pc->SetState(STATE_SHADOW); @@ -1157,6 +1153,59 @@ void CMainDialog::ChangePhase(Phase phase) pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); } + CEnumSlider* pes; + + pos.x = ox+sx*8.5f; + pos.y = 0.385f; + ddim.x = dim.x*2.2f; + ddim.y = 18.0f/480.0f; + pes = pw->CreateEnumSlider(pos, ddim, 0, EVENT_INTERFACE_TEXTURE_FILTER); + pes->SetState(STATE_SHADOW); + pes->SetPossibleValues({ + { Gfx::TEX_FILTER_NEAREST, "Nearest" }, + { Gfx::TEX_FILTER_BILINEAR, "Bilinear" }, + { Gfx::TEX_FILTER_TRILINEAR, "Trilinear" } + }); + pos.y += ddim.y/2; + pos.x += 0.005f; + ddim.x = 0.40f; + GetResource(RES_EVENT, EVENT_INTERFACE_TEXTURE_FILTER, name); + pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL12, name); + pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); + + pos.x = ox+sx*8.5f; + pos.y = 0.315f; + ddim.x = dim.x*2.2f; + ddim.y = 18.0f/480.0f; + pes = pw->CreateEnumSlider(pos, ddim, 0, EVENT_INTERFACE_TEXTURE_MIPMAP); + pes->SetState(STATE_SHADOW); + pes->SetPossibleValues({1, 4, 8, 16}); + pos.y += ddim.y/2; + pos.x += 0.005f; + ddim.x = 0.40f; + GetResource(RES_EVENT, EVENT_INTERFACE_TEXTURE_MIPMAP, name); + pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL12, name); + pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); + + pos.x = ox+sx*8.5f; + pos.y = 0.245f; + ddim.x = dim.x*2.2f; + ddim.y = 18.0f/480.0f; + pes = pw->CreateEnumSlider(pos, ddim, 0, EVENT_INTERFACE_TEXTURE_ANISOTROPY); + pes->SetState(STATE_SHADOW); + std::vector anisotropyOptions; + for(int i = 1; i <= m_engine->GetDevice()->GetMaxAnisotropyLevel(); i *= 2) + anisotropyOptions.push_back(i); + pes->SetPossibleValues(anisotropyOptions); + if(!m_engine->GetDevice()->IsAnisotropySupported()) + pes->ClearState(STATE_ENABLE); + pos.y += ddim.y/2; + pos.x += 0.005f; + ddim.x = 0.40f; + GetResource(RES_EVENT, EVENT_INTERFACE_TEXTURE_ANISOTROPY, name); + pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL12, name); + pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); + ddim.x = dim.x*2; ddim.y = dim.y*1; pos.x = ox+sx*10; @@ -2413,6 +2462,13 @@ bool CMainDialog::EventProcess(const Event &event) ChangeSetupButtons(); break; + case EVENT_INTERFACE_TEXTURE_FILTER: + case EVENT_INTERFACE_TEXTURE_MIPMAP: + case EVENT_INTERFACE_TEXTURE_ANISOTROPY: + ChangeSetupButtons(); + UpdateSetupButtons(); + break; + case EVENT_INTERFACE_MIN: ChangeSetupQuality(-1); UpdateSetupButtons(); @@ -4470,6 +4526,7 @@ void CMainDialog::UpdateSetupButtons() CCheck* pc; CEditValue* pv; CSlider* ps; + CEnumSlider* pes; float value; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); @@ -4592,6 +4649,25 @@ void CMainDialog::UpdateSetupButtons() ps->SetVisibleValue(m_main->GetAutosaveSlots()); } + pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_FILTER)); + if ( pes != 0 ) + { + pes->SetVisibleValue(m_engine->GetTextureFilterMode()); + } + + pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_MIPMAP)); + if ( pes != 0 ) + { + pes->SetState(STATE_ENABLE, m_engine->GetTextureFilterMode() == Gfx::TEX_FILTER_TRILINEAR); + pes->SetVisibleValue(m_engine->GetTextureMipmapLevel()); + } + + pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_ANISOTROPY)); + if ( pes != 0 ) + { + pes->SetVisibleValue(m_engine->GetTextureAnisotropyLevel()); + } + pc = static_cast(pw->SearchControl(EVENT_INTERFACE_SHADOW)); if ( pc != 0 ) { @@ -4697,6 +4773,7 @@ void CMainDialog::ChangeSetupButtons() CWindow* pw; CEditValue* pv; CSlider* ps; + CEnumSlider* pes; float value; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); @@ -4757,6 +4834,27 @@ void CMainDialog::ChangeSetupButtons() value = ps->GetVisibleValue(); m_main->SetAutosaveSlots(static_cast(value)); } + + pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_FILTER)); + if ( pes != 0 ) + { + value = pes->GetVisibleValue(); + m_engine->SetTextureFilterMode(static_cast(value)); + } + + pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_MIPMAP)); + if ( pes != 0 ) + { + value = pes->GetVisibleValue(); + m_engine->SetTextureMipmapLevel(static_cast(value)); + } + + pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_ANISOTROPY)); + if ( pes != 0 ) + { + value = pes->GetVisibleValue(); + m_engine->SetTextureAnisotropyLevel(static_cast(value)); + } } @@ -4804,6 +4902,7 @@ void CMainDialog::SetupMemorize() GetConfigFile().SetFloatProperty("Setup", "ShadowColor", m_engine->GetShadowColor()); GetConfigFile().SetFloatProperty("Setup", "ShadowRange", m_engine->GetShadowRange()); GetConfigFile().SetIntProperty("Setup", "MSAA", m_engine->GetMultiSample()); + GetConfigFile().SetIntProperty("Setup", "FilterMode", m_engine->GetTextureFilterMode()); /* screen setup */ GetConfigFile().SetIntProperty("Setup", "Fullscreen", m_setupFull ? 1 : 0); @@ -5089,6 +5188,11 @@ void CMainDialog::SetupRecall() { m_engine->SetMultiSample(iValue); } + + if (GetConfigFile().GetIntProperty("Setup", "FilterMode", iValue)) + { + m_engine->SetTextureFilterMode(static_cast(iValue)); + } } diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 70ba7ef3..b2f2ff48 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -22,6 +22,7 @@ #include "common/event.h" #include "common/misc.h" +#include "common/stringutils.h" #include "graphics/engine/engine.h" #include "graphics/engine/text.h" @@ -389,7 +390,6 @@ void CSlider::Draw() Math::Point pos, dim, ppos, ddim, spos; int icon; float h; - char text[100]; if ( (m_state & STATE_VISIBLE) == 0 ) return; @@ -471,7 +471,7 @@ void CSlider::Draw() { if ( m_state & STATE_ENABLE ) { - sprintf(text, "%d", static_cast(m_min+m_visibleValue*(m_max-m_min))); + std::string text = GetLabel(); h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); pos.x = m_pos.x+m_dim.x+(10.0f/640.0f); pos.y = m_pos.y+(m_dim.y-h)/2.0f; @@ -488,12 +488,17 @@ void CSlider::Draw() pos.y += (h-CURSOR_WIDTH)*m_visibleValue; dim.x = 50.0f/640.0f; dim.y = 16.0f/480.0f; - sprintf(text, "%d", static_cast(m_min+(m_visibleValue*(m_max-m_min)))); + std::string text = GetLabel(); m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); } } } +std::string CSlider::GetLabel() +{ + return StrUtils::ToString(static_cast(m_min+(m_visibleValue*(m_max-m_min)))); +} + // Draws a rectangle. void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) @@ -586,4 +591,3 @@ float CSlider::GetArrowStep() } - diff --git a/src/ui/slider.h b/src/ui/slider.h index c55d64b8..c1f42db8 100644 --- a/src/ui/slider.h +++ b/src/ui/slider.h @@ -25,6 +25,8 @@ #include "ui/control.h" #include "common/event.h" +#include + namespace Ui { class CButton; @@ -59,6 +61,7 @@ protected: void MoveAdjust(); void AdjustGlint(); void DrawVertex(Math::Point pos, Math::Point dim, int icon); + virtual std::string GetLabel(); protected: CButton* m_buttonLeft; @@ -82,4 +85,3 @@ protected: } - diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 9468023d..8754b343 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -342,6 +342,26 @@ CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, Event return 0; } +CEnumSlider* CWindow::CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +{ + CEnumSlider* pc; + int i; + + if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); + + for ( i=0 ; i(m_table[i]); + pc->Create(pos, dim, icon, eventMsg); + return pc; + } + } + return 0; +} + // Creates a new list. // if expand is less then zero, then the list would try to use expand's absolute value, // and try to scale items to some size, so that dim of the list would not change after @@ -1555,4 +1575,3 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim) } } - diff --git a/src/ui/window.h b/src/ui/window.h index abc4ce7f..5c99557e 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -36,6 +36,7 @@ #include "ui/label.h" #include "ui/edit.h" #include "ui/editvalue.h" +#include "ui/enumslider.h" #include "ui/scroll.h" #include "ui/slider.h" #include "ui/list.h" @@ -72,6 +73,7 @@ public: CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CEnumSlider* CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f); CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); @@ -153,4 +155,3 @@ protected: } -