7 #include "flutter/fml/closure.h"
8 #include "fml/trace_event.h"
21 gl.BindFramebuffer(
type, GL_NONE);
22 gl.DeleteFramebuffers(1u, &fbo);
28 const std::shared_ptr<Texture>& texture,
31 if (!handle.has_value()) {
38 gl.BindFramebuffer(fbo_type, 0);
43 gl.GenFramebuffers(1u, &fbo);
44 gl.BindFramebuffer(fbo_type, fbo);
53 if (gl.CheckFramebufferStatus(fbo_type) != GL_FRAMEBUFFER_COMPLETE) {
75 if (!gl.BlitFramebuffer.IsAvailable()) {
77 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
81 GLuint read_fbo = GL_NONE;
82 GLuint draw_fbo = GL_NONE;
83 fml::ScopedCleanupClosure delete_fbos([&gl, &read_fbo, &draw_fbo]() {
84 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
85 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
90 if (!read.has_value()) {
93 read_fbo = read.value();
98 if (!draw.has_value()) {
101 draw_fbo = draw.value();
104 gl.Disable(GL_SCISSOR_TEST);
105 gl.Disable(GL_DEPTH_TEST);
106 gl.Disable(GL_STENCIL_TEST);
124 struct TexImage2DData {
130 explicit TexImage2DData(
PixelFormat pixel_format) {
131 switch (pixel_format) {
135 type = GL_UNSIGNED_BYTE;
140 type = GL_UNSIGNED_BYTE;
148 type = GL_UNSIGNED_BYTE;
158 type = GL_HALF_FLOAT;
169 type = GL_UNSIGNED_INT_24_8;
182 TexImage2DData(
PixelFormat pixel_format, BufferView p_buffer_view)
183 : TexImage2DData(pixel_format) {
187 bool IsValid()
const {
return is_valid_; }
190 bool is_valid_ =
false;
206 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
207 "this texture object.";
212 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
218 if (tex_descriptor.size.IsEmpty()) {
222 if (!tex_descriptor.IsValid() ||
232 GLenum texture_target;
233 switch (tex_descriptor.type) {
235 texture_type = GL_TEXTURE_2D;
236 texture_target = GL_TEXTURE_2D;
239 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
240 "the OpenGLES backend.";
243 texture_type = GL_TEXTURE_CUBE_MAP;
244 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
slice;
247 texture_type = GL_TEXTURE_EXTERNAL_OES;
248 texture_target = GL_TEXTURE_EXTERNAL_OES;
252 TexImage2DData
data = TexImage2DData(tex_descriptor.format,
source);
253 if (!
data.IsValid()) {
259 if (!gl_handle.has_value()) {
261 <<
"Texture was collected before it could be uploaded to the GPU.";
265 gl.BindTexture(texture_type, gl_handle.value());
266 const GLvoid* tex_data =
267 data.buffer_view.buffer->OnGetContents() +
data.buffer_view.range.offset;
272 gl.TexImage2D(texture_target,
274 data.internal_format,
275 tex_descriptor.size.width,
276 tex_descriptor.size.height,
278 data.external_format,
286 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
287 gl.TexSubImage2D(texture_target,
293 data.external_format,
312 VALIDATION_LOG <<
"Only textures with pixel format RGBA are supported yet.";
318 GLuint read_fbo = GL_NONE;
319 fml::ScopedCleanupClosure delete_fbos(
320 [&gl, &read_fbo]() {
DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER); });
324 if (!read.has_value()) {
327 read_fbo = read.value();
348 if (!texture_gles->GenerateMipmap()) {
361 return "Resize Texture";
369 if (!gl.BlitFramebuffer.IsAvailable()) {
371 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
375 GLuint read_fbo = GL_NONE;
376 GLuint draw_fbo = GL_NONE;
377 fml::ScopedCleanupClosure delete_fbos([&gl, &read_fbo, &draw_fbo]() {
378 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
379 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
384 if (!read.has_value()) {
387 read_fbo = read.value();
392 if (!draw.has_value()) {
395 draw_fbo = draw.value();
398 gl.Disable(GL_SCISSOR_TEST);
399 gl.Disable(GL_DEPTH_TEST);
400 gl.Disable(GL_STENCIL_TEST);
405 gl.BlitFramebuffer(source_region.
GetX(),
406 source_region.
GetY(),
409 destination_region.
GetX(),
410 destination_region.
GetY(),