From 12c7ce43df975a0d85557d8bdff1aa383fa4d00b Mon Sep 17 00:00:00 2001 From: "pull[bot]" <39814207+pull[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:51:17 +0530 Subject: [PATCH] [pull] master from alvr-org:master (#139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Increase maximum resolution from 4096 to 8192 * decimal instead of hex * chore: add formatting style for c++ * chore: reformat c++ to new style * chore: add c++ autoformatter * chore: Add missed/bugfixed format changes * fix: routing assumption basis of microphone loopback detection (#2209) * fix(server) HEVC black screen on some linux config (#2203) * refactor(xtask): :recycle: Fix clippy and refactor (#2213) * fix(client_core): :bug: Fix USB mode (#2214) * refactor(client): :recycle: Remove separate Pico Neo 3 Link platform * client gfx refactor (7): partially port lobby * feat(client): :sparkles: Show hands in lobby * feat(client_openxr): :sparkles: Make lobby use max swapchain res (#2220) * feat(client_core): :sparkles: Thicken lobby grid lines * fix(client): :bug: Fix performance regressions on Quest 1 --------- Co-authored-by: shinyquagsire23 Co-authored-by: Leonhard Saam Co-authored-by: 瑄 Co-authored-by: Nibor62 Co-authored-by: zarik5 --- .clang-format | 6 +- .editorconfig | 16 + .gitattributes | 2 +- .github/workflows/rust.yml | 9 +- Cargo.lock | 1 + alvr/client_core/cpp/bindings.h | 14 - alvr/client_core/cpp/gltf_model.cpp | 238 - alvr/client_core/cpp/gltf_model.h | 32 - alvr/client_core/cpp/graphics.cpp | 477 +- alvr/client_core/cpp/tinygltf/json.hpp | 20406 ---------------- alvr/client_core/cpp/tinygltf/stb_image.h | 7530 ------ .../cpp/tinygltf/stb_image_write.h | 1621 -- alvr/client_core/cpp/tinygltf/tiny_gltf.h | 5300 ---- alvr/client_core/resources/buffer.bin | Bin 42368 -> 0 bytes alvr/client_core/resources/loading.gltf | 895 - .../client_core/resources/lobby_fragment.glsl | 63 + alvr/client_core/resources/lobby_vertex.glsl | 28 + alvr/client_core/src/c_api.rs | 5 +- alvr/client_core/src/connection.rs | 2 +- alvr/client_core/src/graphics/lobby.rs | 306 +- alvr/client_core/src/graphics/mod.rs | 173 +- alvr/client_core/src/platform/mod.rs | 5 +- alvr/client_openxr/src/graphics.rs | 6 +- alvr/client_openxr/src/interaction.rs | 4 +- alvr/client_openxr/src/lib.rs | 3 +- alvr/client_openxr/src/lobby.rs | 59 +- alvr/client_openxr/src/stream.rs | 14 +- alvr/common/src/primitives.rs | 2 +- alvr/server/cpp/ALVR-common/common-utils.cpp | 14 +- alvr/server/cpp/ALVR-common/common-utils.h | 4 +- alvr/server/cpp/ALVR-common/exception.cpp | 26 +- alvr/server/cpp/ALVR-common/exception.h | 21 +- alvr/server/cpp/ALVR-common/packet_types.h | 40 +- .../cpp/alvr_server/ChaperoneUpdater.cpp | 28 +- alvr/server/cpp/alvr_server/Controller.cpp | 1738 +- alvr/server/cpp/alvr_server/Controller.h | 22 +- .../cpp/alvr_server/FakeViveTracker.cpp | 213 +- alvr/server/cpp/alvr_server/FakeViveTracker.h | 68 +- alvr/server/cpp/alvr_server/HMD.cpp | 127 +- alvr/server/cpp/alvr_server/HMD.h | 19 +- alvr/server/cpp/alvr_server/IDRScheduler.cpp | 89 +- alvr/server/cpp/alvr_server/IDRScheduler.h | 33 +- alvr/server/cpp/alvr_server/Logger.cpp | 109 +- alvr/server/cpp/alvr_server/Logger.h | 12 +- alvr/server/cpp/alvr_server/NalParsing.cpp | 19 +- alvr/server/cpp/alvr_server/Paths.cpp | 255 +- alvr/server/cpp/alvr_server/Paths.h | 6 +- alvr/server/cpp/alvr_server/PoseHistory.cpp | 148 +- alvr/server/cpp/alvr_server/PoseHistory.h | 34 +- alvr/server/cpp/alvr_server/Settings.cpp | 24 +- alvr/server/cpp/alvr_server/Settings.h | 4 +- alvr/server/cpp/alvr_server/TrackedDevice.cpp | 15 +- alvr/server/cpp/alvr_server/TrackedDevice.h | 7 +- alvr/server/cpp/alvr_server/Utils.h | 311 +- .../cpp/alvr_server/ViveTrackerProxy.cpp | 208 +- .../server/cpp/alvr_server/ViveTrackerProxy.h | 50 +- alvr/server/cpp/alvr_server/alvr_server.cpp | 214 +- alvr/server/cpp/alvr_server/bindings.h | 79 +- alvr/server/cpp/alvr_server/driverlog.cpp | 57 +- alvr/server/cpp/alvr_server/driverlog.h | 7 +- alvr/server/cpp/alvr_server/nvEncodeAPI.h | 4086 ++-- alvr/server/cpp/platform/linux/CEncoder.cpp | 215 +- alvr/server/cpp/platform/linux/CEncoder.h | 6 +- .../cpp/platform/linux/CrashHandler.cpp | 2 +- .../cpp/platform/linux/EncodePipeline.cpp | 125 +- .../cpp/platform/linux/EncodePipeline.h | 56 +- .../platform/linux/EncodePipelineNvEnc.cpp | 100 +- .../cpp/platform/linux/EncodePipelineNvEnc.h | 29 +- .../cpp/platform/linux/EncodePipelineSW.cpp | 205 +- .../cpp/platform/linux/EncodePipelineSW.h | 34 +- .../platform/linux/EncodePipelineVAAPI.cpp | 737 +- .../cpp/platform/linux/EncodePipelineVAAPI.h | 66 +- .../cpp/platform/linux/FormatConverter.cpp | 95 +- .../cpp/platform/linux/FormatConverter.h | 29 +- .../server/cpp/platform/linux/FrameRender.cpp | 114 +- alvr/server/cpp/platform/linux/FrameRender.h | 7 +- alvr/server/cpp/platform/linux/Renderer.cpp | 360 +- alvr/server/cpp/platform/linux/Renderer.h | 84 +- .../cpp/platform/linux/ffmpeg_helper.cpp | 601 +- .../server/cpp/platform/linux/ffmpeg_helper.h | 135 +- alvr/server/cpp/platform/macos/CEncoder.h | 16 +- .../cpp/platform/macos/CrashHandler.cpp | 2 +- alvr/server/cpp/platform/win32/CEncoder.cpp | 267 +- alvr/server/cpp/platform/win32/CEncoder.h | 87 +- alvr/server/cpp/platform/win32/FFR.cpp | 200 +- alvr/server/cpp/platform/win32/FFR.h | 22 +- .../server/cpp/platform/win32/FrameRender.cpp | 1280 +- alvr/server/cpp/platform/win32/FrameRender.h | 252 +- .../platform/win32/OvrDirectModeComponent.cpp | 574 +- .../platform/win32/OvrDirectModeComponent.h | 100 +- .../cpp/platform/win32/VideoEncoder.cpp | 2 +- alvr/server/cpp/platform/win32/VideoEncoder.h | 12 +- .../cpp/platform/win32/VideoEncoderAMF.cpp | 1398 +- .../cpp/platform/win32/VideoEncoderAMF.h | 147 +- .../cpp/platform/win32/VideoEncoderNVENC.cpp | 677 +- .../cpp/platform/win32/VideoEncoderNVENC.h | 62 +- .../cpp/platform/win32/VideoEncoderSW.cpp | 488 +- .../cpp/platform/win32/VideoEncoderSW.h | 62 +- .../win32/d3d-render-utils/RenderPipeline.cpp | 211 +- .../win32/d3d-render-utils/RenderPipeline.h | 62 +- .../d3d-render-utils/RenderPipelineYUV.cpp | 282 +- .../d3d-render-utils/RenderPipelineYUV.h | 62 +- .../win32/d3d-render-utils/RenderUtils.cpp | 351 +- .../win32/d3d-render-utils/RenderUtils.h | 63 +- alvr/server/src/connection.rs | 22 +- alvr/session/src/settings.rs | 4 +- alvr/xtask/Cargo.toml | 1 + alvr/xtask/src/build.rs | 8 +- alvr/xtask/src/format.rs | 77 + alvr/xtask/src/main.rs | 5 + 110 files changed, 10596 insertions(+), 44504 deletions(-) create mode 100644 .editorconfig delete mode 100644 alvr/client_core/cpp/gltf_model.cpp delete mode 100644 alvr/client_core/cpp/gltf_model.h delete mode 100644 alvr/client_core/cpp/tinygltf/json.hpp delete mode 100644 alvr/client_core/cpp/tinygltf/stb_image.h delete mode 100644 alvr/client_core/cpp/tinygltf/stb_image_write.h delete mode 100644 alvr/client_core/cpp/tinygltf/tiny_gltf.h delete mode 100644 alvr/client_core/resources/buffer.bin delete mode 100644 alvr/client_core/resources/loading.gltf create mode 100644 alvr/client_core/resources/lobby_fragment.glsl create mode 100644 alvr/client_core/resources/lobby_vertex.glsl create mode 100644 alvr/xtask/src/format.rs diff --git a/.clang-format b/.clang-format index ac5487b2fa..faa13fe9b1 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,8 @@ +BasedOnStyle: WebKit IndentWidth: 4 ColumnLimit: 100 BinPackArguments: false -BinPackParameters: false \ No newline at end of file +BinPackParameters: false +AlignAfterOpenBracket: BlockIndent +BreakBeforeBraces: Attach +InsertNewlineAtEOF: true diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..50fdc3717e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# Editor configuration, see https://editorconfig.org + +[*.{c,cpp,h,hpp}] +indent_style = space +indent_size = 4 +tab_width = 4 +max_line_length = 100 +end_of_line = lf +insert_final_newline = true + +[.editorconfig] +indent_style = space +indent_size = 4 +tab_width = 4 +end_of_line = lf +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes index c78dff9dde..c5ebf26c98 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,7 +4,7 @@ alvr/client_core/cpp/VrApi_* linguist-vendored alvr/client_core/cpp/glm/** linguist-vendored alvr/client_core/cpp/tinygltf/** linguist-vendored alvr/server/cpp/alvr_server/include/** linguist-vendored -alvr/server/cpp/openvr/** linguist-vendored +alvr/server/cpp/alvr_server/nvEncodeAPI.h linguist-vendored alvr/server/cpp/platform/win32/NvCodecUtils.h linguist-vendored alvr/server/cpp/platform/win32/NvEncoder.cpp linguist-vendored alvr/server/cpp/platform/win32/NvEncoder.h linguist-vendored diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9d48a8d35c..fcdf49d070 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -143,8 +143,8 @@ jobs: command: test args: -p alvr_session - rustfmt: - runs-on: ubuntu-latest + check-format: + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -154,10 +154,7 @@ jobs: override: true components: rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo xtask check-format check-msrv-windows: runs-on: windows-2019 diff --git a/Cargo.lock b/Cargo.lock index e26325b776..42c4bb137c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -457,6 +457,7 @@ dependencies = [ "alvr_filesystem", "pico-args", "pkg-config", + "walkdir", "xshell", ] diff --git a/alvr/client_core/cpp/bindings.h b/alvr/client_core/cpp/bindings.h index 54dc1b1832..265256acae 100644 --- a/alvr/client_core/cpp/bindings.h +++ b/alvr/client_core/cpp/bindings.h @@ -27,23 +27,9 @@ struct FfiStreamConfig { float encodingGamma; }; -// gltf_model.h -extern "C" const unsigned char *LOBBY_ROOM_GLTF_PTR; -extern "C" unsigned int LOBBY_ROOM_GLTF_LEN; -extern "C" const unsigned char *LOBBY_ROOM_BIN_PTR; -extern "C" unsigned int LOBBY_ROOM_BIN_LEN; - // graphics.h extern "C" void initGraphicsNative(); -extern "C" void prepareLobbyRoom(int viewWidth, - int viewHeight, - const unsigned int *swapchainTextures[2], - int swapchainLength, - bool enable_srgb_correction); -extern "C" void destroyLobby(); extern "C" void destroyStream(); extern "C" void streamStartNative(FfiStreamConfig config); -extern "C" void updateLobbyHudTexture(const unsigned char *data); -extern "C" void renderLobbyNative(const FfiViewInput eyeInputs[2]); extern "C" void renderStreamNative(void *streamHardwareBuffer, const unsigned int swapchainIndices[2]); diff --git a/alvr/client_core/cpp/gltf_model.cpp b/alvr/client_core/cpp/gltf_model.cpp deleted file mode 100644 index b2bf6417c8..0000000000 --- a/alvr/client_core/cpp/gltf_model.cpp +++ /dev/null @@ -1,238 +0,0 @@ -#include "gltf_model.h" - -#define TINYGLTF_IMPLEMENTATION -#define STB_IMAGE_IMPLEMENTATION -#define TINYGLTF_NO_STB_IMAGE_WRITE - -#include "tinygltf/tiny_gltf.h" -#include "utils.h" - -const unsigned char *LOBBY_ROOM_GLTF_PTR; -unsigned int LOBBY_ROOM_GLTF_LEN; -const unsigned char *LOBBY_ROOM_BIN_PTR; -unsigned int LOBBY_ROOM_BIN_LEN; - -bool AssetFileExists(const std::string &abs_filename, void *) { return true; } - -std::string AssetExpandFilePath(const std::string &path, void *) { return path; } - -bool AssetReadWholeFile(std::vector *out, - std::string *, - const std::string &path, - void *) { - out->resize(LOBBY_ROOM_BIN_LEN); - memcpy(&(*out)[0], LOBBY_ROOM_BIN_PTR, LOBBY_ROOM_BIN_LEN); - - return true; -} - -bool AssetWriteWholeFile(std::string *, - const std::string &, - const std::vector &, - void *) { - return false; -} - -tinygltf::FsCallbacks gAssetFsCallbacks{.FileExists = AssetFileExists, - .ExpandFilePath = AssetExpandFilePath, - .ReadWholeFile = AssetReadWholeFile, - .WriteWholeFile = AssetWriteWholeFile}; - -void GltfModel::load() { - tinygltf::TinyGLTF loader; - std::string err, warn; - - loader.SetFsCallbacks(gAssetFsCallbacks); - - auto buffer = std::vector(LOBBY_ROOM_GLTF_LEN); - memcpy(&buffer[0], LOBBY_ROOM_GLTF_PTR, LOBBY_ROOM_GLTF_LEN); - bool ret = - loader.LoadASCIIFromString(&m_model, &err, &warn, (char *)&buffer[0], buffer.size(), ""); - - LOGI("GltfModel loaded. ret=%d scenes=%lu defaultScene=%d err=%s.\nwarn=%s", - ret, - m_model.scenes.size(), - m_model.defaultScene, - err.c_str(), - warn.c_str()); - - m_vbs.resize(m_model.bufferViews.size()); - - GL(glGenVertexArrays(1, &m_vao)); - GL(glBindVertexArray(m_vao)); - - for (auto accessor : m_model.accessors) { - auto bufferView = m_model.bufferViews[accessor.bufferView]; - auto buffer = m_model.buffers[bufferView.buffer]; - - glGenBuffers(1, &m_vbs[accessor.bufferView]); - glBindBuffer(bufferView.target, m_vbs[accessor.bufferView]); - glBufferData(bufferView.target, - bufferView.byteLength, - &buffer.data.at(0) + bufferView.byteOffset, - GL_STATIC_DRAW); - glBindBuffer(bufferView.target, 0); - } - - GL(glBindVertexArray(0)); -} - -void GltfModel::drawScene(int position, int uv, GLint mMatrix, GLint mode) { - if (m_model.scenes.size() == 0) { - return; - } - auto &scene = m_model.scenes[m_model.defaultScene]; - - m_position = position; - m_uv = uv; - m_mMatrix = mMatrix; - m_mode = mode; - - GL(glBindVertexArray(m_vao)); - - ovrMatrix4f transform = ovrMatrix4f_CreateIdentity(); - - for (auto node_i : scene.nodes) { - drawNodeTree(node_i, transform); - } - - GL(glBindVertexArray(0)); -} - -void GltfModel::drawNodeTree(int node_i, const ovrMatrix4f &transform) { - auto &node = m_model.nodes[node_i]; - - ovrMatrix4f nodeTransform = createNodeTransform(transform, node); - - drawNode(node_i, nodeTransform); - - for (auto &child_i : node.children) { - drawNodeTree(child_i, nodeTransform); - } -} - -void GltfModel::drawNode(int node_i, const ovrMatrix4f &transform) { - auto &node = m_model.nodes[node_i]; - if (node.mesh < 0) { - return; - } - auto &mesh = m_model.meshes[node.mesh]; - - for (auto &prim : mesh.primitives) { - if (prim.indices < 0) { - continue; - } - for (auto &att : prim.attributes) { - const std::string &name = att.first; - int att_i = att.second; - auto &accessor = m_model.accessors[att_i]; - auto &bufferView = m_model.bufferViews[accessor.bufferView]; - - glBindBuffer(bufferView.target, m_vbs[accessor.bufferView]); - - int size = 1; - if (accessor.type == TINYGLTF_TYPE_SCALAR) { - size = 1; - } else if (accessor.type == TINYGLTF_TYPE_VEC2) { - size = 2; - } else if (accessor.type == TINYGLTF_TYPE_VEC3) { - size = 3; - } else if (accessor.type == TINYGLTF_TYPE_VEC4) { - size = 4; - } else { - LOGE("accessor.type is invalid. type=%d", accessor.type); - } - - int index = -1; - if (name == "POSITION") { - index = m_position; - } else if (name == "TEXCOORD_0") { - index = m_uv; - } - - if (index != -1) { - // Compute byteStride from Accessor + BufferView combination. - int byteStride = accessor.ByteStride(m_model.bufferViews[accessor.bufferView]); - GL(glVertexAttribPointer(index, - size, - accessor.componentType, - accessor.normalized ? GL_TRUE : GL_FALSE, - byteStride, - (void *)accessor.byteOffset)); - GL(glEnableVertexAttribArray(index)); - } - } - - auto &material = m_model.materials[prim.material]; - - tinygltf::ColorValue colorValue = {1.0, 1.0, 1.0, 1.0}; - - auto it = material.values.find("baseColorFactor"); - if (it != material.values.end()) { - colorValue = it->second.ColorFactor(); - } - - GL(glUniformMatrix4fv(m_mMatrix, 1, true, (float *)&transform)); - - if (material.name == "Plane") { - GL(glUniform1i(m_mode, 0)); - } else if (material.name == "Message") { - GL(glUniform1i(m_mode, 1)); - } else { - GL(glUniform1i(m_mode, 2)); - } - - auto &indexAccessor = m_model.accessors[prim.indices]; - auto &bufferView = m_model.bufferViews[indexAccessor.bufferView]; - - GL(glBindBuffer(bufferView.target, m_vbs[indexAccessor.bufferView])); - - int mode = -1; - if (prim.mode == TINYGLTF_MODE_TRIANGLES) { - mode = GL_TRIANGLES; - } else if (prim.mode == TINYGLTF_MODE_TRIANGLE_STRIP) { - mode = GL_TRIANGLE_STRIP; - } else if (prim.mode == TINYGLTF_MODE_TRIANGLE_FAN) { - mode = GL_TRIANGLE_FAN; - } else if (prim.mode == TINYGLTF_MODE_POINTS) { - mode = GL_POINTS; - } else if (prim.mode == TINYGLTF_MODE_LINE) { - mode = GL_LINES; - } else if (prim.mode == TINYGLTF_MODE_LINE_LOOP) { - mode = GL_LINE_LOOP; - } else { - LOGE("Unknown primitive mode. mode=%d", prim.mode); - continue; - } - - GL(glDrawElements(mode, - indexAccessor.count, - indexAccessor.componentType, - (void *)indexAccessor.byteOffset)); - GL(glDisableVertexAttribArray(m_position)); - } -} - -ovrMatrix4f GltfModel::createNodeTransform(const ovrMatrix4f &baseTransform, - const tinygltf::Node &node) { - ovrMatrix4f nodeTransform = baseTransform; - if (node.translation.size() == 3) { - ovrMatrix4f translation = ovrMatrix4f_CreateTranslation( - node.translation[0], node.translation[1], node.translation[2]); - nodeTransform = ovrMatrix4f_Multiply(&nodeTransform, &translation); - } - if (node.rotation.size() == 4) { - ovrQuatf q; - q.x = node.rotation[0]; - q.y = node.rotation[1]; - q.z = node.rotation[2]; - q.w = node.rotation[3]; - ovrMatrix4f rotation = ovrMatrix4f_CreateFromQuaternion(&q); - nodeTransform = ovrMatrix4f_Multiply(&nodeTransform, &rotation); - } - if (node.scale.size() == 3) { - ovrMatrix4f scale = ovrMatrix4f_CreateScale(node.scale[0], node.scale[1], node.scale[2]); - nodeTransform = ovrMatrix4f_Multiply(&nodeTransform, &scale); - } - return nodeTransform; -} diff --git a/alvr/client_core/cpp/gltf_model.h b/alvr/client_core/cpp/gltf_model.h deleted file mode 100644 index 15d658c8f2..0000000000 --- a/alvr/client_core/cpp/gltf_model.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ALVRCLIENT_GLTFMODEL_H -#define ALVRCLIENT_GLTFMODEL_H - -#include -#include -#include -#include -#include - -#define TINYGLTF_NO_STB_IMAGE_WRITE -#include "tinygltf/tiny_gltf.h" - -class GltfModel { - std::vector m_vbs; - tinygltf::Model m_model; - GLuint m_vao; - - int m_position; - int m_uv; - GLint m_mMatrix; - GLint m_mode; - - void drawNodeTree(int node_i, const ovrMatrix4f &transform); - void drawNode(int node_i, const ovrMatrix4f &transform); - ovrMatrix4f createNodeTransform(const ovrMatrix4f &baseTransform, const tinygltf::Node &node); - - public: - void load(); - void drawScene(int position, int uv, GLint mMatrix, GLint mode); -}; - -#endif // ALVRCLIENT_GLTFMODEL_H diff --git a/alvr/client_core/cpp/graphics.cpp b/alvr/client_core/cpp/graphics.cpp index 4f47f31def..8c562eeb90 100644 --- a/alvr/client_core/cpp/graphics.cpp +++ b/alvr/client_core/cpp/graphics.cpp @@ -1,11 +1,9 @@ #include "bindings.h" #include "ffr.h" -#include "gltf_model.h" #include "srgb_correction_pass.h" #include "utils.h" #include #include -#include #include using namespace gl_render_utils; @@ -14,8 +12,6 @@ const float NEAR = 0.1; const int MAX_VERTEX_ATTRIB_POINTERS = 5; const int MAX_PROGRAM_UNIFORMS = 8; const int MAX_PROGRAM_TEXTURES = 8; -const int HUD_TEXTURE_WIDTH = 1280; -const int HUD_TEXTURE_HEIGHT = 720; /// Integer version of ovrRectf typedef struct Recti_ { @@ -36,8 +32,8 @@ typedef struct { GLuint FragmentShader; // These will be -1 if not used by the program. GLint UniformLocation[MAX_PROGRAM_UNIFORMS]; // ProgramUniforms[].name - GLint UniformBinding[MAX_PROGRAM_UNIFORMS]; // ProgramUniforms[].name - GLint Textures[MAX_PROGRAM_TEXTURES]; // Texture%i + GLint UniformBinding[MAX_PROGRAM_UNIFORMS]; // ProgramUniforms[].name + GLint Textures[MAX_PROGRAM_TEXTURES]; // Texture%i } ovrProgram; enum ovrProgramType { @@ -48,12 +44,8 @@ enum ovrProgramType { typedef struct { ovrFramebuffer FrameBuffer[2]; - bool SceneCreated; ovrProgram streamProgram; - ovrProgram lobbyProgram; - gl_render_utils::Texture *streamTexture; - GLuint hudTexture; - GltfModel *lobbyScene; + gl_render_utils::Texture* streamTexture; std::unique_ptr ffr; std::unique_ptr srgbCorrectionPass; bool enableFFE; @@ -67,13 +59,13 @@ enum VertexAttributeLocation { typedef struct { enum VertexAttributeLocation location; - const char *name; + const char* name; bool usedInProg[MAX_PROGS]; } ovrVertexAttribute; ovrVertexAttribute ProgramVertexAttributes[] = { - {VERTEX_ATTRIBUTE_LOCATION_POSITION, "vertexPosition", {true, true}}, - {VERTEX_ATTRIBUTE_LOCATION_UV, "vertexUv", {true, true}}, + { VERTEX_ATTRIBUTE_LOCATION_POSITION, "vertexPosition", { true, true } }, + { VERTEX_ATTRIBUTE_LOCATION_UV, "vertexUv", { true, true } }, }; enum E1test { UNIFORM_VIEW_ID, UNIFORM_MVP_MATRIX, UNIFORM_M_MATRIX, UNIFORM_MODE }; @@ -86,26 +78,20 @@ enum E2test { typedef struct { E1test index; E2test type; - const char *name; + const char* name; } ovrUniform; static ovrUniform ProgramUniforms[] = { - {UNIFORM_VIEW_ID, UNIFORM_TYPE_INT, "ViewID"}, - {UNIFORM_MVP_MATRIX, UNIFORM_TYPE_MATRIX4X4, "mvpMatrix"}, - {UNIFORM_M_MATRIX, UNIFORM_TYPE_MATRIX4X4, "mMatrix"}, - {UNIFORM_MODE, UNIFORM_TYPE_INT, "Mode"}, + { UNIFORM_VIEW_ID, UNIFORM_TYPE_INT, "ViewID" }, + { UNIFORM_MVP_MATRIX, UNIFORM_TYPE_MATRIX4X4, "mvpMatrix" }, + { UNIFORM_M_MATRIX, UNIFORM_TYPE_MATRIX4X4, "mMatrix" }, + { UNIFORM_MODE, UNIFORM_TYPE_INT, "Mode" }, }; class GraphicsContext { - public: +public: EGLDisplay eglDisplay; - std::vector hudTextureBitmap; - std::mutex hudTextureMutex; - std::unique_ptr hudTexture; - std::vector lobbySwapchainTextures[2]; - std::unique_ptr lobbyRenderer; - std::unique_ptr streamTexture; std::vector streamSwapchainTextures[2]; std::unique_ptr streamRenderer; @@ -143,100 +129,14 @@ void main() } )glsl"; -static const char LOBBY_VERTEX_SHADER[] = R"glsl( -in vec3 vertexPosition; -in vec2 vertexUv; -uniform mat4 mvpMatrix; -uniform mat4 mMatrix; -out vec2 uv; -out lowp vec3 position; -void main() -{ - lowp vec4 position4 = mMatrix * vec4( vertexPosition, 1.0 ); - gl_Position = mvpMatrix * position4; - uv = vertexUv; - position = position4.xyz / position4.w; -} -)glsl"; - -static const char LOBBY_FRAGMENT_SHADER[] = R"glsl( -in lowp vec2 uv; -in lowp vec3 position; -out lowp vec4 outColor; -uniform sampler2D sTexture; -uniform lowp int Mode; -void main() -{ - if(Mode == 0){ // ground - lowp vec3 groundCenter = vec3(0.0, 0.0, 0.00); - lowp vec3 groundHorizon = vec3(0.00, 0.00, 0.015); - - lowp vec3 gridClose = vec3(0.114, 0.545, 0.804); - lowp vec3 gridFar = vec3(0.259, 0.863, 0.886); - - lowp float lineFadeStart = 10.0; - lowp float lineFadeEnd = 50.0; - lowp float lineFadeDist = lineFadeEnd - lineFadeStart; - - lowp float lineBloom = 10.0; - - lowp float distance = length(position.xz); - - // Pick a coordinate to visualize in a grid - lowp vec2 coord = position.xz / 2.0; - - // Compute anti-aliased world-space grid lines - lowp vec2 grid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord); +static const char* programVersion = "#version 300 es\n"; - // Create mask for grid lines and fade over distance - lowp float line = clamp(1.0 - min(grid.x, grid.y), 0.0, 1.0); - line *= clamp((lineFadeStart - distance) / lineFadeDist, 0.0, 1.0); - - // Fill in normal ground colour - outColor.rgb = groundCenter * (1.0 - line); - - // Add cheap and simple "bloom" to the grid lines - line *= 1.0 + lineBloom; - - // Fill in grid line colour - outColor.rgb += line * mix(gridFar, gridClose, clamp((lineFadeEnd - distance) / lineFadeEnd, 0.0, 1.0)); - - // Fade to the horizon colour over distance - if(distance > 10.0){ - lowp float coef = 1.0 - 10.0 / distance; - outColor.rgb = (1.0 - coef) * outColor.rgb + coef * groundHorizon; - } - - outColor.a = 1.0; - } else if(Mode == 1) { // text - lowp vec3 textColor = vec3(1.0, 1.0, 1.0); - - outColor.rgb = textColor; - outColor.a = texture(sTexture, uv).a; - } else { // sky - lowp vec3 skyCenter = vec3(0.0, 0.0, 0.0); - lowp vec3 skyHorizon = vec3(0.0, 0.0, 0.02); - - lowp float coef = 1.0; - if(position.y < 50.0){ - coef = position.y / 100.0; - }else if(position.y < 100.0){ - coef = (position.y - 50.0) / 50.0 * 0.3 + 0.5; - }else{ - coef = (position.y - 100.0) / 150.0 * 0.2 + 0.8; - } - outColor.a = 1.0; - outColor.rgb = skyCenter * coef + skyHorizon * (1.0 - coef); - } -} -)glsl"; - -static const char *programVersion = "#version 300 es\n"; - -bool ovrProgram_Create(ovrProgram *program, - const char *vertexSource, - const char *fragmentSource, - ovrProgramType progType) { +bool ovrProgram_Create( + ovrProgram* program, + const char* vertexSource, + const char* fragmentSource, + ovrProgramType progType +) { GLint r; LOGI("Compiling shaders."); @@ -246,7 +146,8 @@ bool ovrProgram_Create(ovrProgram *program, return false; } - const char *vertexSources[3] = {programVersion, "#define DISABLE_MULTIVIEW 1\n", vertexSource}; + const char* vertexSources[3] + = { programVersion, "#define DISABLE_MULTIVIEW 1\n", vertexSource }; GL(glShaderSource(program->VertexShader, 3, vertexSources, 0)); GL(glCompileShader(program->VertexShader)); GL(glGetShaderiv(program->VertexShader, GL_COMPILE_STATUS, &r)); @@ -258,7 +159,7 @@ bool ovrProgram_Create(ovrProgram *program, // Ignore compile error. If this error is only a warning, we can proceed to next. } - const char *fragmentSources[2] = {programVersion, fragmentSource}; + const char* fragmentSources[2] = { programVersion, fragmentSource }; GL(program->FragmentShader = glCreateShader(GL_FRAGMENT_SHADER)); GL(glShaderSource(program->FragmentShader, 2, fragmentSources, 0)); GL(glCompileShader(program->FragmentShader)); @@ -279,13 +180,17 @@ bool ovrProgram_Create(ovrProgram *program, // Only bind vertex attributes which are used/active in shader else causes uncessary bugs // via compiler optimization/aliasing if (ProgramVertexAttributes[i].usedInProg[progType]) { - GL(glBindAttribLocation(program->streamProgram, - ProgramVertexAttributes[i].location, - ProgramVertexAttributes[i].name)); - LOGD("Binding ProgramVertexAttribute [id.%d] %s to location %d", - i, - ProgramVertexAttributes[i].name, - ProgramVertexAttributes[i].location); + GL(glBindAttribLocation( + program->streamProgram, + ProgramVertexAttributes[i].location, + ProgramVertexAttributes[i].name + )); + LOGD( + "Binding ProgramVertexAttribute [id.%d] %s to location %d", + i, + ProgramVertexAttributes[i].name, + ProgramVertexAttributes[i].location + ); } } @@ -310,8 +215,8 @@ bool ovrProgram_Create(ovrProgram *program, for (unsigned long i = 0; i < sizeof(ProgramUniforms) / sizeof(ProgramUniforms[0]); i++) { const int uniformIndex = ProgramUniforms[i].index; - GL(program->UniformLocation[uniformIndex] = - glGetUniformLocation(program->streamProgram, ProgramUniforms[i].name)); + GL(program->UniformLocation[uniformIndex] + = glGetUniformLocation(program->streamProgram, ProgramUniforms[i].name)); program->UniformBinding[uniformIndex] = program->UniformLocation[uniformIndex]; } @@ -333,7 +238,7 @@ bool ovrProgram_Create(ovrProgram *program, return true; } -void ovrProgram_Destroy(ovrProgram *program) { +void ovrProgram_Destroy(ovrProgram* program) { if (GL_TRUE == glIsProgram(program->streamProgram)) { GL(glDeleteProgram(program->streamProgram)); } @@ -348,168 +253,104 @@ void ovrProgram_Destroy(ovrProgram *program) { program->FragmentShader = 0; } -void ovrRenderer_Create(ovrRenderer *renderer, - int width, - int height, - Texture *streamTexture, - int hudTexture, - std::vector textures[2], - FFRData ffrData, - bool isLobby, - bool enableSrgbCorrection, - bool fixLimitedRange, - float encodingGamma) { - if (!isLobby) { - renderer->srgbCorrectionPass = std::make_unique(streamTexture); - renderer->enableFFE = ffrData.enabled; - if (renderer->enableFFE) { - FoveationVars fv = CalculateFoveationVars(ffrData); - renderer->srgbCorrectionPass->Initialize(fv.optimizedEyeWidth, - fv.optimizedEyeHeight, - !enableSrgbCorrection, - fixLimitedRange, - encodingGamma); - renderer->ffr = std::make_unique(renderer->srgbCorrectionPass->GetOutputTexture()); - renderer->ffr->Initialize(fv); - renderer->streamRenderTexture = renderer->ffr->GetOutputTexture()->GetGLTexture(); - } else { - renderer->srgbCorrectionPass->Initialize( - width, height, !enableSrgbCorrection, fixLimitedRange, encodingGamma); - renderer->streamRenderTexture = - renderer->srgbCorrectionPass->GetOutputTexture()->GetGLTexture(); - } +void ovrRenderer_Create( + ovrRenderer* renderer, + int width, + int height, + Texture* streamTexture, + std::vector textures[2], + FFRData ffrData, + bool enableSrgbCorrection, + bool fixLimitedRange, + float encodingGamma +) { + + renderer->srgbCorrectionPass = std::make_unique(streamTexture); + renderer->enableFFE = ffrData.enabled; + if (renderer->enableFFE) { + FoveationVars fv = CalculateFoveationVars(ffrData); + renderer->srgbCorrectionPass->Initialize( + fv.optimizedEyeWidth, + fv.optimizedEyeHeight, + !enableSrgbCorrection, + fixLimitedRange, + encodingGamma + ); + renderer->ffr = std::make_unique(renderer->srgbCorrectionPass->GetOutputTexture()); + renderer->ffr->Initialize(fv); + renderer->streamRenderTexture = renderer->ffr->GetOutputTexture()->GetGLTexture(); + } else { + renderer->srgbCorrectionPass->Initialize( + width, height, !enableSrgbCorrection, fixLimitedRange, encodingGamma + ); + renderer->streamRenderTexture + = renderer->srgbCorrectionPass->GetOutputTexture()->GetGLTexture(); } // Create the frame buffers. for (int eye = 0; eye < 2; eye++) { - ovrFramebuffer *frameBuffer = &renderer->FrameBuffer[eye]; + ovrFramebuffer* frameBuffer = &renderer->FrameBuffer[eye]; for (int i = 0; i < textures[eye].size(); i++) { auto glRenderTarget = textures[eye][i]; frameBuffer->renderTargets.push_back(std::make_unique( - true, glRenderTarget, false, width, height, GL_RGBA16F, GL_RGBA)); - frameBuffer->renderStates.push_back(std::make_unique( - frameBuffer->renderTargets[i].get())); + true, glRenderTarget, false, width, height, GL_RGBA16F, GL_RGBA + )); + frameBuffer->renderStates.push_back( + std::make_unique(frameBuffer->renderTargets[i].get()) + ); } } renderer->streamTexture = streamTexture; - renderer->hudTexture = hudTexture; - renderer->SceneCreated = false; - renderer->lobbyScene = new GltfModel(); - renderer->lobbyScene->load(); ovrProgram_Create(&renderer->streamProgram, VERTEX_SHADER, FRAGMENT_SHADER, STREAMER_PROG); - - ovrProgram_Create( - &renderer->lobbyProgram, LOBBY_VERTEX_SHADER, LOBBY_FRAGMENT_SHADER, LOBBY_PROG); - - renderer->SceneCreated = true; } -void ovrRenderer_Destroy(ovrRenderer *renderer) { +void ovrRenderer_Destroy(ovrRenderer* renderer) { ovrProgram_Destroy(&renderer->streamProgram); - ovrProgram_Destroy(&renderer->lobbyProgram); for (int eye = 0; eye < 2; eye++) { - ovrFramebuffer *frameBuffer = &renderer->FrameBuffer[eye]; + ovrFramebuffer* frameBuffer = &renderer->FrameBuffer[eye]; frameBuffer->renderStates.clear(); frameBuffer->renderTargets.clear(); } } -void renderEye(int eye, glm::mat4 mvpMatrix, Recti *viewport, ovrRenderer *renderer, bool isLobby) { - if (isLobby) { - GL(glUseProgram(renderer->lobbyProgram.streamProgram)); - - GL(glDisable(GL_SCISSOR_TEST)); - GL(glEnable(GL_DEPTH_TEST)); - GL(glDepthFunc(GL_LEQUAL)); - GL(glDisable(GL_CULL_FACE)); - GL(glViewport(viewport->x, viewport->y, viewport->width, viewport->height)); - - GL(glClearColor(0.88f, 0.95f, 0.95f, 1.0f)); - GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - - GL(glEnable(GL_BLEND)); - GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - - GL(glUniformMatrix4fv(renderer->lobbyProgram.UniformLocation[UNIFORM_MVP_MATRIX], - 1, - true, - (float *)&mvpMatrix)); - - GL(glActiveTexture(GL_TEXTURE0)); - GL(glBindTexture(GL_TEXTURE_2D, renderer->hudTexture)); - - renderer->lobbyScene->drawScene(VERTEX_ATTRIBUTE_LOCATION_POSITION, - VERTEX_ATTRIBUTE_LOCATION_UV, - renderer->lobbyProgram.UniformLocation[UNIFORM_M_MATRIX], - renderer->lobbyProgram.UniformLocation[UNIFORM_MODE]); - GL(glBindVertexArray(0)); - GL(glBindTexture(GL_TEXTURE_2D, 0)); - } else { - GL(glUseProgram(renderer->streamProgram.streamProgram)); +void renderEye(int eye, Recti* viewport, ovrRenderer* renderer) { + GL(glUseProgram(renderer->streamProgram.streamProgram)); - GL(glDisable(GL_SCISSOR_TEST)); - GL(glDisable(GL_DEPTH_TEST)); - GL(glDisable(GL_CULL_FACE)); - GL(glViewport(viewport->x, viewport->y, viewport->width, viewport->height)); + GL(glDisable(GL_SCISSOR_TEST)); + GL(glDisable(GL_DEPTH_TEST)); + GL(glDisable(GL_CULL_FACE)); + GL(glViewport(viewport->x, viewport->y, viewport->width, viewport->height)); - GL(glUniform1i(renderer->streamProgram.UniformLocation[UNIFORM_VIEW_ID], eye)); + GL(glUniform1i(renderer->streamProgram.UniformLocation[UNIFORM_VIEW_ID], eye)); - GL(glActiveTexture(GL_TEXTURE0)); - GL(glBindTexture(GL_TEXTURE_2D, renderer->streamRenderTexture)); + GL(glActiveTexture(GL_TEXTURE0)); + GL(glBindTexture(GL_TEXTURE_2D, renderer->streamRenderTexture)); - GL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); - } + GL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } -void ovrRenderer_RenderFrame(ovrRenderer *renderer, const FfiViewInput input[2], bool isLobby) { - glm::mat4 mvpMatrix[2]; - if (isLobby) { - for (int eye = 0; eye < 2; eye++) { - auto p = input[eye].position; - auto o = input[eye].orientation; - auto trans = glm::translate(glm::mat4(1.0), glm::vec3(p[0], p[1], p[2])); - auto rot = glm::mat4_cast(glm::quat(o[3], o[0], o[1], o[2])); - auto viewInv = glm::inverse(trans * rot); - - auto tanl = tan(input[eye].fovLeft); - auto tanr = tan(input[eye].fovRight); - auto tant = tan(input[eye].fovUp); - auto tanb = tan(input[eye].fovDown); - auto a = 2 / (tanr - tanl); - auto b = 2 / (tant - tanb); - auto c = (tanr + tanl) / (tanr - tanl); - auto d = (tant + tanb) / (tant - tanb); - auto proj = glm::mat4( - a, 0.f, c, 0.f, 0.f, b, d, 0.f, 0.f, 0.f, -1.f, -2 * NEAR, 0.f, 0.f, -1.f, 0.f); - proj = glm::transpose(proj); - - mvpMatrix[eye] = glm::transpose(proj * viewInv); - } - } else { - mvpMatrix[0] = glm::mat4(1.0); - mvpMatrix[1] = glm::mat4(1.0); - } - +void ovrRenderer_RenderFrame(ovrRenderer* renderer, const FfiViewInput input[2]) { // Render the eye images. for (int eye = 0; eye < 2; eye++) { - ovrFramebuffer *frameBuffer = &renderer->FrameBuffer[eye]; + ovrFramebuffer* frameBuffer = &renderer->FrameBuffer[eye]; GL(glBindFramebuffer( GL_DRAW_FRAMEBUFFER, - frameBuffer->renderStates[input[eye].swapchainIndex]->GetFrameBuffer())); + frameBuffer->renderStates[input[eye].swapchainIndex]->GetFrameBuffer() + )); - Recti viewport = {0, - 0, - (int)frameBuffer->renderTargets[0]->GetWidth(), - (int)frameBuffer->renderTargets[0]->GetHeight()}; + Recti viewport = { 0, + 0, + (int)frameBuffer->renderTargets[0]->GetWidth(), + (int)frameBuffer->renderTargets[0]->GetHeight() }; - renderEye(eye, mvpMatrix[eye], &viewport, renderer, isLobby); + renderEye(eye, &viewport, renderer); // Discard the depth buffer, so the tiler won't need to write it back out to memory. - const GLenum depthAttachment[1] = {GL_DEPTH_ATTACHMENT}; + const GLenum depthAttachment[1] = { GL_DEPTH_ATTACHMENT }; glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, 1, depthAttachment); // Flush this frame worth of commands. @@ -523,10 +364,10 @@ void initGraphicsNative() { g_ctx.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); - eglGetNativeClientBufferANDROID = (PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC)eglGetProcAddress( - "eglGetNativeClientBufferANDROID"); - glEGLImageTargetTexture2DOES = - (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); + eglGetNativeClientBufferANDROID = (PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC + )eglGetProcAddress("eglGetNativeClientBufferANDROID"); + glEGLImageTargetTexture2DOES + = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); const GLubyte *sVendor, *sRenderer, *sVersion, *sExts; @@ -539,44 +380,6 @@ void initGraphicsNative() { LOGI("glExts : %s", sExts); } -// on resume -void prepareLobbyRoom(int viewWidth, - int viewHeight, - const unsigned int *swapchainTextures[2], - int swapchainLength, - bool enable_srgb_correction) { - g_ctx.hudTexture = std::make_unique( - false, 0, false, 1280, 720, GL_RGBA8, GL_RGBA, std::vector(1280 * 720 * 4, 0)); - for (int eye = 0; eye < 2; eye++) { - g_ctx.lobbySwapchainTextures[eye].clear(); - - for (int i = 0; i < swapchainLength; i++) { - g_ctx.lobbySwapchainTextures[eye].push_back(swapchainTextures[eye][i]); - } - } - - g_ctx.lobbyRenderer = std::make_unique(); - ovrRenderer_Create(g_ctx.lobbyRenderer.get(), - viewWidth, - viewHeight, - nullptr, - g_ctx.hudTexture->GetGLTexture(), - g_ctx.lobbySwapchainTextures, - {false}, - true, - enable_srgb_correction, - false, - 1.0); -} - -void destroyLobby() { - if (g_ctx.lobbyRenderer) { - ovrRenderer_Destroy(g_ctx.lobbyRenderer.get()); - g_ctx.lobbyRenderer.reset(); - } - g_ctx.hudTexture.reset(); -} - void destroyStream() { if (g_ctx.streamRenderer) { ovrRenderer_Destroy(g_ctx.streamRenderer.get()); @@ -601,66 +404,36 @@ void streamStartNative(FfiStreamConfig config) { } g_ctx.streamRenderer = std::make_unique(); - ovrRenderer_Create(g_ctx.streamRenderer.get(), - config.viewWidth, - config.viewHeight, - g_ctx.streamTexture.get(), - g_ctx.hudTexture->GetGLTexture(), - g_ctx.streamSwapchainTextures, - {(bool)config.enableFoveation, - config.viewWidth, - config.viewHeight, - config.foveationCenterSizeX, - config.foveationCenterSizeY, - config.foveationCenterShiftX, - config.foveationCenterShiftY, - config.foveationEdgeRatioX, - config.foveationEdgeRatioY}, - false, - config.enableSrgbCorrection, - config.fixLimitedRange, - config.encodingGamma); -} - -void updateLobbyHudTexture(const unsigned char *data) { - std::lock_guard lock(g_ctx.hudTextureMutex); - - g_ctx.hudTextureBitmap.resize(HUD_TEXTURE_WIDTH * HUD_TEXTURE_HEIGHT * 4); - - memcpy(&g_ctx.hudTextureBitmap[0], data, HUD_TEXTURE_WIDTH * HUD_TEXTURE_HEIGHT * 4); -} - -void renderLobbyNative(const FfiViewInput eyeInputs[2]) { - // update text image - { - std::lock_guard lock(g_ctx.hudTextureMutex); - - if (!g_ctx.hudTextureBitmap.empty()) { - GL(glBindTexture(GL_TEXTURE_2D, g_ctx.hudTexture->GetGLTexture())); - GL(glTexSubImage2D(GL_TEXTURE_2D, - 0, - 0, - 0, - HUD_TEXTURE_WIDTH, - HUD_TEXTURE_HEIGHT, - GL_RGBA, - GL_UNSIGNED_BYTE, - &g_ctx.hudTextureBitmap[0])); - } - g_ctx.hudTextureBitmap.clear(); - } - - ovrRenderer_RenderFrame(g_ctx.lobbyRenderer.get(), eyeInputs, true); + ovrRenderer_Create( + g_ctx.streamRenderer.get(), + config.viewWidth, + config.viewHeight, + g_ctx.streamTexture.get(), + g_ctx.streamSwapchainTextures, + { (bool)config.enableFoveation, + config.viewWidth, + config.viewHeight, + config.foveationCenterSizeX, + config.foveationCenterSizeY, + config.foveationCenterShiftX, + config.foveationCenterShiftY, + config.foveationEdgeRatioX, + config.foveationEdgeRatioY }, + config.enableSrgbCorrection, + config.fixLimitedRange, + config.encodingGamma + ); } -void renderStreamNative(void *streamHardwareBuffer, const unsigned int swapchainIndices[2]) { +void renderStreamNative(void* streamHardwareBuffer, const unsigned int swapchainIndices[2]) { auto renderer = g_ctx.streamRenderer.get(); if (streamHardwareBuffer != 0) { - GL(EGLClientBuffer clientBuffer = - eglGetNativeClientBufferANDROID((const AHardwareBuffer *)streamHardwareBuffer)); + GL(EGLClientBuffer clientBuffer + = eglGetNativeClientBufferANDROID((const AHardwareBuffer*)streamHardwareBuffer)); GL(EGLImageKHR image = eglCreateImageKHR( - g_ctx.eglDisplay, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, nullptr)); + g_ctx.eglDisplay, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, nullptr + )); GL(glBindTexture(GL_TEXTURE_EXTERNAL_OES, g_ctx.streamTexture->GetGLTexture())); GL(glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)image)); @@ -676,5 +449,5 @@ void renderStreamNative(void *streamHardwareBuffer, const unsigned int swapchain FfiViewInput eyeInputs[2] = {}; eyeInputs[0].swapchainIndex = swapchainIndices[0]; eyeInputs[1].swapchainIndex = swapchainIndices[1]; - ovrRenderer_RenderFrame(renderer, eyeInputs, false); + ovrRenderer_RenderFrame(renderer, eyeInputs); } diff --git a/alvr/client_core/cpp/tinygltf/json.hpp b/alvr/client_core/cpp/tinygltf/json.hpp deleted file mode 100644 index c9af0bed36..0000000000 --- a/alvr/client_core/cpp/tinygltf/json.hpp +++ /dev/null @@ -1,20406 +0,0 @@ -/* - __ _____ _____ _____ - __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.5.0 -|_____|_____|_____|_|___| /~https://github.com/nlohmann/json - -Licensed under the MIT License . -SPDX-License-Identifier: MIT -Copyright (c) 2013-2018 Niels Lohmann . - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef NLOHMANN_JSON_HPP -#define NLOHMANN_JSON_HPP - -#define NLOHMANN_JSON_VERSION_MAJOR 3 -#define NLOHMANN_JSON_VERSION_MINOR 5 -#define NLOHMANN_JSON_VERSION_PATCH 0 - -#include // all_of, find, for_each -#include // assert -#include // and, not, or -#include // nullptr_t, ptrdiff_t, size_t -#include // hash, less -#include // initializer_list -#include // istream, ostream -#include // random_access_iterator_tag -#include // accumulate -#include // string, stoi, to_string -#include // declval, forward, move, pair, swap - -// #include -#ifndef NLOHMANN_JSON_FWD_HPP -#define NLOHMANN_JSON_FWD_HPP - -#include // int64_t, uint64_t -#include // map -#include // allocator -#include // string -#include // vector - -/*! -@brief namespace for Niels Lohmann -@see /~https://github.com/nlohmann -@since version 1.0.0 -*/ -namespace nlohmann -{ -/*! -@brief default JSONSerializer template argument - -This serializer ignores the template arguments and uses ADL -([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) -for serialization. -*/ -template -struct adl_serializer; - -template class ObjectType = - std::map, - template class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, - class NumberIntegerType = std::int64_t, - class NumberUnsignedType = std::uint64_t, - class NumberFloatType = double, - template class AllocatorType = std::allocator, - template class JSONSerializer = - adl_serializer> -class basic_json; - -/*! -@brief JSON Pointer - -A JSON pointer defines a string syntax for identifying a specific value -within a JSON document. It can be used with functions `at` and -`operator[]`. Furthermore, JSON pointers are the base for JSON patches. - -@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) - -@since version 2.0.0 -*/ -template -class json_pointer; - -/*! -@brief default JSON class - -This type is the default specialization of the @ref basic_json class which -uses the standard template types. - -@since version 1.0.0 -*/ -using json = basic_json<>; -} // namespace nlohmann - -#endif - -// #include - - -// This file contains all internal macro definitions -// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them - -// exclude unsupported compilers -#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) - #if defined(__clang__) - #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 - #error "unsupported Clang version - see /~https://github.com/nlohmann/json#supported-compilers" - #endif - #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) - #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 - #error "unsupported GCC version - see /~https://github.com/nlohmann/json#supported-compilers" - #endif - #endif -#endif - -// disable float-equal warnings on GCC/clang -#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - -// disable documentation warnings on clang -#if defined(__clang__) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdocumentation" -#endif - -// allow for portable deprecation warnings -#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) - #define JSON_DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) - #define JSON_DEPRECATED __declspec(deprecated) -#else - #define JSON_DEPRECATED -#endif - -// allow to disable exceptions -#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) - #define JSON_THROW(exception) throw exception - #define JSON_TRY try - #define JSON_CATCH(exception) catch(exception) - #define JSON_INTERNAL_CATCH(exception) catch(exception) -#else - #define JSON_THROW(exception) std::abort() - #define JSON_TRY if(true) - #define JSON_CATCH(exception) if(false) - #define JSON_INTERNAL_CATCH(exception) if(false) -#endif - -// override exception macros -#if defined(JSON_THROW_USER) - #undef JSON_THROW - #define JSON_THROW JSON_THROW_USER -#endif -#if defined(JSON_TRY_USER) - #undef JSON_TRY - #define JSON_TRY JSON_TRY_USER -#endif -#if defined(JSON_CATCH_USER) - #undef JSON_CATCH - #define JSON_CATCH JSON_CATCH_USER - #undef JSON_INTERNAL_CATCH - #define JSON_INTERNAL_CATCH JSON_CATCH_USER -#endif -#if defined(JSON_INTERNAL_CATCH_USER) - #undef JSON_INTERNAL_CATCH - #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER -#endif - -// manual branch prediction -#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) - #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) - #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) -#else - #define JSON_LIKELY(x) x - #define JSON_UNLIKELY(x) x -#endif - -// C++ language standard detection -#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 - #define JSON_HAS_CPP_17 - #define JSON_HAS_CPP_14 -#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) - #define JSON_HAS_CPP_14 -#endif - -/*! -@brief macro to briefly define a mapping between an enum and JSON -@def NLOHMANN_JSON_SERIALIZE_ENUM -@since version 3.4.0 -*/ -#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ - template \ - inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ - { \ - static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ - static const std::pair m[] = __VA_ARGS__; \ - auto it = std::find_if(std::begin(m), std::end(m), \ - [e](const std::pair& ej_pair) -> bool \ - { \ - return ej_pair.first == e; \ - }); \ - j = ((it != std::end(m)) ? it : std::begin(m))->second; \ - } \ - template \ - inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ - { \ - static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ - static const std::pair m[] = __VA_ARGS__; \ - auto it = std::find_if(std::begin(m), std::end(m), \ - [j](const std::pair& ej_pair) -> bool \ - { \ - return ej_pair.second == j; \ - }); \ - e = ((it != std::end(m)) ? it : std::begin(m))->first; \ - } - -// Ugly macros to avoid uglier copy-paste when specializing basic_json. They -// may be removed in the future once the class is split. - -#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ - template class ObjectType, \ - template class ArrayType, \ - class StringType, class BooleanType, class NumberIntegerType, \ - class NumberUnsignedType, class NumberFloatType, \ - template class AllocatorType, \ - template class JSONSerializer> - -#define NLOHMANN_BASIC_JSON_TPL \ - basic_json - -// #include - - -#include // not -#include // size_t -#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type - -namespace nlohmann -{ -namespace detail -{ -// alias templates to reduce boilerplate -template -using enable_if_t = typename std::enable_if::type; - -template -using uncvref_t = typename std::remove_cv::type>::type; - -// implementation of C++14 index_sequence and affiliates -// source: https://stackoverflow.com/a/32223343 -template -struct index_sequence -{ - using type = index_sequence; - using value_type = std::size_t; - static constexpr std::size_t size() noexcept - { - return sizeof...(Ints); - } -}; - -template -struct merge_and_renumber; - -template -struct merge_and_renumber, index_sequence> - : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; - -template -struct make_index_sequence - : merge_and_renumber < typename make_index_sequence < N / 2 >::type, - typename make_index_sequence < N - N / 2 >::type > {}; - -template<> struct make_index_sequence<0> : index_sequence<> {}; -template<> struct make_index_sequence<1> : index_sequence<0> {}; - -template -using index_sequence_for = make_index_sequence; - -// dispatch utility (taken from ranges-v3) -template struct priority_tag : priority_tag < N - 1 > {}; -template<> struct priority_tag<0> {}; - -// taken from ranges-v3 -template -struct static_const -{ - static constexpr T value{}; -}; - -template -constexpr T static_const::value; -} // namespace detail -} // namespace nlohmann - -// #include - - -#include // not -#include // numeric_limits -#include // false_type, is_constructible, is_integral, is_same, true_type -#include // declval - -// #include - -// #include - - -#include // random_access_iterator_tag - -// #include - - -namespace nlohmann -{ -namespace detail -{ -template struct make_void -{ - using type = void; -}; -template using void_t = typename make_void::type; -} // namespace detail -} // namespace nlohmann - -// #include - - -namespace nlohmann -{ -namespace detail -{ -template -struct iterator_types {}; - -template -struct iterator_types < - It, - void_t> -{ - using difference_type = typename It::difference_type; - using value_type = typename It::value_type; - using pointer = typename It::pointer; - using reference = typename It::reference; - using iterator_category = typename It::iterator_category; -}; - -// This is required as some compilers implement std::iterator_traits in a way that -// doesn't work with SFINAE. See /~https://github.com/nlohmann/json/issues/1341. -template -struct iterator_traits -{ -}; - -template -struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types -{ -}; - -template -struct iterator_traits::value>> -{ - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = ptrdiff_t; - using pointer = T*; - using reference = T&; -}; -} -} - -// #include - -// #include - - -#include - -// #include - - -// http://en.cppreference.com/w/cpp/experimental/is_detected -namespace nlohmann -{ -namespace detail -{ -struct nonesuch -{ - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch(nonesuch const&) = delete; - void operator=(nonesuch const&) = delete; -}; - -template class Op, - class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op; -}; - -template