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

The following examples show how to use android.opengl.GLES20#glGetProgramiv() . 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: EglUtil.java    From SimpleVideoEdit with Apache License 2.0 6 votes vote down vote up
public static int createProgram(final int vertexShader, final int pixelShader) throws GLException {
    // create empty OpenGL ES Program, store the id in program
    final int program = glCreateProgram();
    if (program == 0) {
        throw new RuntimeException("Could not create program");
    }

    // add the vertex shader to program
    GLES20.glAttachShader(program, vertexShader);
    // add the fragment shader to program
    GLES20.glAttachShader(program, pixelShader);
    // creates OpenGL ES program executables
    GLES20.glLinkProgram(program);
    final int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GL_TRUE) {
        GLES20.glDeleteProgram(program);
        throw new RuntimeException("Could not link program");
    }
    return program;
}
 
Example 2
Source File: EglUtil.java    From GPUVideo-android with MIT License 6 votes vote down vote up
public static int createProgram(final int vertexShader, final int pixelShader) throws GLException {
    final int program = glCreateProgram();
    if (program == 0) {
        throw new RuntimeException("Could not create program");
    }

    GLES20.glAttachShader(program, vertexShader);
    GLES20.glAttachShader(program, pixelShader);

    GLES20.glLinkProgram(program);
    final int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GL_TRUE) {
        GLES20.glDeleteProgram(program);
        throw new RuntimeException("Could not link program");
    }
    return program;
}
 
Example 3
Source File: EffectsShader.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
void setProgram(String vertexSource, String fragmentSource) throws Exception {
	mIdShaderVertex = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
	mIdShaderFragment = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
	int program = GLES20.glCreateProgram();
	if (program != 0) {
		GLES20.glAttachShader(program, mIdShaderVertex);
		GLES20.glAttachShader(program, mIdShaderFragment);
		GLES20.glLinkProgram(program);
		int[] linkStatus = new int[1];
		GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
		if (linkStatus[0] != GLES20.GL_TRUE) {
			String error = GLES20.glGetProgramInfoLog(program);
			deleteProgram();
			throw new Exception(error);
		}
	}
	mIdProgram = program;
	mShaderHandleMap.clear();
}
 
Example 4
Source File: GlUtil.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a GL shader program from vertex and fragment shader code.
 *
 * @param vertexCode GLES20 vertex shader program.
 * @param fragmentCode GLES20 fragment shader program.
 * @return GLES20 program id.
 */
public static int compileProgram(String vertexCode, String fragmentCode) {
  int program = GLES20.glCreateProgram();
  checkGlError();

  // Add the vertex and fragment shaders.
  addShader(GLES20.GL_VERTEX_SHADER, vertexCode, program);
  addShader(GLES20.GL_FRAGMENT_SHADER, fragmentCode, program);

  // Link and check for errors.
  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) {
    throwGlError("Unable to link shader program: \n" + GLES20.glGetProgramInfoLog(program));
  }
  checkGlError();

  return program;
}
 
Example 5
Source File: GLUtil.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
public static int loadProgram(final String strVSource, final String strFSource) {
    int iVShader;
    int iFShader;
    int iProgId;
    int[] link = new int[1];
    iVShader = loadShader(strVSource, GLES20.GL_VERTEX_SHADER);
    if (iVShader == 0) {
        Log.d("Load Program", "Vertex Shader Failed");
        return 0;
    }
    iFShader = loadShader(strFSource, GLES20.GL_FRAGMENT_SHADER);
    if (iFShader == 0) {
        Log.d("Load Program", "Fragment Shader Failed");
        return 0;
    }

    iProgId = GLES20.glCreateProgram();

    GLES20.glAttachShader(iProgId, iVShader);
    GLES20.glAttachShader(iProgId, iFShader);

    GLES20.glLinkProgram(iProgId);

    GLES20.glGetProgramiv(iProgId, GLES20.GL_LINK_STATUS, link, 0);
    if (link[0] <= 0) {
        Log.d("Load Program", "Linking Failed");
        return 0;
    }
    GLES20.glDeleteShader(iVShader);
    GLES20.glDeleteShader(iFShader);
    return iProgId;
}
 
