@@ -717,6 +717,27 @@ static void DestroyFramebuffer(FramebufferData& fb)
717
717
fb = {};
718
718
}
719
719
720
+ static GLuint CreateTexture (Rml::Span<const Rml::byte> source_data, Rml::Vector2i source_dimensions)
721
+ {
722
+ GLuint texture_id = 0 ;
723
+ glGenTextures (1 , &texture_id);
724
+ if (texture_id == 0 )
725
+ return 0 ;
726
+
727
+ glBindTexture (GL_TEXTURE_2D, texture_id);
728
+
729
+ glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA8, source_dimensions.x , source_dimensions.y , 0 , GL_RGBA, GL_UNSIGNED_BYTE, source_data.data ());
730
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
731
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
732
+
733
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
734
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
735
+
736
+ glBindTexture (GL_TEXTURE_2D, 0 );
737
+
738
+ return texture_id;
739
+ }
740
+
720
741
static void BindTexture (const FramebufferData& fb)
721
742
{
722
743
if (!fb.color_tex_buffer )
@@ -1277,25 +1298,12 @@ Rml::TextureHandle RenderInterface_GL3::GenerateTexture(Rml::Span<const Rml::byt
1277
1298
{
1278
1299
RMLUI_ASSERT (source_data.data () && source_data.size () == size_t (source_dimensions.x * source_dimensions.y * 4 ));
1279
1300
1280
- GLuint texture_id = 0 ;
1281
- glGenTextures (1 , &texture_id);
1301
+ GLuint texture_id = Gfx::CreateTexture (source_data, source_dimensions);
1282
1302
if (texture_id == 0 )
1283
1303
{
1284
1304
Rml::Log::Message (Rml::Log::LT_ERROR, " Failed to generate texture." );
1285
- return false ;
1305
+ return {} ;
1286
1306
}
1287
-
1288
- glBindTexture (GL_TEXTURE_2D, texture_id);
1289
-
1290
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA8, source_dimensions.x , source_dimensions.y , 0 , GL_RGBA, GL_UNSIGNED_BYTE, source_data.data ());
1291
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1292
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1293
-
1294
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1295
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1296
-
1297
- glBindTexture (GL_TEXTURE_2D, 0 );
1298
-
1299
1307
return (Rml::TextureHandle)texture_id;
1300
1308
}
1301
1309
@@ -1956,9 +1964,12 @@ Rml::TextureHandle RenderInterface_GL3::SaveLayerAsTexture()
1956
1964
RMLUI_ASSERT (scissor_state.Valid ());
1957
1965
const Rml::Rectanglei bounds = scissor_state;
1958
1966
1959
- Rml::TextureHandle render_texture = GenerateTexture ({}, bounds.Size ());
1960
- if (!render_texture)
1967
+ GLuint render_texture = Gfx::CreateTexture ({}, bounds.Size ());
1968
+ if (render_texture == 0 )
1969
+ {
1970
+ Rml::Log::Message (Rml::Log::LT_ERROR, " Failed to create render texture." );
1961
1971
return {};
1972
+ }
1962
1973
1963
1974
BlitLayerToPostprocessPrimary (render_layers.GetTopLayerHandle ());
1964
1975
@@ -1978,7 +1989,7 @@ Rml::TextureHandle RenderInterface_GL3::SaveLayerAsTexture()
1978
1989
GL_COLOR_BUFFER_BIT, GL_NEAREST //
1979
1990
);
1980
1991
1981
- glBindTexture (GL_TEXTURE_2D, (GLuint) render_texture);
1992
+ glBindTexture (GL_TEXTURE_2D, render_texture);
1982
1993
1983
1994
const Gfx::FramebufferData& texture_source = destination;
1984
1995
glBindFramebuffer (GL_READ_FRAMEBUFFER, texture_source.framebuffer );
@@ -1988,7 +1999,7 @@ Rml::TextureHandle RenderInterface_GL3::SaveLayerAsTexture()
1988
1999
glBindFramebuffer (GL_FRAMEBUFFER, render_layers.GetTopLayer ().framebuffer );
1989
2000
Gfx::CheckGLError (" SaveLayerAsTexture" );
1990
2001
1991
- return render_texture;
2002
+ return (Rml::TextureHandle) render_texture;
1992
2003
}
1993
2004
1994
2005
Rml::CompiledFilterHandle RenderInterface_GL3::SaveLayerAsMaskImage ()
0 commit comments