<commit_before>/*
  -----------------------------------------------------------------------------
  This source file is part of OGRE
  (Object-oriented Graphics Rendering Engine)
  For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2014 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

  You may use this sample code for anything you like, it is not covered by the
  same license as the rest of the engine.
  -----------------------------------------------------------------------------
*/

#ifndef __CompositorDemo_H__
#define __CompositorDemo_H__

#include "OgreConfigFile.h"
#include "OgreStringConverter.h"
#include "OgreException.h"

#include "SdkSample.h"
#include "SamplePlugin.h"

using namespace Ogre;
using namespace OgreBites;

#define COMPOSITORS_PER_PAGE 8

class _OgreSampleClassExport Sample_Compositor : public SdkSample
{
 public:
    Sample_Compositor();

    void setupContent(void);
    void cleanupContent(void);

    bool frameRenderingQueued(const FrameEvent& evt);

    void checkBoxToggled(OgreBites::CheckBox * box);
    void buttonHit(OgreBites::Button* button);
    void itemSelected(OgreBites::SelectMenu* menu);

 protected:

    void setupView(void);
    void setupControls(void);
    void setupScene(void);
    void createEffects(void);
    void createTextures(void);

    void registerCompositors();
    void changePage(size_t pageNum);

    SceneNode * mSpinny;
    StringVector mCompositorNames;
    size_t mActiveCompositorPage;
    size_t mNumCompositorPages;

    //Used to unregister compositor logics and free memory
    typedef std::map<String, CompositorLogic*> CompositorLogicMap;
    CompositorLogicMap mCompositorLogics;

    String mDebugCompositorName;
    SelectMenu* mDebugTextureSelectMenu;
    TextureUnitState* mDebugTextureTUS;

};

/**
   @file
   Compositor.cpp
   @brief
   Shows OGRE's Compositor feature
   @author
   W.J. :wumpus: <NAME>
   Ogre compositor framework
   <NAME>
   Postfilter ideas and original out-of-core implementation
   Jeff (nfz) Doyle
   added gui framework to demo
*/

#include "HelperLogics.h"

/*************************************************************************
                            Sample_Compositor Methods
*************************************************************************/
Sample_Compositor::Sample_Compositor()
{
    mInfo["Title"] = "Compositor";
    mInfo["Description"] = "A demo of Ogre's post-processing framework.";
    mInfo["Thumbnail"] = "thumb_comp.png";
    mInfo["Category"] = "Effects";
}


void Sample_Compositor::setupView()
{
    SdkSample::setupView();
    mCameraNode->setPosition(Ogre::Vector3(0,0,0));
    mCameraNode->lookAt(Ogre::Vector3(0,0,-300), Ogre::Node::TS_PARENT);
    mCamera->setNearClipDistance(1);
}


void Sample_Compositor::setupContent(void)
{
    // Register the compositor logics
    // See comment in beginning of HelperLogics.h for explanation
    Ogre::CompositorManager& compMgr = Ogre::CompositorManager::getSingleton();
    mCompositorLogics["GaussianBlur"] = new GaussianBlurLogic;
    mCompositorLogics["HDR"] = new HDRLogic;
    mCompositorLogics["HeatVision"] = new HeatVisionLogic;
    compMgr.registerCompositorLogic("GaussianBlur", mCompositorLogics["GaussianBlur"]);
    compMgr.registerCompositorLogic("HDR", mCompositorLogics["HDR"]);
    compMgr.registerCompositorLogic("HeatVision", mCompositorLogics["HeatVision"]);

#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
    mShaderGenerator->createScheme("HDR"); // make sure HDR viewport is handled
#endif

    createTextures();
    /// Create a couple of hard coded postfilter effects as an example of how to do it
    /// but the preferred method is to use compositor scripts.
    createEffects();

    setupScene();

    registerCompositors();

    setupControls();

#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
    setDragLook(true);
#endif
}

