<commit_before>/**
 * @file PostEffect.h
 *
 * Copyright (c) 2015 by <NAME>
 *
 * Code covered by the MIT License
 * The authors make no representations about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 */


#ifndef _POSTEFFECT_H_
#define _POSTEFFECT_H_

#include <OgreRoot.h>
#include <OgrePrerequisites.h>
#include <OgreStringInterface.h>
#include <OgreResource.h>
#include <OgreCompositor.h>
#include <OgreSharedPtr.h>
#include <OgreCompositorInstance.h>
#include <OgreMaterial.h>

namespace Ogre
{
    class RenderWindow;
    class Timer;
}

namespace OgreEffect
{

    class PostEffect : public Ogre::StringInterface, public Ogre::CompositorInstance::Listener
    {
    protected:
        using MaterialsVector = Ogre::vector<Ogre::Material*>::type;
        //-------------------------------------------------------

        static const Ogre::String DICTIONARY_NAME; ///< name of the parameters dictionary for this class

        static const Ogre::String TEXTURE_MARKER_SCENE; ///< name marker for attaching RT with rendered scene 
        static const Ogre::String TEXTURE_MARKER_PREVIOUS; ///< name marker for attaching RT from the previous pass
        //-------------------------------------------------------

    private:
        //Store materials of the effect shared between all instances
        //Will be initialized by the first effect instance
        //ToDo: maybe using the static field is not the best idea. Consider other solutions
        static OGRE_HashMap<Ogre::String, MaterialsVector> msMaterialPrototypesMap;
        //-------------------------------------------------------
        
        /**
         * Create dummy textures with names of markers in order to
         * the Material Manager will generate 'failed to find texture' errors
         */
        static void CreateMarkerDummies();
        //-------------------------------------------------------

        bool mInited = false;
        Ogre::Real mStartTime = -1;

        //Ogre::CompositorPtr mCompositor;
        Ogre::CompositorInstance* mCompositorInstance;

        //name of the render target where the scene will be rendered before applying post effects
        Ogre::String mSceneRtName;

        //-------------------------------------------------------
        //Get current global time 
        Ogre::Real GetTimeInSeconds() const;

        //Basic initialization; then calls DoCreateParametersDictionary()
        void CreateParametersDictionary();


        PostEffect(const PostEffect&) = delete;
        PostEffect(const PostEffect&&) = delete;
        PostEffect& operator=(const PostEffect&) = delete;
        PostEffect& operator=(const PostEffect&&) = delete;
        //-------------------------------------------------------

    protected:
        const Ogre::String mName; ///< Unique name of the post effect type
        const size_t mId; ///< Unique number of the post effect instance

        const Ogre::RenderWindow* mRenderWindow;

        Ogre::Timer* mTimer = Ogre::Root::getSingleton().getTimer();

        //Helper method to generate unique names
        Ogre::String GetUniquePostfix() const;

        /**
         * Create and setup post effect compositor; Add to the end of the chain
         * @return true if the created compositor has any supported technique
         */
        bool CreateCompositor(const MaterialsVector & materials, Ogre::CompositorChain* chain);

        //-------------------------------------------------------

        //Methods for implementing in the derived classes

        /**
         * Create a material which will be used in the post effect compositor pass
         * This method will be called only one time to create the material prototype during
         * the first PostEffect instance initialization. The compositor instances
         * of the all PostEffect instances will be using copies of this material as
         * it is implemented in the OGRE compositor
         *
         * Use the special name marker TEXTURE_MARKER_SCENE to attach compositor local RT with
         * rendered scene to material's texture unit state. Can be used in any material
         *
         * Use the name marker TEXTURE_MARKER_PREVIOUS to attach output of the previous material
         * to the current material's texture unit state
         *
         * @return A vector of materials which will be transformed to compositor passes in the same order
         * 
         */
        virtual MaterialsVector CreateEffectMaterialPrototypes() = 0;


