[Patch included] OpenGL - Missing blue channel on Mac OS X

This particular forum is archives, bug reports should be made at https://github.com/visualboyadvance-m/v ... e-m/issues


Post Reply
x3ro
Junior Member
Posts: 3
Joined: Thu Mar 29, 2012 11:18 am

[Patch included] OpenGL - Missing blue channel on Mac OS X

Post by x3ro »

Hey there,

 

I took a shot at compiling VBA-M on OS X 10.7.3 and noticed that the blue color channel seemed to be completely absent:

 

Image

 

After some digging, I found out that the systemRed/Green/BlueShift were incorrect in that they didn't match what OpenGL expects when drawing GL_BGRA data. The miscalculation of the shifts is apparently caused by an oddity in SDL on OS X which seems to interpret the in the wrong endianess (maybe for backwards compatibility for software written for PowerPC??).

 

I wrote a fix for the issue that can be found here (excuse the wrong indentation, in case you want to apply this to your codebase I will of course supply a clean patch Image/emoticons/smile@2x.png 2x" width="20" height="20" /> ).

What my change does is an additional byte order check (I took the code from "test/testgl.c" in the SDL sources) if OpenGL is enabled. The resulting shifts have to be shifted an additional byte so that they properly align with OpenGL's BGRA.

I also changed GL_UNSIGNED_BYTE to GL_UNSIGNED_INT_8_8_8_8 as suggested here in order to prevent further endianess issues.

 

I tested the change on Ubuntu and OS X, but haven't tried it on Windows yet. I'm looking forward to some feedback and suggestions to improve the fix =)

 

PS: I built VBA-M from the latest revision available in the SVN repo

Last edited by x3ro on Fri Mar 30, 2012 9:06 am, edited 1 time in total.
mudlord
Senior Member
Posts: 306
Joined: Sun Feb 08, 2009 7:16 am

[Patch included] OpenGL - Missing blue channel on Mac OS X

Post by mudlord »

Nice find.

Are you running on a PowerPC arch, or Intel?

x3ro
Junior Member
Posts: 3
Joined: Thu Mar 29, 2012 11:18 am

[Patch included] OpenGL - Missing blue channel on Mac OS X

Post by x3ro »

I'm running on an Intel (i7). I don't know for sure why SDL does stuff differently on OS X than on an x86 Linux system, but me and a friend of mine guessed that they may simulate the wrong endianess in order to keep backwards compatibility with code written for PowerPC, but we haven't found any evidence yet.

Squall Leonhart
Posting Freak
Posts: 1223
Joined: Tue Mar 18, 2008 9:21 am

[Patch included] OpenGL - Missing blue channel on Mac OS X

Post by Squall Leonhart »

x3ro, can you supply a clean patch based on the current svn [img]<fileStore.core_Emoticons>/emoticons/smile.png[/img]/emoticons/smile@2x.png 2x" width="20" height="20" />

 

i'll do the appropriate merging into trunk and bgk's branch

x3ro
Junior Member
Posts: 3
Joined: Thu Mar 29, 2012 11:18 am

[Patch included] OpenGL - Missing blue channel on Mac OS X

Post by x3ro »

Hey there. As it seems, you already applied the patch and I just verified that it works on OS X 10.7.5 [img]<fileStore.core_Emoticons>/emoticons/smile.png[/img]/emoticons/smile@2x.png 2x" width="20" height="20" />

 

You might also want to include this patch, which fixes a compile error in GBALink.cpp on OS X: https://github.com/x3ro/VBA-M/commit/9e9d82414c708002107080f27b484b5f1fcc702d (the patch is also attached)

Last edited by x3ro on Tue Nov 20, 2012 2:39 am, edited 1 time in total.
Post Reply