void Sample_Compositor::registerCompositors(void)
{
    Ogre::Viewport *vp = mViewport;

    //iterate through Compositor Managers resources and add name keys to menu
    Ogre::CompositorManager::ResourceMapIterator resourceIterator =
        Ogre::CompositorManager::getSingleton().getResourceIterator();

    // add all compositor resources to the view container
    while (resourceIterator.hasMoreElements())
    {
        Ogre::ResourcePtr resource = resourceIterator.getNext();
        const Ogre::String& compositorName = resource->getName();
        // Don't add base Ogre/Scene compositor to view
        if (Ogre::StringUtil::startsWith(compositorName, "Ogre/Scene/", false))
            continue;
        // Don't add the deferred shading compositors, thats a different demo.
        if (Ogre::StringUtil::startsWith(compositorName, "DeferredShading", false))
            continue;
        // Don't add the SSAO compositors, thats a different demo.
        if (Ogre::StringUtil::startsWith(compositorName, "SSAO", false))
            continue;
        // Don't add the TestMRT compositor, it needs extra scene setup so doesn't currently work.
        if (Ogre::StringUtil::startsWith(compositorName, "TestMRT", false))
            continue;
        // Don't add the Compute compositors, thats a different demo.
        if (Ogre::StringUtil::startsWith(compositorName, "Compute", false))
            continue;

        mCompositorNames.push_back(compositorName);
        int addPosition = -1;
        if (compositorName == "HDR")
        {
            // HDR must be first in the chain
            addPosition = 0;
        }
        try
        {
            Ogre::CompositorManager::getSingleton().addCompositor(vp, compositorName, addPosition);
            Ogre::CompositorManager::getSingleton().setCompositorEnabled(vp, compositorName, false);
        } catch (...) {
            /// Warn user
            LogManager::getSingleton().logMessage("Could not load compositor " + compositorName, LML_CRITICAL);
        }
    }

    mNumCompositorPages = (mCompositorNames.size() / COMPOSITORS_PER_PAGE) +
        ((mCompositorNames.size() % COMPOSITORS_PER_PAGE == 0) ? 0 : 1);
}


