Skip to content

Commit a109b05

Browse files
committed
Replace the NV proc alias macro with a template function
1 parent 889be83 commit a109b05

2 files changed

Lines changed: 30 additions & 20 deletions

File tree

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ ProcTableGLES::Resolver WrappedResolver(
7272
};
7373
}
7474

75+
// Resolves `gl_name` and installs it as `proc`'s implementation. Used to alias
76+
// extension entry points that share a core proc's signature under a different
77+
// name (e.g. the *NV-suffixed GL_NV_texture_array procs).
78+
template <typename Proc, typename Resolver, typename ErrorFn>
79+
static void BindProcAlias(Proc& proc,
80+
const Resolver& resolver,
81+
const ErrorFn& error_fn,
82+
const char* gl_name) {
83+
if (auto fn_ptr = resolver(gl_name)) {
84+
proc.function = reinterpret_cast<decltype(proc.function)>(fn_ptr);
85+
proc.error_fn = error_fn;
86+
}
87+
}
88+
7589
ProcTableGLES::ProcTableGLES( // NOLINT(google-readability-function-size)
7690
Resolver resolver) {
7791
// The reason this constructor has anywhere near enough code to tip off
@@ -136,17 +150,12 @@ ProcTableGLES::ProcTableGLES( // NOLINT(google-readability-function-size)
136150
if (supports_gl3 || description_->HasExtension("GL_EXT_texture_array")) {
137151
FOR_EACH_IMPELLER_TEXTURE_ARRAY_PROC(IMPELLER_PROC);
138152
} 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
153+
BindProcAlias(TexImage3D, resolver, error_fn, "glTexImage3DNV");
154+
BindProcAlias(TexSubImage3D, resolver, error_fn, "glTexSubImage3DNV");
155+
BindProcAlias(CompressedTexImage3D, resolver, error_fn,
156+
"glCompressedTexImage3DNV");
157+
BindProcAlias(CompressedTexSubImage3D, resolver, error_fn,
158+
"glCompressedTexSubImage3DNV");
150159
}
151160

152161
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,15 +778,16 @@ bool TextureGLES::EnsureSliceMipLevelStorage(size_t slice, size_t mip_level) {
778778
GLenum image_target =
779779
is_cube ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice : GL_TEXTURE_2D;
780780
gl.BindTexture(is_cube ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, handle.value());
781-
gl.TexImage2D(image_target, // target
782-
static_cast<GLint>(mip_level), // LOD level
783-
gles_format->internal_format, // internal
784-
mip_width, // width
785-
mip_height, // height
786-
0u, // border
787-
gles_format->external_format, // format
788-
gles_format->type, // type
789-
nullptr // data
781+
gl.TexImage2D(
782+
/*target=*/image_target, //
783+
/*level=*/static_cast<GLint>(mip_level), //
784+
/*internal_format=*/gles_format->internal_format, //
785+
/*width=*/mip_width, //
786+
/*height=*/mip_height, //
787+
/*border=*/0u, //
788+
/*format=*/gles_format->external_format, //
789+
/*type=*/gles_format->type, //
790+
/*data=*/nullptr //
790791
);
791792
MarkSliceMipLevelInitialized(slice, mip_level);
792793
return true;

0 commit comments

Comments
 (0)