Check for packed depth stencil
This commit is contained in:
@@ -533,6 +533,16 @@ void NativeMapView::loadExtensions() {
|
||||
gl::IsVertexArray = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (extensions.find("GL_OES_packed_depth_stencil") != std::string::npos) {
|
||||
mbgl::Log::Info(mbgl::Event::OpenGL, "Using GL_OES_packed_depth_stencil.");
|
||||
gl::is_packed_depth_stencil_supported = true;
|
||||
}
|
||||
|
||||
if (extensions.find("GL_OES_depth24") != std::string::npos) {
|
||||
mbgl::Log::Info(mbgl::Event::OpenGL, "Using GL_OES_depth24.");
|
||||
gl::is_depth24_supported = true;
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::stop() {
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
#if TARGET_OS_IPHONE
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
// #define glGenVertexArrays glGenVertexArraysOES
|
||||
// #define glBindVertexArray glBindVertexArrayOES
|
||||
// #define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||
// #define GL_ARB_vertex_array_object 1
|
||||
// #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
|
||||
#elif TARGET_IPHONE_SIMULATOR
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
@@ -44,6 +39,11 @@ extern PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
||||
extern PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
||||
extern PFNGLISVERTEXARRAYPROC IsVertexArray;
|
||||
|
||||
extern bool is_packed_depth_stencil_supported;
|
||||
#define GL_DEPTH24_STENCIL8 0x88F0
|
||||
|
||||
extern bool is_depth24_supported;
|
||||
#define GL_DEPTH_COMPONENT24 0x81A6
|
||||
|
||||
// Debug group markers, useful for debuggin on iOS
|
||||
#if __APPLE__ && defined(DEBUG) && defined(GL_EXT_debug_marker)
|
||||
@@ -63,7 +63,6 @@ inline void start_group(const std::string &) {}
|
||||
inline void end_group() {}
|
||||
#endif
|
||||
|
||||
|
||||
struct group {
|
||||
inline group(const std::string &str) { start_group(str); }
|
||||
~group() { end_group(); };
|
||||
|
||||
@@ -29,7 +29,8 @@ private:
|
||||
GLint previous_fbo = 0;
|
||||
GLuint fbo = 0;
|
||||
GLuint texture = 0;
|
||||
GLuint fbo_depth_stencil = 0;
|
||||
GLuint fbo_depth= 0;
|
||||
GLuint fbo_stencil = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,12 @@ PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays = nullptr;
|
||||
PFNGLGENVERTEXARRAYSPROC GenVertexArrays = nullptr;
|
||||
PFNGLISVERTEXARRAYPROC IsVertexArray = nullptr;
|
||||
|
||||
// GL_OES_packed_depth_stencil
|
||||
bool is_packed_depth_stencil_supported = false;
|
||||
|
||||
// GL_OES_depth24
|
||||
bool is_depth24_supported = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +38,4 @@ void _CHECK_GL_ERROR(const char *cmd, const char *file, int line) {
|
||||
std::cerr << "GL_" << error.c_str() << " - " << file << ":" << line << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,16 @@ PrerenderedTexture::~PrerenderedTexture() {
|
||||
texture = 0;
|
||||
}
|
||||
|
||||
if (fbo_depth != 0) {
|
||||
glDeleteRenderbuffers(1, &fbo_depth);
|
||||
fbo_depth = 0;
|
||||
}
|
||||
|
||||
if (fbo_stencil != 0) {
|
||||
glDeleteRenderbuffers(1, &fbo_stencil);
|
||||
fbo_stencil = 0;
|
||||
}
|
||||
|
||||
if (fbo != 0) {
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
fbo = 0;
|
||||
@@ -45,15 +55,29 @@ void PrerenderedTexture::bindFramebuffer() {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
if (fbo_depth_stencil == 0) {
|
||||
// Create depth/stencil buffer
|
||||
glGenRenderbuffers(1, &fbo_depth_stencil);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_stencil);
|
||||
#ifdef GL_ES_VERSION_2_0
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, properties.size, properties.size);
|
||||
#else
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, properties.size, properties.size);
|
||||
#endif
|
||||
if (fbo_depth == 0) {
|
||||
// Create depth buffer
|
||||
glGenRenderbuffers(1, &fbo_depth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth);
|
||||
if (gl::is_packed_depth_stencil_supported) {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, properties.size, properties.size);
|
||||
} else {
|
||||
if (gl::is_depth24_supported) {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, properties.size, properties.size);
|
||||
} else {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, properties.size, properties.size);
|
||||
}
|
||||
}
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
if (!gl::is_packed_depth_stencil_supported && (fbo_stencil == 0)) {
|
||||
// Create stencil buffer
|
||||
glGenRenderbuffers(1, &fbo_stencil);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fbo_stencil);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, properties.size, properties.size);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
@@ -61,12 +85,18 @@ void PrerenderedTexture::bindFramebuffer() {
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
|
||||
if (gl::is_packed_depth_stencil_supported) {
|
||||
#ifdef GL_ES_VERSION_2_0
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth_stencil);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_depth_stencil);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_depth);
|
||||
#else
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_depth_stencil);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_depth);
|
||||
#endif
|
||||
} else {
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_stencil);
|
||||
}
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
|
||||
Reference in New Issue
Block a user