Jump to content


Instancing using ID3DX10Mesh


3 replies to this topic

#1 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 10 November 2008 - 08:41 AM

I already made Geometry Instancing examples throught ID3D10Buffer interfaces.
Now i would like make it via ID3DX10Mesh interface.

I look at all methods and functions: i found that interface supports multiple vertexbuffers (as you can see in SetVertexData) and also Instanced drawing, but i'm not able to found a way to create another vertex buffer in the interface Mesh10 in which i would store instancing data (it's just a float value), neither in creation, neither after.

So, how can i make it?

I found a way: the cloneMesh function. It, infact, gave him a new array of Input Element Desc, creates me 2 vertex buffers. The first one it's already filled, but when i try to fill the second using SetVertexData(1,buffer) it gives me error. The only way to fill it it's to lock it using GetVertexBuffer with ID3DX10MeshBuffer and copy values.

Ok, no problem, but when i try to make DrawSubsetInstanced it gives me INFO about "No second vertex buffer bound to pipeline"
Using PIX it effectively does not bound second vertex buffer, but makes a redundant bound of first vertex buffer, so i'm not able to draw instanced.
Can have you got some suggestions??

#2 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 13 November 2008 - 06:15 AM

Mabye i've found a bug in the ID3DX10Mesh interface.
It supports natively the instancing feature using DrawSubsetInstanced function, but also a lot of tries, it did not worked.

I'm using an InputLayout that has got 2 input slots and it works becouse the function GetVertexBufferCount() gives me 2 that it's ok (my intention is to make a vertex buffer for position and other informations, another one for a float value that will be used via instancing.)

So, using this simple code

float *bufdata = new float[LayerNum];
for (int i = 0; i < LayerNum; i++)
bufdata[i] = static_cast<float>(i) / LayerNum;

ID3DX10MeshBuffer *Mbuf;
void *bdata;
SIZE_T bsize;

geometry->Mesh->GetVertexBuffer(1,&Mbuf);

Mbuf->Map(&bdata,&bsize);
memcpy(bdata,bufdata,sizeof(float) * LayerNum);
Mbuf->Unmap();

Mbuf->Release();

delete[] bufdata;

i fill the second buffer.

The drawsubsetfunction gives me an INFO that say me that the input element 3 has got a input slot = 1 but no vertex buffer is bound at slot 1. So i opened PIX and started to make a debug, and i found this:

::IASetVertexBuffers 0,1,0xabce,0xabcde,0xabcde1
::IASetVertexBuffers 0,1,0xabce,0xabcde,0xabcde2

The second buffer REPLACE the first one, and so i remain with an unbound buffer at input slot 1. Should not it be

::IASetVertexBuffers 0,1,0xabce,0xabcde,0xabcde1
::IASetVertexBuffers 1,1,0xabce,0xabcde,0xabcde2

or

::IASetVertexBuffers 0,2,0xabce,0xabcde,0xabcdeBUFFERARRAY?

Thank you for your attention. I'm always ready to give you code or simply more informations.

#3 Blackfighter

    New Member

  • Members
  • Pip
  • 1 posts

Posted 02 March 2009 - 05:21 PM

XVincentX said:

Mabye i've found a bug in the ID3DX10Mesh interface.
It supports natively the instancing feature using DrawSubsetInstanced function, but also a lot of tries, it did not worked.

It seems realy stupid, i've tried a lot but it's not working.

I've got mesh with two vertex buffers,
first buffer contains mesh data, second contains instance data

here's decl

const D3D10_INPUT_ELEMENT_DESC ModelMultiWall::layout[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"mTransform", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1 },
{"mTransform", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D10_INPUT_PER_INSTANCE_DATA, 1 },
{"mTransform", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 32, D3D10_INPUT_PER_INSTANCE_DATA, 1 },
{"mTransform", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 48, D3D10_INPUT_PER_INSTANCE_DATA, 1 }

};

mTransform is 4x4float matrix (16*float = 64B)

When I call D3DX10CreateMesh, it knows how big create first vertex buffer, because it knows how many vertices I'll use. But it doesn't know how big create second buffer, because it doesn't know how many instances I'd like to create. So it creates vertex buffer of size 576 Bytes (9 instances). Why? DrawSubsetInstanced isn't wokring. I thing Mesh instancing isn't finished yet.

#4 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 02 March 2009 - 06:39 PM

I resolved getting ID3D10Buffer from mesh.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users