Ejemplo n.º 1
0
        /// <summary>
        /// Create a device context on the specified P-Buffer.
        /// </summary>
        /// <param name="nativeBuffer">
        /// A <see cref="INativePBuffer"/> created with <see cref="CreatePBuffer(DevicePixelFormat, uint, uint)"/> which
        /// the created context shall be able to render on.
        /// </param>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create(INativePBuffer nativeBuffer)
        {
            DeviceContext deviceContext = null;

            if (IsEglRequired == false)
            {
                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    deviceContext = new DeviceContextWGL(nativeBuffer);
                    break;

                default:
                    throw new NotSupportedException(String.Format("platform {0} not supported", Environment.OSVersion));
                }
            }
            else
            {
                deviceContext = new DeviceContextEGL(nativeBuffer);
            }

            deviceContext._Api = _DefaultApi;

            return(deviceContext);
        }
Ejemplo n.º 2
0
		static void Main()
		{
			string envDebug = Environment.GetEnvironmentVariable("DEBUG");

			if (envDebug == "GL") {
				KhronosApi.RegisterApplicationLogDelegate(delegate (string format, object[] args) {
					Console.WriteLine(format, args);
				});
			}

			try {
				// Gl.CurrentExtensions.FramebufferObject_ARB = false;		// Test P-Buffer
				// Egl.IsRequired = Egl.IsAvailable;						// Test EGL (not yet working)

				if (Gl.CurrentExtensions.FramebufferObject_ARB) {
					using (DeviceContext deviceContext = DeviceContext.Create()) {
						RenderOsdFramebuffer(deviceContext);
					}
				} else {
					// Fallback to old-school pbuffer
					using (INativePBuffer nativeBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 800, 600)) {
						using (DeviceContext deviceContext = DeviceContext.Create(nativeBuffer)) {
							RenderOsdPBuffer(deviceContext);
						}
					}
				}
			} catch (Exception exception) {
				Console.WriteLine("Unexpected exception: {0}", exception.ToString());
			}
		}
Ejemplo n.º 3
0
        public void TestCreatePBuffer()
        {
            if (DeviceContext.IsPBufferSupported == false)
            {
                Assert.Inconclusive("platform don't support P-Buffers");
            }

            // Inconclusive test?
            switch (Platform.CurrentPlatformId)
            {
            case Platform.Id.WindowsNT:
                if (Wgl.CurrentExtensions.Pbuffer_ARB == false && Wgl.CurrentExtensions.Pbuffer_EXT == false)
                {
                    Assert.Inconclusive("no WGL_ARB_pbuffer or WGL_EXT_pbuffer support");
                }
                break;
            }

            INativePBuffer nativePBuffer = null;

            // P-Buffer creation should be possible on every platform
            Assert.DoesNotThrow(delegate() {
                nativePBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 64, 64);
            });
            Assert.IsNotNull(nativePBuffer);

            // Release resources
            nativePBuffer.Dispose();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Gl.Initialize();

            try {
                // Gl.CurrentExtensions.FramebufferObject_ARB = false;		// Test P-Buffer
                // Egl.IsRequired = Egl.IsAvailable;						// Test EGL (not yet working)

                if (Gl.CurrentExtensions.FramebufferObject_ARB)
                {
                    using (DeviceContext deviceContext = DeviceContext.Create()) {
                        RenderOsdFramebuffer(deviceContext);
                    }
                }
                else
                {
                    // Fallback to old-school pbuffer
                    using (INativePBuffer nativeBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 800, 600)) {
                        using (DeviceContext deviceContext = DeviceContext.Create(nativeBuffer)) {
                            RenderOsdPBuffer(deviceContext);
                        }
                    }
                }
            } catch (Exception exception) {
                Console.WriteLine("Unexpected exception: {0}", exception.ToString());
            }
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DeviceContextWGL"/> class.
		/// </summary>
		/// <param name='nativeBuffer'>
		/// A <see cref="INativePBuffer"/> that specifies the P-Buffer used to create the device context.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// Exception thrown if <paramref name="nativeBuffer"/> is null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// Exception thrown if <paramref name="nativeBuffer"/> is not an instance created by
		/// <see cref="DeviceContext.CreatePBuffer(DevicePixelFormat, uint, uint)"/>.
		/// </exception>
		/// <exception cref='InvalidOperationException'>
		/// Is thrown when an operation cannot be performed.
		/// </exception>
		public DeviceContextWGL(INativePBuffer nativeBuffer)
		{
			if (nativeBuffer == null)
				throw new ArgumentNullException("nativeBuffer");

			NativePBuffer nativePBuffer = nativeBuffer as NativePBuffer;
			if (nativePBuffer == null)
				throw new ArgumentException("INativePBuffer not created with DeviceContext.CreatePBuffer");

			if (!Wgl.CurrentExtensions.Pbuffer_ARB && !Wgl.CurrentExtensions.Pbuffer_EXT)
				throw new InvalidOperationException("WGL_(ARB|EXT)_pbuffer not supported");

			_WindowHandle = nativePBuffer.Handle;

			if (Wgl.CurrentExtensions.Pbuffer_ARB)
				_DeviceContext = Wgl.GetPbufferDCARB(nativePBuffer.Handle);
			else
				_DeviceContext = Wgl.GetPbufferDCEXT(nativePBuffer.Handle);

			if (_DeviceContext == IntPtr.Zero)
				throw new InvalidOperationException("unable to get device context");
			_DeviceContextPBuffer = true;

			IsPixelFormatSet = true;
		}
