/* osgEarth
 * Copyright 2025 Pelican Mapping
 * MIT License
 */
#pragma once

#include <osgEarth/Common>
#include <osgEarth/DepthOffset>
#include <osgEarth/Expression>
#include <osgEarth/Symbol>
#include <osg/Referenced>
#include <vector>

namespace osgEarth
{
    /** 
     * Symbol that contains general rendering settings.
     */
    class OSGEARTH_EXPORT RenderSymbol : public Symbol
    {
    public:
        META_Object(osgEarth, RenderSymbol);

        /** construct a render symbol */
        RenderSymbol(const Config& conf =Config());
        RenderSymbol(const RenderSymbol& rhs,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        /** whether to perform depth buffer testing */
        OE_OPTION(bool, depthTest, true);

        /** whether to force lighting on/off */
        OE_OPTION(bool, lighting, true);

        /** depth offset properties */
        OE_OPTION(DepthOffsetOptions, depthOffset);

        /** whether to force backface culling on or off */
        OE_OPTION(bool, backfaceCulling, true);

        /** applies a rendering order to affected geometry */
        OE_OPTION(Expression<int>, order, 0);

        /** clip plane number to activate. */
        OE_OPTION(unsigned, clipPlane, 0);

        /** discard fragments with alpha < threshold */
        OE_OPTION(float, minAlpha, 0.0f);

        /** hint to render in the transparent (depth-sorted) bin */
        OE_OPTION(bool, transparent, false);

        /** render bin to use for sorting */
        OE_OPTION(std::string, renderBin);

        /** enable decaling (lequal + polygonoffset) */
        OE_OPTION(bool, decal, false);

        /** maximum crease angle for normal smoothing (default=0) */
        OE_OPTION(Angle, maxCreaseAngle, Angle(0, Units::DEGREES));

        /** maximum angle at which to tessellate geometry when curving it to the earth's surface */
        OE_OPTION(Angle, maxTessAngle, Angle(1, Units::DEGREES));

        /** maximum visibility altitude */
        OE_OPTION(Distance, maxAltitude, Distance(FLT_MAX, Units::METERS));

        /** geometric error present when rendering */
        OE_OPTION(Distance, geometricError, Distance(0.0, Units::METERS));

        /** minimum distance (maps to 0) when rendering a signed distance field */
        OE_OPTION(Expression<Distance>, sdfMinDistance, Distance(0.0, Units::METERS));

        /** maximum distance (maps to 1) when rendering a signed distance field */
        OE_OPTION(Expression<Distance>, sdfMaxDistance, Distance(20.0, Units::METERS));

    public:
        virtual Config getConfig() const;
        virtual void mergeConfig( const Config& conf );
        static void parseSLD(const Config& c, class Style& style);

        void applyTo(osg::Node*) const;
    };
} // namespace osgEarth
