Advertisement
Guest User

Noesis Ogre OpenGL example headers

a guest
Oct 14th, 2013
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.52 KB | None | 0 0
  1. /*
  2.  * File:   NoesisManager.h
  3.  * Author: TheSHEEEP
  4.  *
  5.  * Created on 6. August 2013, 16:02
  6.  */
  7.  
  8. #ifndef NOESISMANAGER_H
  9. #define NOESISMANAGER_H
  10.  
  11. #include <oolua.h>
  12. #include <OgreRenderQueueListener.h>
  13. #include <OgreRenderSystem.h>
  14. #include <OIS.h>
  15.  
  16. #include <NsGui/IRenderer.h>
  17. #include <NsGui/FrameworkElement.h>
  18.    
  19. namespace Ogre
  20. {
  21.     class SceneManager;
  22.     class Root;
  23. }
  24. namespace Noesis
  25. {
  26.     namespace Gui
  27.     {
  28.         class OgreNsGuiFileSystem;
  29.     }
  30. }
  31. class MemoryLog;
  32. class MouseCursor;
  33. class DynamicCallbackRegistry;
  34.  
  35. class NoesisManager
  36.     :   public Ogre::RenderQueueListener
  37.     ,   public Ogre::RenderSystem::Listener
  38.     ,   public OIS::MouseListener
  39. {
  40. public:
  41.     /**
  42.      * Constructor.
  43.      */
  44.     NoesisManager();
  45.  
  46.     /**
  47.      * Destructor.
  48.      */
  49.     virtual ~NoesisManager();
  50.    
  51.     /**
  52.      * Will initialize the Noesis GUI manager, initializing NoesisGUI, logging, etc.
  53.      * @param p_sceneMgr    The Ogre SceneManager to use.
  54.      * @param p_root        The Ogre root.
  55.      * @param p_logger      The logger which will be used to log errors.  
  56.      * @param p_mouse       The OIS Mouse.
  57.      * @param p_width       The width of the screen. In pixels.
  58.      * @param p_height      The height of the screen. In pixels.
  59.      * @return True if the setup succeeded.
  60.      */
  61.     bool setup(Ogre::SceneManager* p_sceneMgr, Ogre::Root* p_root, MemoryLog* p_logger, OIS::Mouse* p_mouse, int p_width, int p_height);
  62.    
  63.     /**
  64.      * Will shutdown the Noesis GUI.
  65.      */
  66.     void shutdown(void);
  67.    
  68.     /**
  69.      * Will update the mouse position.
  70.      * @param p_mouseEvent  The event that is passed when the mouse was moved.
  71.      * @return  Should return true, I guess.
  72.      */
  73.     virtual bool mouseMoved(const OIS::MouseEvent& p_mouseEvent);
  74.    
  75.     /**
  76.      * Will notify the UI of a pressed mouse button.
  77.      * @param p_mouseEvent  The event that is passed when a mouse button was pressed.
  78.      * @param p_id          The ID of the mouse button.
  79.      * @return  Should return true, I guess.
  80.      */
  81.     virtual bool mousePressed(const OIS::MouseEvent& p_mouseEvent, OIS::MouseButtonID p_id);
  82.    
  83.     /**
  84.      * Will notify the UI of a released mouse button.
  85.      * @param p_mouseEvent  The event that is passed when a mouse button was released.
  86.      * @param p_id          The ID of the mouse button.
  87.      * @return  Should return true, I guess.
  88.      */
  89.     virtual bool mouseReleased(const OIS::MouseEvent& p_mouseEvent, OIS::MouseButtonID p_id);
  90.    
  91.     /**
  92.      * This will render the Noesis UI content onto the screen.
  93.      * @param p_queueGroupId        The ID of the current queue group. We only render if it's RENDER_QUEUE_OVERLAY.
  94.      * @param p_invocation          ??
  95.      * @param p_skipThisInvocation  ??
  96.      */
  97.     void renderQueueStarted(Ogre::uint8 p_queueGroupId, const Ogre::String& p_invocation, bool& p_skipThisInvocation);
  98.    
  99.     /**
  100.      * Called by Ogre when an event occurred.
  101.      * @param p_eventName   The name of the event. We will listen for DeviceLost and DeviceRestored.
  102.      * @param p_parameters  The parameters belonging to the event.
  103.      */
  104.     void eventOccurred(const Ogre::String& p_eventName, const Ogre::NameValuePairList* p_parameters);
  105.    
  106.     /**
  107.      * This function must be called each frame before the 3D scene is rendered.
  108.      * @param p_timeSinceLastFrame  The time since the last frame, in seconds.
  109.      */
  110.     void doPreSceneStep(const double& p_timeSinceLastFrame);
  111.    
  112.     /**
  113.      * This function must be called each frame after the 3D scene was rendered.
  114.      */
  115.     void doPostSceneStep();
  116.    
  117.     /**
  118.      * Will bind a lua function to a Gui button with the passed name.
  119.      * @param p_buttonName  The name of the button to attach to.
  120.      * @param p_luaFunc     The lua function to bind.
  121.      */
  122.     void bindFunctionToButtonClick(std::string p_buttonName, OOLUA::Lua_func_ref p_luaFunc);
  123.    
  124.     /**
  125.      * Updates the Ui depending on the jump status.
  126.      */
  127.     void setJumping(bool p_isJumping);
  128.    
  129. private:
  130.     static MemoryLog*  _logger;
  131.     /**
  132.      * This function will be called by Noesis when an error occurs.
  133.      * @param p_filename    The name of the file where the error occurred.
  134.      * @param p_line        The line in the file where the error occured.
  135.      * @param p_desc        The description of the error (by Noesis).
  136.      */
  137.     static void handleNoesisError(const NsChar* p_filename, NsInt p_line, const NsChar* p_desc);
  138.    
  139. private:
  140.     Ogre::SceneManager*         _sceneMgr;
  141.     Ogre::Root*                 _root;
  142.    
  143.     OIS::Mouse*     _mouse;
  144.     MouseCursor*    _mouseCursor;
  145.    
  146.     int _width;
  147.     int _height;
  148.    
  149.     Noesis::Gui::OgreNsGuiFileSystem*           _ogreFileSystem;
  150.     Noesis::Core::Ptr<Noesis::Gui::IRenderer>   _noesisGLRenderer;
  151.     Noesis::Ptr<Noesis::Gui::FrameworkElement>  _xamlRoot;
  152.     Noesis::Gui::RenderCommands                 _renderCommands;
  153.    
  154.     DynamicCallbackRegistry*    _callbackRegistry;
  155.    
  156.     /**
  157.      * Handles a button click.
  158.      * @param p_baseComp    The component that caused the event.
  159.      * @param p_args        ???
  160.      */
  161.     void handleButtonClick(Noesis::Core::BaseComponent* p_baseComp, const Noesis::Gui::RoutedEventArgs& p_args);
  162.    
  163.     /**
  164.      * Will tell Noesis that the device was lost.
  165.      */
  166.     void deviceLostCallback();
  167.  
  168.     /**
  169.      * Will tell Noesis that the device was recovered.
  170.      */
  171.     void deviceResetCallback();
  172.    
  173. private:
  174.     struct RenderStatesStorage
  175.     {
  176.         bool            hasState = false;
  177.         int             frameBuffer;
  178.         float           clearColors[4];
  179.         float           clearDepth;
  180.         int             clearStencil;
  181.         unsigned char   depthTest;
  182.         unsigned char   depthWrite;
  183.         int             depthFunc;
  184.         unsigned char   stencilTest;
  185.         int             stencilTestFailOp;
  186.         int             stencilTestSPDF;
  187.         int             stencilTestSPDP;
  188.         int             stencilFunc;
  189.         int             stencilRef;
  190.         unsigned int    stencilMask;
  191.         unsigned int    stencilWriteMask;
  192.         unsigned char   scissorTest;
  193.         unsigned char   cullFaceEnabled;
  194.         int             cullFaceMode;
  195.         unsigned char   blendEnabled;
  196.         int             blendEquationRGB;
  197.         int             blendEquationA;
  198.         int             blendSource;
  199.         int             blendDestination;
  200.         unsigned char   colorWriteMask[4];
  201.         unsigned int    arrayBuffer;
  202.         unsigned int    maxVertexAttribs;
  203.         int             vertexAttribsEnabled[32];
  204.         int             activeTexture;
  205.         unsigned int    elementArrayBuffer;
  206.         unsigned int    maxTextureUnits;
  207.         int             boundTexture[16];
  208.         int             currentProgram;
  209.         int             unpackAlignment;
  210.     };
  211.     RenderStatesStorage _rsStorage;
  212.    
  213.     /**
  214.      * Will store the current render states.
  215.      */
  216.     void storeCurrentRenderStates();
  217.    
  218.     /**
  219.      * Will restore the previously saved render states.
  220.      */
  221.     void restoreRenderStates();
  222.    
  223.     /**
  224.      * Initializes all OpenGL function pointers.
  225.      */
  226.     void setupOpenGLFuncs();
  227. };
  228.  
  229. OOLUA_PROXY_CLASS(NoesisManager)
  230.     OOLUA_NO_TYPEDEFS
  231.     OOLUA_ONLY_DEFAULT_CONSTRUCTOR
  232.     OOLUA_MEM_FUNC(void, bindFunctionToButtonClick, std::string, OOLUA::Lua_func_ref)
  233.     OOLUA_MEM_FUNC(void, setJumping, bool)
  234. OOLUA_CLASS_END
  235.  
  236.        
  237. #endif  /* NOESISMANAGER_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement