24 gl.BindFramebuffer(
type, GL_NONE);
25 gl.DeleteFramebuffers(1u, &fbo);
31 const std::shared_ptr<Texture>&
texture,
34 if (!handle.has_value()) {
41 gl.BindFramebuffer(fbo_type, 0);
46 gl.GenFramebuffers(1u, &fbo);
47 gl.BindFramebuffer(fbo_type, fbo);
56 GLenum status = gl.CheckFramebufferStatus(fbo_type);
57 if (status != GL_FRAMEBUFFER_COMPLETE) {
76 const auto& gl =
reactor.GetProcTable();
80 if (!gl.BlitFramebuffer.IsAvailable()) {
82 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
86 GLuint read_fbo = GL_NONE;
87 GLuint draw_fbo = GL_NONE;
89 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
90 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
95 if (!read.has_value()) {
98 read_fbo = read.value();
103 if (!draw.has_value()) {
106 draw_fbo = draw.value();
109 gl.Disable(GL_SCISSOR_TEST);
110 gl.Disable(GL_DEPTH_TEST);
111 gl.Disable(GL_STENCIL_TEST);
113 const auto destination_right =
115 const auto destination_bottom =
145 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
146 "this texture object.";
151 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
157 if (tex_descriptor.size.IsEmpty()) {
161 if (!tex_descriptor.IsValid() ||
170 GLenum texture_target;
171 switch (tex_descriptor.type) {
173 texture_type = GL_TEXTURE_2D;
174 texture_target = GL_TEXTURE_2D;
177 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
178 "the OpenGLES backend.";
181 texture_type = GL_TEXTURE_CUBE_MAP;
182 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
slice;
185 texture_type = GL_TEXTURE_EXTERNAL_OES;
186 texture_target = GL_TEXTURE_EXTERNAL_OES;
190 std::optional<PixelFormatGLES> gles_format =
193 reactor.GetProcTable().GetDescription()->HasExtension(
194 "GL_EXT_texture_format_BGRA8888"));
195 if (!gles_format.has_value()) {
201 if (!gl_handle.has_value()) {
203 <<
"Texture was collected before it could be uploaded to the GPU.";
206 const auto& gl =
reactor.GetProcTable();
207 gl.BindTexture(texture_type, gl_handle.value());
208 const GLvoid* tex_data =
214 if (gles_format->is_compressed) {
215 const auto mip_width =
216 std::max<int32_t>(1, tex_descriptor.size.width >>
mip_level);
217 const auto mip_height =
218 std::max<int32_t>(1, tex_descriptor.size.height >>
mip_level);
222 VALIDATION_LOG <<
"Compressed textures must be uploaded as a full mip "
223 "level starting at the origin.";
226 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
227 gl.CompressedTexImage2D(texture_target,
229 gles_format->internal_format,
246 const auto level_width =
247 std::max<int32_t>(1, tex_descriptor.size.width >>
mip_level);
248 const auto level_height =
249 std::max<int32_t>(1, tex_descriptor.size.height >>
mip_level);
250 gl.TexImage2D(texture_target,
252 gles_format->internal_format,
256 gles_format->external_format,
263 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
264 gl.TexSubImage2D(texture_target,
270 gles_format->external_format,
286 const auto& gl =
reactor.GetProcTable();
289 std::optional<PixelFormatGLES> gles_format =
292 reactor.GetProcTable().GetDescription()->HasExtension(
293 "GL_EXT_texture_format_BGRA8888"));
295 if (!gles_format.has_value()) {
300 GLuint read_fbo = GL_NONE;
302 [&gl, &read_fbo]() {
DeleteFBO(gl, read_fbo, GL_FRAMEBUFFER); });
306 if (!read.has_value()) {
309 read_fbo = read.value();
315 format = gles_format->external_format,
316 type = gles_format->type
317 ](uint8_t* data,
size_t length) {
318 gl.ReadPixels(source_region.GetX(), source_region.GetY(),
319 source_region.GetWidth(), source_region.GetHeight(),
320 format, type, data + destination_offset);
334 if (!texture_gles->GenerateMipmap()) {
347 return "Resize Texture";
351 const auto& gl =
reactor.GetProcTable();
355 if (!gl.BlitFramebuffer.IsAvailable()) {
357 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
361 GLuint read_fbo = GL_NONE;
362 GLuint draw_fbo = GL_NONE;
364 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
365 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
370 if (!read.has_value()) {
373 read_fbo = read.value();
378 if (!draw.has_value()) {
381 draw_fbo = draw.value();
384 gl.Disable(GL_SCISSOR_TEST);
385 gl.Disable(GL_DEPTH_TEST);
386 gl.Disable(GL_STENCIL_TEST);
391 gl.BlitFramebuffer(source_region.
GetX(),
392 source_region.
GetY(),
395 destination_region.
GetX(),
396 destination_region.
GetY(),
Wraps a closure that is invoked in the destructor unless released by the caller.
static TextureGLES & Cast(Texture &base)
void UpdateBufferData(const std::function< void(uint8_t *, size_t length)> &update_buffer_data)
virtual uint8_t * OnGetContents() const =0
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
bool IsSliceMipLevelInitialized(size_t slice, size_t mip_level) const
void MarkSliceMipLevelInitialized(size_t slice, size_t mip_level)
Indicates that storage for mip_level of slice has been allocated by a glTexImage2D call (or equivalen...
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type, uint32_t mip_level=0, uint32_t slice=0)
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
uint32_t uint32_t * format
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
std::string DebugToFramebufferError(int status)
static std::optional< GLuint > ConfigureFBO(const ProcTableGLES &gl, const std::shared_ptr< Texture > &texture, GLenum fbo_type)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
static void DeleteFBO(const ProcTableGLES &gl, GLuint fbo, GLenum type)
constexpr size_t BytesForTextureRegion(PixelFormat format, int64_t width, int64_t height)
The number of bytes required to store a width x height texel region in format. Block-compressed forma...
std::shared_ptr< ReactorGLES > reactor
impeller::ShaderType type
~BlitCopyBufferToTextureCommandGLES() override
std::string GetLabel() const override
bool Encode(const ReactorGLES &reactor) const override
std::shared_ptr< Texture > destination
~BlitCopyTextureToBufferCommandGLES() override
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
std::shared_ptr< DeviceBuffer > destination
std::shared_ptr< Texture > source
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
~BlitCopyTextureToTextureCommandGLES() override
IPoint destination_origin
std::shared_ptr< Texture > destination
std::shared_ptr< Texture > source
virtual ~BlitEncodeGLES()
~BlitGenerateMipmapCommandGLES() override
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
std::shared_ptr< Texture > texture
~BlitResizeTextureCommandGLES() override
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
std::shared_ptr< Texture > destination
std::shared_ptr< Texture > source
const DeviceBuffer * GetBuffer() const
constexpr auto GetBottom() const
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
constexpr auto GetRight() const
static constexpr TRect MakeSize(const TSize< U > &size)
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.