1
\$\begingroup\$

I'm making a Direct3D engine but I'm stuck with this one little problem.

I want to not use effect files but instead use shader files. What can I use to send matrix variables to shaders if I don't use ID3D11XEffectMatrixVariable?

\$\endgroup\$
2
\$\begingroup\$

To send constant values to shaders without using the effect framework, you create constant buffers and bind them to the pipeline with (for example) VSSetConstantBuffers.

For example:

// You can of course eschew the structure, but this allows you to stuff more data
// into the pipeline with a minimum of fuss; you should generally create constant
// buffers based on what you would update together (per frame versus per object
// state, for example) rather than one-buffer-per-variable.
struct MyConstantBuffer  {
  XMFLOAT4X4 transform;
  // ...optionally more stuff...
};

MyConstantBuffer instance;
instance.transform = someMatrixValue;

// Create buffer description and resource data objects.
D3D11_BUFFER_DESC description = { 0 };
description.ByteWidth = sizeof(MyConstantBuffer);
description.Usage = D3D11_USAGE_DYNAMIC;
description.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
description.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

D3D11_SUBRESOURCE_DATA data = { 0 };
data.pSysMem = &instance;

// Create the buffer and bind it.
ID3D11Buffer * result = nullptr;
device->CreateBuffer(&description, &data, &result);
context->VSSetConstantBuffers(0, 1, &result);

MSDN has a how-to page as well.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.