Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Limit the amount of vertices drawn  (Read 4311 times)

0 Members and 1 Guest are viewing this topic.

Chris12

  • Newbie
  • *
  • Posts: 20
    • View Profile
Limit the amount of vertices drawn
« on: March 07, 2012, 09:49:58 pm »
Hi there,
I have a custom vertex array (not the VertexArray class).
And when drawing I sometimes only want to draw the first N quads, not all.

This is for a particle effect, if there are only 20 out of 2000 particles "alive", I don't want to draw all 2000.

Draw(vertices, PrimitiveType, renderStates) is missing something like a "count" parameter to specify this ?
Or how do I do this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Limit the amount of vertices drawn
« Reply #1 on: March 07, 2012, 10:18:32 pm »
Doesn't .Net provide a simple way to get a sub-array from a bigger array?

If not, then I can probably add an explicit count, yes.
Laurent Gomila - SFML developer

Chris12

  • Newbie
  • *
  • Posts: 20
    • View Profile
Limit the amount of vertices drawn
« Reply #2 on: March 07, 2012, 11:07:30 pm »
The only possible way would be copying out the part of the array I want to render.
But since there is a (hidden) maximum variable, i'd rather use use that.

Chris12

  • Newbie
  • *
  • Posts: 20
    • View Profile
Limit the amount of vertices drawn
« Reply #3 on: March 07, 2012, 11:41:45 pm »
By the way: RenderStates is somehow buggy.

When I use the following renderstates, the program crashes:

Code: [Select]

renderStates = new RenderStates(Texture);
renderStates.BlendMode = BlendMode.Add;

target.Draw(vertices, PrimitiveType.Quads, renderStates);


"Access Violation" inside this:
           
                     
Code: [Select]
  sfRenderWindow_DrawPrimitives(CPointer, vertexPtr, (uint)vertices.Length, type, states.Marshal());


EDITED:
But when I try it that way, it works without problems:
Code: [Select]

var va = new VertexArray(PrimitiveType.Quads);
for (int i = 0; i < particles.Count; i++)
{
va.Append(vertices[i * 4 + 0]);
va.Append(vertices[i * 4 + 1]);
va.Append(vertices[i * 4 + 2]);
va.Append(vertices[i * 4 + 3]);
}

va.Draw(target, renderState);


That would be very inefficient. But strangely it works.
Maybe only the vertexarray should draw vertices ? But why does RenderTarget.Draw() have an overload that allows drawing Vertex[] types directly ????

I'm using that method for now :/
I hope its only a small bug.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Limit the amount of vertices drawn
« Reply #4 on: March 08, 2012, 08:19:39 am »
Quote
The only possible way would be copying out the part of the array I want to render.
But since there is a (hidden) maximum variable, i'd rather use use that.

Hmm ok, I'll do it.

Quote
By the way: RenderStates is somehow buggy.

Is it better now? Sorry I haven't tested the fix.

Quote
But why does RenderTarget.Draw() have an overload that allows drawing Vertex[] types directly ????

For the same reason that you're not using VertexArray ;)
Laurent Gomila - SFML developer

Chris12

  • Newbie
  • *
  • Posts: 20
    • View Profile
Limit the amount of vertices drawn
« Reply #5 on: March 08, 2012, 11:29:28 am »
Yeah, now it works, thank you.