Skip to main content
GameDev.net gamedev.net
🔒 Locked

MEMCPY - some problems

Started by johnny_no1_boy Aug 2, 2007 at 12:35 PM 0 replies 850+ views
Original Post
johnny_no1_boy
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
Evil Steve
Evil Steve
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.