BaseGLSupport.cs :  » Game » RealmForge » Axiom » RenderSystems » OpenGL » 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 » RenderSystems » OpenGL » BaseGLSupport.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.Runtime.InteropServices;
using System.Collections.Specialized;
using Axiom.Configuration;
using Axiom.Graphics;
using Tao.OpenGl;

namespace Axiom.RenderSystems.OpenGL{
  /// <summary>
  /// Summary description for GLHelper.
  /// </summary>
  public abstract class BaseGLSupport {
    #region Fields

    /// <summary>
    ///    Collection of extensions supported by the current hardware.
    /// </summary>
    private static StringCollection extensionList;
    /// <summary>
    ///    OpenGL version string.
    /// </summary>
    private static string glVersion;
    /// <summary>
    ///    Vendor of the current hardware.
    /// </summary>
    private static string vendor;
    /// <summary>
    ///    Name of the video card in use.
    /// </summary>
    private static string videoCard;
    /// <summary>
    ///    Config options.
    /// </summary>
    protected EngineConfig engineConfig = new EngineConfig();

    #endregion Fields

    #region Base Members

    #region Properties

    /// <summary>
    ///    Gets the options currently set by the current GL implementation.
    /// </summary>
    public EngineConfig ConfigOptions {
      get {
        return engineConfig;
      }
    }

    /// <summary>
    ///    Gets a collection of strings listing all the available extensions.
    /// </summary>
    public StringCollection Extensions {
      get {
        return extensionList; 
      }
    }

    /// <summary>
    ///    Name of the vendor for the current video hardware.
    /// </summary>
    public string Vendor {
      get { 
        return vendor; 
      }
    }

    /// <summary>
    ///    Name/brand of the current video hardware.
    /// </summary>
    public string VideoCard {
      get { 
        return videoCard; 
      }
    }

    /// <summary>
    ///    Version string for the current OpenGL driver.
    /// </summary>
    public string Version {
      get { 
        return glVersion; 
      }
    }

    #endregion Properties

    #region Methods

    /// <summary>
    ///    Handy check to see if the current GL version is at least what is supplied.
    /// </summary>
    /// <param name="version">What you want to check for, i.e. "1.3" </param>
    /// <returns></returns>
    public bool CheckMinVersion(string version) {
      return glVersion.StartsWith(version);
    }

    /// <summary>
    ///    
    /// </summary>
    /// <param name="extention"></param>
    /// <returns></returns>
    public bool CheckExtension(string extention) {
      // check if the extension is supported
      return extensionList.Contains(extention);
    }

    /// <summary>
    /// 
    /// </summary>
    public void InitializeExtensions() {
      if(extensionList == null) {
        GlExtensionLoader.LoadAllExtensions();

        // get the OpenGL version string and vendor name
        glVersion = Marshal.PtrToStringAnsi(Gl.glGetString(Gl.GL_VERSION));
        videoCard = Marshal.PtrToStringAnsi(Gl.glGetString(Gl.GL_RENDERER));
        vendor = Marshal.PtrToStringAnsi(Gl.glGetString(Gl.GL_VENDOR));

        // parse out the first piece of the vendor string if there are spaces in it
        if(vendor.IndexOf(" ") != -1) {
          vendor = vendor.Substring(0, vendor.IndexOf(" "));
        }

        // create a new extension list
        extensionList = new StringCollection();

        string allExt = Marshal.PtrToStringAnsi(Gl.glGetString(Gl.GL_EXTENSIONS));
        string[] splitExt = allExt.Split(Char.Parse(" "));

        // store the parsed extension list
        for(int i = 0; i < splitExt.Length; i++) {
          extensionList.Add(splitExt[i]);
        }
      }
    }

    #endregion Methods

    #endregion Base Members

    #region Abstract Members

    /// <summary>
    ///    Add any special config values to the system.
    /// </summary>
    public abstract void AddConfig();

    /// <summary>
    ///    
    /// </summary>
    /// <param name="autoCreateWindow"></param>
    /// <param name="renderSystem"></param>
    /// <param name="windowTitle"></param>
    /// <returns></returns>
    public abstract RenderWindow CreateWindow(bool autoCreateWindow, GLRenderSystem renderSystem, string windowTitle);

    /// <summary>
    ///    Subclasses need to implement a means to return the pointer to the extension function
    ///    for OpenGL calls.
    /// </summary>
    /// <param name="extension">Name of the extension to retreive the pointer for.</param>
    /// <returns>Pointer to the location of the function in the OpenGL driver modules.</returns>
    public abstract IntPtr GetProcAddress(string extension);

    /// <summary>
    ///    Creates a specific instance of a render window.
    /// </summary>
    /// <param name="name"></param>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="colorDepth"></param>
    /// <param name="fullScreen"></param>
    /// <param name="left"></param>
    /// <param name="top"></param>
    /// <param name="depthBuffer"></param>
    /// <param name="parent"></param>
    /// <param name="vsync"></param>
    /// <returns></returns>
    public abstract RenderWindow NewWindow(string name, int width, int height, int colorDepth, bool fullScreen, 
      int left, int top, bool depthBuffer, bool vsync, object target);

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