/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Window/Context.cs
117 строк
4 KB
EugenyCh7
comments fix
24 июл 2025, 22:54
24 июл 2025, 22:54
421ed1f
Код
Авторство
О чём код?
using System; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security; using Puppet2D.System; namespace Puppet2D.Window { /// <summary> /// This class defines a .NET interface to an Puppet2D OpenGL Context /// </summary> public class Context : CriticalFinalizerObject { /// <summary> /// Default constructor /// </summary> public Context() { myThis = sfContext_create(); } /// <summary> /// Finalizer /// </summary> ~Context() { sfContext_destroy(myThis); } /// <summary> /// Check whether a given OpenGL extension is available. /// </summary> /// <param name="name">Name of the extension to check for</param> /// <returns>True if available, false if unavailable</returns> public static bool IsExtensionAvailable(string name) { return sfContext_isExtensionAvailable(name); } /// <summary> /// Activate or deactivate the context /// </summary> /// <param name="active">True to activate, false to deactivate</param> /// <returns>True on success, false on failure</returns> public bool SetActive(bool active) { return sfContext_setActive(myThis, active); } /// <summary> /// Get the address of an OpenGL function. /// </summary> /// <param name="name">Name of the function to get the address of</param> /// <returns>Address of the OpenGL function, <see cref="IntPtr.Zero"/> on failure</returns> public static IntPtr GetFunction(string name) { return sfContext_getFunction(name); } /// <summary> /// Get the settings of the context. /// </summary> public ContextSettings Settings { get { return sfContext_getSettings(myThis); } } /// <summary> /// Global helper context /// </summary> public static Context Global { get { if (ourGlobalContext == null) { ourGlobalContext = new Context(); } return ourGlobalContext; } } /// <summary> /// Provide a string describing the object /// </summary> /// <returns>String description of the object</returns> public override string ToString() { return "[Context]"; } private static Context ourGlobalContext = null; private readonly IntPtr myThis = IntPtr.Zero; #region Imports [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfContext_create(); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfContext_destroy(IntPtr View); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfContext_isExtensionAvailable(string name); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfContext_setActive(IntPtr View, bool Active); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfContext_getFunction(string name); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern ContextSettings sfContext_getSettings(IntPtr View); #endregion } }