Jump to content
  • Advertisement
Sign in to follow this  
AgentSnoop

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.

If you intended to correct an error in the post then please contact us.

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 );	

cgD3D10BindProgram(pVertexShader);
cgD3D10BindProgram(pPixelShader);	
	
cgSetMatrixParameterfr(cgGetNamedParameter(cgShader, param), *m);

pD3DDevice->PSSetShaderResources(0, 1, &pSRV);
pD3DDevice->PSSetSamplers(0, 1, &pSamplerState);
cgD3D10SetTextureSamplerStateParameter(cgGetNamedParameter(cgShader, param), pResource, pSamplerState);

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

pD3DDevice->PSSetShaderResources(0, 1, 0);
pD3DDevice->PSSetSamplers(0, 1, 0);
cgD3D10SetTextureSamplerStateParameter(cgGetNamedParameter(cgShader, param), 0, 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::PSSetShaderResources(0,1,0x)
ID3D10Device::PSSetSamplers(0,1,0x)
ID3D10Texture2D::GetType(0x)
ID3D10Texture2D::GetDesc(0x)
ID3D10Device::CreateShaderResourceView(0x)
ID3D10Device::IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
ID3D10Device::Draw(36,0)
ID3D10Device::PSSetShaderResources(0,1,NULL)
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 this post


Link to post
Share on other sites
Advertisement
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:
cgSetMatrixParameterfr(cgGetNamedParameter(cgShader, param), *m);
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 this post


Link to post
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?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!