Exemplo n.º 1
0
        internal static unsafe void Shutdown()
        {
            foreach (var target in renderTargets.ToArray())
            {
                target.DisposeInternal();
            }
            //while( renderTargets.Count != 0 )
            //{
            //	Dictionary<IntPtr, RenderTarget>.Enumerator enumerator = renderTargets.GetEnumerator();
            //	enumerator.MoveNext();
            //	enumerator.Current.Value.DisposeInternal();
            //}

            while (canvasRenderers.Count != 0)
            {
                foreach (var r in canvasRenderers)
                {
                    r.Dispose();
                }
            }

            //!!!!!
            //ResourceLoadingManagerInBackground.Shutdown();

            GpuProgramManager.Shutdown();

            EngineFontManager.Shutdown();

            //!!!!!temp. как делать?
            //!!!!!какие еще ресурсы так удалять? и где?
            //delete resources of renderer
            //{
            //	List<Resource> toDelete = new List<Resource>();
            //	foreach( var v in ResourceManager.Instances )
            //	{
            //		var obj = v.ResultObject as Resource;

            //		if( obj is GpuTexture || obj is Material || obj is Mesh )
            //			toDelete.Add( obj );
            //	}
            //	foreach( var v in toDelete )
            //		v.Dispose();
            //}

            //LowLevelMaterialManager.Shutdown();
            GpuBufferManager.Shutdown();

            if (applicationRenderWindow != null)
            {
                applicationRenderWindow.Dispose();
                applicationRenderWindow = null;
            }

            if (sceneManager != null)
            {
                sceneManager.Dispose();
                sceneManager = null;
            }

            if (logListener != null)
            {
                OgreLogManager.getDefaultLog_removeListener(realRoot, logListener);
                MyOgreLogListener.Delete(logListener);
                logListener = null;
            }

            MyOgreVirtualFileSystem.Shutdown();

            Bgfx.Shutdown();

            disposed = true;
        }
Exemplo n.º 2
0
        unsafe static bool InitInternal(bool startedAtFullScreen, bool multiMonitorMode, string fontManagerDefaultLanguage) //, bool isEditor )//, Vec2I mainRenderTargetSize )
        {
            OgreNativeWrapper.CheckNativeBridge((int)ParameterType.TextureCube);                                            // GpuProgramParameters.GetAutoConstantTypeCount() );

            //!!!!new UWP
            var path = VirtualFileSystem.Directories.PlatformSpecific;

            if (SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP)
            {
                path = VirtualFileSystem.MakePathRelative(path);
            }

            Vector2I initialWindowSize = new Vector2I(10, 10);

            if (SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP)
            {
                initialWindowSize = EngineApp.platform.CreatedWindow_GetClientRectangle().Size;
            }

            //set backend for Android
            if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Android)
            {
                EngineSettings.Init.RendererBackend = RendererBackend.OpenGLES;
                //EngineSettings.Init.RendererBackend = RendererBackend.Vulkan;
                //EngineSettings.Init.RendererBackend = RendererBackend.Noop;
            }

            //set platform data
            if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Android && EngineSettings.Init.RendererBackend == RendererBackend.OpenGLES)
            {
                //Android, OpenGLES
                Bgfx.SetPlatformData(new PlatformData {
                    Context = (IntPtr)1
                });
            }
            else
            {
                Bgfx.SetPlatformData(new PlatformData {
                    WindowHandle = EngineApp.ApplicationWindowHandle
                });
            }

            if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Simulation && EngineSettings.Init.SimulationTripleBuffering)
            {
                Bgfx.SetTripleBuffering();
            }

            //Log.InvisibleInfo( "Renderer backend: " + EngineSettings.Init.RendererBackend.ToString() );

            var initSettings = new InitSettings
            {
                Backend         = EngineSettings.Init.RendererBackend,
                CallbackHandler = new CallbackHandler(),

                ////!!!!в релизе можно включить. в NeoAxis.DefaultSettings.config
                //Debug = true
                //!!!!
                //ResetFlags = ResetFlags.MSAA8x,
            };

            Bgfx.Init(initSettings);

            Bgfx.Reset(initialWindowSize.X, initialWindowSize.Y, GetApplicationWindowResetFlags());

            realRoot = (OgreRoot *)OgreRoot.New(path);

            //profilingToolBeginOperationDelegate = profilingToolBeginOperation;
            //profilingToolEndOperationDelegate = profilingToolEndOperation;
            //OgreRoot.setCallbackDelegates( realRoot,
            //   profilingToolBeginOperationDelegate,
            //   profilingToolEndOperationDelegate );

            logListener_messageLoggedDelegate = logListener_messageLogged;
            logListener = (MyOgreLogListener *)MyOgreLogListener.New(
                logListener_messageLoggedDelegate);
            OgreLogManager.getDefaultLog_addListener(realRoot, logListener);

            MyOgreVirtualFileSystem.Init();

            //TextBlock configBlock = null;
            //if( VirtualFile.Exists( "Base/Constants/RenderingSystem.config" ) )
            //	configBlock = TextBlockUtility.LoadFromVirtualFile( "Base/Constants/RenderingSystem.config" );

            ////irradianceVolumeLightPowerSpeed
            //{
            //   irradianceVolumeLightPowerSpeed = 1;

            //   if( configBlock != null )
            //   {
            //      TextBlock staticLightingBlock = configBlock.FindChild( "staticLighting" );
            //      if( staticLightingBlock != null )
            //      {
            //         if( staticLightingBlock.IsAttributeExist( "irradianceVolumeLightPowerSpeed" ) )
            //         {
            //            irradianceVolumeLightPowerSpeed = float.Parse(
            //               staticLightingBlock.GetAttribute( "irradianceVolumeLightPowerSpeed" ) );
            //         }
            //      }
            //   }
            //}

            //if( !string.IsNullOrEmpty( EngineApp.InitSettings.RenderingDeviceName ) )
            //{
            //	OgreRoot.setRenderingDevice( realRoot, EngineApp.InitSettings.RenderingDeviceName,
            //		EngineApp.InitSettings.RenderingDeviceIndex );
            //}

            ////!!!!!!всё таки выключать можно для NULL рендеринга?
            ////renderSystem.MaxPixelShadersVersion = MaxPixelShadersVersions.PS30;
            ////renderSystem.MaxVertexShadersVersion = MaxVertexShadersVersions.VS30;
            //RenderingSystem.Direct3DFPUPreserve = EngineApp.InitSettings.RenderingDirect3DFPUPreserve;

            unsafe
            {
                OgreRoot.initialise(realRoot);
            }

            GpuProgramManager.Init();

            InitGPUSettingsAndCapabilities();

            applicationRenderWindow = new RenderWindow(FrameBuffer.Invalid, initialWindowSize, EngineApp.ApplicationWindowHandle, true);
            //applicationRenderWindow.WindowMovedOrResized( xxx );
            //!!!!!?, mainRenderTargetSize );

            //Scene manager
            MyOgreSceneManager *realSceneManager = (MyOgreSceneManager *)OgreRoot.createSceneManager(realRoot, "NeoAxisSceneManager");

            sceneManager = new OgreSceneManager(realSceneManager);

            EngineFontManager.Init(fontManagerDefaultLanguage);

            //Create viewport
            Viewport viewport = applicationRenderWindow.AddViewport(true, true);

            // RenderCamera.Purposes.UsualScene );// mainRenderTargetCamera );
            //viewport.Camera.AllowFrustumCullingTestMode = true;
            //mainRenderTargetViewport = mainRenderTarget.AddViewport( RenderCamera.Purposes.UsualScene );// mainRenderTargetCamera );
            //mainRenderTargetCamera = mainRenderTargetViewport.ViewportCamera;
            //mainRenderTargetCamera.AllowFrustumCullingTestMode = true;

            {
                IntPtr errorPointer;
                OgreResourceGroupManager.initialiseAllResourceGroups(realRoot, out errorPointer);
                string error = OgreNativeWrapper.GetOutString(errorPointer);
                if (error != null)
                {
                    Log.Error(string.Format("Renderer: {0}", error));
                    return(false);
                }
            }

            //Ogre initialization errors
            if (resourceInitializationErrors.Count != 0)
            {
                string text = "Renderer initialization errors:\n\n";
                foreach (string message in resourceInitializationErrors)
                {
                    text += message + "\n";
                }
                resourceInitializationErrors.Clear();
                Log.Error(text);
                return(false);
            }
            resourcesInitialized = true;

            GpuBufferManager.Init();

            //!!!!!
            //ResourceLoadingManagerInBackground.Init();

            return(true);
        }