[core] move gl::Context to Backend and refactor View

This commit is contained in:
Konstantin Käfer
2016-10-10 17:16:37 +02:00
parent 5cc390d694
commit a4d259c33f
76 changed files with 914 additions and 1024 deletions

View File

@@ -89,7 +89,7 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
}
#ifndef NDEBUG
void Painter::renderClipMasks(PaintParameters& parameters) {
void Painter::renderClipMasks(PaintParameters&) {
context.stencilTest = false;
context.depthTest = false;
context.program = 0;
@@ -100,13 +100,13 @@ void Painter::renderClipMasks(PaintParameters& parameters) {
context.rasterPos = { -1, -1, 0, 0 };
// Read the stencil buffer
const auto& fbSize = parameters.view.getFramebufferSize();
auto pixels = std::make_unique<uint8_t[]>(fbSize[0] * fbSize[1]);
const auto viewport = context.viewport.getCurrentValue();
auto pixels = std::make_unique<uint8_t[]>(viewport.width * viewport.height);
MBGL_CHECK_ERROR(glReadPixels(
0, // GLint x
0, // GLint y
fbSize[0], // GLsizei width
fbSize[1], // GLsizei height
viewport.x, // GLint x
viewport.y, // GLint y
viewport.width, // GLsizei width
viewport.height, // GLsizei height
GL_STENCIL_INDEX, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
pixels.get() // GLvoid * data
@@ -114,22 +114,21 @@ void Painter::renderClipMasks(PaintParameters& parameters) {
// Scale the Stencil buffer to cover the entire color space.
auto it = pixels.get();
auto end = it + fbSize[0] * fbSize[1];
auto end = it + viewport.width * viewport.height;
const auto factor = 255.0f / *std::max_element(it, end);
for (; it != end; ++it) {
*it *= factor;
}
MBGL_CHECK_ERROR(glWindowPos2i(0, 0));
MBGL_CHECK_ERROR(glDrawPixels(fbSize[0], fbSize[1], GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
#else
(void)parameters;
MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y));
MBGL_CHECK_ERROR(glDrawPixels(viewport.width, viewport.height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
pixels.get()));
#endif // MBGL_USE_GLES2
}
#endif // NDEBUG
#ifndef NDEBUG
void Painter::renderDepthBuffer(PaintParameters& parameters) {
void Painter::renderDepthBuffer(PaintParameters&) {
context.stencilTest = false;
context.depthTest = false;
context.program = 0;
@@ -140,27 +139,26 @@ void Painter::renderDepthBuffer(PaintParameters& parameters) {
context.rasterPos = { -1, -1, 0, 0 };
// Read the stencil buffer
const auto& fbSize = parameters.view.getFramebufferSize();
auto pixels = std::make_unique<GLubyte[]>(fbSize[0] * fbSize[1]);
const auto viewport = context.viewport.getCurrentValue();
auto pixels = std::make_unique<uint8_t[]>(viewport.width * viewport.height);
const double base = 1.0 / (1.0 - depthRangeSize);
glPixelTransferf(GL_DEPTH_SCALE, base);
glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base);
MBGL_CHECK_ERROR(glReadPixels(
0, // GLint x
0, // GLint y
fbSize[0], // GLsizei width
fbSize[1], // GLsizei height
viewport.x, // GLint x
viewport.y, // GLint y
viewport.width, // GLsizei width
viewport.height, // GLsizei height
GL_DEPTH_COMPONENT, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
pixels.get() // GLvoid * data
));
MBGL_CHECK_ERROR(glWindowPos2i(0, 0));
MBGL_CHECK_ERROR(glDrawPixels(fbSize[0], fbSize[1], GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
#else
(void)parameters;
MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y));
MBGL_CHECK_ERROR(glDrawPixels(viewport.width, viewport.height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
pixels.get()));
#endif // MBGL_USE_GLES2
}
#endif // NDEBUG