Jump to content
  • Advertisement
Sign in to follow this  
_goat

OpenGL Generic vertices - DirectX / OpenGL

This topic is 4553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm doing an Interactive Graphics course at my uni, and am going for extra credit. My problem is that I've been using DirectX in conjucture with my development of my graphics engine. From the outset, it's been designed to be API-independant, but I'm having trouble, due to the way DirectX and OpenGL handle the vertex data differently. DirectX: <3D Vertex 1> <3D Vertex 2> [vertex--normal--texture_coords---][--vertex--normal--te.... |______||______||_______________| <- knows striding of components |_________________________________| <- and striding of vertices DirectX strides across the data by the FVF. (As an aside, if this is not how it happens anymore, please let me know - I learnt that way back in DX8). OpenGL: <Vertex 1><Vertex 2><Vertex 3> |________| <- strides vertex by vertex OpenGL, with gl____Pointer, operates in a similar way, in that it asks for a chunk of memory and a stride. I could basically provide the same functionality as DirectX in OpenGL, by supplying a DX-like 3D vertex (make the distinction of a structure that holds the position, normal, texture coords) to the gl____Pointer functions, and passing the size of the whole 3d vertex as the stride. Like so: glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &vertices[0].Position); glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &vertices[0].Normal); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &vertices[0].TextureCoords); Now, it seems to work (in theory), flawlessly, but that's not really my problem. DirectX allows different types of vertices (via FVF). And I sort of liked the idea of variable data structures. It's at this point I'll ask if advanced techniques such as bump-mapping, light-mapping etc require extra data (maybe another float3 structure). If they don't, this point would be close to mute, however, not quite. Regardless, here's what I came up with (where NT is the number of textures):
template <class V = SVector<3>, class N = V, class T = SVector<2>, unsigned long NT = 1>
struct S3DVertex
{
	static const unsigned long TextureCount = NT;
	static const unsigned long Stride = sizeof(V) + sizeof(N) + sizeof(T) * NT;
	
	V position;
	N normal;
	T texture_coords[NT];
};

Is there a standard way of solving this problem? Or should I create a be-all-and-end-all vertex structure and use it exclusively?

Share this post


Link to post
Share on other sites
Advertisement
Okay, I've done some reading on glAttribPointer and D3DVERTEXELEMENT9s, and I'm wondering - it doesn't appear that OpenGL supports different streams? Or did I just miss the right link?

Share this post


Link to post
Share on other sites
The first parameter to glVertexAttribPointer is the generic vertex array index... i.e. "stream number".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!