Skip to content

Commit

Permalink
[GLFW] Use no error context only when indicated by debug config
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Dec 7, 2023
1 parent 1399341 commit cd91be4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Application/Aardvark.Application.Slim.GL/Application.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module private OpenGL =
open FSharp.Data.Adaptive

let mutable version = System.Version(3,3)
let mutable useNoError = false
let mutable supportsNoError = false

let private tryCreateOffscreenWindow (version : Version) (useNoError : bool) (glfw : Glfw) =
glfw.DefaultWindowHints()
Expand All @@ -50,13 +50,13 @@ module private OpenGL =
else
glfw.DestroyWindow w
true
let supportsNoError (version : Version) (glfw : Glfw) =

let queryNoErrorSupport (version : Version) (glfw : Glfw) =
if tryCreateOffscreenWindow version true glfw then
true
else
let error, _ = glfw.GetError()
Report.Line(2, "OpenGL does not support KHR_no_error: {0}", error)
Report.Line(2, $"OpenGL does not support KHR_no_error ({error})")
false

let initVersion (glfw : Glfw) =
Expand Down Expand Up @@ -90,7 +90,7 @@ module private OpenGL =
match best with
| Some b ->
version <- b
useNoError <- glfw |> supportsNoError b
supportsNoError <- glfw |> queryNoErrorSupport b
| None -> failwith "no compatible OpenGL version found"

type MyWindowInfo(win : nativeptr<WindowHandle>) =
Expand Down Expand Up @@ -292,7 +292,10 @@ module private OpenGL =
()
}

let interop =
let interop (debug : DebugConfig) =
let disableErrorChecks =
debug.ErrorFlagCheck = ErrorFlagCheck.Disabled

{ new IWindowInterop with
override __.Boot(glfw) =
initVersion glfw
Expand All @@ -307,7 +310,6 @@ module private OpenGL =
glfw.WindowHint(WindowHintInt.DepthBits, 24)
glfw.WindowHint(WindowHintInt.StencilBits, 8)


let m = glfw.GetPrimaryMonitor()
let mode = glfw.GetVideoMode(m) |> NativePtr.read
glfw.WindowHint(WindowHintInt.RedBits, 8)
Expand All @@ -320,7 +322,7 @@ module private OpenGL =
glfw.WindowHint(WindowHintBool.OpenGLForwardCompat, true)
glfw.WindowHint(WindowHintBool.DoubleBuffer, true)
glfw.WindowHint(WindowHintBool.OpenGLDebugContext, false)
if useNoError then glfw.WindowHint(WindowHintBool.ContextNoError, true)
glfw.WindowHint(WindowHintBool.ContextNoError, disableErrorChecks && supportsNoError)
glfw.WindowHint(WindowHintBool.SrgbCapable, false)
if RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then
glfw.WindowHint(WindowHintBool.CocoaRetinaFramebuffer, cfg.physicalSize)
Expand All @@ -330,7 +332,7 @@ module private OpenGL =
}

type OpenGlApplication private (runtime : Runtime, shaderCachePath : Option<string>, hideCocoaMenuBar : bool) as this =
inherit Application(runtime, OpenGL.interop, hideCocoaMenuBar)
inherit Application(runtime, OpenGL.interop runtime.DebugConfig, hideCocoaMenuBar)

let createContext() =
let w = this.Instance.CreateWindow WindowConfig.Default
Expand Down

0 comments on commit cd91be4

Please sign in to comment.