| 1 |
/* ______ ___ ___ |
| 2 |
* /\ _ \ /\_ \ /\_ \ |
| 3 |
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ |
| 4 |
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ |
| 5 |
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ |
| 6 |
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ |
| 7 |
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ |
| 8 |
* /\____/ |
| 9 |
* \_/__/ |
| 10 |
* |
| 11 |
* Core primitive addon functions. |
| 12 |
* |
| 13 |
* |
| 14 |
* By Pavel Sountsov. |
| 15 |
* |
| 16 |
* See readme.txt for copyright information. |
| 17 |
*/ |
| 18 |
|
| 19 |
#define ALLEGRO_INTERNAL_UNSTABLE |
| 20 |
|
| 21 |
#include "allegro5/allegro.h" |
| 22 |
#include "allegro5/allegro_primitives.h" |
| 23 |
#include "allegro5/platform/alplatf.h" |
| 24 |
#include "allegro5/internal/aintern.h" |
| 25 |
#include "allegro5/internal/aintern_bitmap.h" |
| 26 |
#include "allegro5/internal/aintern_exitfunc.h" |
| 27 |
#include "allegro5/internal/aintern_pixels.h" |
| 28 |
#include "allegro5/internal/aintern_prim_addon.h" |
| 29 |
#include "allegro5/internal/aintern_prim_directx.h" |
| 30 |
#include "allegro5/internal/aintern_prim_soft.h" |
| 31 |
#include "allegro5/internal/aintern_primitives.h" |
| 32 |
#include <math.h> |
| 33 |
|
| 34 |
#ifdef ALLEGRO_CFG_OPENGL |
| 35 |
#include "allegro5/allegro_opengl.h" |
| 36 |
#endif |
| 37 |
|
| 38 |
#ifndef ALLEGRO_DIRECT3D |
| 39 |
#define ALLEGRO_DIRECT3D ALLEGRO_DIRECT3D_INTERNAL |
| 40 |
#endif |
| 41 |
|
| 42 |
ALLEGRO_DEBUG_CHANNEL("primitives") |
| 43 |
|
| 44 |
|
| 45 |
static bool addon_initialized = false; |
| 46 |
|
| 47 |
/* Function: al_init_primitives_addon |
| 48 |
*/ |
| 49 |
bool al_init_primitives_addon(void) |
| 50 |
{ |
| 51 |
addon_initialized = true; |
| 52 |
_al_add_exit_func(al_shutdown_primitives_addon, "primitives_shutdown"); |
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
/* Function: al_is_primitives_addon_initialized |
| 57 |
*/ |
| 58 |
bool al_is_primitives_addon_initialized(void) |
| 59 |
{ |
| 60 |
return addon_initialized; |
| 61 |
} |
| 62 |
|
| 63 |
/* Function: al_shutdown_primitives_addon |
| 64 |
*/ |
| 65 |
void al_shutdown_primitives_addon(void) |
| 66 |
{ |
| 67 |
addon_initialized = false; |
| 68 |
} |
| 69 |
|
| 70 |
/* Function: al_draw_prim |
| 71 |
*/ |
| 72 |
int al_draw_prim(const void* vtxs, const ALLEGRO_VERTEX_DECL* decl, |
| 73 |
ALLEGRO_BITMAP* texture, int start, int end, int type) |
| 74 |
{ |
| 75 |
ASSERT(addon_initialized); |
| 76 |
return _al_draw_prim(vtxs, decl, texture, start, end, type); |
| 77 |
} |
| 78 |
|
| 79 |
/* Function: al_draw_indexed_prim |
| 80 |
*/ |
| 81 |
int al_draw_indexed_prim(const void* vtxs, const ALLEGRO_VERTEX_DECL* decl, |
| 82 |
ALLEGRO_BITMAP* texture, const int* indices, int num_vtx, int type) |
| 83 |
{ |
| 84 |
ASSERT(addon_initialized); |
| 85 |
return _al_draw_indexed_prim(vtxs, decl, texture, indices, num_vtx, type); |
| 86 |
} |
| 87 |
|
| 88 |
/* Function: al_get_allegro_primitives_version |
| 89 |
*/ |
| 90 |
uint32_t al_get_allegro_primitives_version(void) |
| 91 |
{ |
| 92 |
return ALLEGRO_VERSION_INT; |
| 93 |
} |
| 94 |
|
| 95 |
/* Function: al_create_vertex_decl |
| 96 |
*/ |
| 97 |
ALLEGRO_VERTEX_DECL* al_create_vertex_decl(const ALLEGRO_VERTEX_ELEMENT* elements, int stride) |
| 98 |
{ |
| 99 |
ASSERT(addon_initialized); |
| 100 |
return _al_create_vertex_decl(elements, stride); |
| 101 |
} |
| 102 |
|
| 103 |
/* Function: al_destroy_vertex_decl |
| 104 |
*/ |
| 105 |
void al_destroy_vertex_decl(ALLEGRO_VERTEX_DECL* decl) |
| 106 |
{ |
| 107 |
_al_destroy_vertex_decl(decl); |
| 108 |
} |
| 109 |
|
| 110 |
/* Function: al_create_vertex_buffer |
| 111 |
*/ |
| 112 |
ALLEGRO_VERTEX_BUFFER* al_create_vertex_buffer(ALLEGRO_VERTEX_DECL* decl, |
| 113 |
const void* initial_data, int num_vertices, int flags) |
| 114 |
{ |
| 115 |
return _al_create_vertex_buffer(decl, initial_data, num_vertices, flags); |
| 116 |
} |
| 117 |
|
| 118 |
/* Function: al_create_index_buffer |
| 119 |
*/ |
| 120 |
ALLEGRO_INDEX_BUFFER* al_create_index_buffer(int index_size, |
| 121 |
const void* initial_data, int num_indices, int flags) |
| 122 |
{ |
| 123 |
return _al_create_index_buffer(index_size, initial_data, num_indices, flags); |
| 124 |
} |
| 125 |
|
| 126 |
/* Function: al_destroy_vertex_buffer |
| 127 |
*/ |
| 128 |
void al_destroy_vertex_buffer(ALLEGRO_VERTEX_BUFFER* buffer) |
| 129 |
{ |
| 130 |
_al_destroy_vertex_buffer(buffer); |
| 131 |
} |
| 132 |
|
| 133 |
/* Function: al_destroy_index_buffer |
| 134 |
*/ |
| 135 |
void al_destroy_index_buffer(ALLEGRO_INDEX_BUFFER* buffer) |
| 136 |
{ |
| 137 |
_al_destroy_index_buffer(buffer); |
| 138 |
} |
| 139 |
|
| 140 |
/* Function: al_lock_vertex_buffer |
| 141 |
*/ |
| 142 |
void* al_lock_vertex_buffer(ALLEGRO_VERTEX_BUFFER* buffer, int offset, |
| 143 |
int length, int flags) |
| 144 |
{ |
| 145 |
ASSERT(addon_initialized); |
| 146 |
return _al_lock_vertex_buffer(buffer, offset, length, flags); |
| 147 |
} |
| 148 |
|
| 149 |
/* Function: al_lock_index_buffer |
| 150 |
*/ |
| 151 |
void* al_lock_index_buffer(ALLEGRO_INDEX_BUFFER* buffer, int offset, |
| 152 |
int length, int flags) |
| 153 |
{ |
| 154 |
ASSERT(addon_initialized); |
| 155 |
return _al_lock_index_buffer(buffer, offset, length, flags); |
| 156 |
} |
| 157 |
|
| 158 |
/* Function: al_unlock_vertex_buffer |
| 159 |
*/ |
| 160 |
void al_unlock_vertex_buffer(ALLEGRO_VERTEX_BUFFER* buffer) |
| 161 |
{ |
| 162 |
ASSERT(addon_initialized); |
| 163 |
_al_unlock_vertex_buffer(buffer); |
| 164 |
} |
| 165 |
|
| 166 |
/* Function: al_unlock_index_buffer |
| 167 |
*/ |
| 168 |
void al_unlock_index_buffer(ALLEGRO_INDEX_BUFFER* buffer) |
| 169 |
{ |
| 170 |
ASSERT(addon_initialized); |
| 171 |
_al_unlock_index_buffer(buffer); |
| 172 |
} |
| 173 |
|
| 174 |
/* Function: al_draw_vertex_buffer |
| 175 |
*/ |
| 176 |
int al_draw_vertex_buffer(ALLEGRO_VERTEX_BUFFER* vertex_buffer, |
| 177 |
ALLEGRO_BITMAP* texture, int start, int end, int type) |
| 178 |
{ |
| 179 |
ASSERT(addon_initialized); |
| 180 |
return _al_draw_vertex_buffer(vertex_buffer, texture, start, end, type); |
| 181 |
} |
| 182 |
|
| 183 |
/* Function: al_draw_indexed_buffer |
| 184 |
*/ |
| 185 |
int al_draw_indexed_buffer(ALLEGRO_VERTEX_BUFFER* vertex_buffer, |
| 186 |
ALLEGRO_BITMAP* texture, ALLEGRO_INDEX_BUFFER* index_buffer, |
| 187 |
int start, int end, int type) |
| 188 |
{ |
| 189 |
ASSERT(addon_initialized); |
| 190 |
return _al_draw_indexed_buffer(vertex_buffer, texture, index_buffer, start, end, type); |
| 191 |
} |
| 192 |
|
| 193 |
/* Function: al_get_vertex_buffer_size |
| 194 |
*/ |
| 195 |
int al_get_vertex_buffer_size(ALLEGRO_VERTEX_BUFFER* buffer) |
| 196 |
{ |
| 197 |
return _al_get_vertex_buffer_size(buffer); |
| 198 |
} |
| 199 |
|
| 200 |
/* Function: al_get_index_buffer_size |
| 201 |
*/ |
| 202 |
int al_get_index_buffer_size(ALLEGRO_INDEX_BUFFER* buffer) |
| 203 |
{ |
| 204 |
return _al_get_index_buffer_size(buffer); |
| 205 |
} |