/// <summary>
        /// Query OpenGL implementation extensions.
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        internal static GraphicsCapabilities Query()
        {
            GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();

            // OpenGL extensions
            graphicsCapabilities._GlExtensions = Gl.CurrentExtensions;
            // Platform OpenGL extensions
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                graphicsCapabilities._WglExtensions = Wgl.CurrentExtensions;
                graphicsCapabilities._EglExtensions = Egl.CurrentExtensions;
                break;

            case PlatformID.Unix:
                graphicsCapabilities._GlxExtensions = Glx.CurrentExtensions;
                break;

            case PlatformID.MacOSX:
                graphicsCapabilities._EglExtensions = Egl.CurrentExtensions;
                break;
            }
            // Query implementation limits
            graphicsCapabilities._GraphicsLimits = Gl.CurrentLimits;

            return(graphicsCapabilities);
        }
예제 #2
0
            /// <summary>
            /// Construct a PlatformExtensions specifying the GraphicsCapabilities which it belongs to.
            /// </summary>
            /// <param name="caps"></param>
            internal PlatformExtensionsCollection(GraphicsCapabilities caps)
            {
                if (caps == null)
                {
                    throw new ArgumentNullException("caps");
                }

                _GraphicsCapabilities = caps;
            }
예제 #3
0
        /// <summary>
        /// Clone this GraphicsCapabilities.
        /// </summary>
        /// <returns></returns>
        public GraphicsCapabilities Clone()
        {
            GraphicsCapabilities clone = (GraphicsCapabilities)MemberwiseClone();

            clone._GlExtensions  = _GlExtensions.Clone();
            clone._WglExtensions = _WglExtensions.Clone();
            clone._GlxExtensions = _GlxExtensions.Clone();

            return(clone);
        }
예제 #4
0
		/// <summary>
		/// Query OpenGL implementation extensions.
		/// </summary>
		/// <param name="ctx"></param>
		/// <returns></returns>
		public static GraphicsCapabilities Query(GraphicsContext ctx, IDeviceContext deviceContext)
		{
			GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();
			FieldInfo[] capsFields = typeof(GraphicsCapabilities).GetFields(BindingFlags.Public | BindingFlags.Instance);

			#region Platform Extension Reload

			// Since at this point there's a current OpenGL context, it's possible to use
			// {glx|wgl}GetExtensionsString to retrieve platform specific extensions

			switch (Environment.OSVersion.Platform) {
				case PlatformID.Win32NT:
				case PlatformID.Win32Windows:
				case PlatformID.Win32S:
				case PlatformID.WinCE:
					Wgl.SyncDelegates();
					break;
			}

			#endregion

			// Only boolean fields are considered
			FieldInfo[] extsFields = Array.FindAll<FieldInfo>(capsFields, delegate(FieldInfo info) {
				return (info.FieldType == typeof(bool));
			});

			foreach (FieldInfo field in extsFields) {
				Attribute[] graphicsExtensionAttributes = Attribute.GetCustomAttributes(field, typeof(GraphicsExtensionAttribute));
				GraphicsExtensionDisabledAttribute graphicsExtensionDisabled = (GraphicsExtensionDisabledAttribute)Attribute.GetCustomAttribute(field, typeof(GraphicsExtensionDisabledAttribute));
				bool implemented = false;

				// Check whether at least one extension is implemented
				implemented = Array.Exists(graphicsExtensionAttributes, delegate(Attribute item) {
					return ((GraphicsExtensionAttribute)item).IsSupported(ctx, deviceContext);
				});
				// Check whether the required extensions are artifically disabled
				if (graphicsExtensionDisabled != null)
					implemented = false;

				field.SetValue(graphicsCapabilities, implemented);
			}

			return (graphicsCapabilities);
		}