Example 6
Source File: GlUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public static int createProgram(String vertexSource, String fragmentSource) {
  int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
  if (vertexShader == 0) {
    return 0;
  }
  int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
  if (pixelShader == 0) {
    return 0;
  }

  int program = GLES20.glCreateProgram();
  checkGlError("glCreateProgram");
  if (program == 0) {
    Log.e(TAG, "Could not create program");
  }
  GLES20.glAttachShader(program, vertexShader);
  checkGlError("glAttachShader");
  GLES20.glAttachShader(program, pixelShader);
  checkGlError("glAttachShader");
  GLES20.glLinkProgram(program);
  int[] linkStatus = new int[1];
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
  if (linkStatus[0] != GLES20.GL_TRUE) {
    Log.e(TAG, "Could not link program: ");
    Log.e(TAG, GLES20.glGetProgramInfoLog(program));
    GLES20.glDeleteProgram(program);
    program = 0;
  }
  return program;
}
 
Example 7
Source File: OpenGlUtils.java    From TikTok with Apache License 2.0 5 votes vote down vote up
public static int loadProgram(final String strVSource, final String strFSource) {
    int iVShader;
    int iFShader;
    int iProgId;
    int[] link = new int[1];
    iVShader = loadShader(strVSource, GLES20.GL_VERTEX_SHADER);
    if (iVShader == 0) {
        Log.d("Load Program", "Vertex Shader Failed");
        return 0;
    }
    iFShader = loadShader(strFSource, GLES20.GL_FRAGMENT_SHADER);
    if (iFShader == 0) {
        Log.d("Load Program", "Fragment Shader Failed");
        return 0;
    }

    iProgId = GLES20.glCreateProgram();
    GLES20.glAttachShader(iProgId, iVShader);
    GLES20.glAttachShader(iProgId, iFShader);
    GLES20.glLinkProgram(iProgId);
    GLES20.glGetProgramiv(iProgId, GLES20.GL_LINK_STATUS, link, 0);
    if (link[0] <= 0) {
        Log.d("Load Program", "Linking Failed");
        return 0;
    }
    GLES20.glDeleteShader(iVShader);
    GLES20.glDeleteShader(iFShader);
    return iProgId;
}
 
Example 8
Source File: FrameRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void onSurfaceCreated() {
  // Create the GL program.
  program = GLES20.glCreateProgram();

  // Add the vertex and fragment shaders.
  addShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER, program);
  addShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER, program);

  // Link the GL 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);
  int posLocation = GLES20.glGetAttribLocation(program, "in_pos");
  GLES20.glEnableVertexAttribArray(posLocation);
  GLES20.glVertexAttribPointer(
          posLocation, 2, GLES20.GL_FLOAT, false, 0, TEXTURE_VERTICES);
  texLocation = GLES20.glGetAttribLocation(program, "in_tc");
  GLES20.glEnableVertexAttribArray(texLocation);
  checkNoGLES2Error();
  bitDepthLocation = GLES20.glGetUniformLocation(program, "bitDepth");
  checkNoGLES2Error();
  colorMatrixLocation = GLES20.glGetUniformLocation(program, "mColorConversion");
  checkNoGLES2Error();
  setupTextures();
  checkNoGLES2Error();
}
 
Example 9
Source File: TextureManager.java    From spydroid-ipcamera with GNU General Public License v3.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
	int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
	if (vertexShader == 0) {
		return 0;
	}
	int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
	if (pixelShader == 0) {
		return 0;
	}

	int program = GLES20.glCreateProgram();
	checkGlError("glCreateProgram");
	if (program == 0) {
		Log.e(TAG, "Could not create program");
	}
	GLES20.glAttachShader(program, vertexShader);
	checkGlError("glAttachShader");
	GLES20.glAttachShader(program, pixelShader);
	checkGlError("glAttachShader");
	GLES20.glLinkProgram(program);
	int[] linkStatus = new int[1];
	GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
	if (linkStatus[0] != GLES20.GL_TRUE) {
		Log.e(TAG, "Could not link program: ");
		Log.e(TAG, GLES20.glGetProgramInfoLog(program));
		GLES20.glDeleteProgram(program);
		program = 0;
	}
	return program;
}
 
Example 10
Source File: TextureManager.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
	int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
	if (vertexShader == 0) {
		return 0;
	}
	int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
	if (pixelShader == 0) {
		return 0;
	}

	int program = GLES20.glCreateProgram();
	checkGlError("glCreateProgram");
	if (program == 0) {
		Log.e(TAG, "Could not create program");
	}
	GLES20.glAttachShader(program, vertexShader);
	checkGlError("glAttachShader");
	GLES20.glAttachShader(program, pixelShader);
	checkGlError("glAttachShader");
	GLES20.glLinkProgram(program);
	int[] linkStatus = new int[1];
	GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
	if (linkStatus[0] != GLES20.GL_TRUE) {
		Log.e(TAG, "Could not link program: ");
		Log.e(TAG, GLES20.glGetProgramInfoLog(program));
		GLES20.glDeleteProgram(program);
		program = 0;
	}
	return program;
}
 
