bool
COgrePluginAdapter::Link( void* modulePtr                         ,
                          CORE::TPluginMetaDataPtr pluginMetaData )
{GUCEF_TRACE;

    if ( IsLoaded() ) return false;
    
    m_moduleHandle = modulePtr;
    if ( NULL != m_moduleHandle )
    {
        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "COgrePluginAdapter: Linking API using module pointer: " + CORE::PointerToString( modulePtr ) );
            
        // We have now successfully loaded the module itself
        // We will now try to lookup the function pointers
        m_funcPointers[ OGREPLUGINFUNCPTR_STARTPLUGIN ] = CORE::GetFunctionAddress( m_moduleHandle   ,
                                                                                    "dllStartPlugin" ,
                                                                                    0                ).funcPtr;
        m_funcPointers[ OGREPLUGINFUNCPTR_STOPPLUGIN ] = CORE::GetFunctionAddress( m_moduleHandle  ,
                                                                                   "dllStopPlugin" ,
                                                                                   0               ).funcPtr;

        // Verify that all function pointers are loaded correctly
        if ( ( NULL != m_funcPointers[ OGREPLUGINFUNCPTR_STARTPLUGIN ] ) &&
             ( NULL != m_funcPointers[ OGREPLUGINFUNCPTR_STOPPLUGIN ] )  )
        {
            // Call the module's dllStartPlugin()
            reinterpret_cast< TOGREPLUGFPTR_StartPlugin >( m_funcPointers[ OGREPLUGINFUNCPTR_STARTPLUGIN ] )();
                
            // We have loaded & linked our plugin module
            GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "COgrePluginAdapterCORE::: Successfully loaded module and invoked dllStartPlugin() using module: " + CORE::PointerToString( modulePtr ) );

            // Copy the given metadata 
            m_metaData = new CORE::CPluginMetaData( *pluginMetaData );                

            return true;                
        }
        else
        {
            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "COgrePluginAdapter: Failed to locate the required exports in module: " + CORE::PointerToString( modulePtr ) );
        }

        // We failed to link the functions :(
        memset( m_funcPointers, 0, OGREPLUGINFUNCPTR_COUNT );
        m_moduleHandle = NULL;
        return false;
    }

    // Unloading->Loading must be done explicitly
    return false;
}
Esempio n. 2
0
void
CGUIManager::RegisterGUIDriver( const CString& driverName ,
                                CIGUIDriver& driver       )
{GUCE_TRACE;

    GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "GUCE CGUIManager: registering GUI driver: " + driverName );
    
    m_drivers[ driverName ] = &driver;
    
    if ( m_selectedDriverName.IsNULLOrEmpty() )
    {        
        GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "GUCE CGUIManager: Setting the selected GUI driver to " + driverName );
        m_selectedDriverName = driverName;
    }
}
CProdManGlobal::~CProdManGlobal()
{GUCEF_TRACE;

    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "Shutting down gucefPRODMAN global systems" );
        
    delete m_productManager;
    m_productManager = NULL;
    delete m_productInfoListProviderRegistry;
    m_productInfoListProviderRegistry = NULL;
}
void
CProdManGlobal::Initialize( void )
{GUCEF_TRACE;

    // Ensure the systems we depend on are initialzed first
    CORE::CCoreGlobal::Instance();
    COMCORE::CComCoreGlobal::Instance();

    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "Initializing gucefPRODMAN Global systems" );

    m_productInfoListProviderRegistry = new CProductInfoListProviderRegistry();
    m_productManager = new CProductManager();

    CProductManager::RegisterEvents();
    CProductInfoListProvider::RegisterEvents();

    m_productInfoListProviderRegistry->RegisterProvider( "CodecBased", new CCodecBasedProductInfoListProvider() );

    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "gucefPRODMAN Global systems initialized" );
}
Esempio n. 5
0
void
CGUIManager::ShutdownGUISystems( void )
{GUCE_TRACE;

    if ( m_initialized )
    {   
        GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "Shutting down GUI system" );

        TDriverMap::iterator i = m_drivers.find( m_selectedDriverName );
        if ( i != m_drivers.end() )
        {
            CIGUIDriver* driver = (*i).second;
            driver->Shutdown();
        }
                
        m_initialized = false;
        
        GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "Shutdown of GUI system complete" );
    }
}
Esempio n. 6
0
void
CGUIManager::UnregisterGUIDriver( const CString& driverName )
{GUCE_TRACE;

    TDriverMap::iterator i = m_drivers.find( driverName );
    if ( i != m_drivers.end() )
    {
        GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "GUCE CGUIManager: Unregistering GUI driver: " + driverName ); 
        
        if ( (*i).second->Shutdown() )
        {
            GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "GUCE CGUIManager: GUI driver successfully shutdown. Reason: because it is being unregistered. Name: " + driverName );
        }
        else
        {
            GUCEF_ERROR_LOG( GUCEF::CORE::LOGLEVEL_IMPORTANT, "GUCE CGUIManager: GUI driver failed to shutdown. Reason: Shutdown because it is being unregistered. Name: " + driverName );
        }
               
        m_drivers.erase( i );
    }
}
bool
CProductManager::SaveConfig( GUCEF::CORE::CDataNode& node )
{GUCEF_TRACE;

    GUCEF_SYSTEM_LOG( 0, "Saving the product manager configuration" );

    GUCEF::CORE::CDataNode* n = node.Structure( "GU%CORE%CProductManager", '%' );
    n->SetAttribute( "ProductListPath", m_productListPath );
    n->SetAttribute( "ProductListCodec", m_productListCodec );
    n->SetAttribute( "CommonProductRoot", m_productRoot );
    m_downloadsManager.SaveConfig( node );
    return true;
}
void
CGUIContextOgre::OnNotify( CORE::CNotifier* notifier   ,
                           const CORE::CEvent& eventID ,
                           CORE::CICloneable* evenData )
{GUCEF_TRACE;

    if ( eventID == GUI::CWindowContext::WindowContextRedrawEvent   ||
         eventID == GUI::CWindowContext::WindowContextActivateEvent  )
    {
        CEGUI::System* guiSystem = m_driver->GetCEGui();
        if ( NULL != guiSystem && NULL != m_ceGuiContext ) 
        {       
            clock_t now = clock();
            float elapsedGuiTime = ( now - m_lastTimeInjection ) * 0.001f;        
            guiSystem->injectTimePulse( elapsedGuiTime );
            m_ceGuiContext->injectTimePulse( elapsedGuiTime );
            m_lastTimeInjection = now;
        
            CEGUI::Renderer* guiRenderer = guiSystem->getRenderer();
            guiRenderer->beginRendering();
        
            m_ceGuiContext->markAsDirty();
            m_ceGuiContext->draw();

            guiRenderer->endRendering();
        }
    }
    else
    if ( eventID == GUI::CWindowContext::WindowContextSizeEvent )
    {        
        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "GUIContext: Resizing CEGUI GUI context to " + CORE::UInt32ToString( m_windowContext->GetWidth() ) + "x" +
                                                                                                CORE::UInt32ToString( m_windowContext->GetHeight() ) );

		CEGUI::System::getSingleton().notifyDisplaySizeChanged( CEGUI::Sizef( (float) m_windowContext->GetWidth(), (float) m_windowContext->GetHeight() ) );
        //m_ceGuiContext->getRenderTarget().setArea( m_windowContext->GetWidth(), m_windowContext->GetHeight() );

        //CEGUI::Renderer* guiRenderer = m_driver->GetCEGui()->getRenderer();
        //guiRenderer->beginRendering();

        //m_ceGuiContext->markAsDirty();
        //m_ceGuiContext->draw();

        //guiRenderer->endRendering();
    }
}
Esempio n. 9
0
bool
CGUIManager::LoadConfig( const GUCEF::CORE::CDataNode& rootNode )       
{GUCE_TRACE;             

    GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_BELOW_NORMAL, "GUCE::GUI::CGUCEApplication: Loading config" );
    
    const GUCEF::CORE::CDataNode* m = NULL;
    
    if ( &m_guiConfig != &rootNode )
    {
        m = rootNode.Search( "GUCE%GUI" ,
                             '%'        ,
                             false      );

        if ( m != NULL )
        {
            m_guiConfig.ClearAttributes();
            m_guiConfig.DelSubTree();
            m_guiConfig.Copy( *m );
        }
        else
        {
            return false;
        }
    }
    else
    {
        m = &m_guiConfig;
    }
    
    if ( !m_initialized )
    {       
        m = m_guiConfig.Find( "CGUIManager" );
        if ( 0 != m )
        {
            m_selectedDriverName = m->GetAttributeValue( "Driver" );
        }
    }
    
    return true;
}
bool
CProductManager::LoadConfig( const GUCEF::CORE::CDataNode& node )
{GUCEF_TRACE;

    GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CProductManager: Loading the configuration" );

    GUCEF::CORE::CDataNode* n = node.Search( "GUCEF%PRODMAN%CProductManager", '%', false );
    if ( NULL != n )
    {
        GUCEF::CORE::CDataNode::TKeyValuePair* att = NULL;
        att = n->GetAttribute( "ProductListPath" );
        if ( NULL != att )
        {
            m_productListPath = att->second;
        }
        att = n->GetAttribute( "ProductListCodec" );
        if ( NULL != att )
        {
            m_productListCodec = att->second;
        }

        att = n->GetAttribute( "CommonProductRoot" );
        if ( NULL != att )
        {
            m_productRoot = att->second;
        }

        //GUCEF::CORE::CDataNode productList;
        //if ( GUCE::CORE::VFSLoadDataTree( m_productListPath  ,
        //                                  m_productListCodec ,
        //                                  &productList       ) )
        //{
        //    m_productList.LoadConfig( productList );
        //}

        m_downloadsManager.LoadConfig( node );
        return true;
    }
    return false;
}
bool
CWin32WindowContext::Initialize( const GUI::CString& title                ,
                                     const GUI::CVideoSettings& videoSettings )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    if ( !CORE::CMsWin32Window::RegisterWindowClass( GetClassTypeName() ) )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Win32WindowContext: Could not register window class" );
        return false;
    }

    // First create a regular Win32 window
    if ( m_window.WindowCreate( GetClassTypeName()                          ,
                                title                                       ,
                                0                                           ,
                                0                                           ,
                                videoSettings.GetResolutionWidthInPixels()  ,
                                videoSettings.GetResolutionHeightInPixels() ) )
    {
        // Display the new window
        m_window.Show();
        m_window.SendToForegound();
        m_window.GrabFocus();

        // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
        CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator(); 
        pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
        SubscribeTo( &pulseGenerator );

        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "Win32WindowContext: Succesfully created Win32 window" );
        return true;
    }
    return false;
}
Esempio n. 12
0
bool
CDStoreCodecPlugin::Link( void* modulePtr                   ,
                         TPluginMetaDataPtr pluginMetaData )
{GUCEF_TRACE;

    if ( IsLoaded() ) return false;
    
    _sohandle = modulePtr;
    if ( NULL != _sohandle )
    {
        GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "DStoreCodecPlugin: Linking API using module pointer: " + PointerToString( modulePtr ) );

        _fptable[ DSTOREPLUG_INIT ] = GetFunctionAddress( _sohandle         ,
                                                          "DSTOREPLUG_Init" ,
                                                          1*sizeof(void*)   ).funcPtr;
        _fptable[ DSTOREPLUG_SHUTDOWN ] = GetFunctionAddress( _sohandle             ,
                                                              "DSTOREPLUG_Shutdown" ,
                                                              1*sizeof(void*)       ).funcPtr;
        _fptable[ DSTOREPLUG_NAME ] = GetFunctionAddress( _sohandle         ,
                                                          "DSTOREPLUG_Name" ,
                                                          1*sizeof(void*)   ).funcPtr;
        _fptable[ DSTOREPLUG_COPYRIGHT ] = GetFunctionAddress( _sohandle              ,
                                                               "DSTOREPLUG_Copyright" ,
                                                               1*sizeof(void*)        ).funcPtr;
        _fptable[ DSTOREPLUG_VERSION ] = GetFunctionAddress( _sohandle            ,
                                                             "DSTOREPLUG_Version" ,
                                                             1*sizeof(void*)      ).funcPtr;
        _fptable[ DSTOREPLUG_TYPE ] = GetFunctionAddress( _sohandle         ,
                                                          "DSTOREPLUG_Type" ,
                                                          1*sizeof(void*)   ).funcPtr;
        _fptable[ DSTOREPLUG_DEST_FILE_OPEN ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_Dest_File_Open" ,
                                                                    3*sizeof(void*)             ).funcPtr;
        _fptable[ DSTOREPLUG_DEST_FILE_CLOSE ] = GetFunctionAddress( _sohandle                    ,
                                                                     "DSTOREPLUG_Dest_File_Close" ,
                                                                     2*sizeof(void*)              ).funcPtr;
        _fptable[ DSTOREPLUG_BEGIN_NODE_STORE ] = GetFunctionAddress( _sohandle                    ,
                                                                     "DSTOREPLUG_Begin_Node_Store" ,
                                                                     3*sizeof(void*)+8             ).funcPtr;
        _fptable[ DSTOREPLUG_END_NODE_STORE ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_End_Node_Store" ,
                                                                    3*sizeof(void*)+8           ).funcPtr;
        _fptable[ DSTOREPLUG_STORE_NODE_ATT ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_Store_Node_Att" ,
                                                                    5*sizeof(void*)+12          ).funcPtr;
        _fptable[ DSTOREPLUG_BEGIN_NODE_CHILDREN ] = GetFunctionAddress( _sohandle                        ,
                                                                         "DSTOREPLUG_Begin_Node_Children" ,
                                                                         3*sizeof(void*)                  ).funcPtr;
        _fptable[ DSTOREPLUG_END_NODE_CHILDREN ] = GetFunctionAddress( _sohandle                      ,
                                                                       "DSTOREPLUG_End_Node_Children" ,
                                                                       3*sizeof(void*)                ).funcPtr;
        _fptable[ DSTOREPLUG_SRC_FILE_OPEN ] = GetFunctionAddress( _sohandle                  ,
                                                                   "DSTOREPLUG_Src_File_Open" ,
                                                                   2*sizeof(void*)            ).funcPtr;
        _fptable[ DSTOREPLUG_SRC_FILE_CLOSE ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_Src_File_Close" ,
                                                                    2*sizeof(void*)             ).funcPtr;
        _fptable[ DSTOREPLUG_SET_READ_HANDLERS ] = GetFunctionAddress( _sohandle                      ,
                                                                       "DSTOREPLUG_Set_Read_Handlers" ,
                                                                       4*sizeof(void*)                ).funcPtr;
        _fptable[ DSTOREPLUG_START_READING ] = GetFunctionAddress( _sohandle                  ,
                                                                   "DSTOREPLUG_Start_Reading" ,
                                                                   2*sizeof(void*)            ).funcPtr;


        if ( ( _fptable[ DSTOREPLUG_INIT ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SHUTDOWN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_NAME ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_COPYRIGHT ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_VERSION ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_TYPE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_DEST_FILE_OPEN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_DEST_FILE_CLOSE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_BEGIN_NODE_STORE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_END_NODE_STORE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_STORE_NODE_ATT ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_BEGIN_NODE_CHILDREN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_END_NODE_CHILDREN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SRC_FILE_OPEN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SRC_FILE_CLOSE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SET_READ_HANDLERS ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_START_READING ] == NULL ) )
        {
                memset( _fptable, NULL, sizeof(anyPointer) * DSTOREPLUG_LASTFPTR );
                _sohandle = NULL;

                GUCEF_ERROR_LOG( LOGLEVEL_NORMAL, "Invalid codec module: One or more functions could not be located in the module " + PointerToString( modulePtr ) );
                return false;
        }

        /*
         *      Intialize the plugin module
         */
        UInt32 statusCode = ( (TDSTOREPLUGFPTR_Init) _fptable[ DSTOREPLUG_INIT ] )( &_plugdata );
        if ( statusCode > 0 )
        {
            // We have loaded & linked our plugin module
            GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "DStoreCodecPlugin: Successfully loaded module and invoked Init() which returned status " + 
                    Int32ToString( statusCode  ) + " using module: " + PointerToString( modulePtr ) );
            GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "  - Name: " + GetName() );
            GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "  - Copyright/EULA: " + GetCopyright() );

            // Copy the given metadata and update it with info from the actual module
            m_metaData = new CPluginMetaData( *pluginMetaData );                 
            m_metaData->SetDescription( GetDescription() );
            m_metaData->SetCopyright( GetCopyright() );
            m_metaData->SetVersion( GetVersion() );
            
            return true;
        }
        else
        {
            memset( _fptable, NULL, sizeof(anyPointer) * DSTOREPLUG_LASTFPTR );
            _sohandle = NULL;
            _plugdata = NULL;

            GUCEF_ERROR_LOG( LOGLEVEL_NORMAL, "Initialization routine reported an error for module " + PointerToString( modulePtr ) );
            return false;
        }        
    }

    return false;
}
CEvent
CNotificationIDRegistry::Register( const CString& keyvalue                       ,
                                   const bool okIfAlreadyRegisterd /* = false */ )
{GUCEF_TRACE;

    m_dataLock.Lock();

    if ( keyvalue.Length() > 0 )
    {
        TRegistryList::const_iterator i = m_list.find( keyvalue );
        if ( i == m_list.end() )
        {
            if ( GUCEFCORE_UINT32MAX > m_lastid )
            {
                m_list[ keyvalue ] = m_lastid;
                ++m_lastid;
                m_dataLock.Unlock();

                GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "Event registered with ID " + UInt32ToString( m_lastid-1 ) + " and name \"" + keyvalue + "\"" );

                return CEvent( m_lastid-1, keyvalue );
            }

            /*
             *  Because all event id's have been used at least once we
             *  now have to perform a linear search for available event id's
             *  In practice it is rather unlikely this code will ever be used due to the insane
             *  amount of event registration actions required.
             */
            for ( UInt32 n=0; n<ULONG_MAX; ++n )
            {
                bool found = false;
                i = m_list.begin();
                while ( i != m_list.end() )
                {
                    if ( (*i).second == n )
                    {
                        found = true;
                        break;
                    }
                    ++i;
                }
                if ( !found )
                {
                    m_list[ keyvalue ] = n;
                    m_dataLock.Unlock();
                    return CEvent( n, keyvalue );
                }
            }
        }

        if ( !okIfAlreadyRegisterd )
        {
            m_dataLock.Unlock();
            GUCEF_EMSGTHROW( EKeyAlreadyRegistered, "CNotificationIDRegistry: Key is already registerd" );
        }
        m_dataLock.Unlock();
        return CEvent( (*i).second, keyvalue );
    }
    else
    {
        m_dataLock.Unlock();
        GUCEF_EMSGTHROW( EEmptyKeyString, "CNotificationIDRegistry: Empty key string" );
    }

    m_dataLock.Unlock();
}
Esempio n. 14
0
bool
CGUIManager::Init( CORE::TWindowContextPtr& windowContext )
{GUCE_TRACE;

    if ( !m_initialized )
    {
        GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Initializing GUI system" );

        // Apply the loaded configuration (if any exists)
        if ( LoadConfig( m_guiConfig ) )
        {
            if ( m_drivers.size() == 0 )
            {
                GUCEF_ERROR_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Cannot initialize GUI system because no driver is available" ); 
                return false;
            }
            if ( m_selectedDriverName.Length() == 0 )
            {
                GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: No GUI driver specified in config: Using first available driver" ); 
                m_selectedDriverName = (*m_drivers.begin()).first;
            }
            
            TDriverMap::iterator i = m_drivers.find( m_selectedDriverName );
            if ( i != m_drivers.end() )
            {
                GUCEF_DEBUG_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Using driver with name " + m_selectedDriverName );
                
                CIGUIDriver* driver = (*i).second;
                if ( driver->LoadConfig( m_guiConfig ) )
                {
                    if ( driver->Initialize( windowContext ) )
                    {
                        m_initialized = true;
                        GUCEF_SYSTEM_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Successfully initialized the GUI system" );
                        
                        TGUIInitializedEventData eData( windowContext );
                        NotifyObservers( GUIInitializedEvent, &eData );
                        return true;
                    }
                    else
                    {
                        GUCEF_ERROR_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Failed to initialize the GUI system driver" );
                    }
                }
                else
                {
                    GUCEF_ERROR_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Failed to load the GUI system driver config" );
                }
            }
            else
            {
                GUCEF_ERROR_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Failed to locate the configured GUI system driver" );
            }            
        }
        else
        {
            GUCEF_ERROR_LOG( GUCEF::CORE::LOGLEVEL_NORMAL, "CGUIManager: Failed to load the GUI system config" );
            return false;
        }
    }
    
    return true;
}
bool
CXWinGLWindowContext::Initialize( const GUI::CString& title                ,
                                  const GUI::CVideoSettings& videoSettings )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    // First get access to the display
    ::Display* display = CORE::CX11EventDispatcher::Instance()->GetDisplay();
    if ( NULL == display )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Could not open display" );
        return false;
    }

    // Now proceed with setting up the OpenGL specifics
    int dummy = 0;
    if ( 0 == glXQueryExtension( display, &dummy, &dummy ) )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: X server has no OpenGL GLX extension" );
        Shutdown();
        return false;
    }

    // find an OpenGL-capable Color Index visual with depth buffer
    static int attributes[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
    //static int attributes[] = {GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
    XVisualInfo* vi = glXChooseVisual( display, DefaultScreen( display ), attributes );
    if ( NULL == vi )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Could not get visual info for display" );
        Shutdown();
        return false;
    }

    // create an OpenGL rendering context
    GLXContext cx = glXCreateContext( display, vi,  None, GL_TRUE );
    if ( NULL == cx )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Could not create rendering context" );
        XFree( vi );
        Shutdown();
        return false;
    }
    GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Created GL context using GLX" );

    // create an X colormap since probably not using default visual
    ::Colormap cmap = ::XCreateColormap( display, RootWindow( display, vi->screen),
                                vi->visual, AllocNone);

    ::XSetWindowAttributes swa;
    swa.colormap = cmap;
    swa.border_pixel = 0;
    swa.event_mask = ExposureMask | EnterWindowMask | StructureNotifyMask | SubstructureNotifyMask;

    ::Window glwin = ::XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, videoSettings.GetResolutionWidthInPixels(),
                        videoSettings.GetResolutionHeightInPixels(), 0, vi->depth, InputOutput, vi->visual,
                        CWBorderPixel | CWColormap | CWEventMask, &swa);
    if ( 0 == glwin )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Failed to create X11 window" );
        ::XFree( vi );
        Shutdown();
        return false;
    }
    GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Created X11 Window" );

