X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fcommon%2Fshader-data.h;h=3d50cfa2dda15d2a55d3e490991e6bc3b264710a;hb=163acb9705f8575842b9f2195037598428e0c7ce;hp=35d6d9add97f0416c19f3fc63f56509707147df2;hpb=e3d321fb84d0b431d8f4397b5da285577441cfc7;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/common/shader-data.h b/dali/internal/common/shader-data.h index 35d6d9a..3d50cfa 100644 --- a/dali/internal/common/shader-data.h +++ b/dali/internal/common/shader-data.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_SHADER_DATA_H__ -#define __DALI_INTERNAL_SHADER_DATA_H__ +#ifndef DALI_INTERNAL_SHADER_DATA_H +#define DALI_INTERNAL_SHADER_DATA_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -22,18 +22,31 @@ #include // INTERNAL INCLUDES -#include +#include #include -#include // ShaderHints +#include +#include // ShaderHints namespace Dali { - namespace Internal { - class ShaderData; -typedef IntrusivePtr ShaderDataPtr; +using ShaderDataPtr = IntrusivePtr; + +namespace +{ +static const std::vector emptyShader; + +inline std::vector StringToVector(const std::string& str) +{ + auto retval = std::vector{}; + retval.insert(retval.begin(), str.begin(), str.end()); + retval.push_back('\0'); + return retval; +} + +} // namespace /** * ShaderData class. @@ -42,38 +55,54 @@ typedef IntrusivePtr ShaderDataPtr; class ShaderData : public Dali::RefObject { public: - /** * Constructor * @param[in] vertexSource Source code for vertex program * @param[in] fragmentSource Source code for fragment program + * @param[in] hints Hints for rendering */ - ShaderData(const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::ShaderHints hints) - : mShaderHash( -1 ), + ShaderData(std::string vertexSource, std::string fragmentSource, const Dali::Shader::Hint::Value hints) + : mShaderHash(-1), + mVertexShader(StringToVector(vertexSource)), + mFragmentShader(StringToVector(fragmentSource)), + mHints(hints), + mSourceMode(Graphics::ShaderSourceMode::TEXT) + { + } + + /** + * Creates a shader data containing binary content + * @param[in] vertexSource Source code for vertex program + * @param[in] fragmentSource Source code for fragment program + * @param[in] hints Hints for rendering + */ + ShaderData(std::vector& vertexSource, std::vector& fragmentSource, const Dali::Shader::Hint::Value hints) + : mShaderHash(-1), mVertexShader(vertexSource), mFragmentShader(fragmentSource), - mHints(hints) - { } + mHints(hints), + mSourceMode(Graphics::ShaderSourceMode::BINARY) + { + } protected: /** * Protected Destructor * A reference counted object may only be deleted by calling Unreference() */ - virtual ~ShaderData() + ~ShaderData() override { // vector releases its data } public: // API - /** * Set hash value which is created with vertex and fragment shader code * @param [in] shaderHash hash key created with vertex and fragment shader code */ void SetHashValue(size_t shaderHash) { - DALI_ASSERT_DEBUG( shaderHash != size_t(-1) ); + DALI_ASSERT_DEBUG(shaderHash != size_t(-1)); mShaderHash = shaderHash; } @@ -83,7 +112,7 @@ public: // API */ size_t GetHashValue() const { - DALI_ASSERT_DEBUG( mShaderHash != size_t(-1) ); + DALI_ASSERT_DEBUG(mShaderHash != size_t(-1)); return mShaderHash; } @@ -92,7 +121,7 @@ public: // API */ const char* GetVertexShader() const { - return mVertexShader.c_str(); + return &mVertexShader[0]; } /** @@ -100,13 +129,35 @@ public: // API */ const char* GetFragmentShader() const { - return mFragmentShader.c_str(); + return &mFragmentShader[0]; + } + + /** + * Returns a std::vector containing the shader code associated with particular pipeline stage + * @param[in] the graphics pipeline stage + * @return the shader code + */ + const std::vector& GetShaderForPipelineStage(Graphics::PipelineStage stage) const + { + if(stage == Graphics::PipelineStage::VERTEX_SHADER) + { + return mVertexShader; + } + else if(stage == Graphics::PipelineStage::FRAGMENT_SHADER) + { + return mFragmentShader; + } + else + { + // DALI_LOG_ERROR("Unsupported shader stage\n"); + return emptyShader; + } } /** * @return the hints */ - Dali::Shader::ShaderHints GetHints() const + Dali::Shader::Hint::Value GetHints() const { return mHints; } @@ -123,16 +174,16 @@ public: // API * Allocate a buffer for the compiled binary bytecode * @param[in] size The size of the buffer in bytes */ - void AllocateBuffer( size_t size ) + void AllocateBuffer(std::size_t size) { - mBuffer.Resize( size ); + mBuffer.Resize(size); } /** * Get the program buffer * @return reference to the buffer */ - size_t GetBufferSize() const + std::size_t GetBufferSize() const { return mBuffer.Size(); } @@ -141,9 +192,9 @@ public: // API * Get the data that the buffer points to * @return raw pointer to the buffer data */ - unsigned char* GetBufferData() + uint8_t* GetBufferData() { - DALI_ASSERT_DEBUG( mBuffer.Size() > 0 ); + DALI_ASSERT_DEBUG(mBuffer.Size() > 0); return &mBuffer[0]; } @@ -151,27 +202,35 @@ public: // API * Get the data that the buffer points to * @return raw pointer to the buffer data */ - Dali::Vector& GetBuffer() + Dali::Vector& GetBuffer() { return mBuffer; } -private: // Not implemented - - ShaderData(const ShaderData& other); ///< no copying of this object - ShaderData& operator= (const ShaderData& rhs); ///< no copying of this object - -private: // Data + /** + * Get the source mode of shader data + * @return the source mode of shader data ( text or binary ) + */ + Graphics::ShaderSourceMode GetSourceMode() const + { + return mSourceMode; + } - size_t mShaderHash; ///< hash key created with vertex and fragment shader code - std::string mVertexShader; ///< source code for vertex program - std::string mFragmentShader; ///< source code for fragment program - Dali::Shader::ShaderHints mHints; ///< take a hint - Dali::Vector mBuffer; ///< buffer containing compiled binary bytecode +private: // Not implemented + ShaderData(const ShaderData& other); ///< no copying of this object + ShaderData& operator=(const ShaderData& rhs); ///< no copying of this object + +private: // Data + std::size_t mShaderHash; ///< hash key created with vertex and fragment shader code + std::vector mVertexShader; ///< source code for vertex program + std::vector mFragmentShader; ///< source code for fragment program + Dali::Shader::Hint::Value mHints; ///< take a hint + Dali::Vector mBuffer; ///< buffer containing compiled binary bytecode + Graphics::ShaderSourceMode mSourceMode; ///< Source mode of shader data ( text or binary ) }; -} // namespace Integration +} // namespace Internal } // namespace Dali -#endif // __DALI_INTERNAL_SHADER_DATA_H__ +#endif // DALI_INTERNAL_SHADER_DATA_H