Java Code Examples for android.opengl.GLES20#GL_FALSE

The following examples show how to use android.opengl.GLES20#GL_FALSE . 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: GLRenderer.java    From HoloKilo with GNU General Public License v3.0 6 votes vote down vote up
static public int loadShader(int type, String shaderCode)
{
    int shader = GLES20.glCreateShader(type);

    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);
    IntBuffer compile = IntBuffer.allocate(1);
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compile);
    if (compile.get(0) == GLES20.GL_FALSE) {
        Log.e(Config.TAG, "Error:");
        Log.e(Config.TAG, shaderCode);
        Log.e(Config.TAG, "Fault:");
        printLog(shader);
        return 0;
    }

    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: SampleUtils.java    From VuforiaLibGDX with MIT License 5 votes vote down vote up
public static int createProgramFromShaderSrc(String vertexShaderSrc,
                                             String fragmentShaderSrc)
{
    int vertShader = initShader(GLES20.GL_VERTEX_SHADER, vertexShaderSrc);
    int fragShader = initShader(GLES20.GL_FRAGMENT_SHADER,
            fragmentShaderSrc);

    if (vertShader == 0 || fragShader == 0)
        return 0;

    int program = GLES20.glCreateProgram();
    if (program != 0)
    {
        GLES20.glAttachShader(program, vertShader);
        checkGLError("glAttchShader(vert)");

        GLES20.glAttachShader(program, fragShader);
        checkGLError("glAttchShader(frag)");

        GLES20.glLinkProgram(program);
        int[] glStatusVar = { GLES20.GL_FALSE };
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, glStatusVar,
                0);
        if (glStatusVar[0] == GLES20.GL_FALSE)
        {
            Log.e(
                    LOGTAG,
                    "Could NOT link program : "
                            + GLES20.glGetProgramInfoLog(program));
            GLES20.glDeleteProgram(program);
            program = 0;
        }
    }

    return program;
}
 
Example 4
Source File: Shader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private int linkProgram(int program) {
    GLES20.glLinkProgram(program);

    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e(GLES20.glGetProgramInfoLog(program));
        }
    }

    return linkStatus[0];
}
 
Example 5
Source File: GlShader.java    From VideoCRE with MIT License 5 votes vote down vote up
public GlShader(String vertexSource, String fragmentSource) {
  final int vertexShader = compileShader(GLES20.GL_VERTEX_SHADER, vertexSource);
  final int fragmentShader = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
  program = GLES20.glCreateProgram();
  if (program == 0) {
    throw new RuntimeException("glCreateProgram() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glAttachShader(program, vertexShader);
  GLES20.glAttachShader(program, fragmentShader);
  GLES20.glLinkProgram(program);
  int[] linkStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
  if (linkStatus[0] != GLES20.GL_TRUE) {
    Logging.e(TAG, "Could not link program: " + GLES20.glGetProgramInfoLog(program));
    throw new RuntimeException(GLES20.glGetProgramInfoLog(program));
  }
  // According to the documentation of glLinkProgram():
  // "After the link operation, applications are free to modify attached shader objects, compile
  // attached shader objects, detach shader objects, delete shader objects, and attach additional
  // shader objects. None of these operations affects the information log or the program that is
  // part of the program object."
  // But in practice, detaching shaders from the program seems to break some devices. Deleting the
  // shaders are fine however - it will delete them when they are no longer attached to a program.
  GLES20.glDeleteShader(vertexShader);
  GLES20.glDeleteShader(fragmentShader);
  GlUtil.checkNoGLES2Error("Creating GlShader");
}
 
Example 6
Source File: Shader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private int linkProgram(int program) {
    GLES20.glLinkProgram(program);

    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e(GLES20.glGetProgramInfoLog(program));
        }
    }

    return linkStatus[0];
}
 
Example 7
Source File: Shader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private CompilationResult compileShader(int type, String shaderCode) {
    int shader = GLES20.glCreateShader(type);
    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);

    int[] compileStatus = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
    if (compileStatus[0] == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e(GLES20.glGetShaderInfoLog(shader));
        }
    }

    return new CompilationResult(shader, compileStatus[0]);
}
 
Example 8
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 9
Source File: FrameRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private void addShader(int type, String source, int program) {
  int[] result = new int[]{
          GLES20.GL_FALSE
  };
  int shader = GLES20.glCreateShader(type);
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, result, 0);
  abortUnless(result[0] == GLES20.GL_TRUE,
          GLES20.glGetShaderInfoLog(shader) + ", source: " + source);
  GLES20.glAttachShader(program, shader);
  GLES20.glDeleteShader(shader);

  checkNoGLES2Error();
}
 
Example 10
Source File: Program.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public void link() {
	GLES20.glLinkProgram( handle );
	
	int[] status = new int[1];
	GLES20.glGetProgramiv( handle, GLES20.GL_LINK_STATUS, status, 0 );
	if (status[0] == GLES20.GL_FALSE) {
		throw new Error( GLES20.glGetProgramInfoLog( handle ) );
	}
}
 
Example 11
Source File: Shader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private CompilationResult compileShader(int type, String shaderCode) {
    int shader = GLES20.glCreateShader(type);
    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);

    int[] compileStatus = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
    if (compileStatus[0] == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e(GLES20.glGetShaderInfoLog(shader));
        }
    }

    return new CompilationResult(shader, compileStatus[0]);
}
 
Example 12
Source File: Shader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private CompilationResult compileShader(int type, String shaderCode) {
    int shader = GLES20.glCreateShader(type);
    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);

    int[] compileStatus = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
    if (compileStatus[0] == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e(GLES20.glGetShaderInfoLog(shader));
        }
    }

    return new CompilationResult(shader, compileStatus[0]);
}
 
Example 13
Source File: VideoRendererGui.java    From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
  Log.v(TAG, "VideoRendererGui.onSurfaceCreated");

  // Create program.
  program = GLES20.glCreateProgram();
  addShaderTo(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_STRING, program);
  addShaderTo(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_STRING, program);

  GLES20.glLinkProgram(program);
  int[] result = new int[] {
      GLES20.GL_FALSE
  };
  result[0] = GLES20.GL_FALSE;
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, result, 0);
  abortUnless(result[0] == GLES20.GL_TRUE,
      GLES20.glGetProgramInfoLog(program));
  GLES20.glUseProgram(program);

  GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "y_tex"), 0);
  GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "u_tex"), 1);
  GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "v_tex"), 2);

  synchronized (yuvImageRenderers) {
    // Create textures for all images.
    for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) {
      yuvImageRenderer.createTextures(program);
    }
    onSurfaceCreatedCalled = true;
  }
  checkNoGLES2Error();
  GLES20.glClearColor(0.0f, 0.0f, 0.3f, 1.0f);
}
 
Example 14
Source File: Shader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private int linkProgram(int program) {
    GLES20.glLinkProgram(program);

    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e(GLES20.glGetProgramInfoLog(program));
        }
    }

    return linkStatus[0];
}
 
Example 15
Source File: GlShader.java    From webrtc_android with MIT License 5 votes vote down vote up
public GlShader(String vertexSource, String fragmentSource) {
  final int vertexShader = compileShader(GLES20.GL_VERTEX_SHADER, vertexSource);
  final int fragmentShader = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
  program = GLES20.glCreateProgram();
  if (program == 0) {
    throw new RuntimeException("glCreateProgram() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glAttachShader(program, vertexShader);
  GLES20.glAttachShader(program, fragmentShader);
  GLES20.glLinkProgram(program);
  int[] linkStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
  if (linkStatus[0] != GLES20.GL_TRUE) {
    Logging.e(TAG, "Could not link program: " + GLES20.glGetProgramInfoLog(program));
    throw new RuntimeException(GLES20.glGetProgramInfoLog(program));
  }
  // According to the documentation of glLinkProgram():
  // "After the link operation, applications are free to modify attached shader objects, compile
  // attached shader objects, detach shader objects, delete shader objects, and attach additional
  // shader objects. None of these operations affects the information log or the program that is
  // part of the program object."
  // But in practice, detaching shaders from the program seems to break some devices. Deleting the
  // shaders are fine however - it will delete them when they are no longer attached to a program.
  GLES20.glDeleteShader(vertexShader);
  GLES20.glDeleteShader(fragmentShader);
  GlUtil.checkNoGLES2Error("Creating GlShader");
}
 
Example 16
Source File: Program.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void link() {
	GLES20.glLinkProgram( handle );
	
	int[] status = new int[1];
	GLES20.glGetProgramiv( handle, GLES20.GL_LINK_STATUS, status, 0 );
	if (status[0] == GLES20.GL_FALSE) {
		throw new Error( GLES20.glGetProgramInfoLog( handle ) );
	}
}
 
Example 17
Source File: VideoStreamsView.java    From licodeAndroidClient with MIT License 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
	int program = GLES20.glCreateProgram();
	addShaderTo(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_STRING, program);
	addShaderTo(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_STRING, program);

	GLES20.glLinkProgram(program);
	int[] result = new int[] { GLES20.GL_FALSE };
	result[0] = GLES20.GL_FALSE;
	GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, result, 0);
	abortUnless(result[0] == GLES20.GL_TRUE,
			GLES20.glGetProgramInfoLog(program));
	GLES20.glUseProgram(program);

	GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "y_tex"), 0);
	GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "u_tex"), 1);
	GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "v_tex"), 2);

	// Actually set in drawRectangle(), but queried only once here.
	posLocation = GLES20.glGetAttribLocation(program, "in_pos");

	int tcLocation = GLES20.glGetAttribLocation(program, "in_tc");
	GLES20.glEnableVertexAttribArray(tcLocation);
	GLES20.glVertexAttribPointer(tcLocation, 2, GLES20.GL_FLOAT, false, 0,
			textureCoords);

	GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	checkNoGLES2Error();
}
 
