Skip to content

Commit

Permalink
Only use GL_R32F for the atlas if EXT_float_blend is supported
Browse files Browse the repository at this point in the history
Diffs=
a4c0954201 Only use GL_R32F for the atlas if EXT_float_blend is supported (#9050)

Co-authored-by: Chris Dalton <[email protected]>
  • Loading branch information
csmartdalton and csmartdalton committed Feb 17, 2025
1 parent da9b173 commit 66cabdf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223ed4c89a78c24d1a6152551041b30193f1427f
a4c0954201bd38aca9f6d65514994d9c9969c9ed
2 changes: 2 additions & 0 deletions renderer/include/rive/renderer/gl/gles3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ struct GLCapabilities
bool KHR_blend_equation_advanced_coherent : 1;
bool EXT_base_instance : 1;
bool EXT_clip_cull_distance : 1;
bool EXT_color_buffer_half_float : 1;
bool EXT_float_blend : 1; // Implies EXT_color_buffer_float.
bool EXT_multisampled_render_to_texture : 1;
bool EXT_shader_framebuffer_fetch : 1;
bool EXT_shader_pixel_local_storage : 1;
Expand Down
43 changes: 42 additions & 1 deletion renderer/src/gl/render_context_gl_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,16 @@ void RenderContextGLImpl::resizeAtlasTexture(uint32_t width, uint32_t height)
m_atlasTexture = glutils::Texture();
glActiveTexture(GL_TEXTURE0 + kPLSTexIdxOffset + ATLAS_TEXTURE_IDX);
glBindTexture(GL_TEXTURE_2D, m_atlasTexture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, width, height);
glTexStorage2D(
GL_TEXTURE_2D,
1,
m_capabilities.EXT_float_blend
? GL_R32F // fp32 is ideal for the atlas. When there's a lot of
// overlap, fp16 can run out of precision.
: GL_R16F, // FIXME: Fallback for when EXT_color_buffer_half_float
// isn't supported.
width,
height);
glutils::SetTexture2DSamplingParams(GL_NEAREST, GL_NEAREST);

glBindFramebuffer(GL_FRAMEBUFFER, m_atlasFBO);
Expand Down Expand Up @@ -2105,6 +2114,12 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
// versions are reported as extensions.
if (capabilities.isGLES)
{
if (capabilities.isContextVersionAtLeast(3, 2))
{
// Floating point render targets became core in OpenGL ES 3.2.
capabilities.EXT_color_buffer_half_float = true;
capabilities.EXT_float_blend = true;
}
if (capabilities.isContextVersionAtLeast(3, 1))
{
capabilities.ARB_shader_storage_buffer_object = true;
Expand All @@ -2121,6 +2136,9 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
capabilities.ARB_shader_storage_buffer_object = true;
}
capabilities.EXT_clip_cull_distance = true;
// Floating point render targets became core in OpenGL 3.0.
capabilities.EXT_color_buffer_half_float = true;
capabilities.EXT_float_blend = true;
}

#ifndef RIVE_WEBGL
Expand Down Expand Up @@ -2204,6 +2222,14 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
{
capabilities.INTEL_fragment_shader_ordering = true;
}
else if (strcmp(ext, "GL_EXT_color_buffer_half_float") == 0)
{
capabilities.EXT_color_buffer_half_float = true;
}
else if (strcmp(ext, "GL_EXT_float_blend") == 0)
{
capabilities.EXT_float_blend = true;
}
else if (strcmp(ext, "GL_EXT_shader_framebuffer_fetch") == 0)
{
capabilities.EXT_shader_framebuffer_fetch = true;
Expand Down Expand Up @@ -2234,6 +2260,21 @@ std::unique_ptr<RenderContext> RenderContextGLImpl::MakeContext(
{
capabilities.EXT_clip_cull_distance = true;
}
if (emscripten_webgl_enable_extension(
emscripten_webgl_get_current_context(),
"EXT_color_buffer_half_float"))
{
capabilities.EXT_color_buffer_half_float = true;
}
if (emscripten_webgl_enable_extension(
emscripten_webgl_get_current_context(),
"EXT_color_buffer_float") &&
emscripten_webgl_enable_extension(
emscripten_webgl_get_current_context(),
"EXT_float_blend"))
{
capabilities.EXT_float_blend = true;
}
#endif // RIVE_WEBGL

#ifdef RIVE_DESKTOP_GL
Expand Down

0 comments on commit 66cabdf

Please sign in to comment.