| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "BsObjectRendering.h"
- #include "Material/BsShader.h"
- #include "RenderAPI/BsGpuParams.h"
- #include "BsRenderBeast.h"
- #include "Material/BsMaterial.h"
- #include "Mesh/BsMesh.h"
- #include "Animation/BsSkeleton.h"
- #include "RenderAPI/BsGpuBuffer.h"
- #include "Material/BsGpuParamsSet.h"
- #include "Animation/BsMorphShapes.h"
- #include "Animation/BsAnimationManager.h"
- namespace bs { namespace ct
- {
- PerFrameParamDef gPerFrameParamDef;
- ObjectRenderer::ObjectRenderer()
- {
- mPerFrameParamBuffer = gPerFrameParamDef.createBuffer();
- }
- void ObjectRenderer::initElement(RendererObject& owner, BeastRenderableElement& element)
- {
- SPtr<Shader> shader = element.material->getShader();
- if (shader == nullptr)
- {
- element.perCameraBindingIdx = -1;
- element.gridParamsBindingIdx = -1;
- LOGWRN("Missing shader on material.");
- return;
- }
- SPtr<GpuParams> gpuParams = element.params->getGpuParams();
- // Note: Perhaps perform buffer validation to ensure expected buffer has the same size and layout as the provided
- // buffer, and show a warning otherwise. But this is perhaps better handled on a higher level.
- if(shader->hasParamBlock("PerFrame"))
- element.params->setParamBlockBuffer("PerFrame", mPerFrameParamBuffer, true);
- if(shader->hasParamBlock("PerObject"))
- element.params->setParamBlockBuffer("PerObject", owner.perObjectParamBuffer, true);
- if(shader->hasParamBlock("PerCall"))
- element.params->setParamBlockBuffer("PerCall", owner.perCallParamBuffer, true);
- if(shader->hasParamBlock("PerCamera"))
- element.perCameraBindingIdx = element.params->getParamBlockBufferIndex("PerCamera");
- element.gridParamsBindingIdx = element.params->getParamBlockBufferIndex("GridParams");
- if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLights"))
- gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLights", element.lightsBufferParam);
- if(gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gGridLightOffsetsAndSize"))
- gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gGridLightOffsetsAndSize", element.gridLightOffsetsAndSizeParam);
- if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLightIndices"))
- gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLightIndices", element.gridLightIndicesParam);
- if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gGridProbeOffsetsAndSize"))
- gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gGridProbeOffsetsAndSize", element.gridProbeOffsetsAndSizeParam);
- element.imageBasedParams.populate(element.params, GPT_FRAGMENT_PROGRAM, true, true);
- if (gpuParams->hasBuffer(GPT_VERTEX_PROGRAM, "boneMatrices"))
- gpuParams->setBuffer(GPT_VERTEX_PROGRAM, "boneMatrices", element.boneMatrixBuffer);
- }
- void ObjectRenderer::setParamFrameParams(float time)
- {
- gPerFrameParamDef.gTime.set(mPerFrameParamBuffer, time);
- }
- void DefaultMaterial::_initVariations(ShaderVariations& variations)
- {
- // Do nothing
- }
- }}
|