| Flutter Linux Embedder |

fl_framebuffer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "fl_framebuffer.h"
6
7 #include <epoxy/gl.h>
8
9 struct _FlFramebuffer {
10 GObject parent_instance;
11
12 // Width of framebuffer in pixels.
13 size_t width;
14
15 // Height of framebuffer in pixels.
16 size_t height;
17
18 // Framebuffer ID.
19 GLuint framebuffer_id;
20
21 // Texture backing framebuffer.
22 GLuint texture_id;
23 };
24
25 G_DEFINE_TYPE(FlFramebuffer, fl_framebuffer, G_TYPE_OBJECT)
26
27 static void fl_framebuffer_dispose(GObject* object) {
28 FlFramebuffer* self = FL_FRAMEBUFFER(object);
29
30 glDeleteFramebuffers(1, &self->framebuffer_id);
31 glDeleteTextures(1, &self->texture_id);
32
33 G_OBJECT_CLASS(fl_framebuffer_parent_class)->dispose(object);
34 }
35
36 static void fl_framebuffer_class_init(FlFramebufferClass* klass) {
37 G_OBJECT_CLASS(klass)->dispose = fl_framebuffer_dispose;
38 }
39
40 static void fl_framebuffer_init(FlFramebuffer* self) {}
41
42 FlFramebuffer* fl_framebuffer_new(GLint format, size_t width, size_t height) {
43 FlFramebuffer* provider =
44 FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
45
46 provider->width = width;
47 provider->height = height;
48
49 glGenTextures(1, &provider->texture_id);
50 glGenFramebuffers(1, &provider->framebuffer_id);
51
52 glBindFramebuffer(GL_FRAMEBUFFER, provider->framebuffer_id);
53
54 glBindTexture(GL_TEXTURE_2D, provider->texture_id);
55 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
56 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
59 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format,
60 GL_UNSIGNED_BYTE, NULL);
61 glBindTexture(GL_TEXTURE_2D, 0);
62
63 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
64 provider->texture_id, 0);
65
66 GLuint depth_stencil;
67 glGenRenderbuffers(1, &depth_stencil);
68 glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil);
69 glRenderbufferStorage(GL_RENDERBUFFER, // target
70 GL_DEPTH24_STENCIL8, // internal format
71 width, // width
72 height // height
73 );
74 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
75 GL_RENDERBUFFER, depth_stencil);
76 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
77 GL_RENDERBUFFER, depth_stencil);
78
79 return provider;
80 }
81
82 GLuint fl_framebuffer_get_id(FlFramebuffer* self) {
83 return self->framebuffer_id;
84 }
85
86 GLuint fl_framebuffer_get_texture_id(FlFramebuffer* self) {
87 return self->texture_id;
88 }
89
90 GLenum fl_framebuffer_get_target(FlFramebuffer* self) {
91 return GL_TEXTURE_2D;
92 }
93
94 size_t fl_framebuffer_get_width(FlFramebuffer* self) {
95 return self->width;
96 }
97
98 size_t fl_framebuffer_get_height(FlFramebuffer* self) {
99 return self->height;
100 }
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
fl_framebuffer_get_height
size_t fl_framebuffer_get_height(FlFramebuffer *self)
Definition: fl_framebuffer.cc:98
fl_framebuffer_init
static void fl_framebuffer_init(FlFramebuffer *self)
Definition: fl_framebuffer.cc:40
fl_framebuffer_get_id
GLuint fl_framebuffer_get_id(FlFramebuffer *self)
Definition: fl_framebuffer.cc:82
fl_framebuffer_get_target
GLenum fl_framebuffer_get_target(FlFramebuffer *self)
Definition: fl_framebuffer.cc:90
fl_framebuffer_class_init
static void fl_framebuffer_class_init(FlFramebufferClass *klass)
Definition: fl_framebuffer.cc:36
fl_framebuffer_dispose
static void fl_framebuffer_dispose(GObject *object)
Definition: fl_framebuffer.cc:27
fl_framebuffer_get_width
size_t fl_framebuffer_get_width(FlFramebuffer *self)
Definition: fl_framebuffer.cc:94
fl_framebuffer_get_texture_id
GLuint fl_framebuffer_get_texture_id(FlFramebuffer *self)
Definition: fl_framebuffer.cc:86
fl_framebuffer_new
FlFramebuffer * fl_framebuffer_new(GLint format, size_t width, size_t height)
Definition: fl_framebuffer.cc:42
fl_framebuffer.h
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
format
uint32_t uint32_t * format
Definition: fl_texture_registrar_test.cc:42
_FlFramebuffer
Definition: fl_framebuffer.cc:9
_FlFramebuffer::framebuffer_id
GLuint framebuffer_id
Definition: fl_framebuffer.cc:19
_FlFramebuffer::parent_instance
GObject parent_instance
Definition: fl_framebuffer.cc:10
_FlFramebuffer::width
size_t width
Definition: fl_framebuffer.cc:13
_FlFramebuffer::texture_id
GLuint texture_id
Definition: fl_framebuffer.cc:22
_FlFramebuffer::height
size_t height
Definition: fl_framebuffer.cc:16