void Sample_Compositor::changePage(size_t pageNum)
{
    assert(pageNum < mNumCompositorPages);
<commit_msg>Samples: Compositor - update blacklist<commit_after>/*
  -----------------------------------------------------------------------------
  This source file is part of OGRE
  (Object-oriented Graphics Rendering Engine)
  For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2014 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

  You may use this sample code for anything you like, it is not covered by the
  same license as the rest of the engine.
  -----------------------------------------------------------------------------
*/

#ifndef __CompositorDemo_H__
#define __CompositorDemo_H__

#include "OgreConfigFile.h"
#include "OgreStringConverter.h"
#include "OgreException.h"

#include "SdkSample.h"
#include "SamplePlugin.h"

using namespace Ogre;
using namespace OgreBites;

#define COMPOSITORS_PER_PAGE 8

class _OgreSampleClassExport Sample_Compositor : public SdkSample
{
 public:
    Sample_Compositor();

    void setupContent(void);
    void cleanupContent(void);

    bool frameRenderingQueued(const FrameEvent& evt);

    void checkBoxToggled(OgreBites::CheckBox * box);
    void buttonHit(OgreBites::Button* button);
    void itemSelected(OgreBites::SelectMenu* menu);

 protected:

    void setupView(void);
    void setupControls(void);
    void setupScene(void);
    void createEffects(void);
    void createTextures(void);

    void registerCompositors();
    void changePage(size_t pageNum);

    SceneNode * mSpinny;
    StringVector mCompositorNames;
    size_t mActiveCompositorPage;
    size_t mNumCompositorPages;

    //Used to unregister compositor logics and free memory
    typedef std::map<String, CompositorLogic*> CompositorLogicMap;
    CompositorLogicMap mCompositorLogics;

    String mDebugCompositorName;
    SelectMenu* mDebugTextureSelectMenu;
    TextureUnitState* mDebugTextureTUS;

};

/**
   @file
   Compositor.cpp
   @brief
   Shows OGRE's Compositor feature
   @author
   W.J. :wumpus: <NAME>
   Ogre compositor framework
   <NAME>
   Postfilter ideas and original out-of-core implementation
   Jeff (nfz) Doyle
   added gui framework to demo
*/

#include "HelperLogics.h"

/*************************************************************************
                            Sample_Compositor Methods
*************************************************************************/
Sample_Compositor::Sample_Compositor()
{
    mInfo["Title"] = "Compositor";
    mInfo["Description"] = "A demo of Ogre's post-processing framework.";
    mInfo["Thumbnail"] = "thumb_comp.png";
    mInfo["Category"] = "Effects";
}


void Sample_Compositor::setupView()
{
    SdkSample::setupView();
    mCameraNode->setPosition(Ogre::Vector3(0,0,0));
    mCameraNode->lookAt(Ogre::Vector3(0,0,-300), Ogre::Node::TS_PARENT);
    mCamera->setNearClipDistance(1);
}


void Sample_Compositor::setupContent(void)
{
    // Register the compositor logics
    // See comment in beginning of HelperLogics.h for explanation
    Ogre::CompositorManager& compMgr = Ogre::CompositorManager::getSingleton();
    mCompositorLogics["GaussianBlur"] = new GaussianBlurLogic;
    mCompositorLogics["HDR"] = new HDRLogic;
    mCompositorLogics["HeatVision"] = new HeatVisionLogic;
    compMgr.registerCompositorLogic("GaussianBlur", mCompositorLogics["GaussianBlur"]);
    compMgr.registerCompositorLogic("HDR", mCompositorLogics["HDR"]);
    compMgr.registerCompositorLogic("HeatVision", mCompositorLogics["HeatVision"]);

#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
    mShaderGenerator->createScheme("HDR"); // make sure HDR viewport is handled
#endif

    createTextures();
    /// Create a couple of hard coded postfilter effects as an example of how to do it
    /// but the preferred method is to use compositor scripts.
    createEffects();

    setupScene();

    registerCompositors();

    setupControls();

#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
    setDragLook(true);
#endif
}

static bool blacklisted(const String& name)
{
    const char* blacklist[] = {"Ogre/Scene/", "DeferredShading", "SSAO", "TestMRT", "Compute", "Fresnel", "CubeMap"};

    for(auto it : blacklist)
    {
        if(name.find(it) == 0)
            return true;
    }

    return false;
}

void Sample_Compositor::registerCompositors(void)
{
    Ogre::Viewport *vp = mViewport;

    //iterate through Compositor Managers resources and add name keys to menu
    Ogre::CompositorManager::ResourceMapIterator resourceIterator =
        Ogre::CompositorManager::getSingleton().getResourceIterator();

    // add all compositor resources to the view container
    while (resourceIterator.hasMoreElements())
    {
        Ogre::ResourcePtr resource = resourceIterator.getNext();
        const Ogre::String& compositorName = resource->getName();

        // Don't add blacklisted compositor to view
        if (blacklisted(compositorName))
            continue;

        mCompositorNames.push_back(compositorName);
        int addPosition = -1;
        if (compositorName == "HDR")
        {
            // HDR must be first in the chain
            addPosition = 0;
        }
        try
        {
            Ogre::CompositorManager::getSingleton().addCompositor(vp, compositorName, addPosition);
            Ogre::CompositorManager::getSingleton().setCompositorEnabled(vp, compositorName, false);
        } catch (...) {
            /// Warn user
            LogManager::getSingleton().logMessage("Could not load compositor " + compositorName, LML_CRITICAL);
        }
    }

    mNumCompositorPages = (mCompositorNames.size() / COMPOSITORS_PER_PAGE) +
        ((mCompositorNames.size() % COMPOSITORS_PER_PAGE == 0) ? 0 : 1);
}


void Sample_Compositor::changePage(size_t pageNum)
{
    assert(pageNum < mNumCompositorPages);

{'fraction_non_alphanumeric': 0.14715494846224755, 'fraction_numerical': 0.004441464845386742, 'mean_word_length': 3.390728476821192, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6330585', 'n_tokens_mistral': 3657, 'n_tokens_neox': 3520, 'n_words': 824}