Example 18
Source File: Shader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public Shader(String vertexShader, String fragmentShader, String attributes[], String uniforms[]) {
    this.program = GLES20.glCreateProgram();

    CompilationResult vResult = compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
    if (vResult.status == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("Vertex shader compilation failed");
        }
        destroyShader(vResult.shader, 0, program);
        return;
    }

    CompilationResult fResult = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
    if (fResult.status == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("Fragment shader compilation failed");
        }
        destroyShader(vResult.shader, fResult.shader, program);
        return;
    }

    GLES20.glAttachShader(program, vResult.shader);
    GLES20.glAttachShader(program, fResult.shader);

    for (int i = 0; i < attributes.length; i++) {
        GLES20.glBindAttribLocation(program, i, attributes[i]);
    }

    if (linkProgram(program) == GLES20.GL_FALSE) {
        destroyShader(vResult.shader, fResult.shader, program);
        return;
    }

    for (String uniform : uniforms) {
        uniformsMap.put(uniform, GLES20.glGetUniformLocation(program, uniform));
    }

    if (vResult.shader != 0) {
        GLES20.glDeleteShader(vResult.shader);
    }

    if (fResult.shader != 0) {
        GLES20.glDeleteShader(fResult.shader);
    }
}
 
Example 19
Source File: Shader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public Shader(String vertexShader, String fragmentShader, String attributes[], String uniforms[]) {
    this.program = GLES20.glCreateProgram();

    CompilationResult vResult = compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
    if (vResult.status == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("Vertex shader compilation failed");
        }
        destroyShader(vResult.shader, 0, program);
        return;
    }

    CompilationResult fResult = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
    if (fResult.status == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("Fragment shader compilation failed");
        }
        destroyShader(vResult.shader, fResult.shader, program);
        return;
    }

    GLES20.glAttachShader(program, vResult.shader);
    GLES20.glAttachShader(program, fResult.shader);

    for (int i = 0; i < attributes.length; i++) {
        GLES20.glBindAttribLocation(program, i, attributes[i]);
    }

    if (linkProgram(program) == GLES20.GL_FALSE) {
        destroyShader(vResult.shader, fResult.shader, program);
        return;
    }

    for (String uniform : uniforms) {
        uniformsMap.put(uniform, GLES20.glGetUniformLocation(program, uniform));
    }

    if (vResult.shader != 0) {
        GLES20.glDeleteShader(vResult.shader);
    }

    if (fResult.shader != 0) {
        GLES20.glDeleteShader(fResult.shader);
    }
}
 
Example 20
Source File: Shader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public Shader(String vertexShader, String fragmentShader, String[] attributes, String[] uniforms) {
    this.program = GLES20.glCreateProgram();

    CompilationResult vResult = compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
    if (vResult.status == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("Vertex shader compilation failed");
        }
        destroyShader(vResult.shader, 0, program);
        return;
    }

    CompilationResult fResult = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
    if (fResult.status == GLES20.GL_FALSE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("Fragment shader compilation failed");
        }
        destroyShader(vResult.shader, fResult.shader, program);
        return;
    }

    GLES20.glAttachShader(program, vResult.shader);
    GLES20.glAttachShader(program, fResult.shader);

    for (int i = 0; i < attributes.length; i++) {
        GLES20.glBindAttribLocation(program, i, attributes[i]);
    }

    if (linkProgram(program) == GLES20.GL_FALSE) {
        destroyShader(vResult.shader, fResult.shader, program);
        return;
    }

    for (String uniform : uniforms) {
        uniformsMap.put(uniform, GLES20.glGetUniformLocation(program, uniform));
    }

    if (vResult.shader != 0) {
        GLES20.glDeleteShader(vResult.shader);
    }

    if (fResult.shader != 0) {
        GLES20.glDeleteShader(fResult.shader);
    }
}