Flutter Linux Embedder
fl_framebuffer.h File Reference
#include <epoxy/gl.h>
#include <glib-object.h>

Go to the source code of this file.

Functions

G_BEGIN_DECLS FlFramebuffer * fl_framebuffer_new (GLint format, size_t width, size_t height, gboolean depth_stencil)
 
FlFramebuffer * fl_framebuffer_new_multisample (GLint format, size_t width, size_t height, gboolean use_msaa)
 
GLuint fl_framebuffer_get_id (FlFramebuffer *framebuffer)
 
GLuint fl_framebuffer_get_texture_id (FlFramebuffer *framebuffer)
 
size_t fl_framebuffer_get_width (FlFramebuffer *framebuffer)
 
size_t fl_framebuffer_get_height (FlFramebuffer *framebuffer)
 

Function Documentation

◆ fl_framebuffer_get_height()

size_t fl_framebuffer_get_height ( FlFramebuffer *  framebuffer)

fl_framebuffer_get_height: @framebuffer: an #FlFramebuffer.

Gets the height of the framebuffer in pixels.

Returns: height in pixels.

Definition at line 206 of file fl_framebuffer.cc.

206  {
207  return self->height;
208 }

Referenced by composite_layer(), fl_opengl_frame_composite(), fl_opengl_frame_draw(), and fl_opengl_frame_get_size().

◆ fl_framebuffer_get_id()

GLuint fl_framebuffer_get_id ( FlFramebuffer *  framebuffer)

fl_framebuffer_get_id: @framebuffer: an #FlFramebuffer.

Gets the ID for this framebuffer.

Returns: OpenGL framebuffer id or 0 if creation failed.

Definition at line 194 of file fl_framebuffer.cc.

194  {
195  return self->framebuffer_id;
196 }

Referenced by create_opengl_backing_store(), fl_compositor_opengl_composite_layers(), fl_opengl_frame_composite(), and TEST_F().

◆ fl_framebuffer_get_texture_id()

GLuint fl_framebuffer_get_texture_id ( FlFramebuffer *  framebuffer)

fl_framebuffer_get_texture_id: @framebuffer: an #FlFramebuffer.

Gets the ID of the texture associated with this framebuffer.

Returns: OpenGL texture id or 0 if creation failed.

Definition at line 198 of file fl_framebuffer.cc.

198  {
199  return self->texture_id;
200 }

Referenced by composite_layer(), create_opengl_backing_store(), and TEST_F().

◆ fl_framebuffer_get_width()

size_t fl_framebuffer_get_width ( FlFramebuffer *  framebuffer)

fl_framebuffer_get_width: @framebuffer: an #FlFramebuffer.

Gets the width of the framebuffer in pixels.

Returns: width in pixels.

Definition at line 202 of file fl_framebuffer.cc.

202  {
203  return self->width;
204 }

Referenced by composite_layer(), fl_opengl_frame_composite(), fl_opengl_frame_draw(), and fl_opengl_frame_get_size().

◆ fl_framebuffer_new()

G_BEGIN_DECLS FlFramebuffer* fl_framebuffer_new ( GLint  format,
size_t  width,
size_t  height,
gboolean  depth_stencil 
)

FlFramebuffer:

#FlFramebuffer creates framebuffers and their backing textures for use by the Flutter compositor. fl_framebuffer_new: @format: format, e.g. GL_RGB, GL_BGR @width: width of texture. @height: height of texture. @depth_stencil: TRUE to attach a depth/stencil buffer, which is required to render into this framebuffer.

Creates a new frame buffer. Requires a valid OpenGL context to create.

Returns: a new #FlFramebuffer.

Definition at line 96 of file fl_framebuffer.cc.

99  {
100  FlFramebuffer* self =
101  FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
102 
103  self->width = width;
104  self->height = height;
105 
106  glGenFramebuffers(1, &self->framebuffer_id);
107  glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffer_id);
108 
109  self->texture_id = create_texture(format, width, height);
110 
111  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
112  self->texture_id, 0);
113 
114  if (depth_stencil) {
115  glGenRenderbuffers(1, &self->depth_stencil);
116  glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
117  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
118  attach_depth_stencil(self->depth_stencil);
119  }
120 
121  return self;
122 }
static void attach_depth_stencil(GLuint depth_stencil)
static GLuint create_texture(GLint format, size_t width, size_t height)
const uint8_t uint32_t uint32_t * height
const uint8_t uint32_t * width
uint32_t uint32_t * format

