mirror of https://github.com/bjornbytes/lovr.git
t.headset.supersample;
Can be used to change the size of the headset texture that gets submitted to the VR runtime. It can be a boolean or a number.
This commit is contained in:
parent
b864f74be1
commit
caca0ef71c
|
@ -104,6 +104,7 @@ static int l_lovrHeadsetInit(lua_State* L) {
|
|||
|
||||
size_t driverCount = 0;
|
||||
HeadsetDriver drivers[8];
|
||||
float supersample = 1.f;
|
||||
float offset = 1.7f;
|
||||
int msaa = 4;
|
||||
|
||||
|
@ -120,6 +121,15 @@ static int l_lovrHeadsetInit(lua_State* L) {
|
|||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Supersample
|
||||
lua_getfield(L, -1, "supersample");
|
||||
if (lua_type(L, -1) == LUA_TBOOLEAN) {
|
||||
supersample = lua_toboolean(L, -1) ? 2.f : 1.f;
|
||||
} else {
|
||||
supersample = luax_optfloat(L, -1, 1.f);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Offset
|
||||
lua_getfield(L, -1, "offset");
|
||||
offset = luax_optfloat(L, -1, 1.7f);
|
||||
|
@ -131,7 +141,7 @@ static int l_lovrHeadsetInit(lua_State* L) {
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
if (lovrHeadsetInit(drivers, driverCount, offset, msaa)) {
|
||||
if (lovrHeadsetInit(drivers, driverCount, supersample, offset, msaa)) {
|
||||
luax_atexit(L, lovrHeadsetDestroy);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ HeadsetInterface* lovrHeadsetDriver = NULL;
|
|||
HeadsetInterface* lovrHeadsetTrackingDrivers = NULL;
|
||||
static bool initialized = false;
|
||||
|
||||
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float offset, uint32_t msaa) {
|
||||
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float supersample, float offset, uint32_t msaa) {
|
||||
if (initialized) return false;
|
||||
initialized = true;
|
||||
|
||||
|
@ -42,7 +42,7 @@ bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float offset, uint32_
|
|||
bool hasDisplay = interface->renderTo != NULL;
|
||||
bool shouldInitialize = !hasDisplay || !lovrHeadsetDriver;
|
||||
|
||||
if (shouldInitialize && interface->init(offset, msaa)) {
|
||||
if (shouldInitialize && interface->init(supersample, offset, msaa)) {
|
||||
if (hasDisplay) {
|
||||
lovrHeadsetDriver = interface;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ typedef enum {
|
|||
typedef struct HeadsetInterface {
|
||||
struct HeadsetInterface* next;
|
||||
HeadsetDriver driverType;
|
||||
bool (*init)(float offset, uint32_t msaa);
|
||||
bool (*init)(float supersample, float offset, uint32_t msaa);
|
||||
void (*destroy)(void);
|
||||
bool (*getName)(char* name, size_t length);
|
||||
HeadsetOrigin (*getOriginType)(void);
|
||||
|
@ -145,5 +145,5 @@ extern HeadsetInterface* lovrHeadsetTrackingDrivers;
|
|||
#define FOREACH_TRACKING_DRIVER(i)\
|
||||
for (HeadsetInterface* i = lovrHeadsetTrackingDrivers; i != NULL; i = i->next)
|
||||
|
||||
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float offset, uint32_t msaa);
|
||||
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float supersample, float offset, uint32_t msaa);
|
||||
void lovrHeadsetDestroy(void);
|
||||
|
|
|
@ -34,7 +34,7 @@ static struct {
|
|||
float yaw;
|
||||
} state;
|
||||
|
||||
static bool desktop_init(float offset, uint32_t msaa) {
|
||||
static bool desktop_init(float supersample, float offset, uint32_t msaa) {
|
||||
state.offset = offset;
|
||||
state.clipNear = .1f;
|
||||
state.clipFar = 100.f;
|
||||
|
|
|
@ -24,6 +24,7 @@ static struct {
|
|||
float clipFar;
|
||||
ovrSizei size;
|
||||
Canvas* canvas;
|
||||
float supersample;
|
||||
ovrTextureSwapChain chain;
|
||||
ovrMirrorTexture mirror;
|
||||
float hapticFrequency[2];
|
||||
|
@ -83,7 +84,7 @@ static ovrInputState *refreshButtons(void) {
|
|||
return &is;
|
||||
}
|
||||
|
||||
static bool oculus_init(float offset, uint32_t msaa) {
|
||||
static bool oculus_init(float supersample, float offset, uint32_t msaa) {
|
||||
ovrResult result = ovr_Initialize(NULL);
|
||||
if (OVR_FAILURE(result)) {
|
||||
return false;
|
||||
|
@ -101,6 +102,7 @@ static bool oculus_init(float offset, uint32_t msaa) {
|
|||
state.needRefreshButtons = true;
|
||||
state.clipNear = .1f;
|
||||
state.clipFar = 100.f;
|
||||
state.supersample = supersample;
|
||||
|
||||
map_init(&state.textureLookup, 4);
|
||||
|
||||
|
@ -325,6 +327,8 @@ static ModelData* oculus_newModelData(Device device, bool animated) {
|
|||
static void oculus_renderTo(void (*callback)(void*), void* userdata) {
|
||||
if (!state.canvas) {
|
||||
state.size = ovr_GetFovTextureSize(state.session, ovrEye_Left, state.desc.DefaultEyeFov[ovrEye_Left], 1.0f);
|
||||
state.size.w *= state.supersample;
|
||||
state.size.h *= state.supersample;
|
||||
|
||||
ovrTextureSwapChainDesc swdesc = {
|
||||
.Type = ovrTexture_2D,
|
||||
|
|
|
@ -83,6 +83,7 @@ static struct {
|
|||
float boundsGeometry[16];
|
||||
float clipNear;
|
||||
float clipFar;
|
||||
float supersample;
|
||||
float offset;
|
||||
int msaa;
|
||||
} state;
|
||||
|
@ -97,7 +98,7 @@ static TrackedDeviceIndex_t getDeviceIndex(Device device) {
|
|||
}
|
||||
|
||||
static bool openvr_getName(char* name, size_t length);
|
||||
static bool openvr_init(float offset, uint32_t msaa) {
|
||||
static bool openvr_init(float supersample, float offset, uint32_t msaa) {
|
||||
if (!VR_IsHmdPresent() || !VR_IsRuntimeInstalled()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -207,6 +208,7 @@ static bool openvr_init(float offset, uint32_t msaa) {
|
|||
|
||||
state.clipNear = 0.1f;
|
||||
state.clipFar = 100.f;
|
||||
state.supersample = supersample;
|
||||
state.offset = state.compositor->GetTrackingSpace() == ETrackingUniverseOrigin_TrackingUniverseStanding ? 0. : offset;
|
||||
state.msaa = msaa;
|
||||
|
||||
|
@ -762,6 +764,8 @@ static void openvr_renderTo(void (*callback)(void*), void* userdata) {
|
|||
if (!state.canvas) {
|
||||
uint32_t width, height;
|
||||
openvr_getDisplayDimensions(&width, &height);
|
||||
width *= state.supersample;
|
||||
height *= state.supersample;
|
||||
CanvasFlags flags = { .depth = { true, false, FORMAT_D24S8 }, .stereo = true, .mipmaps = true, .msaa = state.msaa };
|
||||
state.canvas = lovrCanvasCreate(width, height, flags);
|
||||
Texture* texture = lovrTextureCreate(TEXTURE_2D, NULL, 0, true, true, state.msaa);
|
||||
|
|
|
@ -146,7 +146,7 @@ static bool hasExtension(XrExtensionProperties* extensions, uint32_t count, cons
|
|||
|
||||
static void openxr_destroy();
|
||||
|
||||
static bool openxr_init(float offset, uint32_t msaa) {
|
||||
static bool openxr_init(float supersample, float offset, uint32_t msaa) {
|
||||
state.msaa = msaa;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
@ -254,8 +254,8 @@ static bool openxr_init(float offset, uint32_t msaa) {
|
|||
return false;
|
||||
}
|
||||
|
||||
state.width = views[0].recommendedImageRectWidth;
|
||||
state.height = views[0].recommendedImageRectHeight;
|
||||
state.width = MIN(views[0].recommendedImageRectWidth * supersample, views[0].maxImageRectWidth);
|
||||
state.height = MIN(views[0].recommendedImageRectHeight * supersample, views[0].maxImageRectHeight);
|
||||
}
|
||||
|
||||
{ // Actions
|
||||
|
|
|
@ -226,7 +226,7 @@ static struct {
|
|||
void* renderUserdata;
|
||||
} state;
|
||||
|
||||
static bool pico_init(float offset, uint32_t msaa) {
|
||||
static bool pico_init(float supersample, float offset, uint32_t msaa) {
|
||||
state.offset = offset;
|
||||
state.clipNear = .1f;
|
||||
state.clipFar = 100.f;
|
||||
|
|
|
@ -37,6 +37,7 @@ static struct {
|
|||
ovrDeviceType deviceType;
|
||||
uint64_t frameIndex;
|
||||
double displayTime;
|
||||
float supersample;
|
||||
float offset;
|
||||
uint32_t msaa;
|
||||
ovrVector3f* rawBoundaryPoints;
|
||||
|
@ -56,12 +57,13 @@ static struct {
|
|||
float hapticDuration[2];
|
||||
} state;
|
||||
|
||||
static bool vrapi_init(float offset, uint32_t msaa) {
|
||||
static bool vrapi_init(float supersample, float offset, uint32_t msaa) {
|
||||
ANativeActivity* activity = lovrPlatformGetActivity();
|
||||
JNIEnv* jni = lovrPlatformGetJNI();
|
||||
state.java.Vm = activity->vm;
|
||||
state.java.ActivityObject = activity->clazz;
|
||||
state.java.Env = jni;
|
||||
state.supersample = supersample;
|
||||
state.offset = offset;
|
||||
state.msaa = msaa;
|
||||
const ovrInitParms config = vrapi_DefaultInitParms(&state.java);
|
||||
|
@ -641,6 +643,8 @@ static void vrapi_renderTo(void (*callback)(void*), void* userdata) {
|
|||
|
||||
uint32_t width, height;
|
||||
vrapi_getDisplayDimensions(&width, &height);
|
||||
width *= state.supersample;
|
||||
height *= state.supersample;
|
||||
state.swapchain = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D_ARRAY, GL_SRGB8_ALPHA8, width, height, 1, 3);
|
||||
state.swapchainLength = vrapi_GetTextureSwapChainLength(state.swapchain);
|
||||
lovrAssert(state.swapchainLength <= sizeof(state.canvases) / sizeof(state.canvases[0]), "VrApi: The swapchain is too long");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "headset/headset.h"
|
||||
|
||||
extern bool webxr_init(float offset, uint32_t msaa);
|
||||
extern bool webxr_init(float supersample, float offset, uint32_t msaa);
|
||||
extern void webxr_destroy(void);
|
||||
extern bool webxr_getName(char* name, size_t length);
|
||||
extern HeadsetOrigin webxr_getOriginType(void);
|
||||
|
|
|
@ -2,6 +2,7 @@ lovr = require 'lovr'
|
|||
|
||||
local function nogame()
|
||||
function lovr.conf(t)
|
||||
t.headset.supersample = true
|
||||
t.modules.audio = false
|
||||
t.modules.math = false
|
||||
t.modules.physics = false
|
||||
|
@ -106,6 +107,7 @@ function lovr.boot()
|
|||
},
|
||||
headset = {
|
||||
drivers = { 'openxr', 'oculus', 'vrapi', 'pico', 'openvr', 'webxr', 'desktop' },
|
||||
supersample = false,
|
||||
offset = 1.7,
|
||||
msaa = 4
|
||||
},
|
||||
|
|
|
@ -48,7 +48,7 @@ var webxr = {
|
|||
},
|
||||
|
||||
webxr_init__deps: ['$buttons', '$axes'],
|
||||
webxr_init: function(offset, msaa) {
|
||||
webxr_init: function(supersample, offset, msaa) {
|
||||
if (!navigator.xr) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue