[core] add state tracking to pixel transfer

This commit is contained in:
Konstantin Käfer
2016-11-04 17:12:47 +01:00
parent 008a83b915
commit eed16cb1bb
5 changed files with 65 additions and 3 deletions

View File

@@ -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();

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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();