Skip to content

Commit d392879

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

File tree

3 files changed

+180
-20
lines changed

3 files changed

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

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)