From 27b83fa7224dbf5f0f0ed46ededfb22af92c60e5 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 20 Feb 2012 11:10:54 -0200 Subject: [PATCH] some optimizations and compilation changes * speedup render of widget images on low end devices using mipmaps * changes in CMakeLists.txt to allow usage of distcc and crosscompiling --- src/framework/CMakeLists.txt | 6 +++--- src/framework/graphics/texture.cpp | 12 ++++++------ src/framework/graphics/texture.h | 5 +++-- src/framework/ui/uiwidgetimage.cpp | 5 +++++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 204c7bec..67daa416 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -37,15 +37,15 @@ FIND_PACKAGE(ZLIB REQUIRED) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable") - SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}") - SET(CMAKE_C_FLAGS "-pipe ${CXX_WARNS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNS} -std=gnu++0x -pipe") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CXX_WARNS} -pipe") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") SET(CMAKE_C_FLAGS_RELEASE "-O2") - SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed") + SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++ -Wl,--as-needed") ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 2d9394dd..0582dd91 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -98,8 +98,8 @@ void Texture::generateMipmaps() { bind(); - if(!m_useMipmaps) { - m_useMipmaps = true; + if(!m_hasMipmaps) { + m_hasMipmaps = true; setupFilters(); } @@ -141,8 +141,8 @@ void Texture::generateBilinearMipmaps(std::vector inPixels) { bind(); - if(!m_useMipmaps) { - m_useMipmaps = true; + if(!m_hasMipmaps) { + m_hasMipmaps = true; setupFilters(); } @@ -204,10 +204,10 @@ void Texture::setupFilters() GLint minFilter; GLint magFilter; if(m_smooth) { - minFilter = m_useMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; + minFilter = m_hasMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; magFilter = GL_LINEAR; } else { - minFilter = m_useMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST; + minFilter = m_hasMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST; magFilter = GL_NEAREST; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); diff --git a/src/framework/graphics/texture.h b/src/framework/graphics/texture.h index 5850db73..0219295f 100644 --- a/src/framework/graphics/texture.h +++ b/src/framework/graphics/texture.h @@ -48,7 +48,8 @@ public: int getHeight() { return m_size.height(); } const Size& getSize() { return m_size; } - bool isEmpty() const { return m_textureId == 0; } + bool isEmpty() { return m_textureId == 0; } + bool hasMipmaps() { return m_hasMipmaps; } protected: void setupFilters(); @@ -56,7 +57,7 @@ protected: GLuint m_textureId; Size m_size; - Boolean m_useMipmaps; + Boolean m_hasMipmaps; Boolean m_smooth; }; diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index 5f2b0981..8652a44c 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -160,6 +160,11 @@ void UIWidget::drawImage(const Rect& screenCoords) } m_imageTexture->setSmooth(m_imageSmooth); + + // this will increase fps when rendering larger images, like the background, and improve image quality + if(m_imageSmooth && !m_imageTexture->hasMipmaps()) + m_imageTexture->generateMipmaps(); + g_painter.setColor(m_imageColor); g_painter.drawTextureCoords(m_imageCoordsBuffer, m_imageTexture); }