1
\$\begingroup\$

I try to create rendering system that supports DirectX and OpenGL. I am trying to create class for constant buffer, but DirectX constant buffers and OpenGL uniform buffers have different memory organisation rules. Is there any way to to achieve the compatibility between DirectX and std140 from OpenGL?

Or probably will it be better to choose a other way to create abstraction of constant buffers for shaders? And how developers solve problem of passing data to shaders effectively in serious engines?

\$\endgroup\$
0
\$\begingroup\$

Yes, you can solve this with another layer of abstraction.

The structure that client code uses to fill out shader parameters does not need to be the same structure the engine actually provides to the underlying API. So your engine could present the simple structure:

struct DrawParameters {
  Matrix4x4 worldTransform;
  float glowAmount;
  float chromaticAberationStrength;
  // ...whatever..
};

Within your engine code, you take the instances of the above structures that you're given in any particular set of draw requests and you copy the data into suitably-sized, suitably-aligned buffers that you'll actually give to OpenGL or DirectX or Vulkan or Metal or whatever you're really using under the hood.

\$\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.