performance improvement, lock free render
This commit is contained in:
parent
04c2e1d245
commit
a46a16738c
|
@ -94,10 +94,6 @@ IF(WIN32)
|
||||||
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp
|
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp)
|
${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp)
|
||||||
|
|
||||||
IF(CRASH_HANDLER)
|
|
||||||
SET(ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} imagehlp)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
IF(WINDOWS_CONSOLE)
|
IF(WINDOWS_CONSOLE)
|
||||||
MESSAGE(STATUS "Windows console: ON")
|
MESSAGE(STATUS "Windows console: ON")
|
||||||
ELSE()
|
ELSE()
|
||||||
|
|
|
@ -35,6 +35,7 @@ void Painter::init()
|
||||||
setColor(Color::white);
|
setColor(Color::white);
|
||||||
setOpacity(1.0f);
|
setOpacity(1.0f);
|
||||||
setCompositionMode(CompositionMode_Normal);
|
setCompositionMode(CompositionMode_Normal);
|
||||||
|
releaseCustomProgram();
|
||||||
|
|
||||||
m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram);
|
m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||||
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||||
|
@ -53,7 +54,7 @@ void Painter::terminate()
|
||||||
m_drawSolidColorProgram.reset();
|
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)
|
if(coordsBuffer.getVertexCount() == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -66,7 +67,7 @@ void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer&
|
||||||
|
|
||||||
void Painter::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
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);
|
program->setTexture(texture);
|
||||||
drawProgram(program, coordsBuffer);
|
drawProgram(program, coordsBuffer);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +79,7 @@ void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture, cons
|
||||||
|
|
||||||
m_coordsBuffer.clear();
|
m_coordsBuffer.clear();
|
||||||
m_coordsBuffer.addQuad(dest, src);
|
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);
|
program->setTexture(texture);
|
||||||
drawProgram(program, m_coordsBuffer, PainterShaderProgram::TriangleStrip);
|
drawProgram(program, m_coordsBuffer, PainterShaderProgram::TriangleStrip);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +101,7 @@ void Painter::drawFilledRect(const Rect& dest)
|
||||||
|
|
||||||
m_coordsBuffer.clear();
|
m_coordsBuffer.clear();
|
||||||
m_coordsBuffer.addRect(dest);
|
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)
|
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.clear();
|
||||||
m_coordsBuffer.addBoudingRect(dest, innerLineWidth);
|
m_coordsBuffer.addBoudingRect(dest, innerLineWidth);
|
||||||
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer);
|
drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram.get(), m_coordsBuffer);
|
||||||
}
|
|
||||||
|
|
||||||
void Painter::setCustomProgram(const PainterShaderProgramPtr& program)
|
|
||||||
{
|
|
||||||
m_customProgram = program;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||||
|
@ -172,7 +168,7 @@ void Painter::saveAndResetState()
|
||||||
|
|
||||||
void Painter::restoreSavedState()
|
void Painter::restoreSavedState()
|
||||||
{
|
{
|
||||||
setCustomProgram(m_oldCustomProgram);
|
m_customProgram = m_oldCustomProgram;
|
||||||
setColor(m_oldColor);
|
setColor(m_oldColor);
|
||||||
setOpacity(m_oldOpacity);
|
setOpacity(m_oldOpacity);
|
||||||
setCompositionMode(m_oldCompostionMode);
|
setCompositionMode(m_oldCompostionMode);
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
void init();
|
void init();
|
||||||
void terminate();
|
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 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, const Rect& src);
|
||||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); }
|
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; }
|
Rect getClipRect() { return m_clipRect; }
|
||||||
void resetClipRect() { setClipRect(Rect()); }
|
void resetClipRect() { setClipRect(Rect()); }
|
||||||
|
|
||||||
void setCustomProgram(const PainterShaderProgramPtr& program);
|
void setCustomProgram(const PainterShaderProgramPtr& program) { m_customProgram = program.get(); }
|
||||||
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); }
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
private:
|
private:
|
||||||
PainterShaderProgramPtr m_drawTexturedProgram;
|
PainterShaderProgramPtr m_drawTexturedProgram;
|
||||||
PainterShaderProgramPtr m_drawSolidColorProgram;
|
PainterShaderProgramPtr m_drawSolidColorProgram;
|
||||||
PainterShaderProgramPtr m_customProgram;
|
PainterShaderProgram *m_customProgram;
|
||||||
Matrix3 m_projectionMatrix;
|
Matrix3 m_projectionMatrix;
|
||||||
Color m_color;
|
Color m_color;
|
||||||
float m_opacity;
|
float m_opacity;
|
||||||
|
@ -83,7 +83,7 @@ private:
|
||||||
CoordsBuffer m_coordsBuffer;
|
CoordsBuffer m_coordsBuffer;
|
||||||
Rect m_clipRect;
|
Rect m_clipRect;
|
||||||
|
|
||||||
PainterShaderProgramPtr m_oldCustomProgram;
|
PainterShaderProgram *m_oldCustomProgram;
|
||||||
Matrix3 m_oldProjectionMatrix;
|
Matrix3 m_oldProjectionMatrix;
|
||||||
Color m_oldColor;
|
Color m_oldColor;
|
||||||
float m_oldOpacity;
|
float m_oldOpacity;
|
||||||
|
|
|
@ -793,12 +793,24 @@ void X11Window::poll()
|
||||||
|
|
||||||
void X11Window::swapBuffers()
|
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
|
#ifndef OPENGL_ES2
|
||||||
glFinish();
|
glFinish();
|
||||||
glXSwapBuffers(m_display, m_window);
|
glXSwapBuffers(m_display, m_window);
|
||||||
#else
|
#else
|
||||||
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
||||||
#endif
|
#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()
|
void X11Window::showMouse()
|
||||||
|
|
Loading…
Reference in New Issue