Skip to content

Commit d4eca3d

Browse files
Add drawlist to C FFI
1 parent d4a0d93 commit d4eca3d

File tree

4 files changed

+182
-21
lines changed

4 files changed

+182
-21
lines changed

source/inochi2d/cffi/puppet.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,19 @@ in_parameter_t** in_puppet_get_parameters(in_puppet_t* obj, ref uint count) {
255255
return cast(in_parameter_t**)(cast(Puppet)obj).parameters.ptr;
256256
}
257257

258+
/**
259+
Gets the puppet's draw list.
260+
261+
Params:
262+
obj = The puppet object.
263+
264+
Returns:
265+
The drawlist used by the puppet.
266+
*/
267+
in_drawlist_t* in_puppet_get_drawlist(in_puppet_t* obj) {
268+
return cast(in_drawlist_t*)(cast(Puppet)obj).drawList;
269+
}
270+
258271
//
259272
// PARAMETERS
260273
//

source/inochi2d/cffi/render.d

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
module inochi2d.cffi.render;
1010
import inochi2d.core.render;
11+
import inochi2d.core.mesh;
1112

1213
version(IN_DYNLIB):
1314
extern(C) export @nogc:
@@ -161,4 +162,151 @@ void in_texture_flip_vertically(in_texture_t* obj) {
161162
*/
162163
void* in_texture_get_pixels(in_texture_t* obj) {
163164
return (cast(Texture)obj).pixels.ptr;
165+
}
166+
167+
//
168+
// DRAWLIST
169+
//
170+
171+
/**
172+
DrawState flags
173+
*/
174+
alias in_drawstate_t = uint;
175+
enum in_drawstate_t
176+
IN_DRAW_STATE_NORMAL = 0,
177+
IN_DRAW_STATE_DEFINE_MASK = 1,
178+
IN_DRAW_STATE_MASKED_DRAW = 2,
179+
IN_DRAW_STATE_COMPOSITE_BEGIN = 3,
180+
IN_DRAW_STATE_COMPOSITE_END = 4,
181+
IN_DRAW_STATE_COMPOSITE_BLIT = 5;
182+
183+
/**
184+
Masking modes
185+
*/
186+
alias in_mask_mode_t = uint;
187+
enum in_mask_mode_t
188+
IN_MASK_MODE_MASK = 0,
189+
IN_MASK_MODE_DODGE = 1;
190+
191+
/**
192+
Blending modes
193+
*/
194+
alias in_blend_mode_t = uint;
195+
enum in_blend_mode_t
196+
IN_BLEND_MODE_NORMAL = 0x00,
197+
IN_BLEND_MODE_MULTIPLY = 0x01,
198+
IN_BLEND_MODE_SCREEN = 0x02,
199+
IN_BLEND_MODE_OVERLAY = 0x03,
200+
IN_BLEND_MODE_DARKEN = 0x04,
201+
IN_BLEND_MODE_LIGHTEN = 0x05,
202+
IN_BLEND_MODE_COLOR_DODGE = 0x06,
203+
IN_BLEND_MODE_LINEAR_DODGE = 0x07,
204+
IN_BLEND_MODE_ADD_GLOW = 0x08,
205+
IN_BLEND_MODE_COLOR_BURN = 0x09,
206+
IN_BLEND_MODE_HARD_LIGHT = 0x0A,
207+
IN_BLEND_MODE_SOFT_LIGHT = 0x0B,
208+
IN_BLEND_MODE_DIFFERENCE = 0x0C,
209+
IN_BLEND_MODE_EXCLUSION = 0x0D,
210+
IN_BLEND_MODE_SUBTRACT = 0x0E,
211+
IN_BLEND_MODE_INVERSE = 0x0F,
212+
IN_BLEND_MODE_DESTINATION_IN = 0x10,
213+
IN_BLEND_MODE_CLIP_TO_LOWER = 0x11,
214+
IN_BLEND_MODE_SLICE_FROM_LOWER = 0x12;
215+
216+
/**
217+
A drawing command from the Inochi2D draw list
218+
*/
219+
struct in_drawcmd_t {
220+
in_texture_t*[IN_MAX_ATTACHMENTS] sources;
221+
in_drawstate_t state;
222+
float opacity;
223+
in_blend_mode_t blendMode;
224+
in_mask_mode_t maskMode;
225+
uint vtxOffset;
226+
uint idxOffset;
227+
uint elemCount;
228+
}
229+
230+
/**
231+
A drawlist instance
232+
*/
233+
struct in_drawlist_t;
234+
235+
/**
236+
Gets whether the draw list uses base vertex offsets.
237+
238+
Params:
239+
obj = The drawlist
240+
241+
Returns:
242+
$(D true) if base vertex offsets are being generated,
243+
$(D false) otherwise.
244+
*/
245+
bool in_drawlist_get_use_base_vertex(in_drawlist_t* obj) {
246+
return (cast(DrawList)obj).useBaseVertex;
247+
}
248+
249+
/**
250+
Sets whether the draw list uses base vertex offsets.
251+
252+
Params:
253+
obj = The drawlist
254+
value = The value to set.
255+
*/
256+
void in_drawlist_set_use_base_vertex(in_drawlist_t* obj, bool value) {
257+
(cast(DrawList)obj).useBaseVertex = value;
258+
}
259+
260+
/**
261+
Gets all of the commands stored in the draw list for iteration.
262+
263+
This memory is owned by the draw list and should not be freed
264+
by you.
265+
266+
Params:
267+
obj = The drawlist
268+
count = Where to store the command count
269+
270+
Returns:
271+
A pointer to an array of draw commands
272+
*/
273+
in_drawcmd_t* in_drawlist_get_commands(in_drawlist_t* obj, ref uint count) {
274+
count = cast(uint)(cast(DrawList)obj).commands.length;
275+
return cast(in_drawcmd_t*)(cast(DrawList)obj).commands.ptr;
276+
}
277+
278+
/**
279+
Gets all of the vertex data stored in the draw list.
280+
281+
This memory is owned by the draw list and should not be freed
282+
by you.
283+
284+
Params:
285+
obj = The drawlist
286+
bytes = Where to store the byte count of the data.
287+
288+
Returns:
289+
A pointer to the data
290+
*/
291+
void* in_drawlist_get_vertex_data(in_drawlist_t* obj, ref uint bytes) {
292+
bytes = cast(uint)((cast(DrawList)obj).vertices.length*VtxData.sizeof);
293+
return cast(void*)(cast(DrawList)obj).vertices.ptr;
294+
}
295+
296+
/**
297+
Gets all of the index data stored in the draw list.
298+
299+
This memory is owned by the draw list and should not be freed
300+
by you.
301+
302+
Params:
303+
obj = The drawlist
304+
bytes = Where to store the byte count of the data.
305+
306+
Returns:
307+
A pointer to the data
308+
*/
309+
void* in_drawlist_get_index_data(in_drawlist_t* obj, ref uint bytes) {
310+
bytes = cast(uint)((cast(DrawList)obj).indices.length*uint.sizeof);
311+
return cast(void*)(cast(DrawList)obj).indices.ptr;
164312
}

source/inochi2d/core/puppet.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public:
448448
/**
449449
The active draw list for the puppet.
450450
*/
451-
@property DrawList drawList() => drawList_;
451+
@property DrawList drawList() @nogc => drawList_;
452452

453453
// Destructor
454454
~this() {

source/inochi2d/core/render/state.d

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,68 +53,68 @@ import inmath;
5353
/**
5454
Blending modes
5555
*/
56-
enum BlendMode {
56+
enum BlendMode : uint {
5757
// Normal blending mode
58-
normal,
58+
normal = 0x00,
5959

6060
// Multiply blending mode
61-
multiply,
61+
multiply = 0x01,
6262

6363
// Screen
64-
screen,
64+
screen = 0x02,
6565

6666
// Overlay
67-
overlay,
67+
overlay = 0x03,
6868

6969
// Darken
70-
darken,
70+
darken = 0x04,
7171

7272
// Lighten
73-
lighten,
73+
lighten = 0x05,
7474

7575
// Color Dodge
76-
colorDodge,
76+
colorDodge = 0x06,
7777

7878
// Linear Dodge
79-
linearDodge,
79+
linearDodge = 0x07,
8080

8181
// Add (Glow)
82-
addGlow,
82+
addGlow = 0x08,
8383

8484
// Color Burn
85-
colorBurn,
85+
colorBurn = 0x09,
8686

8787
// Hard Light
88-
hardLight,
88+
hardLight = 0x0A,
8989

9090
// Soft Light
91-
softLight,
91+
softLight = 0x0B,
9292

9393
// Difference
94-
difference,
94+
difference = 0x0C,
9595

9696
// Exclusion
97-
exclusion,
97+
exclusion = 0x0D,
9898

9999
// Subtract
100-
subtract,
100+
subtract = 0x0E,
101101

102102
// Inverse
103-
inverse,
103+
inverse = 0x0F,
104104

105105
// Destination In
106-
destinationIn,
106+
destinationIn = 0x10,
107107

108108
// Clip to Lower
109109
// Special blending mode that clips the drawable
110110
// to a lower rendered area.
111-
clipToLower,
111+
clipToLower = 0x11,
112112

113113
// Slice from Lower
114114
// Special blending mode that slices the drawable
115115
// via a lower rendered area.
116116
// Basically inverse ClipToLower
117-
sliceFromLower
117+
sliceFromLower = 0x12
118118
}
119119

120120
BlendMode toBlendMode(string name) {

0 commit comments

Comments
 (0)