Exemple #1
0
        /// <summary>
        /// Actually create this GraphicsWindow resources in Unix platform.
        /// </summary>
        /// <param name="surfaceFormat">
        /// A <see cref="GraphicsBuffersFormat"/> used for selecting the most appropriate visual.
        /// </param>
        internal void PreCreateObjectX11(GraphicsBuffersFormat surfaceFormat)
        {
            if (surfaceFormat == null)
            {
                throw new ArgumentNullException("surfaceFormat");
            }

            // Choose "best" pixel format matching with surface configuration
            _DeviceFormat = surfaceFormat.ChoosePixelFormat(_DeviceContext, ValidPixelFormat);

            sLog.Debug("Choosen frame buffer configuration: 0x{0} (visual 0x{1}).", _DeviceFormat.XFbConfig.ToString("X3"), _DeviceFormat.XVisualInfo.visualid.ToString("X3"));

            Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");

            if (xplatui == null)
            {
                throw new PlatformNotSupportedException("mono runtime version no supported");
            }

            IntPtr display    = (IntPtr)xplatui.GetField("DisplayHandle", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
            IntPtr rootWindow = (IntPtr)xplatui.GetField("RootWindow", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
            IntPtr colorMap   = Glx.UnsafeNativeMethods.XCreateColormap(display, rootWindow, _DeviceFormat.XVisualInfo.visual, 0);
            // KhronosApi.LogFunction("XCreateColormap(0x{0}, {1}, {2}. 0) = {0}", display.ToString("X"), rootWindow.ToString("X"), _DeviceFormat.XVisualInfo.visual.ToString());

            IntPtr customVisual     = _DeviceFormat.XVisualInfo.visual;
            IntPtr origCustomVisual = (IntPtr)xplatui.GetField("CustomVisual", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            KhronosApi.LogComment("Set System.Windows.Forms.XplatUIX11.CustomVisual change from {0} to {1}", origCustomVisual.ToString("X"), customVisual.ToString("X"));
            xplatui.GetField("CustomVisual", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, customVisual);

            KhronosApi.LogComment("Create System.Windows.Forms.XplatUIX11.CustomColormap ({0})", colorMap.ToString("X"));
            xplatui.GetField("CustomColormap", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, colorMap);
        }
Exemple #2
0
        /// <summary>
        /// Check whether sRGB color correction on this GraphicsSurface is enabled.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/>.
        /// </param>
        /// <param name="surfaceFormat">
        ///
        /// </param>
        /// <returns>
        /// Is returns a boolean value indicating whether sRGB color correction on this GraphicsSurface is enabled.
        /// </returns>
        protected bool IsEnabledSRGB(GraphicsContext ctx, GraphicsBuffersFormat surfaceFormat)
        {
            if (surfaceFormat.HasBuffer(GraphicsBuffersFormat.BufferType.ColorSRGB) == false)
            {
                throw new InvalidOperationException("surface has no sRGB buffer");
            }
            if ((ctx.Caps.GlExtensions.FramebufferSRGB_ARB == false) && (ctx.Caps.GlExtensions.FramebufferSRGB_EXT == false))
            {
                throw new InvalidOperationException("no framebuffer sRGB extension supported");
            }

            return(Gl.IsEnabled(EnableCap.FramebufferSrgb));
        }
Exemple #3
0
        /// <summary>
        /// Disable sRGB color correction on this GraphicsSurface.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/>.
        /// </param>
        /// <param name="surfaceFormat">
        /// A <see cref="GraphicsBuffersFormat"/> that specify this GraphicsSurface format.
        /// </param>
        protected void DisableSRGB(GraphicsContext ctx, GraphicsBuffersFormat surfaceFormat)
        {
            if ((surfaceFormat.BuffersMask & GraphicsBufferType.ColorSRGB) == 0)
            {
                throw new InvalidOperationException("surface has no sRGB buffer");
            }
            if ((ctx.Caps.GlExtensions.FramebufferSRGB_ARB == false) && (ctx.Caps.GlExtensions.FramebufferSRGB_EXT == false))
            {
                throw new InvalidOperationException("no framebuffer sRGB extension supported");
            }

            Gl.Disable(EnableCap.FramebufferSrgb);
        }
Exemple #4
0
        /// <summary>
        /// Create this GraphicsWindow.
        /// </summary>
        /// <param name="surfaceFormat">
        /// A <see cref="GraphicsBuffersFormat"/> that specify the pixel format of the device context created
        /// along with this GraphicsWindow.
        /// </param>
        public void Create(GraphicsBuffersFormat surfaceFormat)
        {
            if ((surfaceFormat == null) && (_SurfaceFormat == null))
            {
                throw new ArgumentNullException("surfaceFormat");
            }

            // Store surface format
            if (surfaceFormat != null)
            {
                _SurfaceFormat = surfaceFormat;
            }
            // Actually create this GraphicsWindow
            Create((GraphicsContext)null);
        }
		/// <summary>
		/// Check whether sRGB color correction on this GraphicsSurface is enabled.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/>.
		/// </param>
		/// <param name="surfaceFormat">
		/// 
		/// </param>
		/// <returns>
		/// Is returns a boolean value indicating whether sRGB color correction on this GraphicsSurface is enabled.
		/// </returns>
		protected bool IsEnabledSRGB(GraphicsContext ctx, GraphicsBuffersFormat surfaceFormat)
		{
			if (surfaceFormat.HasBuffer(GraphicsBuffersFormat.BufferType.ColorSRGB) == false)
				throw new InvalidOperationException("surface has no sRGB buffer");
			if ((ctx.Caps.GlExtensions.FramebufferSRGB_ARB == false) && (ctx.Caps.GlExtensions.FramebufferSRGB_EXT == false))
				throw new InvalidOperationException("no framebuffer sRGB extension supported");

			return (Gl.IsEnabled(EnableCap.FramebufferSrgb));
		}
		private static ClearBufferMask GetClearFlags(GraphicsBuffersFormat.BufferType bufferMask)
		{
			ClearBufferMask clearFlags = 0;

			if ((bufferMask & GraphicsBuffersFormat.BufferType.Color) != 0)
				clearFlags |= ClearBufferMask.ColorBufferBit;
			if ((bufferMask & GraphicsBuffersFormat.BufferType.Depth) != 0)
				clearFlags |= ClearBufferMask.DepthBufferBit;
			if ((bufferMask & GraphicsBuffersFormat.BufferType.Stencil) != 0)
				clearFlags |= ClearBufferMask.StencilBufferBit;

			return (clearFlags);
		}
		/// <summary>
		/// Clear surface buffers.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used for clearing buffers.
		/// </param>
		/// <param name="bufferMask">
		/// A <see cref="GraphicsBuffersFormat.BufferType"/> indicating which buffers to clear.
		/// </param>
		public void Clear(GraphicsContext ctx, GraphicsBuffersFormat.BufferType bufferMask)
		{
			// Update clear values (only what is necessary)
			if ((bufferMask & GraphicsBuffersFormat.BufferType.Color) != 0)
				Gl.ClearColor(mClearColor.Red, mClearColor.Green, mClearColor.Blue, mClearColor.Alpha);
			if ((bufferMask & GraphicsBuffersFormat.BufferType.Depth) != 0)
				Gl.ClearDepth(mClearDepth);
			if ((bufferMask & GraphicsBuffersFormat.BufferType.Stencil) != 0)
				Gl.ClearStencil(mClearStencil);
			
			// Clear
			Gl.Clear(GetClearFlags(bufferMask));
		}
		/// <summary>
		/// Actually create this GraphicsWindow resources in Unix platform.
		/// </summary>
		/// <param name="surfaceFormat">
		/// A <see cref="GraphicsBuffersFormat"/> used for selecting the most appropriate visual.
		/// </param>
		internal void PreCreateObjectX11(GraphicsBuffersFormat surfaceFormat)
		{
			if (surfaceFormat == null)
				throw new ArgumentNullException("surfaceFormat");
			
			// Choose "best" pixel format matching with surface configuration
			_DeviceFormat = surfaceFormat.ChoosePixelFormat(_DeviceContext, ValidPixelFormat);
			
			sLog.Debug("Choosen frame buffer configuration: 0x{0} (visual 0x{1}).", _DeviceFormat.XFbConfig.ToString("X3"), _DeviceFormat.XVisualInfo.visualid.ToString("X3"));

			Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");

			if (xplatui == null)
				throw new PlatformNotSupportedException("mono runtime version no supported");
			
			IntPtr display = (IntPtr)xplatui.GetField("DisplayHandle", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			IntPtr rootWindow = (IntPtr)xplatui.GetField("RootWindow", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			IntPtr colorMap = Glx.UnsafeNativeMethods.XCreateColormap(display, rootWindow, _DeviceFormat.XVisualInfo.visual, 0);
			// KhronosApi.LogFunction("XCreateColormap(0x{0}, {1}, {2}. 0) = {0}", display.ToString("X"), rootWindow.ToString("X"), _DeviceFormat.XVisualInfo.visual.ToString());

			IntPtr customVisual = _DeviceFormat.XVisualInfo.visual;
			IntPtr origCustomVisual = (IntPtr)xplatui.GetField("CustomVisual", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

			KhronosApi.LogComment("Set System.Windows.Forms.XplatUIX11.CustomVisual change from {0} to {1}", origCustomVisual.ToString("X"), customVisual.ToString("X"));
			xplatui.GetField("CustomVisual", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, customVisual);
			
			KhronosApi.LogComment("Create System.Windows.Forms.XplatUIX11.CustomColormap ({0})", colorMap.ToString("X"));
			xplatui.GetField("CustomColormap", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, colorMap);
		}
		/// <summary>
		/// Create this GraphicsWindow.
		/// </summary>
		/// <param name="surfaceFormat">
		/// A <see cref="GraphicsBuffersFormat"/> that specify the pixel format of the device context created
		/// along with this GraphicsWindow.
		/// </param>
		public void Create(GraphicsBuffersFormat surfaceFormat)
		{
			if ((surfaceFormat == null) && (_SurfaceFormat == null))
				throw new ArgumentNullException("surfaceFormat");

			// Store surface format
			if (surfaceFormat != null)
				_SurfaceFormat = surfaceFormat;
			// Actually create this GraphicsWindow
			Create((GraphicsContext)null);
		}