pspdev / psplibraries

A script to automatically build open-source libraries for PSP homebrew development.
47 stars 45 forks source link

SDL - Enabling all OpenGL functions provided by PSP-GL *by default* #39

Closed dbeef closed 4 years ago

dbeef commented 4 years ago

Synopsis:

I've been developing my PSP project utilizing SDL 1.2.15 that you provide within psplibraries repository (well, thing you provide is scripts and patches for building, but you get it).

I successfuly built PSP toolchain, installed SDL and began development.

As I wanted to provide some abstraction layer, namely by using glad, to not rely on system headers when building I stumbled on a problem - creating OpenGL context on a PSP using SDL was successful, glad didn't fail on loading OpenGL functions, but emulator still crashed in runtime, when it came to execute OpenGL functions.

I checked glad's pointers to OpenGL functions and they were all null.

Some experimenting of mine has shown, that some functions fail, but some not. After some recursive grepping through SDL's sources I found SDL_glfuncs.h (as I included patch to this specific file in this MR, you can open diff to have some knowledge what lies there)

Weirdly, all functions that were preceded with SDL_PROC_UNUSED crashed emulator, and those with SDL_PROC didn't.

After I annotated all of them with SDL_PROC I had linking errors:

/usr/local/pspdev/psp/lib/libSDL.a(SDL_pspgl.o):(.rodata+0x9e4): undefined reference to glVertex2s
/usr/local/pspdev/psp/lib/libSDL.a(SDL_pspgl.o):(.rodata+0x9ec): undefined reference to glVertex2sv
/usr/local/pspdev/psp/lib/libSDL.a(SDL_pspgl.o):(.rodata+0xa1c): undefined reference to glVertex3iv
/usr/local/pspdev/psp/lib/libSDL.a(SDL_pspgl.o):(.rodata+0xa24): undefined reference to glVertex3s
/usr/local/pspdev/psp/lib/libSDL.a(SDL_pspgl.o):(.rodata+0xa2c): undefined reference to glVertex3sv
/usr/local/pspdev/psp/lib/libSDL.a(SDL_pspgl.o):(.rodata+0xa34): undefined reference to glVertex4d

(it was 200 lines, shortened it for clarity)

I understood, that PSP-GL that lies under this particular SDL implementation, does not provide all of those OpenGL function-definitions. So I prefixed again all functions that raised undefined reference with SDL_PROC_UNUSED - those that I needed were still there, so I was happy.

I recompiled SDL and that was it - linking succeeded. Now I can build an artifact of my code on PC / PSP from the same codebase ;)

You can clone it from here: https://github.com/dbeef/spelunky-psp Build scripts are under /scripts Obviously, only thing it does now is blinking, but it blinks in a proud, cross-platform way ;)

dbeef commented 4 years ago

@ooPo, sorry to bother you but I see you're the only maintainer responding to this MR for a whole month, and activity on pspdev projects is just flatline. Any way of merging to master, having only your approval?

I introduce changes of no risk to break anyone's build, in the same time allowing me to build my own project, which is why I care.

ooPo commented 4 years ago

@dbeef Sure thing, I can merge it. I only held back because I've not been active lately and didn't want to step on any toes.

dbeef commented 4 years ago

Thanks!