//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// #pragma once #include "BsCorePrerequisites.h" #include "BsGpuParam.h" namespace BansheeEngine { /** @addtogroup Implementation * @{ */ class Material; class MaterialCore; template struct TMaterialType { }; template<> struct TMaterialType { typedef SPtr Type; }; template<> struct TMaterialType { typedef SPtr Type; }; class MaterialParams; class MaterialParamsCore; template struct TMaterialParamsType { }; template<> struct TMaterialParamsType { typedef MaterialParams Type; }; template<> struct TMaterialParamsType { typedef MaterialParamsCore Type; }; /** * A handle that allows you to set a Material parameter. Internally keeps a reference to the material parameters so that * possibly expensive lookup of parameter name can be avoided each time the parameter is accessed, and instead the * handle can be cached. * * @note * This is pretty much identical to GPU parameter version (for example TGpuDataParam), except that this will get/set * parameter values on all GPU programs attached to the material, while TGpuDataParam works only for single GPU * program's parameters. Also, additional parameters that might be optimized out in the GPU program will still exist * here as long as they're defined in the shader used by the material, which is not the case with TGpuDataParam. * @note * For core-thread version of this class no shader-based caching is done, and instead this represents just a wrapper * for multiple GPU parameters. * * @see Material */ template class BS_CORE_EXPORT TMaterialDataParam { typedef typename TMaterialType::Type MaterialPtrType; typedef typename TMaterialParamsType::Type MaterialParamsType; public: TMaterialDataParam(const String& name, const MaterialPtrType& material); TMaterialDataParam() { } /** @copydoc TGpuDataParam::set */ void set(const T& value, UINT32 arrayIdx = 0) const; /** @copydoc TGpuDataParam::get */ T get(UINT32 arrayIdx = 0) const; /** Checks if param is initialized. */ bool operator==(const nullptr_t& nullval) const { return mMaterial == nullptr; } protected: UINT32 mParamIndex; UINT32 mArraySize; MaterialPtrType mMaterial; }; /** @copydoc TMaterialDataParam */ template class BS_CORE_EXPORT TMaterialParamStruct { typedef typename TMaterialType::Type MaterialPtrType; typedef typename TMaterialParamsType::Type MaterialParamsType; public: TMaterialParamStruct(const String& name, const MaterialPtrType& material); TMaterialParamStruct() { } /** @copydoc TGpuParamStruct::set */ void set(const void* value, UINT32 sizeBytes, UINT32 arrayIdx = 0) const; /** @copydoc TGpuParamStruct::get */ void get(void* value, UINT32 sizeBytes, UINT32 arrayIdx = 0) const; /** @copydoc TGpuParamStruct::getElementSize */ UINT32 getElementSize() const; /** Checks if param is initialized. */ bool operator==(const nullptr_t& nullval) const { return mMaterial == nullptr; } protected: UINT32 mParamIndex; UINT32 mArraySize; MaterialPtrType mMaterial; }; /** @copydoc TMaterialDataParam */ template class BS_CORE_EXPORT TMaterialParamTexture { typedef typename TMaterialType::Type MaterialPtrType; typedef typename TMaterialParamsType::Type MaterialParamsType; typedef typename TGpuParamTextureType::Type TextureType; public: TMaterialParamTexture(const String& name, const MaterialPtrType& material); TMaterialParamTexture() { } /** @copydoc GpuParamTexture::set */ void set(const TextureType& texture) const; /** @copydoc GpuParamTexture::get */ TextureType get() const; /** Checks if param is initialized. */ bool operator==(const nullptr_t& nullval) const { return mMaterial == nullptr; } protected: UINT32 mParamIndex; MaterialPtrType mMaterial; }; /** @copydoc TMaterialDataParam */ template class BS_CORE_EXPORT TMaterialParamLoadStoreTexture { typedef typename TMaterialType::Type MaterialPtrType; typedef typename TMaterialParamsType::Type MaterialParamsType; typedef typename TGpuParamTextureType::Type TextureType; public: TMaterialParamLoadStoreTexture(const String& name, const MaterialPtrType& material); TMaterialParamLoadStoreTexture() { } /** @copydoc GpuParamLoadStoreTexture::set */ void set(const TextureType& texture, const TextureSurface& surface = TextureSurface()) const; /** @copydoc GpuParamLoadStoreTexture::get */ TextureType get() const; /** Checks if param is initialized. */ bool operator==(const nullptr_t& nullval) const { return mMaterial == nullptr; } protected: UINT32 mParamIndex; MaterialPtrType mMaterial; }; /** @copydoc TMaterialDataParam */ template class BS_CORE_EXPORT TMaterialParamBuffer { typedef typename TMaterialType::Type MaterialPtrType; typedef typename TMaterialParamsType::Type MaterialParamsType; typedef typename TGpuBufferType::Type BufferType; public: TMaterialParamBuffer(const String& name, const MaterialPtrType& material); TMaterialParamBuffer() { } /** @copydoc GpuParamBuffer::set */ void set(const BufferType& buffer) const; /** @copydoc GpuParamBuffer::get */ BufferType get() const; /** Checks if param is initialized. */ bool operator==(const nullptr_t& nullval) const { return mMaterial == nullptr; } protected: UINT32 mParamIndex; MaterialPtrType mMaterial; }; /** @copydoc TMaterialDataParam */ template class BS_CORE_EXPORT TMaterialParamSampState { typedef typename TMaterialType::Type MaterialPtrType; typedef typename TMaterialParamsType::Type MaterialParamsType; typedef typename TGpuParamSamplerStateType::Type SamplerStateType; public: TMaterialParamSampState(const String& name, const MaterialPtrType& material); TMaterialParamSampState() { } /** @copydoc GpuParamSampState::set */ void set(const SamplerStateType& sampState) const; /** @copydoc GpuParamSampState::get */ SamplerStateType get() const; /** Checks if param is initialized. */ bool operator==(const nullptr_t& nullval) const { return mMaterial == nullptr; } protected: UINT32 mParamIndex; MaterialPtrType mMaterial; }; /** @} */ /** @addtogroup Material * @{ */ typedef TMaterialDataParam MaterialParamFloat; typedef TMaterialDataParam MaterialParamVec2; typedef TMaterialDataParam MaterialParamVec3; typedef TMaterialDataParam MaterialParamVec4; typedef TMaterialDataParam MaterialParamInt; typedef TMaterialDataParam MaterialParamVec2I; typedef TMaterialDataParam MaterialParamVec3I; typedef TMaterialDataParam MaterialParamVec4I; typedef TMaterialDataParam MaterialParamMat3; typedef TMaterialDataParam MaterialParamMat4; typedef TMaterialDataParam MaterialParamColor; typedef TMaterialDataParam MaterialParamFloatCore; typedef TMaterialDataParam MaterialParamVec2Core; typedef TMaterialDataParam MaterialParamVec3Core; typedef TMaterialDataParam MaterialParamVec4Core; typedef TMaterialDataParam MaterialParamIntCore; typedef TMaterialDataParam MaterialParamVec2ICore; typedef TMaterialDataParam MaterialParamVec3ICore; typedef TMaterialDataParam MaterialParamVec4ICore; typedef TMaterialDataParam MaterialParamMat3Core; typedef TMaterialDataParam MaterialParamMat4Core; typedef TMaterialDataParam MaterialParamColorCore; typedef TMaterialParamStruct MaterialParamStruct; typedef TMaterialParamStruct MaterialParamStructCore; typedef TMaterialParamTexture MaterialParamTexture; typedef TMaterialParamTexture MaterialParamTextureCore; typedef TMaterialParamLoadStoreTexture MaterialParamLoadStoreTexture; typedef TMaterialParamLoadStoreTexture MaterialParamLoadStoreTextureCore; typedef TMaterialParamBuffer MaterialParamBuffer; typedef TMaterialParamBuffer MaterialParamBufferCore; typedef TMaterialParamSampState MaterialParamSampState; typedef TMaterialParamSampState MaterialParamSampStateCore; /** @} */ }