Upgrade OpenGL backend to ES 3.0 (#995)
Co-authored-by: Tadej Novak <tadej@tano.si>
This commit is contained in:
@@ -26,7 +26,6 @@ protected:
|
||||
public:
|
||||
static constexpr const uint32_t minimumRequiredVertexBindingCount = 8;
|
||||
const uint32_t maximumVertexBindingCount;
|
||||
bool supportsHalfFloatTextures = false;
|
||||
|
||||
public:
|
||||
Context(Context&&) = delete;
|
||||
|
||||
@@ -107,19 +107,6 @@ void Context::initializeExtensions(const std::function<gl::ProcAddress(const cha
|
||||
vertexArray = std::make_unique<extension::VertexArray>(fn);
|
||||
}
|
||||
|
||||
#if MBGL_USE_GLES2
|
||||
constexpr const char* halfFloatExtensionName = "OES_texture_half_float";
|
||||
constexpr const char* halfFloatColorBufferExtensionName = "EXT_color_buffer_half_float";
|
||||
#else
|
||||
constexpr const char* halfFloatExtensionName = "ARB_half_float_pixel";
|
||||
constexpr const char* halfFloatColorBufferExtensionName = "ARB_color_buffer_float";
|
||||
#endif
|
||||
if (strstr(extensions, halfFloatExtensionName) != nullptr &&
|
||||
strstr(extensions, halfFloatColorBufferExtensionName) != nullptr) {
|
||||
|
||||
supportsHalfFloatTextures = true;
|
||||
}
|
||||
|
||||
if (!supportsVertexArrays()) {
|
||||
Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
|
||||
}
|
||||
@@ -316,18 +303,6 @@ std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const gfx::
|
||||
return data;
|
||||
}
|
||||
|
||||
#if !MBGL_USE_GLES2
|
||||
void Context::drawPixels(const Size size, const void* data, gfx::TexturePixelType format) {
|
||||
pixelStoreUnpack = { 1 };
|
||||
// TODO
|
||||
if (format != gfx::TexturePixelType::RGBA) {
|
||||
format = gfx::TexturePixelType::Luminance;
|
||||
}
|
||||
MBGL_CHECK_ERROR(glDrawPixels(size.width, size.height, Enum<gfx::TexturePixelType>::to(format),
|
||||
GL_UNSIGNED_BYTE, data));
|
||||
}
|
||||
#endif // MBGL_USE_GLES2
|
||||
|
||||
namespace {
|
||||
|
||||
void checkFramebuffer() {
|
||||
@@ -486,13 +461,6 @@ void Context::setDirtyState() {
|
||||
activeTextureUnit.setDirty();
|
||||
pixelStorePack.setDirty();
|
||||
pixelStoreUnpack.setDirty();
|
||||
#if !MBGL_USE_GLES2
|
||||
pointSize.setDirty();
|
||||
pixelZoom.setDirty();
|
||||
rasterPos.setDirty();
|
||||
pixelTransferDepth.setDirty();
|
||||
pixelTransferStencil.setDirty();
|
||||
#endif // MBGL_USE_GLES2
|
||||
for (auto& tex : texture) {
|
||||
tex.setDirty();
|
||||
}
|
||||
@@ -610,10 +578,6 @@ void Context::draw(const gfx::DrawMode& drawMode,
|
||||
std::size_t indexLength) {
|
||||
switch (drawMode.type) {
|
||||
case gfx::DrawModeType::Points:
|
||||
#if !MBGL_USE_GLES2
|
||||
// In OpenGL ES 2, the point size is set in the vertex shader.
|
||||
pointSize = drawMode.size;
|
||||
#endif // MBGL_USE_GLES2
|
||||
break;
|
||||
case gfx::DrawModeType::Lines:
|
||||
case gfx::DrawModeType::LineLoop:
|
||||
@@ -727,56 +691,12 @@ void Context::reduceMemoryUsage() {
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
void Context::visualizeStencilBuffer() {
|
||||
#if !MBGL_USE_GLES2
|
||||
setStencilMode(gfx::StencilMode::disabled());
|
||||
setDepthMode(gfx::DepthMode::disabled());
|
||||
setColorMode(gfx::ColorMode::unblended());
|
||||
program = 0;
|
||||
|
||||
// Reset the value in case someone else changed it, or it's dirty.
|
||||
pixelTransferStencil = gl::value::PixelTransferStencil::Default;
|
||||
|
||||
// Read the stencil buffer
|
||||
const auto viewportValue = viewport.getCurrentValue();
|
||||
auto image = readFramebuffer<AlphaImage, gfx::TexturePixelType::Stencil>(viewportValue.size, false);
|
||||
|
||||
// Scale the Stencil buffer to cover the entire color space.
|
||||
auto it = image.data.get();
|
||||
auto end = it + viewportValue.size.width * viewportValue.size.height;
|
||||
const auto factor = 255.0f / *std::max_element(it, end);
|
||||
for (; it != end; ++it) {
|
||||
*it *= factor;
|
||||
}
|
||||
|
||||
pixelZoom = { 1, 1 };
|
||||
rasterPos = { -1, -1, 0, 1 };
|
||||
drawPixels(image);
|
||||
#endif
|
||||
throw std::runtime_error("Not yet implemented");
|
||||
}
|
||||
|
||||
void Context::visualizeDepthBuffer(const float depthRangeSize) {
|
||||
(void)depthRangeSize;
|
||||
#if !MBGL_USE_GLES2
|
||||
setStencilMode(gfx::StencilMode::disabled());
|
||||
setDepthMode(gfx::DepthMode::disabled());
|
||||
setColorMode(gfx::ColorMode::unblended());
|
||||
program = 0;
|
||||
|
||||
// Scales the values in the depth buffer so that they cover the entire grayscale range. This
|
||||
// makes it easier to spot tiny differences.
|
||||
const float base = 1.0f / (1.0f - depthRangeSize);
|
||||
pixelTransferDepth = { base, 1.0f - base };
|
||||
|
||||
// Read the stencil buffer
|
||||
auto viewportValue = viewport.getCurrentValue();
|
||||
auto image = readFramebuffer<AlphaImage, gfx::TexturePixelType::Depth>(viewportValue.size, false);
|
||||
|
||||
pixelZoom = { 1, 1 };
|
||||
rasterPos = { -1, -1, 0, 1 };
|
||||
drawPixels(image);
|
||||
#endif
|
||||
void Context::visualizeDepthBuffer([[maybe_unused]] const float depthRangeSize) {
|
||||
throw std::runtime_error("Not yet implemented");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Context::clearStencilBuffer(const int32_t bits) {
|
||||
|
||||
@@ -74,14 +74,6 @@ public:
|
||||
return { size, readFramebuffer(size, format, flip) };
|
||||
}
|
||||
|
||||
#if !MBGL_USE_GLES2
|
||||
template <typename Image>
|
||||
void drawPixels(const Image& image) {
|
||||
auto format = image.channels == 4 ? gfx::TexturePixelType::RGBA : gfx::TexturePixelType::Alpha;
|
||||
drawPixels(image.size, image.data.get(), format);
|
||||
}
|
||||
#endif // MBGL_USE_GLES2
|
||||
|
||||
void clear(std::optional<mbgl::Color> color,
|
||||
std::optional<float> depth,
|
||||
std::optional<int32_t> stencil);
|
||||
@@ -154,13 +146,6 @@ public:
|
||||
State<value::PixelStorePack> pixelStorePack;
|
||||
State<value::PixelStoreUnpack> pixelStoreUnpack;
|
||||
|
||||
#if !MBGL_USE_GLES2
|
||||
State<value::PixelZoom> pixelZoom;
|
||||
State<value::RasterPos> rasterPos;
|
||||
State<value::PixelTransferDepth> pixelTransferDepth;
|
||||
State<value::PixelTransferStencil> pixelTransferStencil;
|
||||
#endif // MBGL_USE_GLES2
|
||||
|
||||
private:
|
||||
State<value::StencilFunc> stencilFunc;
|
||||
State<value::StencilMask> stencilMask;
|
||||
@@ -183,9 +168,6 @@ private:
|
||||
State<value::CullFace> cullFace;
|
||||
State<value::CullFaceSide> cullFaceSide;
|
||||
State<value::CullFaceWinding> cullFaceWinding;
|
||||
#if !MBGL_USE_GLES2
|
||||
State<value::PointSize> pointSize;
|
||||
#endif // MBGL_USE_GLES2
|
||||
|
||||
std::unique_ptr<gfx::OffscreenTexture> createOffscreenTexture(Size, gfx::TextureChannelDataType) override;
|
||||
|
||||
@@ -198,9 +180,6 @@ private:
|
||||
|
||||
UniqueFramebuffer createFramebuffer();
|
||||
std::unique_ptr<uint8_t[]> readFramebuffer(Size, gfx::TexturePixelType, bool flip);
|
||||
#if !MBGL_USE_GLES2
|
||||
void drawPixels(Size size, const void* data, gfx::TexturePixelType);
|
||||
#endif // MBGL_USE_GLES2
|
||||
|
||||
VertexArray createVertexArray();
|
||||
bool supportsVertexArrays() const;
|
||||
|
||||
@@ -164,18 +164,4 @@
|
||||
#define GL_VERTEX_SHADER 0x8B31
|
||||
#define GL_VIEWPORT 0x0BA2
|
||||
#define GL_ZERO 0
|
||||
#ifdef MBGL_USE_GLES2
|
||||
#define GL_HALF_FLOAT 0x8D61
|
||||
#else
|
||||
#define GL_CURRENT_RASTER_POSITION 0x0B07
|
||||
#define GL_DEPTH24_STENCIL8 0x88F0
|
||||
#define GL_DEPTH_BIAS 0x0D1F
|
||||
#define GL_DEPTH_SCALE 0x0D1E
|
||||
#define GL_HALF_FLOAT 0x140B
|
||||
#define GL_INDEX_OFFSET 0x0D13
|
||||
#define GL_INDEX_SHIFT 0x0D12
|
||||
#define GL_POINT_SIZE 0x0B11
|
||||
#define GL_RGBA8 0x8058
|
||||
#define GL_ZOOM_X 0x0D16
|
||||
#define GL_ZOOM_Y 0x0D17
|
||||
#endif
|
||||
#define GL_HALF_FLOAT 0x8D61
|
||||
@@ -286,15 +286,9 @@ platform::GLenum Enum<gfx::TextureChannelDataType>::to(const gfx::TextureChannel
|
||||
template <>
|
||||
gfx::RenderbufferPixelType Enum<gfx::RenderbufferPixelType>::from(const platform::GLint value) {
|
||||
switch (value) {
|
||||
#if !MBGL_USE_GLES2
|
||||
case GL_RGBA8: return gfx::RenderbufferPixelType::RGBA;
|
||||
case GL_DEPTH_COMPONENT: return gfx::RenderbufferPixelType::Depth;
|
||||
case GL_DEPTH24_STENCIL8: return gfx::RenderbufferPixelType::DepthStencil;
|
||||
#else
|
||||
case GL_RGBA8_OES: return gfx::RenderbufferPixelType::RGBA;
|
||||
case GL_DEPTH_COMPONENT16: return gfx::RenderbufferPixelType::Depth;
|
||||
case GL_DEPTH24_STENCIL8_OES: return gfx::RenderbufferPixelType::DepthStencil;
|
||||
#endif
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -302,15 +296,9 @@ gfx::RenderbufferPixelType Enum<gfx::RenderbufferPixelType>::from(const platform
|
||||
template <>
|
||||
platform::GLenum Enum<gfx::RenderbufferPixelType>::to(const gfx::RenderbufferPixelType value) {
|
||||
switch (value) {
|
||||
#if !MBGL_USE_GLES2
|
||||
case gfx::RenderbufferPixelType::RGBA: return GL_RGBA8;
|
||||
case gfx::RenderbufferPixelType::Depth: return GL_DEPTH_COMPONENT;
|
||||
case gfx::RenderbufferPixelType::DepthStencil: return GL_DEPTH24_STENCIL8;
|
||||
#else
|
||||
case gfx::RenderbufferPixelType::RGBA: return GL_RGBA8_OES;
|
||||
case gfx::RenderbufferPixelType::Depth: return GL_DEPTH_COMPONENT16;
|
||||
case gfx::RenderbufferPixelType::DepthStencil: return GL_DEPTH24_STENCIL8_OES;
|
||||
#endif
|
||||
}
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
const std::string& additionalDefines) {
|
||||
// Compile the shader
|
||||
std::initializer_list<const char*> vertexSource = {
|
||||
"#version 300 es\n",
|
||||
programParameters.getDefines().c_str(),
|
||||
additionalDefines.c_str(),
|
||||
shaders::ShaderSource<shaders::BuiltIn::Prelude, gfx::Backend::Type::OpenGL>::vertex,
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
};
|
||||
|
||||
std::initializer_list<const char*> fragmentSource = {
|
||||
"#version 300 es\n",
|
||||
programParameters.getDefines().c_str(),
|
||||
additionalDefines.c_str(),
|
||||
shaders::ShaderSource<shaders::BuiltIn::Prelude, gfx::Backend::Type::OpenGL>::fragment,
|
||||
|
||||
@@ -542,76 +542,6 @@ PixelStoreUnpack::Type PixelStoreUnpack::Get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
#if !MBGL_USE_GLES2
|
||||
|
||||
const constexpr PointSize::Type PointSize::Default;
|
||||
|
||||
void PointSize::Set(const Type& value) {
|
||||
MBGL_CHECK_ERROR(glPointSize(value));
|
||||
}
|
||||
|
||||
PointSize::Type PointSize::Get() {
|
||||
GLfloat pointSize;
|
||||
MBGL_CHECK_ERROR(glGetFloatv(GL_POINT_SIZE, &pointSize));
|
||||
return pointSize;
|
||||
}
|
||||
|
||||
const constexpr PixelZoom::Type PixelZoom::Default;
|
||||
|
||||
void PixelZoom::Set(const Type& value) {
|
||||
MBGL_CHECK_ERROR(glPixelZoom(value.xfactor, value.yfactor));
|
||||
}
|
||||
|
||||
PixelZoom::Type PixelZoom::Get() {
|
||||
GLfloat xfactor;
|
||||
GLfloat yfactor;
|
||||
MBGL_CHECK_ERROR(glGetFloatv(GL_ZOOM_X, &xfactor));
|
||||
MBGL_CHECK_ERROR(glGetFloatv(GL_ZOOM_Y, &yfactor));
|
||||
return { xfactor, yfactor };
|
||||
}
|
||||
|
||||
const constexpr RasterPos::Type RasterPos::Default;
|
||||
|
||||
void RasterPos::Set(const Type& value) {
|
||||
MBGL_CHECK_ERROR(glRasterPos4d(value.x, value.y, value.z, value.w));
|
||||
}
|
||||
|
||||
RasterPos::Type RasterPos::Get() {
|
||||
GLdouble pos[4];
|
||||
MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos));
|
||||
return { pos[0], pos[1], pos[2], pos[3] };
|
||||
}
|
||||
|
||||
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
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -283,75 +283,6 @@ struct PixelStoreUnpack {
|
||||
static Type Get();
|
||||
};
|
||||
|
||||
#if !MBGL_USE_GLES2
|
||||
|
||||
struct PointSize {
|
||||
using Type = float;
|
||||
static const constexpr Type Default = 1;
|
||||
static void Set(const Type&);
|
||||
static Type Get();
|
||||
};
|
||||
|
||||
struct PixelZoom {
|
||||
struct Type {
|
||||
float xfactor;
|
||||
float yfactor;
|
||||
};
|
||||
static const constexpr Type Default = { 1, 1 };
|
||||
static void Set(const Type&);
|
||||
static Type Get();
|
||||
};
|
||||
|
||||
constexpr bool operator!=(const PixelZoom::Type& a, const PixelZoom::Type& b) {
|
||||
return a.xfactor != b.xfactor || a.yfactor != b.yfactor;
|
||||
}
|
||||
|
||||
struct RasterPos {
|
||||
struct Type {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
double w;
|
||||
};
|
||||
static const constexpr Type Default = { 0, 0, 0, 1 };
|
||||
static void Set(const Type&);
|
||||
static Type Get();
|
||||
};
|
||||
|
||||
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 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
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -82,20 +82,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters) {
|
||||
assert(colorRampTexture);
|
||||
|
||||
if (!renderTexture || renderTexture->getSize() != size) {
|
||||
renderTexture.reset();
|
||||
if (parameters.context.supportsHalfFloatTextures) {
|
||||
renderTexture = parameters.context.createOffscreenTexture(size, gfx::TextureChannelDataType::HalfFloat);
|
||||
|
||||
if (!renderTexture->isRenderable()) {
|
||||
// can't render to a half-float texture; falling back to unsigned byte one
|
||||
renderTexture.reset();
|
||||
parameters.context.supportsHalfFloatTextures = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!renderTexture) {
|
||||
renderTexture = parameters.context.createOffscreenTexture(size, gfx::TextureChannelDataType::UnsignedByte);
|
||||
}
|
||||
renderTexture = parameters.context.createOffscreenTexture(size, gfx::TextureChannelDataType::HalfFloat);
|
||||
}
|
||||
|
||||
auto renderPass = parameters.encoder->createRenderPass(
|
||||
|
||||
Reference in New Issue
Block a user