7 #include "flutter/fml/closure.h"
8 #include "fml/trace_event.h"
20 gl.BindFramebuffer(
type, GL_NONE);
21 gl.DeleteFramebuffers(1u, &fbo);
27 const std::shared_ptr<Texture>& texture,
30 if (!handle.has_value()) {
37 gl.BindFramebuffer(fbo_type, 0);
42 gl.GenFramebuffers(1u, &fbo);
43 gl.BindFramebuffer(fbo_type, fbo);
52 if (gl.CheckFramebufferStatus(fbo_type) != GL_FRAMEBUFFER_COMPLETE) {
74 if (!gl.BlitFramebuffer.IsAvailable()) {
76 FML_LOG(ERROR) <<
"Texture blit fallback not implemented yet for GLES2.";
80 GLuint read_fbo = GL_NONE;
81 GLuint draw_fbo = GL_NONE;
82 fml::ScopedCleanupClosure delete_fbos([&gl, &read_fbo, &draw_fbo]() {
83 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
84 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
89 if (!read.has_value()) {
92 read_fbo = read.value();
97 if (!draw.has_value()) {
100 draw_fbo = draw.value();
103 gl.Disable(GL_SCISSOR_TEST);
104 gl.Disable(GL_DEPTH_TEST);
105 gl.Disable(GL_STENCIL_TEST);
123 struct TexImage2DData {
129 explicit TexImage2DData(
PixelFormat pixel_format) {
130 switch (pixel_format) {
134 type = GL_UNSIGNED_BYTE;
139 type = GL_UNSIGNED_BYTE;
147 type = GL_UNSIGNED_BYTE;
157 type = GL_HALF_FLOAT;
168 type = GL_UNSIGNED_INT_24_8;
181 TexImage2DData(
PixelFormat pixel_format, BufferView p_buffer_view)
182 : TexImage2DData(pixel_format) {
186 bool IsValid()
const {
return is_valid_; }
189 bool is_valid_ =
false;
205 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
206 "this texture object.";
211 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
217 if (tex_descriptor.size.IsEmpty()) {
221 if (!tex_descriptor.IsValid() ||
231 GLenum texture_target;
232 switch (tex_descriptor.type) {
234 texture_type = GL_TEXTURE_2D;
235 texture_target = GL_TEXTURE_2D;
238 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
239 "the OpenGLES backend.";
242 texture_type = GL_TEXTURE_CUBE_MAP;
243 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
slice;
246 texture_type = GL_TEXTURE_EXTERNAL_OES;
247 texture_target = GL_TEXTURE_EXTERNAL_OES;
251 TexImage2DData
data = TexImage2DData(tex_descriptor.format,
source);
252 if (!
data.IsValid()) {
258 if (!gl_handle.has_value()) {
260 <<
"Texture was collected before it could be uploaded to the GPU.";
264 gl.BindTexture(texture_type, gl_handle.value());
265 const GLvoid* tex_data =
266 data.buffer_view.buffer->OnGetContents() +
data.buffer_view.range.offset;
271 gl.TexImage2D(texture_target,
273 data.internal_format,
274 tex_descriptor.size.width,
275 tex_descriptor.size.height,
277 data.external_format,
285 TRACE_EVENT1(
"impeller",
"TexImage2DUpload",
"Bytes",
286 std::to_string(
data.buffer_view.range.length).c_str());
287 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
288 gl.TexSubImage2D(texture_target,
294 data.external_format,
313 VALIDATION_LOG <<
"Only textures with pixel format RGBA are supported yet.";
319 GLuint read_fbo = GL_NONE;
320 fml::ScopedCleanupClosure delete_fbos(
321 [&gl, &read_fbo]() {
DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER); });
325 if (!read.has_value()) {
328 read_fbo = read.value();
349 if (!texture_gles->GenerateMipmap()) {