Sign in to follow this  

MEMCPY - some problems

This topic is 3787 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

If I have 2 structs for CUSTOM VERTEX...how can i copy both to the vertex buffer struct CUSTOMVERTEX2{FLOAT X,Y,Z;DWORD COLOR;FLOAT U,V;}; struct CUSTOMVERTEX1{FLOAT X, Y, Z; DWORD COLOR;}; memcpy(pVoid, CUSTOMVERTEX1, sizeof(CUSTOMVERTEX1)); memcpy(pVoid, CUSTOMVERTEX2, sizeof(CUSTOMVERTEX2)); this is not working :| ...what I should do? I'm using VC++, DirectX9

Share this post


Link to post
Share on other sites
Quote:
Original post by johnny_no1_boy
If I have 2 structs for CUSTOM VERTEX...how can i copy both to the vertex buffer

struct CUSTOMVERTEX2{FLOAT X,Y,Z;DWORD COLOR;FLOAT U,V;};
struct CUSTOMVERTEX1{FLOAT X, Y, Z; DWORD COLOR;};

memcpy(pVoid, CUSTOMVERTEX1, sizeof(CUSTOMVERTEX1));
memcpy(pVoid, CUSTOMVERTEX2, sizeof(CUSTOMVERTEX2));
this is not working :| ...what I should do?

I'm using VC++, DirectX9
You're overwriting the first vertex with the second. You probably want:

BYTE* pVertices = (BYTE*)pVoid;
memcpy(pVertices, CUSTOMVERTEX1, sizeof(CUSTOMVERTEX1));
pVertices += sizeof(CUSTOMVERTEX1);
memcpy(pVertices, CUSTOMVERTEX2, sizeof(CUSTOMVERTEX2));
pVertices += sizeof(CUSTOMVERTEX2);


Although, unless you're doing something extremely odd, this won't work as you expect - all the vertices used in draw calls usually have to be the same format, or it won't work. The graphics card won't be able to tell where each vertex starts.
The only exception to this is if you're storing data for different draw calls in one VB, for instance one mesh with texture coordinates, one without, and then using stream offsets to choose which one to use.

Share this post


Link to post
Share on other sites

This topic is 3787 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this