예제 #5
0
        /// <summary>
        /// Query OpenGL implementation extensions.
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static GraphicsCapabilities Query(GraphicsContext ctx, IDeviceContext deviceContext)
        {
            GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();

            KhronosApi.LogComment("Query OpenGL extensions.");

            #region Platform Extension Reload

            // Since at this point there's a current OpenGL context, it's possible to use
            // {glx|wgl}GetExtensionsString to retrieve platform specific extensions

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32Windows:
            case PlatformID.Win32S:
            case PlatformID.WinCE:
                // Wgl.SyncDelegates();
                break;
            }

            #endregion

            // OpenGL extensions
            graphicsCapabilities._GlExtensions.Query();
            // Windows OpenGL extensions
            WindowsDeviceContext windowsDeviceContext = deviceContext as WindowsDeviceContext;
            if (windowsDeviceContext != null)
            {
                graphicsCapabilities._WglExtensions.Query(windowsDeviceContext);
            }
            // GLX OpenGL extensions
            XServerDeviceContext xserverDeviceContext = deviceContext as XServerDeviceContext;
            if (xserverDeviceContext != null)
            {
                graphicsCapabilities._GlxExtensions.Query(xserverDeviceContext);
            }

            // Query implementation limits
            graphicsCapabilities._GraphicsLimits = GraphicsLimits.Query(graphicsCapabilities._GlExtensions);

            return(graphicsCapabilities);
        }
		/// <summary>
		/// Query OpenGL implementation extensions.
		/// </summary>
		/// <param name="ctx"></param>
		/// <returns></returns>
		public static GraphicsCapabilities Query(GraphicsContext ctx, IDeviceContext deviceContext)
		{
			GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();

			KhronosApi.LogComment("Query OpenGL extensions.");

			#region Platform Extension Reload

			// Since at this point there's a current OpenGL context, it's possible to use
			// {glx|wgl}GetExtensionsString to retrieve platform specific extensions

			switch (Environment.OSVersion.Platform) {
				case PlatformID.Win32NT:
				case PlatformID.Win32Windows:
				case PlatformID.Win32S:
				case PlatformID.WinCE:
					// Wgl.SyncDelegates();
					break;
			}

			#endregion

			// OpenGL extensions
			graphicsCapabilities._GlExtensions.Query();
			// Windows OpenGL extensions
			WindowsDeviceContext windowsDeviceContext = deviceContext as WindowsDeviceContext;
			if (windowsDeviceContext != null)
				graphicsCapabilities._WglExtensions.Query(windowsDeviceContext);
			// GLX OpenGL extensions
			XServerDeviceContext xserverDeviceContext = deviceContext as XServerDeviceContext;
			if (xserverDeviceContext != null)
				graphicsCapabilities._GlxExtensions.Query(xserverDeviceContext);

			// Query implementation limits
			graphicsCapabilities._GraphicsLimits = GraphicsLimits.Query(graphicsCapabilities._GlExtensions);

			return (graphicsCapabilities);
		}
예제 #7
0
		/// <summary>
		/// Check whether the texture extents are compatible with context capabilities.
		/// </summary>
		/// <param name="caps">
		/// A <see cref="GraphicsCapabilities"/> determining the underlying texture capabilities.
		/// </param>
		/// <param name="width">
		/// A <see cref="UInt32"/> that specify the texture width.
		/// </param>
		/// <param name="height">
		/// A <see cref="UInt32"/> that specify the texture height.
		/// </param>
		/// <param name="depth">
		/// A <see cref="UInt32"/> that specify the texture depth.
		/// </param>
		/// <param name="format">
		/// A <see cref="OpenGL.PixelLayout"/> that specify the texture internal format.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// Exception throw if <paramref name="caps"/> is null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// Exception thrown if <paramref name="width"/>, <paramref name="height"/> or <paramref name="depth"/> is greater than
		/// the maximum allowed for the specific texture target.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// Exception thrown if NPOT texture are not supported by <paramref name="caps"/>, and <paramref name="width"/>, <paramref name="height"/>
		/// or <paramref name="depth"/> is not a power-of-two value.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// Exception thrown if <paramref name="format"/> is not a supported internal format.
		/// </exception>
		private void CheckCapabilities(GraphicsCapabilities caps, uint width, uint height, uint depth, PixelLayout format)
		{
			if (caps == null)
				throw new ArgumentNullException("caps");
			if (caps.GlExtensions == null)
				throw new ArgumentException("caps GL extensions not queried", "caps");
			if (caps.Limits == null)
				throw new ArgumentException("caps Limits not queried", "caps");
		
			// Texture maximum size
			switch (TextureTarget) {
				case TextureTarget.Texture1d:
					if (width > caps.Limits.MaxTexture2DSize)
						throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTexture2DSize));
					break;
				case TextureTarget.Texture2d:
					if (width > caps.Limits.MaxTexture2DSize)
						throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTexture2DSize));
					if (height > caps.Limits.MaxTexture2DSize)
						throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTexture2DSize));
					break;
				case TextureTarget.TextureRectangle:
					if (width > caps.Limits.MaxTextureRectSize)
						throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTextureRectSize));
					if (height > caps.Limits.MaxTextureRectSize)
						throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTextureRectSize));
					break;
				case TextureTarget.Texture3d:
					if (width > caps.Limits.MaxTexture3DSize)
						throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTexture3DSize));
					if (height > caps.Limits.MaxTexture3DSize)
						throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTexture3DSize));
					if (depth > caps.Limits.MaxTexture3DSize)
						throw new ArgumentException(String.Format("depth greater than maximum allowed ({0})", caps.Limits.MaxTexture3DSize));
					break;
				case TextureTarget.TextureCubeMap:
					if (width > caps.Limits.MaxTextureCubeSize)
						throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTextureCubeSize));
					if (height > caps.Limits.MaxTextureCubeSize)
						throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTextureCubeSize));
					break;
				default:
					throw new NotImplementedException("not implemented checks on texture " + GetType());
			}
			// Texture not-power-of-two
			if (caps.GlExtensions.TextureNonPowerOfTwo_ARB == false) {
				if (IsPowerOfTwo(width) == false)
					throw new ArgumentException(String.Format("NPOT texture width not supported (width is {0})", width));
				if (IsPowerOfTwo(height) == false)
					throw new ArgumentException(String.Format("NPOT texture height not supported (height is {0})", height));
				if (IsPowerOfTwo(depth) == false)
					throw new ArgumentException(String.Format("NPOT texture depth not supported (height is {0})", height));
			}
			// Texture internal format
			if (Pixel.IsSupportedInternalFormat(format) == false)
				throw new ArgumentException(String.Format("not supported texture internal format {0}", format), "format");
		}
