#define DALI_GRAPHICS_GLES_SHADER_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
namespace Dali::Graphics::GLES
{
-using ShaderResource = Resource<Graphics::Shader, Graphics::ShaderCreateInfo>;
-
-class Shader : public ShaderResource
+class ShaderImpl
{
public:
/**
* @param[in] createInfo Valid createInfo structure
* @param[in] controller Reference to the controller
*/
- Shader(const Graphics::ShaderCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
+ ShaderImpl(const Graphics::ShaderCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
+ ~ShaderImpl();
+
+ uint32_t Retain();
+
+ uint32_t Release();
+
+ [[nodiscard]] uint32_t GetRefCount() const;
/**
- * @brief Destructor
+ * Whilst unreferenced, increase the flush count and return it
+ *
+ * @return The new flush count
*/
- ~Shader() override = default;
+ [[nodiscard]] uint32_t IncreaseFlushCount();
/**
- * @brief Called when GL resources are destroyed
+ * Get the flush count whilst unreferenced
+ *
+ * @return the flush count
*/
- void DestroyResource() override
- {
- // TODO: Implement destroying the resource
- }
+ [[nodiscard]] uint32_t GetFlushCount() const;
/**
- * @brief Called when initializing the resource
+ * @brief Compiles shader
*
* @return True on success
*/
- bool InitializeResource() override
- {
- // TODO: Implement initializing resource
- return {};
- }
+ [[nodiscard]] bool Compile() const;
/**
- * @brief Compiles shader
- * @return
+ * @brief Destroys GL shader
+ */
+ void Destroy();
+
+ uint32_t GetGLShader() const;
+
+ [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
+
+ [[nodiscard]] EglGraphicsController& GetController() const;
+
+private:
+ friend class Shader;
+ struct Impl;
+ std::unique_ptr<Impl> mImpl{nullptr};
+};
+
+class Shader : public Graphics::Shader
+{
+public:
+ /**
+ * @brief Constructor
+ *
+ * @param[in] impl Pointer to valid implementation
*/
- bool Compile() const
+ explicit Shader(ShaderImpl* impl)
+ : mShader(impl)
{
- mGlShader = 0;
- return true;
+ mShader->Retain();
}
/**
- * @brief Called when UniquePtr<> on client-side dies
+ * @brief Destructor
*/
- void DiscardResource() override
+ ~Shader() override;
+
+ [[nodiscard]] ShaderImpl* GetImplementation() const
+ {
+ return mShader;
+ }
+
+ [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
+
+ bool operator==(const GLES::Shader& shader) const
+ {
+ return (shader.mShader == mShader);
+ }
+
+ bool operator==(const GLES::ShaderImpl* shaderImpl) const
+ {
+ return (shaderImpl == mShader);
+ }
+
+ bool operator!=(const GLES::Shader& shader) const
{
- // TODO: Implement moving to the discard queue
+ return (shader.mShader != mShader);
}
- uint32_t GetGLShader() const
+ /**
+ * @brief Called when UniquePtr<> on client-side dies.
+ */
+ void DiscardResource();
+
+ /**
+ * @brief Destroying GL resources
+ *
+ * This function is kept for compatibility with Resource<> class
+ * so can the object can be use with templated functions.
+ */
+ void DestroyResource()
{
- return mGlShader;
+ // nothing to do here
}
private:
- mutable uint32_t mGlShader;
+ ShaderImpl* mShader{nullptr};
};
} // namespace Dali::Graphics::GLES