///////////////////////////////////////// /// <summary> /// Loads an image file. /// </summary> /// <param name="virtualFileName">The virtual file name.</param> /// <param name="data">The image data.</param> /// <param name="size">The image size.</param> /// <param name="depth">The image depth (in 3d images, numbers of layers, otherwhise 1).</param> /// <param name="format">Pixel format.</param> /// <param name="numFaces">The number of faces the image data has inside (6 for cubemaps, 1 otherwise).</param> /// <param name="numMipmaps">The number of mipmaps the image data has inside.</param> /// <param name="error">Output error string.</param> /// <returns><b>true</b> if image is loaded; otherwise, <b>false</b>.</returns> public static bool LoadFromVirtualFile(string virtualFileName, out byte[] data, out Vector2I size, out int depth, out PixelFormat format, out int numFaces, out int numMipmaps, out string error) { unsafe { IntPtr pData; int dataSize; int width; int height; IntPtr errPointer; bool result = OgreImageManager.loadFromFile(RenderingSystem.realRoot, virtualFileName, out pData, out dataSize, out width, out height, out depth, out format, out numFaces, out numMipmaps, out errPointer); string err = OgreNativeWrapper.GetOutString(errPointer); error = null; data = null; size = new Vector2I(width, height); if (err != null) { error = string.Format("Loading file failed \"{0}\" ({1}).", virtualFileName, err); } if (pData != IntPtr.Zero) { data = new byte[dataSize]; Marshal.Copy(pData, data, 0, data.Length); OgreImageManager.freeData(RenderingSystem.realRoot, pData); } return(result); } }
public static bool GetImageFlags(string realFileName, out ImageFlags flags, out string error) { error = null; unsafe { bool result = OgreImageManager.getImageFlags(RenderingSystem.realRoot, realFileName, out uint uflags, out IntPtr errPointer); string err = OgreNativeWrapper.GetOutString(errPointer); if (err != null) error = string.Format("Error in file \"{0}\" ({1}).", realFileName, err); } flags = (ImageFlags)uflags; return(result); }
/// <summary> /// Save the image as a file. /// </summary> /// <param name="realFileName">The real file name.</param> /// <param name="data">The image data.</param> /// <param name="size">The image size.</param> /// <param name="depth">The image depth (in 3d images, numbers of layers, otherwhise 1).</param> /// <param name="format">Pixel format.</param> /// <param name="numFaces">The number of faces the image data has inside (6 for cubemaps, 1 otherwise).</param> /// <param name="numMipmaps">The number of mipmaps the image data has inside.</param> /// <param name="error">Output error string.</param> /// <returns><b>true</b> if image is currently serialized; otherwise, <b>false</b>.</returns> public static bool Save(string realFileName, IntPtr data, Vector2I size, int depth, PixelFormat format, int numFaces, int numMipmaps, out string error) { error = null; unsafe { IntPtr errPointer; bool result = OgreImageManager.save(RenderingSystem.realRoot, realFileName, data, size.X, size.Y, depth, format, numFaces, numMipmaps, out errPointer); string err = OgreNativeWrapper.GetOutString(errPointer); if (err != null) { error = string.Format("Saving file failed \"{0}\" ({1}).", realFileName, err); } return(result); } }
/// <summary> /// Loads an image from buffer. /// </summary> /// <param name="sourceBuffer">The source buffer.</param> /// <param name="fileType">The file type (file extension).</param> /// <param name="data">The image data.</param> /// <param name="size">The image size.</param> /// <param name="depth">The image depth (in 3d images, numbers of layers, otherwhise 1).</param> /// <param name="format">Pixel format.</param> /// <param name="numFaces">The number of faces the image data has inside (6 for cubemaps, 1 otherwise).</param> /// <param name="numMipmaps">The number of mipmaps the image data has inside.</param> /// <param name="error">Output error string.</param> /// <returns><b>true</b> if image is loaded; otherwise, <b>false</b>.</returns> public static bool LoadFromBuffer(byte[] sourceBuffer, string fileType, out byte[] data, out Vector2I size, out int depth, out PixelFormat format, out int numFaces, out int numMipmaps, out string error) { unsafe { IntPtr pData; int dataSize; int width; int height; IntPtr errPointer; bool result; fixed(byte *pSourceBuffer = sourceBuffer) { result = OgreImageManager.loadFromBuffer(RenderingSystem.realRoot, (IntPtr)pSourceBuffer, sourceBuffer.Length, fileType, out pData, out dataSize, out width, out height, out depth, out format, out numFaces, out numMipmaps, out errPointer); } string err = OgreNativeWrapper.GetOutString(errPointer); error = null; data = null; size = new Vector2I(width, height); if (err != null) { error = string.Format("Loading file from buffer failed ({0}).", err); } if (pData != IntPtr.Zero) { data = new byte[dataSize]; Marshal.Copy(pData, data, 0, data.Length); OgreImageManager.freeData(RenderingSystem.realRoot, pData); } return(result); } }
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); }