Ejemplo n.º 6
0
        public static void Init()
        {
            Gl.Initialize();

            pixelBuff = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 128, 128);
            devCtx    = DeviceContext.Create(pixelBuff);
            glCtx     = devCtx.CreateContext(IntPtr.Zero);

            devCtx.MakeCurrent(glCtx);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContextEGL"/> class.
        /// </summary>
        /// <param name='nativeBuffer'>
        /// A <see cref="INativePBuffer"/> that specifies the P-Buffer used to create the device context.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="nativeBuffer"/> is null.
        /// </exception>
        public DeviceContextEGL(INativePBuffer nativeBuffer)
        {
            if (nativeBuffer == null)
            {
                throw new ArgumentNullException("nativeBuffer");
            }

            NativePBuffer nativePBuffer = nativeBuffer as NativePBuffer;

            if (nativePBuffer == null)
            {
                throw new ArgumentException("INativePBuffer not created with DeviceContext.CreatePBuffer");
            }

            _NativeSurface = nativePBuffer;
        }
Ejemplo n.º 8
0
        private void DeviceContext_Create3_Core()
        {
            if (DeviceContext.IsPBufferSupported == false)
            {
                Assert.Inconclusive("platform don't support P-Buffers");
            }

            DeviceContext deviceContext = null;

            using (INativePBuffer nativePBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 64, 64)) {
                Assert.DoesNotThrow(() => deviceContext = DeviceContext.Create(nativePBuffer));
                Assert.IsNotNull(nativePBuffer);

                // Release resources
                deviceContext.Dispose();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create a device context on the specified P-Buffer.
        /// </summary>
        /// <param name="nativeBuffer">
        /// A <see cref="INativePBuffer"/> created with <see cref="CreatePBuffer(DevicePixelFormat, uint, uint)"/> which
        /// the created context shall be able to render on.
        /// </param>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create(INativePBuffer nativeBuffer)
        {
#if !MONODROID
            if (IsEglRequired == false)
            {
                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    return(new DeviceContextWGL(nativeBuffer));

                default:
                    throw new NotSupportedException("platform not supported");
                }
            }
            else
#endif
            return(new DeviceContextEGL(nativeBuffer));
        }
Ejemplo n.º 10
0
        public void DeviceContext_CreatePBuffer_Core()
        {
            if (DeviceContext.IsPBufferSupported == false)
            {
                Assert.Inconclusive("platform don't support P-Buffers");
            }

            INativePBuffer nativePBuffer = null;

            Assert.Throws <ArgumentNullException>(() => DeviceContext.CreatePBuffer(null, 64, 64));

            // P-Buffer creation should be possible on every platform
            Assert.DoesNotThrow(() => nativePBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 64, 64));
            Assert.IsNotNull(nativePBuffer);

            // Release resources
            nativePBuffer.Dispose();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContextEGL"/> class.
        /// </summary>
        /// <param name='nativeBuffer'>
        /// A <see cref="INativePBuffer"/> that specifies the P-Buffer used to create the device context.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="nativeBuffer"/> is null.
        /// </exception>
        public DeviceContextEGL(INativePBuffer nativeBuffer)
            : this()
        {
            if (nativeBuffer == null)
            {
                throw new ArgumentNullException(nameof(nativeBuffer));
            }

            NativePBuffer nativePBuffer = nativeBuffer as NativePBuffer;

            if (nativePBuffer == null)
            {
                throw new ArgumentException("INativePBuffer not created with DeviceContext.CreatePBuffer");
            }

            _NativeSurface = nativePBuffer;

            IsPixelFormatSet = true;
        }
