Skip to content

Commit

Permalink
GL: Move loadAsset to GlProgram, where it's used.
Browse files Browse the repository at this point in the history
(Also, make some public methods private)

PiperOrigin-RevId: 481912071
  • Loading branch information
dway123 authored and marcbaechinger committed Oct 20, 2022
1 parent bd9181e commit a404fde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
Expand Up @@ -22,6 +22,7 @@
import android.opengl.GLES20;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -54,9 +55,25 @@ public final class GlProgram {
*/
public GlProgram(Context context, String vertexShaderFilePath, String fragmentShaderFilePath)
throws IOException, GlUtil.GlException {
this(
GlUtil.loadAsset(context, vertexShaderFilePath),
GlUtil.loadAsset(context, fragmentShaderFilePath));
this(loadAsset(context, vertexShaderFilePath), loadAsset(context, fragmentShaderFilePath));
}

/**
* Loads a file from the assets folder.
*
* @param context The {@link Context}.
* @param assetPath The path to the file to load, from the assets folder.
* @return The content of the file to load.
* @throws IOException If the file couldn't be read.
*/
public static String loadAsset(Context context, String assetPath) throws IOException {
@Nullable InputStream inputStream = null;
try {
inputStream = context.getAssets().open(assetPath);
return Util.fromUtf8Bytes(Util.toByteArray(inputStream));
} finally {
Util.closeQuietly(inputStream);
}
}

/**
Expand Down
Expand Up @@ -32,8 +32,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
Expand All @@ -58,8 +56,6 @@ public GlException(String message) {
/** Length of the normalized device coordinate (NDC) space, which spans from -1 to 1. */
public static final float LENGTH_NDC = 2f;

private static final String TAG = "GlUtil";

// https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_protected_content.txt
private static final String EXTENSION_PROTECTED_CONTENT = "EGL_EXT_protected_content";
// https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_surfaceless_context.txt
Expand Down Expand Up @@ -351,7 +347,7 @@ public static void checkGlError() throws GlException {
* @param height The height for a texture.
* @throws GlException If the texture width or height is invalid.
*/
public static void assertValidTextureSize(int width, int height) throws GlException {
private static void assertValidTextureSize(int width, int height) throws GlException {
// TODO(b/201293185): Consider handling adjustments for sizes > GL_MAX_TEXTURE_SIZE
// (ex. downscaling appropriately) in a texture processor instead of asserting incorrect
// values.
Expand Down Expand Up @@ -459,29 +455,11 @@ public static FloatBuffer createBuffer(float[] data) {
*
* @param capacity The new buffer's capacity, in floats.
*/
public static FloatBuffer createBuffer(int capacity) {
private static FloatBuffer createBuffer(int capacity) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(capacity * C.BYTES_PER_FLOAT);
return byteBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
}

/**
* Loads a file from the assets folder.
*
* @param context The {@link Context}.
* @param assetPath The path to the file to load, from the assets folder.
* @return The content of the file to load.
* @throws IOException If the file couldn't be read.
*/
public static String loadAsset(Context context, String assetPath) throws IOException {
@Nullable InputStream inputStream = null;
try {
inputStream = context.getAssets().open(assetPath);
return Util.fromUtf8Bytes(Util.toByteArray(inputStream));
} finally {
Util.closeQuietly(inputStream);
}
}

/**
* Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and
* GL_CLAMP_TO_EDGE wrapping.
Expand Down

0 comments on commit a404fde

Please sign in to comment.