List of usage examples for android.opengl GLES20 glCreateShader
public static native int glCreateShader(int type);
From source file:Main.java
public static int loadShader(int type, String shaderCode) { int shader = GLES20.glCreateShader(type); GLES20.glShaderSource(shader, shaderCode); GLES20.glCompileShader(shader);//w w w. ja va 2 s .com return shader; }
From source file:Main.java
public static int loadShader(String vss, String fss) { int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); GLES20.glShaderSource(vshader, vss); GLES20.glCompileShader(vshader);//w ww . j a va 2s. co m int[] compiled = new int[1]; GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.e("Shader", "Could not compile vshader"); Log.v("Shader", "Could not compile vshader:" + GLES20.glGetShaderInfoLog(vshader)); GLES20.glDeleteShader(vshader); vshader = 0; } int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); GLES20.glShaderSource(fshader, fss); GLES20.glCompileShader(fshader); GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.e("Shader", "Could not compile fshader"); Log.v("Shader", "Could not compile fshader:" + GLES20.glGetShaderInfoLog(fshader)); GLES20.glDeleteShader(fshader); fshader = 0; } int program = GLES20.glCreateProgram(); GLES20.glAttachShader(program, vshader); GLES20.glAttachShader(program, fshader); GLES20.glLinkProgram(program); return program; }
From source file:Main.java
public static int loadShader(int type, String shaderCode) { int shaderHandle = GLES20.glCreateShader(type); if (shaderHandle != 0) { GLES20.glShaderSource(shaderHandle, shaderCode); GLES20.glCompileShader(shaderHandle); // Get the compilation status. final int[] compileStatus = new int[1]; GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0); // If the compilation failed, delete the shader. if (compileStatus[0] == 0) { Log.v(TAG, "Shader fail info: " + GLES20.glGetShaderInfoLog(shaderHandle)); GLES20.glDeleteShader(shaderHandle); shaderHandle = 0;/*from w w w .jav a2s .c om*/ } } if (shaderHandle == 0) { throw new RuntimeException("Error creating shader " + type); } return shaderHandle; }
From source file:Main.java
private static int compileShader(int target, String source, int[] output) { output[0] = GLES20.glCreateShader(target); // const GLchar *str = src.c_str(); GLES20.glShaderSource(output[0], source); GLES20.glCompileShader(output[0]);//from w w w . j av a2s .co m checkGLError("Compile shader"); int[] status = new int[1]; GLES20.glGetShaderiv(output[0], GLES20.GL_COMPILE_STATUS, status, 0); if (status[0] == 0) { Log.e(TAG, "Failed to compile shader: " + GLES20.glGetShaderInfoLog(output[0])); GLES20.glDeleteShader(output[0]); } return status[0]; }
From source file:Main.java
public static int loadShader(int type, String shaderCode) { // create a vertex shader type (GLES20.GL_VERTEX_SHADER) // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER) int shader = GLES20.glCreateShader(type); // add the source code to the shader and compile it GLES20.glShaderSource(shader, shaderCode); GLES20.glCompileShader(shader);/* w w w . j ava 2 s . c o m*/ return shader; }
From source file:Main.java
public static int createShader(int type, String source) { String typeString;//from w ww . jav a 2 s . co m if (type == GLES20.GL_VERTEX_SHADER) typeString = "vertex"; else if (type == GLES20.GL_FRAGMENT_SHADER) typeString = "fragment"; else throw new RuntimeException("Unknown shader type"); int sh = GLES20.glCreateShader(type); if (sh <= 0) { throw new RuntimeException("Could not create " + typeString + " shader"); } GLES20.glShaderSource(sh, source); GLES20.glCompileShader(sh); int[] status = new int[1]; GLES20.glGetShaderiv(sh, GLES20.GL_COMPILE_STATUS, status, 0); if (status[0] <= 0) { String message = GLES20.glGetShaderInfoLog(sh); GLES20.glDeleteShader(sh); throw new RuntimeException("Could not compile " + typeString + " shader: " + message); } return sh; }
From source file:Main.java
/** * Converts a raw text file, saved as a resource, into an OpenGL ES shader. * * @param type The type of shader we will be creating. * @param resId The resource ID of the raw text file about to be turned into a shader. * @return The shader object handler./*www . ja va 2s . co m*/ */ public static int loadGLShader(Context con, int type, int resId) { String code = readRawTextFile(con, resId); int shader = GLES20.glCreateShader(type); GLES20.glShaderSource(shader, code); GLES20.glCompileShader(shader); // Get the compilation status. final int[] compileStatus = new int[1]; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0); // If the compilation failed, delete the shader. if (compileStatus[0] == 0) { Log.e(TAG, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } if (shader == 0) { throw new RuntimeException("Error creating shader."); } return shader; }
From source file:Main.java
public static int loadShader(final String strSource, final int iType) { int[] compiled = new int[1]; int iShader = GLES20.glCreateShader(iType); GLES20.glShaderSource(iShader, strSource); GLES20.glCompileShader(iShader);/*w w w. java2 s . c o m*/ GLES20.glGetShaderiv(iShader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.d("Load Shader Failed", "Compilation\n" + GLES20.glGetShaderInfoLog(iShader)); return 0; } return iShader; }
From source file:Main.java
/** * Compiles the provided shader source./* ww w . j a v a 2 s.com*/ * * @return A handle to the shader, or 0 on failure. */ public static int loadShader(int shaderType, String source) { int shader = GLES20.glCreateShader(shaderType); checkGlError("glCreateShader type=" + shaderType); GLES20.glShaderSource(shader, source); GLES20.glCompileShader(shader); int[] compiled = new int[1]; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.e(TAG, "Could not compile shader " + shaderType + ":"); Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } return shader; }
From source file:Main.java
static int initShader(int shaderType, String source) { int shader = GLES20.glCreateShader(shaderType); if (shader != 0) { GLES20.glShaderSource(shader, source); GLES20.glCompileShader(shader);//from w w w . j av a 2 s . c om int[] glStatusVar = { GLES20.GL_FALSE }; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, glStatusVar, 0); if (glStatusVar[0] == GLES20.GL_FALSE) { Log.e(LOGTAG, "Could NOT compile shader " + shaderType + " : " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } } return shader; }