[glfw] Remove GL state restoration

We're doing all of this in our own context anyway, so no need to restore the state
This commit is contained in:
Konstantin Käfer
2017-03-21 15:01:32 +01:00
parent 68e032e505
commit 14bf47c296
3 changed files with 10 additions and 69 deletions

View File

@@ -12,9 +12,6 @@
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/gl/state.hpp>
#include <mbgl/gl/value.hpp>
#include <cassert>
#include <cstdlib>
@@ -567,14 +564,9 @@ void showDebugImage(std::string name, const char *data, size_t width, size_t hei
glfwGetFramebufferSize(debugWindow, &fbWidth, &fbHeight);
float scale = static_cast<float>(fbWidth) / static_cast<float>(width);
{
gl::PreserveState<gl::value::PixelZoom> pixelZoom;
gl::PreserveState<gl::value::RasterPos> rasterPos;
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data));
}
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data));
glfwSwapBuffers(debugWindow);
@@ -604,21 +596,13 @@ void showColorDebugImage(std::string name, const char *data, size_t logicalWidth
float xScale = static_cast<float>(fbWidth) / static_cast<float>(width);
float yScale = static_cast<float>(fbHeight) / static_cast<float>(height);
{
gl::PreserveState<gl::value::ClearColor> clearColor;
gl::PreserveState<gl::value::Blend> blend;
gl::PreserveState<gl::value::BlendFunc> blendFunc;
gl::PreserveState<gl::value::PixelZoom> pixelZoom;
gl::PreserveState<gl::value::RasterPos> rasterPos;
MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1));
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
MBGL_CHECK_ERROR(glPixelZoom(xScale, -yScale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data));
}
MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1));
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
MBGL_CHECK_ERROR(glPixelZoom(xScale, -yScale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data));
glfwSwapBuffers(debugWindow);

View File

@@ -66,34 +66,5 @@ private:
const std::tuple<Args...> params;
};
// Helper struct that stores the current state and restores it upon destruction. You should not use
// this code normally, except for debugging purposes.
template <typename T, typename... Args>
class PreserveState {
public:
PreserveState(Args&&... args)
: params(std::forward_as_tuple(std::forward<Args>(args)...)),
value(get(std::index_sequence_for<Args...>{})) {
}
~PreserveState() {
set(std::index_sequence_for<Args...>{});
}
private:
template <std::size_t... I>
typename T::Type get(std::index_sequence<I...>) {
return T::Get(std::get<I>(params)...);
}
template <std::size_t... I>
void set(std::index_sequence<I...>) {
T::Set(value, std::get<I>(params)...);
}
private:
const std::tuple<Args...> params;
const typename T::Type value;
};
} // namespace gl
} // namespace mbgl

View File

@@ -26,20 +26,6 @@ struct MockGLObject {
const bool MockGLObject::Default = false;
TEST(GLObject, PreserveState) {
getFlag = false;
setFlag = false;
auto object = std::make_unique<gl::PreserveState<MockGLObject>>();
EXPECT_TRUE(getFlag);
EXPECT_FALSE(setFlag);
getFlag = false;
object.reset();
EXPECT_FALSE(getFlag);
EXPECT_TRUE(setFlag);
}
TEST(GLObject, Value) {
setFlag = false;