PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

two pass creation of surface in PHAL

Pejo Software - Per · 01 Feb 2004, 20:48 UTC
I would have liked to have a default contructor and a Create/Init function for PHAL surfaces. Could this be something?
Pejo Software - Per wrote:I would have liked to have a default contructor and a Create/Init function for PHAL surfaces. Could this be something?


I am sorry, but the short answer is no. A longer answer would be that this would result in a bad design. It would allow you to create surfaces in an invalid state (no initialized).

I am curious to know why you need such functionality?

If you really need it, I guess you can write your own Surface class that wraps PHAL's?
Pejo Software - Per · 02 Feb 2004, 07:57 UTC
OK I'll wrap it in my own Surface class then.
Two pass creation could be useful in many cases. For example: when I want to create a Surface from a png.
Thanks Thierry for worrying about my(and others) design :).
Agree, two pass creation is not a good idea but .. having resize(int x,int y) method available would be nice :-)
The way I load images is like this:

1) Get the file header to retrieve the width and height
2) Create the surface (width x height)
3) Load the image data in the surface

If you are loading an image into some other temporary buffer then:

1) Load image
2) Create the surface (width x height)
3) Blit the image into the surface

In both cases I don't see the need for a two-step process. It is my believe that the less things you need, the better the library is (smaller, faster and less errors are possible).

Let me know if I am missing anything.
warmi wrote:Agree, two pass creation is not a good idea but .. having resize(int x,int y) method available would be nice :-)


The only way I could implement a resize() function would be like this:

1) Create a new surface (with the new size)
2) Blit the old surface into the new one
3) Replace the old surface with the new one

So that is really expensive and something that can be done easily by the user. I don't see the point in having this in the library itself.

Resizing surfaces just seems a bad idea in the first place.
No, I meant destructive resize.
Basically a scenario when one creates a surface and then goes to reuse it for different things (different size etc ..)
It simplifies life for the user ( as it should be the case with all libraries) since he/she doesn't have to create/destroy new objects.
But like Pejo Software said, I already wrapped HAL::Surface into my own code ( I was going to derive from it but issues like lack of resizing etc prevented me from doing it) so it is not a big issue for me.
OK... Well the PHAL's Surface is not meant to be your perfect surface class. It is just a really simple and basic implementation used to give you access to the backbuffer.

The user should definitely implement it's own surface class if it is needed. That's what I am doing with PF right now...