Repository navigation
Expand file tree
/
Copy pathImDrawData.java
More file actions
415 lines (341 loc) · 13.5 KB
/
Copy pathImDrawData.java
File metadata and controls
415 lines (341 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
package imgui;
import imgui.binding.ImGuiStruct;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* All draw data to render Dear ImGui frame
* (NB: the style and the naming convention here is a little inconsistent, we currently preserve them for backward compatibility purpose,
* as this is one of the oldest structure exposed by the library! Basically, ImDrawList == CmdList)
* <p>
* BINDING NOTICE: Since it's impossible to do a 1:1 mapping with JNI, current class provides "getCmdList*()" methods.
* Those are used to get the data needed to do a rendering.
*/
public final class ImDrawData extends ImGuiStruct {
private static final int RESIZE_FACTOR = 5_000;
private static ByteBuffer dataBuffer = ByteBuffer.allocateDirect(25_000).order(ByteOrder.nativeOrder());
private static final ImTextureData _GETTEXTURES_1 = new ImTextureData(0);
public ImDrawData(final long ptr) {
super(ptr);
}
/*JNI
#include "_common.h"
#define THIS ((ImDrawData*)STRUCT_PTR)
*/
///////// Start of Render Methods | Binding
/**
* Draw commands. Typically 1 command = 1 GPU draw call, unless the command is a callback.
*/
public native int getCmdListCmdBufferSize(int cmdListIdx); /*
return THIS->CmdLists[cmdListIdx]->CmdBuffer.Size;
*/
/**
* Number of indices (multiple of 3) to be rendered as triangles.
* Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[].
*/
public native int getCmdListCmdBufferElemCount(int cmdListIdx, int cmdBufferIdx); /*
return THIS->CmdLists[cmdListIdx]->CmdBuffer[cmdBufferIdx].ElemCount;
*/
/**
* Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData.DisplayPos to get clipping rectangle in "viewport" coordinates
*/
public ImVec4 getCmdListCmdBufferClipRect(final int cmdListIdx, final int cmdBufferIdx) {
final ImVec4 dst = new ImVec4();
getCmdListCmdBufferClipRect(dst, cmdListIdx, cmdBufferIdx);
return dst;
}
/**
* Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData.DisplayPos to get clipping rectangle in "viewport" coordinates
*/
public native void getCmdListCmdBufferClipRect(ImVec4 dst, int cmdListIdx, int cmdBufferIdx); /*
Jni::ImVec4Cpy(env, &THIS->CmdLists[cmdListIdx]->CmdBuffer[cmdBufferIdx].ClipRect, dst);
*/
/**
* User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions.
* Ignore if never using images or multiple fonts atlas.
*/
public native long getCmdListCmdBufferTextureId(int cmdListIdx, int cmdBufferIdx); /*
return (uintptr_t)THIS->CmdLists[cmdListIdx]->CmdBuffer[cmdBufferIdx].GetTexID();
*/
/**
* Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_RendererHasVtxOffset: always 0.
* With ImGuiBackendFlags_RendererHasVtxOffset: may be {@code >}0 to support meshes larger than 64K vertices with 16-bit indices.
*/
public native int getCmdListCmdBufferVtxOffset(int cmdListIdx, int cmdBufferIdx); /*
return THIS->CmdLists[cmdListIdx]->CmdBuffer[cmdBufferIdx].VtxOffset;
*/
/**
* Start offset in index buffer. Always equal to sum of ElemCount drawn so far.
*/
public native int getCmdListCmdBufferIdxOffset(int cmdListIdx, int cmdBufferIdx); /*
return THIS->CmdLists[cmdListIdx]->CmdBuffer[cmdBufferIdx].IdxOffset;
*/
/**
* Index buffer. Each command consume ImDrawCmd::ElemCount of those
*/
public native int getCmdListIdxBufferSize(int cmdListIdx); /*
return THIS->CmdLists[cmdListIdx]->IdxBuffer.Size;
*/
public ByteBuffer getCmdListIdxBufferData(final int cmdListIdx) {
final int idxBufferCapacity = getCmdListIdxBufferSize(cmdListIdx) * sizeOfImDrawIdx();
if (dataBuffer.capacity() < idxBufferCapacity) {
dataBuffer.clear();
dataBuffer = ByteBuffer.allocateDirect(idxBufferCapacity + RESIZE_FACTOR).order(ByteOrder.nativeOrder());
}
nGetCmdListIdxBufferData(cmdListIdx, dataBuffer, idxBufferCapacity);
dataBuffer.position(0);
dataBuffer.limit(idxBufferCapacity);
return dataBuffer;
}
private native void nGetCmdListIdxBufferData(int cmdListIdx, ByteBuffer idxBuffer, int idxBufferCapacity); /*
memcpy(idxBuffer, THIS->CmdLists[cmdListIdx]->IdxBuffer.Data, idxBufferCapacity);
*/
/**
* Vertex buffer.
*/
public native int getCmdListVtxBufferSize(int cmdListIdx); /*
return THIS->CmdLists[cmdListIdx]->VtxBuffer.Size;
*/
public ByteBuffer getCmdListVtxBufferData(final int cmdListIdx) {
final int vtxBufferCapacity = getCmdListVtxBufferSize(cmdListIdx) * sizeOfImDrawVert();
if (dataBuffer.capacity() < vtxBufferCapacity) {
dataBuffer.clear();
dataBuffer = ByteBuffer.allocateDirect(vtxBufferCapacity + RESIZE_FACTOR).order(ByteOrder.nativeOrder());
}
nGetCmdListVtxBufferData(cmdListIdx, dataBuffer, vtxBufferCapacity);
dataBuffer.position(0);
dataBuffer.limit(vtxBufferCapacity);
return dataBuffer;
}
private native void nGetCmdListVtxBufferData(int cmdListIdx, ByteBuffer vtxBuffer, int vtxBufferCapacity); /*
memcpy(vtxBuffer, THIS->CmdLists[cmdListIdx]->VtxBuffer.Data, vtxBufferCapacity);
*/
/**
* Number of textures to update before rendering this draw data. Most of the time the list is shared by all
* ImDrawData, has only one texture and does not need any update. This almost always mirrors
* {@link ImGuiPlatformIO#getTexturesSize()}. May be zero if texture updates are disabled (list set to NULL).
*/
public native int getTexturesSize(); /*
return THIS->Textures != NULL ? THIS->Textures->Size : 0;
*/
/**
* Texture to update at the given index. The returned value is a shared instance, valid only until the next call to
* this method.
*
* @param idx index in {@code [0, getTexturesSize())}
*/
public ImTextureData getTextures(final int idx) {
_GETTEXTURES_1.ptr = nGetTextures(idx);
return _GETTEXTURES_1;
}
private native long nGetTextures(int idx); /*
return (uintptr_t)(*THIS->Textures)[idx];
*/
public static native int sizeOfImDrawVert(); /*
return (int)sizeof(ImDrawVert);
*/
public static native int sizeOfImDrawIdx(); /*
return (int)sizeof(ImDrawIdx);
*/
///////// End of Render Methods
/**
* Only valid after Render() is called and before the next NewFrame() is called.
*/
public boolean getValid() {
return nGetValid();
}
private native boolean nGetValid(); /*
return THIS->Valid;
*/
/**
* Number of ImDrawList* to render
*/
public int getCmdListsCount() {
return nGetCmdListsCount();
}
private native int nGetCmdListsCount(); /*
return THIS->CmdListsCount;
*/
/**
* For convenience, sum of all ImDrawList's IdxBuffer.Size
*/
public int getTotalIdxCount() {
return nGetTotalIdxCount();
}
private native int nGetTotalIdxCount(); /*
return THIS->TotalIdxCount;
*/
/**
* For convenience, sum of all ImDrawList's VtxBuffer.Size
*/
public int getTotalVtxCount() {
return nGetTotalVtxCount();
}
private native int nGetTotalVtxCount(); /*
return THIS->TotalVtxCount;
*/
/**
* Upper-left position of the viewport to render (== upper-left of the orthogonal projection matrix to use)
*/
public ImVec2 getDisplayPos() {
final ImVec2 dst = new ImVec2();
nGetDisplayPos(dst);
return dst;
}
/**
* Upper-left position of the viewport to render (== upper-left of the orthogonal projection matrix to use)
*/
public float getDisplayPosX() {
return nGetDisplayPosX();
}
/**
* Upper-left position of the viewport to render (== upper-left of the orthogonal projection matrix to use)
*/
public float getDisplayPosY() {
return nGetDisplayPosY();
}
/**
* Upper-left position of the viewport to render (== upper-left of the orthogonal projection matrix to use)
*/
public void getDisplayPos(final ImVec2 dst) {
nGetDisplayPos(dst);
}
private native void nGetDisplayPos(ImVec2 dst); /*
Jni::ImVec2Cpy(env, THIS->DisplayPos, dst);
*/
private native float nGetDisplayPosX(); /*
return THIS->DisplayPos.x;
*/
private native float nGetDisplayPosY(); /*
return THIS->DisplayPos.y;
*/
/**
* Size of the viewport to render (== io.DisplaySize for the main viewport)
* (DisplayPos + DisplaySize == lower-right of the orthogonal projection matrix to use)
*/
public ImVec2 getDisplaySize() {
final ImVec2 dst = new ImVec2();
nGetDisplaySize(dst);
return dst;
}
/**
* Size of the viewport to render (== io.DisplaySize for the main viewport)
* (DisplayPos + DisplaySize == lower-right of the orthogonal projection matrix to use)
*/
public float getDisplaySizeX() {
return nGetDisplaySizeX();
}
/**
* Size of the viewport to render (== io.DisplaySize for the main viewport)
* (DisplayPos + DisplaySize == lower-right of the orthogonal projection matrix to use)
*/
public float getDisplaySizeY() {
return nGetDisplaySizeY();
}
/**
* Size of the viewport to render (== io.DisplaySize for the main viewport)
* (DisplayPos + DisplaySize == lower-right of the orthogonal projection matrix to use)
*/
public void getDisplaySize(final ImVec2 dst) {
nGetDisplaySize(dst);
}
private native void nGetDisplaySize(ImVec2 dst); /*
Jni::ImVec2Cpy(env, THIS->DisplaySize, dst);
*/
private native float nGetDisplaySizeX(); /*
return THIS->DisplaySize.x;
*/
private native float nGetDisplaySizeY(); /*
return THIS->DisplaySize.y;
*/
/**
* Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display.
*/
public ImVec2 getFramebufferScale() {
final ImVec2 dst = new ImVec2();
nGetFramebufferScale(dst);
return dst;
}
/**
* Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display.
*/
public float getFramebufferScaleX() {
return nGetFramebufferScaleX();
}
/**
* Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display.
*/
public float getFramebufferScaleY() {
return nGetFramebufferScaleY();
}
/**
* Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display.
*/
public void getFramebufferScale(final ImVec2 dst) {
nGetFramebufferScale(dst);
}
private native void nGetFramebufferScale(ImVec2 dst); /*
Jni::ImVec2Cpy(env, THIS->FramebufferScale, dst);
*/
private native float nGetFramebufferScaleX(); /*
return THIS->FramebufferScale.x;
*/
private native float nGetFramebufferScaleY(); /*
return THIS->FramebufferScale.y;
*/
/**
* Viewport carrying the ImDrawData instance, might be of use to the renderer (generally not).
*/
public ImGuiViewport getOwnerViewport() {
return new ImGuiViewport(nGetOwnerViewport());
}
private native long nGetOwnerViewport(); /*
return (uintptr_t)THIS->OwnerViewport;
*/
// Functions
public void clear() {
nClear();
}
private native void nClear(); /*
THIS->Clear();
*/
/**
* Helper to add an external draw list into an existing ImDrawData.
*/
public void addDrawList(final ImDrawList drawList) {
nAddDrawList(drawList.ptr);
}
private native void nAddDrawList(long drawList); /*
THIS->AddDrawList(reinterpret_cast<ImDrawList*>(drawList));
*/
/**
* Helper to convert all buffers from indexed to non-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources.
* Always prefer indexed rendering!
*/
public void deIndexAllBuffers() {
nDeIndexAllBuffers();
}
private native void nDeIndexAllBuffers(); /*
THIS->DeIndexAllBuffers();
*/
/**
* Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than Dear ImGui expects,
* or if there is a difference between your window resolution and framebuffer resolution.
*/
public void scaleClipRects(final ImVec2 fbScale) {
nScaleClipRects(fbScale.x, fbScale.y);
}
/**
* Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than Dear ImGui expects,
* or if there is a difference between your window resolution and framebuffer resolution.
*/
public void scaleClipRects(final float fbScaleX, final float fbScaleY) {
nScaleClipRects(fbScaleX, fbScaleY);
}
private native void nScaleClipRects(float fbScaleX, float fbScaleY); /*MANUAL
ImVec2 fbScale = ImVec2(fbScaleX, fbScaleY);
THIS->ScaleClipRects(fbScale);
*/
/*JNI
#undef THIS
*/
}