References attach_depth_stencil(), create_texture(), format, height, and width.

Referenced by fl_opengl_frame_composite(), and TEST_F().

◆ fl_framebuffer_new_multisample()

FlFramebuffer* fl_framebuffer_new_multisample ( GLint  format,
size_t  width,
size_t  height,
gboolean  use_msaa 
)

fl_framebuffer_new_multisample: @format: texture format, e.g. GL_RGBA, GL_BGRA_EXT. @width: width of framebuffer in pixels. @height: height of framebuffer in pixels. @use_msaa: TRUE to enable multisample anti-aliasing (MSAA) attachments.

Creates a new frame buffer, configuring MSAA attachments if supported and @use_msaa is TRUE.

When @use_msaa is TRUE, the framebuffer will configure 4x MSAA attachments using either implicit MSAA (multisampled texture via GL_EXT_multisampled_render_to_texture) with the requested @format or offscreen MSAA (multisample color renderbuffer). If offscreen MSAA is used, the framebuffer is backed by a GL_RGBA8 renderbuffer instead of a texture (fl_framebuffer_get_texture_id() returns 0) and must be resolved into a single-sample texture via glBlitFramebuffer before compositing.

If @use_msaa is FALSE or MSAA is not supported by the OpenGL context, a standard single-sample texture with @format and depth/stencil renderbuffer are created.

Returns: a new #FlFramebuffer.

Definition at line 124 of file fl_framebuffer.cc.

127  {
128  FlFramebuffer* self =
129  FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
130 
131  self->width = width;
132  self->height = height;
133 
134  glGenFramebuffers(1, &self->framebuffer_id);
135  glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffer_id);
136 
137  if (use_msaa) {
139  // Implicit MSAA uses GL_EXT_multisampled_render_to_texture, where the
140  // OpenGL driver automatically resolves multisamples into the attached
141  // texture when rendering is completed.
142  self->texture_id = create_texture(format, width, height);
143  glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
144  GL_TEXTURE_2D, self->texture_id, 0,
145  4);
146 
147  glGenRenderbuffers(1, &self->depth_stencil);
148  glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
149  glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4,
150  GL_DEPTH24_STENCIL8, width, height);
151  attach_depth_stencil(self->depth_stencil);
152  } else if (check_supports_offscreen_msaa()) {
153  // Offscreen MSAA uses a multisample renderbuffer instead of a texture.
154  // The multisample resolve occurs in fl_compositor_opengl_composite_layers
155  // via glBlitFramebuffer (or composite_layer) into the compositor's
156  // single-sample framebuffer texture.
157  glGenRenderbuffers(1, &self->color_renderbuffer);
158  glBindRenderbuffer(GL_RENDERBUFFER, self->color_renderbuffer);
159  glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, width,
160  height);
161  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
162  GL_RENDERBUFFER, self->color_renderbuffer);
163 
164  glGenRenderbuffers(1, &self->depth_stencil);
165  glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
166  glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8,
167  width, height);
168  attach_depth_stencil(self->depth_stencil);
169  } else {
170  self->texture_id = create_texture(format, width, height);
171  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
172  GL_TEXTURE_2D, self->texture_id, 0);
173 
174  glGenRenderbuffers(1, &self->depth_stencil);
175  glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
176  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width,
177  height);
178  attach_depth_stencil(self->depth_stencil);
179  }
180  } else {
181  self->texture_id = create_texture(format, width, height);
182  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
183  self->texture_id, 0);
184 
185  glGenRenderbuffers(1, &self->depth_stencil);
186  glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
187  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
188  attach_depth_stencil(self->depth_stencil);
189  }
190 
191  return self;
192 }
static bool check_supports_offscreen_msaa()
static bool check_supports_implicit_msaa()

References attach_depth_stencil(), check_supports_implicit_msaa(), check_supports_offscreen_msaa(), create_texture(), format, height, and width.

Referenced by create_opengl_backing_store(), and TEST_F().