Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Small Change to allow GeometricPrimitives to draw PatchLists #282

Merged
merged 2 commits into from Feb 18, 2014

Conversation

dazerdude
Copy link
Contributor

Added an option to GeometricPrimitive to use a PatchList of 3 instead of
a TriangleList when drawing.

Added an option to GeometricPrimitive to use a PatchList of 3 instead of
a TriangleList when drawing.
@@ -175,7 +176,7 @@ public void Draw(GraphicsDevice graphicsDevice, EffectPass pass = null)
graphicsDevice.SetIndexBuffer(indexBuffer, isIndex32Bits);

// Finally Draw this mesh
graphicsDevice.DrawIndexed(PrimitiveType.TriangleList, indexBuffer.ElementCount);
graphicsDevice.DrawIndexed(usePatches ? PrimitiveType.PatchList(3) : PrimitiveType.TriangleList, indexBuffer.ElementCount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is better to pass PrimitiveType as parameter instead of executing an if branch at each draw call?
This would allow a greater flexibility.

We could add two overloads for the Draw method:

  1. public void Draw(GraphicsDevice graphicsDevice, EffectPass pass = null)
  2. public void Draw(GraphicsDevice graphicsDevice, PrimitiveType primitiveType, EffectPass pass = null)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would add greater flexibility, but currently I think that geometric primitives only build TriangleLists, so I'm not sure other PrimitiveTypes really make sense. Really, either would work here, it's really a preference of how safe do you want the toolkit to be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a whole lot more than TriangleLists, like TriangleStrips. I also hate functions being two functions at once having a bool passed to decide at runtime what they should do. This is bad style so I would support ArtiomsCiumac's aproach. If you want to reduce code, you better have the one method without PrimitiveType-Parameter just call the other with a predefined PrimitiveType. This makes it the same viewed from caller, but removes branching at runtime. Also you remain flexible to other PrimitiveTypes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that there are other PrimitiveTypes besides the two I've used. And I agree about your point that this isn't the best programming pattern. However, none of the current geometric primitives use anything besides TriangleLists, which is why it's currently hard coded as a TriangleList. As such, the question I was ask was whether we really want to expose the more generic function, or whether we would prefer the following pattern.

public void DrawTriList(GraphicsDevice graphicsDevice, EffectPass pass = null);
public void DrawPatch3(GraphicsDevice graphicsDevice, EffectPass pass = null);
protected void Draw(GraphicsDevice graphicsDevice, PrimitiveType primitiveType, EffectPass pass = null);

Clearly these names could be better, but this pattern prevents the developer from making a bad call, and the toolkit, generally speaking, is about providing a more user friendly experience. The question is, how user friendly do we want this api?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - but I'd at least prefer two methods as you suggested, to reduce branching. But this might be just my no-branching style from GPGPU-Programming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still insist on my proposal, as GeometricPrimitive class can be instantiated from an arbitrary arrays of vertex data. With DrawTriList I don't agree, as the functions will be too specialized. Let's leave the default as PrimitiveType.TriangleList.

If the developer will make a wrong call - those are his problems. A hammer manufacturer is not responsible for someone hitting his finger. There is always a balance between flexibility and safety.

@dazerdude, you made a good point about extending GeometricPrimitive functionality with this pull request - therefore adding a single overload (which accepts PrimitiveType as parameter) - will add a lot of possibilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound's good. I've updated the branch to be in line with your suggestion.

@ArtiomCiumac ArtiomCiumac merged commit 4cfeba8 into sharpdx:master_integration Feb 18, 2014
@ArtiomCiumac
Copy link
Contributor

merged. Thank you for contribution - this is one of those small enhancements which add big possibilities ;) Now the GeometricPrimitive class should support any type of primitive.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants