Skip to content

Commit e18a22b

Browse files
author
Trent Gamblin
committed
Use al_have_opengl_extension in place of the removed EXT_multisampled_render_to_texture
1 parent e5e89cb commit e18a22b

File tree

2 files changed

+41
-188
lines changed

2 files changed

+41
-188
lines changed

src/macosx/hidjoy.m

+39-183
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@
5050
#define JOYSTICK_USAGE_NUMBER 0x04
5151
#define GAMEPAD_USAGE_NUMBER 0x05
5252

53-
#define JOYSTICK_NAME_MAX 256
54-
5553
typedef struct {
5654
ALLEGRO_JOYSTICK parent;
57-
char name[JOYSTICK_NAME_MAX];
5855
IOHIDElementRef buttons[_AL_MAX_JOYSTICK_BUTTONS];
5956
IOHIDElementRef axes[_AL_MAX_JOYSTICK_STICKS][_AL_MAX_JOYSTICK_AXES];
6057
IOHIDElementRef dpad;
@@ -133,37 +130,12 @@ static CFMutableDictionaryRef CreateDeviceMatchingDictionary(
133130
return result;
134131
}
135132

136-
static bool joystick_uses_element(ALLEGRO_JOYSTICK_OSX *joy, IOHIDElementRef elem)
137-
{
138-
int i, j;
139-
140-
if(elem) {
141-
for (i = 0; i < joy->parent.info.num_buttons; i++) {
142-
if(joy->buttons[i] == elem)
143-
return true;
144-
}
145-
for (i = 0; i < joy->parent.info.num_sticks; i++) {
146-
for(j = 0; j < joy->parent.info.stick[i].num_axes; j++) {
147-
if(joy->axes[i][j] == elem)
148-
return true;
149-
}
150-
}
151-
if (joy->dpad == elem)
152-
return true;
153-
}
154-
else {
155-
return true;
156-
}
157-
158-
return false;
159-
}
160-
161-
static ALLEGRO_JOYSTICK_OSX *find_joystick(IOHIDDeviceRef ident, IOHIDElementRef elem)
133+
static ALLEGRO_JOYSTICK_OSX *find_joystick(IOHIDDeviceRef ident)
162134
{
163135
int i;
164136
for (i = 0; i < (int)_al_vector_size(&joysticks); i++) {
165137
ALLEGRO_JOYSTICK_OSX *joy = *(ALLEGRO_JOYSTICK_OSX **)_al_vector_ref(&joysticks, i);
166-
if (ident == joy->ident && joystick_uses_element(joy, elem)) {
138+
if (ident == joy->ident) {
167139
return joy;
168140
}
169141
}
@@ -173,12 +145,10 @@ static bool joystick_uses_element(ALLEGRO_JOYSTICK_OSX *joy, IOHIDElementRef ele
173145

174146
static const char *get_element_name(IOHIDElementRef elem, const char *default_name)
175147
{
176-
const char *name_cstr = NULL;
177148
CFStringRef name = IOHIDElementGetName(elem);
178-
if (name)
179-
name_cstr = CFStringGetCStringPtr(name, kCFStringEncodingUTF8);
180-
if (name_cstr)
181-
return name_cstr;
149+
if (name) {
150+
return CFStringGetCStringPtr(name, kCFStringEncodingUTF8);
151+
}
182152
else
183153
return default_name;
184154
}
@@ -212,58 +182,31 @@ static void add_axis(ALLEGRO_JOYSTICK_OSX *joy, int stick_index, int axis_index,
212182
joy->axes[stick_index][axis_index] = elem;
213183
}
214184

215-
static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int device_joystick)
185+
static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy)
216186
{
217-
int i, start_i = 0;
187+
int i;
218188
char default_name[100];
219189
int stick_class = -1;
220190
int axis_index = 0;
221-
bool collection_started = false;
222-
int current_joystick = -1;
223191

224192
joy_null(joy);
225193

226-
/* look for device_joystick */
227194
for (i = 0; i < CFArrayGetCount(elements); i++) {
228195
IOHIDElementRef elem = (IOHIDElementRef)CFArrayGetValueAtIndex(
229196
elements,
230197
i
231198
);
232-
int etype = IOHIDElementGetType(elem);
233-
if (etype == kIOHIDElementTypeCollection) {
234-
collection_started = true;
235-
}
236-
else if (etype == kIOHIDElementTypeInput_Button || etype == kIOHIDElementTypeInput_Misc) {
237-
if (collection_started) {
238-
current_joystick++;
239-
collection_started = false;
240-
if (current_joystick == device_joystick) {
241-
start_i = i;
242-
break;
243-
}
244-
}
245-
}
246-
}
247-
248-
for (i = start_i; i < CFArrayGetCount(elements); i++) {
249-
IOHIDElementRef elem = (IOHIDElementRef)CFArrayGetValueAtIndex(
250-
elements,
251-
i
252-
);
253199

254200
int usage = IOHIDElementGetUsage(elem);
255-
if (IOHIDElementGetType(elem) == kIOHIDElementTypeCollection) {
256-
break;
257-
}
258201
if (IOHIDElementGetType(elem) == kIOHIDElementTypeInput_Button) {
259-
if (usage >= 0 && joy->parent.info.num_buttons < _AL_MAX_JOYSTICK_BUTTONS &&
260-
!joy->buttons[joy->parent.info.num_buttons]) {
261-
joy->buttons[joy->parent.info.num_buttons] = elem;
262-
sprintf(default_name, "Button %d", joy->parent.info.num_buttons);
202+
if (usage >= 0 && usage < _AL_MAX_JOYSTICK_BUTTONS &&
203+
!joy->buttons[usage-1]) {
204+
joy->buttons[usage-1] = elem;
205+
sprintf(default_name, "Button %d", usage-1);
263206
const char *name = get_element_name(elem, default_name);
264207
char *str = al_malloc(strlen(name)+1);
265208
strcpy(str, name);
266-
joy->parent.info.button[joy->parent.info.num_buttons].name = str;
209+
joy->parent.info.button[usage-1].name = str;
267210
joy->parent.info.num_buttons++;
268211
}
269212
}
@@ -273,33 +216,18 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
273216
long max = IOHIDElementGetLogicalMax(elem);
274217
int new_stick_class = -1;
275218
int stick_index = joy->parent.info.num_sticks - 1;
276-
int axis_type = -1;
277219

278220
switch (usage) {
279221
case kHIDUsage_GD_X:
280-
new_stick_class = 1;
281-
axis_type = 0;
282-
break;
283222
case kHIDUsage_GD_Y:
284-
new_stick_class = 1;
285-
axis_type = 1;
286-
break;
287223
case kHIDUsage_GD_Z:
288224
new_stick_class = 1;
289-
axis_type = 2;
290225
break;
291226

292227
case kHIDUsage_GD_Rx:
293-
new_stick_class = 2;
294-
axis_type = 0;
295-
break;
296228
case kHIDUsage_GD_Ry:
297-
new_stick_class = 2;
298-
axis_type = 1;
299-
break;
300229
case kHIDUsage_GD_Rz:
301230
new_stick_class = 2;
302-
axis_type = 2;
303231
break;
304232

305233
case kHIDUsage_GD_Hatswitch:
@@ -322,19 +250,7 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
322250
stick_class = new_stick_class;
323251

324252
char *buf = al_malloc(20);
325-
switch (stick_class) {
326-
case 1:
327-
sprintf(buf, "Primary Stick");
328-
break;
329-
case 2:
330-
sprintf(buf, "Secondary Stick");
331-
break;
332-
case 3:
333-
sprintf(buf, "Hat Switch");
334-
break;
335-
default:
336-
sprintf(buf, "Stick %d", stick_index);
337-
}
253+
sprintf(buf, "Stick %d", stick_index);
338254
joy->parent.info.stick[stick_index].name = buf;
339255
}
340256
else
@@ -345,14 +261,14 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
345261
joy->dpad = elem;
346262

347263
joy->dpad_axis_horiz = axis_index;
348-
sprintf(default_name, "X-Axis");
264+
sprintf(default_name, "Axis %i", axis_index);
349265
char *str = al_malloc(strlen(default_name)+1);
350266
strcpy(str, default_name);
351267
joy->parent.info.stick[stick_index].axis[axis_index].name = str;
352268

353269
++axis_index;
354270
joy->dpad_axis_vert = axis_index;
355-
sprintf(default_name, "Y-Axis");
271+
sprintf(default_name, "Axis %i", axis_index);
356272
str = al_malloc(strlen(default_name)+1);
357273
strcpy(str, default_name);
358274
add_axis(joy, stick_index, axis_index, min, max, str, elem);
@@ -361,19 +277,7 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
361277
joy->parent.info.stick[stick_index].num_axes = 2;
362278
}
363279
else {
364-
switch (axis_type) {
365-
case 0:
366-
sprintf(default_name, "X-Axis");
367-
break;
368-
case 1:
369-
sprintf(default_name, "Y-Axis");
370-
break;
371-
case 2:
372-
sprintf(default_name, "Z-Axis");
373-
break;
374-
default:
375-
sprintf(default_name, "Axis %i", axis_index);
376-
}
280+
sprintf(default_name, "Axis %i", axis_index);
377281
const char *name = get_element_name(elem, default_name);
378282
char *str = al_malloc(strlen(name)+1);
379283
strcpy(str, name);
@@ -394,92 +298,44 @@ static void osx_joy_generate_configure_event(void)
394298
_al_generate_joystick_event(&event);
395299
}
396300

397-
static int device_count_joysticks(IOHIDDeviceRef ref)
398-
{
399-
int i;
400-
int count = 0;
401-
bool collection_started = false;
402-
403-
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(
404-
ref,
405-
NULL,
406-
kIOHIDOptionsTypeNone
407-
);
408-
for (i = 0; i < CFArrayGetCount(elements); i++) {
409-
IOHIDElementRef elem = (IOHIDElementRef)CFArrayGetValueAtIndex(
410-
elements,
411-
i
412-
);
413-
414-
int etype = IOHIDElementGetType(elem);
415-
if (etype == kIOHIDElementTypeCollection) {
416-
collection_started = true;
417-
}
418-
else if (etype == kIOHIDElementTypeInput_Button || etype == kIOHIDElementTypeInput_Misc) {
419-
if (collection_started) {
420-
count++;
421-
collection_started = false;
422-
}
423-
}
424-
}
425-
CFRelease(elements);
426-
return count;
427-
}
428-
429-
static void device_setup_joystick(IOHIDDeviceRef ref, ALLEGRO_JOYSTICK_OSX *joy, int device_joystick)
430-
{
431-
CFStringRef product_name;
432-
joy->cfg_state = new_joystick_state;
433-
434-
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(
435-
ref,
436-
NULL,
437-
kIOHIDOptionsTypeNone
438-
);
439-
440-
add_elements(elements, joy, device_joystick);
441-
product_name = IOHIDDeviceGetProperty(ref, CFSTR(kIOHIDProductKey));
442-
if(product_name)
443-
{
444-
CFStringGetCString(product_name, joy->name, JOYSTICK_NAME_MAX, kCFStringEncodingUTF8);
445-
}
446-
CFRelease(elements);
447-
}
448-
449301
static void device_add_callback(
450302
void *context,
451303
IOReturn result,
452304
void *sender,
453305
IOHIDDeviceRef ref
454306
) {
455-
int i;
456-
int device_joysticks;
457307
(void)context;
458308
(void)result;
459309
(void)sender;
460310

461311
al_lock_mutex(add_mutex);
462312

463-
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref, NULL);
313+
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref);
464314
if (joy == NULL) {
465-
device_joysticks = device_count_joysticks(ref);
466-
for (i = 0; i < device_joysticks; i++) {
467-
joy = al_calloc(1, sizeof(ALLEGRO_JOYSTICK_OSX));
468-
joy->ident = ref;
469-
ALLEGRO_JOYSTICK_OSX **back = _al_vector_alloc_back(&joysticks);
470-
*back = joy;
471-
device_setup_joystick(ref, joy, i);
472-
ALLEGRO_INFO("Found joystick (%d buttons, %d sticks)\n",
473-
joy->parent.info.num_buttons, joy->parent.info.num_sticks);
474-
}
475-
}
476-
else {
477-
device_setup_joystick(ref, joy, 0);
315+
joy = al_calloc(1, sizeof(ALLEGRO_JOYSTICK_OSX));
316+
joy->ident = ref;
317+
ALLEGRO_JOYSTICK_OSX **back = _al_vector_alloc_back(&joysticks);
318+
*back = joy;
478319
}
320+
joy->cfg_state = new_joystick_state;
321+
322+
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(
323+
ref,
324+
NULL,
325+
kIOHIDOptionsTypeNone
326+
);
327+
328+
add_elements(elements, joy);
329+
330+
CFRelease(elements);
331+
479332

480333
al_unlock_mutex(add_mutex);
481334

482335
osx_joy_generate_configure_event();
336+
337+
ALLEGRO_INFO("Found joystick (%d buttons, %d sticks)\n",
338+
joy->parent.info.num_buttons, joy->parent.info.num_sticks);
483339
}
484340

485341
static void device_remove_callback(
@@ -576,7 +432,7 @@ static void value_callback(
576432

577433
IOHIDElementRef elem = IOHIDValueGetElement(value);
578434
IOHIDDeviceRef ref = IOHIDElementGetDevice(elem);
579-
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref, elem);
435+
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref);
580436

581437
if (!joy) return;
582438

@@ -877,8 +733,8 @@ static bool reconfigure_joysticks(void)
877733
// FIXME!
878734
static const char *get_joystick_name(ALLEGRO_JOYSTICK *joy_)
879735
{
880-
ALLEGRO_JOYSTICK_OSX *joy = (ALLEGRO_JOYSTICK_OSX *)joy_;
881-
return joy->name;
736+
(void)joy_;
737+
return "Joystick";
882738
}
883739

884740
static bool get_joystick_active(ALLEGRO_JOYSTICK *joy_)

src/opengl/ogl_fbo.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info)
183183

184184
bool extension_supported;
185185
#ifdef ALLEGRO_CFG_OPENGLES
186-
extension_supported = display->ogl_extras->extension_list->ALLEGRO_GL_EXT_multisampled_render_to_texture;
186+
extension_supported = al_have_opengl_extension("EXT_multisampled_render_to_texture");
187187
#else
188188
extension_supported = display->ogl_extras->extension_list->ALLEGRO_GL_EXT_framebuffer_multisample;
189189
#endif
@@ -605,10 +605,7 @@ static void use_fbo_for_bitmap(ALLEGRO_DISPLAY *display,
605605
/* Attach the texture. */
606606
#ifdef ALLEGRO_CFG_OPENGLES
607607
if (ANDROID_PROGRAMMABLE_PIPELINE(al_get_current_display())) {
608-
bool extension_supported = display->ogl_extras->
609-
extension_list->
610-
ALLEGRO_GL_EXT_multisampled_render_to_texture;
611-
if (al_get_bitmap_samples(bitmap) == 0 || !extension_supported) {
608+
if (al_get_bitmap_samples(bitmap) == 0 || !al_have_opengl_extension("EXT_multisampled_render_to_texture")) {
612609
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
613610
GL_TEXTURE_2D, ogl_bitmap->texture, 0);
614611
}

0 commit comments

Comments
 (0)