예제 #8
0
        /// <summary>
        /// Check whether the texture extents are compatible with context capabilities.
        /// </summary>
        /// <param name="caps">
        /// A <see cref="GraphicsCapabilities"/> determining the underlying texture capabilities.
        /// </param>
        /// <param name="width">
        /// A <see cref="UInt32"/> that specify the texture width.
        /// </param>
        /// <param name="height">
        /// A <see cref="UInt32"/> that specify the texture height.
        /// </param>
        /// <param name="depth">
        /// A <see cref="UInt32"/> that specify the texture depth.
        /// </param>
        /// <param name="format">
        /// A <see cref="OpenGL.PixelLayout"/> that specify the texture internal format.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception throw if <paramref name="caps"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Exception thrown if <paramref name="width"/>, <paramref name="height"/> or <paramref name="depth"/> is greater than
        /// the maximum allowed for the specific texture target.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Exception thrown if NPOT texture are not supported by <paramref name="caps"/>, and <paramref name="width"/>, <paramref name="height"/>
        /// or <paramref name="depth"/> is not a power-of-two value.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Exception thrown if <paramref name="format"/> is not a supported internal format.
        /// </exception>
        private void CheckCapabilities(GraphicsCapabilities caps, uint width, uint height, uint depth, PixelLayout format)
        {
            if (caps == null)
            {
                throw new ArgumentNullException("caps");
            }
            if (caps.GlExtensions == null)
            {
                throw new ArgumentException("caps GL extensions not queried", "caps");
            }
            if (caps.Limits == null)
            {
                throw new ArgumentException("caps Limits not queried", "caps");
            }

            // Texture maximum size
            switch (TextureTarget)
            {
            case TextureTarget.Texture1d:
                if (width > caps.Limits.MaxTexture2DSize)
                {
                    throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTexture2DSize));
                }
                break;

            case TextureTarget.Texture2d:
                if (width > caps.Limits.MaxTexture2DSize)
                {
                    throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTexture2DSize));
                }
                if (height > caps.Limits.MaxTexture2DSize)
                {
                    throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTexture2DSize));
                }
                break;

            case TextureTarget.TextureRectangle:
                if (width > caps.Limits.MaxTextureRectSize)
                {
                    throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTextureRectSize));
                }
                if (height > caps.Limits.MaxTextureRectSize)
                {
                    throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTextureRectSize));
                }
                break;

            case TextureTarget.Texture3d:
                if (width > caps.Limits.MaxTexture3DSize)
                {
                    throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTexture3DSize));
                }
                if (height > caps.Limits.MaxTexture3DSize)
                {
                    throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTexture3DSize));
                }
                if (depth > caps.Limits.MaxTexture3DSize)
                {
                    throw new ArgumentException(String.Format("depth greater than maximum allowed ({0})", caps.Limits.MaxTexture3DSize));
                }
                break;

            case TextureTarget.TextureCubeMap:
                if (width > caps.Limits.MaxTextureCubeSize)
                {
                    throw new ArgumentException(String.Format("width greater than maximum allowed ({0})", caps.Limits.MaxTextureCubeSize));
                }
                if (height > caps.Limits.MaxTextureCubeSize)
                {
                    throw new ArgumentException(String.Format("height greater than maximum allowed ({0})", caps.Limits.MaxTextureCubeSize));
                }
                break;

            default:
                throw new NotImplementedException("not implemented checks on texture " + GetType());
            }
            // Texture not-power-of-two
            if (caps.GlExtensions.TextureNonPowerOfTwo_ARB == false)
            {
                if (IsPowerOfTwo(width) == false)
                {
                    throw new ArgumentException(String.Format("NPOT texture width not supported (width is {0})", width));
                }
                if (IsPowerOfTwo(height) == false)
                {
                    throw new ArgumentException(String.Format("NPOT texture height not supported (height is {0})", height));
                }
                if (IsPowerOfTwo(depth) == false)
                {
                    throw new ArgumentException(String.Format("NPOT texture depth not supported (height is {0})", height));
                }
            }
            // Texture internal format
            if (Pixel.IsSupportedInternalFormat(format) == false)
            {
                throw new ArgumentException(String.Format("not supported texture internal format {0}", format), "format");
            }
        }
			/// <summary>
			/// Construct a PlatformExtensions specifying the GraphicsCapabilities which it belongs to.
			/// </summary>
			/// <param name="caps"></param>
			internal PlatformExtensionsCollection(GraphicsCapabilities caps)
			{
				if (caps == null)
					throw new ArgumentNullException("caps");

				_GraphicsCapabilities = caps;
			}