Hello everyone, I start to write render on android OPEN GL ES 2.0
Advice please! gp == false, then drawn. If gp == true, it is not drawn, where there may be a bug???
//true - used memory GPU otherwise. false - the application memory
private boolean gp=true;
//in constructor
private void jobCreate(){
final short[] inde={0,1,2,1,2,3};
bufInd=ByteBuffer.allocateDirect(inde.length*2)
.order(ByteOrder.nativeOrder()).asShortBuffer();
bufInd.put(inde);
bufInd.position(0);
this.bytesTry=mTriangleVerticesData.length
* FLOAT_SIZE_BYTES;
mTriangleVertices = ByteBuffer.allocateDirect(this.bytesTry).order(ByteOrder.nativeOrder()).asFloatBuffer();
mTriangleVertices.put(mTriangleVerticesData).position(0);
//----vertex
vertexBufferId=new int[1];
GLES20.glGenBuffers(1,this.vertexBufferId, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.vertexBufferId[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,this.bytesTry,this.mTriangleVertices,GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
//in onDrawFrame
private void jobPaint(){
if(!gp){
//=============================apps
//---------v
mTriangleVertices.position(0);
GLES20.glVertexAttribPointer(maPositionHandle,
3,
GLES20.GL_FLOAT,
false,
20,
mTriangleVertices);
checkGlError("vertex");
GLES20.glEnableVertexAttribArray(maPositionHandle);
//---------------------UV
mTriangleVertices.position(3);
GLES20.glVertexAttribPointer(maTextureHandle,
2,
GLES20.GL_FLOAT,
false,
20,
mTriangleVertices);
checkGlError("uv");
GLES20.glEnableVertexAttribArray(maTextureHandle);
}else{
//================================gpu
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.vertexBufferId[0]);
//--------v
GLES20.glVertexAttribPointer(maPositionHandle,
3,
GLES20.GL_FLOAT,
false,
20,
0);
checkGlError("vertex");
GLES20.glEnableVertexAttribArray(maPositionHandle);
//------------uv
GLES20.glVertexAttribPointer(maTextureHandle,
2,
GLES20.GL_FLOAT,
false,
20,
12);
checkGlError("uv");
GLES20.glEnableVertexAttribArray(maTextureHandle);
}
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
if(gp){
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
GLES20.glDisableVertexAttribArray(maPositionHandle);
GLES20.glDisableVertexAttribArray(maTextureHandle);
}