Sign in to follow this  
AussieSpoon

Check contents of a Vertex Buffer

Recommended Posts

Hello,

 

I am tringing to make a 2D sprite engine that uses a dynamic Vertex Buffer, but I can't tell if the way I'm adding vertex data to is is working. So I was wondering if there is any way I can use the Visual Studio 2010 debugger to find the value of each vetex in the Vertex buffer (to see if its being stored correctly)?

 

Just in case here is how I'm creating it:

 


//Called once during initialization 
if(FAILED( g_pd3dDevice->CreateVertexBuffer( s_nBatchSize * 4 * sizeof( SpriteVertex ), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
D3DFVF_SPRITEVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )

 

Here is how I'm putting data into it every frame:
 
SpriteVertex* pVertex;
		m_pVB->Lock(nRenderOffset, nSpritesToLock*4, (void**)&pVertex, 0);

//Use these variables to set the 4 verticies for each sprite (quad)
			//Set vertex 1
			pVertex->vPos = D3DXVECTOR3(vPos.x - 0.5f, vPos.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMin();
			pVertex->v1 = pTexture->GetTextureVMin();
			pVertex++;
			//Set vertex 2
			pVertex->vPos = D3DXVECTOR3(vPos.x+vSize.x - 0.5f, vPos.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMax();
			pVertex->v1 = pTexture->GetTextureVMin();
			pVertex++;
			//Set vertex 3
			pVertex->vPos = D3DXVECTOR3(vPos.x - 0.5f, vPos.y+vSize.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMin();
			pVertex->v1 = pTexture->GetTextureVMax();
			pVertex++;
			//Set vertex 
			pVertex->vPos = D3DXVECTOR3(vPos.x+vSize.x - 0.5f, vPos.y+vSize.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMax();
			pVertex->v1 = pTexture->GetTextureVMax();
			pVertex++;
		}

m_pVB->Unlock();

 

This is using something Evil Steve posted here

 

 

Share this post


Link to post
Share on other sites

I'm not sure of the corresponding action in the graphics debugger (you mean VS2012, right?) but in PIX you could take a frame snapshot, and then go back through and analyze the contents of any resource that was used during that frame.  I think this should also be possible in the new version - but to be honest I haven't had a chance to use the new version yet...

 

Are you seeing behavior that makes you think it isn't working correctly?  You should be able to build some test code and see if the corresponding rendered output is correct given a specific input pattern.  Sometimes that is the best way I can find to test out my graphics related code.

Share this post


Link to post
Share on other sites

[quote name='Jason Z' timestamp='1358130572' post='5021254']
Are you seeing behavior that makes you think it isn't working correctly? 
[/quote]

Well all the values are what they should be, but I'm just having trouble finding what part of the process isn't working. Nothing draws to the screen when I call drawIndexedPrimitive but the code is too big to put up here (I think) 

 

The only way I have used VB's previously was by creating an array then using memcpy(); but I don't see how I can create an array out of the for loop I had above? 

Share this post


Link to post
Share on other sites
Put up a screenshot of all the PIX state values at the time of rendering.
Check the obvious: Is your viewport correct? Are your near/far planes correct? Is your culling correct? Is your depth negative when it should be positive or vice-versa? Is your world-view-project matrix orthogonal and correct? Is it of the correct handedness?

Post a PIX screenshot or 2 containing all of these values at the time of render.


L. Spiro

Share this post


Link to post
Share on other sites
Put up a screenshot of all the PIX state values at the time of rendering.
Check the obvious: Is your viewport correct? Are your near/far planes correct? Is your culling correct? Is your depth negative when it should be positive or vice-versa? Is your world-view-project matrix orthogonal and correct? Is it of the correct handedness?

Post a PIX screenshot or 2 containing all of these values at the time of render.


L. Spiro

 

This, plus are there other 'normal' draw calls that are working properly?  Or are none of them working as you expected?

Share this post


Link to post
Share on other sites
If nothing draws make a PIX capture.
Find your drawcall for the sprite buffer then look at the mesh tab
In the mesh tab select the post VS tab and check whether the values there valid.
Also in the views above these tabs you can see what the vertex buffer looks like pre VS, post VS and what's in the viewport.

If stuff isn't showing up in the viewport then most likely one of your transforms or camera position is wrong or like mentioned above one of your renderderstates.
Also by clicking on one of the vertex numbers in the list you can debug the vertex or geometry shader associated with this draw call. Edited by NightCreature83

Share this post


Link to post
Share on other sites
Put up a screenshot of all the PIX state values at the time of rendering.
Check the obvious: Is your viewport correct? Are your near/far planes correct? Is your culling correct? Is your depth negative when it should be positive or vice-versa? Is your world-view-project matrix orthogonal and correct? Is it of the correct handedness?

Post a PIX screenshot or 2 containing all of these values at the time of render.


L. Spiro

I've never used PIX, I have the SDK but have no idea how to use it? Do you mind explaining? 

 

Yeah I havn't really touched the matrices, Stupid as this sounds I am just using the SetupMatracis();  from one of the SDK Tutorials, So it might be this. 

 

How do I ensure the world view projection Matrix is Orthogonal and the correct handedness?

 

Currently I just have:

 

    D3DXMATRIXA16 matWorld;
    D3DXMatrixIdentity( &matWorld );
    D3DXMatrixRotationX( &matWorld, timeGetTime() / 1000.0f );
    g_pd3dDevice->SetTransform( D3DTS_WORLD,  &matWorld );

    D3DXVECTOR3 vEyePt( 0.0f, 0.0f, -70.0f );
    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 800.0f / 600.0f, 1.0f, 100.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

 

 

 

All my depths are 0 (by default) , is this a problem?

 

 

I have :

g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

 

 

So I think it might be my matrices, so how do I ensure the world view projection Matrix is Orthogonal and the correct handedness?

 

Thanks 

Share this post


Link to post
Share on other sites
I've never used PIX, I have the SDK but have no idea how to use it? Do you mind explaining?
I just did: http://www.gamedev.net/topic/637219-particles-engine-and-slow-fps/#entry5021364

Also, your call to D3DXMatrixRotationX() is incorrect. It should be D3DXMatrixRotationZ().
Also your matrix is not orthogonal. Replace D3DXMatrixPerspectiveFovLH() with D3DXMatrixOrthoLH() or D3DXMatrixOrthoOffCenterLH().


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites
Running under Microsoft® Visual Studio® causes the working directory to be changed to that of the project. For now you should just manually override that via SetCurrentDirectory() at run-time so that the directories will be the same regardless of from where you start the application.

Since you didn’t actually step into Frame 150 or Frame 67 there is no information contained in either of your screen shots. Fix the resource problem first and try again—this time actually go to a render call.


L. Spiro

Share this post


Link to post
Share on other sites

Ok I think I did this right,

 

 

 

z41iW.jpg?1

 

and:

 

h5HO1.jpg?1

 

and:

 

41Pzq.jpg?1

 

The values do seem right so I'm not sure, what else is potentially wrong

 

Thanks 

 

EDIT: Actually my index buffer has incorrect values, the array values I create are correct , then I just memcpy the array to a pointer. But the index buffer is wrong, so I will work on that

Edited by AussieSpoon

Share this post


Link to post
Share on other sites

If you actually browse to your drawcall you can get a lot more detailed information about the vertex buffer, by doing what you are currently doing you will only see the input buffer not the transformed one after the VS has run. And it can well be that your input buffer is correct but the output of the vertex shader isn't, I am assuming you are using a vertex shader here. Even if you are not using a vertex shader looking at when the drawcall is submitted will give you an idea of whether your transforms are correctly transforming your vertices in the buffer. Also it will tell you whether they are within the viewport or not which can also affect what you see on screen.
So just hit the plus on that frame you captured and look through the drawcalls till you find something that is rendering with that vertex buffer. By the way if you extend the list of a frame it will show you which commands your are actually sending to the D3D runtime from your application. Hit F1 in pix and look for this subject in the help file "View Buffer Data" checking out subject "View Mesh Data" is also a good idea. You can find this in the DirectX Software Development Kit help file under:

-DirectX Software Development Kit
  -Tools
    -DirectX Performance Tools
      -PIX
        -Tutorials and Samples

 

Edited by NightCreature83

Share this post


Link to post
Share on other sites

1st Draw Call (Pre VS):

 

jFjGQ.jpg?1

 

1st Draw Call (Post VS):

 

Wre2X.jpg?1

 

2nd (Last) Draw Call (Both PreVS and Post VS are the same):

 

hvOtN.jpg?1

 

Device info:

 

BxFjF.jpg?1

 

The first Draw indexed primitive seems to have correct Position (not sure why there are 4 though) and Text Co-ord values but no colour values. (Am I reading that right?)

 

Then the 2nd draw call look completely wrong.

 

And I'm not sure what to look at for the device. 

Share this post


Link to post
Share on other sites

One problem at a time.

Do you think there is anything you can glean from that second draw call?

Why would the input buffer have positions all-0’s and the index buffer be fubar…?

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Do you think there is anything you can glean from that second draw call?

Why would the input buffer have positions all-0’s and the index buffer be fubar…?

 

From what I can tell (since I've never used this before).

 

(Assumuming Prim = Primative ie. 1 triangle, VTX = Vertex and IDX = index)

Then the index buffer has the correct values, and the VB is using them the way I want. But the values of each Vertex are worng, also there is a 4th value for position and I'm not sure why. I'm using D3DXVECTOR3 so not sure if that has an extra value I am unaware of? 

 

So I somehow have to find what is changing the values in the VB, right? 

 

Thanks 

Share this post


Link to post
Share on other sites
You will always see 4 values in the position, internally setting a vector 4 is faster on most hardware then setting a vector 3, and thats why you see that fourth value.

It seems that you are overwriting your index buffer in between your draw calls, you might want to have a careful look at how you fill these. Also in the SetStreamSource call for the second draw is using an offset of 36 instead of 24 like the first one, why is this as that might be why you are skipping 2 verts at a time. Have a look at your vertex declarations in PIX as they will tell you what your stride size should be Edited by NightCreature83

Share this post


Link to post
Share on other sites
It seems that you are overwriting your index buffer in between your draw calls, you might want to have a careful look at how you fill these. Also in the SetStreamSource call for the second draw is using an offset of 36 instead of 24 like the first one, why is this as that might be why you are skipping 2 verts at a time. Have a look at your vertex declarations in PIX as they will tell you what your stride size should be

 

My index buffer is only filled once, (During initialization)

 

Here is how I fill it 

 

//Creation
if(FAILED( g_pd3dDevice->CreateIndexBuffer(s_nBatchSize * 6, 0, 
	D3DFMT_INDEX32, D3DPOOL_DEFAULT ,&m_pIB, NULL)))

//Filling only done once
// Lock the index buffer
VOID* pIndices;
m_pIB->Lock(0, s_nBatchSize * 6, (void**)&pIndices, 0);

uINT indices[s_nBatchSize * 6];//Because for a quad you need 4 verts and 6 indicies
uINT indexCounter = 0;//used to store a value that helps set the correct indicie value
for(uINT i = 0; i < s_nBatchSize * 6; i += 6)
{
	//Set 6 values that use 4 verticies
	//0, 1, 2  Triangle 1		
	indices[i + 0] = (indexCounter * 4 + 0);
	indices[i + 1] = (indexCounter * 4 + 1);
	indices[i + 2] = (indexCounter * 4 + 2);
	//2, 1, 3  Triangle 2		
        indices[i + 3] = (indexCounter * 4 + 2);
	indices[i + 4] = (indexCounter * 4 + 1);
	indices[i + 5] = (indexCounter * 4 + 3);

	//Increase the index counter to get the right values
	++indexCounter;
}

memcpy(pIndices, indices, sizeof(indices) / sizeof(indices[0]));//sizeof(indices) / sizeof(indices[0]) = number of elements in the array 


// Unlock it
m_pIB->Unlock();

 

Does that look right? 

 

 

"second draw is using an offset of 36 instead of 24"

 

I can't figure this out, I don't know where the first one is coming from, it only gets called once per frame atm, so I have no idea what is calling it

 

g_pd3dDevice->SetStreamSource(0, m_pVB, nRenderOffset, sizeof( SpriteVertex ));

 

Interestingly though, sizeof (SpriteVetex) = 36 but when I put 24 in there instead I ACTUALLY SEE A SPRITE RENDERED  I'm not sure what this means though.

 

One thing I just want check though as I am unfimiliar with them is my Vertex Declaration.

 

Do these two add up?:

 

//VERTEX
struct SpriteVertex
{
	D3DXVECTOR3		vPos;
	D3DXCOLOR		Colour;
	uINT			u1, v1;
};

//VERTEX DECLARATION 

D3DVERTEXELEMENT9 Sprite_Decl[] =
{
	{0, 0,  D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
	{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
	{0, 24, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
	D3DDECL_END() // this macro is needed as the last item!
};

 

Thanks 

Share this post


Link to post
Share on other sites

D3DXCOLOR looks like this: http://msdn.microsoft.com/en-us/library/windows/desktop/bb172730%28v=vs.85%29.aspx

struct D3DXCOLOR
{
    float r,g,b,a;
}

Which means it's 16 bytes big so you have D3DXVector3 = 12 bytes + D3DXCOLOR = 16 + uint = 4 bytes * 2 = 36 bytes, which happens to be the same thing sizeof(SpriteVertex) will return. Your vertex declaration however tells D3D that the color value is only a DWORD big which is 4 bytes.
If you define your SpriteVertex as:

struct SpriteVertex
{
   D3DXVector3 position;
   DWORD color;//This is the same as D3DCOLOR
   unsigned int u, v;
}

This will match your vertex declaration and will make your sprite buffer work again, there are helper functions in D3DX that allow you to transform a 4 float value into a dword(http://msdn.microsoft.com/en-us/library/windows/desktop/bb172518%28v=vs.85%29.aspx).

Edited by NightCreature83

Share this post


Link to post
Share on other sites
This will match your vertex declaration and will make your sprite buffer work again, there are helper functions in D3DX that allow you to transform a 4 float value into a dword(http://msdn.microsoft.com/en-us/library/windows/desktop/bb172518%28v=vs.85%29.aspx).

I'm kind of confused by this. 

 

Is it ok to write:

 

DWORD tColour = (*itCurr)->GetColour();//GetColour(): returns a D3DXCOLOR
//Then to change a vertex's color:
pVertex[VertexCounter].Colour = tColour;

Share this post


Link to post
Share on other sites

Yes because D3DXCOLOR defines a cast operator through which it can do this automatically. You just can't use sizeof(SpriteVertex) if you keep storing a D3DXCOLOR in there as the vertexdeclaration and stride won't match up.
Also you should find the D3D control panel and turn the debug layer on with messages set to warning, you will get warnings about this stuff in your output log this way. In the start menu folder where you found pix there is also something called DirectX Control panel launch that application and change the settings under Direct3D 9 tab to use the debug Version of the runtime. Move the slider, under the heading Debug Output Level, to one tick before More, click apply.

You also have to modify your vertex declaration to this when using only a dword to store your color values:

    //VERTEX DECLARATION
     
    D3DVERTEXELEMENT9 Sprite_Decl[] =
    {
    {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
    {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
    {0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
    D3DDECL_END() // this macro is needed as the last item!
    };

Share this post


Link to post
Share on other sites

Hmmmm I did the control panel thing but I get no additional errors.

 

I've fixed the declaration like you said but I still can't see anything. But I am getting crazy values for my vertices

 

Zi988.jpg?1

 

Still getting the same problem where I don't know why Draw indexed prim is being called twice and the pre-VS had good values but the post VS-Doesn't 

 

You wouldn't happen to have any other ideas? 

 

Thanks

 

EDIT: According to PIX I have 2 Vertex Buffer and Index objects but I only create 1, could this be a problem? (Not sure how). The VB and IB (pointers) are members of a custom class

Edited by AussieSpoon

Share this post


Link to post
Share on other sites

//VERTEX
struct SpriteVertex
{
	D3DXVECTOR3		vPos;
	D3DXCOLOR		Colour;
	uINT			u1, v1;
};

//VERTEX DECLARATION 

D3DVERTEXELEMENT9 Sprite_Decl[] =
{
	{0, 0,  D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
	{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
	{0, 24, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
	D3DDECL_END() // this macro is needed as the last item!
};
 
 
 


Look at what you did (aside from the color and alignment problems that should already be fixed).
Your structure has integers for the UV coordinates but you told Direct3D that you have 2 floats. UV coordinates are typically floating-point values often between 0.0f and 1.0f. Fix your structure and any logic you were using to put values into those.


Now look back at your screen shots.
Firstly, the index buffer is not correct on the second draw. A triangle is 3 unique points.  Your index buffer specifies only 2 unique points for every triangle, meaning every triangle is degenerate no matter what position values they had.
 
 
Secondly, look at the ranges of the indices.
You are using the same vertex buffer for both calls.
Fine.
Look at the index buffer.  The vertex buffer elements 95-99 are valid.  The vertex buffer elements 0-?? are not.
It is fairly clear you did not initialize the whole vertex buffer.  You handled some of the vertices but not the rest.


 
I've fixed the declaration like you said but I still can't see anything. But I am getting crazy values for my vertices
If you have ever used a debugger before you would easily recognize the pattern of bytes there. 0xDD and 0xCD are what the debugger fills over memory in certain cases.
If you see 0xCD, it means something was not initialized.
If you see 0xDD, it means the memory was freed/deleted.

The problem is obvious. You have deleted that memory.
 
the pre-VS had good values but the post VS-Doesn't 
Are you talking about the values in that screenshot? If so, I can guarantee the PreVS values are not good.
 
Still getting the same problem where I don't know why Draw indexed prim is being called twice
Again, have you ever used a debugger? Do you know what “breakpoints” are?
I am not going to spoon-feed you this. You need to learn a few very very fundamental and basic debugging skills in order to help yourself.
The most basic debugging skills would have solved the problem I mentioned first in this post as well. The screenshots made it obvious what the problem was, and a few breakpoints, some single-stepping, and 10 minutes of code-checking would have exposed the underlying issue.

I am not going to spoon-feed you this.
Google keywords: “Microsoft Visual Studio Debugger”, “Breakpoints”, “Single-Stepping”, and any combination of these.


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites

[quote name='L. Spiro' timestamp='1358275396' post='5021878']
Firstly, the index buffer is not correct on the second draw. A triangle is 3 unique points.
[/quote]

 

I understand that but a sprite is a quad and from what I thought you need 4 unique points for a quad? (Hence having only haveing 2 for each triangle). So using what you are saying each index's value should equal what number it is in the buffer?

 

for(uINT i = 0; i < s_nBatchSize * 6; i++)
{
 index[i] = i;}

 

[quote name='L. Spiro' timestamp='1358275396' post='5021878']
It is fairly clear you did not initialize the whole vertex buffer
[/quote]

 

This is true, I currently have a large index buffer and only lock what is needed at rendering (only 2 sprites atm)

 

Should I initialize every Vertex's value of the VB to 0 on creation? Is there an easy way to do this?

 

I can only think of something like:

 

	if(FAILED( g_pd3dDevice->CreateVertexBuffer( s_nBatchSize * 4 * sizeof( SpriteVertex ), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
												 0, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )
	{
		m_pVB = 0;//Prints error msg
	}

	//Initialize VB to 0
	SpriteVertex* pVertex;
	m_pVB->Lock(0, 0, (void**)&pVertex, 0);

	for(uINT i = 0; i < s_nBatchSize * 4 + 1 ; i++)
	{
		pVertex[i].vPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
		pVertex[i].Colour = 0;
		pVertex[i].u1 = 0;
		pVertex[i].v1 = 0;
	}

	m_pVB->Unlock();

 

 

 

(Yeah I have debugged before, but still a novice) Ok, not sure how I missed it but, is see that the position of the 4 vertices all have the same value (The pos of the current sprite). I think I have rectified this problem:

 

//pVertex[VertexCounter + 0].
			pVertex[VertexCounter].vPos = D3DXVECTOR3(vPos.x, vPos.y, fDepth);//NOT SURE ABOUT
			pVertex[VertexCounter].Colour = tColour;
			pVertex[VertexCounter].u1 = pTexture->GetTextureUMin();
			pVertex[VertexCounter].v1 = pTexture->GetTextureVMin();
			VertexCounter++;
			//Set vertex 2
			pVertex[VertexCounter].vPos = D3DXVECTOR3(vPos.x + pTexture->GetDrawArea().right, vPos.y, fDepth);
			pVertex[VertexCounter].Colour = tColour;
			pVertex[VertexCounter].u1 = pTexture->GetTextureUMax();
			pVertex[VertexCounter].v1 = pTexture->GetTextureVMin();
			VertexCounter++;
			//Set vertex 3
			pVertex[VertexCounter].vPos = D3DXVECTOR3(vPos.x, vPos.y + pTexture->GetDrawArea().bottom, fDepth);
			pVertex[VertexCounter].Colour = tColour;
			pVertex[VertexCounter].u1 = pTexture->GetTextureUMin();
			pVertex[VertexCounter].v1 = pTexture->GetTextureVMax();
			VertexCounter++;
			//Set vertex 4
			pVertex[VertexCounter].vPos = D3DXVECTOR3(vPos.x + pTexture->GetDrawArea().right, vPos.y + pTexture->GetDrawArea().bottom, fDepth);
			pVertex[VertexCounter].Colour = tColour;
			pVertex[VertexCounter].u1 = pTexture->GetTextureUMax();
			pVertex[VertexCounter].v1 = pTexture->GetTextureVMax();
			VertexCounter++;

 

Was that it?

 

Still unsure on how I am loosing data, do I need to :

 

memcpy(pVertex, indices, sizeof(indices) / sizeof(indices[0]));

 

 

?

 

Thanks

Share this post


Link to post
Share on other sites
I understand that but a sprite is a quad and from what I thought you need 4 unique points for a quad?

This basically means you don’t understand anything your code is doing.
Your idea is that a quad is just a single 4-point primitive, but your code says a quad is a D3DPT_TRIANGLELIST with 2 triangles (3-point primitives) in it in the shape of a quadrilateral.
In other words, you copied and pasted from some tutorial without understanding any of it.
 

This is true, I currently have a large index buffer and only lock what is needed at rendering (only 2 sprites atm)

Which means only 1 of 2 things: Either you aren’t updating the correct parts or you aren’t using the correct parts.
Simple debugging techniques will tell you which is the case.

 

Should I initialize every Vertex's value of the VB to 0 on creation? Is there an easy way to do this?
 
I can only think of something like:

	if(FAILED( g_pd3dDevice->CreateVertexBuffer( s_nBatchSize * 4 * sizeof( SpriteVertex ), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
												 0, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )
	{
		m_pVB = 0;//Prints error msg
	}

	//Initialize VB to 0
	SpriteVertex* pVertex;
	m_pVB->Lock(0, 0, (void**)&pVertex, 0);

	for(uINT i = 0; i < s_nBatchSize * 4 + 1 ; i++)
	{
		pVertex[i].vPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
		pVertex[i].Colour = 0;
		pVertex[i].u1 = 0;
		pVertex[i].v1 = 0;
	}

	m_pVB->Unlock();

That is correct (except s_nBatchSize * 4 + 1) for initializing the whole buffer with 0’s, however looking at your 2nd screenshot the invalid region is already filled with 0’s.
Meaning although this is a good idea it won’t solve your problem.
 
 

 
Was that it?
 
Still unsure on how I am loosing data, do I need to :

memcpy(pVertex, indices, sizeof(indices) / sizeof(indices[0]));

That will only copy less data than before.


L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites

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