Page 1 of 1

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

Posted: Thu Mar 29, 2012 2:41 pm
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


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

Posted: Thu Mar 29, 2012 10:08 pm
by mudlord

Nice find.

Are you running on a PowerPC arch, or Intel?


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

Posted: Fri Mar 30, 2012 5:11 am
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.


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

Posted: Mon Nov 19, 2012 10:37 pm
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


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

Posted: Tue Nov 20, 2012 2:36 am
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)