4
4
#include " WebXRProviderContext.h"
5
5
#include < cmath>
6
6
#include < vector>
7
- #include < stdio.h>
8
7
9
8
#define SIDE_BY_SIDE 1
10
9
#define NUM_RENDER_PASSES 2
@@ -40,7 +39,6 @@ class WebXRDisplayProvider : ProviderImpl
40
39
UnitySubsystemErrorCode GfxThread_Stop ();
41
40
UnitySubsystemErrorCode GfxThread_FinalBlitToGameViewBackBuffer (const UnityXRMirrorViewBlitInfo* mirrorBlitInfo, WebXRProviderContext& ctx);
42
41
43
- UnitySubsystemErrorCode QueryMirrorViewBlitDesc (const UnityXRMirrorViewBlitInfo* mirrorRtDesc, UnityXRMirrorViewBlitDesc* blitDescriptor, WebXRProviderContext& ctx);
44
42
UnitySubsystemErrorCode UpdateDisplayState (UnityXRDisplayState* state);
45
43
46
44
void Stop () override ;
@@ -54,9 +52,7 @@ class WebXRDisplayProvider : ProviderImpl
54
52
UnityXRProjection GetProjection (int pass);
55
53
56
54
private:
57
- // std::vector<void*> m_NativeTextures;
58
55
std::vector<UnityXRRenderTextureId> m_UnityTextures;
59
- std::vector<UnityXRVector2> m_UnityTexturesSizes;
60
56
float *m_ViewsDataArray;
61
57
float viewWidth;
62
58
float viewHeight;
@@ -78,7 +74,6 @@ UnitySubsystemErrorCode WebXRDisplayProvider::Start()
78
74
viewHeight = *(m_ViewsDataArray + 47 );
79
75
frameBufferWidth = *(m_ViewsDataArray + 56 );
80
76
frameBufferHeight = *(m_ViewsDataArray + 57 );
81
- printf (" Start %f, %f\n " , frameBufferWidth, frameBufferHeight);
82
77
hasMultipleViews = *(m_ViewsDataArray + 54 ) > 1 ;
83
78
if (hasMultipleViews)
84
79
{
@@ -278,9 +273,7 @@ void WebXRDisplayProvider::CreateTextures(int numTextures, int textureArrayLengt
278
273
const int texWidth = (int )(SIDE_BY_SIDE ? frameBufferWidth : viewWidth);
279
274
const int texHeight = (int )(SIDE_BY_SIDE ? frameBufferHeight : viewHeight);
280
275
281
- // m_NativeTextures.resize(numTextures);
282
276
m_UnityTextures.resize (numTextures);
283
- m_UnityTexturesSizes.resize (numTextures);
284
277
285
278
// Tell unity about the native textures, getting back UnityXRRenderTextureIds.
286
279
for (int i = 0 ; i < numTextures; ++i)
@@ -295,14 +288,11 @@ void WebXRDisplayProvider::CreateTextures(int numTextures, int textureArrayLengt
295
288
296
289
// Create an UnityXRRenderTextureId for the native texture so we can tell unity to render to it later.
297
290
UnityXRRenderTextureId uTexId;
298
- printf (" CreateTexture\n " );
299
291
m_Ctx.display ->CreateTexture (m_Handle, &uDesc, &uTexId);
300
292
UnityXRVector2 size;
301
293
size.x = texWidth;
302
294
size.x = texHeight;
303
295
m_UnityTextures[i] = uTexId;
304
- m_UnityTexturesSizes[i] = size;
305
- printf (" uTexId %d\n " , uTexId);
306
296
}
307
297
}
308
298
@@ -317,8 +307,6 @@ void WebXRDisplayProvider::DestroyTextures()
317
307
}
318
308
319
309
m_UnityTextures.clear ();
320
- m_UnityTexturesSizes.clear ();
321
- // m_NativeTextures.clear();
322
310
}
323
311
324
312
UnityXRPose WebXRDisplayProvider::GetPose (int pass)
@@ -351,63 +339,14 @@ UnityXRProjection WebXRDisplayProvider::GetProjection(int pass)
351
339
ret.data .matrix .columns [2 ].x = *(m_ViewsDataArray + start + 8 );
352
340
ret.data .matrix .columns [2 ].y = *(m_ViewsDataArray + start + 9 );
353
341
ret.data .matrix .columns [2 ].z = *(m_ViewsDataArray + start + 10 );
354
- ret.data .matrix .columns [2 ].w = *(m_ViewsDataArray + start + 11 ); // should replace with 14?
342
+ ret.data .matrix .columns [2 ].w = *(m_ViewsDataArray + start + 11 );
355
343
ret.data .matrix .columns [3 ].x = *(m_ViewsDataArray + start + 12 );
356
344
ret.data .matrix .columns [3 ].y = *(m_ViewsDataArray + start + 13 );
357
- ret.data .matrix .columns [3 ].z = *(m_ViewsDataArray + start + 14 ); // should replace with 11?
345
+ ret.data .matrix .columns [3 ].z = *(m_ViewsDataArray + start + 14 );
358
346
ret.data .matrix .columns [3 ].w = *(m_ViewsDataArray + start + 15 );
359
347
return ret;
360
348
}
361
349
362
- UnitySubsystemErrorCode WebXRDisplayProvider::QueryMirrorViewBlitDesc (const UnityXRMirrorViewBlitInfo* mirrorBlitInfo, UnityXRMirrorViewBlitDesc* blitDescriptor, WebXRProviderContext& ctx)
363
- {
364
- if (ctx.displayProvider ->m_UnityTextures .size () == 0 )
365
- {
366
- // Eye texture is not available yet, return failure
367
- return UnitySubsystemErrorCode::kUnitySubsystemErrorCodeFailure ;
368
- }
369
- int srcTexId = ctx.displayProvider ->m_UnityTextures [0 ];
370
- const UnityXRVector2 sourceTextureSize = {static_cast <float >(m_UnityTexturesSizes[0 ].x ), static_cast <float >(m_UnityTexturesSizes[0 ].y )};
371
- const UnityXRRectf sourceUVRect = {0 .0f , 0 .0f , 1 .0f , 1 .0f };
372
- const UnityXRVector2 destTextureSize = {static_cast <float >(mirrorBlitInfo->mirrorRtDesc ->rtScaledWidth ), static_cast <float >(mirrorBlitInfo->mirrorRtDesc ->rtScaledHeight )};
373
- const UnityXRRectf destUVRect = {0 .0f , 0 .0f , 1 .0f , 1 .0f };
374
-
375
- // By default, The source rect will be adjust so that it matches the dest rect aspect ratio.
376
- // This has the visual effect of expanding the source image, resulting in cropping
377
- // along the non-fitting axis. In this mode, the destination rect will be completely
378
- // filled, but not all the source image may be visible.
379
- UnityXRVector2 sourceUV0, sourceUV1, destUV0, destUV1;
380
-
381
- float sourceAspect = (sourceTextureSize.x * sourceUVRect.width ) / (sourceTextureSize.y * sourceUVRect.height );
382
- float destAspect = (destTextureSize.x * destUVRect.width ) / (destTextureSize.y * destUVRect.height );
383
- float ratio = sourceAspect / destAspect;
384
- UnityXRVector2 sourceUVCenter = {sourceUVRect.x + sourceUVRect.width * 0 .5f , sourceUVRect.y + sourceUVRect.height * 0 .5f };
385
- UnityXRVector2 sourceUVSize = {sourceUVRect.width , sourceUVRect.height };
386
- UnityXRVector2 destUVCenter = {destUVRect.x + destUVRect.width * 0 .5f , destUVRect.y + destUVRect.height * 0 .5f };
387
- UnityXRVector2 destUVSize = {destUVRect.width , destUVRect.height };
388
-
389
- if (ratio > 1 .0f )
390
- {
391
- sourceUVSize.x /= ratio;
392
- }
393
- else
394
- {
395
- sourceUVSize.y *= ratio;
396
- }
397
-
398
- sourceUV0 = {sourceUVCenter.x - (sourceUVSize.x * 0 .5f ), sourceUVCenter.y - (sourceUVSize.y * 0 .5f )};
399
- sourceUV1 = {sourceUV0.x + sourceUVSize.x , sourceUV0.y + sourceUVSize.y };
400
- destUV0 = {destUVCenter.x - destUVSize.x * 0 .5f , destUVCenter.y - destUVSize.y * 0 .5f };
401
- destUV1 = {destUV0.x + destUVSize.x , destUV0.y + destUVSize.y };
402
-
403
- (*blitDescriptor).blitParamsCount = 1 ;
404
- (*blitDescriptor).blitParams [0 ].srcTexId = srcTexId;
405
- (*blitDescriptor).blitParams [0 ].srcTexArraySlice = 0 ;
406
- (*blitDescriptor).blitParams [0 ].srcRect = {sourceUV0.x , sourceUV0.y , sourceUV1.x - sourceUV0.x , sourceUV1.y - sourceUV0.y };
407
- (*blitDescriptor).blitParams [0 ].destRect = {destUV0.x , destUV0.y , destUV1.x - destUV0.x , destUV1.y - destUV0.y };
408
- return kUnitySubsystemErrorCodeSuccess ;
409
- }
410
-
411
350
UnitySubsystemErrorCode WebXRDisplayProvider::UpdateDisplayState (UnityXRDisplayState * state)
412
351
{
413
352
state->displayIsTransparent = transparentBackground;
@@ -454,10 +393,6 @@ static UnitySubsystemErrorCode UNITY_INTERFACE_API Display_Initialize(UnitySubsy
454
393
ctx.display ->RegisterProviderForGraphicsThread (handle, &gfxThreadProvider);
455
394
456
395
UnityXRDisplayProvider provider{&ctx, NULL , NULL };
457
- // provider.QueryMirrorViewBlitDesc = [](UnitySubsystemHandle handle, void* userData, const UnityXRMirrorViewBlitInfo mirrorBlitInfo, UnityXRMirrorViewBlitDesc* blitDescriptor) -> UnitySubsystemErrorCode {
458
- // auto& ctx = GetWebXRProviderContext(userData);
459
- // return ctx.displayProvider->QueryMirrorViewBlitDesc(&mirrorBlitInfo, blitDescriptor, ctx);
460
- // };
461
396
462
397
provider.UpdateDisplayState = [](UnitySubsystemHandle handle, void * userData, UnityXRDisplayState* state) -> UnitySubsystemErrorCode {
463
398
auto & ctx = GetWebXRProviderContext (userData);
0 commit comments