@@ -29,18 +29,70 @@ public ImGuiSDL3Renderer(nint renderer)
2929
3030 ImGuiIOPtr io = ImGui . GetIO ( ) ;
3131 io . BackendFlags |= ImGuiBackendFlags . RendererHasVtxOffset ;
32+ io . BackendFlags |= ImGuiBackendFlags . RendererHasTextures ;
33+
34+ // Mark that we support the new texture system
35+ io . Fonts . RendererHasTextures = true ;
3236 }
3337
3438 public void Dispose ( )
3539 {
3640 DestroyDeviceObjects ( ) ;
3741 }
3842
39- public void NewFrame ( )
43+ public unsafe void NewFrame ( )
4044 {
41- if ( _fontTexture == IntPtr . Zero )
45+ // Handle texture updates for the new ImGui 1.92+ texture system
46+ ImGuiIOPtr io = ImGui . GetIO ( ) ;
47+ var texList = io . Fonts . TexList ;
48+
49+ for ( int i = 0 ; i < texList . Size ; i ++ )
4250 {
43- CreateDeviceObjects ( ) ;
51+ var texData = texList [ i ] ;
52+ var status = texData . Status ;
53+
54+ if ( status == ImTextureStatus . WantCreate || status == ImTextureStatus . WantUpdates )
55+ {
56+ // Create or update the texture
57+ int width = texData . Width ;
58+ int height = texData . Height ;
59+ byte * pixels = ( byte * ) texData . Pixels ;
60+
61+ if ( width > 0 && height > 0 && pixels != null )
62+ {
63+ // Create SDL texture
64+ var surface = SDL . CreateSurfaceFrom ( width , height , SDL . PixelFormat . RGBA8888 , ( IntPtr ) pixels , width * 4 ) ;
65+ if ( surface != IntPtr . Zero )
66+ {
67+ var texture = SDL . CreateTextureFromSurface ( Renderer , surface ) ;
68+ if ( texture != IntPtr . Zero )
69+ {
70+ SDL . UpdateTexture ( texture , IntPtr . Zero , ( IntPtr ) pixels , width * 4 ) ;
71+ SDL . SetTextureBlendMode ( texture , SDL . BlendMode . Blend ) ;
72+ SDL . SetTextureScaleMode ( texture , SDL . ScaleMode . Nearest ) ;
73+
74+ // Store the texture ID
75+ texData . SetTexID ( texture ) ;
76+ texData . SetStatus ( ImTextureStatus . OK ) ;
77+
78+ // Track font texture for cleanup
79+ if ( i == 0 )
80+ _fontTexture = texture ;
81+ }
82+ SDL . DestroySurface ( surface ) ;
83+ }
84+ }
85+ }
86+ else if ( status == ImTextureStatus . WantDestroy )
87+ {
88+ var texId = texData . TexID ;
89+ if ( texId != IntPtr . Zero )
90+ {
91+ SDL . DestroyTexture ( texId ) ;
92+ texData . SetTexID ( IntPtr . Zero ) ;
93+ }
94+ texData . SetStatus ( ImTextureStatus . Destroyed ) ;
95+ }
4496 }
4597 }
4698
@@ -245,57 +297,10 @@ private void DestroyDeviceObjects()
245297 DestroyFontsTexture ( ) ;
246298 }
247299
248- public unsafe IntPtr CreateFontsTexture ( ImFontPtr font )
249- {
250- ImGuiIOPtr io = ImGui . GetIO ( ) ;
251-
252- // Build texture atlas
253- io . Fonts . GetTexDataAsRGBA32 ( out byte * pixels , out int width , out int height ) ;
254-
255- // Create surface from pixel data
256- var surface = SDL . CreateSurfaceFrom ( width , height , SDL . PixelFormat . RGBA8888 , ( IntPtr ) pixels , width * 4 ) ;
257- if ( surface == IntPtr . Zero )
258- {
259- SDL . LogError ( SDL . LogCategory . Application , $ "Failed to create font surface: { SDL . GetError ( ) } ") ;
260- return IntPtr . Zero ;
261- }
262-
263- // Create texture
264- var fontTexture = SDL . CreateTextureFromSurface ( Renderer , surface ) ;
265- if ( fontTexture == IntPtr . Zero )
266- {
267- SDL . LogError ( SDL . LogCategory . Application , $ "Failed to create font texture: { SDL . GetError ( ) } ") ;
268- return IntPtr . Zero ;
269- }
270-
271- // Update texture directly without converting pixel format
272- if ( ! SDL . UpdateTexture ( fontTexture , IntPtr . Zero , ( IntPtr ) pixels , width * 4 ) )
273- {
274- SDL . LogError ( SDL . LogCategory . Application , $ "Failed to update font texture: { SDL . GetError ( ) } ") ;
275- return IntPtr . Zero ;
276- }
277-
278- // Ensure proper blending for font rendering
279- SDL . SetTextureBlendMode ( fontTexture , SDL . BlendMode . Blend ) ;
280-
281- // Use nearest neighbor filtering for crisp font rendering at small sizes
282- SDL . SetTextureScaleMode ( fontTexture , SDL . ScaleMode . Nearest ) ;
283-
284- // Store our identifier
285- io . Fonts . SetTexID ( fontTexture ) ;
286-
287- SDL . DestroySurface ( surface ) ;
288- io . Fonts . ClearTexData ( ) ;
289-
290- return fontTexture ;
291- }
292-
293300 private void DestroyFontsTexture ( )
294301 {
295- ImGuiIOPtr io = ImGui . GetIO ( ) ;
296302 if ( _fontTexture != IntPtr . Zero )
297303 {
298- io . Fonts . SetTexID ( IntPtr . Zero ) ;
299304 SDL . DestroyTexture ( _fontTexture ) ;
300305 _fontTexture = IntPtr . Zero ;
301306 }
0 commit comments