Author Topic: Move primitive drawing calls in to Surface  (Read 5681 times)

Offline sir_nacnud

  • Captain
  • ***
  • Posts: 54
    • View Profile
Move primitive drawing calls in to Surface
« on: November 18, 2010, 04:11:25 am »
I have been looking over the code base and noticed there are calls to SDL_gfx functions in multiple places.  Given there has been talk of switching to a different library for primitive rendering, this would involve changing multiple files.  If we were to have these primitive drawing functions in the Surface class, switching would involve updating one file.   Also if we wanted to support multiple rendering libraries, it would be simple as using a different implementation of Surface or something along those lines.  It is also probably a good idea to keep all code for doing pixel manipulation on SDL Surfaces in one place, again allowing easy switching of rendering solutions.

I am proposing we have functions in Surface like:

Surface::drawCircle()
Surface::drawPolygon()
Surface::drawTexturedPolygon()
Surface::drawLine()
...

SupSuper, if you are ok with this change, I will implement the necessary changes and submit a patch.

Offline michal

  • Commander
  • *****
  • Posts: 629
    • View Profile
Re: Move primitive drawing calls in to Surface
« Reply #1 on: November 18, 2010, 10:01:27 am »
Also if we wanted to support multiple rendering libraries, it would be simple as using a different implementation of Surface or something along those lines.

Unfortunately, there are more SDL code floating around. You would need to make abstraction for it too.

Generally, i like that idea. At least for primitive drawing, it should be done IMHO. As for totally abstracting SDL it would be great, but it would require much more work and i don't think it's good at that stage of project.

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2159
    • View Profile
Re: Move primitive drawing calls in to Surface
« Reply #2 on: November 18, 2010, 02:06:34 pm »
In general most SDL code is hidden away in more low-level classes, like Game, Surface, Action, etc, but it's impossible to completely abstract away SDL without duplicating work (eg. replicating SDL structs, etc).

I have considered moving all the primitive/drawing routines to Surface before (eg. replace SDL_FillRect with some Surface::drawRectangle), I just never got around to it because the drawing operations I use tend to vary a lot. But if you want to do it, go ahead.

Offline sir_nacnud

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: Move primitive drawing calls in to Surface
« Reply #3 on: November 19, 2010, 07:00:43 am »
I have considered moving all the primitive/drawing routines to Surface before (eg. replace SDL_FillRect with some Surface::drawRectangle), I just never got around to it because the drawing operations I use tend to vary a lot. But if you want to do it, go ahead.


Good deal.  I will start working on it and submit a patch when it is ready.