Ok... here's another thing I'm trying to work out: vertex types and input layouts (can't remember what the OpenGL counterpart of an input layout is called... usage hint, maybe?)...
I need to design a sub-system through which new vertex structures can be implemented beyond the common ones the engine will already offer, and the ones I do offer need to adhere to a clean, consistent format. It needs to be written so that the same data can be used to create an D3D "input layout" or an OpenGL "usage hint" (or whatever it's called) on-the-fly as the vertex data is pushed to the renderer. It's hard for me to decide on things sometimes because I'm not sure what parts/features of D3D and OpenGL are so seldomly used that they can just be cut out, and which people are going to be pissed if I don't let them have... Anyway, some of the ideas I have are:
The first thing to consider is how we designate what fields of a vertex are for (and how big they are). We could, like DirectX, just use a string (e.g., "POSITION"). Or we could use some type of enumeration, like this:
[source lang="csharp"] public enum VertexElements
{
NULL = 0x0000,
POSITION = 0x0001,
COLOR = 0x0002,
TEXCOORD = 0x0004,
NORMAL = 0x0008,
BINORMAL = 0x0016,
TANGENT = 0x0032
};[/source]
What might the pros/cons of each method be? And what would be a good way to represent the size of vertex fields without using a platform-specific enumeration like SlimDX's "Format" enum? Or is there yet another unthought-of way of doing this that would be superior to both?
Next, what would be the best way to implement a cohesive vertex typing system that can be broken-down and understood by virtually any type of renderer? I have some thoughts already, and I'll show you what ideas I'm toying with:
1) A common interface all vertex structures inherit from. For example:
[source lang="csharp"] [StructLayout(LayoutKind.Sequential)]
public interface IVertex
{
int SizeInBytes { get; }
VertexElements[] Elements { get; }
byte[] ToBytes();
};[/source]
All vertex types would implement that interface if such a method was used, and they would have to return a static value which is not part of the memory of an actual vertex instance on the stack (as that would throw things off).
2) Create a new struct/class (e.g., "VertexDescription") that houses a nice description of a vertex-type and tells you what's in its guts. The essence of it might look like this (incomplete example):
[source lang="csharp"] public class VertexLayout
{
int sizeInBytes;
VertexElements[] elements;
};[/source]
In addition to this structure, perhabs it might be an idea to implement a new enumeration type which replaces platform-specific enumerations like SlimDX's "Format" but offers the same data in a new way; potential even giving the size in bytes of an element as its own numerical value!?
[source lang="csharp"] public enum ElementFormat
{
byteX1 = 1,
byteX2 = 2,
byteX3 = 3,
byteX4 = 4,
shortX1 = 2,
shortX2 = 4,
// ...and so on...
};[/source]
Anyway, I hope the wisdom of the community can once again offer me some excellent ideas!
EDIT: The idea of assigning the enum values of "ElementFormat" the size on the element in bytes actually wont work because C# treats enums as numeric values and would not be able to distinguish between them. My bad, didn't think about that. Please disregard that erroneous idea.