diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-11-04 17:12:47 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-11-04 21:24:05 +0100 |
commit | eed16cb1bb14c5de68e71ba7960cbe264cc08760 (patch) | |
tree | 6e43e3d84c170b8bf55742bd0dfdc8022922dbd8 /src/mbgl | |
parent | 008a83b91584b8cf406264c5378bdd7ef87683ec (diff) | |
download | qtlocation-mapboxgl-eed16cb1bb14c5de68e71ba7960cbe264cc08760.tar.gz |
[core] add state tracking to pixel transfer
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/value.cpp | 28 | ||||
-rw-r--r-- | src/mbgl/gl/value.hpp | 28 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_debug.cpp | 8 |
5 files changed, 65 insertions, 3 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index ceb9796ba6..1cd546f407 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -285,6 +285,8 @@ void Context::setDirtyState() { rasterPos.setDirty(); pixelStorePack.setDirty(); pixelStoreUnpack.setDirty(); + pixelTransferDepth.setDirty(); + pixelTransferStencil.setDirty(); #endif // MBGL_USE_GLES2 for (auto& tex : texture) { tex.setDirty(); diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index b3edd55636..9bfa54fa55 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -132,6 +132,8 @@ public: State<value::RasterPos> rasterPos; State<value::PixelStorePack> pixelStorePack; State<value::PixelStoreUnpack> pixelStoreUnpack; + State<value::PixelTransferDepth> pixelTransferDepth; + State<value::PixelTransferStencil> pixelTransferStencil; #endif // MBGL_USE_GLES2 private: diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index af4f03a132..86218f3d9a 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -417,6 +417,34 @@ PixelStoreUnpack::Type PixelStoreUnpack::Get() { return value; } +const constexpr PixelTransferDepth::Type PixelTransferDepth::Default; + +void PixelTransferDepth::Set(const Type& value) { + MBGL_CHECK_ERROR(glPixelTransferf(GL_DEPTH_SCALE, value.scale)); + MBGL_CHECK_ERROR(glPixelTransferf(GL_DEPTH_BIAS, value.bias)); +} + +PixelTransferDepth::Type PixelTransferDepth::Get() { + Type value; + MBGL_CHECK_ERROR(glGetFloatv(GL_DEPTH_SCALE, &value.scale)); + MBGL_CHECK_ERROR(glGetFloatv(GL_DEPTH_BIAS, &value.bias)); + return value; +} + +const constexpr PixelTransferStencil::Type PixelTransferStencil::Default; + +void PixelTransferStencil::Set(const Type& value) { + MBGL_CHECK_ERROR(glPixelTransferf(GL_INDEX_SHIFT, value.shift)); + MBGL_CHECK_ERROR(glPixelTransferf(GL_INDEX_OFFSET, value.offset)); +} + +PixelTransferStencil::Type PixelTransferStencil::Get() { + Type value; + MBGL_CHECK_ERROR(glGetIntegerv(GL_INDEX_SHIFT, &value.shift)); + MBGL_CHECK_ERROR(glGetIntegerv(GL_INDEX_OFFSET, &value.offset)); + return value; +} + #endif // MBGL_USE_GLES2 } // namespace value diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 613bbfcab2..3586c26bda 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -282,6 +282,34 @@ struct PixelStoreUnpack { static Type Get(); }; +struct PixelTransferDepth { + struct Type { + float scale; + float bias; + }; + static const constexpr Type Default = { 1, 0 }; + static void Set(const Type&); + static Type Get(); +}; + +constexpr bool operator!=(const PixelTransferDepth::Type& a, const PixelTransferDepth::Type& b) { + return a.scale != b.scale || a.bias != b.bias; +} + +struct PixelTransferStencil { + struct Type { + int32_t shift; + int32_t offset; + }; + static const constexpr Type Default = { 0, 0 }; + static void Set(const Type&); + static Type Get(); +}; + +constexpr bool operator!=(const PixelTransferStencil::Type& a, const PixelTransferStencil::Type& b) { + return a.shift != b.shift || a.offset != b.offset; +} + #endif // MBGL_USE_GLES2 } // namespace value diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index 1db2167b71..bdc0b90bd4 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -73,6 +73,9 @@ void Painter::renderClipMasks(PaintParameters&) { // tightly packed into the buffer to avoid buffer overruns. Also see unpacking adjustment below. context.pixelStorePack = { 1 }; + // Reset the value in case someone else changed it, or it's dirty. + context.pixelTransferStencil = gl::value::PixelTransferStencil::Default; + // Read the stencil buffer const auto viewport = context.viewport.getCurrentValue(); auto pixels = std::make_unique<uint8_t[]>(viewport.size.width * viewport.size.height); @@ -116,9 +119,8 @@ void Painter::renderDepthBuffer(PaintParameters&) { // Scales the values in the depth buffer so that they cover the entire grayscale range. This // makes it easier to spot tiny differences. - const double base = 1.0 / (1.0 - depthRangeSize); - MBGL_CHECK_ERROR(glPixelTransferf(GL_DEPTH_SCALE, base)); - MBGL_CHECK_ERROR(glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base)); + const float base = 1.0f / (1.0f - depthRangeSize); + context.pixelTransferDepth = { base, 1.0f - base }; // Read the stencil buffer auto viewport = context.viewport.getCurrentValue(); |