<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics;
using Pulsar4X.WinForms;
using System.Drawing;
using System.Windows.Forms;
using Pulsar4X.WinForms.Controls;
using OpenTK.Graphics.OpenGL;
using OpenTK;
using log4net.Config;
using log4net;
using OpenTK.Platform;
using Config = OpenTK.Configuration;
using Utilities = OpenTK.Platform.Utilities;

namespace Pulsar4X.WinForms
{
    /// <summary>
    /// Used to initilise, configure, etc. OpenTK components.
    /// </summary>
    public sealed class OpenTKUtilities
    {
        public static readonly ILog logger = LogManager.GetLogger(typeof(OpenTKUtilities));

        /// <summary>
        /// A Structure used to store data about a texture.
        /// </summary>
        class TextureData
        {
            public int m_iUseCount = 0;
            public uint m_uiTextureID = 0;
            public string m_szTextureFile = "null";
        }

        /// <summary>
        /// Values that repesent OpenGL Versions.
        /// </summary>
        public enum GLVersion
        {
            Unknown = 0,
            OpenGL1X,
            OpenGL2X,
            OpenGL3X,
            OpenGL4X
        };

        /// <summary>
        /// List of Textures already loaded.
        /// </summary>
        //List<TextureData> m_lLoadedTextures = new List<TextureData>();

        /// <summary>
        /// Used to determine our currently active texture;
        /// </summary>
        uint m_uiActiveTexture = 0;

        /// <summary>
        /// Used to determine our currently active shader.
        /// </summary>
        int m_iActiveShader = 0;

        /// <summary> 
        /// The supported openGL version 
        /// </summary>
        GLVersion m_eSupportedOpenGLVersion;

        /// <summary>
        /// Instance of this class/singelton
        /// </summary>
        private static readonly OpenTKUtilities m_oInstance = new OpenTKUtilities(); 



        /// <summary>
        /// Returns the instance of the OpenTKUtilities class.
        /// </summary>
        public static OpenTKUtilities Instance
        {
            get
            {
                return m_oInstance;
            }
        }

        /// <summary>   Gets or sets the supported open gl version. </summary>
        /// <value> The supported openGL version. </value>
        public GLVersion SupportedOpenGLVersion
        {
            get
            {
                return m_eSupportedOpenGLVersion;
            }
            set
            {
                m_eSupportedOpenGLVersion = value;
            }
        }



        /// <summary>
        /// Constructor that prevents a default instance of this class from being created.
        /// </summary>
        private OpenTKUtilities() { }

        /// <summary>   Initialises the OpenTK Framework, Specificaly OpenGL. </summary>
        /// <param name="a_eGLVersion"> (optional) the e gl version. </param>
        /// <returns> True If Successfull, false otherwise. </returns>
        public bool Initialise(GLVersion a_eGLVersion = GLVersion.Unknown)
        {
            bool bSuccess = false;  // used to shpow success or failure of Init.

            // create a OpenTK Controll and query it for the GLContext version number:
            OpenTK.GLControl oTest = new GLControl(new GraphicsMode(32,24,8,4), 4, 0, GraphicsContextFlags.Default);
            // We need to "show" a for before OpenTK actuall initilise the GLContext (which we need to happen to get a version number!).
            // the following creates a form that we can show but will never be seen by the end user!
            Form oOpenGLVersionCheck = new Form();
            oOpenGLVersionCheck.Controls.Add(oTest);
            oOpenGLVersionCheck.StartPosition = FormStartPosition.CenterScreen;
            oOpenGLVersionCheck.Size = new Size(0, 0);
            oOpenGLVersionCheck.ShowInTaskbar = false;
            oOpenGLVersionCheck.FormBorderStyle = FormBorderStyle.None;
            oOpenGLVersionCheck.TopMost = false;
            oOpenGLVersionCheck.Show();
            oOpenGLVersionCheck.Hide();
            
            string szOpenGLVersion = GL.GetString(StringName.Version);
            int iMajor = int.Parse(szOpenGLVersion[0].ToString());      // extracts the major verion number an converts it to a int.
            int iMinor = int.Parse(szOpenGLVersion[2].ToString());      // same again for minor verion number.

            #if DEBUG
                logger.Debug("Highest OpenGL Version Initialised is " + szOpenGLVersion);  
            #endif

            if (iMajor == 1)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL1X;
            }
            else if (iMajor == 2)<commit_msg>Fixed OpenGL Version Detection Bug on Linux.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics;
using Pulsar4X.WinForms;
using System.Drawing;
using System.Windows.Forms;
using Pulsar4X.WinForms.Controls;
using OpenTK.Graphics.OpenGL;
using OpenTK;
using log4net.Config;
using log4net;
using OpenTK.Platform;
using Config = OpenTK.Configuration;
using Utilities = OpenTK.Platform.Utilities;

namespace Pulsar4X.WinForms
{
    /// <summary>
    /// Used to initilise, configure, etc. OpenTK components.
    /// </summary>
    public sealed class OpenTKUtilities
    {
        public static readonly ILog logger = LogManager.GetLogger(typeof(OpenTKUtilities));

        /// <summary>
        /// A Structure used to store data about a texture.
        /// </summary>
        class TextureData
        {
            public int m_iUseCount = 0;
            public uint m_uiTextureID = 0;
            public string m_szTextureFile = "null";
        }

        /// <summary>
        /// Values that repesent OpenGL Versions.
        /// </summary>
        public enum GLVersion
        {
            Unknown = 0,
            OpenGL1X,
            OpenGL2X,
            OpenGL3X,
            OpenGL4X
        };

        /// <summary>
        /// List of Textures already loaded.
        /// </summary>
        //List<TextureData> m_lLoadedTextures = new List<TextureData>();

        /// <summary>
        /// Used to determine our currently active texture;
        /// </summary>
        uint m_uiActiveTexture = 0;

        /// <summary>
        /// Used to determine our currently active shader.
        /// </summary>
        int m_iActiveShader = 0;

        /// <summary> 
        /// The supported openGL version 
        /// </summary>
        GLVersion m_eSupportedOpenGLVersion;

        /// <summary>
        /// Instance of this class/singelton
        /// </summary>
        private static readonly OpenTKUtilities m_oInstance = new OpenTKUtilities(); 



        /// <summary>
        /// Returns the instance of the OpenTKUtilities class.
        /// </summary>
        public static OpenTKUtilities Instance
        {
            get
            {
                return m_oInstance;
            }
        }

        /// <summary>   Gets or sets the supported open gl version. </summary>
        /// <value> The supported openGL version. </value>
        public GLVersion SupportedOpenGLVersion
        {
            get
            {
                return m_eSupportedOpenGLVersion;
            }
            set
            {
                m_eSupportedOpenGLVersion = value;
            }
        }



        /// <summary>
        /// Constructor that prevents a default instance of this class from being created.
        /// </summary>
        private OpenTKUtilities() { }

        /// <summary>   Initialises the OpenTK Framework, Specificaly OpenGL. </summary>
        /// <param name="a_eGLVersion"> (optional) the e gl version. </param>
        /// <returns> True If Successfull, false otherwise. </returns>
        public bool Initialise(GLVersion a_eGLVersion = GLVersion.Unknown)
        {
            bool bSuccess = false;  // used to shpow success or failure of Init.

            // create a OpenTK Controll and query it for the GLContext version number:
            OpenTK.GLControl oTest = new GLControl(new GraphicsMode(32,24,8,4), 4, 0, GraphicsContextFlags.Default);
            // We need to "show" a for before OpenTK actuall initilise the GLContext (which we need to happen to get a version number!).
            // the following creates a form that we can show but will never be seen by the end user!
            Form oOpenGLVersionCheck = new Form();
            oOpenGLVersionCheck.Controls.Add(oTest);
            oOpenGLVersionCheck.StartPosition = FormStartPosition.CenterScreen;
            oOpenGLVersionCheck.Size = new Size(0, 0);
            oOpenGLVersionCheck.ShowInTaskbar = false;
            oOpenGLVersionCheck.FormBorderStyle = FormBorderStyle.None;
            oOpenGLVersionCheck.TopMost = false;
            oOpenGLVersionCheck.Show();
            oOpenGLVersionCheck.Hide();

            string szOpenGLVersion;
            int iMajor, iMinor;
            try
            {
                szOpenGLVersion = GL.GetString(StringName.Version);
                iMajor = int.Parse(szOpenGLVersion[0].ToString());      // extracts the major verion number an converts it to a int.
                iMinor = int.Parse(szOpenGLVersion[2].ToString());      // same again for minor verion number.
                #if DEBUG
                    logger.Debug("Highest OpenGL Version Initialised is " + szOpenGLVersion);  
                #endif
            }
            catch (System.NullReferenceException e)
            {
                // Problem occured when trying to get open GL Verion, Logg and assume 2.0 so program exacution can continue:
                logger.Error("Error Getting OpenGL Version, Assumong version 2.0!");
                iMajor = 2;
                iMinor = 0;
            }
            

            if (iMajor == 1)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL1X;
            }
            else if (iMajor == 2)
{'fraction_non_alphanumeric': 0.08976393572703828, 'fraction_numerical': 0.006347946835945249, 'mean_word_length': 1.7534134352812671, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623915', 'n_tokens_mistral': 2722, 'n_tokens_neox': 2590, 'n_words': 782}