Jump to content
  • Advertisement
Sign in to follow this  

D3D10 - How to set constant buffers for effects?

This topic is 3770 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

Hi, I'm having a bit of trouble getting constant buffers to work. I have grouped the variables together in my shader in a constant buffer, like so:
cbuffer Camera
     matrix view, projection, world;
And I am using them like this:
     VS_OUTPUT output = (VS_OUTPUT) 0;
     output.pos = mul(input.pos, world);
     output.pos = mul(output.pos, view);
     output.pos = mul(output.pos, projection);
     return output;
This code works fine if I set variables by hand. By this, I mean retrieving each variable with ID3DEffect::GetVariableByName(...)::AsMatrix. Here's an example, to clarify:
However, when I try and use a constant buffer to set these variables, I get no output - so presumably the matrices are not being passed.
ID3D10EffectConstantBuffer *cameraCBuffer, *worldCBuffer;
cameraCBuffer = effect->GetConstantBufferByName("Camera");
bool valid = cameraCBuffer->IsValid(); // Is showing as true.

D3D10_BUFFER_DESC cameraBufferDesc;
cameraBufferDesc.ByteWidth = sizeof(CameraConstants);
cameraBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
cameraBufferDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
cameraBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
cameraBufferDesc.MiscFlags = 0;

CameraConstants cameraConstants;
cameraConstants.projection = scene->GetCamera()->GetProjection();
cameraConstants.view = scene->GetCamera()->GetView();
cameraConstants.world= geometry->GetTransformation().GetWorldMatrix();

cameraData.pSysMem = &cameraConstants;

ID3D10Buffer *cameraBuffer;
HRESULT hr = display->GetDevice()->CreateBuffer(&cameraBufferDesc, &cameraData, &cameraBuffer); // Returns S_OK
hr = cameraCBuffer->SetConstantBuffer(cameraBuffer); // Returns S_OK

I've check my hr's where they're returned and they are all S_OK. Also, there is nothing in the debug output. Any ideas?

Share this post

Link to post
Share on other sites
While I haven't found a solution to make this work, I don't think it's actually necessary. I made a shader with 2 constant buffers, and updated variables in both buffers. Profiling in PIX automatically handles 2 VSSetConstantBuffers(...) calls, so presumably setting "just" by variable in ID3D10Effect handles this for you.

Brilliant! :)

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!