Skip to content

Commit

Permalink
Use al_have_opengl_extension in place of the removed EXT_multisampled…
Browse files Browse the repository at this point in the history
…_render_to_texture
  • Loading branch information
Trent Gamblin committed Aug 10, 2016
1 parent e5e89cb commit e18a22b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 188 deletions.
222 changes: 39 additions & 183 deletions src/macosx/hidjoy.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@
#define JOYSTICK_USAGE_NUMBER 0x04
#define GAMEPAD_USAGE_NUMBER 0x05

#define JOYSTICK_NAME_MAX 256

typedef struct {
ALLEGRO_JOYSTICK parent;
char name[JOYSTICK_NAME_MAX];
IOHIDElementRef buttons[_AL_MAX_JOYSTICK_BUTTONS];
IOHIDElementRef axes[_AL_MAX_JOYSTICK_STICKS][_AL_MAX_JOYSTICK_AXES];
IOHIDElementRef dpad;
Expand Down Expand Up @@ -133,37 +130,12 @@ static CFMutableDictionaryRef CreateDeviceMatchingDictionary(
return result;
}

static bool joystick_uses_element(ALLEGRO_JOYSTICK_OSX *joy, IOHIDElementRef elem)
{
int i, j;

if(elem) {
for (i = 0; i < joy->parent.info.num_buttons; i++) {
if(joy->buttons[i] == elem)
return true;
}
for (i = 0; i < joy->parent.info.num_sticks; i++) {
for(j = 0; j < joy->parent.info.stick[i].num_axes; j++) {
if(joy->axes[i][j] == elem)
return true;
}
}
if (joy->dpad == elem)
return true;
}
else {
return true;
}

return false;
}

static ALLEGRO_JOYSTICK_OSX *find_joystick(IOHIDDeviceRef ident, IOHIDElementRef elem)
static ALLEGRO_JOYSTICK_OSX *find_joystick(IOHIDDeviceRef ident)
{
int i;
for (i = 0; i < (int)_al_vector_size(&joysticks); i++) {
ALLEGRO_JOYSTICK_OSX *joy = *(ALLEGRO_JOYSTICK_OSX **)_al_vector_ref(&joysticks, i);
if (ident == joy->ident && joystick_uses_element(joy, elem)) {
if (ident == joy->ident) {
return joy;
}
}
Expand All @@ -173,12 +145,10 @@ static bool joystick_uses_element(ALLEGRO_JOYSTICK_OSX *joy, IOHIDElementRef ele

static const char *get_element_name(IOHIDElementRef elem, const char *default_name)
{
const char *name_cstr = NULL;
CFStringRef name = IOHIDElementGetName(elem);
if (name)
name_cstr = CFStringGetCStringPtr(name, kCFStringEncodingUTF8);
if (name_cstr)
return name_cstr;
if (name) {
return CFStringGetCStringPtr(name, kCFStringEncodingUTF8);
}
else
return default_name;
}
Expand Down Expand Up @@ -212,58 +182,31 @@ static void add_axis(ALLEGRO_JOYSTICK_OSX *joy, int stick_index, int axis_index,
joy->axes[stick_index][axis_index] = elem;
}

static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int device_joystick)
static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy)
{
int i, start_i = 0;
int i;
char default_name[100];
int stick_class = -1;
int axis_index = 0;
bool collection_started = false;
int current_joystick = -1;

joy_null(joy);

/* look for device_joystick */
for (i = 0; i < CFArrayGetCount(elements); i++) {
IOHIDElementRef elem = (IOHIDElementRef)CFArrayGetValueAtIndex(
elements,
i
);
int etype = IOHIDElementGetType(elem);
if (etype == kIOHIDElementTypeCollection) {
collection_started = true;
}
else if (etype == kIOHIDElementTypeInput_Button || etype == kIOHIDElementTypeInput_Misc) {
if (collection_started) {
current_joystick++;
collection_started = false;
if (current_joystick == device_joystick) {
start_i = i;
break;
}
}
}
}

for (i = start_i; i < CFArrayGetCount(elements); i++) {
IOHIDElementRef elem = (IOHIDElementRef)CFArrayGetValueAtIndex(
elements,
i
);

int usage = IOHIDElementGetUsage(elem);
if (IOHIDElementGetType(elem) == kIOHIDElementTypeCollection) {
break;
}
if (IOHIDElementGetType(elem) == kIOHIDElementTypeInput_Button) {
if (usage >= 0 && joy->parent.info.num_buttons < _AL_MAX_JOYSTICK_BUTTONS &&
!joy->buttons[joy->parent.info.num_buttons]) {
joy->buttons[joy->parent.info.num_buttons] = elem;
sprintf(default_name, "Button %d", joy->parent.info.num_buttons);
if (usage >= 0 && usage < _AL_MAX_JOYSTICK_BUTTONS &&
!joy->buttons[usage-1]) {
joy->buttons[usage-1] = elem;
sprintf(default_name, "Button %d", usage-1);
const char *name = get_element_name(elem, default_name);
char *str = al_malloc(strlen(name)+1);
strcpy(str, name);
joy->parent.info.button[joy->parent.info.num_buttons].name = str;
joy->parent.info.button[usage-1].name = str;
joy->parent.info.num_buttons++;
}
}
Expand All @@ -273,33 +216,18 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
long max = IOHIDElementGetLogicalMax(elem);
int new_stick_class = -1;
int stick_index = joy->parent.info.num_sticks - 1;
int axis_type = -1;

switch (usage) {
case kHIDUsage_GD_X:
new_stick_class = 1;
axis_type = 0;
break;
case kHIDUsage_GD_Y:
new_stick_class = 1;
axis_type = 1;
break;
case kHIDUsage_GD_Z:
new_stick_class = 1;
axis_type = 2;
break;

case kHIDUsage_GD_Rx:
new_stick_class = 2;
axis_type = 0;
break;
case kHIDUsage_GD_Ry:
new_stick_class = 2;
axis_type = 1;
break;
case kHIDUsage_GD_Rz:
new_stick_class = 2;
axis_type = 2;
break;

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

char *buf = al_malloc(20);
switch (stick_class) {
case 1:
sprintf(buf, "Primary Stick");
break;
case 2:
sprintf(buf, "Secondary Stick");
break;
case 3:
sprintf(buf, "Hat Switch");
break;
default:
sprintf(buf, "Stick %d", stick_index);
}
sprintf(buf, "Stick %d", stick_index);
joy->parent.info.stick[stick_index].name = buf;
}
else
Expand All @@ -345,14 +261,14 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
joy->dpad = elem;

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

++axis_index;
joy->dpad_axis_vert = axis_index;
sprintf(default_name, "Y-Axis");
sprintf(default_name, "Axis %i", axis_index);
str = al_malloc(strlen(default_name)+1);
strcpy(str, default_name);
add_axis(joy, stick_index, axis_index, min, max, str, elem);
Expand All @@ -361,19 +277,7 @@ static void add_elements(CFArrayRef elements, ALLEGRO_JOYSTICK_OSX *joy, int dev
joy->parent.info.stick[stick_index].num_axes = 2;
}
else {
switch (axis_type) {
case 0:
sprintf(default_name, "X-Axis");
break;
case 1:
sprintf(default_name, "Y-Axis");
break;
case 2:
sprintf(default_name, "Z-Axis");
break;
default:
sprintf(default_name, "Axis %i", axis_index);
}
sprintf(default_name, "Axis %i", axis_index);
const char *name = get_element_name(elem, default_name);
char *str = al_malloc(strlen(name)+1);
strcpy(str, name);
Expand All @@ -394,92 +298,44 @@ static void osx_joy_generate_configure_event(void)
_al_generate_joystick_event(&event);
}

static int device_count_joysticks(IOHIDDeviceRef ref)
{
int i;
int count = 0;
bool collection_started = false;

CFArrayRef elements = IOHIDDeviceCopyMatchingElements(
ref,
NULL,
kIOHIDOptionsTypeNone
);
for (i = 0; i < CFArrayGetCount(elements); i++) {
IOHIDElementRef elem = (IOHIDElementRef)CFArrayGetValueAtIndex(
elements,
i
);

int etype = IOHIDElementGetType(elem);
if (etype == kIOHIDElementTypeCollection) {
collection_started = true;
}
else if (etype == kIOHIDElementTypeInput_Button || etype == kIOHIDElementTypeInput_Misc) {
if (collection_started) {
count++;
collection_started = false;
}
}
}
CFRelease(elements);
return count;
}

static void device_setup_joystick(IOHIDDeviceRef ref, ALLEGRO_JOYSTICK_OSX *joy, int device_joystick)
{
CFStringRef product_name;
joy->cfg_state = new_joystick_state;

CFArrayRef elements = IOHIDDeviceCopyMatchingElements(
ref,
NULL,
kIOHIDOptionsTypeNone
);

add_elements(elements, joy, device_joystick);
product_name = IOHIDDeviceGetProperty(ref, CFSTR(kIOHIDProductKey));
if(product_name)
{
CFStringGetCString(product_name, joy->name, JOYSTICK_NAME_MAX, kCFStringEncodingUTF8);
}
CFRelease(elements);
}

static void device_add_callback(
void *context,
IOReturn result,
void *sender,
IOHIDDeviceRef ref
) {
int i;
int device_joysticks;
(void)context;
(void)result;
(void)sender;

al_lock_mutex(add_mutex);

ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref, NULL);
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref);
if (joy == NULL) {
device_joysticks = device_count_joysticks(ref);
for (i = 0; i < device_joysticks; i++) {
joy = al_calloc(1, sizeof(ALLEGRO_JOYSTICK_OSX));
joy->ident = ref;
ALLEGRO_JOYSTICK_OSX **back = _al_vector_alloc_back(&joysticks);
*back = joy;
device_setup_joystick(ref, joy, i);
ALLEGRO_INFO("Found joystick (%d buttons, %d sticks)\n",
joy->parent.info.num_buttons, joy->parent.info.num_sticks);
}
}
else {
device_setup_joystick(ref, joy, 0);
joy = al_calloc(1, sizeof(ALLEGRO_JOYSTICK_OSX));
joy->ident = ref;
ALLEGRO_JOYSTICK_OSX **back = _al_vector_alloc_back(&joysticks);
*back = joy;
}
joy->cfg_state = new_joystick_state;

CFArrayRef elements = IOHIDDeviceCopyMatchingElements(
ref,
NULL,
kIOHIDOptionsTypeNone
);

add_elements(elements, joy);

CFRelease(elements);


al_unlock_mutex(add_mutex);

osx_joy_generate_configure_event();

ALLEGRO_INFO("Found joystick (%d buttons, %d sticks)\n",
joy->parent.info.num_buttons, joy->parent.info.num_sticks);
}

static void device_remove_callback(
Expand Down Expand Up @@ -576,7 +432,7 @@ static void value_callback(

IOHIDElementRef elem = IOHIDValueGetElement(value);
IOHIDDeviceRef ref = IOHIDElementGetDevice(elem);
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref, elem);
ALLEGRO_JOYSTICK_OSX *joy = find_joystick(ref);

if (!joy) return;

Expand Down Expand Up @@ -877,8 +733,8 @@ static bool reconfigure_joysticks(void)
// FIXME!
static const char *get_joystick_name(ALLEGRO_JOYSTICK *joy_)
{
ALLEGRO_JOYSTICK_OSX *joy = (ALLEGRO_JOYSTICK_OSX *)joy_;
return joy->name;
(void)joy_;
return "Joystick";
}

static bool get_joystick_active(ALLEGRO_JOYSTICK *joy_)
Expand Down
7 changes: 2 additions & 5 deletions src/opengl/ogl_fbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info)

bool extension_supported;
#ifdef ALLEGRO_CFG_OPENGLES
extension_supported = display->ogl_extras->extension_list->ALLEGRO_GL_EXT_multisampled_render_to_texture;
extension_supported = al_have_opengl_extension("EXT_multisampled_render_to_texture");
#else
extension_supported = display->ogl_extras->extension_list->ALLEGRO_GL_EXT_framebuffer_multisample;
#endif
Expand Down Expand Up @@ -605,10 +605,7 @@ static void use_fbo_for_bitmap(ALLEGRO_DISPLAY *display,
/* Attach the texture. */
#ifdef ALLEGRO_CFG_OPENGLES
if (ANDROID_PROGRAMMABLE_PIPELINE(al_get_current_display())) {
bool extension_supported = display->ogl_extras->
extension_list->
ALLEGRO_GL_EXT_multisampled_render_to_texture;
if (al_get_bitmap_samples(bitmap) == 0 || !extension_supported) {
if (al_get_bitmap_samples(bitmap) == 0 || !al_have_opengl_extension("EXT_multisampled_render_to_texture")) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, ogl_bitmap->texture, 0);
}
Expand Down

3 comments on commit e18a22b

@NewCreature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this commit accidentally reverted the joystick code to an older version. I see that there were some recent commits related to joystick code on MacOS which might address some of the issues in a different way. I may go back over the newest joystick code and see if any of the reverted changes from this commit need to be re-implemented on top of the newest version of the code.

@SiegeLord
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional to some extent, there was some incompatibility that it introduced. I saved the change as a pull request: #662 Don't recall what the other more recent changes did.

@NewCreature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Thanks for the explanation.

Please sign in to comment.