Skip to content

Commit

Permalink
[OpenVR] changed GL texture submit to 2 textures (previously side by …
Browse files Browse the repository at this point in the history
…side, issue with Quest 3)
  • Loading branch information
aszabo314 committed May 7, 2024
1 parent bf11308 commit b647753
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 70 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
@@ -1,3 +1,6 @@
### 5.4.10
- [OpenVR] changed GL texture submit to 2 textures (previously side by side, issue with Quest 3)

### 5.4.9
- [LodRenderer] Handle exceptions in background threads
- [GL] Implemented GLSL shader caches for platforms that do not support program binaries (e.g. MacOS)
Expand Down
28 changes: 17 additions & 11 deletions src/Application/Aardvark.Application.OpenVR.GL/Application.fs
Expand Up @@ -66,7 +66,8 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize
let mutable cTex = Unchecked.defaultof<Texture>
let mutable fbo = Unchecked.defaultof<IFramebuffer>
let mutable info = Unchecked.defaultof<VrRenderInfo>
let mutable fTex = Unchecked.defaultof<Texture>
let mutable fTexl = Unchecked.defaultof<Texture>
let mutable fTexr = Unchecked.defaultof<Texture>

let start = System.DateTime.Now
let sw = System.Diagnostics.Stopwatch.StartNew()
Expand All @@ -93,7 +94,7 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize
let caller = DummyObject()

let version = AVal.init 0
let tex = AVal.custom (fun _ -> fTex :> ITexture)
let tex = AVal.custom (fun _ -> fTexl :> ITexture)

let keyboard = new EventKeyboard()
let mouse = new EventMouse(false)
Expand Down Expand Up @@ -150,7 +151,8 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize
override x.Use(f : unit -> 'a) =
Operators.using ctx.ResourceLock (fun _ -> f())

override x.Handedness with get() = Trafo3d.FromBasis(V3d.IOO, -V3d.OOI, -V3d.OIO, V3d.Zero)
//override x.Handedness
// with get() = Trafo3d.FromBasis(V3d.IOO, -V3d.OOI, -V3d.OIO, V3d.Zero)

override x.OnLoad(i : VrRenderInfo) =
//renderCtx.MakeCurrent()
Expand All @@ -161,7 +163,8 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize

if loaded then
ctx.Delete (unbox<Framebuffer> fbo)
ctx.Delete fTex
ctx.Delete fTexl
ctx.Delete fTexr
ctx.Delete dTex
ctx.Delete cTex
else
Expand All @@ -171,7 +174,8 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize

let nTex = ctx.CreateTexture2DArray(info.framebufferSize, 2, 1, TextureFormat.Rgba8, samples)
let nDepth = ctx.CreateTexture2DArray(info.framebufferSize, 2, 1, TextureFormat.Depth24Stencil8, samples)
let nfTex = ctx.CreateTexture2D(info.framebufferSize * V2i(2,1), 1, TextureFormat.Rgba8, 1)
let nfTexl = ctx.CreateTexture2D(info.framebufferSize, 1, TextureFormat.Rgba8, 1)
let nfTexr = ctx.CreateTexture2D(info.framebufferSize, 1, TextureFormat.Rgba8, 1)

let nFbo =
runtime.CreateFramebuffer(
Expand All @@ -186,12 +190,13 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize

dTex <- nDepth
cTex <- nTex
fTex <- nfTex
fTexl <- nfTexl
fTexr <- nfTexr
fbo <- nFbo


let lTex = VrTexture.OpenGL(fTex.Handle, Box2d(V2d(0.0, 1.0), V2d(0.5, 0.0)))
let rTex = VrTexture.OpenGL(fTex.Handle, Box2d(V2d(0.5, 1.0), V2d(1.0, 0.0)))
let lTex = VrTexture.OpenGL(fTexl.Handle)
let rTex = VrTexture.OpenGL(fTexr.Handle)
loaded <- true


Expand All @@ -213,8 +218,8 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize
GL.Sync()

if samples > 1 then
runtime.ResolveMultisamples(cTex.[TextureAspect.Color, 0, 0], fTex, V2i.Zero, V2i.Zero, cTex.Size.XY)
runtime.ResolveMultisamples(cTex.[TextureAspect.Color, 0, 1], fTex, V2i.Zero, V2i(cTex.Size.X, 0), cTex.Size.XY)
runtime.ResolveMultisamples(cTex.[TextureAspect.Color, 0, 0], fTexl, V2i.Zero, V2i.Zero, cTex.Size.XY)
runtime.ResolveMultisamples(cTex.[TextureAspect.Color, 0, 1], fTexr, V2i.Zero, V2i.Zero, cTex.Size.XY)
else
failwith "not implemented"
//runtime.Copy(cTex.[TextureAspect.Color, 0, *], fTex.[TextureAspect.Color, 0, *])
Expand All @@ -236,7 +241,8 @@ type OpenGlVRApplicationLayered(samples : int, debug : IDebugConfig, adjustSize
ctx.Delete (unbox<Framebuffer> fbo)
ctx.Delete dTex
ctx.Delete cTex
ctx.Delete fTex
ctx.Delete fTexl
ctx.Delete fTexr

app.Dispose()

Expand Down
95 changes: 36 additions & 59 deletions src/Application/Aardvark.Application.Utilities/Window.fs
Expand Up @@ -607,66 +607,43 @@ module Utilities =
res

let private createOpenVR (cfg : RenderConfig) =
match cfg.backend with
| Backend.Vulkan ->
let app = new VulkanVRApplicationLayered(cfg.samples, cfg.debug)
let hmdLocation = app.Hmd.MotionState.Pose |> AVal.map (fun t -> t.Forward.C3.XYZ)


let stencilTest =
{ StencilMode.None with
Comparison = ComparisonFunction.Equal }

{ new SimpleRenderWindow(app, app.Info.viewTrafos, app.Info.projTrafos) with

override x.WrapSg(win, sg) =
sg
|> Sg.stencilMode' stencilTest
|> Sg.uniform "ViewTrafo" app.Info.viewTrafos
|> Sg.uniform "ProjTrafo" app.Info.projTrafos
|> Sg.uniform "CameraLocation" hmdLocation
|> Sg.uniform "LightLocation" hmdLocation

override x.Compile(win, sg) =
sg
|> Sg.stencilMode' stencilTest
|> Sg.uniform "ViewTrafo" app.Info.viewTrafos
|> Sg.uniform "ProjTrafo" app.Info.projTrafos
|> Sg.uniform "CameraLocation" hmdLocation
|> Sg.uniform "LightLocation" hmdLocation
|> Sg.compile app.Runtime app.FramebufferSignature
} :> ISimpleRenderWindow
let app =
match cfg.backend with
| Backend.Vulkan ->
let app = new VulkanVRApplicationLayered(cfg.samples, cfg.debug)
app :> VrRenderer
| Backend.GL ->
let app = new OpenGlVRApplicationLayered(cfg.samples, cfg.debug)
app :> VrRenderer

let hmdLocation = app.Hmd.MotionState.Pose |> AVal.map (fun t -> t.Forward.C3.XYZ)

let stencilTest =
{ StencilMode.None with
Comparison = ComparisonFunction.Equal }


let app1 = unbox<IRenderWindow> app
{ new SimpleRenderWindow(app1, app.Info.viewTrafos, app.Info.projTrafos) with

override x.WrapSg(win, sg) =
sg
|> Sg.stencilMode' stencilTest
|> Sg.uniform "ViewTrafo" app.Info.viewTrafos
|> Sg.uniform "ProjTrafo" app.Info.projTrafos
|> Sg.uniform "CameraLocation" hmdLocation
|> Sg.uniform "LightLocation" hmdLocation

override x.Compile(win, sg) =
sg
|> Sg.stencilMode' stencilTest
|> Sg.uniform "ViewTrafo" app.Info.viewTrafos
|> Sg.uniform "ProjTrafo" app.Info.projTrafos
|> Sg.uniform "CameraLocation" hmdLocation
|> Sg.uniform "LightLocation" hmdLocation
|> Sg.compile app1.Runtime app1.FramebufferSignature
} :> ISimpleRenderWindow

| Backend.GL ->
let app = new OpenGlVRApplicationLayered(cfg.samples, cfg.debug)

let hmdLocation = app.Hmd.MotionState.Pose |> AVal.map (fun t -> t.Forward.C3.XYZ)


let stencilTest =
{ StencilMode.None with
Comparison = ComparisonFunction.Equal }

{ new SimpleRenderWindow(app, app.Info.viewTrafos, app.Info.projTrafos) with

override x.WrapSg(win, sg) =
sg
|> Sg.stencilMode' stencilTest
|> Sg.uniform "ViewTrafo" app.Info.viewTrafos
|> Sg.uniform "ProjTrafo" app.Info.projTrafos
|> Sg.uniform "CameraLocation" hmdLocation
|> Sg.uniform "LightLocation" hmdLocation

override x.Compile(win, sg) =
sg
|> Sg.stencilMode' stencilTest
|> Sg.uniform "ViewTrafo" app.Info.viewTrafos
|> Sg.uniform "ProjTrafo" app.Info.projTrafos
|> Sg.uniform "CameraLocation" hmdLocation
|> Sg.uniform "LightLocation" hmdLocation
|> Sg.compile app.Runtime app.FramebufferSignature
} :> ISimpleRenderWindow



let createWindow (cfg : RenderConfig) =
Expand Down

0 comments on commit b647753

Please sign in to comment.