Note that there are some explanatory texts on larger screens.

plurals
  1. POCocoa - OpenGL ES - Wrapping my head around C-Arrays
    primarykey
    data
    text
    <p>This is more of a general theory question that I just cant seem to wrap my head around, so Ill explain what Im trying to do.</p> <p>Im writing a 3D Game Engine with Cocoa and OpenGL ES. Im trying to determine the best way to store my vertex data for my 3d models (each vertex has an x, y, and z position).</p> <p>Previously, I was storing each vertex as an individual custom object (<code>AEVertex</code>), this object had an x, y, and z instance variable. The issue is I am using the command <code>glDrawArrays()</code>, which takes the address of a C-Array as it's first param. This C-Array is supposed to be a one-dimensional array storing all of the vert positions in succesion (vert 1's x position, vert 1's y position, vert 1's z position, vert 2's x position, vert 2's y position, vert 2's z position, etc, etc).</p> <p>The issue I faced was that I had to gather all of the vertexdata for a given model from each individual vertex object and create a C-Array big enough to store all of these verts / fill the C-Array with the vert data, and then pass in this array. This is obviously going to slow things down a lot, as I am essentially allocating memory for every model twice.</p> <p>So what I would LIKE to do is simply have a class AEMesh, that has a C-Array instance variable that stores all of the vertexdata for the given AEMesh object. My issue with this is that as far as I know its only possible to declare C-Array instance variables of a fixed size, however a) all of my models will have different numbers of vertices and b) I wont know how many verts each model has until reading in the model data at runtime.</p> <p>So, my questions:</p> <ol> <li><p>Is there some way to create a mutable, dynamic C-Array as an instance variable for an object? Thus allowing me to add new array indices for every vertex read in from a given AEMesh's model file?</p></li> <li><p>If not, Im wondering if I can create the vertexdata C-Array outside of the AEMesh's initialization, and simply have a pointer instance variable pointing to nil when an AEMesh is instantiated, and repointed to the created C-Array after the C-Array is declared.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    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.
    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