internal void CompileDataOfThisObject(Component_Mesh.CompiledData compiledData)          // Component_Mesh mesh, Component_Mesh.CompiledData result )
        {
            VertexElement[] vertexStructureV = VertexStructure;
            UnwrappedUVEnum unwrappedUVV     = UnwrappedUV;

            byte[]             verticesV = Vertices;
            int[]              indicesV  = Indices;
            Component_Material materialV = Material;

            Component_Mesh.StructureClass structure = null;

            OnGetDataOfThisObject(ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);
            GetDataOfThisObjectEvent?.Invoke(this, ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);

            //add to result
            if (vertexStructureV != null && vertexStructureV.Length != 0 && verticesV != null && verticesV.Length != 0 && (indicesV == null || indicesV.Length != 0))
            {
                vertexStructureV.GetInfo(out var vertexSize, out var holes);
                //if( !holes )
                {
                    int vertexCount = verticesV.Length / vertexSize;

                    var op = new Component_RenderingPipeline.RenderSceneData.MeshDataRenderOperation(this);

                    op.VertexStructure = vertexStructureV;
                    op.VertexStructureContainsColor = op.VertexStructure.Any(e => e.Semantic == VertexElementSemantic.Color0);
                    op.UnwrappedUV = unwrappedUVV;

                    var vertexDeclaration = op.VertexStructure.CreateVertexDeclaration(0);
                    op.VertexBuffers     = new GpuVertexBuffer[] { GpuBufferManager.CreateVertexBuffer(verticesV, vertexDeclaration) };
                    op.VertexStartOffset = 0;
                    op.VertexCount       = vertexCount;

                    if (indicesV != null)
                    {
                        op.IndexBuffer      = GpuBufferManager.CreateIndexBuffer(indicesV);
                        op.IndexStartOffset = 0;
                        op.IndexCount       = indicesV.Length;
                    }

                    //!!!!так?
                    op.Material = materialV;

                    compiledData.MeshData.RenderOperations.Add(op);

                    //!!!!может мержить когда несколько. индексы MeshGeometry в RawVertices
                    if (compiledData.MeshData.Structure == null)
                    {
                        compiledData.MeshData.Structure = structure;
                    }
                }
                //else
                //{
                //	//!!!!!error
                //}
            }
        }
Пример #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);
        }
Пример #3
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;
        }
Пример #4
0
        internal void CompileDataOfThisObject(Component_Mesh.CompiledData compiledData)          // Component_Mesh mesh, Component_Mesh.CompiledData result )
        {
            VertexElement[] vertexStructureV = VertexStructure;
            UnwrappedUVEnum unwrappedUVV     = UnwrappedUV;

            byte[]             verticesV = Vertices;
            int[]              indicesV  = Indices;
            Component_Material materialV = Material;

            Component_Mesh.StructureClass structure = null;

            OnGetDataOfThisObject(ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);
            GetDataOfThisObjectEvent?.Invoke(this, ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);

            //add to result
            if (vertexStructureV != null && vertexStructureV.Length != 0 && verticesV != null && verticesV.Length != 0 && (indicesV == null || indicesV.Length != 0))
            {
                //!!!!еще чтобы был с позициями?

                vertexStructureV.GetInfo(out var vertexSize, out var holes);
                //if( !holes )
                {
                    int vertexCount = verticesV.Length / vertexSize;

                    var op = new Component_RenderingPipeline.RenderSceneData.MeshDataRenderOperation(this);

                    op.VertexStructure = vertexStructureV;

                    op.VertexStructureContainsColor = op.VertexStructure.Any(e => e.Semantic == VertexElementSemantic.Color0);
                    ////disable if all data equal zero. it is means no data.
                    //if( op.VertexStructureContainsColor )
                    //{
                    //	if( vertexStructureV.GetElementBySemantic( VertexElementSemantic.Color0, out var element ) )
                    //	{
                    //		var size = element.GetSizeInBytes();
                    //		int vertexOffset = element.Offset;
                    //		for( int nVertex = 0; nVertex < vertexCount; nVertex++ )
                    //		{
                    //			for( int n = 0; n < size; n++ )
                    //			{
                    //				if( verticesV[ vertexOffset + n ] != 0 )
                    //				{
                    //					//found non zero
                    //					goto exit;
                    //				}
                    //			}
                    //			vertexOffset += vertexSize;
                    //		}
                    //		op.VertexStructureContainsColor = false;
                    //		exit:;
                    //	}
                    //}

                    op.UnwrappedUV = unwrappedUVV;

                    var vertexDeclaration = op.VertexStructure.CreateVertexDeclaration(0);
                    op.VertexBuffers     = new GpuVertexBuffer[] { GpuBufferManager.CreateVertexBuffer(verticesV, vertexDeclaration) };
                    op.VertexStartOffset = 0;
                    op.VertexCount       = vertexCount;

                    if (indicesV != null)
                    {
                        op.IndexBuffer      = GpuBufferManager.CreateIndexBuffer(indicesV);
                        op.IndexStartOffset = 0;
                        op.IndexCount       = indicesV.Length;
                    }

                    //!!!!так?
                    op.Material = materialV;

                    compiledData.MeshData.RenderOperations.Add(op);

                    //!!!!может мержить когда несколько. индексы MeshGeometry в RawVertices
                    if (compiledData.MeshData.Structure == null)
                    {
                        compiledData.MeshData.Structure = structure;
                    }

                    //var op = new Component_Mesh.CompiledData.RenderOperation();
                    //op.creator = this;

                    //op.vertexStructure = vertexStructureV;
                    //List<GpuVertexBuffer> l = new List<GpuVertexBuffer>();

                    ////!!!!make copy of arrays?

                    //var vertexDeclaration = op.vertexStructure.CreateVertexDeclaration( 0 );

                    //l.Add( GpuBufferManager.CreateVertexBuffer( verticesV, vertexDeclaration, false ) );
                    //op.vertexBuffers = l;
                    //op.vertexStartOffset = 0;
                    //op.vertexCount = vertexCount;

                    //if( indicesV != null )
                    //{
                    //	op.indexBuffer = GpuBufferManager.CreateIndexBuffer( indicesV, false );
                    //	op.indexStartOffset = 0;
                    //	op.indexCount = indicesV.Length;
                    //}

                    ////!!!!так?
                    //op.material = materialV;

                    //var item = new Component_Mesh.CompiledData.RenderOperationItem();
                    //item.operation = op;
                    ////!!!!
                    ////item.transform = TransformOfData;//TransformRelativeToParent;
                    //compiledData.RenderOperations.Add( item );

                    ////op.transform = Transform;
                    ////compiledData.RenderOperations.Add( op );
                }
                //else
                //{
                //	//!!!!!error
                //}
            }
        }