Jump to content
  • Advertisement
Sign in to follow this  
johnny_no1_boy

MEMCPY - some problems

This topic is 4003 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
Advertisement
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
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!