Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGLES2 iOS: How best to stream vertex animation for dynamic terrain?
    primarykey
    data
    text
    <p>I'm writing an app that creates a dynamic 640*480 terrain (changes every frame). Each terrain is stored in a raw data file which represents a string of (float) height values. So far I can read the files in sequence into memory, and dynamically create a mesh based on height values each frame (and the framerate is actually reasonable), but I am maxing out at around 20 frames before my app quits with no error or stack trace.</p> <p>I suspect that I am approaching this incorrectly. How would I stream this data so that I don't have to hold each frame in memory?</p> <p>Here is a section from my data class, which holds a collection of terrains:</p> <pre><code>- (void)addModelWithID:(int)modelID; { NSString* resourcePath = [[NSBundle mainBundle] resourcePath]; NSString* fileName = [NSString stringWithFormat:@"depth_%i.raw", modelID]; NSString* fullPath = [resourcePath stringByAppendingPathComponent:fileName]; NSData *myData = [NSData dataWithContentsOfFile:fullPath]; if (!myData) return; const float *data = [myData bytes]; int meshWidth = 640; int meshHeight = 480; Model *kModel = [[Model alloc] init]; int indicesPtr = 0; int depthPtr = 2; for (int y=0;y&lt;meshHeight;y++) // Loop through y pixels { for (int x=0;x&lt;meshWidth;x++) // Loop through x pixels { // Set up vertex positions int index = y*meshWidth+x; float xpos = ((float)x/(float)(meshWidth-1)) - 0.5f; float ypos = ((float)y/(float)(meshHeight-1)) - 0.5f; float zpos = (float)data[index]; kModel.vertices1[index*3+0] = xpos; kModel.vertices1[index*3+1] = ypos; kModel.vertices1[index*3+2] = zpos; // Create a new index based on whether the current line is even or odd (flipped horizontally if odd) int _index = (y%2==0) ? index : (y*meshWidth) + ((meshWidth-1)-x); //Create the first index kModel.indices[indicesPtr++] = _index; // Create the second index if ((x&lt;meshWidth-1) || (x==meshWidth-1 &amp;&amp; y==meshHeight-2)) kModel.indices[indicesPtr++] = _index+meshWidth; } } } // Add the model to the data object [Models addObject:kModel]; [kModel release]; } </code></pre> <p>And my draw code (each frame I call a different terrain, hopefully up to 500 or so, but I max out at ~20:</p> <pre><code>{ ... Model *kModel = [kData.kinectModels objectAtIndex:sequenceCurrentFrame]; glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)kModel.vertices1); glEnableVertexAttribArray(vertexHandle); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&amp;modelViewProjection.data[0]); glDrawElements(GL_TRIANGLE_STRIP, kModel.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)kModel.indices); ... } </code></pre> <p>Thanks a million for your help,</p> <p>Josh</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload