From f88eecf4821fa88866216ce5af4af779b841538d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 1 Jan 2022 18:06:50 -0400 Subject: [PATCH] Allow texel buffers in OpenGL ES, when supported by the system. --- src/modules/graphics/Shader.cpp | 5 +++++ src/modules/graphics/opengl/Buffer.cpp | 9 ++++++++- src/modules/graphics/opengl/OpenGL.cpp | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index 728e372ab..c613fd429 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -78,6 +78,11 @@ static const char global_syntax[] = R"( #ifdef GL_OES_standard_derivatives #extension GL_OES_standard_derivatives : enable #endif +#if __VERSION__ >= 300 && defined(GL_OES_texture_buffer) +#extension GL_OES_texture_buffer : enable +#elif __VERSION__ >= 300 && defined(GL_EXT_texture_buffer) +#extension GL_EXT_texture_buffer : enable +#endif )"; static const char render_uniforms[] = R"( diff --git a/src/modules/graphics/opengl/Buffer.cpp b/src/modules/graphics/opengl/Buffer.cpp index d9f880281..327abc273 100644 --- a/src/modules/graphics/opengl/Buffer.cpp +++ b/src/modules/graphics/opengl/Buffer.cpp @@ -151,7 +151,14 @@ bool Buffer::load(const void *initialdata) glGenTextures(1, &texture); gl.bindBufferTextureToUnit(texture, 0, false, true); - glTexBuffer(target, getGLFormat(getDataMember(0).decl.format), buffer); + GLenum glformat = getGLFormat(getDataMember(0).decl.format); + + if (GLAD_VERSION_3_1) + glTexBuffer(target, glformat, buffer); + else if (GLAD_OES_texture_buffer) + glTexBufferOES(target, glformat, buffer); + else if (GLAD_EXT_texture_buffer) + glTexBufferEXT(target, glformat, buffer); } return (glGetError() == GL_NO_ERROR); diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index b4e898cda..11957b60e 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -1479,8 +1479,8 @@ bool OpenGL::isBufferUsageSupported(BufferUsage usage) const case BUFFERUSAGE_INDEX: return true; case BUFFERUSAGE_TEXEL: - // Not supported in ES until 3.2, which we don't support shaders for... - return GLAD_VERSION_3_1; + // Not supported in ES until 3.2, so we rely on extensions there... + return GLAD_VERSION_3_1 || GLAD_OES_texture_buffer || GLAD_EXT_texture_buffer; case BUFFERUSAGE_SHADER_STORAGE: return (GLAD_VERSION_4_3 && isCoreProfile()) || GLAD_ES_VERSION_3_1; case BUFFERUSAGE_MAX_ENUM: