Skip to content

Commit 76c0e11

Browse files
committed
Support 2D texture arrays on OpenGL ES 2.0 via extensions
The GLES array-texture path previously required GL/GLES 3.0 for the glTexImage3D/glTexSubImage3D entry points. Split those procs into their own group and resolve them below 3.0 when an extension provides them: desktop GL 2.x exposes the core-named entry points through GL_EXT_texture_array, and OpenGL ES 2.0 exposes them through GL_NV_texture_array under *NV-suffixed names, which share the core signatures and are resolved as aliases into the core procs so call sites do not branch. SupportsTextureArray() now gates on the resolved procs rather than the GL version, so a context that advertises an extension without providing the entry points is correctly treated as unsupported, and ES 2.0 devices that do expose them are supported. Adds CapabilitiesGLES tests for the ES 3.0, ES 2.0 (unsupported), NV, and EXT paths.
1 parent 05a9902 commit 76c0e11

7 files changed

Lines changed: 91 additions & 17 deletions

File tree

‎engine/src/flutter/impeller/renderer/backend/gles/capabilities_gles.cc‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,16 @@ CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
207207
desc->GetGlVersion().major_version >= 3 ||
208208
desc->HasExtension(kAppleTextureMaxLevelExt);
209209

210-
// GL_TEXTURE_2D_ARRAY and sampler2DArray are core in desktop GL 3.0 and
211-
// OpenGL ES 3.0. ES 2.0 has no core fallback, though some ES 2.0 devices
212-
// expose them via GL_EXT_texture_array.
213-
// TODO(bdero): Also honor GL_EXT_texture_array on ES 2.0 contexts that expose
214-
// it, resolving the array procs from the extension.
215-
supports_texture_array_ = desc->GetGlVersion().major_version >= 3;
210+
// 2D array textures (GL_TEXTURE_2D_ARRAY, sampled as sampler2DArray) need the
211+
// 3D texture upload entry points. These are core on desktop GL 3.0 and
212+
// OpenGL ES 3.0, and reachable below them via GL_EXT_texture_array (desktop
213+
// GL 2.x) or GL_NV_texture_array (OpenGL ES 2.0). Gate on the resolved procs
214+
// rather than the version so a context that advertises an extension but does
215+
// not actually provide the entry points is treated as unsupported, and so
216+
// ES 2.0 devices that do expose them are supported.
217+
supports_texture_array_ = gl.TexImage3D.IsAvailable() &&
218+
gl.TexSubImage3D.IsAvailable() &&
219+
gl.CompressedTexSubImage3D.IsAvailable();
216220

217221
// Anisotropic filtering is not part of any core GL or GLES version; it is
218222
// always gated on GL_EXT_texture_filter_anisotropic. The query and the

‎engine/src/flutter/impeller/renderer/backend/gles/capabilities_gles.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ class CapabilitiesGLES final
9393
bool SupportsTextureMaxLevel() const;
9494

9595
/// @brief Whether 2D array textures (`GL_TEXTURE_2D_ARRAY`, `sampler2DArray`)
96-
/// are available. Core on desktop GL 3.0+ and OpenGL ES 3.0+; absent
97-
/// on ES 2.0, where callers must fall back to a texture atlas.
96+
/// are available. Core on desktop GL 3.0+ and OpenGL ES 3.0+, and also
97+
/// available below them through GL_EXT_texture_array (desktop GL 2.x)
98+
/// or GL_NV_texture_array (OpenGL ES 2.0). When absent, callers must
99+
/// fall back to a texture atlas.
98100
bool SupportsTextureArray() const;
99101

100102
// |Capabilities|

‎engine/src/flutter/impeller/renderer/backend/gles/proc_table_gles.cc‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,33 @@ ProcTableGLES::ProcTableGLES( // NOLINT(google-readability-function-size)
122122
proc_ivar.error_fn = error_fn; \
123123
}
124124

125-
if (description_->GetGlVersion().IsAtLeast(Version(3))) {
125+
const bool supports_gl3 = description_->GetGlVersion().IsAtLeast(Version(3));
126+
if (supports_gl3) {
126127
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC);
127128
}
128129

130+
// 2D array textures need the 3D texture entry points. They are core on
131+
// GL/GLES 3.0, exposed on desktop GL 2.x through GL_EXT_texture_array (which
132+
// uses the same entry-point names), and on OpenGL ES 2.0 through
133+
// GL_NV_texture_array (which suffixes them with NV). The NV entry points
134+
// share the core signatures, so they are resolved as aliases into the core
135+
// procs and the rest of the backend can call them without branching.
136+
if (supports_gl3 || description_->HasExtension("GL_EXT_texture_array")) {
137+
FOR_EACH_IMPELLER_TEXTURE_ARRAY_PROC(IMPELLER_PROC);
138+
} else if (description_->HasExtension("GL_NV_texture_array")) {
139+
#define IMPELLER_PROC_ALIAS(proc_ivar, gl_name) \
140+
if (auto fn_ptr = resolver(gl_name)) { \
141+
proc_ivar.function = \
142+
reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
143+
proc_ivar.error_fn = error_fn; \
144+
}
145+
IMPELLER_PROC_ALIAS(TexImage3D, "glTexImage3DNV");
146+
IMPELLER_PROC_ALIAS(TexSubImage3D, "glTexSubImage3DNV");
147+
IMPELLER_PROC_ALIAS(CompressedTexImage3D, "glCompressedTexImage3DNV");
148+
IMPELLER_PROC_ALIAS(CompressedTexSubImage3D, "glCompressedTexSubImage3DNV");
149+
#undef IMPELLER_PROC_ALIAS
150+
}
151+
129152
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
130153

131154
#undef IMPELLER_PROC

‎engine/src/flutter/impeller/renderer/backend/gles/proc_table_gles.h‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,17 @@ void(glDepthRange)(GLdouble n, GLdouble f);
269269
PROC(WaitSync); \
270270
PROC(RenderbufferStorageMultisample); \
271271
PROC(BlitFramebuffer); \
272-
PROC(InvalidateFramebuffer); \
273-
PROC(TexImage3D); \
274-
PROC(TexSubImage3D); \
275-
PROC(CompressedTexImage3D); \
272+
PROC(InvalidateFramebuffer);
273+
274+
// 3D texture entry points, used by 2D array textures. These are core on
275+
// GL/GLES 3.0 and also reachable below it: desktop GL 2.x exposes these exact
276+
// entry points through GL_EXT_texture_array, and OpenGL ES 2.0 exposes them
277+
// through GL_NV_texture_array under *NV-suffixed names (resolved as aliases
278+
// into these procs). See ProcTableGLES setup.
279+
#define FOR_EACH_IMPELLER_TEXTURE_ARRAY_PROC(PROC) \
280+
PROC(TexImage3D); \
281+
PROC(TexSubImage3D); \
282+
PROC(CompressedTexImage3D); \
276283
PROC(CompressedTexSubImage3D);
277284

278285
#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
@@ -323,6 +330,7 @@ class ProcTableGLES {
323330
FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC);
324331
FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC);
325332
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC);
333+
FOR_EACH_IMPELLER_TEXTURE_ARRAY_PROC(IMPELLER_PROC);
326334
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
327335

328336
#undef IMPELLER_PROC

‎engine/src/flutter/impeller/renderer/backend/gles/test/capabilities_unittests.cc‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,43 @@ TEST(CapabilitiesGLES, MaxSamplerAnisotropyWithExtension) {
8989
EXPECT_GE(capabilities->GetMaxSamplerAnisotropy(), 2u);
9090
}
9191

92+
TEST(CapabilitiesGLES, SupportsTextureArrayOnES3) {
93+
// 2D array textures are core on OpenGL ES 3.0, no extension needed.
94+
auto mock_gles = MockGLES::Init(std::nullopt, "OpenGL ES 3.0");
95+
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
96+
EXPECT_TRUE(capabilities->SupportsTextureArray());
97+
}
98+
99+
TEST(CapabilitiesGLES, DoesNotSupportTextureArrayOnES2WithoutExtension) {
100+
auto const extensions = std::vector<const char*>{"GL_KHR_debug"};
101+
auto mock_gles = MockGLES::Init(extensions, "OpenGL ES 2.0");
102+
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
103+
EXPECT_FALSE(capabilities->SupportsTextureArray());
104+
}
105+
106+
TEST(CapabilitiesGLES, SupportsTextureArrayViaNVExtensionOnES2) {
107+
// OpenGL ES 2.0 has no core array textures, but GL_NV_texture_array exposes
108+
// them through *NV-suffixed 3D texture entry points.
109+
auto const extensions = std::vector<const char*>{
110+
"GL_KHR_debug", //
111+
"GL_NV_texture_array", //
112+
};
113+
auto mock_gles = MockGLES::Init(extensions, "OpenGL ES 2.0");
114+
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
115+
EXPECT_TRUE(capabilities->SupportsTextureArray());
116+
}
117+
118+
TEST(CapabilitiesGLES, SupportsTextureArrayViaEXTExtension) {
119+
// GL_EXT_texture_array exposes the core-named 3D texture entry points below
120+
// GL 3.0 (desktop GL 2.x).
121+
auto const extensions = std::vector<const char*>{
122+
"GL_KHR_debug", //
123+
"GL_EXT_texture_array", //
124+
};
125+
auto mock_gles = MockGLES::Init(extensions, "OpenGL ES 2.0");
126+
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
127+
EXPECT_TRUE(capabilities->SupportsTextureArray());
128+
}
129+
92130
} // namespace testing
93131
} // namespace impeller

‎engine/src/flutter/impeller/renderer/backend/gles/test/texture_gles_unittests.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ TEST_P(TextureGLESTest, CanCreateAndUpload2DArrayTexture) {
156156
->GetProcTable()
157157
.GetCapabilities()
158158
->SupportsTextureArray()) {
159-
GTEST_SKIP() << "2D array textures require OpenGL ES 3.0.";
159+
GTEST_SKIP() << "2D array textures are not supported on this context.";
160160
}
161161

162162
TextureDescriptor desc;

‎engine/src/flutter/impeller/renderer/backend/gles/texture_gles.cc‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ void TextureGLES::InitializeContentsIfNecessary() {
507507
}
508508
} else if (desc.type == TextureType::kTexture2DArray) {
509509
if (!gl.GetCapabilities()->SupportsTextureArray()) {
510-
VALIDATION_LOG
511-
<< "2D array textures require OpenGL ES 3.0 or desktop "
512-
"GL 3.0; this context does not support them.";
510+
VALIDATION_LOG << "2D array textures are not supported on this "
511+
"context.";
513512
return;
514513
}
515514
// Array textures allocate the whole base mip level (all layers) in one

0 commit comments

Comments
 (0)