HardwareCaps.cs :  » Game » RealmForge » Axiom » Graphics » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » Axiom » Graphics » HardwareCaps.cs
#region LGPL License
/*
Axiom Game Engine Library
Copyright (C) 2003  Axiom Project Team

The overall design, and a majority of the core engine and rendering code 
contained within this library is a derivative of the open source Object Oriented 
Graphics Engine OGRE, which can be found at http://ogre.sourceforge.net.  
Many thanks to the OGRE team for maintaining such a high quality project.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#endregion

using System;
using System.Diagnostics;
using System.Reflection;
using Axiom.Core;

namespace Axiom.Graphics{
    /// <summary>
    ///   This serves as a way to query information about the capabilies of a 3D API and the
    ///   users hardware configuration.  A RenderSystem should create and initialize an instance
    ///   of this class during startup so that it will be available for use ASAP for checking caps.
    /// </summary>
    public class HardwareCaps {
        #region Member variables
    
        /// <summary>
        ///    Flag enum holding the bits that identify each supported feature.
        /// </summary>
        private Capabilities caps;
        /// <summary>
        ///    Max number of texture units available on the current hardware.
        /// </summary>
        private int numTextureUnits;
        /// <summary>
        ///    Max number of world matrices supported.
        /// </summary>
        private int numWorldMatrices;
        /// <summary>
        ///    The best vertex program version supported by the hardware.
        /// </summary>
        private string maxVertexProgramVersion;
        /// <summary>
        ///    The best fragment program version supported by the hardware.
        /// </summary>
        private string maxFragmentProgramVersion;
        /// <summary>
        ///    The number of floating point constants the current hardware supports for vertex programs.
        /// </summary>
        private int vertexProgramConstantFloatCount;
        /// <summary>
        ///    The number of integer constants the current hardware supports for vertex programs.
        /// </summary>
        private int vertexProgramConstantIntCount;
        /// <summary>
        ///    The number of floating point constants the current hardware supports for fragment programs.
        /// </summary>
        private int fragmentProgramConstantFloatCount;
        /// <summary>
        ///    The number of integer constants the current hardware supports for fragment programs.
        /// </summary>
        private int fragmentProgramConstantIntCount;
        /// <summary>
        ///    Stencil buffer bits available.
        /// </summary>
        private int stencilBufferBits;
        /// <summary>
        ///    Maximum number of lights that can be active in the scene at any given time.
        /// </summary>
        private int maxLights;
        
        #endregion
    
        #region Constructors
    
        /// <summary>
        ///    Default constructor.
        /// </summary>
        public HardwareCaps() {
            caps = 0;
        }
    
        #endregion
    
        #region Properties

        /// <summary>
        ///    Max number of floating point constants supported by the hardware for fragment programs.
        /// </summary>
        public int FragmentProgramConstantFloatCount {
            get {
                return fragmentProgramConstantFloatCount;
            }
            set {
                fragmentProgramConstantFloatCount = value;
            }
        }

        /// <summary>
        ///    Max number of integer constants supported by the hardware for fragment programs.
        /// </summary>
        public int FragmentProgramConstantIntCount {
            get {
                return fragmentProgramConstantIntCount;
            }
            set {
                fragmentProgramConstantIntCount = value;
            }
        }

        /// <summary>
        ///    Best fragment program version supported by the hardware.
        /// </summary>
        public string MaxFragmentProgramVersion {
            get {
                return maxFragmentProgramVersion;
            }
            set {
                maxFragmentProgramVersion = value;
            }
        }

        /// <summary>
        ///    Maximum number of lights that can be active in the scene at any given time.
        /// </summary>
        public int MaxLights {
            get { 
                return maxLights; 
            }
            set { 
                maxLights = value; 
            }
        }

        /// <summary>
        ///    Best vertex program version supported by the hardware.
        /// </summary>
        public string MaxVertexProgramVersion {
            get {
                return maxVertexProgramVersion;
            }
            set {
                maxVertexProgramVersion = value;
            }
        }

        /// <summary>
        ///    Reports on the number of texture units the graphics hardware has available.
        /// </summary>
        public int TextureUnitCount {
            get { 
                return numTextureUnits; 
            }
            set { 
                numTextureUnits = value; 
            }
        }

        /// <summary>
        ///    Max number of world matrices supported by the hardware.
        /// </summary>
        public int NumWorldMatrices {
            get {
                return numWorldMatrices;
            }
            set {
                numWorldMatrices = value;
            }
        }

        /// <summary>
        ///    Number of stencil buffer bits suppported by the hardware.
        /// </summary>
        public int StencilBufferBits {
            get { 
                return stencilBufferBits; 
            }
            set { 
                stencilBufferBits = value; 
            }
        }

        /// <summary>
        ///    Max number of floating point constants supported by the hardware for vertex programs.
        /// </summary>
        public int VertexProgramConstantFloatCount {
            get {
                return vertexProgramConstantFloatCount;
            }
            set {
                vertexProgramConstantFloatCount = value;
            }
        }

        /// <summary>
        ///    Max number of integer constants supported by the hardware for vertex programs.
        /// </summary>
        public int VertexProgramConstantIntCount {
            get {
                return vertexProgramConstantIntCount;
            }
            set {
                vertexProgramConstantIntCount = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        ///    Returns true if the current hardware supports the requested feature.
        /// </summary>
        /// <param name="cap">Feature to query (i.e. Dot3 bump mapping)</param>
        /// <returns></returns>
        public bool CheckCap(Capabilities cap) {
            return (caps & cap) > 0;
        }

        /// <summary>
        ///    Sets a flag stating the specified feature is supported.
        /// </summary>
        /// <param name="cap"></param>
        public void SetCap(Capabilities cap) {
            caps |= cap;
        }

        /// <summary>
        ///    Write all hardware capability information to registered listeners.
        /// </summary>
        public void Log() {
            LogManager logMgr = LogManager.Instance;

            logMgr.Write("---RenderSystem capabilities---");
            logMgr.Write("\t-Available texture units: {0}", this.TextureUnitCount);
            logMgr.Write("\t-Maximum lights available: {0}", this.MaxLights);
            logMgr.Write("\t-Hardware generation of mip-maps: {0}", ConvertBool(CheckCap(Capabilities.HardwareMipMaps)));
            logMgr.Write("\t-Texture blending: {0}", ConvertBool(CheckCap(Capabilities.TextureBlending)));
            logMgr.Write("\t-Anisotropic texture filtering: {0}", ConvertBool(CheckCap(Capabilities.AnisotropicFiltering)));
            logMgr.Write("\t-Dot product texture operation: {0}", ConvertBool(CheckCap(Capabilities.Dot3)));
            logMgr.Write("\t-Cube Mapping: {0}", ConvertBool(CheckCap(Capabilities.CubeMapping)));

            logMgr.Write("\t-Hardware stencil buffer: {0}", ConvertBool(CheckCap(Capabilities.StencilBuffer)));

            if (CheckCap(Capabilities.StencilBuffer)) {
                logMgr.Write("\t\t-Stencil depth: {0} bits", stencilBufferBits);
                logMgr.Write("\t\t-Two sided stencil support: {0}", ConvertBool(CheckCap(Capabilities.TwoSidedStencil)));
                logMgr.Write("\t\t-Wrap stencil values: {0}", ConvertBool(CheckCap(Capabilities.StencilWrap)));
            }

            logMgr.Write("\t-Hardware vertex/index buffers: {0}", ConvertBool(CheckCap(Capabilities.VertexBuffer)));

            logMgr.Write("\t-Vertex programs: {0}", ConvertBool(CheckCap(Capabilities.VertexPrograms)));

            if(CheckCap(Capabilities.VertexPrograms)) {
                logMgr.Write("\t\t-Max vertex program version: {0}", this.MaxVertexProgramVersion);
            }

            logMgr.Write("\t-Fragment programs: {0}", ConvertBool(CheckCap(Capabilities.FragmentPrograms)));

            if (CheckCap(Capabilities.FragmentPrograms)) {
                logMgr.Write("\t\t-Max fragment program version: {0}", this.MaxFragmentProgramVersion);
            }

            logMgr.Write("\t-Texture compression: {0}", ConvertBool(CheckCap(Capabilities.TextureCompression)));

            if (CheckCap(Capabilities.TextureCompression)) {
                logMgr.Write("\t\t-DXT: {0}", ConvertBool(CheckCap(Capabilities.TextureCompressionDXT)));
                logMgr.Write("\t\t-VTC: {0}", ConvertBool(CheckCap(Capabilities.TextureCompressionVTC)));
            }

            logMgr.Write("\t-Scissor rectangle: {0}", ConvertBool(CheckCap(Capabilities.ScissorTest)));
            logMgr.Write("\t-Hardware Occlusion Query: {0}", ConvertBool(CheckCap(Capabilities.HardwareOcculusion)));
            logMgr.Write("\t-User clip planes: {0}", ConvertBool(CheckCap(Capabilities.UserClipPlanes)));
            logMgr.Write("\t-VertexElementType.UBYTE4: {0}", ConvertBool(CheckCap(Capabilities.VertexFormatUByte4)));
            logMgr.Write("\t-Infinite far plane projection: {0}", ConvertBool(CheckCap(Capabilities.InfiniteFarPlane)));
        }

        /// <summary>
        ///     Helper method to convert true/false to yes/no.
        /// </summary>
        /// <param name="val">Bool bal.</param>
        /// <returns>"yes" if true, else "no".</returns>
        private string ConvertBool(bool val) {
            return val ? "yes" : "no";
        }

        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.