Jump to content
  • Advertisement
Sign in to follow this  
dave

My memcpy/vertexbuffer question,

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

Before people read this and think, why doesn't he just try it, i have. Umm the thing is i have groups of 36 vertices stored in different locations, there is a reason why for this but thats not relevent. What i want to do is copy these straight into a vb. The problem im facing is the way that data is copied into a vb, the only way i know how. The only method i have so far is to copy all the verts into 1 big group of vertices, then to copy that group into the actual vb, hope this makes some sense the code:
	int buffInd = 0;
	for ( int i = 0; i < 1000; i++)
	{
		if (bGuide.inUse == true)
		{
			memcpy(&finalBuffer[buffInd], &bGuide.pBL->v[0], sizeof(bGuide.pBL->v));
			buffInd += 36;
		}
		else 
			break;
	}

    VOID* pVertices;
	vb->Lock( 0, sizeof(finalBuffer), (void**)&pVertices, 0 );
	memcpy( pVertices, finalBuffer, sizeof(finalBuffer) );
    vb->Unlock();

so i loop through the 1000 locations where these groups of 36 verts are copy them into finalBuffer[], then copy finaleBuffer[] into the vb afterwards. i want to optimise this by instead of using finalBuffer[], just copy straight into the vb. I dont understand quite why this code uses: VOID* pVertices; Is that just an open ended section of memory? I want to be able to index through the vb so like vb[0], vb[3] so i can copy the verts into the location i want. what should i use instead of VOID* pVertices, ace?

Share this post


Link to post
Share on other sites
Advertisement
memcpy is used for copying ranges from one location of memory to another. It is not necessary for copying individual elements. The purpose of the IDirect3DVertexBuffer9::Lock() is to provide you with a pointer to the beginning of a range of memory that you can safely write to. That means that you can index from that pointer using the subscript operator/notation to access/write individual elements.

What all that verbiage means is that after you've called IDirect3DVertexBuffer9::Lock(), you can do
pVertices = <ptr_to_vertex_data>;

Hope that helped.

Share this post


Link to post
Share on other sites
You'll have to cast the pVertices to something else in order to index it.

For example:

void *pVertices;
MyVertex *pVB;
int total = 0;

// Lock somewhere before this
pVB = (MyVertex*)pVertices; // Cast to indexable type
memcpy(&pVB[total], source1, sizeof(MyVertex)*numverts1);
whereIPutThem1 = total; // You can use this in DrawIndexedPrimitive
total += numverts1;

memcpy(&pVB[total], source2, sizeof(MyVertex)*numverts2);
whereIPutThem2 = total; // You can use this in DrawIndexedPrimitive
total += numverts2;
...
// Unlock somewhere after you copy


obviously you'd have proper structures, not just variables with numbers tacked onto the end, but you get the idea.

Share this post


Link to post
Share on other sites
i just tested and i tried to cahnge the code so that the

VOID* pVertices
was

GENERICVERTEX* pVertices

then tried indexing into it, and it said it cant convert

pVertices[0] to VOID*

thanx for that source snippet BTW but i cant quite follow it.

Any chance on a more worded reflection on that source?
thanx :)
ace

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!