Ejemplo n.º 1
0
        public void destroyRendererWindow(RendererWindow window)
        {
            OgreWindow ogreWindow = window as OgreWindow;

            if (ogreWindow != null)
            {
                Log.Default.sendMessage("Destroying RenderWindow {0}.", LogLevel.Info, "OgrePlugin", ogreWindow.OgreRenderTarget.getName());
                ogreWindow.Dispose();
                root.destroyRenderTarget(ogreWindow.OgreRenderTarget);
                if (ogreWindow == primaryWindow)
                {
                    primaryWindow = null;
                }
            }
            else
            {
                if (window == null)
                {
                    Log.Default.sendMessage("Error attempted to destroy a null RenderWindow. No changes have been made.", LogLevel.Warning, "OgrePlugin");
                }
                else
                {
                    Log.Default.sendMessage("Error destroying RendererWindow {0}. It is not a recognized OgreWindow. The window has not been destroyed.", LogLevel.Warning, "OgrePlugin", window.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        public RendererWindow recreatePrimaryWindow()
        {
            destroyRendererWindow(primaryWindow);

            WindowInfo defaultWindowInfo;

            PluginManager.Instance.reconfigureDefaultWindow(out defaultWindowInfo);

            //Create the default window.
            Dictionary <String, String> miscParams = new Dictionary <string, string>();
            String fsaa = OgreConfig.FSAA;

            if (fsaa.Contains("Quality"))
            {
                miscParams.Add("FSAAHint", "Quality");
            }
            int spaceIndex = fsaa.IndexOf(' ');

            if (spaceIndex != -1)
            {
                fsaa = fsaa.Substring(0, spaceIndex);
            }
            miscParams.Add("FSAA", fsaa);
            miscParams.Add("vsync", OgreConfig.VSync.ToString());
            miscParams.Add("monitorIndex", defaultWindowInfo.MonitorIndex.ToString());
            miscParams.Add("useNVPerfHUD", OgreConfig.UseNvPerfHUD.ToString());
            miscParams.Add("contentScalingFactor", defaultWindowInfo.ContentScalingFactor.ToString());
            if (defaultWindowInfo.AutoCreateWindow)
            {
                RenderWindow renderWindow = root.createRenderWindow(defaultWindowInfo.AutoWindowTitle, (uint)defaultWindowInfo.Width, (uint)defaultWindowInfo.Height, defaultWindowInfo.Fullscreen, miscParams);
                OgreOSWindow ogreWindow   = new OgreOSWindow(renderWindow);
                primaryWindow = new AutomaticWindow(ogreWindow);
            }
            else
            {
                miscParams.Add("externalWindowHandle", defaultWindowInfo.EmbedWindow.WindowHandle.ToString());
                RenderWindow renderWindow = root.createRenderWindow(defaultWindowInfo.AutoWindowTitle, (uint)defaultWindowInfo.Width, (uint)defaultWindowInfo.Height, defaultWindowInfo.Fullscreen, miscParams);
                primaryWindow = new EmbeddedWindow(defaultWindowInfo.EmbedWindow, renderWindow);
            }
            defaultWindowInfo._fireWindowCreated(new WindowInfoEventArgs(primaryWindow));

            return(primaryWindow);
        }
Ejemplo n.º 3
0
        public void initialize(PluginManager pluginManager, IServiceCollection serviceCollection)
        {
            //Load config
            new OgreConfig(pluginManager.ConfigFile);
            chosenRenderSystem = OgreConfig.RenderSystemType;

            //Setup ogre root
            root = new Root("", "", "");
            renderSystemPlugin = OgreInterface_LoadRenderSystem(ref chosenRenderSystem);
            ogreUpdate         = new OgreUpdate(root);
            instance           = this;

            WindowInfo defaultWindowInfo;

            pluginManager.setRendererPlugin(this, out defaultWindowInfo);

            try
            {
                //Initialize Ogre
                rs = root._getRenderSystemWrapper(OgreInterface_GetRenderSystem(ref chosenRenderSystem));
                root.setRenderSystem(rs);
                root.initialize(false);

                //Create the default window.
                Dictionary <String, String> miscParams = new Dictionary <string, string>();
                String fsaa = OgreConfig.FSAA;
                if (fsaa.Contains("Quality"))
                {
                    miscParams.Add("FSAAHint", "Quality");
                }
                int spaceIndex = fsaa.IndexOf(' ');
                if (spaceIndex != -1)
                {
                    fsaa = fsaa.Substring(0, spaceIndex);
                }
                miscParams.Add("FSAA", fsaa);
                miscParams.Add("vsync", OgreConfig.VSync.ToString());
                miscParams.Add("monitorIndex", defaultWindowInfo.MonitorIndex.ToString());
                miscParams.Add("useNVPerfHUD", OgreConfig.UseNvPerfHUD.ToString());
                miscParams.Add("contentScalingFactor", defaultWindowInfo.ContentScalingFactor.ToString());
                if (defaultWindowInfo.AutoCreateWindow)
                {
                    RenderWindow renderWindow = root.createRenderWindow(defaultWindowInfo.AutoWindowTitle, (uint)defaultWindowInfo.Width, (uint)defaultWindowInfo.Height, defaultWindowInfo.Fullscreen, miscParams);
                    OgreOSWindow ogreWindow   = new OgreOSWindow(renderWindow);
                    primaryWindow = new AutomaticWindow(ogreWindow);
                }
                else
                {
                    miscParams.Add("externalWindowHandle", defaultWindowInfo.EmbedWindow.WindowHandle.ToString());
                    RenderWindow renderWindow = root.createRenderWindow(defaultWindowInfo.AutoWindowTitle, (uint)defaultWindowInfo.Width, (uint)defaultWindowInfo.Height, defaultWindowInfo.Fullscreen, miscParams);
                    primaryWindow = new EmbeddedWindow(defaultWindowInfo.EmbedWindow, renderWindow);
                }

                if (InitialClearColor.HasValue)
                {
                    rs.clearFrameBuffer(FrameBufferType.FBT_COLOUR, InitialClearColor.Value);
                    primaryWindow.OgreRenderTarget.update(true);
                }

                defaultWindowInfo._fireWindowCreated(new WindowInfoEventArgs(primaryWindow));

                //Setup compressed textures
                SelectedTextureFormat = OgreInterface_SetupVaryingCompressedTextures(CompressedTextureSupport);

                //Setup commands
                pluginManager.addCreateSimElementManagerCommand(new AddSimElementManagerCommand("Create Ogre Scene Manager", OgreSceneManagerDefinition.Create));
                pluginManager.addCreateSimElementCommand(new AddSimElementCommand("Create Ogre Scene Node", SceneNodeDefinition.Create));

                //Setup shader cache
                if (MicrocodeCachePath != null)
                {
                    GpuProgramManager.Instance.SaveMicrocodesToCache = true;
                    if (File.Exists(MicrocodeCachePath))
                    {
                        if (AllowMicrocodeCacheLoad)
                        {
                            using (Stream stream = File.OpenRead(MicrocodeCachePath))
                            {
                                GpuProgramManager.Instance.loadMicrocodeCache(stream);
                                Log.Info("Using microcode cache {0}", MicrocodeCachePath);
                            }
                        }
                        else
                        {
                            deleteMicrocodeCache();
                        }
                    }
                }

                //Setup Resources
                pluginManager.addSubsystemResources("Ogre", OgreResourceManager.Instance);

                //Setup the device lost listener.
                deviceLostListener = new DeviceLostListener();
                rs.addListener(deviceLostListener);

                serviceCollection.TryAddSingleton <Root>(this.root);                                       //This is externally owned

                serviceCollection.TryAddSingleton <RendererWindow>(this.PrimaryWindow);                    //This is externally owned

                serviceCollection.TryAddSingleton <RenderTarget>(this.OgrePrimaryWindow.OgreRenderTarget); //This is externally owned

                serviceCollection.TryAddSingleton <SceneViewLightManager>(s => s.GetRequiredService <PluginManager>().RendererPlugin.createSceneViewLightManager());

                serviceCollection.TryAddSingleton <FrameClearManager>(s => new FrameClearManager(s.GetRequiredService <RenderTarget>(), Color.FromRGB(0x333333)));
            }
            catch (Exception e)
            {
                throw new InvalidPluginException(String.Format("Exception initializing renderer. Message: {0}", e.Message), e);
            }
        }