# OpenGL Direct3D10 with Cg ?

This topic is 3151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does anyone have any experience with Direct3D10 using Cg for shaders? I have something in place already for OpenGL and Direct3D9 which works, but I'm trying to get everything working in Direct3D10, but I'm running into problems. The biggest problem I have now is I'm trying to render a sky box, and that's it. When I check PIX, Direct3D9 correctly shows the pre-vertex shader, then he post-vertex shader, and lastly the viewport. Direct3D10 has the same pre-vertex shader, but the post-vertex shader is no where near close, and obviously the viewport won't be the same either. Is there anything special I have to do differently compared to Direct3D9? I've looked at the Cg examples for Direct3D10, and it seems I'm doing things similarly so I thought I would ask others. EDIT: Also, I'm roughly doing this code for rendering:
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(color.v));
pD3DDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH , depth, stencil);

pD3DDevice->IASetInputLayout( pLayout );
pD3DDevice->IASetVertexBuffers( 0, 1, &pBuffer, &stride, &offset );

pD3DDevice->PSSetSamplers(0, 1, &pSamplerState);

pD3DDevice->IASetPrimitiveTopology((D3D10_PRIMITIVE_TOPOLOGY)primitiveType);
pD3DDevice->Draw(36, 0);

pD3DDevice->PSSetSamplers(0, 1, 0);

pSwapChain->Present( 0, 0 );


while, PIX says this is what is going on:
ID3D10Device::ClearRenderTargetView(0x)
ID3D10Device::ClearDepthStencilView(0x,1,1.000f,0)
ID3D10Device::IASetInputLayout(0x)
ID3D10Device::IASetVertexBuffers(0,1,0x)
ID3D10Device::PSSetSamplers(0,1,0x)
ID3D10Texture2D::GetType(0x)
ID3D10Texture2D::GetDesc(0x)
ID3D10Device::IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
ID3D10Device::Draw(36,0)
ID3D10Device::PSSetSamplers(0,1,NULL)
IDXGSwapChain::Present(0,0)


So, they are similar, but I don't see any setting of shaders, or sending the matrix data [Edited by - AgentSnoop on February 28, 2010 1:29:08 PM]

##### Share on other sites
So I did a more debugging and found out the no VSSetShader and PSSetShader was because of an optimization I had, so that isn't an issue.

I've moved things around to make sure setting of parameters is done before binding the shader.

It looks more like this now:
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(color.v));pD3DDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH , depth, stencil);		cgSetMatrixParameterfr(cgGetNamedParameter(cgShader, param), *m);cgD3D10SetTextureSamplerStateParameter(cgGetNamedParameter(cgShader, param), pResource, pSamplerState);cgD3D10BindProgram(pVertexShader);cgD3D10BindProgram(pPixelShader);pD3DDevice->IASetInputLayout( pLayout );pD3DDevice->IASetVertexBuffers( 0, 1, &pBuffer, &stride, &offset );pD3DDevice->IASetPrimitiveTopology((D3D10_PRIMITIVE_TOPOLOGY)primitiveType);pD3DDevice->Draw(36, 0);	cgD3D10SetTextureSamplerStateParameter(cgGetNamedParameter(cgShader, param), 0, 0);

I've looked more closely at the PIX output and found that nothing gets sent to the vertex shader for the matrix.

I do this:
but nothing appears to be sent.

I have an earlier build which seems to work, but I got them to do roughly the same thing but it won't send my matrix, so there's no way it will transform correctly.

Has anyone had a similar problem? Is anyone sending a matrix a different way that is similar to what I am trying to use? Is there something I'm overlooking?

Thanks for any help.

##### Share on other sites
I hate bumping this up like this, but maybe with new stuff, someone will know something.

Anyway, so it seems when I load my skybox shader, which needs a matrix, and then load my text shader, which just needs to know some offsets, even if the skybox isn't rendered, the text will not be seen correctly as it doesn't seem to correctly updated the constants buffer at all. If I don't load the skybox shader, the constants buffer will magically (seems that way right now) update for the font shader, and thus display correctly.

I've looked at PIX and it's calling UpdateSubResource for the constants buffer, but it doesn't seem to actually be updating (when skybox is loaded and rendered, it's just the worldviewproj matrix it seems, when skybox is loaded but not rendered, it is just all zeros)

Any thoughts on this?

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632934
• Total Posts
3009301
• ### Who's Online (See full list)

There are no registered users currently online

×