#define DALI_INTERNAL_SHADER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
-#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
-#include <dali/public-api/rendering/shader.h> // Dali::Shader
+#include <dali/internal/common/shader-data.h> // ShaderPtr
#include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
-#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
-#include <dali/internal/common/shader-data.h> // ShaderPtr
+#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
+#include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
+#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
+#include <dali/public-api/rendering/shader.h> // Dali::Shader
namespace Dali
{
class Shader : public Object
{
public:
+ /**
+ * @copydoc Dali::Shader::New()
+ */
+ static ShaderPtr New(std::string_view vertexShader,
+ std::string_view fragmentShader,
+ Dali::Shader::Hint::Value hints,
+ std::string_view shaderName);
/**
* @copydoc Dali::Shader::New()
*/
- static ShaderPtr New( const std::string& vertexShader,
- const std::string& fragmentShader,
- Dali::Shader::Hint::Value hints );
+ static ShaderPtr New(Dali::Property::Value shaderMap);
/**
* Retrieve the scene-graph shader added by this object.
const SceneGraph::Shader& GetShaderSceneObject() const;
public: // Default property extensions from Object
-
/**
* @copydoc Dali::Internal::Object::SetDefaultProperty()
*/
/**
* @copydoc Dali::Internal::Object::GetDefaultProperty()
*/
- Property::Value GetDefaultProperty( Property::Index index ) const override;
+ Property::Value GetDefaultProperty(Property::Index index) const override;
/**
* @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
*/
- Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const override;
+ Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
private: // implementation
-
/**
* Constructor
*
- * @param sceneObject the scene object
+ * @param[in] sceneObject the scene object
+ */
+ Shader(const SceneGraph::Shader* sceneObject);
+
+ /**
+ * @brief Update Shader Data
+ * If a ShaderData of the same renderPassTag is already exist, it is replaced,
+ * if not, new ShaderData is added.
+ * @param[in] vertexShader Vertex shader code for the effect.
+ * @param[in] fragmentShader Fragment Shader code for the effect.
+ * @param[in] renderPassTag render pass tag of this shader data
+ * @param[in] hints Hints to define the geometry of the rendered object
+ * @param[in] name The name of shader data.
*/
- Shader( const SceneGraph::Shader* sceneObject );
+ void UpdateShaderData(std::string_view vertexShader, std::string_view fragmentShader, uint32_t renderPassTag, Dali::Shader::Hint::Value hints, std::string_view name);
/**
- * Second stage initialization
+ * @brief Sets shader data from shaderMap.
+ * The shaderMap should be Property::Map or Property::Array.
+ * @param[in] shaderMap shader property map.
*/
- void SetShader( const std::string& vertexShader, const std::string& fragmentShader, Dali::Shader::Hint::Value hints );
+ void SetShaderProperty(const Dali::Property::Value& shaderMap);
protected:
/**
~Shader() override;
private: // unimplemented methods
-
- Shader() = delete;
- Shader( const Shader& ) = delete;
- Shader& operator=( const Shader& ) = delete;
+ Shader() = delete;
+ Shader(const Shader&) = delete;
+ Shader& operator=(const Shader&) = delete;
private:
+ std::vector<Internal::ShaderDataPtr> mShaderDataList;
+
+public:
+ /**
+ * @copydoc Dali::Shader::GetShaderLanguageVersion()
+ */
+ static uint32_t GetShaderLanguageVersion();
+
+ /**
+ * @copydoc Dali::Shader::GetShaderVersionPrefix()
+ */
+ static std::string GetShaderVersionPrefix();
+
+ /**
+ * @copydoc Dali::Shader::GetVertexShaderPrefix()
+ */
+ static std::string GetVertexShaderPrefix();
- Internal::ShaderDataPtr mShaderData;
+ /**
+ * @copydoc Dali::Shader::GetFragmentShaderPrefix()
+ */
+ static std::string GetFragmentShaderPrefix();
+public:
+ /**
+ * Generates tag 'legacy-prefix-end' with end position of
+ * prefix text to make shader code parsing easier.
+ * Function is public to be testable
+ */
+ static std::string GenerateTaggedShaderPrefix(const std::string& shaderPrefix);
};
} // namespace Internal
// Helpers for public-api forwarding methods
-inline Internal::Shader& GetImplementation( Dali::Shader& handle )
+inline Internal::Shader& GetImplementation(Dali::Shader& handle)
{
DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");
return static_cast<Internal::Shader&>(object);
}
-inline const Internal::Shader& GetImplementation( const Dali::Shader& handle )
+inline const Internal::Shader& GetImplementation(const Dali::Shader& handle)
{
DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");