/* osgEarth
 * Copyright 2025 Pelican Mapping
 * MIT License
 */
#ifndef OSGEARTH_SHADER_MERGER_H
#define OSGEARTH_SHADER_MERGER_H 1

#include <osgEarth/GLSLChunker>
#include <osg/Shader>

namespace osg {
    class Program;
}

namespace osgEarth { namespace Util
{
    /**
     * Merges multiple shader objects into one (per type) and installs 
     * them in a program. Some platforms (like GLES) only support one
     * shader object, neccesiting this function.
     */
    class OSGEARTH_EXPORT ShaderMerger
    {
    public:
        //! Adds a shader to the merge set
        void add(const osg::Shader* shader);

        //! Merges all shaders and installs them into the provided program.
        void merge(osg::Program* program);

    private:
        std::vector<const osg::Shader*> _shaders;
        std::set<osg::Shader::Type> _types;

        //! Merge shaders of shaders's type into shader, and returns
        //! the number of shaders merged.
        unsigned merge(osg::Shader* shader);
    };
} }

#endif // OSGEARTH_SHADER_MERGER_H
