Skip to content

Commit

Permalink
Cardboard SDK v1.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyunh0929 committed Nov 16, 2021
1 parent 369fb3a commit f021e6c
Show file tree
Hide file tree
Showing 18 changed files with 1,757 additions and 44 deletions.
14 changes: 11 additions & 3 deletions hellocardboard-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ android {
}
defaultConfig {
applicationId "com.google.cardboard.hellocardboard"
minSdkVersion 18
// #gles3 #vulkan - You can reduce minSdkVersion down to 16 depending
// on rendering APIs supported:
//
// OpenGL ES 2.0 - Requires 16 or higher
// OpenGL ES 3.0 - Requires 18 or higher
// Vulkan - Requires 24 or higher
//
// See the release notes for details.
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.9.0"
versionName "1.10.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
Expand Down Expand Up @@ -42,7 +50,7 @@ dependencies {
// Android Mobile Vision
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.protobuf:protobuf-javalite:3.8.0'
implementation 'com.google.protobuf:protobuf-javalite:3.10.0'
implementation project(":sdk")
}

Expand Down
4 changes: 2 additions & 2 deletions hellocardboard-ios/HelloCardboard-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.9.0</string>
<string>1.10.0</string>
<key>CFBundleVersion</key>
<string>1.9.0</string>
<string>1.10.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
Expand Down
4 changes: 2 additions & 2 deletions hellocardboard-ios/HelloCardboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = C5M9TX4B3U;
ENABLE_BITCODE = NO;
ENABLE_BITCODE = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -395,7 +395,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = C5M9TX4B3U;
ENABLE_BITCODE = NO;
ENABLE_BITCODE = YES;
GCC_PREPROCESSOR_DEFINITIONS = GLES_SILENCE_DEPRECATION;
HEADER_SEARCH_PATHS = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
INFOPLIST_FILE = "$(SRCROOT)/HelloCardboard-Info.plist";
Expand Down
23 changes: 20 additions & 3 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ file(GLOB screen_params_srcs "screen_params/android/*.cc")
# Device Params Sources
file(GLOB device_params_srcs "device_params/android/*.cc")
# Rendering Sources
file(GLOB rendering_srcs "rendering/opengl_*.cc")
file(GLOB rendering_opengl_srcs "rendering/opengl_*.cc")
# #vulkan This is required for Vulkan rendering. Remove the following two lines
# if Vulkan rendering is not needed.
file(GLOB rendering_vulkan_srcs "rendering/android/*.cc")
file(GLOB rendering_vulkan_wrapper_srcs "rendering/android/vulkan/*.cc")

# === Cardboard Unity JNI ===
file(GLOB cardboard_unity_jni_srcs "unity/android/*.cc")
Expand All @@ -72,7 +76,11 @@ add_library(cardboard_api SHARED
${qrcode_srcs}
${screen_params_srcs}
${device_params_srcs}
${rendering_srcs}
${rendering_opengl_srcs}
# #vulkan This is required for Vulkan rendering. Remove the following two
# lines if Vulkan rendering is not needed.
${rendering_vulkan_srcs}
${rendering_vulkan_wrapper_srcs}
# Cardboard Unity JNI sources
${cardboard_unity_jni_srcs}
# Cardboard Unity Wrapper sources
Expand All @@ -84,11 +92,20 @@ add_library(cardboard_api SHARED
target_include_directories(cardboard_api
PRIVATE ../third_party/unity_plugin_api)

# #vulkan This is required for Vulkan rendering. Remove the following line if
# Vulkan rendering is not needed.
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR=1)

# Build
target_link_libraries(cardboard_api
${android-lib}
${GLESv2-lib}
# #gles3 - Library is only needed if OpenGL ES 3.0 support is desired.
# Remove the following line if OpenGL ES 3.0 support is not needed.
${GLESv3-lib}
${log-lib})
${log-lib}
# #vulkan - This is required for Vulkan rendering (it is required to load
# libvulkan.so at runtime). Remove the following line if Vulkan rendering
# is not needed
dl
)
19 changes: 12 additions & 7 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ android {
abortOnError false
}
defaultConfig {
// #gles3 - minSdkVersion is only 18 for OpenGL ES 3.0 support. You can
// reduce minSDKVersion to 16 if only OpenGL ES 2.0 is required by your
// app. See the release notes for details.
minSdkVersion 18
// #gles3 #vulkan - You can reduce minSdkVersion down to 16 depending
// on rendering APIs supported:
//
// OpenGL ES 2.0 - Requires 16 or higher
// OpenGL ES 3.0 - Requires 18 or higher
// Vulkan - Requires 24 or higher
//
// See the release notes for details.
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.9.0"
versionName "1.10.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
Expand Down Expand Up @@ -52,7 +57,7 @@ android {

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.8.0'
artifact = 'com.google.protobuf:protoc:3.10.0'
}
generateProtoTasks {
all().each { task ->
Expand All @@ -72,5 +77,5 @@ dependencies {
// Android Mobile Vision
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.protobuf:protobuf-javalite:3.8.0'
implementation 'com.google.protobuf:protobuf-javalite:3.10.0'
}
8 changes: 0 additions & 8 deletions sdk/cardboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ CardboardUv CardboardLensDistortion_distortedUvForUndistortedUv(
return ret;
}

CardboardDistortionRenderer* CardboardVulkanDistortionRenderer_create() {
if (CARDBOARD_IS_NOT_INITIALIZED()) {
return nullptr;
}
CARDBOARD_LOGE("Vulkan rendering API not available");
return nullptr;
}

void CardboardDistortionRenderer_destroy(
CardboardDistortionRenderer* renderer) {
if (CARDBOARD_IS_NOT_INITIALIZED() || CARDBOARD_IS_ARG_NULL(renderer)) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/distortion_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DistortionRenderer {
virtual void RenderEyeToDisplay(
uint64_t target, int x, int y, int width, int height,
const CardboardEyeTextureDescription* left_eye,
const CardboardEyeTextureDescription* right_eye) const = 0;
const CardboardEyeTextureDescription* right_eye) = 0;
};

} // namespace cardboard
Expand Down
129 changes: 114 additions & 15 deletions sdk/include/cardboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ typedef struct CardboardEyeTextureDescription {
/// When using OpenGL ES 2.x and OpenGL ES 3.x, this field corresponds to a
/// GLuint variable.
///
/// When using Vulkan, this field corresponds to an uint64_t address pointing
/// to a @c VkImageView variable.The SDK client is expected to manage the
/// object ownership and to guarantee the pointer validity during the
/// @c ::CardboardDistortionRenderer_renderEyeToDisplay function execution
/// to ensure it is properly retained. Usage example:
///
/// @code{.cc}
/// VkImageView imageView;
/// // Initialize and set up the imageView...
/// CardboardEyeTextureDescription leftEye;
/// leftEye.texture = reinterpret_cast<uint64_t>(&imageView)
/// // Fill remaining fields in leftEye...
/// CardboardDistortionRenderer_renderEyeToDisplay(..., &leftEye, ...);
/// // Clear previous imageView if it is needed.
/// @endcode
///
/// When using Metal, this field corresponds to a @c CFTypeRef
/// variable pointing to a @c MTLTexture object. The SDK client is expected
/// to manage the object ownership and to guarantee the pointer validity
Expand Down Expand Up @@ -129,16 +145,85 @@ typedef struct CardboardMetalDistortionRendererConfig {
/// @endcode
uint64_t mtl_device;
/// Color attachment pixel format.
/// This field holds a [MTLPixelFormat enum value](https://developer.apple.com/documentation/metalkit/mtkview/1535940-colorpixelformat?language=objc).
/// This field holds a [MTLPixelFormat enum
/// value](https://developer.apple.com/documentation/metalkit/mtkview/1535940-colorpixelformat?language=objc).
uint64_t color_attachment_pixel_format;
/// Depth attachment pixel format.
/// This field holds a [MTLPixelFormat enum value](https://developer.apple.com/documentation/metalkit/mtkview/1535940-colorpixelformat?language=objc).
/// This field holds a [MTLPixelFormat enum
/// value](https://developer.apple.com/documentation/metalkit/mtkview/1535940-colorpixelformat?language=objc).
uint64_t depth_attachment_pixel_format;
/// Stencil attachment pixel format.
/// This field holds a [MTLPixelFormat enum value](https://developer.apple.com/documentation/metalkit/mtkview/1535940-colorpixelformat?language=objc).
/// This field holds a [MTLPixelFormat enum
/// value](https://developer.apple.com/documentation/metalkit/mtkview/1535940-colorpixelformat?language=objc).
uint64_t stencil_attachment_pixel_format;
} CardboardMetalDistortionRendererConfig;

/// Struct to set Vulkan distortion renderer configuration.
typedef struct CardboardVulkanDistortionRendererConfig {
/// The physical device available for the rendering.
/// This field holds a [VkPhysicalDevice
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkPhysicalDevice.html).
/// Maintained by the user.
uint64_t physical_device;
/// The logical device available for the rendering.
/// This field holds a [VkDevice
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkDevice.html).
/// Maintained by the user.
uint64_t logical_device;
/// The render pass object that would be used to bind vertex, indices and
/// descriptor set.
/// This field holds a [VkRenderPass
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkRenderPass.html).
/// Maintained by the user.
uint64_t render_pass;
/// An array of command buffer objects. The number should be the same as
/// the image count in swapchain.
/// This field holds an array of [VkCommandBuffer
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkCommandBuffer.html).
/// Maintained by the user.
uint64_t command_buffers;
/// The texture sampler that would be used in rendering texture.
/// This field holds a [VkSampler
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkSampler.html).
/// Maintained by the user.
uint64_t texture_sampler;
/// The number of images in the swapchain.
uint32_t swapchain_image_count;
/// The width of the display area.
uint32_t image_width;
/// The height of the display area.
uint32_t image_height;
} CardboardVulkanDistortionRendererConfig;

