OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chromoting.cardboard; | |
6 | |
7 import java.nio.ByteBuffer; | |
8 import java.nio.ByteOrder; | |
9 import java.nio.FloatBuffer; | |
10 import java.nio.ShortBuffer; | |
11 | |
12 /** | |
13 * Utility class for Cardboard activity. | |
14 */ | |
15 public class CardboardUtil { | |
16 private static final int BYTES_PER_FLOAT = 4; | |
17 private static final int BYTES_PER_SHORT = 2; | |
18 | |
19 /** | |
20 * Create rectangular texture float buffer. | |
21 */ | |
22 public static FloatBuffer makeRectangularTextureBuffer(float left, float rig
ht, | |
23 float bottom, float top) { | |
24 float[] position = new float[] { | |
25 left, bottom, | |
26 left, top, | |
27 right, bottom, | |
28 left, top, | |
29 right, top, | |
30 right, bottom | |
31 }; | |
32 return makeFloatBuffer(position); | |
33 } | |
34 | |
35 /** | |
36 * Convert float array to a FloatBuffer for use in OpenGL calls. | |
37 */ | |
38 public static FloatBuffer makeFloatBuffer(float[] data) { | |
39 FloatBuffer result = ByteBuffer | |
40 .allocateDirect(data.length * BYTES_PER_FLOAT) | |
41 .order(ByteOrder.nativeOrder()).asFloatBuffer(); | |
42 result.put(data).position(0); | |
43 return result; | |
44 } | |
45 | |
46 /** | |
47 * Convert short array to a ShortBuffer for use in OpenGL calls. | |
48 */ | |
49 public static ShortBuffer makeShortBuffer(short[] data) { | |
50 ShortBuffer result = ByteBuffer | |
51 .allocateDirect(data.length * BYTES_PER_SHORT) | |
52 .order(ByteOrder.nativeOrder()).asShortBuffer(); | |
53 result.put(data).position(0); | |
54 return result; | |
55 } | |
56 } | |
OLD | NEW |