//    ::XSetStandardProperties(display, glwin, "xogl", "xogl", None, 0,
//                                0, NULL);

    glXMakeCurrent( display, glwin, cx );

    // Set up the default GL state.
    glClearColor(0, 0, 0, 1);
    //glEnableClientState( GL_VERTEX_ARRAY );
    //glEnableClientState( GL_COLOR_ARRAY );

    //glEnable( GL_BLEND );
    //glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, GetWidth(), GetHeight(), 0, -1, 1 );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // Hook up our window object to re-use its eventing capabilities
    m_window.SetDisplay( display );
    m_window.SetScreen( vi->screen );
    m_window.SetWindow( glwin );
    m_window.SetText( title );

    // cleanup
    ::XFree( vi );

    // Display the new window
    m_window.Show();
    m_window.SendToForegound();
    //m_window.GrabFocus();

    // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
    CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator();
    pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
    SubscribeTo( &pulseGenerator, CORE::CPulseGenerator::PulseEvent );

    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Succesfully created OpenGL rendering context" );

    return true;
}
Esempio n. 16
0
bool
COgreWindowContext::Initialize( const GUI::CString& title                ,
                                const GUI::CVideoSettings& videoSettings ,
                                const GUI::CString& ogreRenderSystem     )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    // First create a regular O/S window
    if ( m_osWindow->WindowCreate( title                                       ,
                                   0                                           ,
                                   0                                           ,
                                   videoSettings.GetResolutionWidthInPixels()  ,
                                   videoSettings.GetResolutionHeightInPixels() ) )
    {
        // Display the new window
        m_osWindow->Show();
        m_osWindow->SendToForegound();
        m_osWindow->GrabFocus();

	    // Now proceed with setting up the Ogre specifics
        
        // We grab the O/S window identifier 'the handle' 
        // This is passed to Ogre to tie things together
        CORE::Int64 windowRef = 0; 
        CORE::CString windowIntStr = m_osWindow->GetProperty( "WINDOWINT" );
        if ( !windowIntStr.IsNULLOrEmpty() )
        {
            windowRef = CORE::StringToInt64( windowIntStr );
        }
        Ogre::NameValuePairList options;         
        options[ "externalWindowHandle" ] = Ogre::StringConverter::toString( (size_t) windowRef ); 

        Ogre::Root* ogreRoot = Ogre::Root::getSingletonPtr();
        if ( ogreRoot == nullptr )
        {            
            ogreRoot = OGRE_NEW Ogre::Root( "", "", "" ); 
        }

        if ( !ogreRoot->isInitialised() )
        {
            // Load any Ogre plugins not loaded yet from the bootstrap group
            CORE::CCoreGlobal::Instance()->GetPluginControl().LoadPluginGroup( "Ogre" );
            
            const Ogre::RenderSystemList& rsList = ogreRoot->getAvailableRenderers();
            if ( rsList.size() == 0 )
            {
                GUCEF_ERROR_LOG( CORE::LOGLEVEL_IMPORTANT, "OgreWindowContext: No Ogre render systems are available, cannot initialize" );
                return false;
            }

            Ogre::RenderSystem* renderSystem = nullptr;
            Ogre::RenderSystemList::const_iterator i = rsList.begin();
            while ( i != rsList.end() )
            {
                GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Available Ogre render system: " + (*i)->getFriendlyName() );
                if ( ogreRenderSystem == (*i)->getName() )
                {
                    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Found desired/preferred Ogre render system: " + (*i)->getFriendlyName() );
                    renderSystem = (*i); 
                }
                ++i;
            }
            if ( renderSystem == nullptr )
            {
                GUCEF_WARNING_LOG( CORE::LOGLEVEL_IMPORTANT, "OgreWindowContext: Preferred Ogre render systems not available, using first available alternative: " + (*rsList.begin())->getFriendlyName() );
                renderSystem = *rsList.begin();
            }

            ogreRoot->setRenderSystem( renderSystem );
            m_sceneManager = ogreRoot->createSceneManager( Ogre::ST_GENERIC );

            m_renderWindow = ogreRoot->initialise( false, title );
        }

        m_renderWindow = ogreRoot->createRenderWindow( title, 
                                                       videoSettings.GetResolutionWidthInPixels(), 
                                                       videoSettings.GetResolutionHeightInPixels(), 
                                                       videoSettings.GetFullscreenState(),
                                                       &options ); 

        // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
        CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator(); 
        pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
        SubscribeTo( &pulseGenerator );

        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Succesfully created Ogre rendering context" );
        m_initialized = true;
        return true;
    }
    return false;
}