What is a good code structure for api-independent vertex processing? [closed]

血红的双手。 提交于 2019-12-03 11:03:53

It has been a long time since I've done any directx or opengl, so take my advice with a grain of salt, but I remember doing something like this a while ago.

I think I did something like this:

var graphicsStream = new GraphicsStream();

var elements = graphicsStream.Create<Vector3>(Usage.Position);
graphicsStream.Create<Color>(Usage.Color);
graphicsStream.Create<Quaternion>(Usage.Fribble);

elements.SetData(new[] { new Vector3(), new Vector3() });

var vertexFormat = graphicsStream.GetFormat();
graphicsStream.Validate();  // ensure all the streams have the same length

// get a particular element by type
var p = graphicsStream.GetData(Usage.Position, 1);

You'd have a graphics stream which was a set of typed data sets with a usage applied. From this you can generate an appropriate vertex format. The API would let you change individual elements or upload and replace the entire vertex buffer in one go.

The biggest downside is that you don't have one structure that represents a "column" in your vertex structure.

I don't know if this is the kind of thing you're looking for. Why would a design like this not be appropriate?

You could have a look at how OGRE handles this. In particular The render system documentation about VertexElement and also the vertex buffer classes. OGRE is C++ but I am sure you will be able to get the design patterns easily converted to C#.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!