• Advertisement
Sign in to follow this  

Cross Platform Library Question

This topic is 633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all,

this is not a question on what library to use to develop a game, but this is different :)

i have a group of students who asked me how do libraries such as SDL handled their cross platform ability, i knw they use opengl and/or native like gdi, but how about the windowing system that works on 3 platforms (windows, linux, mac)

also, if there are articles, books and other resources for cross platform lib building (desktop and not mobile) please point me to it :)

this is just for education and research purposes and not for actual game dev, more like their final requirement before they graduate

thank you in advance

Share this post


Link to post
Share on other sites
Advertisement

To take the window creation and management as an example, SDL implements it separately (using the relevant OS-level API's) for each OS / platform it supports. Same for e.g. audio, joystick etc.

Share this post


Link to post
Share on other sites

To take the window creation and management as an example, SDL implements it separately (using the relevant OS-level API's) for each OS / platform it supports. Same for e.g. audio, joystick etc.

that's what i thought so too, like in windows, SDL uses win32 api, etc. 

i asked coz i thought they are using another way.. 

 

thanks

Share this post


Link to post
Share on other sites

that's what i thought so too, like in windows, SDL uses win32 api, etc. i asked coz i thought they are using another way..

 

It's not just a compile-time option.  For example, on Linux, libSDL2 autodetects whether the system renderer is X11, Mir, or Wayland automatically, then instantiates the appropriate back end (by loading a DSO) to handle the required operations.  On top of that, there's an EGL layer for handling OpenGL vs. OpenGL|ES and EGL itself needs to know the native renderer and window manager for context creation.  That gives you nine possible combinations of dynamically determined back ends on Linux alone.  None of that is compile-time, although the order in which back ends are autodetected is set at compile time (and at Ubuntu we switch the order so X11 is tried last instead of first).

 

Other supported platforms are simpler because they have a choice of one system renderer.

Share this post


Link to post
Share on other sites

There are some apis which can be implemented once and used on multiple OS.

E.g. network communication can mostly done with the berkeley socket api.

Windows need extra initialization but create, send, recv, bind and listen work the same.

C++ 11, 13 and 17 implemented threading, time(chronos), atomic operation, async io and so on but behind the scene they use also system api.

Windows, OSX, Linux use most of the posix api there are a couple of functions which are not implemented on different OS like fadvise but that are mostly optimization functions. In Windows the posix functions are wrapper to the specific windows apis and on linux they mostly call the kernel functions.

 

There are some traps which make it very hard to support multiplatform like assigning a thread a specific logical processor.

You need information about the hardware(NUMA, CPU features, CPU design) and how the OS handles the hardware.

Windows 10 and Windows95 have different ways to handle multi cpu systems and the way they assign the visible logical processor of a cpu to a mask. In the past they used a fix 32bit mask now they assign them to groups that you can use more then 32 logical processor on a system(the newest Intel Server CPU comes with 44 logical processor). This also means the function to assign your thread changed.

Linux and OSX handle this problem also in different ways because this goes deep down into the guts of the kernel design.

Windows e.g. enforce you to assign the thread after the thread started and entered the thread callback function and linux allows you to do it between creation and enter the thread callback function.

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement