public void EnableDebugCallback(DebugProc callback) { glEnable(EnableCap.DebugOutput); // The debug callback delegate must be persisted, otherwise errors will occur // when the OpenGL drivers attempt to call it after it has been collected. _debugMessageCallback = callback; glDebugMessageCallback(_debugMessageCallback, null); }
public static void Init() { #if DEBUG GL.Enable(EnableCap.DebugOutput); OnDebugProc = new DebugProc(OnDebugOutput); GL.DebugMessageCallback(OnDebugProc, IntPtr.Zero); #endif }
#pragma warning restore S1450 /// <summary> /// Enable the debugging features. /// </summary> public void Enable() { GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.Multisample); debugCallbackDelegate = DebugCallback; GL.DebugMessageCallback(debugCallbackDelegate, IntPtr.Zero); }
public static void Initialize() { GL.Enable(EnableCap.DebugOutputSynchronous); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, true); _debugCallback = GLDebugHandler; GL.DebugMessageCallback(_debugCallback, IntPtr.Zero); }
public RenderEngine(Map map, Camera camera) { // Temp config worldSizeDim = 20f; // Total size of the world, per dimension // End temp config // Initialise variables this.map = map; this.camera = camera; tilesCountDim = Config.WorldSize; int tilesCount = tilesCountDim * tilesCountDim; tilesVertexCount = tilesCount * 2 * 3; // For each tile, we have 2 triangles * 3 vertices dataSize = tilesVertexCount * 3; // 3 coordinates per vertex // Setup data arrays InitVertexData(); InitTileTextureData(); InitEntityTextureData(); // Set debug callback GL.Enable(EnableCap.DebugOutput); openGLErrorDelegate = new DebugProc(OpenGLErrorCallback); GL.DebugMessageCallback(openGLErrorDelegate, IntPtr.Zero); // Set OpenGL parameters GL.EnableClientState(ArrayCap.VertexArray); // Shader programID = GL.CreateProgram(); LoadShader(Path.Combine(Config.ShadersFolder, "vs.glsl"), ShaderType.VertexShader, programID, out int vsID); LoadShader(Path.Combine(Config.ShadersFolder, "fs.glsl"), ShaderType.FragmentShader, programID, out int fsID); GL.LinkProgram(programID); attribute_vPosition = GL.GetAttribLocation(programID, "vPosition"); attribute_vTileTexCoord = GL.GetAttribLocation(programID, "vTileTexCoord"); attribute_vEntityTexCoord = GL.GetAttribLocation(programID, "vEntityTexCoord"); uniform_transform = GL.GetUniformLocation(programID, "transform"); uniform_textureAtlas = GL.GetUniformLocation(programID, "textureAtlas"); vertexBuffer = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertexData.Length * 4), vertexData, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(attribute_vPosition, 3, VertexAttribPointerType.Float, false, 0, 0); tileTextureBuffer = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, tileTextureBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(tileTextureData.Length * 4), tileTextureData, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(attribute_vTileTexCoord, 3, VertexAttribPointerType.Float, false, 0, 0); entityTextureBuffer = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, entityTextureBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(entityTextureData.Length * 4), entityTextureData, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(attribute_vEntityTexCoord, 3, VertexAttribPointerType.Float, false, 0, 0); }
public static void Init(GameWindowSettings gws, NativeWindowSettings nws, GLRenderer renderer = null, Action initCallback = null) { _window = new GameWindow(gws, nws); //log basic info Logger.Log("Base Directory: " + AppContext.BaseDirectory, true); Logger.Log("Renderer: " + GL.GetString(StringName.Renderer), true); Logger.Log("Vendor: " + GL.GetString(StringName.Vendor), true); Logger.Log("Version: " + GL.GetString(StringName.Version), true); Logger.Log("Shading Language version: " + GL.GetString(StringName.ShadingLanguageVersion), true); //subscribe to window events MainWindow.UpdateFrame += UpdateFrame; MainWindow.RenderFrame += RenderFrame; //intialize engine Logger.Log("Initializing LeaderEngine...", true); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //init debug callbacks GLFW.SetErrorCallback(LogGLFWError); DebugProc debugProcCallback = DebugCallback; GCHandle debugProcCallbackHandle = GCHandle.Alloc(debugProcCallback); GL.DebugMessageCallback(debugProcCallback, IntPtr.Zero); GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); //init modules AssetManager.Init(); DefaultShaders.Init(); SpriteRenderer.Init(); SkyboxRenderer.Init(); _renderer = renderer ?? new ForwardRenderer(); Renderer.Init(); AudioManager.Init(); Input.Init(MainWindow.KeyboardState, MainWindow.MouseState); //init main application initCallback?.Invoke(); stopwatch.Stop(); //print init complete msg Logger.Log($"LeaderEngine initialized. ({stopwatch.ElapsedMilliseconds}ms)", true); //open window MainWindow.Run(); }
/// <summary> /// Initializes a new instance of the <see cref="DebuggerGL"/> class. /// </summary> public DebuggerGL() { Debug.WriteLine($"{GL.GetString(StringName.Renderer)} running OpenGL " + $"Version {GL.GetInteger(GetPName.MajorVersion)}.{GL.GetInteger(GetPName.MinorVersion)} with "); Debug.WriteLine($"Shading Language Version {GL.GetString(StringName.ShadingLanguageVersion)}"); GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); //Console.WriteLine(GL.GetString(StringName.Extensions)); debugCallback = DebugCallback; //need to keep an instance, otherwise delegate is garbage collected GL.DebugMessageCallback(debugCallback, IntPtr.Zero); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, new int[] { }, true); }
protected override void OnLoad(EventArgs e) { if (!isReady) { return; } #if DEBUG debugCallback = new DebugProc(GLDebugCallback); GL.DebugMessageCallback(debugCallback, IntPtr.Zero); #endif GL.ClearColor(BackColor); base.OnLoad(e); }
public Game(int width, int height, string title) : base(width, height, GraphicsMode.Default, title) { GL.Enable((EnableCap)All.DebugOutput); GL.Enable((EnableCap)All.DebugOutputSynchronous); openGLDebugDelegate = new DebugProc(openGLDebugCallback); GL.DebugMessageCallback(openGLDebugDelegate, IntPtr.Zero); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, new int[0], true); GL.DebugMessageInsert(DebugSourceExternal.DebugSourceApplication, DebugType.DebugTypeMarker, 0, DebugSeverity.DebugSeverityNotification, -1, "Debug output enabled"); }
protected override void OnLoad(EventArgs e) { if (!isReady) { return; } if (Program.AppEnvironment.EnableOpenGLDebug) { debugCallback = new DebugProc(GLDebugCallback); GL.DebugMessageCallback(debugCallback, IntPtr.Zero); } GL.ClearColor(BackColor); base.OnLoad(e); }
public Game() : base(1280, 900, new GraphicsMode(new ColorFormat(8, 8, 8, 0), 24, // Depth bits 8, // Stencil bits 4 // FSAA samples ), string.Empty, GameWindowFlags.Default, DisplayDevice.Default, 4, 0, GraphicsContextFlags.ForwardCompatible) { Console.WriteLine($"Renderer: {GL.GetString(StringName.Renderer)}"); Console.WriteLine($"Version: {GL.GetString(StringName.Version)}"); _openGlDebugDelegate += OpenGlDebugCallback; }
// TODO: 此函数的'try to remove unused items from rc2ProcDict'部分尚需检测。 /// <summary> /// 设置Debug模式的回调函数。 /// <para>此函数的'try to remove unused items from rc2ProcDict'部分尚需检测。</para> /// </summary> /// <param name="callback"></param> /// <param name="userParam">建议使用<see cref="UnmanagedArray.Header"/></param> public static void DebugMessageCallback(DebugProc callback, IntPtr userParam) { if (innerCallbackProc == null) { innerCallbackProc = new DEBUGPROC(innerCallback); } IntPtr renderContext = Win32.wglGetCurrentContext(); IntPtr deviceContext = Win32.wglGetCurrentDC(); if (rc2ProcDict.ContainsKey(renderContext)) { rc2ProcDict[renderContext] = callback; rc2dcDict[renderContext] = deviceContext; } else { rc2ProcDict.Add(renderContext, callback); rc2dcDict.Add(renderContext, deviceContext); debugProcDictCount++; // try to remove unused items from rc2ProcDict if (debugProcDictCount > maxDebugProcDictCount) { List <IntPtr> unusedRCList = new List <IntPtr>(); foreach (var item in rc2dcDict) { if (!Win32.wglMakeCurrent(item.Value, item.Key))// 这种检测方式可行吗? { unusedRCList.Add(item.Key); } } foreach (var item in unusedRCList) { rc2ProcDict.Remove(item); rc2dcDict.Remove(item); } debugProcDictCount -= unusedRCList.Count; maxDebugProcDictCount = debugProcDictCount + 100; Win32.wglMakeCurrent(renderContext, deviceContext); } } GetDelegateFor <glDebugMessageCallback>()(innerCallbackProc, userParam); }
public static void EnableOpenTKDebugOutput() { #if DEBUG // This isn't free, so skip this step when not debugging. // TODO: Only works with Intel integrated. if (SFGraphics.Tools.OpenGLExtensions.IsAvailable("GL_KHR_debug")) { GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); debugProc = DebugCallback; GL.DebugMessageCallback(debugProc, IntPtr.Zero); int[] ids = { }; GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, ids, true); } #endif }
public Window(GameConfiguration config) : base( config.Width, config.Height, GraphicsMode.Default, config.Title, config.IsFullscreen ? GameWindowFlags.Fullscreen : GameWindowFlags.Default, DisplayDevice.Default, 3, 3, #if DEBUG GraphicsContextFlags.Debug | #endif GraphicsContextFlags.ForwardCompatible) { this.debugProc = this.DebugLog; this.config = config; this.nextState = config.InitialState; }
static GLDebugLog() { _debugProcCallback = DebugCallback; _callbackHandle = GCHandle.Alloc(_debugProcCallback); GL.GetInteger(GetPName.ContextFlags, out var flags); if ((flags & DEBUG_BIT) != 0) { GL.Enable(EnableCap.DebugOutput); } GL.Enable(EnableCap.DebugOutputSynchronous); _maxMessageLength = GL.GetInteger((GetPName)GLMaxDebugMessageLength); GL.DebugMessageCallback(_debugProcCallback, IntPtr.Zero); }
private static void innerCallback( uint source, uint type, uint id, uint severity, int length, StringBuilder message, IntPtr userParam) { IntPtr context = Win32.wglGetCurrentContext(); DebugProc proc = rc2ProcDict[context]; if (proc != null) { proc( (Enumerations.DebugSource)source, (Enumerations.DebugType)type, id, (Enumerations.DebugSeverity)severity, length, message, userParam); } }
public static void SetupDebugCallback(ITextOutputGlob textOutput) { _debugOutput = textOutput; GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); _callback = DebugMessageCallback; GL.DebugMessageCallback(_callback, IntPtr.Zero); _maxDebugMessageLength = GL.GetInteger((GetPName)GL_MAX_DEBUG_MESSAGE_LENGTH); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, new int[1], true); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypePushGroup, DebugSeverityControl.DontCare, 0, new int[1], false); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypePopGroup, DebugSeverityControl.DontCare, 0, new int[1], false); //GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 2, new int[2] //{ // 131185, // 131186, //}, false); }
protected override void OnLoad() { base.OnLoad(); // Enable GL debugging GL.Enable(EnableCap.DebugOutput); DebugProc openGLDebugDelegate = new DebugProc(OpenGLDebugCallback); GL.DebugMessageCallback(openGLDebugDelegate, IntPtr.Zero); // Create shader shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag"); // Create orthographic perspective matrix perspectiveMatrix = Matrix4.CreateOrthographicOffCenter(0.0f, Size.X, Size.Y, 0.0f, -100.0f, 100.0f); maze = new Maze(MazeLoader.MazeType.Test3); }
// public delegate void DebugProc(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam); /// <summary> /// Enable GL debug proc and vector to this function /// </summary> public static bool EnableDebug(DebugProc callback) { if (HasExtensions("GL_KHR_debug")) { GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); GL.DebugMessageCallback(callback, IntPtr.Zero); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, new int[0], true); GL.DebugMessageInsert(DebugSourceExternal.DebugSourceApplication, DebugType.DebugTypeMarker, 0, DebugSeverity.DebugSeverityNotification, -1, "Debug output enabled"); return(true); } else { return(false); } }
void setupDebugCapture() { //#if false #if DEBUG GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); //filter out noise messages disabledIds = new uint[4] { 131185, 131186, 131204, 1282 }; GL.DebugMessageControl(DebugSourceControl.DebugSourceApi, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, disabledIds.Length, disabledIds, false); GL.DebugMessageControl(DebugSourceControl.DebugSourceApi, DebugTypeControl.DebugTypeOther, DebugSeverityControl.DebugSeverityNotification, 0, (uint[])null, false); //filter out debug push/pop messages (too much console spew) GL.DebugMessageControl(DebugSourceControl.DebugSourceApplication, DebugTypeControl.DebugTypePushGroup, DebugSeverityControl.DebugSeverityNotification, 0, (uint[])null, false); GL.DebugMessageControl(DebugSourceControl.DebugSourceApplication, DebugTypeControl.DebugTypePopGroup, DebugSeverityControl.DebugSeverityNotification, 0, (uint[])null, false); myDebugCallback = new DebugProc(debugOutput); GL.DebugMessageCallback(myDebugCallback, IntPtr.Zero); #endif }
public static void Initialize(GraphicsDebugLevel logLevel) { // Disable everything GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, false); if (logLevel == GraphicsDebugLevel.None) { GL.Disable(EnableCap.DebugOutputSynchronous); GL.DebugMessageCallback(null, IntPtr.Zero); return; } GL.Enable(EnableCap.DebugOutputSynchronous); if (logLevel == GraphicsDebugLevel.Error) { GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypeError, DebugSeverityControl.DontCare, 0, (int[])null, true); } else if (logLevel == GraphicsDebugLevel.Slowdowns) { GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypeError, DebugSeverityControl.DontCare, 0, (int[])null, true); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypePerformance, DebugSeverityControl.DontCare, 0, (int[])null, true); } else { GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, true); } _counter = 0; _debugCallback = GLDebugHandler; GL.DebugMessageCallback(_debugCallback, IntPtr.Zero); Logger.Warning?.Print(LogClass.Gpu, "OpenGL Debugging is enabled. Performance will be negatively impacted."); }
public static void DebugMessageCallback(DebugProc callback, IntPtr userParam) { glDebugMessageCallback(callback, userParam); }
public abstract void DebugMessageCallback <T0>([Flow(FlowDirection.In), Ultz.SuperInvoke.InteropServices.PinObjectAttribute(Ultz.SuperInvoke.InteropServices.PinMode.UntilNextCall)] DebugProc callback, [Flow(FlowDirection.In)] Span <T0> userParam) where T0 : unmanaged;
public abstract unsafe void DebugMessageCallback([Flow(FlowDirection.In), Ultz.SuperInvoke.InteropServices.PinObjectAttribute(Ultz.SuperInvoke.InteropServices.PinMode.UntilNextCall)] DebugProc callback, [Flow(FlowDirection.In)] void *userParam);
private void StartupGL() { #if DEBUG EchoWindow = true; #endif render_window = new GameWindow( (EchoWindow ? textureSizeX : 640), (EchoWindow ? textureSizeY : 480), new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(8, 8, 8, 8), 16, 0), "OpenVR Cards Subsystem", GameWindowFlags.Default, DisplayDevice.Default, 3, 3, OpenTK.Graphics.GraphicsContextFlags.Default) { Visible = EchoWindow, VSync = VSyncMode.Off }; render_window.MakeCurrent(); #if DEBUG cb = DBGProc; GL.Enable(EnableCap.DebugOutput); GL.DebugMessageCallback(cb, IntPtr.Zero); #endif GL.ClearColor(0, 0, 0, 0); VAO = GL.GenVertexArray(); GL.BindVertexArray(VAO); frameBufferId = GL.GenFramebuffer(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferId); textureId = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, textureId); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, textureSizeX, textureSizeY, 0, PixelFormat.Rgb, PixelType.Byte, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); depthBufferId = GL.GenRenderbuffer(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBufferId); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent16, textureSizeX, textureSizeY); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBufferId); GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, textureId, 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment0); FramebufferErrorCode error = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if (error != FramebufferErrorCode.FramebufferComplete) { throw new Exception("OpenGL Error."); } GL.Viewport(0, 0, textureSizeX, textureSizeY); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); ColorShader.Instance.Compile(); EchoShader.Instance.Compile(); RectangleGL.Load(); EchoScene.Instance.Window = render_window; EchoScene.Instance.EchoTexture = textureId; CardRectangle.Scale = new Vector2(textureSizeX, 300); CardRectangle.Shader = ColorShader.Instance; CardScene = new Scene(textureSizeX, textureSizeY); CardFont.Load(); #if DEBUG Debug.WriteLine("StartupGL Complete"); #endif }
//......................................................................................... public static void DebugMessageCallback(DebugProc callback, IntPtr userParam) { _InvokeExtensionFunction <glDebugMessageCallback>(callback, userParam); }
internal extern static void DebugMessageCallback(DebugProc callback, IntPtr userParam);
protected override void OnLoad() { base.OnLoad(); GL.Enable(EnableCap.DebugOutput); DebugProc openGLDebugDelegate = new DebugProc(OpenGLDebugCallback); GL.DebugMessageCallback(openGLDebugDelegate, IntPtr.Zero); // Create shader shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag"); shader.Use(); // Create target texture textureHandle = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, textureHandle); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); Random random = new Random(); byte[] pixels = new byte[64 * 32]; for (int i = 0; i < 64 * 32; i++) { pixels[i] = (byte)(random.NextDouble() * 255.0f); } GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8, 64, 32, 0, PixelFormat.Red, PixelType.UnsignedByte, pixels); // Create mesh float[] vertices = new float[] { // vec2 position // vec2 texCoord // Top left triangle -1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 0, 0, // Bottom right triangle 1, -1, 1, 1, 1, 1, 1, 0, -1, 1, 0, 0, }; vboHandle = GL.GenBuffer(); vaoHandle = GL.GenVertexArray(); GL.BindVertexArray(vaoHandle); GL.BindBuffer(BufferTarget.ArrayBuffer, vboHandle); GL.EnableVertexAttribArray(0); GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0 * sizeof(float)); GL.EnableVertexAttribArray(1); GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float)); GL.BindVertexArray(vaoHandle); GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StreamDraw); // Load program byte[] fileBytes = File.ReadAllBytes("Roms/life.ch8"); // Create emulator ushort[] instructions = new ushort[] { 0x00E0, 0xF029, 0xD115, 0x7001, 0x1200 }; chip8 = new Chip8(fileBytes); //chip8 = new Chip8(instructions); chip8.DumpMemory(); }
private void CheckGraphicsCapabilities(LogLevel logLevel) { openGLCapabilities = new OpenGLGraphicsCapabilities(); capabilities = new GraphicsCapabilities(); openGLCapabilities.OpenGLVersion = new Version(GL.GetInteger(GetPName.MajorVersion), GL.GetInteger(GetPName.MinorVersion)); Log.Write(logLevel, "OpenGL Diagnostics:"); Log.Write(logLevel, "\tOpenGL Version: {0}", openGLCapabilities.OpenGLVersion.ToString()); //GLSL Version string auslesen string glslVersionString = ""; if (openGLCapabilities.OpenGLVersion >= new Version(4, 3) && !string.IsNullOrWhiteSpace(glslVersionString = GL.GetString(StringName.ShadingLanguageVersion))) { string glslVersionStringMajor = glslVersionString.Substring(0, glslVersionString.IndexOf('.')); string glslVersionStringMinor = glslVersionString.Substring(glslVersionString.IndexOf('.') + 1, 1); int glslVersionMajor; int glslVersionMinor; if (!int.TryParse(glslVersionStringMajor, out glslVersionMajor) || !int.TryParse(glslVersionStringMinor, out glslVersionMinor)) { throw new DotGame.Graphics.GraphicsException("Could not determine supported GLSL version"); } //Nicht Version mit String initialisieren da 4.40 als Major 4 und Minor 40 aufgefasst wird openGLCapabilities.GLSLVersion = new Version(glslVersionMajor, glslVersionMinor); } else if (glslVersions.ContainsKey(openGLCapabilities.OpenGLVersion)) { openGLCapabilities.GLSLVersion = glslVersions[openGLCapabilities.OpenGLVersion]; } else { throw new Exception("Could not determine supported GLSL version"); } CheckGLError("Init Version"); Log.Write(logLevel, "\tGLSL Version: {0}", openGLCapabilities.GLSLVersion.ToString()); Log.Write(logLevel, "\tExtensions supported:"); //Extensions überprüfen int extensionCount = GL.GetInteger(GetPName.NumExtensions); var extensions = new List <string>(); if (GL.GetError() == ErrorCode.NoError) { for (int i = 0; i < extensionCount; i++) { extensions.Add(GL.GetString(StringNameIndexed.Extensions, i)); } } else { var extensionString = GL.GetString(StringName.Extensions); extensions.AddRange(extensionString.Split(' ')); } foreach (var extension in extensions) { switch (extension) { case "GL_EXT_texture_compression_s3tc": openGLCapabilities.SupportsS3TextureCompression = true; Log.Write(logLevel, "\t\t" + "GL_EXT_texture_compression_s3tc"); break; case "GL_EXT_texture_filter_anisotropic": openGLCapabilities.SupportsAnisotropicFiltering = true; openGLCapabilities.MaxAnisotropicFiltering = (int)GL.GetFloat((GetPName)OpenTK.Graphics.OpenGL.ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt); Log.Write(logLevel, "\t\t" + "GL_EXT_texture_filter_anisotropic"); CheckGLError("Init GL_EXT_texture_filter_anisotropic"); break; case "GL_ARB_debug_output": openGLCapabilities.SupportsDebugOutput = true; if (CreationFlags.HasFlag(DeviceCreationFlags.Debug)) { onDebugMessage = new DebugProc(OnDebugMessage); GL.Enable(EnableCap.DebugOutput); GL.DebugMessageCallback(onDebugMessage, IntPtr.Zero); GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, new int[0], true); } Log.Write(logLevel, "\t\t" + "GL_ARB_debug_output"); CheckGLError("Init GL_ARB_debug_output"); break; case "GL_ARB_get_program_binary": capabilities.SupportsBinaryShaders = true; Log.Write(logLevel, "\t\t" + "GL_ARB_get_program_binary"); break; case "GL_ARB_texture_storage": openGLCapabilities.SupportsTextureStorage = true; Log.Write(logLevel, "\t\t" + "GL_ARB_texture_storage"); break; case "GL_ARB_buffer_storage": openGLCapabilities.SupportsBufferStorage = true; Log.Write(logLevel, "\t\t" + "GL_ARB_buffer_storage"); break; case "GL_ARB_invalidate_subdata": openGLCapabilities.SupportsResourceValidation = true; Log.Write(logLevel, "\t\t" + "GL_ARB_invalidate_subdata"); break; case "GL_EXT_direct_state_access": if (openGLCapabilities.DirectStateAccess == DirectStateAccess.None) { openGLCapabilities.DirectStateAccess = DirectStateAccess.Extension; } Log.Write(logLevel, "\t\t" + "GL_EXT_direct_state_access"); break; case "GL_ARB_direct_state_access": //openGLCapabilities.DirectStateAccess = DirectStateAccess.Core; Log.Write(logLevel, "\t\t" + "GL_ARB_direct_state_access"); break; case "GL_ARB_vertex_attrib_binding": openGLCapabilities.VertexAttribBinding = true; openGLCapabilities.MaxVertexAttribBindings = GL.GetInteger((GetPName)All.MaxVertexAttribBindings); openGLCapabilities.MaxVertexAttribBindingOffset = GL.GetInteger((GetPName)All.MaxVertexAttribRelativeOffset); openGLCapabilities.MaxVertexAttribStride = GL.GetInteger((GetPName)All.MaxVertexAttribStride); Log.Write(logLevel, "\t\t" + "GL_ARB_vertex_attrib_binding"); CheckGLError("Init GL_ARB_vertex_attrib_binding"); break; } } openGLCapabilities.TextureUnits = GL.GetInteger(GetPName.MaxCombinedTextureImageUnits); CheckGLError("Init MaxCombinedTextureImageUnits"); openGLCapabilities.MaxTextureLoDBias = GL.GetInteger(GetPName.MaxTextureLodBias); CheckGLError("Init MaxTextureLodBias"); openGLCapabilities.MaxTextureSize = GL.GetInteger(GetPName.MaxTextureSize); CheckGLError("Init MaxTextureSize"); openGLCapabilities.MaxVertexAttribs = GL.GetInteger(GetPName.MaxVertexAttribs); CheckGLError("Init MaxVertexAttribs"); openGLCapabilities.MaxUniformBlockSize = GL.GetInteger(GetPName.MaxUniformBlockSize); CheckGLError("Init MaxUniformBlockSize"); openGLCapabilities.MaxUniformBufferBindings = GL.GetInteger(GetPName.MaxUniformBufferBindings); CheckGLError("Init MaxUniformBufferBindings"); }
public static void Initialize() { // glGetError and glGetString are used in our error handlers // so we want these to be available early. openGLDebugDelegate = OpenGLDebugCallback; try { glGetError = Bind <GetError>("glGetError"); glGetStringInternal = Bind <GetString>("glGetString"); } catch (Exception) { throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available"); } DetectGLFeatures(); if (!Features.HasFlag(GLFeatures.GL2OrGreater) || !Features.HasFlag(GLFeatures.FramebufferExt)) { WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION)); throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details."); } else { Console.WriteLine("OpenGL version: " + glGetString(GL_VERSION)); } try { glDeleteProgram = Bind <DeleteProgramDelegate>("glDeleteProgram"); glDeleteShader = Bind <DeleteShaderDelegate>("glDeleteShader"); glDetachShader = Bind <DetachShaderDelegate>("glDetachShader"); glDebugMessageControl = Bind <glDebugMessageControlDelegate>("glDebugMessageControl"); glDebugMessageCallback = Bind <glDebugMessageCallbackDelegate>("glDebugMessageCallback"); glDebugMessageCallback(openGLDebugDelegate, IntPtr.Zero); glDebugMessageControl(DebugSourceControl.GL_DONT_CARE, DebugTypeControl.GL_DONT_CARE, DebugSeverityControl.GL_DEBUG_SEVERITY_LOW, 0, new uint[0], true); glGenVertexArrays = Bind <glGenVertexArraysDeleagte>("glGenVertexArrays"); glBindVertexArray = Bind <glBindVertexArrayDelegate>("glBindVertexArray"); glFlush = Bind <Flush>("glFlush"); glViewport = Bind <Viewport>("glViewport"); glClear = Bind <Clear>("glClear"); glClearColor = Bind <ClearColor>("glClearColor"); glGetIntegerv = Bind <GetIntegerv>("glGetIntegerv"); glFinish = Bind <Finish>("glFinish"); glCreateProgram = Bind <CreateProgram>("glCreateProgram"); glUseProgram = Bind <UseProgram>("glUseProgram"); glGetProgramiv = Bind <GetProgramiv>("glGetProgramiv"); glCreateShader = Bind <CreateShader>("glCreateShader"); glShaderSource = Bind <ShaderSource>("glShaderSource"); glCompileShader = Bind <CompileShader>("glCompileShader"); glGetShaderiv = Bind <GetShaderiv>("glGetShaderiv"); glAttachShader = Bind <AttachShader>("glAttachShader"); glGetShaderInfoLog = Bind <GetShaderInfoLog>("glGetShaderInfoLog"); glLinkProgram = Bind <LinkProgram>("glLinkProgram"); glGetProgramInfoLog = Bind <GetProgramInfoLog>("glGetProgramInfoLog"); glGetUniformLocation = Bind <GetUniformLocation>("glGetUniformLocation"); glGetActiveUniform = Bind <GetActiveUniform>("glGetActiveUniform"); glUniform1i = Bind <Uniform1i>("glUniform1i"); glUniform1f = Bind <Uniform1f>("glUniform1f"); glUniform2f = Bind <Uniform2f>("glUniform2f"); glUniform3f = Bind <Uniform3f>("glUniform3f"); glUniform1fv = Bind <Uniform1fv>("glUniform1fv"); glUniform2fv = Bind <Uniform2fv>("glUniform2fv"); glUniform3fv = Bind <Uniform3fv>("glUniform3fv"); glUniform4fv = Bind <Uniform4fv>("glUniform4fv"); glUniformMatrix4fv = Bind <UniformMatrix4fv>("glUniformMatrix4fv"); glGenBuffers = Bind <GenBuffers>("glGenBuffers"); glBindBuffer = Bind <BindBuffer>("glBindBuffer"); glBufferData = Bind <BufferData>("glBufferData"); glBufferSubData = Bind <BufferSubData>("glBufferSubData"); glDeleteBuffers = Bind <DeleteBuffers>("glDeleteBuffers"); glBindAttribLocation = Bind <BindAttribLocation>("glBindAttribLocation"); glVertexAttribPointer = Bind <VertexAttribPointer>("glVertexAttribPointer"); glEnableVertexAttribArray = Bind <EnableVertexAttribArray>("glEnableVertexAttribArray"); glDisableVertexAttribArray = Bind <DisableVertexAttribArray>("glDisableVertexAttribArray"); glDrawArrays = Bind <DrawArrays>("glDrawArrays"); glEnable = Bind <Enable>("glEnable"); glDisable = Bind <Disable>("glDisable"); glBlendEquation = Bind <BlendEquation>("glBlendEquation"); glBlendFunc = Bind <BlendFunc>("glBlendFunc"); glDepthFunc = Bind <DepthFunc>("glDepthFunc"); glScissor = Bind <Scissor>("glScissor"); glPushClientAttrib = Bind <PushClientAttrib>("glPushClientAttrib"); glPopClientAttrib = Bind <PopClientAttrib>("glPopClientAttrib"); glPixelStoref = Bind <PixelStoref>("glPixelStoref"); glReadPixels = Bind <ReadPixels>("glReadPixels"); glGenTextures = Bind <GenTextures>("glGenTextures"); glDeleteTextures = Bind <DeleteTextures>("glDeleteTextures"); glBindTexture = Bind <BindTexture>("glBindTexture"); glActiveTexture = Bind <ActiveTexture>("glActiveTexture"); glTexImage2D = Bind <TexImage2D>("glTexImage2D"); glTexSubImage3D = Bind <TexSubImage3D>("glTexSubImage3D"); glTexImage3D = Bind <TexImage3D>("glTexImage3D"); glGetTexImage = Bind <GetTexImage>("glGetTexImage"); glTexParameteri = Bind <TexParameteri>("glTexParameteri"); glTexParameterf = Bind <TexParameterf>("glTexParameterf"); glGenFramebuffers = Bind <GenFramebuffers>("glGenFramebuffersEXT"); glBindFramebuffer = Bind <BindFramebuffer>("glBindFramebufferEXT"); glFramebufferTexture2D = Bind <FramebufferTexture2D>("glFramebufferTexture2DEXT"); glDeleteFramebuffers = Bind <DeleteFramebuffers>("glDeleteFramebuffersEXT"); glGenRenderbuffers = Bind <GenRenderbuffers>("glGenRenderbuffersEXT"); glBindRenderbuffer = Bind <BindRenderbuffer>("glBindRenderbufferEXT"); glRenderbufferStorage = Bind <RenderbufferStorage>("glRenderbufferStorageEXT"); glDeleteRenderbuffers = Bind <DeleteRenderbuffers>("glDeleteRenderbuffersEXT"); glFramebufferRenderbuffer = Bind <FramebufferRenderbuffer>("glFramebufferRenderbufferEXT"); glCheckFramebufferStatus = Bind <CheckFramebufferStatus>("glCheckFramebufferStatusEXT"); } catch (Exception e) { WriteGraphicsLog("Failed to initialize OpenGL bindings.\nInner exception was: {0}".F(e)); throw new InvalidProgramException("Failed to initialize OpenGL. See graphics.log for details."); } glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
// TODO: 此函数的'try to remove unused items from rc2ProcDict'部分尚需检测。 /// <summary> /// 设置Debug模式的回调函数。 /// <para>此函数的'try to remove unused items from rc2ProcDict'部分尚需检测。</para> /// </summary> /// <param name="callback"></param> /// <param name="userParam">建议使用<see cref="UnmanagedArray.Header"/></param> public static void DebugMessageCallback(DebugProc callback, IntPtr userParam) { if (innerCallbackProc == null) { innerCallbackProc = new DEBUGPROC(innerCallback); } IntPtr renderContext = Win32.wglGetCurrentContext(); IntPtr deviceContext = Win32.wglGetCurrentDC(); if (rc2ProcDict.ContainsKey(renderContext)) { rc2ProcDict[renderContext] = callback; rc2dcDict[renderContext] = deviceContext; } else { rc2ProcDict.Add(renderContext, callback); rc2dcDict.Add(renderContext, deviceContext); debugProcDictCount++; // try to remove unused items from rc2ProcDict if (debugProcDictCount > maxDebugProcDictCount) { List<IntPtr> unusedRCList = new List<IntPtr>(); foreach (var item in rc2dcDict) { if (!Win32.wglMakeCurrent(item.Value, item.Key))// 这种检测方式可行吗? { unusedRCList.Add(item.Key); } } foreach (var item in unusedRCList) { rc2ProcDict.Remove(item); rc2dcDict.Remove(item); } debugProcDictCount -= unusedRCList.Count; maxDebugProcDictCount = debugProcDictCount + 100; Win32.wglMakeCurrent(renderContext, deviceContext); } } GetDelegateFor<glDebugMessageCallback>()(innerCallbackProc, userParam); }
public static void glDebugMessageCallback(DebugProc callback, void *userParam) => p_glDebugMessageCallback(callback, userParam);