Example 11
Source File: GLToolbox.java    From PhotoEditor with MIT License 5 votes vote down vote up
static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program != 0) {
        GLES20.glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        GLES20.glAttachShader(program, pixelShader);
        checkGlError("glAttachShader");
        GLES20.glLinkProgram(program);
        int[] linkStatus = new int[1];
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus,
                0);
        if (linkStatus[0] != GLES20.GL_TRUE) {
            String info = GLES20.glGetProgramInfoLog(program);
            GLES20.glDeleteProgram(program);
            throw new RuntimeException("Could not link program: " + info);
        }
    }
    return program;
}
 
Example 12
Source File: GLHelper.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
public static int loadProgram(String vSource, String fSource) {
    int iVShader;
    int iFShader;
    int iProgram;
    int[] link = new int[1];
    iVShader = loadShader(vSource, GLES20.GL_VERTEX_SHADER);
    if (iVShader == 0) {
        Log.d(TAG, "Load Vertex Shader Failed");
        return 0;
    }
    iFShader = loadShader(fSource, GLES20.GL_FRAGMENT_SHADER);
    if (iFShader == 0) {
        Log.d(TAG, ":Load Fragment Shader Failed");
        return 0;
    }
    iProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(iProgram, iVShader);
    checkGlError("");
    GLES20.glAttachShader(iProgram, iFShader);
    checkGlError("");
    GLES20.glLinkProgram(iProgram);
    checkGlError("");
    GLES20.glGetProgramiv(iProgram, GLES20.GL_LINK_STATUS, link, 0);
    if (link[0] <= 0) {
        Log.d(TAG, "Linking Failed");
        return 0;
    }
    GLES20.glDeleteShader(iVShader);
    checkGlError("");

    GLES20.glDeleteShader(iFShader);
    checkGlError("");

    return iProgram;
}
 
Example 13
Source File: ShaderHelper.java    From sealrtc-android with MIT License 5 votes vote down vote up
/**
 * 验证OpenGl 程序是否可用
 *
 * @param programObjectId
 * @return
 */
public static boolean validateProgram(int programObjectId) {
    GLES20.glValidateProgram(programObjectId);
    int[] validateStatus = new int[1];
    GLES20.glGetProgramiv(programObjectId, GLES20.GL_VALIDATE_STATUS, validateStatus, 0);
    Log.d(
            TAG,
            "validateProgram: status="
                    + validateStatus[0]
                    + ", log="
                    + GLES20.glGetProgramInfoLog(programObjectId));
    return validateStatus[0] != 0;
}
 
Example 14
Source File: GLShaderUtil.java    From GLES2_AUDIO_VIDEO_RECODE with Apache License 2.0 5 votes vote down vote up
/**
 * 创建shader程序的方法
 *
 * @param vertexSource
 * @param fragmentSource
 * @return
 */
public static int createProgram(String vertexSource, String fragmentSource) {
    //加载顶点着色器
    int vertexShader = GLShaderUtil.loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }

    //加载片元着色器
    int pixelShader = GLShaderUtil.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    //创建程序
    int program = GLES20.glCreateProgram();
    //若程序创建成功则向程序中加入顶点着色器与片元着色器
    if (program != 0) {
        //向程序中加入顶点着色器
        GLES20.glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        //向程序中加入片元着色器
        GLES20.glAttachShader(program, pixelShader);
        checkGlError("glAttachShader");
        //链接程序
        GLES20.glLinkProgram(program);
        //存放链接成功program数量的数组
        int[] linkStatus = new int[1];
        //获取program的链接情况
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
        //若链接失败则报错并删除程序
        if (linkStatus[0] != GLES20.GL_TRUE) {
            Log.e("ES20_ERROR", "Could not link program: ");
            Log.e("ES20_ERROR", GLES20.glGetProgramInfoLog(program));
            GLES20.glDeleteProgram(program);
            program = 0;
        }
    }
    return program;
}
 
Example 15
Source File: ShaderProgram.java    From tilt-game-android with MIT License 4 votes vote down vote up
/**
 * TODO Is this actually needed? As the locations of {@link VertexBufferObjectAttribute}s are now 'predefined'.
 */