        //Setup dictionary values depending on the specific PostEffect implementation
        virtual void DoCreateParametersDictionary(Ogre::ParamDictionary* dictionary) {}
        /*
         * Effects initialization
         */<commit_msg>PostEffect.h: the method CreateCompositor() is moved to the private section<commit_after>/**
 * @file PostEffect.h
 *
 * Copyright (c) 2015 by <NAME>
 *
 * Code covered by the MIT License
 * The authors make no representations about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 */


#ifndef _POSTEFFECT_H_
#define _POSTEFFECT_H_

#include <OgreRoot.h>
#include <OgrePrerequisites.h>
#include <OgreStringInterface.h>
#include <OgreResource.h>
#include <OgreCompositor.h>
#include <OgreSharedPtr.h>
#include <OgreCompositorInstance.h>
#include <OgreMaterial.h>

namespace Ogre
{
    class RenderWindow;
    class Timer;
}

namespace OgreEffect
{

    class PostEffect : public Ogre::StringInterface, public Ogre::CompositorInstance::Listener
    {
    protected:
        using MaterialsVector = Ogre::vector<Ogre::Material*>::type;
        //-------------------------------------------------------

        static const Ogre::String DICTIONARY_NAME; ///< name of the parameters dictionary for this class

        static const Ogre::String TEXTURE_MARKER_SCENE; ///< name marker for attaching RT with rendered scene 
        static const Ogre::String TEXTURE_MARKER_PREVIOUS; ///< name marker for attaching RT from the previous pass
        //-------------------------------------------------------

    private:
        //Store materials of the effect shared between all instances
        //Will be initialized by the first effect instance
        //ToDo: maybe using the static field is not the best idea. Consider other solutions
        static OGRE_HashMap<Ogre::String, MaterialsVector> msMaterialPrototypesMap;
        //-------------------------------------------------------
        
        /**
         * Create dummy textures with names of markers in order to
         * the Material Manager will generate 'failed to find texture' errors
         */
        static void CreateMarkerDummies();
        //-------------------------------------------------------

        bool mInited = false;
        Ogre::Real mStartTime = -1;

        //Ogre::CompositorPtr mCompositor;
        Ogre::CompositorInstance* mCompositorInstance;

        //name of the render target where the scene will be rendered before applying post effects
        Ogre::String mSceneRtName;

        //-------------------------------------------------------
        //Get current global time 
        Ogre::Real GetTimeInSeconds() const;

        //Basic initialization; then calls DoCreateParametersDictionary()
        void CreateParametersDictionary();


        /**
        * Create and setup post effect compositor; Add to the end of the chain
        * @return true if the created compositor has any supported technique
        */
        bool CreateCompositor(const MaterialsVector & materials, Ogre::CompositorChain* chain);


        PostEffect(const PostEffect&) = delete;
        PostEffect(const PostEffect&&) = delete;
        PostEffect& operator=(const PostEffect&) = delete;
        PostEffect& operator=(const PostEffect&&) = delete;
        //-------------------------------------------------------

    protected:
        const Ogre::String mName; ///< Unique name of the post effect type
        const size_t mId; ///< Unique number of the post effect instance

        const Ogre::RenderWindow* mRenderWindow;

        Ogre::Timer* mTimer = Ogre::Root::getSingleton().getTimer();

        //Helper method to generate unique names
        Ogre::String GetUniquePostfix() const;

        //-------------------------------------------------------

        //Methods for implementing in the derived classes

        /**
         * Create a material which will be used in the post effect compositor pass
         * This method will be called only one time to create the material prototype during
         * the first PostEffect instance initialization. The compositor instances
         * of the all PostEffect instances will be using copies of this material as
         * it is implemented in the OGRE compositor
         *
         * Use the special name marker TEXTURE_MARKER_SCENE to attach compositor local RT with
         * rendered scene to material's texture unit state. Can be used in any material
         *
         * Use the name marker TEXTURE_MARKER_PREVIOUS to attach output of the previous material
         * to the current material's texture unit state
         *
         * @return A vector of materials which will be transformed to compositor passes in the same order
         * 
         */
        virtual MaterialsVector CreateEffectMaterialPrototypes() = 0;


        //Setup dictionary values depending on the specific PostEffect implementation
        virtual void DoCreateParametersDictionary(Ogre::ParamDictionary* dictionary) {}
        /*
         * Effects initialization
         */
{'fraction_non_alphanumeric': 0.14341725134131242, 'fraction_numerical': 0.0012381345439537762, 'mean_word_length': 2.028116213683224, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3065362', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2179, 'n_words': 875}