OpenMW
libs/openengine/ogre/selectionbuffer.hpp
Go to the documentation of this file.
00001 #ifndef OENGINE_SELECTIONBUFFER_H
00002 #define OENGINE_SELECTIONBUFFER_H
00003 
00004 
00005 #include <OgreTexture.h>
00006 #include <OgreRenderTarget.h>
00007 #include <OgreMaterialManager.h>
00008 
00009 namespace OEngine
00010 {
00011 namespace Render
00012 {
00013 
00014     struct cmp_ColourValue
00015     {
00016         bool operator()(const Ogre::ColourValue &a, const Ogre::ColourValue &b) const
00017         {
00018         return a.getAsBGRA() < b.getAsBGRA();
00019         }
00020     };
00021 
00022     class SelectionBuffer : public Ogre::MaterialManager::Listener
00023     {
00024     public:
00025         SelectionBuffer(Ogre::Camera* camera, int sizeX, int sizeY, int visibilityFlags);
00026         virtual ~SelectionBuffer();
00027 
00028         int getSelected(int xPos, int yPos);
00030 
00031         void update();
00032 
00033         virtual Ogre::Technique* handleSchemeNotFound (
00034             unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial,
00035             unsigned short lodIndex, const Ogre::Renderable *rend);
00036 
00037 
00038     private:
00039         Ogre::TexturePtr mTexture;
00040         Ogre::RenderTexture* mRenderTarget;
00041 
00042         Ogre::Image mBuffer;
00043 
00044         std::map<Ogre::ColourValue, int, cmp_ColourValue> mColourMap;
00045 
00046         Ogre::ColourValue mCurrentColour;
00047 
00048         void getNextColour();
00049     };
00050 
00051 }
00052 }
00053 
00054 #endif