@Deprecated
private void initAttributeLocations() {
	this.mAttributeLocations.clear();

	ShaderProgram.PARAMETERS_CONTAINER[0] = 0;
	GLES20.glGetProgramiv(this.mProgramID, GLES20.GL_ACTIVE_ATTRIBUTES, ShaderProgram.PARAMETERS_CONTAINER, 0);
	final int numAttributes = ShaderProgram.PARAMETERS_CONTAINER[0];

	for (int i = 0; i < numAttributes; i++) {
		GLES20.glGetActiveAttrib(this.mProgramID, i, ShaderProgram.NAME_CONTAINER_SIZE, ShaderProgram.LENGTH_CONTAINER, 0, ShaderProgram.SIZE_CONTAINER, 0, ShaderProgram.TYPE_CONTAINER, 0, ShaderProgram.NAME_CONTAINER, 0);

		int length = ShaderProgram.LENGTH_CONTAINER[0];

		/* Some drivers do not report the actual length here, but zero. Then the name is '\0' terminated. */
		if (length == 0) {
			while ((length < ShaderProgram.NAME_CONTAINER_SIZE) && (ShaderProgram.NAME_CONTAINER[length] != '\0')) {
				length++;
			}
		}

		String name = new String(ShaderProgram.NAME_CONTAINER, 0, length);
		int location = GLES20.glGetAttribLocation(this.mProgramID, name);

		if (location == ShaderProgramConstants.LOCATION_INVALID) {
			/* Some drivers do not report an incorrect length. Then the name is '\0' terminated. */
			length = 0;
			while (length < ShaderProgram.NAME_CONTAINER_SIZE && ShaderProgram.NAME_CONTAINER[length] != '\0') {
				length++;
			}

			name = new String(ShaderProgram.NAME_CONTAINER, 0, length);
			location = GLES20.glGetAttribLocation(this.mProgramID, name);

			if (location == ShaderProgramConstants.LOCATION_INVALID) {
				throw new ShaderProgramLinkException("Invalid location for attribute: '" + name + "'.");
			}
		}

		this.mAttributeLocations.put(name, location);
	}
}
 
Example 16
Source File: Utils.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
public static int createShaderProgram(String vss, String fss) {
    int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vshader, vss);
    GLES20.glCompileShader(vshader);
    int[] status = new int[1];
    GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetShaderInfoLog(vshader));
        GLES20.glDeleteShader(vshader);
        vshader = 0;
        return 0;
    }

    int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fshader, fss);
    GLES20.glCompileShader(fshader);
    GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetShaderInfoLog(fshader));
        GLES20.glDeleteShader(vshader);
        GLES20.glDeleteShader(fshader);
        fshader = 0;
        return 0;
    }

    int program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vshader);
    GLES20.glAttachShader(program, fshader);
    GLES20.glLinkProgram(program);
    GLES20.glDeleteShader(vshader);
    GLES20.glDeleteShader(fshader);
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        program = 0;
        return 0;
    }
    GLES20.glValidateProgram(program);
    GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
        return 0;
    }

    return program;
}
 
Example 17
Source File: ShaderHelper.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Helper function to compile and link a program.
 * 
 * @param vertexShaderHandle An OpenGL handle to an already-compiled vertex shader.
 * @param fragmentShaderHandle An OpenGL handle to an already-compiled fragment shader.
 * @param attributes Attributes that need to be bound to the program.
 * @return An OpenGL handle to the program.
 */
public static int createAndLinkProgram(final int vertexShaderHandle,
                                          final int fragmentShaderHandle,
                                          final String[] attributes) {

	int programHandle = GLES20.glCreateProgram();
	
	if (programHandle != 0) {
		// Bind the vertex shader to the program.
		GLES20.glAttachShader(programHandle, vertexShaderHandle);

		// Bind the fragment shader to the program.
		GLES20.glAttachShader(programHandle, fragmentShaderHandle);
		
		// Bind attributes
		if (attributes != null) {
			final int size = attributes.length;
			for (int i = 0; i < size; i++) {
				GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
			}						
		}
		
		// Link the two shaders together into a program.
		GLES20.glLinkProgram(programHandle);

		// Get the link status.
		final int[] linkStatus = new int[1];
		GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);

		// If the link failed, delete the program.
		if (linkStatus[0] == 0) {
			Log.e(TAG, "Error compiling program: " + GLES20.glGetProgramInfoLog(programHandle));
			GLES20.glDeleteProgram(programHandle);
			programHandle = 0;
		}
	}
	
	if (programHandle == 0) {
		throw new RuntimeException("Error creating program.");
	}
	
	return programHandle;
}
 
Example 18
Source File: GLUtil.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Helper function to compile and link a program.
 * 
 * @param vertexShaderHandle
 *            An OpenGL handle to an already-compiled vertex shader.
 * @param fragmentShaderHandle
 *            An OpenGL handle to an already-compiled fragment shader.
 * @param attributes
 *            Attributes that need to be bound to the program.
 * @return An OpenGL handle to the program.
 */
public static int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle,
		final String[] attributes) {
	int programHandle = GLES20.glCreateProgram();

	if (programHandle != 0) {
		// Bind the vertex shader to the program.
		GLES20.glAttachShader(programHandle, vertexShaderHandle);

		// Bind the fragment shader to the program.
		GLES20.glAttachShader(programHandle, fragmentShaderHandle);

		// Bind attributes
		if (attributes != null) {
			final int size = attributes.length;
			for (int i = 0; i < size; i++) {
				GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
			}
		}

		// Link the two shaders together into a program.
		GLES20.glLinkProgram(programHandle);

		// Get the link status.
		final int[] linkStatus = new int[1];
		GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);

		// If the link failed, delete the program.
		if (linkStatus[0] == 0) {
			Log.e(TAG, "Error compiling program: " + GLES20.glGetProgramInfoLog(programHandle));
			GLES20.glDeleteProgram(programHandle);
			programHandle = 0;
		}
	}

	if (programHandle == 0) {
		throw new RuntimeException("Error creating program.");
	}

	return programHandle;
}
 
Example 19
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 4 votes vote down vote up
private static int loadShader(String vss, String fss) {
    Log.d("CameraGLRendererBase", "loadShader");
    int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vshader, vss);
    GLES20.glCompileShader(vshader);
    int[] status = new int[1];
    GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not compile vertex shader: "+GLES20.glGetShaderInfoLog(vshader));
        GLES20.glDeleteShader(vshader);
        vshader = 0;
        return 0;
    }

    int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fshader, fss);
    GLES20.glCompileShader(fshader);
    GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not compile fragment shader:"+GLES20.glGetShaderInfoLog(fshader));
        GLES20.glDeleteShader(vshader);
        GLES20.glDeleteShader(fshader);
        fshader = 0;
        return 0;
    }

    int program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vshader);
    GLES20.glAttachShader(program, fshader);
    GLES20.glLinkProgram(program);
    GLES20.glDeleteShader(vshader);
    GLES20.glDeleteShader(fshader);
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not link shader program: "+GLES20.glGetProgramInfoLog(program));
        program = 0;
        return 0;
    }
    GLES20.glValidateProgram(program);
    GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, status, 0);
    if (status[0] == 0)
    {
        Log.e("CameraGLRendererBase", "Shader program validation error: "+GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
        return 0;
    }

    Log.d("CameraGLRendererBase", "Shader program is built OK");

    return program;
}
 
Example 20
Source File: CameraGLRendererBase.java    From pasm-yolov3-Android with GNU General Public License v3.0 4 votes vote down vote up
private static int loadShader(String vss, String fss) {
    Log.d("CameraGLRendererBase", "loadShader");
    int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vshader, vss);
    GLES20.glCompileShader(vshader);
    int[] status = new int[1];
    GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not compile vertex shader: "+GLES20.glGetShaderInfoLog(vshader));
        GLES20.glDeleteShader(vshader);
        vshader = 0;
        return 0;
    }

    int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fshader, fss);
    GLES20.glCompileShader(fshader);
    GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not compile fragment shader:"+GLES20.glGetShaderInfoLog(fshader));
        GLES20.glDeleteShader(vshader);
        GLES20.glDeleteShader(fshader);
        fshader = 0;
        return 0;
    }

    int program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vshader);
    GLES20.glAttachShader(program, fshader);
    GLES20.glLinkProgram(program);
    GLES20.glDeleteShader(vshader);
    GLES20.glDeleteShader(fshader);
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not link shader program: "+GLES20.glGetProgramInfoLog(program));
        program = 0;
        return 0;
    }
    GLES20.glValidateProgram(program);
    GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, status, 0);
    if (status[0] == 0)
    {
        Log.e("CameraGLRendererBase", "Shader program validation error: "+GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
        return 0;
    }

    Log.d("CameraGLRendererBase", "Shader program is built OK");

    return program;
}