performance improvement, lock free render

master
Eduardo Bart 12 years ago
parent 04c2e1d245
commit a46a16738c

@ -94,10 +94,6 @@ IF(WIN32)
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp)
IF(CRASH_HANDLER)
SET(ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} imagehlp)
ENDIF()
IF(WINDOWS_CONSOLE)
MESSAGE(STATUS "Windows console: ON")
ELSE()

@ -35,6 +35,7 @@ void Painter::init()
setColor(Color::white);
setOpacity(1.0f);
setCompositionMode(CompositionMode_Normal);
releaseCustomProgram();
m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram);
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
@ -53,7 +54,7 @@ void Painter::terminate()
m_drawSolidColorProgram.reset();
}
void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode)
void Painter::drawProgram(PainterShaderProgram *program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode)
{
if(coordsBuffer.getVertexCount() == 0)
return;
@ -66,7 +67,7 @@ void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer&
void Painter::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
{
PainterShaderProgramPtr& program = m_customProgram ? m_customProgram : m_drawTexturedProgram;
PainterShaderProgram *program = m_customProgram ? m_customProgram : m_drawTexturedProgram.get();
program->setTexture(texture);
drawProgram(program, coordsBuffer);
}
@ -78,7 +79,7 @@ void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture, cons
m_coordsBuffer.clear();
m_coordsBuffer.addQuad(dest, src);
PainterShaderProgramPtr& program = m_customProgram ? m_customProgram : m_drawTexturedProgram;
PainterShaderProgram *program = m_customProgram ? m_customProgram : m_drawTexturedProgram.get();
program->setTexture(texture);
drawProgram(program, m_coordsBuffer, PainterShaderProgram::TriangleStrip);
}
@ -100,7 +101,7 @@ void Painter::drawFilledRect(const Rect& dest)
m_coordsBuffer.clear();
m_coordsBuffer.addRect(dest);
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer);
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram.get(), m_coordsBuffer);
}
void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
@ -110,12 +111,7 @@ void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
m_coordsBuffer.clear();
m_coordsBuffer.addBoudingRect(dest, innerLineWidth);
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer);
}
void Painter::setCustomProgram(const PainterShaderProgramPtr& program)
{
m_customProgram = program;
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram.get(), m_coordsBuffer);
}
void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
@ -172,7 +168,7 @@ void Painter::saveAndResetState()
void Painter::restoreSavedState()
{
setCustomProgram(m_oldCustomProgram);
m_customProgram = m_oldCustomProgram;
setColor(m_oldColor);
setOpacity(m_oldOpacity);
setCompositionMode(m_oldCompostionMode);

@ -43,7 +43,7 @@ public:
void init();
void terminate();
void drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode = PainterShaderProgram::Triangles);
void drawProgram(PainterShaderProgram *program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode = PainterShaderProgram::Triangles);
void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture);
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); }
@ -61,7 +61,7 @@ public:
Rect getClipRect() { return m_clipRect; }
void resetClipRect() { setClipRect(Rect()); }
void setCustomProgram(const PainterShaderProgramPtr& program);
void setCustomProgram(const PainterShaderProgramPtr& program) { m_customProgram = program.get(); }
void releaseCustomProgram() { m_customProgram = nullptr; }
void setCompositionMode(CompositionMode compositionMode);
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
@ -75,7 +75,7 @@ public:
private:
PainterShaderProgramPtr m_drawTexturedProgram;
PainterShaderProgramPtr m_drawSolidColorProgram;
PainterShaderProgramPtr m_customProgram;
PainterShaderProgram *m_customProgram;
Matrix3 m_projectionMatrix;
Color m_color;
float m_opacity;
@ -83,7 +83,7 @@ private:
CoordsBuffer m_coordsBuffer;
Rect m_clipRect;
PainterShaderProgramPtr m_oldCustomProgram;
PainterShaderProgram *m_oldCustomProgram;
Matrix3 m_oldProjectionMatrix;
Color m_oldColor;
float m_oldOpacity;

@ -793,12 +793,24 @@ void X11Window::poll()
void X11Window::swapBuffers()
{
#if 0
auto now = std::chrono::high_resolution_clock::now();
auto gpuStart = now;
static decltype(now) cpuStart;
int cpu = std::chrono::duration_cast<std::chrono::nanoseconds>(now - cpuStart).count();
#endif
#ifndef OPENGL_ES2
glFinish();
glXSwapBuffers(m_display, m_window);
#else
eglSwapBuffers(m_eglDisplay, m_eglSurface);
#endif
#if 0
now = std::chrono::high_resolution_clock::now();
int gpu = std::chrono::duration_cast<std::chrono::nanoseconds>(now - gpuStart).count();
cpuStart = now;
dump << "cpu" << cpu << "gpu" << gpu;
#endif
}
void X11Window::showMouse()

Loading…
Cancel
Save