Ejemplo n.º 12
0
        private void TestUserCase3_Core()
        {
            if (DeviceContext.IsPBufferSupported == false)
            {
                Assert.Inconclusive("platform don't support P-Buffers");
            }

            using (INativePBuffer nativePBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 64, 64)) {
                using (DeviceContext deviceContext = DeviceContext.Create(nativePBuffer)) {
                    // The pixel format is already defined by INativePBuffer
                    Assert.IsTrue(deviceContext.IsPixelFormatSet);

                    IntPtr glContext = deviceContext.CreateContext(IntPtr.Zero);

                    deviceContext.MakeCurrent(glContext);
                    // Perform drawing...
                    deviceContext.MakeCurrent(IntPtr.Zero);
                    deviceContext.DeleteContext(glContext);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create a device context on the specified P-Buffer.
        /// </summary>
        /// <param name="nativeBuffer">
        /// A <see cref="INativePBuffer"/> created with <see cref="CreatePBuffer(DevicePixelFormat, uint, uint)"/> which
        /// the created context shall be able to render on.
        /// </param>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create(INativePBuffer nativeBuffer)
        {
            DeviceContext deviceContext = null;

            if (IsEglRequired == false)
            {
                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    deviceContext = new DeviceContextWGL(nativeBuffer);
                    break;

                default:
                    throw new NotSupportedException("platform not supported");
                }
            }
            else
            {
                deviceContext = new DeviceContextEGL(nativeBuffer);
            }

            return(deviceContext);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Create a device context without a specific window.
        /// </summary>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create()
        {
#if !MONODROID
            if (IsEglRequired == false)
            {
                // OPENGL_NET_INIT environment set to NO?
                if (Gl._NativeWindow == null)
                {
                    throw new InvalidOperationException("OpenGL.Net not initialized", Gl._InitializationException);
                }

                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    return(new DeviceContextWGL());

                case Platform.Id.Linux:
                    return(new DeviceContextGLX());

                case Platform.Id.MacOS:
                    if (Glx.IsRequired)
                    {
                        return(new DeviceContextGLX());
                    }
                    else
                    {
                        throw new NotSupportedException("platform MacOS not supported without Glx.IsRequired=true");
                    }

                default:
                    throw new NotSupportedException(String.Format("platform {0} not supported", Platform.CurrentPlatformId));
                }
            }
            else
            {
#endif
            // Create a surfaceless context
            if (Egl.CurrentExtensions == null || Egl.CurrentExtensions.SurfacelessContext_KHR == false)
            {
                // OPENGL_NET_INIT environment set to NO?
                if (Gl._NativeWindow == null)
                {
                    throw new InvalidOperationException("OpenGL.Net not initialized", Gl._InitializationException);
                }

                INativePBuffer nativeBuffer = Gl._NativeWindow as INativePBuffer;
                if (nativeBuffer != null)
                {
                    return(new DeviceContextEGL(nativeBuffer));
                }

                INativeWindow nativeWindow = Gl._NativeWindow as INativeWindow;
                if (nativeWindow != null)
                {
                    return(new DeviceContextEGL(nativeWindow.Handle));
                }

                throw new NotSupportedException("EGL surface not supported");
            }
            else
            {
                return(new DeviceContextEGL(IntPtr.Zero));
            }
#if !MONODROID
        }
#endif
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create a device context without a specific window.
        /// </summary>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create()
        {
            Debug.Assert(Gl._NativeWindow != null);

            DeviceContext deviceContext = null;

            if (IsEglRequired == false)
            {
                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    deviceContext = new DeviceContextWGL();
                    break;

                case Platform.Id.Linux:
                    deviceContext = new DeviceContextGLX();
                    break;

                case Platform.Id.MacOS:
                    if (Glx.IsRequired)
                    {
                        deviceContext = new DeviceContextGLX();
                    }
                    else
                    {
                        throw new NotSupportedException("platform MacOS not supported without Glx.IsRequired=true");
                    }
                    break;

                default:
                    throw new NotSupportedException(String.Format("platform {0} not supported", Platform.CurrentPlatformId));
                }
            }
            else
            {
                if (deviceContext == null)
                {
                    INativePBuffer nativeBuffer = Gl._NativeWindow as INativePBuffer;
                    if (nativeBuffer != null)
                    {
                        deviceContext = new DeviceContextEGL(nativeBuffer);
                    }
                }

                if (deviceContext == null)
                {
                    INativeWindow nativeWindow = Gl._NativeWindow as INativeWindow;
                    if (nativeWindow != null)
                    {
                        deviceContext = new DeviceContextEGL(nativeWindow.Handle);
                    }
                }

                if (deviceContext == null)
                {
                    Debug.Fail("unsupported EGL surface");
                    throw new NotSupportedException("EGL surface not supported");
                }
            }

            return(deviceContext);
        }