From 2017fb366e656219df5abc9dad301ff54c85f090 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 9 Apr 2012 09:35:46 -0300 Subject: [PATCH] some optimizations --- src/framework/graphics/graphics.cpp | 2 -- src/framework/graphics/painter.cpp | 5 +++- src/framework/graphics/painter.h | 2 +- .../graphics/paintershaderprogram.cpp | 23 +++++++++---------- src/framework/graphics/paintershaderprogram.h | 2 +- src/framework/ui/uiframecounter.cpp | 1 - 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 932c7e48..7576b401 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -76,8 +76,6 @@ void Graphics::init() #endif - glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); - glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glEnable(GL_BLEND); glClear(GL_COLOR_BUFFER_BIT); diff --git a/src/framework/graphics/painter.cpp b/src/framework/graphics/painter.cpp index 54a2a007..1ca8c4ad 100644 --- a/src/framework/graphics/painter.cpp +++ b/src/framework/graphics/painter.cpp @@ -113,7 +113,7 @@ void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth) drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer); } -void Painter::setCustomProgram(PainterShaderProgramPtr program) +void Painter::setCustomProgram(const PainterShaderProgramPtr& program) { m_customProgram = program; } @@ -142,6 +142,9 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode) void Painter::setClipRect(const Rect& clipRect) { + if(m_clipRect == clipRect) + return; + if(clipRect.isValid()) { glEnable(GL_SCISSOR_TEST); glScissor(clipRect.left(), g_graphics.getViewportSize().height() - clipRect.bottom() - 1, clipRect.width(), clipRect.height()); diff --git a/src/framework/graphics/painter.h b/src/framework/graphics/painter.h index b19436c2..efdd0575 100644 --- a/src/framework/graphics/painter.h +++ b/src/framework/graphics/painter.h @@ -61,7 +61,7 @@ public: Rect getClipRect() { return m_clipRect; } void resetClipRect() { setClipRect(Rect()); } - void setCustomProgram(PainterShaderProgramPtr program); + void setCustomProgram(const PainterShaderProgramPtr& program); void releaseCustomProgram() { m_customProgram = nullptr; } void setCompositionMode(CompositionMode compositionMode); void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); } diff --git a/src/framework/graphics/paintershaderprogram.cpp b/src/framework/graphics/paintershaderprogram.cpp index f870a380..f5e7b857 100644 --- a/src/framework/graphics/paintershaderprogram.cpp +++ b/src/framework/graphics/paintershaderprogram.cpp @@ -33,6 +33,7 @@ PainterShaderProgram::PainterShaderProgram() m_color = Color::white; m_time = 0; m_lastTexture = -1; + m_textures.fill(0); } bool PainterShaderProgram::link() @@ -57,6 +58,9 @@ bool PainterShaderProgram::link() setUniformValue(TIME_UNIFORM, m_time); setUniformValue(TEX0_UNIFORM, 0); setUniformValue(TEX1_UNIFORM, 1); + + enableAttributeArray(PainterShaderProgram::VERTEX_ATTR); + enableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR); return true; } return false; @@ -96,10 +100,12 @@ void PainterShaderProgram::setTexture(const TexturePtr& texture, int index) { assert(index >= 0 && index <= 1); - if(m_textures[index] == texture) + uint texId = texture ? texture->getId() : 0; + + if(m_textures[index] == texId) return; - m_textures[index] = texture; + m_textures[index] = texId; m_lastTexture = std::max(m_lastTexture, index); if(texture && index == 0) { @@ -129,14 +135,12 @@ void PainterShaderProgram::draw(CoordsBuffer& coordsBuffer, DrawMode drawMode) coordsBuffer.updateCaches(); bool hardwareCached = coordsBuffer.isHardwareCached(); - enableAttributeArray(PainterShaderProgram::VERTEX_ATTR); if(hardwareCached) coordsBuffer.getHardwareVertexBuffer()->bind(); setAttributeArray(PainterShaderProgram::VERTEX_ATTR, hardwareCached ? 0 : coordsBuffer.getVertexBuffer(), 2); bool hasTexture = coordsBuffer.getTextureVertexCount() != 0; if(hasTexture) { - enableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR); if(hardwareCached) coordsBuffer.getHardwareTextureVertexBuffer()->bind(); setAttributeArray(PainterShaderProgram::TEXCOORD_ATTR, hardwareCached ? 0 : coordsBuffer.getTextureVertexBuffer(), 2); @@ -146,19 +150,14 @@ void PainterShaderProgram::draw(CoordsBuffer& coordsBuffer, DrawMode drawMode) HardwareBuffer::unbind(HardwareBuffer::VertexBuffer); if(m_lastTexture == 0) { - glBindTexture(GL_TEXTURE_2D, m_textures[0] ? m_textures[0]->getId() : 0); + glBindTexture(GL_TEXTURE_2D, m_textures[0]); } else { glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_textures[1] ? m_textures[1]->getId() : 0); + glBindTexture(GL_TEXTURE_2D, m_textures[1]); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_textures[0] ? m_textures[0]->getId() : 0); + glBindTexture(GL_TEXTURE_2D, m_textures[0]); } glDrawArrays(drawMode, 0, vertexCount); - - disableAttributeArray(PainterShaderProgram::VERTEX_ATTR); - - if(hasTexture) - disableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR); } diff --git a/src/framework/graphics/paintershaderprogram.h b/src/framework/graphics/paintershaderprogram.h index d6d69db5..fff052aa 100644 --- a/src/framework/graphics/paintershaderprogram.h +++ b/src/framework/graphics/paintershaderprogram.h @@ -62,7 +62,7 @@ public: private: DrawMode m_drawMode; float m_startTime; - TexturePtr m_textures[2]; + std::array m_textures; Color m_color; float m_opacity; diff --git a/src/framework/ui/uiframecounter.cpp b/src/framework/ui/uiframecounter.cpp index 4d5f5c0b..390008a3 100644 --- a/src/framework/ui/uiframecounter.cpp +++ b/src/framework/ui/uiframecounter.cpp @@ -44,7 +44,6 @@ void UIFrameCounter::drawSelf() m_fpsText = Fw::formatString("FPS: %d", m_frameCount); m_lastFrameTicks = g_clock.ticks(); m_frameCount = 0; - dump << m_fpsText; } m_frameCount++;