[core] glPixelStorei is in OpenGL ES 2

This commit is contained in:
John Firebaugh
2017-06-07 15:46:16 -07:00
parent f5d3b850bf
commit b201a7900f
5 changed files with 47 additions and 52 deletions

View File

@@ -258,11 +258,9 @@ std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const Textu
const size_t stride = size.width * (format == TextureFormat::RGBA ? 4 : 1);
auto data = std::make_unique<uint8_t[]>(stride * size.height);
#if not MBGL_USE_GLES2
// When reading data from the framebuffer, make sure that we are storing the values
// tightly packed into the buffer to avoid buffer overruns.
pixelStorePack = { 1 };
#endif // MBGL_USE_GLES2
MBGL_CHECK_ERROR(glReadPixels(0, 0, size.width, size.height, static_cast<GLenum>(format),
GL_UNSIGNED_BYTE, data.get()));
@@ -489,12 +487,12 @@ void Context::setDirtyState() {
program.setDirty();
lineWidth.setDirty();
activeTexture.setDirty();
pixelStorePack.setDirty();
pixelStoreUnpack.setDirty();
#if not MBGL_USE_GLES2
pointSize.setDirty();
pixelZoom.setDirty();
rasterPos.setDirty();
pixelStorePack.setDirty();
pixelStoreUnpack.setDirty();
pixelTransferDepth.setDirty();
pixelTransferStencil.setDirty();
#endif // MBGL_USE_GLES2

View File

@@ -206,11 +206,12 @@ public:
State<value::BindVertexBuffer> vertexBuffer;
State<value::BindElementBuffer> elementBuffer;
State<value::PixelStorePack> pixelStorePack;
State<value::PixelStoreUnpack> pixelStoreUnpack;
#if not MBGL_USE_GLES2
State<value::PixelZoom> pixelZoom;
State<value::RasterPos> rasterPos;
State<value::PixelStorePack> pixelStorePack;
State<value::PixelStoreUnpack> pixelStoreUnpack;
State<value::PixelTransferDepth> pixelTransferDepth;
State<value::PixelTransferStencil> pixelTransferStencil;
#endif // MBGL_USE_GLES2

View File

@@ -66,8 +66,6 @@ enum class PrimitiveType {
TriangleFan = 0x0006
};
#if not MBGL_USE_GLES2
struct PixelStorageType {
int32_t alignment;
};
@@ -76,8 +74,6 @@ constexpr bool operator!=(const PixelStorageType& a, const PixelStorageType& b)
return a.alignment != b.alignment;
}
#endif // MBGL_USE_GLES2
using BinaryProgramFormat = uint32_t;
} // namespace gl

View File

@@ -365,6 +365,34 @@ BindVertexArray::Type BindVertexArray::Get(const Context& context) {
return binding;
}
const constexpr PixelStorePack::Type PixelStorePack::Default;
void PixelStorePack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, value.alignment));
}
PixelStorePack::Type PixelStorePack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_PACK_ALIGNMENT, &value.alignment));
return value;
}
const constexpr PixelStoreUnpack::Type PixelStoreUnpack::Default;
void PixelStoreUnpack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, value.alignment));
}
PixelStoreUnpack::Type PixelStoreUnpack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_UNPACK_ALIGNMENT, &value.alignment));
return value;
}
#if not MBGL_USE_GLES2
const constexpr PointSize::Type PointSize::Default;
@@ -404,34 +432,6 @@ RasterPos::Type RasterPos::Get() {
return { pos[0], pos[1], pos[2], pos[3] };
}
const constexpr PixelStorePack::Type PixelStorePack::Default;
void PixelStorePack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, value.alignment));
}
PixelStorePack::Type PixelStorePack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_PACK_ALIGNMENT, &value.alignment));
return value;
}
const constexpr PixelStoreUnpack::Type PixelStoreUnpack::Default;
void PixelStoreUnpack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, value.alignment));
}
PixelStoreUnpack::Type PixelStoreUnpack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_UNPACK_ALIGNMENT, &value.alignment));
return value;
}
const constexpr PixelTransferDepth::Type PixelTransferDepth::Default;
void PixelTransferDepth::Set(const Type& value) {

View File

@@ -239,6 +239,20 @@ struct BindVertexArray {
static Type Get(const Context&);
};
struct PixelStorePack {
using Type = PixelStorageType;
static const constexpr Type Default = { 4 };
static void Set(const Type&);
static Type Get();
};
struct PixelStoreUnpack {
using Type = PixelStorageType;
static const constexpr Type Default = { 4 };
static void Set(const Type&);
static Type Get();
};
#if not MBGL_USE_GLES2
struct PointSize {
@@ -278,20 +292,6 @@ constexpr bool operator!=(const RasterPos::Type& a, const RasterPos::Type& b) {
return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w;
}
struct PixelStorePack {
using Type = PixelStorageType;
static const constexpr Type Default = { 4 };
static void Set(const Type&);
static Type Get();
};
struct PixelStoreUnpack {
using Type = PixelStorageType;
static const constexpr Type Default = { 4 };
static void Set(const Type&);
static Type Get();
};
struct PixelTransferDepth {
struct Type {
float scale;