some optimizations

This commit is contained in:
Eduardo Bart 2012-04-09 09:35:46 -03:00
parent db00792351
commit 2017fb366e
6 changed files with 17 additions and 18 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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); }

View File

@ -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);
}

View File

@ -62,7 +62,7 @@ public:
private:
DrawMode m_drawMode;
float m_startTime;
TexturePtr m_textures[2];
std::array<uint, 2> m_textures;
Color m_color;
float m_opacity;

View File

@ -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++;