c++ - Iterate Vertex Buffer -


i'm trying emulate opengl's gl_point debugging , reverse-engineering opengl. i'm trying iterate vertex-buffer given pointer, index-buffer pointer , stride.

so did:

  • i hooked application uses opengl.
  • i monitored calls using gdebugger (application created amd debugging)

to render single model, calls are:

glpushmatrix() glviewport(4, 165, 512, 334) glmultmatrixf({1, 0, 0, 0} {0, 1, 0, 0} {0, 0, 1, 0} {26880, -741, 26368, 1})  glgenbuffersarb(1, 0x0a2b79d4) glbindbufferarb(gl_array_buffer, 15) glbufferdataarb(gl_array_buffer, 17460, 0x0c85de1c, gl_static_draw) glgenbuffersarb(1, 0x0a2b79d4) glbindbufferarb(gl_element_array_buffer, 16) glbufferdataarb(gl_element_array_buffer, 8946, 0x0c85de1c, gl_static_draw) glbindbufferarb(gl_array_buffer, 0) glvertexpointer(3, gl_float, 12, 0x31cb24c9) glenableclientstate(gl_vertex_array) gldisableclientstate(gl_normal_array) glbindbufferarb(gl_array_buffer, 15) glcolorpointer(4, gl_unsigned_byte, 12, 0x00000000) glenableclientstate(gl_color_array) gltexcoordpointer(2, gl_float, 12, 0x00000004) glenableclientstate(gl_texture_coord_array) gldrawelements(gl_triangles, 4473, gl_unsigned_short, 0x00000000) glpopmatrix() 

i hooked each of calls , stored parameters class , variables.

typedef struct  //a struct hold information every buffer application uses. {     glint id;     glsizei size;     glboolean reserved;     glboolean bound;     glenum type, usage;     uint32_t checksum;     const glvoid* bufferpointer; } bufferobject;   bufferobject currentbuffer;  //keep track of bound buffer. std::vector<bufferobject> listofbuffers;  //a list of buffers used in application.    //detours opengl function calls 1 first before calling original one. (opengl call interception.) void hookglvertexpointer(glint size, glenum type, glsizei stride, const glvoid *pointer) {     if ((size == 3) && (pointer != nullptr) && type == gl_float) //a model rendering..     {         modelrendering = true;         currentmodel.stride = stride;         currentmodel.vertexpointer = pointer; //store pointer.         listofmodels.push_back(currentmodel); //store model.     }      (*original_glvertexpointer) (size, type, stride, pointer); //call original function. }  //hook drawing function , each vertex being rendered. void hookgldrawelements(glenum mode, glsizei count, glenum type, const glvoid *indices) {     model* modelptr = &listofmodels.back();      if (modelptr != nullptr)     {         (int = 0; < count / 3; ++i) //so every triangle, want vertex of , store in vertices vector..         {             //this needs somehow use stride right vertex.             //perhaps currentbuffer.bufferpointer instead of modelptr->vertexpointer.             int x = *reinterpret_cast<const glfloat*>(reinterpret_cast<const char*>(modelptr->vertexpointer) * i);             int y = *reinterpret_cast<const glfloat*>(reinterpret_cast<const char*>(modelptr->vertexpointer) * + 1);             int z = *reinterpret_cast<const glfloat*>(reinterpret_cast<const char*>(modelptr->vertexpointer) * + 2);             modelptr->vertices.push_back(vector3d(x, y, z));         }     }     (*original_gldrawelements) (mode, count, type, indices);  //call original function. } 

how can vertices each triangle if have:

  • the vbo pointer.
  • the stride.
  • the index pointer.

how can vertices each triangle if have:

  • the vbo pointer.
  • the stride.
  • the index pointer.

you can't.

buffer objects do not have pointers. glbufferdata , glbuffersubdata copy data given pointer buffer object storage. opengl functions don't end in word "pointer", after execution of these functions, application free whatever wants them. opengl does not keep these pointers around. , therefore, neither should you.

if want track memory stored in buffer object, going have allocate memory yourself , copy yourself. when glbufferdata or glbuffersubdata call comes through, you're going have copy data pointer internal storage. if user maps buffer writing, you're going have wait buffer unmapped , copy data buffer using glgetbuffersubdata.

it's not going fast.

furthermore, need more stride if intend render vertex data. need type; assuming user using gl_float pretty poor assumption (unless want code application-specific).

in case, dealing ill-behaved application. seems using buffer objects some attributes (glcolorpointer, example) , not using them others (glvertexpointer). that's going make job harder.

you need opengl does. each attribute, need record type, stride, normalization, , given "pointer". also need check whether buffer bound gl_array_buffer (which means need stop pretending there can 1 buffer bound @ time. need track bound each different target).

if buffer bound gl_array_buffer when call 1 of "pointer" functions, means given "pointer" isn't pointer; it's byte offset relative beginning of buffer object. need store "pointer" and buffer object bound gl_array_buffer @ time function called. if no buffer bound there, pointer real memory pointer, application must keep alive long attempts render it.

at render time, each attribute, either use attribute's pointer, or use buffer object + offset compute buffer object data starts. use access copy of buffer object data. either way, resolve pointer. use type , normalization decide how read data, , use stride 1 vertex next.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -