当前位置: 首页>>代码示例>>Java>>正文


Java GLES20.glLinkProgram方法代码示例

本文整理汇总了Java中android.opengl.GLES20.glLinkProgram方法的典型用法代码示例。如果您正苦于以下问题:Java GLES20.glLinkProgram方法的具体用法?Java GLES20.glLinkProgram怎么用?Java GLES20.glLinkProgram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.opengl.GLES20的用法示例。


在下文中一共展示了GLES20.glLinkProgram方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ShaderProgram

import android.opengl.GLES20; //导入方法依赖的package包/类
public ShaderProgram(String vertexShaderCode, String fragmentShaderCode) {
    int vertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vertexShader, vertexShaderCode);
    GLES20.glCompileShader(vertexShader);
    checkCompile(vertexShader);

    int fragmentShader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fragmentShader, fragmentShaderCode);
    GLES20.glCompileShader(fragmentShader);
    checkCompile(fragmentShader);

    id = GLES20.glCreateProgram();
    GLES20.glAttachShader(id, vertexShader);
    GLES20.glAttachShader(id, fragmentShader);
    GLES20.glLinkProgram(id);
}
 
开发者ID:snada,项目名称:BitmapFontLoader,代码行数:17,代码来源:ShaderProgram.java

示例2: initializeProgram

import android.opengl.GLES20; //导入方法依赖的package包/类
private void initializeProgram() {
    vertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vertexShader, vertexShaderCode);
    GLES20.glCompileShader(vertexShader);

    fragmentShader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fragmentShader, fragmentShaderCode);
    GLES20.glCompileShader(fragmentShader);

    program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vertexShader);
    GLES20.glAttachShader(program, fragmentShader);

    GLES20.glLinkProgram(program);
}
 
开发者ID:lucasax,项目名称:Zero,代码行数:16,代码来源:GLLayer.java

示例3: linkProgram

import android.opengl.GLES20; //导入方法依赖的package包/类
/**
 * 把着色器链接进OpenGL的程序
 *
 * 理解OpenGL程序:一个OpenGL程序就是把一个顶点着色器和一个片段着色器连接在一起变成单个对象
 */
public static int linkProgram(int vertexShader, int pixelShader) {

    //1.新建程序对象,programId为程序对象的ID;id为0表示对象创建失败
    int programId = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (programId == 0) {
        Log.e(TAG, "Could not create programId");
    }
    //2.附上着色器:把顶点着色器和片段着色器附到程序对象上
    GLES20.glAttachShader(programId, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(programId, pixelShader);
    checkGlError("glAttachShader");
    //3.链接程序
    GLES20.glLinkProgram(programId);
    //检查链接成功还是失败
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(programId, GLES20.GL_LINK_STATUS, linkStatus, 0);
    //4.验证链接状态并返回程序对象ID
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link programId: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(programId));
        GLES20.glDeleteProgram(programId);
        programId = 0;
    }
    return programId;
}
 
开发者ID:YanJingW,项目名称:OpenGL_Note,代码行数:33,代码来源:GlUtil.java

示例4: onSurfaceCreated

import android.opengl.GLES20; //导入方法依赖的package包/类
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    setUpBuffers();
    setUpSprites();
    GLES20.glClearColor(235f / 255.0f, 235f / 255.0f, 255f / 255.0f, 255f / 255.0f);
    int vertexShader = SpriteKitGraphicTools.loadShader(GLES20.GL_VERTEX_SHADER,
            SpriteKitGraphicTools.imageVertexShader);
    int fragmentShader = SpriteKitGraphicTools.loadShader(GLES20.GL_FRAGMENT_SHADER,
            SpriteKitGraphicTools.imageFragmentShader);
    SpriteKitGraphicTools.imageShaderProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(SpriteKitGraphicTools.imageShaderProgram, vertexShader);
    GLES20.glAttachShader(SpriteKitGraphicTools.imageShaderProgram, fragmentShader);
    GLES20.glLinkProgram(SpriteKitGraphicTools.imageShaderProgram);
    GLES20.glUseProgram(SpriteKitGraphicTools.imageShaderProgram);
}
 
开发者ID:sakkeerhussain,项目名称:SpriteKit-Android,代码行数:16,代码来源:SpriteKitRenderer.java

示例5: GlShader

import android.opengl.GLES20; //导入方法依赖的package包/类
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");
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:28,代码来源:GlShader.java

示例6: createProgram

import android.opengl.GLES20; //导入方法依赖的package包/类
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) {
        return 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) {
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
开发者ID:fishwjy,项目名称:VideoCompressor,代码行数:28,代码来源:TextureRenderer.java

示例7: link

import android.opengl.GLES20; //导入方法依赖的package包/类
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 ) );
	}
}
 
开发者ID:mango-tree,项目名称:UNIST-pixel-dungeon,代码行数:10,代码来源:Program.java

示例8: initShaders

import android.opengl.GLES20; //导入方法依赖的package包/类
private void initShaders() {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    shaderProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(shaderProgram, vertexShader);
    GLES20.glAttachShader(shaderProgram, fragmentShader);
    GLES20.glLinkProgram(shaderProgram);
}
 
开发者ID:PacktPublishing,项目名称:Building-Android-UIs-with-Custom-Views,代码行数:10,代码来源:GLDrawer.java

示例9: Triangle

import android.opengl.GLES20; //导入方法依赖的package包/类
public Triangle() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    FloatBuffer vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);

    // prepare shaders and OpenGL program
    String vertexShaderCode = "uniform mat4 uMVPMatrix;" +

            "attribute vec4 vPosition;" +
            "void main() {" +
            // the matrix must be included as a modifier of gl_Position
            "  gl_Position = vPosition * uMVPMatrix;" +
            "}";
    int vertexShader = GLRenderer.loadShader(GLES20.GL_VERTEX_SHADER,
            vertexShaderCode);
    String fragmentShaderCode = "precision mediump float;" +
            "uniform vec4 vColor;" +
            "void main() {" +
            "  gl_FragColor = vColor;" +
            "}";
    int fragmentShader = GLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER,
            fragmentShaderCode);

    int mProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram);                  // create OpenGL program executables

}
 
开发者ID:efroemling,项目名称:bombsquad-remote-android,代码行数:40,代码来源:GLRenderer.java

示例10: createProgram

import android.opengl.GLES20; //导入方法依赖的package包/类
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;
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:31,代码来源:GlUtil.java

示例11: createOnGlThread

import android.opengl.GLES20; //导入方法依赖的package包/类
/**
 * Allocates and initializes OpenGL resources needed by the plane renderer.  Must be
 * called on the OpenGL thread, typically in
 * {@link GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)}.
 *
 * @param context Needed to access shader source.
 */
public void createOnGlThread(Context context) {
    ShaderUtil.checkGLError(TAG, "before create");

    int buffers[] = new int[1];
    GLES20.glGenBuffers(1, buffers, 0);
    mVbo = buffers[0];
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);

    mVboSize = INITIAL_BUFFER_POINTS * BYTES_PER_POINT;
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    ShaderUtil.checkGLError(TAG, "buffer alloc");

    int vertexShader = ShaderUtil.loadGLShader(TAG, context,
        GLES20.GL_VERTEX_SHADER, R.raw.point_cloud_vertex);
    int passthroughShader = ShaderUtil.loadGLShader(TAG, context,
        GLES20.GL_FRAGMENT_SHADER, R.raw.passthrough_fragment);

    mProgramName = GLES20.glCreateProgram();
    GLES20.glAttachShader(mProgramName, vertexShader);
    GLES20.glAttachShader(mProgramName, passthroughShader);
    GLES20.glLinkProgram(mProgramName);
    GLES20.glUseProgram(mProgramName);

    ShaderUtil.checkGLError(TAG, "program");

    mPositionAttribute = GLES20.glGetAttribLocation(mProgramName, "a_Position");
    mColorUniform = GLES20.glGetUniformLocation(mProgramName, "u_Color");
    mModelViewProjectionUniform = GLES20.glGetUniformLocation(
        mProgramName, "u_ModelViewProjection");
    mPointSizeUniform = GLES20.glGetUniformLocation(mProgramName, "u_PointSize");

    ShaderUtil.checkGLError(TAG, "program  params");
}
 
开发者ID:googlevr,项目名称:poly-sample-android,代码行数:43,代码来源:PointCloudRenderer.java

示例12: Triangle

import android.opengl.GLES20; //导入方法依赖的package包/类
public Triangle() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);


    int vertexShader = MyGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER,
            vertexShaderCode);
    int fragmentShader = MyGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER,
            fragmentShaderCode);

    // create empty OpenGL ES Program
    mProgram = GLES20.glCreateProgram();

    // add the vertex shader to program
    GLES20.glAttachShader(mProgram, vertexShader);

    // add the fragment shader to program
    GLES20.glAttachShader(mProgram, fragmentShader);

    // creates OpenGL ES program executables
    GLES20.glLinkProgram(mProgram);
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:34,代码来源:Triangle.java

示例13: loadShader

import android.opengl.GLES20; //导入方法依赖的package包/类
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;
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:53,代码来源:CameraGLRendererBase.java

示例14: createAndLinkProgram

import android.opengl.GLES20; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:54,代码来源:ShaderHelper.java


注:本文中的android.opengl.GLES20.glLinkProgram方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。