BsObjectRendering.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. element.perCameraBindingIdx = -1;
  27. element.gridParamsBindingIdx = -1;
  28. LOGWRN("Missing shader on material.");
  29. return;
  30. }
  31. SPtr<GpuParams> gpuParams = element.params->getGpuParams();
  32. // Note: Perhaps perform buffer validation to ensure expected buffer has the same size and layout as the provided
  33. // buffer, and show a warning otherwise. But this is perhaps better handled on a higher level.
  34. if(shader->hasParamBlock("PerFrame"))
  35. element.params->setParamBlockBuffer("PerFrame", mPerFrameParamBuffer, true);
  36. if(shader->hasParamBlock("PerObject"))
  37. element.params->setParamBlockBuffer("PerObject", owner.perObjectParamBuffer, true);
  38. if(shader->hasParamBlock("PerCall"))
  39. element.params->setParamBlockBuffer("PerCall", owner.perCallParamBuffer, true);
  40. if(shader->hasParamBlock("PerCamera"))
  41. element.perCameraBindingIdx = element.params->getParamBlockBufferIndex("PerCamera");
  42. element.gridParamsBindingIdx = element.params->getParamBlockBufferIndex("GridParams");
  43. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLights"))
  44. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLights", element.lightsBufferParam);
  45. if(gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gGridLightOffsetsAndSize"))
  46. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gGridLightOffsetsAndSize", element.gridLightOffsetsAndSizeParam);
  47. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLightIndices"))
  48. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLightIndices", element.gridLightIndicesParam);
  49. if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gGridProbeOffsetsAndSize"))
  50. gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gGridProbeOffsetsAndSize", element.gridProbeOffsetsAndSizeParam);
  51. element.imageBasedParams.populate(element.params, GPT_FRAGMENT_PROGRAM, true, true);
  52. if (gpuParams->hasBuffer(GPT_VERTEX_PROGRAM, "boneMatrices"))
  53. gpuParams->setBuffer(GPT_VERTEX_PROGRAM, "boneMatrices", element.boneMatrixBuffer);
  54. }
  55. void ObjectRenderer::setParamFrameParams(float time)
  56. {
  57. gPerFrameParamDef.gTime.set(mPerFrameParamBuffer, time);
  58. }
  59. void DefaultMaterial::_initVariations(ShaderVariations& variations)
  60. {
  61. // Do nothing
  62. }
  63. }}