Enabling Truform(NPatch) in DirectX

hseokman

New member
I just started learning DirectX and have question enabling npatch.

How do I turn on?
I don't know why my program do not draw more polygons.

This is my rendering code

m_pD3DDevice->SetRenderState (D3DRS_PATCHSEGMENTS, (DWORD)8.0f);
m_pD3DDevice->SetRenderState (D3DRS_PATCHEDGESTYLE, D3DPATCHEDGE_DISCRETE);
m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, m_dwNumOfVertices, 0, m_dwNumOfPolygons);
m_pD3DDevice->SetRenderState (D3DRS_PATCHSEGMENTS, (DWORD)1.0f);

This is my FVF

#define CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL)

struct CUSTOMVERTEX
{
FLOAT x, y, z; FLOAT nx, ny, nz;
};

I have these lines when initializing

m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING |
D3DCREATE_PUREDEVICE, &d3dpp, &m_pD3DDevice);
m_pD3DDevice->SetRenderState (D3DRS_POSITIONORDER, D3DORDER_CUBIC);
m_pD3DDevice->SetRenderState (D3DRS_NORMALORDER, D3DORDER_LINEAR);

m_pD3DDevice->CreateVertexBuffer(m_dwNumOfVertices * sizeof(CUSTOMVERTEX), D3DUSAGE_NPATCHES, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &m_pVertexBuffer);

m_pD3DDevice->CreateIndexBuffer(m_dwNumOfIndices * sizeof(WORD), D3DUSAGE_NPATCHES, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIndexBuffer)


I have set all the normals before rendering.

Is there anything that I'm missing?
Is there anything that I have to do before enabling npatch?
or Is there anything that I should not do for npatch?
 
Last edited:
D3DRS_PATCHSEGMENTS state as pointer

D3DRS_PATCHSEGMENTS state as pointer

From the DX8 SDK documentation:

Because the IDirect3DDevice8::SetRenderState method accepts DWORD values, your application must cast a variable that contains the value, as shown in the following code example.
pd3dDevice8->SetRenderState(D3DRS_PATCHSEGMENTS, *((DWORD*)&NumSegments));
Try passing the D3DRS_PATCHSEGMENTS value in this way. Please also have a look at the SimpleNPatch sample, which passes data this way.

-Jason
 
Back
Top