java - Where is GLES30.glGetBufferSubData? how to read transform feedback data opengles 3.0 -
so following 1 of simplest examples find on transform feedback, here, , converting android/java, android seems missing glgetbuffersubdata
function available in opengl es 3.0.
i've tried searching android source see if method used when calling method under jni, not sure looking in correct place that.
if function doesn't exist how can read data out transform feedback? i've looked @ glgettransformfeedbackvarying
, glgetbufferpointerv
, glreadbuffer
none seem want.
here code:
import com.harmonicprocesses.penelopefree.opengl.myglrenderer; import android.opengl.gles30; import android.util.log; import java.nio.bytebuffer; import java.nio.floatbuffer; /** * created izzy on 6/24/15. */ public class transformfeedback { // vertex shader private final string vertexshadersrc = "in float invalue;\n" + "out float outvalue;\n" + "void main() {\n" + " outvalue = sqrt(invalue);\n" + "}\n"; private final int mprogram; public transformfeedback{ // compile shader int vertexshader = myglrenderer.loadshader(gles30.gl_vertex_shader, vertexshadersrc); // create program , specify transform feedback variables mprogram = gles30.glcreateprogram(); gles30.glattachshader(mprogram, vertexshader); //const glchar* feedbackvaryings[] = { "outvalue" }; gles30.gltransformfeedbackvaryings(mprogram, 1, {"outvalue"}, gles30.gl_interleaved_attribs); gles30.gllinkprogram(mprogram); gles30.gluseprogram(mprogram); // create vao int[] vao = new int[1]; gles30.glgenvertexarrays(1, vao, 0); gles30.glbindvertexarray(vao[0]); // create input vbo , vertex format int bufferlength = 5 * 4; //5 floats 4 bytes each bytebuffer bb = bytebuffer.allocatedirect(bufferlength); floatbuffer data = bb.asfloatbuffer(); float[] floatdata = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; data.put(floatdata); data.position(0); int[] vbo = new int[1]; gles30.glgenbuffers(1, vbo, 0); gles30.glbindbuffer(gles30.gl_array_buffer, vbo[0]); gles30.glbufferdata(gles30.gl_array_buffer, bufferlength, data, gles30.gl_static_draw); int inputattrib = gles30.glgetattriblocation(mprogram, "invalue"); gles30.glenablevertexattribarray(inputattrib); gles30.glvertexattribpointer(inputattrib, 1, gles30.gl_float, false, 0, 0); // create transform feedback buffer int[] tbo = new int[1]; gles30.glgenbuffers(1, tbo, 0); gles30.glbindbuffer(gles30.gl_array_buffer, tbo[0]); gles30.glbufferdata(gles30.gl_array_buffer, bufferlength, null, gles30.gl_static_read); // perform feedback transform gles30.glenable(gles30.gl_rasterizer_discard); gles30.glbindbufferbase(gles30.gl_transform_feedback_buffer, 0, tbo[0]); gles30.glbegintransformfeedback(gles30.gl_points); gles30.gldrawarrays(gles30.gl_points, 0, 5); gles30.glendtransformfeedback(); gles30.gldisable(gles30.gl_rasterizer_discard); gles30.glflush(); // fetch , print results float feedback[] = new float[5]; gles30.glgetbuffersubdata(gles30.gl_transform_feedback_buffer, 0, bufferlength, feedback); log.e("transformfeedback", string.format("%f %f %f %f %f\n", feedback[0], feedback[1], feedback[2], feedback[3], feedback[4])); }
my final implementation won't need read data out necessarily, use in shader on next pass(feedback). first step.
glgetbuffersubdata()
not available in es 3.0, or es 3.1 matter. there nothing missing in android java bindings in case.
the function use reading buffer data in es 3.0 glmapbufferrange()
. in c/c++ bindings, returns pointer cpu readable memory containing buffer content. don't forget call glunmapbuffer()
when you're done reading.
in android java bindings, function returns object of type buffer
. since can't directly read buffer, you'll have cast bytebuffer
first. not documented, answer here explains why believe type cast safe: safe usage of glmapbufferrange() on android/java.
Comments
Post a Comment