Converting non-VBO to VBO (Android / Java specific) -


i'm having trouble understanding if vbo code correct. below code working, non-vbo, i've shown i've done in attempts vbo's working, i've had success in sprites/quads drawn, when drawn, i'm not seeing performance increase. please advise if i'm doing correctly, there 1 of 2 tuts out there vbo's on android in java (i've looked @ c examples, not having joy them).

i'm not sure if i'm right in putting of code in constructor - should code no called every time draw sprite?

any appreciated.

standard (non vbo code, note, x/yplotleft/right/top/bottom correctly defined)

//this code drawsprite method of vbo class.      vertices[0]=xplotleft;     vertices[1]=yplottop;     vertices[2]=0;     vertices[3]=0;     vertices[4]=0;      vertices[5]=xplotright;     vertices[6]=yplottop;     vertices[7]=0;     vertices[8]=1;     vertices[9]=0;      vertices[10]=xplotleft;     vertices[11]=yplotbottom;     vertices[12]=0;     vertices[13]=0;     vertices[14]=1;      vertices[15]=xplotright;     vertices[16]=yplotbottom;     vertices[17]=0;     vertices[18]=1;     vertices[19]=1;      //reset byte buffer position      vertexbuf.rewind();     vertexbuf.put(vertices).position(0);      //bind texture     gles20.glbindtexture(gles20.gl_texture_2d, texid);           //use program created earlier     gles20.gluseprogram(iprogid);     //combine rotation matrix projection , camera view     matrix.multiplymm(mvpmatrix2, 0, mvpmatrix, 0,  mrotationmatrix, 0);     // handle shape's transformation matrix     mmvpmatrixhandle = gles20.glgetuniformlocation(iprogid, "umvpmatrix");      // apply projection , view transformation     gles20.gluniformmatrix4fv(mmvpmatrixhandle, 1, false, mvpmatrix2, 0);     //set starting position vertices     vertexbuf.position(0);     //specify attributes vertex (x,y,z)     gles20.glvertexattribpointer(iposition, 3, gles20.gl_float, false, 5 * 4, vertexbuf);     //enable attribute position     gles20.glenablevertexattribarray(iposition);     //set starting position vertices (texture)     vertexbuf.position(3);     //specify attributes vertex (s t textures)     gles20.glvertexattribpointer(itexcoords, 2, gles20.gl_float, false, 5 * 4, vertexbuf);     //enable attribute texture     gles20.glenablevertexattribarray(itexcoords);     //enable alpha blending , set blending function     gles20.glenable(gles20.gl_blend);      gles20.glblendfunc(gles20.gl_one, gles20.gl_one_minus_src_alpha);     //draw     gles20.gldrawarrays(gles20.gl_triangle_strip, 0, 4);     //disable alpha blending     gles20.gldisable(gles20.gl_blend); 

vbo code

defined @ class level:

//buffer object vbo (we copy data floatbuffer this)     final int buffers[] = new int[1]; 

i've added following code constructor of vbo class:

    //generate buffers needed  gles20.glgenbuffers(1, buffers, 0);  // bind buffer. future commands affect buffer specifically. gles20.glbindbuffer(gles20.gl_array_buffer, buffers[0]);  gles20.glbufferdata(gles20.gl_array_buffer, vertexbuf.capacity() * 4,vertexbuf, gles20.gl_static_draw); 

//main vbo code drawsprite method:

    vertices[0]=xplotleft;     vertices[1]=yplottop;     vertices[2]=0;     vertices[3]=0;     vertices[4]=0;      vertices[5]=xplotright;     vertices[6]=yplottop;     vertices[7]=0;     vertices[8]=1;     vertices[9]=0;      vertices[10]=xplotleft;     vertices[11]=yplotbottom;     vertices[12]=0;     vertices[13]=0;     vertices[14]=1;      vertices[15]=xplotright;     vertices[16]=yplotbottom;     vertices[17]=0;     vertices[18]=1;     vertices[19]=1;       //reset byte buffer position      vertexbuf.rewind();     vertexbuf.put(vertices).position(0);  // transfer data client memory      gles20.glbuffersubdata(gles20.gl_array_buffer, 0, vertexbuf.capacity() * 4,vertexbuf);      //bind texture     gles20.glbindtexture(gles20.gl_texture_2d, texid);           //use program     gles20.gluseprogram(iprogid);     //combine rotation matrix projection , camera view     matrix.multiplymm(mvpmatrix2, 0, mvpmatrix, 0,  mrotationmatrix, 0);     //get handle shape's transformation matrix     mmvpmatrixhandle = gles20.glgetuniformlocation(iprogid, "umvpmatrix");     //apply projection , view transformation     gles20.gluniformmatrix4fv(mmvpmatrixhandle, 1, false, mvpmatrix2, 0);     //specify attributes vertex (x,y,z)     gles20.glvertexattribpointer(iposition, 3, gles20.gl_float, false, 5 * 4, 0);     //enable attribute position     gles20.glenablevertexattribarray(iposition);     //specify attributes vertex s & t     gles20.glvertexattribpointer(itexcoords, 2, gles20.gl_float, false, 5 * 4, 3 * 4);     //enable attribute texture     gles20.glenablevertexattribarray(itexcoords);     //enable alpha blending , set blending function     gles20.glenable(gles20.gl_blend);      gles20.glblendfunc(gles20.gl_one, gles20.gl_one_minus_src_alpha);     //draw     gles20.gldrawarrays(gles20.gl_triangle_strip, 0, 4);     //disable alpha blending     gles20.gldisable(gles20.gl_blend);  } 


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -