Java Code Examples for android.opengl.GLES20#glGetShaderInfoLog()

The following examples show how to use android.opengl.GLES20#glGetShaderInfoLog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLToolbox.java    From ImageEffects with Eclipse Public License 1.0 6 votes vote down vote up
public static int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        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) {
            String info = GLES20.glGetShaderInfoLog(shader);
            GLES20.glDeleteShader(shader);
            shader = 0;
            throw new RuntimeException("Could not compile shader " +
            shaderType + ":" + info);
        }
    }
    return shader;
}
 
Example 2
Source File: GlShader.java    From sealrtc-android with MIT License 6 votes vote down vote up
private static int compileShader(int shaderType, String source) {
    final int shader = GLES20.glCreateShader(shaderType);
    if (shader == 0) {
        throw new RuntimeException(
                "glCreateShader() failed. GLES20 error: " + GLES20.glGetError());
    }
    GLES20.glShaderSource(shader, source);
    GLES20.glCompileShader(shader);
    int[] compileStatus = new int[] {GLES20.GL_FALSE};
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
    if (compileStatus[0] != GLES20.GL_TRUE) {
        Log.e(
                TAG,
                "Could not compile shader "
                        + shaderType
                        + ":"
                        + GLES20.glGetShaderInfoLog(shader));
        throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
    }
    GlUtil.checkNoGLES2Error("compileShader");
    return shader;
}
 
Example 3
Source File: ShaderHelper.java    From EZFilter with MIT License 6 votes vote down vote up
public static int compileShader(String shaderSource, int shaderType) {
    String errorInfo = "none";

    int shaderHandle = GLES20.glCreateShader(shaderType);
    if (shaderHandle != 0) {
        GLES20.glShaderSource(shaderHandle, shaderSource);
        GLES20.glCompileShader(shaderHandle);
        final int[] compileStatus = new int[1];
        GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
        if (compileStatus[0] == 0) {
            errorInfo = GLES20.glGetShaderInfoLog(shaderHandle);
            GLES20.glDeleteShader(shaderHandle);
            shaderHandle = 0;
        }
    }
    if (shaderHandle == 0) {
        throw new RuntimeException("failed to compile shader. Reason: " + errorInfo);
    }

    return shaderHandle;
}
 
Example 4
Source File: GlShader.java    From VideoCRE with MIT License 6 votes vote down vote up
private static int compileShader(int shaderType, String source) {
  final int shader = GLES20.glCreateShader(shaderType);
  if (shader == 0) {
    throw new RuntimeException("glCreateShader() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  int[] compileStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
  if (compileStatus[0] != GLES20.GL_TRUE) {
    Logging.e(
        TAG, "Could not compile shader " + shaderType + ":" + GLES20.glGetShaderInfoLog(shader));
    throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
  }
  GlUtil.checkNoGLES2Error("compileShader");
  return shader;
}
 
Example 5
Source File: GLRenderer.java    From HoloKilo with GNU General Public License v3.0 6 votes vote down vote up
static void printLog(int shader) {

        IntBuffer logLength = IntBuffer.allocate(1);
        if (GLES20.glIsShader(shader)) {
            GLES20.glGetShaderiv(shader, GLES20.GL_INFO_LOG_LENGTH, logLength);
        } else if (GLES20.glIsProgram(shader)) {
            GLES20.glGetProgramiv(shader, GLES20.GL_INFO_LOG_LENGTH, logLength);
        } else {
            Log.e(Config.TAG, "printlog: Not a shader or a program");
            return;
        }

        String result = "";
        if (GLES20.glIsShader(shader))
            result = GLES20.glGetShaderInfoLog(shader);
        else if (GLES20.glIsProgram(shader))
            result = GLES20.glGetProgramInfoLog(shader);

        Log.e(Config.TAG, result);

    }
 
Example 6
Source File: GlShader.java    From webrtc_android with MIT License 6 votes vote down vote up
private static int compileShader(int shaderType, String source) {
  final int shader = GLES20.glCreateShader(shaderType);
  if (shader == 0) {
    throw new RuntimeException("glCreateShader() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  int[] compileStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
  if (compileStatus[0] != GLES20.GL_TRUE) {
    Logging.e(
        TAG, "Compile error " + GLES20.glGetShaderInfoLog(shader) + " in shader:\n" + source);
    throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
  }
  GlUtil.checkNoGLES2Error("compileShader");
  return shader;
}
 
Example 7
Source File: GLToolbox.java    From Rocko-Android-Demos with Apache License 2.0 6 votes vote down vote up
public static int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        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) {
            String info = GLES20.glGetShaderInfoLog(shader);
            GLES20.glDeleteShader(shader);
            shader = 0;
            throw new RuntimeException("Could not compile shader " +
                    shaderType + ":" + info);
        }
    }
    return shader;
}
 
Example 8
Source File: Program.java    From ShaderEditor with MIT License 5 votes vote down vote up
private static int compileShader(int type, String src) {
	int s = GLES20.glCreateShader(type);

	if (s == 0) {
		infoLog = "Cannot create shader";
		return 0;
	}

	GLES20.glShaderSource(s, src);
	GLES20.glCompileShader(s);

	int[] compiled = new int[1];
	GLES20.glGetShaderiv(
			s,
			GLES20.GL_COMPILE_STATUS,
			compiled,
			0);

	if (compiled[0] == 0) {
		infoLog = GLES20.glGetShaderInfoLog(s);

		GLES20.glDeleteShader(s);
		s = 0;
	}

	return s;
}
 
Example 9
Source File: Shader.java    From PD-classes with GNU General Public License v3.0 5 votes vote down vote up
public void compile() {
	GLES20.glCompileShader( handle );

	int[] status = new int[1];
	GLES20.glGetShaderiv( handle, GLES20.GL_COMPILE_STATUS, status, 0 );
	if (status[0] == GLES20.GL_FALSE) {
		throw new Error( GLES20.glGetShaderInfoLog( handle ) );
	}
}
 
Example 10
Source File: RRGLProgram.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
private void compileAndAttachShader(final int type, final String source) {

		switch(type) {
			case GLES20.GL_FRAGMENT_SHADER: if(mFragmentShaderHandle != null) throw new RuntimeException(); break;
			case GLES20.GL_VERTEX_SHADER:   if(mVertexShaderHandle != null) throw new RuntimeException(); break;
			default: throw new RuntimeException("Unknown shader type.");
		}

		final int shaderHandle = GLES20.glCreateShader(type);
		if(shaderHandle == 0) {
			throw new RuntimeException("Error creating shader.");
		}

		GLES20.glShaderSource(shaderHandle, source);
		GLES20.glCompileShader(shaderHandle);

		final int[] compileStatus = new int[1];
		GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

		if(compileStatus[0] == 0) {
			final String log = GLES20.glGetShaderInfoLog(mHandle);
			GLES20.glDeleteShader(shaderHandle);
			throw new RuntimeException(String.format(Locale.US, "Shader compile error: \"%s\".", log));
		}

		GLES20.glAttachShader(mHandle, shaderHandle);

		switch(type) {
			case GLES20.GL_FRAGMENT_SHADER: mFragmentShaderHandle = shaderHandle; break;
			case GLES20.GL_VERTEX_SHADER:   mVertexShaderHandle = shaderHandle; break;
			default: throw new RuntimeException("Unknown shader type.");
		}
	}
 
Example 11
Source File: Shader.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void compile() {
	GLES20.glCompileShader( handle );

	int[] status = new int[1];
	GLES20.glGetShaderiv( handle, GLES20.GL_COMPILE_STATUS, status, 0 );
	if (status[0] == GLES20.GL_FALSE) {
		throw new Error( GLES20.glGetShaderInfoLog( handle ) );
	}
}
 
Example 12
Source File: GLES20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
private int createShader(String name, int type) throws IOException {
	int shader = GLES20.glCreateShader(type);

	BufferedReader is = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/"+name)));
	StringBuilder source = new StringBuilder();
	String line;

	while((line = is.readLine()) != null) {
		source.append(line);
		if(line.startsWith("#version")) {
			//source.append(" es");
		}
		source.append("\n");
	}

	GLES20.glShaderSource(shader, source.toString());
	GLES20.glCompileShader(shader);


	String log = GLES20.glGetShaderInfoLog(shader);
	if(!log.isEmpty()) System.out.print("info log of " + name + "=====\n" + log + "==== end\n");

	int[] compile_status = new int[1];
	GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compile_status, 0);
	if(compile_status[0] == 0) {
		GLES20.glDeleteShader(shader);
		throw new Error("Could not compile " + name);
	}

	return shader;
}
 
Example 13
Source File: ShaderProgram.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private static int compileShader(final String pSource, final int pType) throws ShaderProgramException {
	final int shaderID = GLES20.glCreateShader(pType);
	if(shaderID == 0) {
		throw new ShaderProgramException("Could not create Shader of type: '" + pType + '"');
	}

	GLES20.glShaderSource(shaderID, pSource);
	GLES20.glCompileShader(shaderID);

	GLES20.glGetShaderiv(shaderID, GLES20.GL_COMPILE_STATUS, ShaderProgram.HARDWAREID_CONTAINER, 0);
	if(ShaderProgram.HARDWAREID_CONTAINER[0] == 0) {
		throw new ShaderProgramCompileException(GLES20.glGetShaderInfoLog(shaderID), pSource);
	}
	return shaderID;
}
 
Example 14
Source File: ShaderProgram.java    From tilt-game-android with MIT License 5 votes vote down vote up
private static int compileShader(final String pSource, final int pType) throws ShaderProgramException {
	final int shaderID = GLES20.glCreateShader(pType);
	if (shaderID == 0) {
		throw new ShaderProgramException("Could not create Shader of type: '" + pType + '"');
	}

	GLES20.glShaderSource(shaderID, pSource);
	GLES20.glCompileShader(shaderID);

	GLES20.glGetShaderiv(shaderID, GLES20.GL_COMPILE_STATUS, ShaderProgram.HARDWAREID_CONTAINER, 0);
	if (ShaderProgram.HARDWAREID_CONTAINER[0] == 0) {
		throw new ShaderProgramCompileException(GLES20.glGetShaderInfoLog(shaderID), pSource);
	}
	return shaderID;
}
 
Example 15
Source File: GLToolbox.java    From android-MediaEffects with Apache License 2.0 5 votes vote down vote up
public static int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        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) {
            String info = GLES20.glGetShaderInfoLog(shader);
            GLES20.glDeleteShader(shader);
            throw new RuntimeException("Could not compile shader " + shaderType + ":" + info);
        }
    }
    return shader;
}
 
Example 16
Source File: GLHelper.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
public static int loadShader(String shaderStr, int type) {
    int[] compiled = new int[1];
    int iShader = GLES20.glCreateShader(type);
    checkGlError("");
    GLES20.glShaderSource(iShader, shaderStr);
    checkGlError("");
    GLES20.glCompileShader(iShader);
    checkGlError("");
    GLES20.glGetShaderiv(iShader, GLES20.GL_COMPILE_STATUS, compiled, 0);
    checkGlError("");
    if (compiled[0] == 0) {
        throw new RuntimeException("Load Shader Failed Compilation\n" + GLES20.glGetShaderInfoLog(iShader));
    }
    return iShader;
}
 
Example 17
Source File: EffectsShader.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private int loadShader(int shaderType, String source) throws Exception {
	int shader = GLES20.glCreateShader(shaderType);
	if (shader != 0) {
		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) {
			String error = GLES20.glGetShaderInfoLog(shader);
			GLES20.glDeleteShader(shader);
			throw new Exception(error);
		}
	}
	return shader;
}
 
Example 18
Source File: Utils.java    From alynx-live-wallpaper with Apache License 2.0 5 votes vote down vote up
static int compileShaderResourceGLES20(
    @NonNull Context context,
    final int shaderType,
    final int shaderRes
) throws RuntimeException {
    final InputStream inputStream = context.getResources().openRawResource(shaderRes);
    final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
    String line;
    final StringBuilder stringBuilder = new StringBuilder();
    try {
        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append('\n');
        }
    } catch (IOException e) {
        e.printStackTrace();
        return 0;
    }
    final String shaderSource = stringBuilder.toString();
    int shader = GLES20.glCreateShader(shaderType);
    if (shader == 0) {
        throw new RuntimeException("Failed to create shader");
    }
    GLES20.glShaderSource(shader, shaderSource);
    GLES20.glCompileShader(shader);
    final int[] status = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        final String log = GLES20.glGetShaderInfoLog(shader);
        GLES20.glDeleteShader(shader);
        throw new RuntimeException(log);
    }
    return shader;
}
 
Example 19
Source File: GLToolbox.java    From graphics-samples with Apache License 2.0 5 votes vote down vote up
public static int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        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) {
            String info = GLES20.glGetShaderInfoLog(shader);
            GLES20.glDeleteShader(shader);
            throw new RuntimeException("Could not compile shader " + shaderType + ":" + info);
        }
    }
    return shader;
}
 
Example 20
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getShaderInfoLog(int shader) {
    return GLES20.glGetShaderInfoLog(shader);
}