/// Struct to set Vulkan distortion renderer target.
typedef struct CardboardVulkanDistortionRendererTarget {
/// The queue that the command buffers will be submitted to.
/// This field holds a [VkQueue
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkQueue.html).
/// Maintained by the user.
uint64_t vk_queue;
/// The object specifying a queue submit operation.
/// This field holds a [VkSubmitInfo
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkSubmitInfo.html).
/// Maintained by the user.
uint64_t vk_submits_info;
/// The fence to be signaled once all submitted command buffers have
/// completed execution. It is optional, in that, it could be set to
/// VK_NULL_HANDLE.
/// This field holds a [VkFence
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkFence.html).
/// Maintained by the user.
uint64_t vk_fence;
/// The object specifying parameters of the presentation.
/// This field holds a [VkPresentInfoKHR
/// value](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkPresentInfoKHR.html).
/// Maintained by the user.
uint64_t vk_present_info;
/// The index of the image in the swapchain.
uint32_t swapchain_image_index;
} CardboardVulkanDistortionRendererTarget;

/// TODO (b/205317247): Rename it to 'CardboardMetalDistortionRendererTarget'.
/// Struct to set Metal distortion renderer target configuration.
typedef struct CardboardDistortionRendererTargetConfig {
/// MTLRenderCommandEncoder id.
Expand Down Expand Up @@ -194,15 +279,20 @@ extern "C" {
/// @p context:
///
/// -
/// <a href="https://developer.android.com/reference/android/content/Context#getFilesDir()">Context.getFilesDir()</a>
/// <a
/// href="https://developer.android.com/reference/android/content/Context#getFilesDir()">Context.getFilesDir()</a>
/// -
/// <a href="https://developer.android.com/reference/android/content/Context#getResources()">Context.getResources()</a>
/// <a
/// href="https://developer.android.com/reference/android/content/Context#getResources()">Context.getResources()</a>
/// -
/// <a href="https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.String)">Context.getSystemService(Context.WINDOW_SERVICE)</a>
/// <a
/// href="https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.String)">Context.getSystemService(Context.WINDOW_SERVICE)</a>
/// -
/// <a href="https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)">Context.startActivity(Intent)</a>
/// <a
/// href="https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)">Context.startActivity(Intent)</a>
/// -
/// <a href="https://developer.android.com/reference/android/content/Context#getDisplay()">Context.getDisplay()</a>
/// <a
/// href="https://developer.android.com/reference/android/content/Context#getDisplay()">Context.getDisplay()</a>
///
/// @pre @p vm Must not be null.
/// @pre @p context Must not be null.
Expand Down Expand Up @@ -381,8 +471,10 @@ CardboardDistortionRenderer* CardboardMetalDistortionRenderer_create(
/// Creates a new distortion renderer object. It uses Vulkan as the rendering
/// API. Must be called from the render thread.
///
/// @param[in] config Distortion renderer configuration.
/// @return Distortion renderer object pointer
CardboardDistortionRenderer* CardboardVulkanDistortionRenderer_create();
CardboardDistortionRenderer* CardboardVulkanDistortionRenderer_create(
const CardboardVulkanDistortionRendererConfig* config);

/// Destroys and releases memory used by the provided distortion renderer
/// object. Must be called from render thread.
Expand Down Expand Up @@ -417,9 +509,13 @@ void CardboardDistortionRenderer_setMesh(CardboardDistortionRenderer* renderer,
///
/// @param[in] renderer Distortion renderer object pointer.
/// @param[in] target Target configuration.
/// When using OpenGL ES 2.x and OpenGL ES 3.x, this field corresponds to a
/// GLuint variable. When using Metal, this field corresponds to a variable
/// pointing to an CardboardDistortionRendererTargetConfig structure.
/// This parameter is some other type transformed via `reinterpret_cast`
/// to a `uint64_t`. The original type of this parameter depends on the
/// underlying API used as follows:
///
/// * OpenGL ES 2.x or 3.x: @c GLuint.
/// * Metal: @c CardboardDistortionRendererTargetConfig*.
/// * Vulkan: @c CardboardVulkanDistortionRendererTarget*.
/// @param[in] x x coordinate of the rectangle's
/// lower left corner in pixels.
/// @param[in] y y coordinate of the rectangle's
Expand Down Expand Up @@ -504,10 +600,13 @@ void CardboardHeadTracker_resume(CardboardHeadTracker* head_tracker);
///
/// @details On Android devices, @p timestamp_ns must be in system boot time
/// (see [CLOCK_BOOTTIME](https://linux.die.net/man/2/clock_gettime))
/// clock (see [Android Timestamp](https://developer.android.com/reference/android/hardware/SensorEvent#timestamp)).
/// clock (see [Android
/// Timestamp](https://developer.android.com/reference/android/hardware/SensorEvent#timestamp)).
/// On iOS devices, @p timestamp_ns must be in system uptime raw
/// (see [CLOCK_UPTIME_RAW](http://www.manpagez.com/man/3/clock_gettime/))
/// clock (see [Apple Timestamp](https://developer.apple.com/documentation/coremotion/cmlogitem/1615939-timestamp?language=objc)).
/// (see
/// [CLOCK_UPTIME_RAW](http://www.manpagez.com/man/3/clock_gettime/))
/// clock (see [Apple
/// Timestamp](https://developer.apple.com/documentation/coremotion/cmlogitem/1615939-timestamp?language=objc)).
///
/// @pre @p head_tracker Must not be null.
/// @pre @p position Must not be null.
Expand Down
30 changes: 30 additions & 0 deletions sdk/rendering/android/shaders/distortion.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#version 330
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
precision mediump float;

layout (binding = 0) uniform sampler2D u_Texture;
layout (location = 0) in vec2 v_TexCoords;
layout (location = 1) in vec2 u_Start;
layout (location = 2) in vec2 u_End;
layout (location = 0) out vec4 o_FragColor;

void main() {
vec2 coords = u_Start + v_TexCoords * (u_End - u_Start);
o_FragColor = texture(u_Texture, v_TexCoords);
}
Loading

0 comments on commit f021e6c

Please sign in to comment.