November 6, 2019 update:
  • There's a new open source Cardboard SDK for iOS and Android NDK that offers a streamlined API, improved device compatibility, and built-in viewer profile QR code scanning. A corresponding Unity package (SDK) is planned for a future release. We recommend that all developers actively building for Google Cardboard migrate (iOS, Android NDK) to the new Cardboard SDK.
October 15, 2019 update:
  • The Daydream View VR headset is no longer available for purchase. However, you can continue to use the existing Google VR SDK to update and distribute your apps to the Google Play Store, and make them available to users in the Daydream app.

BufferViewport

public class BufferViewport

Encapsulated information about where to find the data in the client's target for a given region (e.g., the region for a particular eye).

This includes the viewport bounds for that region, the field of view, and the type of eye that has been rendered. This latter is used to calculate what kind of distortion to apply when the region is distorted to the screen.

A BufferViewport instance can be created via GvrApi, and populated via BufferViewportList.

Nested Classes

class BufferViewport.EyeType The type of eye corresponding to the BufferViewport
class BufferViewport.Reprojection Types of asynchronous reprojection. 

Constants

int BUFFER_INDEX_EXTERNAL_SURFACE Source buffer index that indicates that the viewport contents should be taken directly from its external surface rather than from one of the frame's buffers.
int EXTERNAL_SURFACE_ID_NONE External surface ID that represents a nonexistent surface.

Public Methods

boolean
equals(Object other)
int
getExternalSurfaceId()
Gets the GvrLayout issued Surface ID.
float
getOpacity()
Gets the opacity to apply to the specified viewport.
int
getReprojection()
Gets the type of reprojection to perform on the viewport.
int
getSourceBufferIndex()
Gets the index of the source buffer that contains the viewport's pixels.
void
getSourceFov(RectF sourceFovOut)
Gets the eye's field of view in degrees.
void
getSourceUv(RectF sourceUvOut)
Gets the UV coordinates within the buffer where this viewport's pixels are located.
int
getTargetEye()
Gets the BufferViewport.EyeType for the viewport.
void
getTransform(float[] transform)
Gets the matrix that transforms a quad with vertices (-1, -1, 0), (1, -1, 0), (-1, 1, 0), (1, 1, 0) representing the viewport contents to its desired position in eye space for the target eye.
void
setExternalSurfaceId(int id)
Sets the ID of the externally-managed Surface texture from which this viewport reads.
void
setOpacity(float opacity)
Sets the opacity to apply to the specified viewport.
void
setReprojection(int reprojection)
Sets the type of reprojection to perform on the viewport.
void
setSourceBufferIndex(int index)
Sets the index of the source buffer that contains the viewport's pixels.
void
setSourceFov(RectF sourceFov)
Sets the eye's field of view in degrees.
void
setSourceLayer(int layerIndex)
Sets the layer in a multiview buffer from which the viewport should sample.
void
setSourceUv(RectF sourceUv)
Sets the UV range within the buffer where this viewport's pixels are located.
void
setTargetEye(int eye)
Sets the BufferViewport.EyeType for the viewport.
void
setTransform(float[] transform)
Sets the matrix that transforms a quad with vertices (-1, -1, 0), (1, -1, 0), (-1, 1, 0), (1, 1, 0) that represents the viewport contents to its correct position in eye space for the target eye.
void
shutdown()
Shuts down the BufferViewport instance, freeing associated resources.

Inherited Methods

Constants

public static final int BUFFER_INDEX_EXTERNAL_SURFACE

Source buffer index that indicates that the viewport contents should be taken directly from its external surface rather than from one of the frame's buffers.

Constant Value: -1

public static final int EXTERNAL_SURFACE_ID_NONE

External surface ID that represents a nonexistent surface.

Constant Value: -1

Public Methods

public boolean equals (Object other)

Parameters
other

public int getExternalSurfaceId ()

Gets the GvrLayout issued Surface ID. EXTERNAL_SURFACE_ID_NONE if no Surface is set.

Returns
  • The ID of the externally-managed surface.

public float getOpacity ()

Gets the opacity to apply to the specified viewport.

Returns
  • Opacity Defaults to 1.

public int getReprojection ()

Gets the type of reprojection to perform on the viewport.

Returns

public int getSourceBufferIndex ()

Gets the index of the source buffer that contains the viewport's pixels.

public void getSourceFov (RectF sourceFovOut)

Gets the eye's field of view in degrees.

Parameters
sourceFovOut The rect to populate with the eye's field-of-view.

public void getSourceUv (RectF sourceUvOut)

Gets the UV coordinates within the buffer where this viewport's pixels are located.

Parameters
sourceUvOut The rect to populate with the current source UV coordinates.

public int getTargetEye ()

Gets the BufferViewport.EyeType for the viewport.

public void getTransform (float[] transform)

Gets the matrix that transforms a quad with vertices (-1, -1, 0), (1, -1, 0), (-1, 1, 0), (1, 1, 0) representing the viewport contents to its desired position in eye space for the target eye.

Parameters
transform The array in which the transform matrix should be returned.

public void setExternalSurfaceId (int id)

Sets the ID of the externally-managed Surface texture from which this viewport reads.

Parameters
id The ID of the external surface, as assigned by GvrLayout. A value of EXTERNAL_SURFACE_ID_NONE will disable use of the external surface.

public void setOpacity (float opacity)

Sets the opacity to apply to the specified viewport.

Parameters
opacity The opacity that will be applied to the viewport, it should be within [0,1].

public void setReprojection (int reprojection)

Sets the type of reprojection to perform on the viewport. Viewports that display world content should use full reprojection. Viewports that display head-locked UI should disable reprojection to avoid excessive judder. The default is to perform full reprojection.

Parameters
reprojection Type of reprojection (see BufferViewport.Reprojection) that will be applied to the viewport.

public void setSourceBufferIndex (int index)

Sets the index of the source buffer that contains the viewport's pixels.

Parameters
index The new buffer index. This is either an index into the array of BufferSpec objects passed when creating the swap chain or BUFFER_INDEX_EXTERNAL_SURFACE when an external surface is used as the image source.

public void setSourceFov (RectF sourceFov)

Sets the eye's field of view in degrees.

Parameters
sourceFov The new field of view.

public void setSourceLayer (int layerIndex)

Sets the layer in a multiview buffer from which the viewport should sample.

Parameters
layerIndex The layer in the array texture that distortion samples from. Must be non-negative. Defaults to 0.

public void setSourceUv (RectF sourceUv)

Sets the UV range within the buffer where this viewport's pixels are located.

Parameters
sourceUv The rect with new source UV coordinates. The coordinates must satisfy left <= right and bottom <= top.

public void setTargetEye (int eye)

Sets the BufferViewport.EyeType for the viewport.

Parameters
eye

public void setTransform (float[] transform)

Sets the matrix that transforms a quad with vertices (-1, -1, 0), (1, -1, 0), (-1, 1, 0), (1, 1, 0) that represents the viewport contents to its correct position in eye space for the target eye. This is a more general version of setSourceFov.

Parameters
transform The new projection matrix to set.

public void shutdown ()

Shuts down the BufferViewport instance, freeing associated resources.

Note: The caller is responsible for ensuring that this BufferViewport isn't used after shutdown.