Vertex positions and texture coordinates

Hi,
first off: Thank you for creating this library.

Now to my question: Is there a way to provide vertex positions and texture coordinates for each vertex of a quad directly? I couldn't find anything in the API.

In my current codebase every sprite caches its four vertices, so its kind of a waste to re-calculate positions in every draw call. A sprite also allows for being rotated and clipped at the same time and I don't see how I could achieve that in AgateLib (other than adding a sprite frame for every clipping rectangle possible). So for speed and memory reasons I'd like to re-use the current setup.

Maybe I am just missing some Surface or Sprite methods but I can also see how this kind of funtionality would be hard to provide in the System.Drawing driver.

Any help is appreciated.

-Michael

kanato
Posted - Tue, 03/17/2009 - 07:49

There is currently no way to specify vertex positions or texture coordinates for the vertices. I haven't found these calculations to have a significant impact on performance, although I suppose it depends on how much you are doing. They are optimized so calls like Math.Cos are made only once the rotation angle is changed for any given surface. Sprites in AgateLib can also manage their own texture memory, so being able to specify texture coordinates (at least in u/v coordinates that the video card expects) might not behave in the way they are expected to.

Clipping can be achieved by using Display.PushClipRect and Display.PopClipRect. Is that not sufficient for what you are doing? If not then it would help if you could explain what you need there in a little more detail.

michaelwoerister
Posted - Tue, 03/17/2009 - 09:04

Yes, I guess performance won't be much of a problem.

Clipping can be achieved by using Display.PushClipRect and Display.PopClipRect. Is that not sufficient for what you are doing?

Almost. I also want to allow for rotated clipping rectangles (just local to one sprite). Currently sprites in my code have a ClipArea property that is a rectangle in the sprite's local, normalized coordinate system (where (0,0) is the upper left corner and (1,1) is the lower right corner). If this property is set to ((0,0)(1,0.5)) for example only the upper half of the sprite is rendered, even if the sprite is rotated.

I think I can use the SurfaceImpl.Draw(float x, float y, Rectangle srcRect, float rotationCenterX, float rotationCenterY) method for now to achieve this.

kanato
Posted - Tue, 03/17/2009 - 12:47

Okay I see. Yeah, the Display.*ClipRect stuff is all in screen space coordinates. There is a corresponding method in Surface to the SurfaceImpl.Draw() method you mention, but it was internal in the last release. I've marked it as public in the Subversion trunk so it's available there if you are using the SVN version.

michaelwoerister
Posted - Wed, 03/18/2009 - 00:27

Thanks. That's a bit cleaner than using the impl directly.