I thought that I was just going to give up on understanding how Libretro renders graphics. However, I still had this urge of solving this problem.
That turned out to be a good thing.
After reading on other engines and thinking just how Libretro handles this stuff directly, I took another look at the example code and actually built the example. I then spent my time reading the code, adding my own comments there. I found out that I was ignorant or mistaken in a few points.
- A software framebuffer, in the case of Libretro, refers to a 2D array in memory. Each cell in that array represents a pixel.
- The “cb” in “video_cb” means “callback.”
- Retro_video_refresh_t, in reality, is a function that renders the actual frame, taking the data, both dimensions, and pitch.
- Speaking of “pitch”, that actually refers to the number of bytes between any two lines in the buffer, that is, the length of a scanline. The “stride” variable refers to the pitch.
- The mouse is not involved in the demo; I was looking at variables that had the name “mouse” in them. They actually refer to the pitch.
My plans have me uploading my comments on the code later. Right now, I shall give what seems to be the general procedure in software rendering using Libretro.
In a nutshell:
- Declare a bitwise 2D array in memory. This is an abstraction of your framebuffer.
- Call retro_video_refresh_t, putting its contents in a static variable.
- Call retro_get_system_av_info, putting information that relates to the framebuffer.
- Make a static void function.
- In that function, copy into a local variable the contents of the array in Step 1.
- In the same function, fill the cells you want in that array with pixel data.
- In the same function, put the buffer, its dimensions and pitch in the variable in Step 2.
- At runtime, call that function.
- At the time of actually loading the game, set the pixel format.
The issue now is that I have to figure out how to either convert lodepng’s RGBA format to RGB565 or how to use Libretro’s own rpng.
Either way, I do not feel lost anymore today.