Understanding Graphics

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:

  1. Declare a bitwise 2D array in memory. This is an abstraction of your framebuffer.
  2. Call retro_video_refresh_t, putting its contents in a static variable.
  3. Call retro_get_system_av_info, putting information that relates to the framebuffer.
  4. Make a static void function.
  5. In that function, copy into a local variable the contents of the array in Step 1.
  6. In the same function, fill the cells you want in that array with pixel data.
  7. In the same function, put the buffer, its dimensions and pitch in the variable in Step 2.
  8. At runtime, call that function.
  9. 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.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s