WrapShaderBindings.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2026 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. /// @cond INTERNAL
  5. // First WrapShaderBegin.h should have been included, then the shader code
  6. /// Bind a buffer to the shader
  7. virtual void Bind(const char *inName, void *inData, uint64 inSize) override
  8. {
  9. // Don't redefine constants
  10. #undef JPH_SHADER_CONSTANT
  11. #define JPH_SHADER_CONSTANT(type, name, value)
  12. // Don't redefine structs
  13. #undef JPH_SHADER_STRUCT_BEGIN
  14. #undef JPH_SHADER_STRUCT_MEMBER
  15. #undef JPH_SHADER_STRUCT_END
  16. #define JPH_SHADER_STRUCT_BEGIN(name)
  17. #define JPH_SHADER_STRUCT_MEMBER(type, name)
  18. #define JPH_SHADER_STRUCT_END(name)
  19. // When a constant buffer is bound, copy the data into the members
  20. #undef JPH_SHADER_CONSTANTS_BEGIN
  21. #undef JPH_SHADER_CONSTANTS_MEMBER
  22. #define JPH_SHADER_CONSTANTS_BEGIN(type, name) case HashString(#name): memcpy(&name + 1, inData, size_t(inSize)); break; // Very hacky way to get the address of the first constant and to copy the entire block of constants
  23. #define JPH_SHADER_CONSTANTS_MEMBER(type, name)
  24. // When a buffer is bound, set the pointer
  25. #undef JPH_SHADER_BIND_BUFFER
  26. #undef JPH_SHADER_BIND_RW_BUFFER
  27. #define JPH_SHADER_BIND_BUFFER(type, name) case HashString(#name): name = (const type *)inData; break;
  28. #define JPH_SHADER_BIND_RW_BUFFER(type, name) case HashString(#name): name = (type *)inData; break;
  29. switch (HashString(inName))
  30. {
  31. // Now include the shader bindings followed by WrapShaderEnd.h
  32. /// @endcond