imgui-bindings 0.1.17 → 1.0.0

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.
Binary file
data/lib/imgui.x86_64.so CHANGED
Binary file
@@ -0,0 +1,638 @@
1
+ require 'ffi'
2
+ require 'opengl'
3
+ require 'fiddle'
4
+
5
+ require_relative 'imgui'
6
+
7
+ module ImGui
8
+
9
+ @@g_DockingGL3GlVersion = 0
10
+ @@g_DockingGL3MaxTextureSize = 0
11
+ @@g_DockingGL3GlslVersionString = ""
12
+
13
+ @@g_DockingGL3ShaderHandle = 0
14
+
15
+ @@g_DockingGL3AttribLocationTex = 0
16
+ @@g_DockingGL3AttribLocationProjMtx = 0
17
+
18
+ @@g_DockingGL3AttribLocationVtxPos = 0
19
+ @@g_DockingGL3AttribLocationVtxUV = 0
20
+ @@g_DockingGL3AttribLocationVtxColor = 0
21
+
22
+ @@g_DockingGL3VboHandle = 0
23
+ @@g_DockingGL3ElementsHandle = 0
24
+
25
+ @@g_DockingGL3BackendRendererName = FFI::MemoryPointer.from_string("imgui_impl_docking_opengl3")
26
+ @@g_DockingGL3RendererCallbacks = nil
27
+
28
+ def self.ImplDockingOpenGL3_PrintShaderCompileStatus(handle)
29
+ rvalue = ' ' * 4
30
+ GL.GetShaderiv(handle, GL::COMPILE_STATUS, rvalue)
31
+ ok = rvalue.unpack1('L')
32
+ return true if ok == GL::TRUE
33
+
34
+ $stderr.puts "Error in compiling shader"
35
+ log_length = ' ' * 4
36
+ GL.GetShaderiv(handle, GL::INFO_LOG_LENGTH, log_length)
37
+ log_length = log_length.unpack1('L')
38
+ if log_length > 0
39
+ buf = ' ' * log_length
40
+ GL.GetShaderInfoLog(handle, log_length, nil, buf)
41
+ $stderr.puts(buf)
42
+ end
43
+ false
44
+ end
45
+
46
+ def self.ImplDockingOpenGL3_PrintProgramLinkStatus(handle)
47
+ rvalue = ' ' * 4
48
+ GL.GetProgramiv(handle, GL::LINK_STATUS, rvalue)
49
+ ok = rvalue.unpack1('L')
50
+ return true if ok == GL::TRUE
51
+
52
+ $stderr.puts "Error in linking program"
53
+ log_length = ' ' * 4
54
+ GL.GetProgramiv(handle, GL::INFO_LOG_LENGTH, log_length)
55
+ log_length = log_length.unpack1('L')
56
+ if log_length > 0
57
+ buf = ' ' * log_length
58
+ GL.GetProgramInfoLog(handle, log_length, nil, buf)
59
+ $stderr.puts(buf)
60
+ end
61
+ false
62
+ end
63
+
64
+ def self.ImplDockingOpenGL3_Init(glsl_version = nil)
65
+ major, minor = ' ' * 4, ' ' * 4
66
+ GL.GetIntegerv(GL::MAJOR_VERSION, major)
67
+ GL.GetIntegerv(GL::MINOR_VERSION, minor)
68
+ major = major.unpack1('L')
69
+ minor = minor.unpack1('L')
70
+
71
+ # OpenGL 2.x fallback when GL_MAJOR_VERSION/GL_MINOR_VERSION are unavailable.
72
+ if major == 0 && minor == 0 && GL.respond_to?(:GetString)
73
+ version_string = GL.GetString(GL::VERSION).to_s
74
+ parts = version_string.split(/[ .]/)
75
+ major = parts[0].to_i
76
+ minor = parts[1].to_i
77
+ end
78
+
79
+ @@g_DockingGL3GlVersion = major * 100 + minor * 10
80
+
81
+ max_texture_size = ' ' * 4
82
+ GL.GetIntegerv(GL::MAX_TEXTURE_SIZE, max_texture_size)
83
+ @@g_DockingGL3MaxTextureSize = max_texture_size.unpack1('L')
84
+
85
+ io = ImGuiIO.new(ImGui::GetIO())
86
+ io[:BackendRendererName] = @@g_DockingGL3BackendRendererName
87
+ io[:BackendFlags] |= ImGuiBackendFlags_RendererHasVtxOffset if @@g_DockingGL3GlVersion >= 320
88
+ io[:BackendFlags] |= ImGuiBackendFlags_RendererHasTextures
89
+ io[:BackendFlags] |= ImGuiBackendFlags_RendererHasViewports
90
+
91
+ platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
92
+ platform_io[:Renderer_TextureMaxWidth] = @@g_DockingGL3MaxTextureSize
93
+ platform_io[:Renderer_TextureMaxHeight] = @@g_DockingGL3MaxTextureSize
94
+
95
+ if glsl_version.nil?
96
+ if GL.get_platform() == :OPENGL_PLATFORM_MACOSX
97
+ glsl_version = '#version 150'
98
+ else
99
+ glsl_version = '#version 130'
100
+ end
101
+ end
102
+
103
+ @@g_DockingGL3GlslVersionString = glsl_version.end_with?("\n") ? glsl_version.dup : "#{glsl_version}\n"
104
+
105
+ ImplDockingOpenGL3_InitMultiViewportSupport()
106
+
107
+ true
108
+ end
109
+
110
+ def self.ImplDockingOpenGL3_Shutdown()
111
+ ImplDockingOpenGL3_DestroyDeviceObjects()
112
+
113
+ io = ImGuiIO.new(ImGui::GetIO())
114
+ io[:BackendRendererName] = nil
115
+ io[:BackendFlags] &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures)
116
+
117
+ begin
118
+ platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
119
+ platform_io.ClearRendererHandlers()
120
+ rescue StandardError
121
+ # Older generated bindings may not expose all platform IO helpers.
122
+ end
123
+ end
124
+
125
+ def self.ImplDockingOpenGL3_NewFrame()
126
+ ImplDockingOpenGL3_CreateDeviceObjects() if @@g_DockingGL3ShaderHandle == 0
127
+ end
128
+
129
+ def self.ImplDockingOpenGL3_RenderDrawData(draw_data_raw)
130
+ draw_data = ImDrawData.new(draw_data_raw)
131
+
132
+ # Avoid rendering when minimized, scale coordinates for retina displays.
133
+ fb_width = (draw_data[:DisplaySize][:x] * draw_data[:FramebufferScale][:x]).to_i
134
+ fb_height = (draw_data[:DisplaySize][:y] * draw_data[:FramebufferScale][:y]).to_i
135
+ return if fb_width <= 0 || fb_height <= 0
136
+
137
+ ImplDockingOpenGL3_ProcessTextureUpdates(draw_data)
138
+
139
+ last_active_texture = ' ' * 4; GL.GetIntegerv(GL::ACTIVE_TEXTURE, last_active_texture)
140
+ GL.ActiveTexture(GL::TEXTURE0)
141
+
142
+ last_program = ' ' * 4; GL.GetIntegerv(GL::CURRENT_PROGRAM, last_program)
143
+ last_texture = ' ' * 4; GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
144
+
145
+ has_sampler = defined?(GL::SAMPLER_BINDING)
146
+ last_sampler = ' ' * 4
147
+ GL.GetIntegerv(GL::SAMPLER_BINDING, last_sampler) if has_sampler
148
+
149
+ last_array_buffer = ' ' * 4; GL.GetIntegerv(GL::ARRAY_BUFFER_BINDING, last_array_buffer)
150
+ last_vertex_array_object = ' ' * 4; GL.GetIntegerv(GL::VERTEX_ARRAY_BINDING, last_vertex_array_object)
151
+
152
+ last_polygon_mode = ' ' * 8; GL.GetIntegerv(GL::POLYGON_MODE, last_polygon_mode)
153
+ last_viewport = ' ' * 16; GL.GetIntegerv(GL::VIEWPORT, last_viewport)
154
+ last_scissor_box = ' ' * 16; GL.GetIntegerv(GL::SCISSOR_BOX, last_scissor_box)
155
+
156
+ last_blend_src_rgb = ' ' * 4; GL.GetIntegerv(GL::BLEND_SRC_RGB, last_blend_src_rgb)
157
+ last_blend_dst_rgb = ' ' * 4; GL.GetIntegerv(GL::BLEND_DST_RGB, last_blend_dst_rgb)
158
+ last_blend_src_alpha = ' ' * 4; GL.GetIntegerv(GL::BLEND_SRC_ALPHA, last_blend_src_alpha)
159
+ last_blend_dst_alpha = ' ' * 4; GL.GetIntegerv(GL::BLEND_DST_ALPHA, last_blend_dst_alpha)
160
+ last_blend_equation_rgb = ' ' * 4; GL.GetIntegerv(GL::BLEND_EQUATION_RGB, last_blend_equation_rgb)
161
+ last_blend_equation_alpha = ' ' * 4; GL.GetIntegerv(GL::BLEND_EQUATION_ALPHA, last_blend_equation_alpha)
162
+
163
+ last_enable_blend = GL.IsEnabled(GL::BLEND)
164
+ last_enable_cull_face = GL.IsEnabled(GL::CULL_FACE)
165
+ last_enable_depth_test = GL.IsEnabled(GL::DEPTH_TEST)
166
+ last_enable_stencil_test = GL.IsEnabled(GL::STENCIL_TEST)
167
+ last_enable_scissor_test = GL.IsEnabled(GL::SCISSOR_TEST)
168
+
169
+ # Recreate VAO every frame so this works across multiple GL contexts.
170
+ vao_mem = ' ' * 4
171
+ GL.GenVertexArrays(1, vao_mem)
172
+ vertex_array_object = vao_mem.unpack1('L')
173
+ ImplDockingOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object)
174
+
175
+ clip_off = draw_data[:DisplayPos]
176
+ clip_scale = draw_data[:FramebufferScale]
177
+
178
+ cmd_list_data = draw_data[:CmdLists][:Data]
179
+ pointer_stride = FFI::Pointer.size
180
+
181
+ draw_data[:CmdListsCount].times do |n|
182
+ cmd_list_ptr = (cmd_list_data + pointer_stride * n).read_pointer
183
+ cmd_list = ImDrawList.new(cmd_list_ptr)
184
+
185
+ vtx_size = cmd_list[:VtxBuffer][:Size] * ImDrawVert.size
186
+ idx_size = cmd_list[:IdxBuffer][:Size] * 2 # ImDrawIdx is currently ushort in generated bindings.
187
+
188
+ GL.BufferData(GL::ARRAY_BUFFER, vtx_size, Fiddle::Pointer.new(cmd_list[:VtxBuffer][:Data]), GL::STREAM_DRAW)
189
+ GL.BufferData(GL::ELEMENT_ARRAY_BUFFER, idx_size, Fiddle::Pointer.new(cmd_list[:IdxBuffer][:Data]), GL::STREAM_DRAW)
190
+
191
+ cmd_list[:CmdBuffer][:Size].times do |cmd_i|
192
+ pcmd = ImDrawCmd.new(cmd_list[:CmdBuffer][:Data] + ImDrawCmd.size * cmd_i)
193
+ if pcmd[:UserCallback] != nil
194
+ # Reset callback token is not exposed cleanly in current bindings, so keep old behavior.
195
+ ImplDockingOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object)
196
+ next
197
+ end
198
+
199
+ clip_min_x = (pcmd[:ClipRect][:x] - clip_off[:x]) * clip_scale[:x]
200
+ clip_min_y = (pcmd[:ClipRect][:y] - clip_off[:y]) * clip_scale[:y]
201
+ clip_max_x = (pcmd[:ClipRect][:z] - clip_off[:x]) * clip_scale[:x]
202
+ clip_max_y = (pcmd[:ClipRect][:w] - clip_off[:y]) * clip_scale[:y]
203
+
204
+ next if clip_max_x <= clip_min_x || clip_max_y <= clip_min_y
205
+
206
+ GL.Scissor(clip_min_x.to_i, (fb_height - clip_max_y).to_i, (clip_max_x - clip_min_x).to_i, (clip_max_y - clip_min_y).to_i)
207
+
208
+ GL.BindTexture(GL::TEXTURE_2D, pcmd.GetTexID())
209
+ if @@g_DockingGL3GlVersion >= 320
210
+ GL.DrawElementsBaseVertex(GL::TRIANGLES, pcmd[:ElemCount], GL::UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * 2), pcmd[:VtxOffset])
211
+ else
212
+ GL.DrawElements(GL::TRIANGLES, pcmd[:ElemCount], GL::UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * 2))
213
+ end
214
+ end
215
+ end
216
+
217
+ GL.DeleteVertexArrays(1, [vertex_array_object].pack('L'))
218
+
219
+ GL.UseProgram(last_program.unpack1('L'))
220
+ GL.BindTexture(GL::TEXTURE_2D, last_texture.unpack1('L'))
221
+ GL.BindSampler(0, last_sampler.unpack1('L')) if has_sampler
222
+ GL.ActiveTexture(last_active_texture.unpack1('L'))
223
+ GL.BindVertexArray(last_vertex_array_object.unpack1('L'))
224
+ GL.BindBuffer(GL::ARRAY_BUFFER, last_array_buffer.unpack1('L'))
225
+
226
+ GL.BlendEquationSeparate(last_blend_equation_rgb.unpack1('L'), last_blend_equation_alpha.unpack1('L'))
227
+ GL.BlendFuncSeparate(
228
+ last_blend_src_rgb.unpack1('L'),
229
+ last_blend_dst_rgb.unpack1('L'),
230
+ last_blend_src_alpha.unpack1('L'),
231
+ last_blend_dst_alpha.unpack1('L')
232
+ )
233
+
234
+ if last_enable_blend then GL.Enable(GL::BLEND) else GL.Disable(GL::BLEND) end
235
+ if last_enable_cull_face then GL.Enable(GL::CULL_FACE) else GL.Disable(GL::CULL_FACE) end
236
+ if last_enable_depth_test then GL.Enable(GL::DEPTH_TEST) else GL.Disable(GL::DEPTH_TEST) end
237
+ if last_enable_stencil_test then GL.Enable(GL::STENCIL_TEST) else GL.Disable(GL::STENCIL_TEST) end
238
+ if last_enable_scissor_test then GL.Enable(GL::SCISSOR_TEST) else GL.Disable(GL::SCISSOR_TEST) end
239
+
240
+ last_polygon_mode = last_polygon_mode.unpack('L2')
241
+ GL.PolygonMode(GL::FRONT_AND_BACK, last_polygon_mode[0])
242
+
243
+ last_viewport = last_viewport.unpack('L4')
244
+ GL.Viewport(last_viewport[0], last_viewport[1], last_viewport[2], last_viewport[3])
245
+
246
+ last_scissor_box = last_scissor_box.unpack('L4')
247
+ GL.Scissor(last_scissor_box[0], last_scissor_box[1], last_scissor_box[2], last_scissor_box[3])
248
+ end
249
+
250
+ def self.ImplDockingOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object)
251
+ GL.Enable(GL::BLEND)
252
+ GL.BlendEquation(GL::FUNC_ADD)
253
+ GL.BlendFuncSeparate(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA, GL::ONE, GL::ONE_MINUS_SRC_ALPHA)
254
+ GL.Disable(GL::CULL_FACE)
255
+ GL.Disable(GL::DEPTH_TEST)
256
+ GL.Disable(GL::STENCIL_TEST)
257
+ GL.Enable(GL::SCISSOR_TEST)
258
+ GL.PolygonMode(GL::FRONT_AND_BACK, GL::FILL)
259
+
260
+ GL.Viewport(0, 0, fb_width, fb_height)
261
+ l = draw_data[:DisplayPos][:x]
262
+ r = draw_data[:DisplayPos][:x] + draw_data[:DisplaySize][:x]
263
+ t = draw_data[:DisplayPos][:y]
264
+ b = draw_data[:DisplayPos][:y] + draw_data[:DisplaySize][:y]
265
+
266
+ ortho_projection = [
267
+ 2.0 / (r - l), 0.0, 0.0, 0.0,
268
+ 0.0, 2.0 / (t - b), 0.0, 0.0,
269
+ 0.0, 0.0, -1.0, 0.0,
270
+ (r + l) / (l - r), (t + b) / (b - t), 0.0, 1.0,
271
+ ]
272
+
273
+ GL.UseProgram(@@g_DockingGL3ShaderHandle)
274
+ GL.Uniform1i(@@g_DockingGL3AttribLocationTex, 0)
275
+ GL.UniformMatrix4fv(@@g_DockingGL3AttribLocationProjMtx, 1, GL::FALSE, ortho_projection.pack('F16'))
276
+
277
+ if defined?(GL::SAMPLER_BINDING)
278
+ GL.BindSampler(0, 0)
279
+ end
280
+
281
+ GL.BindVertexArray(vertex_array_object)
282
+ GL.BindBuffer(GL::ARRAY_BUFFER, @@g_DockingGL3VboHandle)
283
+ GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @@g_DockingGL3ElementsHandle)
284
+
285
+ GL.EnableVertexAttribArray(@@g_DockingGL3AttribLocationVtxPos)
286
+ GL.EnableVertexAttribArray(@@g_DockingGL3AttribLocationVtxUV)
287
+ GL.EnableVertexAttribArray(@@g_DockingGL3AttribLocationVtxColor)
288
+
289
+ GL.VertexAttribPointer(@@g_DockingGL3AttribLocationVtxPos, 2, GL::FLOAT, GL::FALSE, ImDrawVert.size, ImDrawVert.offset_of(:pos))
290
+ GL.VertexAttribPointer(@@g_DockingGL3AttribLocationVtxUV, 2, GL::FLOAT, GL::FALSE, ImDrawVert.size, ImDrawVert.offset_of(:uv))
291
+ GL.VertexAttribPointer(@@g_DockingGL3AttribLocationVtxColor, 4, GL::UNSIGNED_BYTE, GL::TRUE, ImDrawVert.size, ImDrawVert.offset_of(:col))
292
+ end
293
+
294
+ # Compatibility wrapper retained for older caller code.
295
+ def self.ImplDockingOpenGL3_CreateFontsTexture()
296
+ true
297
+ end
298
+
299
+ # Compatibility wrapper retained for older caller code.
300
+ def self.ImplDockingOpenGL3_DestroyFontsTexture()
301
+ nil
302
+ end
303
+
304
+ def self.ImGui_ImplDockingOpenGL3_RenderWindow(viewport_raw, _render_arg)
305
+ viewport = viewport_raw.kind_of?(ImGuiViewport) ? viewport_raw : ImGuiViewport.new(viewport_raw)
306
+ return if viewport[:DrawData] == nil || viewport[:DrawData].address == 0
307
+
308
+ if (viewport[:Flags] & ImGuiViewportFlags_NoRendererClear) == 0
309
+ GL.ClearColor(0.0, 0.0, 0.0, 1.0)
310
+ GL.Clear(GL::COLOR_BUFFER_BIT)
311
+ end
312
+
313
+ ImplDockingOpenGL3_RenderDrawData(viewport[:DrawData])
314
+ end
315
+
316
+ def self.ImplDockingOpenGL3_InitMultiViewportSupport()
317
+ if @@g_DockingGL3RendererCallbacks == nil
318
+ @@g_DockingGL3RendererCallbacks = {
319
+ render_window: FFI::Function.new(:void, [:pointer, :pointer]) { |viewport, arg| ImGui_ImplDockingOpenGL3_RenderWindow(viewport, arg) }
320
+ }
321
+ end
322
+
323
+ platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
324
+ platform_io[:Renderer_RenderWindow] = @@g_DockingGL3RendererCallbacks[:render_window]
325
+ end
326
+
327
+ def self.ImplDockingOpenGL3_ProcessTextureUpdates(draw_data)
328
+ textures_ptr = draw_data[:Textures]
329
+ return if textures_ptr.nil? || textures_ptr.null?
330
+
331
+ textures = ImVector.new(textures_ptr)
332
+ data_ptr = textures[:Data]
333
+ pointer_stride = FFI::Pointer.size
334
+
335
+ textures[:Size].times do |i|
336
+ tex_ptr = (data_ptr + pointer_stride * i).read_pointer
337
+ next if tex_ptr.nil? || tex_ptr.null?
338
+
339
+ tex = ImTextureData.new(tex_ptr)
340
+ ImplDockingOpenGL3_UpdateTexture(tex) if tex[:Status] != ImTextureStatus_OK
341
+ end
342
+ end
343
+
344
+ def self.ImplDockingOpenGL3_DestroyTexture(tex)
345
+ gl_tex_id = tex.GetTexID()
346
+ if gl_tex_id != 0
347
+ GL.DeleteTextures(1, [gl_tex_id].pack('L'))
348
+ end
349
+
350
+ tex.SetTexID(0)
351
+ tex.SetStatus(ImTextureStatus_Destroyed)
352
+ end
353
+
354
+ def self.ImplDockingOpenGL3_AsGLPointer(pointer)
355
+ return nil if pointer.nil? || pointer.null?
356
+
357
+ Fiddle::Pointer.new(pointer.to_i)
358
+ end
359
+
360
+ def self.ImplDockingOpenGL3_UpdateTexture(tex)
361
+ status = tex[:Status]
362
+
363
+ if status == ImTextureStatus_WantCreate || status == ImTextureStatus_WantUpdates
364
+ GL.PixelStorei(GL::UNPACK_ROW_LENGTH, 0) if defined?(GL::UNPACK_ROW_LENGTH)
365
+ GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1) if defined?(GL::UNPACK_ALIGNMENT)
366
+ end
367
+
368
+ if status == ImTextureStatus_WantCreate
369
+ return unless tex[:Format] == ImTextureFormat_RGBA32
370
+
371
+ last_texture = ' ' * 4
372
+ GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
373
+
374
+ texture_mem = ' ' * 4
375
+ GL.GenTextures(1, texture_mem)
376
+ gl_texture_id = texture_mem.unpack1('L')
377
+
378
+ GL.BindTexture(GL::TEXTURE_2D, gl_texture_id)
379
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR)
380
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR)
381
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::CLAMP_TO_EDGE)
382
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::CLAMP_TO_EDGE)
383
+
384
+ pixels_ptr = ImplDockingOpenGL3_AsGLPointer(tex[:Pixels])
385
+ GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, tex[:Width], tex[:Height], 0, GL::RGBA, GL::UNSIGNED_BYTE, pixels_ptr)
386
+
387
+ tex.SetTexID(gl_texture_id)
388
+ tex.SetStatus(ImTextureStatus_OK)
389
+
390
+ GL.BindTexture(GL::TEXTURE_2D, last_texture.unpack1('L'))
391
+ return
392
+ end
393
+
394
+ if status == ImTextureStatus_WantUpdates
395
+ last_texture = ' ' * 4
396
+ GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
397
+
398
+ GL.BindTexture(GL::TEXTURE_2D, tex.GetTexID())
399
+
400
+ updates = tex[:Updates]
401
+ updates_ptr = updates[:Data]
402
+
403
+ if !updates_ptr.nil? && !updates_ptr.null?
404
+ if defined?(GL::UNPACK_ROW_LENGTH)
405
+ GL.PixelStorei(GL::UNPACK_ROW_LENGTH, tex[:Width])
406
+
407
+ updates[:Size].times do |i|
408
+ rect = ImTextureRect.new(updates_ptr + i * ImTextureRect.size)
409
+ pixels_ptr = ImplDockingOpenGL3_AsGLPointer(tex.GetPixelsAt(rect[:x], rect[:y]))
410
+ GL.TexSubImage2D(GL::TEXTURE_2D, 0, rect[:x], rect[:y], rect[:w], rect[:h], GL::RGBA, GL::UNSIGNED_BYTE, pixels_ptr)
411
+ end
412
+
413
+ GL.PixelStorei(GL::UNPACK_ROW_LENGTH, 0)
414
+ else
415
+ updates[:Size].times do |i|
416
+ rect = ImTextureRect.new(updates_ptr + i * ImTextureRect.size)
417
+ rect[:h].times do |line|
418
+ pixels_ptr = ImplDockingOpenGL3_AsGLPointer(tex.GetPixelsAt(rect[:x], rect[:y] + line))
419
+ GL.TexSubImage2D(GL::TEXTURE_2D, 0, rect[:x], rect[:y] + line, rect[:w], 1, GL::RGBA, GL::UNSIGNED_BYTE, pixels_ptr)
420
+ end
421
+ end
422
+ end
423
+ end
424
+
425
+ tex.SetStatus(ImTextureStatus_OK)
426
+ GL.BindTexture(GL::TEXTURE_2D, last_texture.unpack1('L'))
427
+ return
428
+ end
429
+
430
+ if status == ImTextureStatus_WantDestroy && tex[:UnusedFrames] > 0
431
+ ImplDockingOpenGL3_DestroyTexture(tex)
432
+ end
433
+ end
434
+
435
+ def self.ImplDockingOpenGL3_CreateDeviceObjects()
436
+ last_texture = ' ' * 4
437
+ last_array_buffer = ' ' * 4
438
+ GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
439
+ GL.GetIntegerv(GL::ARRAY_BUFFER_BINDING, last_array_buffer)
440
+
441
+ last_vertex_array = ' ' * 4
442
+ GL.GetIntegerv(GL::VERTEX_ARRAY_BINDING, last_vertex_array)
443
+
444
+ glsl_version = @@g_DockingGL3GlslVersionString.split[1].to_i
445
+
446
+ vertex_shader_glsl_120 = <<-'SRC'
447
+ uniform mat4 ProjMtx;
448
+ attribute vec2 Position;
449
+ attribute vec2 UV;
450
+ attribute vec4 Color;
451
+ varying vec2 Frag_UV;
452
+ varying vec4 Frag_Color;
453
+ void main()
454
+ {
455
+ Frag_UV = UV;
456
+ Frag_Color = Color;
457
+ gl_Position = ProjMtx * vec4(Position.xy,0,1);
458
+ }
459
+ SRC
460
+
461
+ vertex_shader_glsl_130 = <<-'SRC'
462
+ uniform mat4 ProjMtx;
463
+ in vec2 Position;
464
+ in vec2 UV;
465
+ in vec4 Color;
466
+ out vec2 Frag_UV;
467
+ out vec4 Frag_Color;
468
+ void main()
469
+ {
470
+ Frag_UV = UV;
471
+ Frag_Color = Color;
472
+ gl_Position = ProjMtx * vec4(Position.xy,0,1);
473
+ }
474
+ SRC
475
+
476
+ vertex_shader_glsl_300_es = <<-'SRC'
477
+ precision highp float;
478
+ layout (location = 0) in vec2 Position;
479
+ layout (location = 1) in vec2 UV;
480
+ layout (location = 2) in vec4 Color;
481
+ uniform mat4 ProjMtx;
482
+ out vec2 Frag_UV;
483
+ out vec4 Frag_Color;
484
+ void main()
485
+ {
486
+ Frag_UV = UV;
487
+ Frag_Color = Color;
488
+ gl_Position = ProjMtx * vec4(Position.xy,0,1);
489
+ }
490
+ SRC
491
+
492
+ vertex_shader_glsl_410_core = <<-'SRC'
493
+ layout (location = 0) in vec2 Position;
494
+ layout (location = 1) in vec2 UV;
495
+ layout (location = 2) in vec4 Color;
496
+ uniform mat4 ProjMtx;
497
+ out vec2 Frag_UV;
498
+ out vec4 Frag_Color;
499
+ void main()
500
+ {
501
+ Frag_UV = UV;
502
+ Frag_Color = Color;
503
+ gl_Position = ProjMtx * vec4(Position.xy,0,1);
504
+ }
505
+ SRC
506
+
507
+ fragment_shader_glsl_120 = <<-'SRC'
508
+ #ifdef GL_ES
509
+ precision mediump float;
510
+ #endif
511
+ uniform sampler2D Texture;
512
+ varying vec2 Frag_UV;
513
+ varying vec4 Frag_Color;
514
+ void main()
515
+ {
516
+ gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);
517
+ }
518
+ SRC
519
+
520
+ fragment_shader_glsl_130 = <<-'SRC'
521
+ uniform sampler2D Texture;
522
+ in vec2 Frag_UV;
523
+ in vec4 Frag_Color;
524
+ out vec4 Out_Color;
525
+ void main()
526
+ {
527
+ Out_Color = Frag_Color * texture(Texture, Frag_UV.st);
528
+ }
529
+ SRC
530
+
531
+ fragment_shader_glsl_300_es = <<-'SRC'
532
+ precision mediump float;
533
+ uniform sampler2D Texture;
534
+ in vec2 Frag_UV;
535
+ in vec4 Frag_Color;
536
+ layout (location = 0) out vec4 Out_Color;
537
+ void main()
538
+ {
539
+ Out_Color = Frag_Color * texture(Texture, Frag_UV.st);
540
+ }
541
+ SRC
542
+
543
+ fragment_shader_glsl_410_core = <<-'SRC'
544
+ in vec2 Frag_UV;
545
+ in vec4 Frag_Color;
546
+ uniform sampler2D Texture;
547
+ layout (location = 0) out vec4 Out_Color;
548
+ void main()
549
+ {
550
+ Out_Color = Frag_Color * texture(Texture, Frag_UV.st);
551
+ }
552
+ SRC
553
+
554
+ vertex_shader, fragment_shader = if glsl_version < 130
555
+ [vertex_shader_glsl_120, fragment_shader_glsl_120]
556
+ elsif glsl_version >= 410
557
+ [vertex_shader_glsl_410_core, fragment_shader_glsl_410_core]
558
+ elsif glsl_version == 300
559
+ [vertex_shader_glsl_300_es, fragment_shader_glsl_300_es]
560
+ else
561
+ [vertex_shader_glsl_130, fragment_shader_glsl_130]
562
+ end
563
+
564
+ vert_handle = GL.CreateShader(GL::VERTEX_SHADER)
565
+ GL.ShaderSource(vert_handle, 2, [@@g_DockingGL3GlslVersionString, vertex_shader].pack('p*'), nil)
566
+ GL.CompileShader(vert_handle)
567
+ return false unless ImplDockingOpenGL3_PrintShaderCompileStatus(vert_handle)
568
+
569
+ frag_handle = GL.CreateShader(GL::FRAGMENT_SHADER)
570
+ GL.ShaderSource(frag_handle, 2, [@@g_DockingGL3GlslVersionString, fragment_shader].pack('p*'), nil)
571
+ GL.CompileShader(frag_handle)
572
+ return false unless ImplDockingOpenGL3_PrintShaderCompileStatus(frag_handle)
573
+
574
+ @@g_DockingGL3ShaderHandle = GL.CreateProgram()
575
+ GL.AttachShader(@@g_DockingGL3ShaderHandle, vert_handle)
576
+ GL.AttachShader(@@g_DockingGL3ShaderHandle, frag_handle)
577
+ GL.LinkProgram(@@g_DockingGL3ShaderHandle)
578
+ return false unless ImplDockingOpenGL3_PrintProgramLinkStatus(@@g_DockingGL3ShaderHandle)
579
+
580
+ GL.DetachShader(@@g_DockingGL3ShaderHandle, vert_handle)
581
+ GL.DetachShader(@@g_DockingGL3ShaderHandle, frag_handle)
582
+ GL.DeleteShader(vert_handle)
583
+ GL.DeleteShader(frag_handle)
584
+
585
+ @@g_DockingGL3AttribLocationTex = GL.GetUniformLocation(@@g_DockingGL3ShaderHandle, 'Texture')
586
+ @@g_DockingGL3AttribLocationProjMtx = GL.GetUniformLocation(@@g_DockingGL3ShaderHandle, 'ProjMtx')
587
+ @@g_DockingGL3AttribLocationVtxPos = GL.GetAttribLocation(@@g_DockingGL3ShaderHandle, 'Position')
588
+ @@g_DockingGL3AttribLocationVtxUV = GL.GetAttribLocation(@@g_DockingGL3ShaderHandle, 'UV')
589
+ @@g_DockingGL3AttribLocationVtxColor = GL.GetAttribLocation(@@g_DockingGL3ShaderHandle, 'Color')
590
+
591
+ vbo_mem = ' ' * 4
592
+ elem_mem = ' ' * 4
593
+ GL.GenBuffers(1, vbo_mem)
594
+ GL.GenBuffers(1, elem_mem)
595
+ @@g_DockingGL3VboHandle = vbo_mem.unpack1('L')
596
+ @@g_DockingGL3ElementsHandle = elem_mem.unpack1('L')
597
+
598
+ GL.BindTexture(GL::TEXTURE_2D, last_texture.unpack1('L'))
599
+ GL.BindBuffer(GL::ARRAY_BUFFER, last_array_buffer.unpack1('L'))
600
+ GL.BindVertexArray(last_vertex_array.unpack1('L'))
601
+
602
+ true
603
+ end
604
+
605
+ def self.ImplDockingOpenGL3_DestroyDeviceObjects()
606
+ if @@g_DockingGL3VboHandle != 0
607
+ GL.DeleteBuffers(1, [@@g_DockingGL3VboHandle].pack('L'))
608
+ @@g_DockingGL3VboHandle = 0
609
+ end
610
+
611
+ if @@g_DockingGL3ElementsHandle != 0
612
+ GL.DeleteBuffers(1, [@@g_DockingGL3ElementsHandle].pack('L'))
613
+ @@g_DockingGL3ElementsHandle = 0
614
+ end
615
+
616
+ if @@g_DockingGL3ShaderHandle != 0
617
+ GL.DeleteProgram(@@g_DockingGL3ShaderHandle)
618
+ @@g_DockingGL3ShaderHandle = 0
619
+ end
620
+
621
+ # Destroy textures retained only by the renderer backend.
622
+ platform_io = ImGuiPlatformIO.new(ImGui::GetPlatformIO())
623
+ textures = platform_io[:Textures]
624
+ tex_data = textures[:Data]
625
+
626
+ if !tex_data.nil? && !tex_data.null?
627
+ pointer_stride = FFI::Pointer.size
628
+ textures[:Size].times do |i|
629
+ tex_ptr = (tex_data + pointer_stride * i).read_pointer
630
+ next if tex_ptr.nil? || tex_ptr.null?
631
+
632
+ tex = ImTextureData.new(tex_ptr)
633
+ ImplDockingOpenGL3_DestroyTexture(tex) if tex[:RefCount] == 1
634
+ end
635
+ end
636
+ end
637
+
638
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'imgui_impl_raylib'
2
+
3
+ # This file exists as a discoverable docking-oriented entry point.
4
+ # The actual implementation lives in imgui_impl_raylib.rb.