mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 21:43:34 +00:00
Start Layers;
This commit is contained in:
parent
2f8d9aa6dc
commit
72aac1c58a
|
@ -495,8 +495,9 @@ endif()
|
||||||
|
|
||||||
if(LOVR_ENABLE_HEADSET)
|
if(LOVR_ENABLE_HEADSET)
|
||||||
target_sources(lovr PRIVATE
|
target_sources(lovr PRIVATE
|
||||||
src/api/l_headset.c
|
|
||||||
src/modules/headset/headset.c
|
src/modules/headset/headset.c
|
||||||
|
src/api/l_headset.c
|
||||||
|
src/api/l_headset_layer.c
|
||||||
)
|
)
|
||||||
|
|
||||||
if(LOVR_USE_OPENXR)
|
if(LOVR_USE_OPENXR)
|
||||||
|
|
|
@ -581,6 +581,40 @@ static int l_lovrHeadsetAnimate(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_lovrHeadsetNewLayer(lua_State* L) {
|
||||||
|
uint32_t width = luax_checku32(L, 1);
|
||||||
|
uint32_t height = luax_checku32(L, 2);
|
||||||
|
Layer* layer = lovrHeadsetInterface->newLayer(width, height);
|
||||||
|
luax_pushtype(L, Layer, layer);
|
||||||
|
lovrRelease(layer, lovrHeadsetInterface->destroyLayer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_lovrHeadsetGetLayers(lua_State* L) {
|
||||||
|
uint32_t count;
|
||||||
|
Layer** layers = lovrHeadsetInterface->getLayers(&count);
|
||||||
|
lua_createtable(L, (int) count, 0);
|
||||||
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
|
luax_pushtype(L, Layer, layers[i]);
|
||||||
|
lua_rawseti(L, -2, (int) i + 1);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_lovrHeadsetSetLayers(lua_State* L) {
|
||||||
|
Layer* layers[MAX_LAYERS];
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
uint32_t count = luax_len(L, 1);
|
||||||
|
lovrCheck(count <= MAX_LAYERS, "Too many layers (max is %d)", MAX_LAYERS);
|
||||||
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
|
lua_rawgeti(L, 1, (int) i + 1);
|
||||||
|
layers[i] = luax_checktype(L, -1, Layer);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
lovrHeadsetInterface->setLayers(layers, count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_lovrHeadsetGetTexture(lua_State* L) {
|
static int l_lovrHeadsetGetTexture(lua_State* L) {
|
||||||
Texture* texture = lovrHeadsetInterface->getTexture();
|
Texture* texture = lovrHeadsetInterface->getTexture();
|
||||||
luax_pushtype(L, Texture, texture);
|
luax_pushtype(L, Texture, texture);
|
||||||
|
@ -690,6 +724,9 @@ static const luaL_Reg lovrHeadset[] = {
|
||||||
{ "stopVibration", l_lovrHeadsetStopVibration },
|
{ "stopVibration", l_lovrHeadsetStopVibration },
|
||||||
{ "newModel", l_lovrHeadsetNewModel },
|
{ "newModel", l_lovrHeadsetNewModel },
|
||||||
{ "animate", l_lovrHeadsetAnimate },
|
{ "animate", l_lovrHeadsetAnimate },
|
||||||
|
{ "newLayer", l_lovrHeadsetNewLayer },
|
||||||
|
{ "getLayers", l_lovrHeadsetGetLayers },
|
||||||
|
{ "setLayers", l_lovrHeadsetSetLayers },
|
||||||
{ "getTexture", l_lovrHeadsetGetTexture },
|
{ "getTexture", l_lovrHeadsetGetTexture },
|
||||||
{ "getPass", l_lovrHeadsetGetPass },
|
{ "getPass", l_lovrHeadsetGetPass },
|
||||||
{ "submit", l_lovrHeadsetSubmit },
|
{ "submit", l_lovrHeadsetSubmit },
|
||||||
|
@ -702,9 +739,12 @@ static const luaL_Reg lovrHeadset[] = {
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern const luaL_Reg lovrLayer[];
|
||||||
|
|
||||||
int luaopen_lovr_headset(lua_State* L) {
|
int luaopen_lovr_headset(lua_State* L) {
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luax_register(L, lovrHeadset);
|
luax_register(L, lovrHeadset);
|
||||||
|
luax_registertype(L, Layer);
|
||||||
|
|
||||||
HeadsetDriver drivers[8];
|
HeadsetDriver drivers[8];
|
||||||
|
|
||||||
|
|
11
src/api/l_headset_layer.c
Normal file
11
src/api/l_headset_layer.c
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include "api.h"
|
||||||
|
|
||||||
|
static int l_lovrLayerGetWidth(lua_State* L) {
|
||||||
|
lua_pushnumber(L, 0.);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg lovrLayer[] = {
|
||||||
|
{ "getWidth", l_lovrLayerGetWidth },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
|
@ -42,3 +42,7 @@ void lovrHeadsetDestroy(void) {
|
||||||
lovrHeadsetInterface = NULL;
|
lovrHeadsetInterface = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lovrLayerDestroy(void* ref) {
|
||||||
|
lovrHeadsetInterface->destroyLayer(ref);
|
||||||
|
}
|
||||||
|
|
|
@ -5,12 +5,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define HAND_JOINT_COUNT 26
|
#define HAND_JOINT_COUNT 26
|
||||||
|
#define MAX_LAYERS 10
|
||||||
|
|
||||||
struct Model;
|
struct Model;
|
||||||
struct ModelData;
|
struct ModelData;
|
||||||
struct Texture;
|
struct Texture;
|
||||||
struct Pass;
|
struct Pass;
|
||||||
|
|
||||||
|
typedef struct Layer Layer;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DRIVER_SIMULATOR,
|
DRIVER_SIMULATOR,
|
||||||
DRIVER_OPENXR,
|
DRIVER_OPENXR,
|
||||||
|
@ -120,6 +123,18 @@ typedef enum {
|
||||||
JOINT_PINKY_TIP
|
JOINT_PINKY_TIP
|
||||||
} HandJoint;
|
} HandJoint;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EYE_NONE,
|
||||||
|
EYE_LEFT,
|
||||||
|
EYE_RIGHT,
|
||||||
|
EYE_BOTH
|
||||||
|
} EyeMask;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LAYER_SUPERSAMPLE,
|
||||||
|
LAYER_SHARPEN
|
||||||
|
} LayerOption;
|
||||||
|
|
||||||
// Notes:
|
// Notes:
|
||||||
// - init is called immediately, the graphics module may not exist yet
|
// - init is called immediately, the graphics module may not exist yet
|
||||||
// - start is called after the graphics module is initialized, can be used to set up textures etc.
|
// - start is called after the graphics module is initialized, can be used to set up textures etc.
|
||||||
|
@ -167,6 +182,24 @@ typedef struct HeadsetInterface {
|
||||||
void (*stopVibration)(Device device);
|
void (*stopVibration)(Device device);
|
||||||
struct ModelData* (*newModelData)(Device device, bool animated);
|
struct ModelData* (*newModelData)(Device device, bool animated);
|
||||||
bool (*animate)(struct Model* model);
|
bool (*animate)(struct Model* model);
|
||||||
|
|
||||||
|
Layer* (*newLayer)(uint32_t width, uint32_t height);
|
||||||
|
void (*destroyLayer)(void* ref);
|
||||||
|
Layer** (*getLayers)(uint32_t* count);
|
||||||
|
void (*setLayers)(Layer** layers, uint32_t count);
|
||||||
|
void (*getLayerTransform)(Layer* layer, float* position, float* orientation);
|
||||||
|
void (*setLayerTransform)(Layer* layer, float* position, float* orientation);
|
||||||
|
void (*getLayerSize)(Layer* layer, float* width, float* height);
|
||||||
|
void (*setLayerSize)(Layer* layer, float width, float height);
|
||||||
|
EyeMask (*getLayerEyeMask)(Layer* layer);
|
||||||
|
void (*setLayerEyeMask)(Layer* layer, EyeMask mask);
|
||||||
|
void (*getLayerViewport)(Layer* layer, uint32_t* viewport);
|
||||||
|
void (*setLayerViewport)(Layer* layer, uint32_t* viewport);
|
||||||
|
bool (*getLayerOption)(Layer* layer, LayerOption option);
|
||||||
|
void (*setLayerOption)(Layer* layer, LayerOption option, bool enable);
|
||||||
|
struct Texture* (*getLayerTexture)(Layer* layer);
|
||||||
|
struct Pass* (*getLayerPass)(Layer* layer);
|
||||||
|
|
||||||
struct Texture* (*getTexture)(void);
|
struct Texture* (*getTexture)(void);
|
||||||
struct Pass* (*getPass)(void);
|
struct Pass* (*getPass)(void);
|
||||||
void (*submit)(void);
|
void (*submit)(void);
|
||||||
|
@ -185,3 +218,4 @@ extern HeadsetInterface* lovrHeadsetInterface;
|
||||||
|
|
||||||
bool lovrHeadsetInit(HeadsetConfig* config);
|
bool lovrHeadsetInit(HeadsetConfig* config);
|
||||||
void lovrHeadsetDestroy(void);
|
void lovrHeadsetDestroy(void);
|
||||||
|
void lovrLayerDestroy(void* ref);
|
||||||
|
|
Loading…
Reference in a new issue