imgui-bindings 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +8 -0
- data/README.md +7 -3
- data/lib/imgui.aarch64.so +0 -0
- data/lib/imgui.arm64.dylib +0 -0
- data/lib/imgui.dll +0 -0
- data/lib/imgui.rb +1494 -1237
- data/lib/imgui.x86_64.dylib +0 -0
- data/lib/imgui.x86_64.so +0 -0
- data/lib/imgui_impl_docking_opengl3.rb +33 -26
- data/lib/imgui_impl_docking_sdl3renderer.rb +107 -60
- data/lib/imgui_impl_opengl3.rb +33 -26
- data/lib/imgui_impl_raylib.rb +58 -53
- data/lib/imgui_impl_sdl3renderer.rb +128 -64
- metadata +2 -2
|
@@ -10,8 +10,23 @@ module ImGui
|
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
class ImGui_ImplSDLRenderer3_RenderState < FFI::Struct
|
|
14
|
+
layout(
|
|
15
|
+
:Renderer, :pointer
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
13
19
|
@@g_BackendRendererName = FFI::MemoryPointer.from_string('imgui_impl_sdlrenderer3')
|
|
14
20
|
@@g_BackendRendererUserData = {}
|
|
21
|
+
@@g_SDL3RendererResetRenderStateCallback = FFI::Function.new(:void, [:pointer, :pointer]) { |_draw_list, _draw_cmd| }
|
|
22
|
+
@@g_SDL3RendererSetSamplerLinearCallback = FFI::Function.new(:void, [:pointer, :pointer]) do |_draw_list, _draw_cmd|
|
|
23
|
+
backend_data = ImGui_ImplSDLRenderer3_GetBackendData()
|
|
24
|
+
backend_data[:current_scale_mode] = SDL::SCALEMODE_LINEAR if backend_data != nil
|
|
25
|
+
end
|
|
26
|
+
@@g_SDL3RendererSetSamplerNearestCallback = FFI::Function.new(:void, [:pointer, :pointer]) do |_draw_list, _draw_cmd|
|
|
27
|
+
backend_data = ImGui_ImplSDLRenderer3_GetBackendData()
|
|
28
|
+
backend_data[:current_scale_mode] = SDL::SCALEMODE_NEAREST if backend_data != nil
|
|
29
|
+
end
|
|
15
30
|
|
|
16
31
|
def self.ImGui_ImplSDLRenderer3_GetBackendData()
|
|
17
32
|
return nil if ImGui::GetCurrentContext() == nil
|
|
@@ -21,11 +36,14 @@ module ImGui
|
|
|
21
36
|
|
|
22
37
|
def self.ImplSDL3Renderer_Init(renderer)
|
|
23
38
|
io = ImGuiIO.new(ImGui::GetIO())
|
|
39
|
+
platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
|
|
24
40
|
|
|
25
41
|
backend_data = {
|
|
26
42
|
bd: ImGui_ImplSDLRenderer3_Data.new,
|
|
27
43
|
color_buffer: nil,
|
|
28
|
-
color_buffer_capacity: 0
|
|
44
|
+
color_buffer_capacity: 0,
|
|
45
|
+
render_state: nil,
|
|
46
|
+
current_scale_mode: SDL::SCALEMODE_LINEAR
|
|
29
47
|
}
|
|
30
48
|
backend_data[:bd][:Renderer] = renderer
|
|
31
49
|
|
|
@@ -36,6 +54,10 @@ module ImGui
|
|
|
36
54
|
io[:BackendFlags] |= ImGuiBackendFlags_RendererHasVtxOffset
|
|
37
55
|
io[:BackendFlags] |= ImGuiBackendFlags_RendererHasTextures
|
|
38
56
|
|
|
57
|
+
platform_io[:DrawCallback_ResetRenderState] = @@g_SDL3RendererResetRenderStateCallback
|
|
58
|
+
platform_io[:DrawCallback_SetSamplerLinear] = @@g_SDL3RendererSetSamplerLinearCallback
|
|
59
|
+
platform_io[:DrawCallback_SetSamplerNearest] = @@g_SDL3RendererSetSamplerNearestCallback
|
|
60
|
+
|
|
39
61
|
true
|
|
40
62
|
end
|
|
41
63
|
|
|
@@ -56,8 +78,17 @@ module ImGui
|
|
|
56
78
|
end
|
|
57
79
|
|
|
58
80
|
def self.ImplSDL3Renderer_SetupRenderState(renderer)
|
|
81
|
+
backend_data = ImGui_ImplSDLRenderer3_GetBackendData()
|
|
82
|
+
|
|
59
83
|
SDL.SetRenderViewport(renderer, nil)
|
|
60
84
|
SDL.SetRenderClipRect(renderer, nil)
|
|
85
|
+
backend_data[:current_scale_mode] = SDL::SCALEMODE_LINEAR if backend_data != nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.ImplSDL3Renderer_TextureIdToPointer(tex_id)
|
|
89
|
+
return nil if tex_id == nil || tex_id == 0
|
|
90
|
+
|
|
91
|
+
FFI::Pointer.new(tex_id)
|
|
61
92
|
end
|
|
62
93
|
|
|
63
94
|
def self.ImplSDL3Renderer_NewFrame()
|
|
@@ -111,7 +142,7 @@ module ImGui
|
|
|
111
142
|
tex.SetStatus(ImTextureStatus_OK)
|
|
112
143
|
|
|
113
144
|
when ImTextureStatus_WantUpdates
|
|
114
|
-
sdl_texture =
|
|
145
|
+
sdl_texture = ImplSDL3Renderer_TextureIdToPointer(tex.GetTexID())
|
|
115
146
|
return if sdl_texture == nil
|
|
116
147
|
|
|
117
148
|
updates = tex[:Updates]
|
|
@@ -127,10 +158,8 @@ module ImGui
|
|
|
127
158
|
tex.SetStatus(ImTextureStatus_OK)
|
|
128
159
|
|
|
129
160
|
when ImTextureStatus_WantDestroy
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
SDL.DestroyTexture(sdl_texture)
|
|
133
|
-
end
|
|
161
|
+
sdl_texture = ImplSDL3Renderer_TextureIdToPointer(tex.GetTexID())
|
|
162
|
+
SDL.DestroyTexture(sdl_texture) if sdl_texture != nil
|
|
134
163
|
tex.SetTexID(0)
|
|
135
164
|
tex.SetStatus(ImTextureStatus_Destroyed)
|
|
136
165
|
end
|
|
@@ -157,11 +186,15 @@ module ImGui
|
|
|
157
186
|
|
|
158
187
|
if draw_data[:Textures] != nil && draw_data[:Textures].address != 0
|
|
159
188
|
textures = ImVector_ImTextureDataPtr.new(draw_data[:Textures])
|
|
160
|
-
textures[:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
189
|
+
textures_data = textures[:Data]
|
|
190
|
+
if textures_data != nil && textures_data.address != 0
|
|
191
|
+
textures[:Size].times do |i|
|
|
192
|
+
tex_ptr = (textures_data + FFI.type_size(:pointer) * i).read_pointer
|
|
193
|
+
next if tex_ptr == nil || tex_ptr.address == 0
|
|
194
|
+
|
|
195
|
+
tex = ImTextureData.new(tex_ptr)
|
|
196
|
+
ImplSDL3Renderer_UpdateTexture(tex) if tex[:Status] != ImTextureStatus_OK
|
|
197
|
+
end
|
|
165
198
|
end
|
|
166
199
|
end
|
|
167
200
|
|
|
@@ -175,60 +208,87 @@ module ImGui
|
|
|
175
208
|
ImplSDL3Renderer_SetupRenderState(renderer)
|
|
176
209
|
|
|
177
210
|
platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
|
|
178
|
-
|
|
211
|
+
backend_data[:render_state] = ImGui_ImplSDLRenderer3_RenderState.new
|
|
212
|
+
backend_data[:render_state][:Renderer] = renderer
|
|
213
|
+
platform_io[:Renderer_RenderState] = backend_data[:render_state]
|
|
179
214
|
|
|
180
215
|
clip_off = draw_data[:DisplayPos]
|
|
181
216
|
clip_scale = render_scale
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
last_scale_mode = backend_data[:current_scale_mode]
|
|
218
|
+
|
|
219
|
+
cmd_lists = draw_data[:CmdLists]
|
|
220
|
+
cmd_lists_data = cmd_lists[:Data]
|
|
221
|
+
|
|
222
|
+
if cmd_lists_data != nil && cmd_lists_data.address != 0
|
|
223
|
+
cmd_lists[:Size].times do |n|
|
|
224
|
+
cmd_list_ptr = (cmd_lists_data + FFI.type_size(:pointer) * n).read_pointer
|
|
225
|
+
next if cmd_list_ptr == nil || cmd_list_ptr.address == 0
|
|
226
|
+
|
|
227
|
+
cmd_list = ImDrawList.new(cmd_list_ptr)
|
|
228
|
+
vtx_buffer = cmd_list[:VtxBuffer][:Data]
|
|
229
|
+
idx_buffer = cmd_list[:IdxBuffer][:Data]
|
|
230
|
+
|
|
231
|
+
cmd_list[:CmdBuffer][:Size].times do |cmd_i|
|
|
232
|
+
pcmd = ImDrawCmd.new(cmd_list[:CmdBuffer][:Data] + ImDrawCmd.size * cmd_i)
|
|
233
|
+
callback_ptr = pcmd[:UserCallback]
|
|
234
|
+
if callback_ptr != nil && callback_ptr.address != 0
|
|
235
|
+
callback_addr = callback_ptr.address
|
|
236
|
+
if callback_addr == @@g_SDL3RendererResetRenderStateCallback.address
|
|
237
|
+
ImplSDL3Renderer_SetupRenderState(renderer)
|
|
238
|
+
elsif callback_addr == @@g_SDL3RendererSetSamplerLinearCallback.address
|
|
239
|
+
backend_data[:current_scale_mode] = SDL::SCALEMODE_LINEAR
|
|
240
|
+
elsif callback_addr == @@g_SDL3RendererSetSamplerNearestCallback.address
|
|
241
|
+
backend_data[:current_scale_mode] = SDL::SCALEMODE_NEAREST
|
|
242
|
+
else
|
|
243
|
+
FFI::Function.new(:void, [:pointer, :pointer], callback_ptr).call(cmd_list.pointer, pcmd.pointer)
|
|
244
|
+
end
|
|
245
|
+
next
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
clip_min = ImVec2.create((pcmd[:ClipRect][:x] - clip_off[:x]) * clip_scale[:x], (pcmd[:ClipRect][:y] - clip_off[:y]) * clip_scale[:y])
|
|
249
|
+
clip_max = ImVec2.create((pcmd[:ClipRect][:z] - clip_off[:x]) * clip_scale[:x], (pcmd[:ClipRect][:w] - clip_off[:y]) * clip_scale[:y])
|
|
250
|
+
|
|
251
|
+
clip_min[:x] = 0.0 if clip_min[:x] < 0.0
|
|
252
|
+
clip_min[:y] = 0.0 if clip_min[:y] < 0.0
|
|
253
|
+
clip_max[:x] = fb_width.to_f if clip_max[:x] > fb_width
|
|
254
|
+
clip_max[:y] = fb_height.to_f if clip_max[:y] > fb_height
|
|
255
|
+
next if clip_max[:x] <= clip_min[:x] || clip_max[:y] <= clip_min[:y]
|
|
256
|
+
|
|
257
|
+
sdl_rect = SDL::Rect.new
|
|
258
|
+
sdl_rect[:x] = clip_min[:x].to_i
|
|
259
|
+
sdl_rect[:y] = clip_min[:y].to_i
|
|
260
|
+
sdl_rect[:w] = (clip_max[:x] - clip_min[:x]).to_i
|
|
261
|
+
sdl_rect[:h] = (clip_max[:y] - clip_min[:y]).to_i
|
|
262
|
+
SDL.SetRenderClipRect(renderer, sdl_rect)
|
|
263
|
+
|
|
264
|
+
vtx_base = pcmd[:VtxOffset] * ImDrawVert.size
|
|
265
|
+
xy = vtx_buffer + vtx_base + ImDrawVert.offset_of(:pos)
|
|
266
|
+
uv = vtx_buffer + vtx_base + ImDrawVert.offset_of(:uv)
|
|
267
|
+
color_src = vtx_buffer + vtx_base + ImDrawVert.offset_of(:col)
|
|
268
|
+
|
|
269
|
+
num_vertices = cmd_list[:VtxBuffer][:Size] - pcmd[:VtxOffset]
|
|
270
|
+
color_f = ImplSDL3Renderer_UpdateColorBuffer(backend_data, color_src, ImDrawVert.size, num_vertices)
|
|
271
|
+
|
|
272
|
+
tex_id = pcmd.GetTexID()
|
|
273
|
+
tex_ptr = ImplSDL3Renderer_TextureIdToPointer(tex_id)
|
|
274
|
+
if last_scale_mode != backend_data[:current_scale_mode]
|
|
275
|
+
SDL.FlushRenderer(renderer)
|
|
276
|
+
last_scale_mode = backend_data[:current_scale_mode]
|
|
277
|
+
end
|
|
278
|
+
SDL.SetTextureScaleMode(tex_ptr, backend_data[:current_scale_mode]) if tex_ptr != nil
|
|
279
|
+
|
|
280
|
+
SDL.RenderGeometryRaw(renderer, tex_ptr,
|
|
281
|
+
xy, ImDrawVert.size,
|
|
282
|
+
color_f, SDL::FColor.size,
|
|
283
|
+
uv, ImDrawVert.size,
|
|
284
|
+
num_vertices,
|
|
285
|
+
idx_buffer + FFI.type_size(:ImDrawIdx) * pcmd[:IdxOffset], pcmd[:ElemCount], FFI.type_size(:ImDrawIdx))
|
|
193
286
|
end
|
|
194
|
-
|
|
195
|
-
clip_min = ImVec2.create((pcmd[:ClipRect][:x] - clip_off[:x]) * clip_scale[:x], (pcmd[:ClipRect][:y] - clip_off[:y]) * clip_scale[:y])
|
|
196
|
-
clip_max = ImVec2.create((pcmd[:ClipRect][:z] - clip_off[:x]) * clip_scale[:x], (pcmd[:ClipRect][:w] - clip_off[:y]) * clip_scale[:y])
|
|
197
|
-
|
|
198
|
-
clip_min[:x] = 0.0 if clip_min[:x] < 0.0
|
|
199
|
-
clip_min[:y] = 0.0 if clip_min[:y] < 0.0
|
|
200
|
-
clip_max[:x] = fb_width.to_f if clip_max[:x] > fb_width
|
|
201
|
-
clip_max[:y] = fb_height.to_f if clip_max[:y] > fb_height
|
|
202
|
-
next if clip_max[:x] <= clip_min[:x] || clip_max[:y] <= clip_min[:y]
|
|
203
|
-
|
|
204
|
-
sdl_rect = SDL::Rect.new
|
|
205
|
-
sdl_rect[:x] = clip_min[:x].to_i
|
|
206
|
-
sdl_rect[:y] = clip_min[:y].to_i
|
|
207
|
-
sdl_rect[:w] = (clip_max[:x] - clip_min[:x]).to_i
|
|
208
|
-
sdl_rect[:h] = (clip_max[:y] - clip_min[:y]).to_i
|
|
209
|
-
SDL.SetRenderClipRect(renderer, sdl_rect)
|
|
210
|
-
|
|
211
|
-
vtx_base = pcmd[:VtxOffset] * ImDrawVert.size
|
|
212
|
-
xy = vtx_buffer + vtx_base + ImDrawVert.offset_of(:pos)
|
|
213
|
-
uv = vtx_buffer + vtx_base + ImDrawVert.offset_of(:uv)
|
|
214
|
-
color_src = vtx_buffer + vtx_base + ImDrawVert.offset_of(:col)
|
|
215
|
-
|
|
216
|
-
num_vertices = cmd_list[:VtxBuffer][:Size] - pcmd[:VtxOffset]
|
|
217
|
-
color_f = ImplSDL3Renderer_UpdateColorBuffer(backend_data, color_src, ImDrawVert.size, num_vertices)
|
|
218
|
-
|
|
219
|
-
tex_id = pcmd.GetTexID()
|
|
220
|
-
tex_ptr = tex_id == 0 ? nil : FFI::Pointer.new(tex_id)
|
|
221
|
-
|
|
222
|
-
SDL.RenderGeometryRaw(renderer, tex_ptr,
|
|
223
|
-
xy, ImDrawVert.size,
|
|
224
|
-
color_f, SDL::FColor.size,
|
|
225
|
-
uv, ImDrawVert.size,
|
|
226
|
-
num_vertices,
|
|
227
|
-
idx_buffer + FFI.type_size(:ImDrawIdx) * pcmd[:IdxOffset], pcmd[:ElemCount], FFI.type_size(:ImDrawIdx))
|
|
228
287
|
end
|
|
229
288
|
end
|
|
230
289
|
|
|
231
290
|
platform_io[:Renderer_RenderState] = nil
|
|
291
|
+
backend_data[:render_state] = nil
|
|
232
292
|
|
|
233
293
|
SDL.SetRenderViewport(renderer, old_viewport_enabled ? old_viewport : nil)
|
|
234
294
|
SDL.SetRenderClipRect(renderer, old_clip_enabled ? old_clip_rect : nil)
|
|
@@ -240,13 +300,17 @@ module ImGui
|
|
|
240
300
|
def self.ImplSDL3Renderer_DestroyDeviceObjects()
|
|
241
301
|
platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
|
|
242
302
|
textures = platform_io[:Textures]
|
|
243
|
-
textures[:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
303
|
+
textures_data = textures[:Data]
|
|
304
|
+
if textures_data != nil && textures_data.address != 0
|
|
305
|
+
textures[:Size].times do |i|
|
|
306
|
+
tex_ptr = (textures_data + FFI.type_size(:pointer) * i).read_pointer
|
|
307
|
+
next if tex_ptr == nil || tex_ptr.address == 0
|
|
308
|
+
|
|
309
|
+
tex = ImTextureData.new(tex_ptr)
|
|
310
|
+
if tex[:RefCount] == 1
|
|
311
|
+
tex.SetStatus(ImTextureStatus_WantDestroy)
|
|
312
|
+
ImplSDL3Renderer_UpdateTexture(tex)
|
|
313
|
+
end
|
|
250
314
|
end
|
|
251
315
|
end
|
|
252
316
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imgui-bindings
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- vaiorabbit
|
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
98
|
- !ruby/object:Gem::Version
|
|
99
99
|
version: '0'
|
|
100
100
|
requirements: []
|
|
101
|
-
rubygems_version: 4.0.
|
|
101
|
+
rubygems_version: 4.0.16
|
|
102
102
|
specification_version: 4
|
|
103
103
|
summary: Bindings for Dear ImGui
|
|
104
104
|
test_files: []
|