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.
5 package org
.chromium
.chromoting
;
7 import android
.graphics
.Bitmap
;
8 import android
.opengl
.GLES20
;
9 import android
.opengl
.GLUtils
;
12 * Helper class for working with OpenGL textures.
14 public class TextureHelper
{
16 * Create new texture handle.
17 * @return New texture handle.
19 public static int createTextureHandle() {
20 int[] textureDataHandle
= new int[1];
21 GLES20
.glGenTextures(1, textureDataHandle
, 0);
22 if (textureDataHandle
[0] != 0) {
23 return textureDataHandle
[0];
25 throw new RuntimeException("Error generating texture handle.");
30 * Link desktop texture with a handle.
31 * @param textureDataHandle the handle to attach texture to
33 public static void linkTexture(int textureDataHandle
, Bitmap bitmap
) {
34 // Delete previously attached texture.
35 GLES20
.glDeleteTextures(1, new int[]{textureDataHandle
}, 0);
37 // Bind to the texture in OpenGL.
38 GLES20
.glBindTexture(GLES20
.GL_TEXTURE_2D
, textureDataHandle
);
40 GLES20
.glTexParameteri(GLES20
.GL_TEXTURE_2D
,
41 GLES20
.GL_TEXTURE_MIN_FILTER
, GLES20
.GL_NEAREST
);
42 GLES20
.glTexParameteri(GLES20
.GL_TEXTURE_2D
,
43 GLES20
.GL_TEXTURE_MAG_FILTER
, GLES20
.GL_NEAREST
);
45 // Load the bitmap into the bound texture.
46 GLUtils
.texImage2D(GLES20
.GL_TEXTURE_2D
, 0, bitmap
, 0);