some optimizations
This commit is contained in:
parent
db00792351
commit
2017fb366e
|
@ -76,8 +76,6 @@ void Graphics::init()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
|
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
||||||
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer);
|
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::setCustomProgram(PainterShaderProgramPtr program)
|
void Painter::setCustomProgram(const PainterShaderProgramPtr& program)
|
||||||
{
|
{
|
||||||
m_customProgram = program;
|
m_customProgram = program;
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,9 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||||
|
|
||||||
void Painter::setClipRect(const Rect& clipRect)
|
void Painter::setClipRect(const Rect& clipRect)
|
||||||
{
|
{
|
||||||
|
if(m_clipRect == clipRect)
|
||||||
|
return;
|
||||||
|
|
||||||
if(clipRect.isValid()) {
|
if(clipRect.isValid()) {
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
glScissor(clipRect.left(), g_graphics.getViewportSize().height() - clipRect.bottom() - 1, clipRect.width(), clipRect.height());
|
glScissor(clipRect.left(), g_graphics.getViewportSize().height() - clipRect.bottom() - 1, clipRect.width(), clipRect.height());
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
Rect getClipRect() { return m_clipRect; }
|
Rect getClipRect() { return m_clipRect; }
|
||||||
void resetClipRect() { setClipRect(Rect()); }
|
void resetClipRect() { setClipRect(Rect()); }
|
||||||
|
|
||||||
void setCustomProgram(PainterShaderProgramPtr program);
|
void setCustomProgram(const PainterShaderProgramPtr& program);
|
||||||
void releaseCustomProgram() { m_customProgram = nullptr; }
|
void releaseCustomProgram() { m_customProgram = nullptr; }
|
||||||
void setCompositionMode(CompositionMode compositionMode);
|
void setCompositionMode(CompositionMode compositionMode);
|
||||||
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
|
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
|
||||||
|
|
|
@ -33,6 +33,7 @@ PainterShaderProgram::PainterShaderProgram()
|
||||||
m_color = Color::white;
|
m_color = Color::white;
|
||||||
m_time = 0;
|
m_time = 0;
|
||||||
m_lastTexture = -1;
|
m_lastTexture = -1;
|
||||||
|
m_textures.fill(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PainterShaderProgram::link()
|
bool PainterShaderProgram::link()
|
||||||
|
@ -57,6 +58,9 @@ bool PainterShaderProgram::link()
|
||||||
setUniformValue(TIME_UNIFORM, m_time);
|
setUniformValue(TIME_UNIFORM, m_time);
|
||||||
setUniformValue(TEX0_UNIFORM, 0);
|
setUniformValue(TEX0_UNIFORM, 0);
|
||||||
setUniformValue(TEX1_UNIFORM, 1);
|
setUniformValue(TEX1_UNIFORM, 1);
|
||||||
|
|
||||||
|
enableAttributeArray(PainterShaderProgram::VERTEX_ATTR);
|
||||||
|
enableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -96,10 +100,12 @@ void PainterShaderProgram::setTexture(const TexturePtr& texture, int index)
|
||||||
{
|
{
|
||||||
assert(index >= 0 && index <= 1);
|
assert(index >= 0 && index <= 1);
|
||||||
|
|
||||||
if(m_textures[index] == texture)
|
uint texId = texture ? texture->getId() : 0;
|
||||||
|
|
||||||
|
if(m_textures[index] == texId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_textures[index] = texture;
|
m_textures[index] = texId;
|
||||||
m_lastTexture = std::max(m_lastTexture, index);
|
m_lastTexture = std::max(m_lastTexture, index);
|
||||||
|
|
||||||
if(texture && index == 0) {
|
if(texture && index == 0) {
|
||||||
|
@ -129,14 +135,12 @@ void PainterShaderProgram::draw(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||||
coordsBuffer.updateCaches();
|
coordsBuffer.updateCaches();
|
||||||
bool hardwareCached = coordsBuffer.isHardwareCached();
|
bool hardwareCached = coordsBuffer.isHardwareCached();
|
||||||
|
|
||||||
enableAttributeArray(PainterShaderProgram::VERTEX_ATTR);
|
|
||||||
if(hardwareCached)
|
if(hardwareCached)
|
||||||
coordsBuffer.getHardwareVertexBuffer()->bind();
|
coordsBuffer.getHardwareVertexBuffer()->bind();
|
||||||
setAttributeArray(PainterShaderProgram::VERTEX_ATTR, hardwareCached ? 0 : coordsBuffer.getVertexBuffer(), 2);
|
setAttributeArray(PainterShaderProgram::VERTEX_ATTR, hardwareCached ? 0 : coordsBuffer.getVertexBuffer(), 2);
|
||||||
|
|
||||||
bool hasTexture = coordsBuffer.getTextureVertexCount() != 0;
|
bool hasTexture = coordsBuffer.getTextureVertexCount() != 0;
|
||||||
if(hasTexture) {
|
if(hasTexture) {
|
||||||
enableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR);
|
|
||||||
if(hardwareCached)
|
if(hardwareCached)
|
||||||
coordsBuffer.getHardwareTextureVertexBuffer()->bind();
|
coordsBuffer.getHardwareTextureVertexBuffer()->bind();
|
||||||
setAttributeArray(PainterShaderProgram::TEXCOORD_ATTR, hardwareCached ? 0 : coordsBuffer.getTextureVertexBuffer(), 2);
|
setAttributeArray(PainterShaderProgram::TEXCOORD_ATTR, hardwareCached ? 0 : coordsBuffer.getTextureVertexBuffer(), 2);
|
||||||
|
@ -146,19 +150,14 @@ void PainterShaderProgram::draw(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||||
HardwareBuffer::unbind(HardwareBuffer::VertexBuffer);
|
HardwareBuffer::unbind(HardwareBuffer::VertexBuffer);
|
||||||
|
|
||||||
if(m_lastTexture == 0) {
|
if(m_lastTexture == 0) {
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textures[0] ? m_textures[0]->getId() : 0);
|
glBindTexture(GL_TEXTURE_2D, m_textures[0]);
|
||||||
} else {
|
} else {
|
||||||
glActiveTexture(GL_TEXTURE1);
|
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);
|
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);
|
glDrawArrays(drawMode, 0, vertexCount);
|
||||||
|
|
||||||
disableAttributeArray(PainterShaderProgram::VERTEX_ATTR);
|
|
||||||
|
|
||||||
if(hasTexture)
|
|
||||||
disableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public:
|
||||||
private:
|
private:
|
||||||
DrawMode m_drawMode;
|
DrawMode m_drawMode;
|
||||||
float m_startTime;
|
float m_startTime;
|
||||||
TexturePtr m_textures[2];
|
std::array<uint, 2> m_textures;
|
||||||
|
|
||||||
Color m_color;
|
Color m_color;
|
||||||
float m_opacity;
|
float m_opacity;
|
||||||
|
|
|
@ -44,7 +44,6 @@ void UIFrameCounter::drawSelf()
|
||||||
m_fpsText = Fw::formatString("FPS: %d", m_frameCount);
|
m_fpsText = Fw::formatString("FPS: %d", m_frameCount);
|
||||||
m_lastFrameTicks = g_clock.ticks();
|
m_lastFrameTicks = g_clock.ticks();
|
||||||
m_frameCount = 0;
|
m_frameCount = 0;
|
||||||
dump << m_fpsText;
|
|
||||||
}
|
}
|
||||||
m_frameCount++;
|
m_frameCount++;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue