Friday, January 21, 2011

Keeping the "Simple" in Simple DirectMedia Layer

SDL serves three types of video API users:
  1. People who just want a framebuffer and use SDL 1.2 blit and direct pixel access to do the job.
  2. People who just want an OpenGL context, and use OpenGL or OpenGL ES to do the job.
  3. People who want a hardware accelerated 2D API

For 1 and 2, the functionality was available in SDL 1.2 and the feature set is well understood.

For 3, this is a new area that SDL 1.3 is supporting, and it's really easy to lose the "Simple" in "Simple DirectMedia Layer"

So I think here is a good time to remember that the goal of the SDL rendering API is simply:

Hardware accelerate operations that were typically done with the SDL 1.2 API.

This is tricky, since people did lots of interesting things with direct framebuffer access, but let me break it down into a feature set:
  • copying images
  • filling rectangles
  • drawing single pixel lines
  • drawing single pixel points

SDL 1.2 provided colorkey, alpha channels, and per-surface alpha, as well as nearest pixel scaling.

Again, to break that down into a feature set:
  • blending for all operations
  • single vertex alpha for all operations
  • single vertex color for all operations
  • scaling for image copy operations

It's tempting to add functionality here, but that road lies madness...

4 comments:

  1. If fit in camp 1 at the moment but will eventually be in camp 3.

    So I have several choices
    a) Re-implement all my drawing functions in OpenGL
    b) Write my own functions to do the work that SDL does not.

    SDL offers more than just a canvas to the game programmer. It also offers simple window management, and input events. So by going to OpenGL I need to keep SDL around as well. It would be much nicer if the API could offer some expanded options, but not too many. Many API's become too rigid in what the end user can do, because of their fancy functionality.

    ReplyDelete
  2. Yeah, that's the trick. Everyone has their own idea of what "expanded options, but not too many" means.

    If you really want to do a lot more than what I described above, you're probably better off going to OpenGL anyway! :)

    ReplyDelete
  3. I fall in category 2 that is People who just want an OpenGL context, and use OpenGL or OpenGL ES to do the job.But its really good to know that SDL 1.3 is supporting, and it's really easy to lose the "Simple" in "Simple DirectMedia Layer. Thanks for sharing the information here

    ReplyDelete