2
0

BsObjectRendering.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsObjectRendering.h"
  4. #include "Material/BsShader.h"
  5. #include "RenderAPI/BsGpuParams.h"
  6. #include "BsRenderBeast.h"
  7. #include "Material/BsMaterial.h"
  8. #include "Mesh/BsMesh.h"
  9. #include "Animation/BsSkeleton.h"
  10. #include "RenderAPI/BsGpuBuffer.h"
  11. #include "Material/BsGpuParamsSet.h"
  12. #include "Animation/BsMorphShapes.h"
  13. #include "Animation/BsAnimationManager.h"
  14. namespace bs { namespace ct
  15. {
  16. PerFrameParamDef gPerFrameParamDef;
  17. ObjectRenderer::ObjectRenderer()
  18. {
  19. mPerFrameParamBuffer = gPerFrameParamDef.createBuffer();
  20. }
  21. void ObjectRenderer::initElement(RendererObject& owner, BeastRenderableElement& element)
  22. {
  23. SPtr<Shader> shader = element.material->getShader();
  24. if (shader == nullptr)
  25. {
  26. LOGWRN("Missing shader on material.");
  27. return;
  28. }
  29. SPtr<GpuParams> gpuParams = element.params->getGpuParams();
  30. // Note: Perhaps perform buffer validation to ensure expected buffer has the same size and layout as the provided
  31. // buffer, and show a warning otherwise. But this is perhaps better handled on a higher level.
  32. gpuParams->setParamBlockBuffer("PerFrame", mPerFrameParamBuffer);
  33. gpuParams->setParamBlockBuffer("PerObject", owner.perObjectParamBuffer);
  34. gpuParams->setParamBlockBuffer("PerCall", owner.perCallParamBuffer);
  35. gpuParams->getParamInfo()->getBindings(
  36. GpuPipelineParamInfoBase::ParamType::ParamBlock,
  37. "PerCamera",
  38. element.perCameraBindings
  39. );
  40. gpuParams->getParamInfo()->getBindings(
  41. GpuPipelineParamInfoBase::ParamType::ParamBlock,
  42. "GridParams",
  43. element.gridParamsBindings
  44. );
  45. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLights"))
  46. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLights", element.lightsBufferParam);
  47. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gGridLightOffsetsAndSize"))
  48. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gGridLightOffsetsAndSize", element.gridLightOffsetsAndSizeParam);
  49. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLightIndices"))
  50. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLightIndices", element.gridLightIndicesParam);
  51. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gGridProbeOffsetsAndSize"))
  52. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gGridProbeOffsetsAndSize", element.gridProbeOffsetsAndSizeParam);
  53. element.imageBasedParams.populate(gpuParams, GPT_FRAGMENT_PROGRAM, true, true, true);
  54. if (gpuParams->hasBuffer(GPT_VERTEX_PROGRAM, "boneMatrices"))
  55. gpuParams->setBuffer(GPT_VERTEX_PROGRAM, "boneMatrices", element.boneMatrixBuffer);
  56. }
  57. void ObjectRenderer::setParamFrameParams(float time)
  58. {
  59. gPerFrameParamDef.gTime.set(mPerFrameParamBuffer, time);
  60. }
  61. }}