1 module allegro5.allegro_primitives;
2 
3 version(ALLEGRO_NO_PRAGMA_LIB) {}
4 else
5 {
6 	pragma(lib, "allegro_primitives");
7 }
8 
9 version (Tango) {
10    import tango.stdc.stdint;
11 }
12 else {
13    import std.stdint;
14 }
15 
16 import allegro5.allegro;
17 
18 nothrow @nogc extern (C)
19 {
20 	enum ALLEGRO_PRIM_TYPE
21 	{
22 		ALLEGRO_PRIM_LINE_LIST,
23 		ALLEGRO_PRIM_LINE_STRIP,
24 		ALLEGRO_PRIM_LINE_LOOP,
25 		ALLEGRO_PRIM_TRIANGLE_LIST,
26 		ALLEGRO_PRIM_TRIANGLE_STRIP,
27 		ALLEGRO_PRIM_TRIANGLE_FAN,
28 		ALLEGRO_PRIM_POINT_LIST,
29 		ALLEGRO_PRIM_NUM_TYPES
30 	}
31 
32 	enum
33 	{
34 		ALLEGRO_PRIM_MAX_USER_ATTR = _ALLEGRO_PRIM_MAX_USER_ATTR
35 	}
36 
37 	enum ALLEGRO_PRIM_ATTR
38 	{
39 		ALLEGRO_PRIM_POSITION = 1,
40 		ALLEGRO_PRIM_COLOR_ATTR,
41 		ALLEGRO_PRIM_TEX_COORD,
42 		ALLEGRO_PRIM_TEX_COORD_PIXEL,
43 		ALLEGRO_PRIM_USER_ATTR,
44 		ALLEGRO_PRIM_ATTR_NUM = ALLEGRO_PRIM_USER_ATTR + ALLEGRO_PRIM_MAX_USER_ATTR
45 	}
46 
47 	enum ALLEGRO_PRIM_STORAGE
48 	{
49 		ALLEGRO_PRIM_FLOAT_2,
50 		ALLEGRO_PRIM_FLOAT_3,
51 		ALLEGRO_PRIM_SHORT_2,
52 		ALLEGRO_PRIM_FLOAT_1,
53 		ALLEGRO_PRIM_FLOAT_4,
54 		ALLEGRO_PRIM_UBYTE_4,
55 		ALLEGRO_PRIM_SHORT_4,
56 		ALLEGRO_PRIM_NORMALIZED_UBYTE_4,
57 		ALLEGRO_PRIM_NORMALIZED_SHORT_2,
58 		ALLEGRO_PRIM_NORMALIZED_SHORT_4,
59 		ALLEGRO_PRIM_NORMALIZED_USHORT_2,
60 		ALLEGRO_PRIM_NORMALIZED_USHORT_4,
61 		ALLEGRO_PRIM_HALF_FLOAT_2,
62 		ALLEGRO_PRIM_HALF_FLOAT_4
63 	}
64 	
65 	enum ALLEGRO_LINE_JOIN
66 	{
67 		ALLEGRO_LINE_JOIN_NONE,
68 		ALLEGRO_LINE_JOIN_BEVEL,
69 		ALLEGRO_LINE_JOIN_ROUND,
70 		ALLEGRO_LINE_JOIN_MITER,
71 		ALLEGRO_LINE_JOIN_MITRE = ALLEGRO_LINE_JOIN_MITER
72 	}
73 
74 	enum ALLEGRO_LINE_CAP
75 	{
76 		ALLEGRO_LINE_CAP_NONE,
77 		ALLEGRO_LINE_CAP_SQUARE,
78 		ALLEGRO_LINE_CAP_ROUND,
79 		ALLEGRO_LINE_CAP_TRIANGLE,
80 		ALLEGRO_LINE_CAP_CLOSED
81 	}
82 
83 	enum ALLEGRO_PRIM_BUFFER_FLAGS
84 	{
85 		ALLEGRO_BUFFER_STREAM  = 0x01,
86 		ALLEGRO_BUFFER_STATIC  = 0x02,
87 		ALLEGRO_BUFFER_DYNAMIC = 0x04,
88 		ALLEGRO_PRIM_BUFFER_READWRITE = 0x08
89 	}
90 
91 	const int ALLEGRO_VERTEX_CACHE_SIZE = 256;
92 
93 	const int ALLEGRO_PRIM_QUALITY = 10;
94 
95 	struct ALLEGRO_VERTEX_ELEMENT 
96 	{
97 		int attribute;
98 		int storage;
99 		int offset;
100 	}
101 
102 	struct ALLEGRO_VERTEX_DECL {};
103 
104 	struct ALLEGRO_VERTEX
105 	{
106 		float x, y, z;
107 		float u, v;
108 		ALLEGRO_COLOR color;
109 	}
110 
111 	struct ALLEGRO_VERTEX_BUFFER {};
112 	
113 	struct ALLEGRO_INDEX_BUFFER {};
114 
115 	uint al_get_allegro_primitives_version();
116 
117 	/*
118 	* Primary Functions
119 	*/
120 	bool al_init_primitives_addon();
121 	void al_shutdown_primitives_addon();
122 	int al_draw_prim(in void* vtxs, in ALLEGRO_VERTEX_DECL* decl, ALLEGRO_BITMAP* texture, int start, int end, int type);
123 	int al_draw_indexed_prim(in void* vtxs, in ALLEGRO_VERTEX_DECL* decl, ALLEGRO_BITMAP* texture, in int* indices, int num_vtx, int type);
124 	int al_draw_vertex_buffer(ALLEGRO_VERTEX_BUFFER* vertex_buffer, ALLEGRO_BITMAP* texture, int start, int end, int type);
125 	int al_draw_indexed_buffer(ALLEGRO_VERTEX_BUFFER* vertex_buffer, ALLEGRO_BITMAP* texture, ALLEGRO_INDEX_BUFFER* index_buffer, int start, int end, int type);
126 	
127 	ALLEGRO_VERTEX_DECL* al_create_vertex_decl(in ALLEGRO_VERTEX_ELEMENT* elements, int stride);
128 	void al_destroy_vertex_decl(ALLEGRO_VERTEX_DECL* decl);
129 	
130 	/*
131 	* Vertex buffers
132 	*/
133 	ALLEGRO_VERTEX_BUFFER* al_create_vertex_buffer(ALLEGRO_VERTEX_DECL* decl, in void* initial_data, int num_vertices, int flags);
134 	void al_destroy_vertex_buffer(ALLEGRO_VERTEX_BUFFER* buffer);
135 	void* al_lock_vertex_buffer(ALLEGRO_VERTEX_BUFFER* buffer, int offset, int length, int flags);
136 	void al_unlock_vertex_buffer(ALLEGRO_VERTEX_BUFFER* buffer);
137 	int al_get_vertex_buffer_size(ALLEGRO_VERTEX_BUFFER* buffer);
138 	
139 	/*
140 	 * Index buffers
141 	 */
142 	ALLEGRO_INDEX_BUFFER* al_create_index_buffer(int index_size, in void* initial_data, int num_indices, int flags);
143 	void al_destroy_index_buffer(ALLEGRO_INDEX_BUFFER* buffer);
144 	void* al_lock_index_buffer(ALLEGRO_INDEX_BUFFER* buffer, int offset, int length, int flags);
145 	void al_unlock_index_buffer(ALLEGRO_INDEX_BUFFER* buffer);
146 	int al_get_index_buffer_size(ALLEGRO_INDEX_BUFFER* buffer);
147 
148 	/*
149 	* Utilities for high level primitives.
150 	*/
151 	bool al_triangulate_polygon(in float* vertices, size_t vertex_stride, in int* vertex_counts, void function(int, int, int, void*) emit_triangle, void* userdata);
152 
153 	/*
154 	* Custom primitives
155 	*/
156 	void al_draw_soft_triangle(ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, ALLEGRO_VERTEX* v3, uintptr_t state,
157 	                                           void function(uintptr_t, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*) init,
158 	                                           void function(uintptr_t, int, int, int, int) first,
159 	                                           void function(uintptr_t, int) step, 
160 	                                           void function(uintptr_t, int, int, int) draw);
161 	void al_draw_soft_line(ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, uintptr_t state,
162 	                                           void function(uintptr_t, int, int, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*) first,
163 	                                           void function(uintptr_t, int) step, 
164 	                                           void function(uintptr_t, int, int) draw);
165 
166 	/*
167 	*High level primitives
168 	*/
169 	void al_draw_line(float x1, float y1, float x2, float y2, ALLEGRO_COLOR color, float thickness);
170 	void al_draw_triangle(float x1, float y1, float x2, float y2, float x3, float y3, ALLEGRO_COLOR color, float thickness);
171 	void al_draw_rectangle(float x1, float y1, float x2, float y2, ALLEGRO_COLOR color, float thickness);
172 	void al_draw_rounded_rectangle(float x1, float y1, float x2, float y2, float rx, float ry, ALLEGRO_COLOR color, float thickness);
173 
174 	void al_calculate_arc(float* dest, int stride, float cx, float cy, float rx, float ry, float start_theta, float delta_theta, float thickness, int num_segments);
175 	void al_draw_circle(float cx, float cy, float r, ALLEGRO_COLOR color, float thickness);
176 	void al_draw_ellipse(float cx, float cy, float rx, float ry, ALLEGRO_COLOR color, float thickness);
177 	void al_draw_arc(float cx, float cy, float r, float start_theta, float delta_theta, ALLEGRO_COLOR color, float thickness);
178 	void al_draw_elliptical_arc(float cx, float cy, float rx, float ry, float start_theta, float delta_theta, ALLEGRO_COLOR color, float thickness);
179 	void al_draw_pieslice(float cx, float cy, float r, float start_theta, float delta_theta, ALLEGRO_COLOR color, float thickness);
180 
181 	void al_calculate_spline(float* dest, int stride, float[8] points, float thickness, int num_segments);
182 	void al_draw_spline(float[8] points, ALLEGRO_COLOR color, float thickness);
183 
184 	void al_calculate_ribbon(float* dest, int dest_stride, in float *points, int points_stride, float thickness, int num_segments);
185 	void al_draw_ribbon(in float *points, int points_stride, ALLEGRO_COLOR color, float thickness, int num_segments);
186 
187 	void al_draw_filled_triangle(float x1, float y1, float x2, float y2, float x3, float y3, ALLEGRO_COLOR color);
188 	void al_draw_filled_rectangle(float x1, float y1, float x2, float y2, ALLEGRO_COLOR color);
189 	void al_draw_filled_ellipse(float cx, float cy, float rx, float ry, ALLEGRO_COLOR color);
190 	void al_draw_filled_circle(float cx, float cy, float r, ALLEGRO_COLOR color);
191 	void al_draw_filled_pieslice(float cx, float cy, float r, float start_theta, float delta_theta, ALLEGRO_COLOR color);
192 	void al_draw_filled_rounded_rectangle(float x1, float y1, float x2, float y2, float rx, float ry, ALLEGRO_COLOR color);
193 	
194 	void al_draw_polyline(in float* vertices, int vertex_stride, int vertex_count, ALLEGRO_LINE_JOIN join_style, ALLEGRO_LINE_CAP cap_style, ALLEGRO_COLOR color, float thickness, float miter_limit);
195 
196 	void al_draw_polygon(in float* vertices, int vertex_count, ALLEGRO_LINE_JOIN join_style, ALLEGRO_COLOR color, float thickness, float miter_limit);
197 	void al_draw_filled_polygon(in float* vertices, int vertex_count, ALLEGRO_COLOR color);
198 	void al_draw_filled_polygon_with_holes(in float* vertices, in int* vertex_counts, ALLEGRO_COLOR color);
199 }