1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 module derelict.allegro5.primitives; 29 30 private { 31 import core.stdc.stdint; 32 33 import derelict.util.loader, 34 derelict.util.system; 35 36 import derelict.allegro5.internal, 37 derelict.allegro5.types; 38 39 enum libNames = genLibNames("Primitives"); 40 } 41 42 alias int ALLEGRO_PRIM_TYPE; 43 enum { 44 ALLEGRO_PRIM_LINE_LIST, 45 ALLEGRO_PRIM_LINE_STRIP, 46 ALLEGRO_PRIM_LINE_LOOP, 47 ALLEGRO_PRIM_TRIANGLE_LIST, 48 ALLEGRO_PRIM_TRIANGLE_STRIP, 49 ALLEGRO_PRIM_TRIANGLE_FAN, 50 ALLEGRO_PRIM_POINT_LIST, 51 ALLEGRO_PRIM_NUM_TYPES, 52 } 53 54 enum ALLEGRO_PRIM_MAX_USER_ATTR = _ALLEGRO_PRIM_MAX_USER_ATTR; 55 56 alias int ALLEGRO_PRIM_ATTR; 57 enum { 58 ALLEGRO_PRIM_POSITION = 1, 59 ALLEGRO_PRIM_COLOR_ATTR, 60 ALLEGRO_PRIM_TEX_COORD, 61 ALLEGRO_PRIM_TEX_COORD_PIXEL, 62 ALLEGRO_PRIM_USER_ATTR, 63 ALLEGRO_PRIM_ATTR_NUM = ALLEGRO_PRIM_USER_ATTR + ALLEGRO_PRIM_MAX_USER_ATTR, 64 } 65 66 alias int ALLEGRO_PRIM_STORAGE; 67 enum { 68 ALLEGRO_PRIM_FLOAT_2, 69 ALLEGRO_PRIM_FLOAT_3, 70 ALLEGRO_PRIM_SHORT_2, 71 ALLEGRO_PRIM_FLOAT_1, 72 ALLEGRO_PRIM_FLOAT_4, 73 ALLEGRO_PRIM_UBYTE_4, 74 ALLEGRO_PRIM_SHORT_4, 75 ALLEGRO_PRIM_NORMALIZED_UBYTE_4, 76 ALLEGRO_PRIM_NORMALIZED_SHORT_2, 77 ALLEGRO_PRIM_NORMALIZED_SHORT_4, 78 ALLEGRO_PRIM_NORMALIZED_USHORT_2, 79 ALLEGRO_PRIM_NORMALIZED_USHORT_4, 80 ALLEGRO_PRIM_HALF_FLOAT_2, 81 ALLEGRO_PRIM_HALF_FLOAT_4 82 } 83 84 alias ALLEGRO_LINE_JOIN = int; 85 enum { 86 ALLEGRO_LINE_JOIN_NONE, 87 ALLEGRO_LINE_JOIN_BEVEL, 88 ALLEGRO_LINE_JOIN_ROUND, 89 ALLEGRO_LINE_JOIN_MITER, 90 ALLEGRO_LINE_JOIN_MITRE = ALLEGRO_LINE_JOIN_MITER 91 } 92 93 alias ALLEGRO_LINE_CAP = int; 94 enum { 95 ALLEGRO_LINE_CAP_NONE, 96 ALLEGRO_LINE_CAP_SQUARE, 97 ALLEGRO_LINE_CAP_ROUND, 98 ALLEGRO_LINE_CAP_TRIANGLE, 99 ALLEGRO_LINE_CAP_CLOSED 100 } 101 102 alias ALLEGRO_PRIM_BUFFER_FLAGS = int; 103 enum { 104 ALLEGRO_PRIM_BUFFER_STREAM = 0x01, 105 ALLEGRO_PRIM_BUFFER_STATIC = 0x02, 106 ALLEGRO_PRIM_BUFFER_DYNAMIC = 0x04, 107 ALLEGRO_PRIM_BUFFER_READWRITE = 0x08 108 } 109 110 enum ALLEGRO_VERTEX_CACHE_SIZE = 256; 111 enum ALLEGRO_PRIM_QUALITY = 10; 112 113 struct ALLEGRO_VERTEX_ELEMENT { 114 int attribute; 115 int storage; 116 int offset; 117 } 118 119 struct ALLEGRO_VERTEX_DECL; 120 121 struct ALLEGRO_VERTEX { 122 float x, y, z; 123 float u, v; 124 ALLEGRO_COLOR color; 125 } 126 127 struct ALLEGRO_VERTEX_BUFFER; 128 struct ALLEGRO_INDEX_BUFFER; 129 130 // Callbacks used as arguments in some of the functions below 131 extern(C) nothrow { 132 alias SoftTriInit = void function(uintptr_t,ALLEGRO_VERTEX*,ALLEGRO_VERTEX*,ALLEGRO_VERTEX*); 133 alias SoftTriFirst = void function(uintptr_t,int,int,int,int); 134 alias SoftTriStep = void function(uintptr_t,int); 135 alias SoftTriDraw = void function(uintptr_t,int,int,int); 136 alias SoftLineFirst = void function(uintptr_t,int,int,ALLEGRO_VERTEX*,ALLEGRO_VERTEX*); 137 alias SoftLineStep = void function(uintptr_t,int); 138 alias SoftLineDraw = void function(uintptr_t,int,int); 139 alias EmitTriangle = void function(int,int,int,void*); 140 } 141 142 extern(C) @nogc nothrow { 143 alias da_al_get_allegro_primitives_version = uint function(); 144 145 alias da_al_init_primitives_addon = bool function(); 146 alias da_al_shutdown_primitives_addon = void function(); 147 alias da_al_draw_prim = int function(const(void)*,const(ALLEGRO_VERTEX_DECL)*,ALLEGRO_BITMAP*,int,int,int); 148 alias da_al_draw_indexed_prim = int function(const(void)*,const(ALLEGRO_VERTEX_DECL)*,ALLEGRO_BITMAP*,const(int)*,int,int); 149 alias da_al_draw_vertex_buffer = int function(ALLEGRO_VERTEX_BUFFER*,ALLEGRO_BITMAP*,int,int,int); 150 alias da_al_draw_indexed_buffer = int function(ALLEGRO_VERTEX_BUFFER*,ALLEGRO_BITMAP*,int,int,int); 151 152 alias da_al_create_vertex_decl = ALLEGRO_VERTEX_DECL* function(const(ALLEGRO_VERTEX_ELEMENT)*,int); 153 alias da_al_destroy_vertex_decl = void function(ALLEGRO_VERTEX_DECL*); 154 155 alias da_al_create_vertex_buffer = ALLEGRO_VERTEX_BUFFER* function(ALLEGRO_VERTEX_DECL*,const(void*),int,int); 156 alias da_al_destroy_vertex_buffer = void function(ALLEGRO_VERTEX_BUFFER*); 157 alias da_al_lock_vertex_buffer = void* function(ALLEGRO_VERTEX_BUFFER*,int,int,int); 158 alias da_al_unlock_vertex_buffer = void function(ALLEGRO_VERTEX_BUFFER*); 159 alias da_al_get_vertex_buffer_size = int function(ALLEGRO_VERTEX_BUFFER*); 160 161 alias da_al_create_index_buffer = ALLEGRO_INDEX_BUFFER* function(int,const(void)*,int,int); 162 alias da_al_destroy_index_buffer = void function(ALLEGRO_INDEX_BUFFER*); 163 alias da_al_lock_index_buffer = void* function(ALLEGRO_INDEX_BUFFER*,int,int,int); 164 alias da_al_unlock_index_buffer = void function(ALLEGRO_INDEX_BUFFER*); 165 alias da_al_get_index_buffer_size = int function(ALLEGRO_INDEX_BUFFER*); 166 167 alias da_al_triangulate_polygon = bool function(const(float)*,size_t,const(int)*,EmitTriangle,void*); 168 169 alias da_al_draw_soft_triangle = void function(ALLEGRO_VERTEX*,ALLEGRO_VERTEX*,ALLEGRO_VERTEX*,uintptr_t, 170 SoftTriInit,SoftTriFirst,SoftTriStep,SoftTriDraw); 171 alias da_al_draw_soft_line = void function(ALLEGRO_VERTEX*,ALLEGRO_VERTEX*,uintptr_t, 172 SoftLineFirst,SoftLineStep,SoftLineDraw); 173 174 alias da_al_draw_line = void function(float,float,float,float,ALLEGRO_COLOR,float); 175 alias da_al_draw_triangle = void function(float,float,float,float,float,float,ALLEGRO_COLOR,float); 176 alias da_al_draw_rectangle = void function(float,float,float,float,ALLEGRO_COLOR,float); 177 alias da_al_draw_rounded_rectangle = void function(float,float,float,float,float,float,ALLEGRO_COLOR,float); 178 179 alias da_al_calculate_arc = void function(float*,int,float,float,float,float,float,float,float,int); 180 alias da_al_draw_circle = void function(float,float,float,ALLEGRO_COLOR,float); 181 alias da_al_draw_ellipse = void function(float,float,float,float,ALLEGRO_COLOR,float); 182 alias da_al_draw_arc = void function(float,float,float,float,float,ALLEGRO_COLOR,float); 183 alias da_al_draw_elliptical_arc = void function(float,float,float,float,float,float,ALLEGRO_COLOR,float); 184 alias da_al_draw_pieslice = void function(float,float,float,float,float,ALLEGRO_COLOR,float); 185 186 alias da_al_calculate_spline = void function(float*,int,float*,float,int); 187 alias da_al_draw_spline = void function(float*,ALLEGRO_COLOR,float); 188 189 alias da_al_calculate_ribbon = void function(float*,int,const(float*),int,float,int); 190 alias da_al_draw_ribbon = void function(const(float)*,int,ALLEGRO_COLOR,float,int); 191 192 alias da_al_draw_filled_triangle = void function(float,float,float,float,float,float,ALLEGRO_COLOR); 193 alias da_al_draw_filled_rectangle = void function(float,float,float,float,ALLEGRO_COLOR); 194 alias da_al_draw_filled_ellipse = void function(float,float,float,float,ALLEGRO_COLOR); 195 alias da_al_draw_filled_circle = void function(float,float,float,ALLEGRO_COLOR); 196 alias da_al_draw_filled_pieslice = void function(float,float,float,float,float,ALLEGRO_COLOR); 197 alias da_al_draw_filled_rounded_rectangle = void function(float,float,float,float,float,float,ALLEGRO_COLOR); 198 199 alias da_al_draw_polyline = void function(const(float)*,int,int,int,int,ALLEGRO_COLOR,float,float); 200 201 alias da_al_draw_polygon = void function(const(float)*,int,int,ALLEGRO_COLOR,float,float); 202 alias da_al_draw_filled_polygon = void function(const(float)*,int,ALLEGRO_COLOR); 203 alias da_al_draw_filled_polygon_with_holes = void function(const(float)*,const(int)*,ALLEGRO_COLOR); 204 } 205 206 __gshared { 207 da_al_get_allegro_primitives_version al_get_allegro_primitives_version; 208 da_al_init_primitives_addon al_init_primitives_addon; 209 da_al_shutdown_primitives_addon al_shutdown_primitives_addon; 210 da_al_draw_prim al_draw_prim; 211 da_al_draw_indexed_prim al_draw_indexed_prim; 212 da_al_draw_vertex_buffer al_draw_vertex_buffer; 213 da_al_draw_indexed_buffer al_draw_indexed_buffer; 214 da_al_create_vertex_decl al_create_vertex_decl; 215 da_al_destroy_vertex_decl al_destroy_vertex_decl; 216 da_al_create_vertex_buffer al_create_vertex_buffer; 217 da_al_destroy_vertex_buffer al_destroy_vertex_buffer; 218 da_al_lock_vertex_buffer al_lock_vertex_buffer; 219 da_al_unlock_vertex_buffer al_unlock_vertex_buffer; 220 da_al_get_vertex_buffer_size al_get_vertex_buffer_size; 221 da_al_create_index_buffer al_create_index_buffer; 222 da_al_destroy_index_buffer al_destroy_index_buffer; 223 da_al_lock_index_buffer al_lock_index_buffer; 224 da_al_unlock_index_buffer al_unlock_index_buffer; 225 da_al_get_index_buffer_size al_get_index_buffer_size; 226 da_al_triangulate_polygon al_triangulate_polygon; 227 da_al_draw_soft_triangle al_draw_soft_triangle; 228 da_al_draw_soft_line al_draw_soft_line; 229 da_al_draw_line al_draw_line; 230 da_al_draw_triangle al_draw_triangle; 231 da_al_draw_rectangle al_draw_rectangle; 232 da_al_draw_rounded_rectangle al_draw_rounded_rectangle; 233 da_al_calculate_arc al_calculate_arc; 234 da_al_draw_circle al_draw_circle; 235 da_al_draw_ellipse al_draw_ellipse; 236 da_al_draw_arc al_draw_arc; 237 da_al_draw_elliptical_arc al_draw_elliptical_arc; 238 da_al_draw_pieslice al_draw_pieslice; 239 da_al_calculate_spline al_calculate_spline; 240 da_al_draw_spline al_draw_spline; 241 da_al_calculate_ribbon al_calculate_ribbon; 242 da_al_draw_ribbon al_draw_ribbon; 243 da_al_draw_filled_triangle al_draw_filled_triangle; 244 da_al_draw_filled_rectangle al_draw_filled_rectangle; 245 da_al_draw_filled_ellipse al_draw_filled_ellipse; 246 da_al_draw_filled_circle al_draw_filled_circle; 247 da_al_draw_filled_pieslice al_draw_filled_pieslice; 248 da_al_draw_filled_rounded_rectangle al_draw_filled_rounded_rectangle; 249 da_al_draw_polyline al_draw_polyline; 250 da_al_draw_polygon al_draw_polygon; 251 da_al_draw_filled_polygon al_draw_filled_polygon; 252 da_al_draw_filled_polygon_with_holes al_draw_filled_polygon_with_holes; 253 } 254 255 class DerelictAllegro5PrimitivesLoader : SharedLibLoader { 256 public this() { 257 super(libNames); 258 } 259 260 protected override void loadSymbols() { 261 bindFunc(cast(void**)&al_get_allegro_primitives_version, "al_get_allegro_primitives_version"); 262 bindFunc(cast(void**)&al_init_primitives_addon, "al_init_primitives_addon"); 263 bindFunc(cast(void**)&al_shutdown_primitives_addon, "al_shutdown_primitives_addon"); 264 bindFunc(cast(void**)&al_draw_prim, "al_draw_prim"); 265 bindFunc(cast(void**)&al_draw_indexed_prim, "al_draw_indexed_prim"); 266 bindFunc(cast(void**)&al_draw_vertex_buffer, "al_draw_vertex_buffer"); 267 bindFunc(cast(void**)&al_draw_indexed_buffer, "al_draw_indexed_buffer"); 268 bindFunc(cast(void**)&al_create_vertex_decl, "al_create_vertex_decl"); 269 bindFunc(cast(void**)&al_destroy_vertex_decl, "al_destroy_vertex_decl"); 270 bindFunc(cast(void**)&al_create_vertex_buffer, "al_create_vertex_buffer"); 271 bindFunc(cast(void**)&al_destroy_vertex_buffer, "al_destroy_vertex_buffer"); 272 bindFunc(cast(void**)&al_lock_vertex_buffer, "al_lock_vertex_buffer"); 273 bindFunc(cast(void**)&al_unlock_vertex_buffer, "al_unlock_vertex_buffer"); 274 bindFunc(cast(void**)&al_get_vertex_buffer_size, "al_get_vertex_buffer_size"); 275 bindFunc(cast(void**)&al_create_index_buffer, "al_create_index_buffer"); 276 bindFunc(cast(void**)&al_lock_index_buffer, "al_lock_index_buffer"); 277 bindFunc(cast(void**)&al_destroy_index_buffer, "al_destroy_index_buffer"); 278 bindFunc(cast(void**)&al_unlock_index_buffer, "al_unlock_index_buffer"); 279 bindFunc(cast(void**)&al_get_index_buffer_size, "al_get_index_buffer_size"); 280 bindFunc(cast(void**)&al_destroy_index_buffer, "al_destroy_index_buffer"); 281 bindFunc(cast(void**)&al_triangulate_polygon, "al_triangulate_polygon"); 282 bindFunc(cast(void**)&al_draw_soft_triangle, "al_draw_soft_triangle"); 283 bindFunc(cast(void**)&al_draw_soft_line, "al_draw_soft_line"); 284 bindFunc(cast(void**)&al_draw_line, "al_draw_line"); 285 bindFunc(cast(void**)&al_draw_triangle, "al_draw_triangle"); 286 bindFunc(cast(void**)&al_draw_rectangle, "al_draw_rectangle"); 287 bindFunc(cast(void**)&al_draw_rounded_rectangle, "al_draw_rounded_rectangle"); 288 bindFunc(cast(void**)&al_draw_circle, "al_draw_circle"); 289 bindFunc(cast(void**)&al_draw_ellipse, "al_draw_ellipse"); 290 bindFunc(cast(void**)&al_draw_arc, "al_draw_arc"); 291 bindFunc(cast(void**)&al_draw_elliptical_arc, "al_draw_elliptical_arc"); 292 bindFunc(cast(void**)&al_draw_pieslice, "al_draw_pieslice"); 293 bindFunc(cast(void**)&al_calculate_spline, "al_calculate_spline"); 294 bindFunc(cast(void**)&al_draw_spline, "al_draw_spline"); 295 bindFunc(cast(void**)&al_calculate_ribbon, "al_calculate_ribbon"); 296 bindFunc(cast(void**)&al_draw_ribbon, "al_draw_ribbon"); 297 bindFunc(cast(void**)&al_draw_filled_triangle, "al_draw_filled_triangle"); 298 bindFunc(cast(void**)&al_draw_filled_rectangle, "al_draw_filled_rectangle"); 299 bindFunc(cast(void**)&al_draw_filled_ellipse, "al_draw_filled_ellipse"); 300 bindFunc(cast(void**)&al_draw_filled_circle, "al_draw_filled_circle"); 301 bindFunc(cast(void**)&al_draw_filled_pieslice, "al_draw_filled_pieslice"); 302 bindFunc(cast(void**)&al_draw_filled_rounded_rectangle, "al_draw_filled_rounded_rectangle"); 303 304 bindFunc(cast(void**)&al_draw_polyline, "al_draw_polyline"); 305 bindFunc(cast(void**)&al_draw_polygon, "al_draw_polygon"); 306 bindFunc(cast(void**)&al_draw_filled_polygon, "al_draw_filled_polygon"); 307 bindFunc(cast(void**)&al_draw_filled_polygon_with_holes, "al_draw_filled_polygon_with_holes"); 308 309 } 310 } 311 312 __gshared DerelictAllegro5PrimitivesLoader DerelictAllegro5Primitives; 313 314 shared static this() { 315 DerelictAllegro5Primitives = new DerelictAllegro5PrimitivesLoader; 316 }