Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Too many vertexes



Hi Filipe,
it worked, but your code had some small errors, I suppose typos.
The right code is:

    // define a structure in the header
    typedef struct {
      GLfloat coords[3];
    } MYCoords;

    // allocate a MYCoords pointer and *not* a GLfloat pointer
    MYCoords    *pVertex = malloc(mTotVertex * sizeof(MYCoords));

    // then assign the values...
    pVertex[p].coords[0] = pointC[0];
    pVertex[p].coords[1] = pointC[1];
    pVertex[p].coords[2] = pointC[2];


    // Then it works well with the VBO
    glBufferData(GL_ARRAY_BUFFER, (sizeof(GLfloat) * mTotVertex *  3),
                 pVertex, GL_STATIC_DRAW);

    // Then release the pointer
    free(pVertex);
    pVertex = nil;

Thanks for the "pointer"!!!


Best Regards
-- 
Lorenzo
email: email@hidden

> From: Filipe Varela <email@hidden>
> Date: Fri, 25 May 2007 12:55:18 +0100
> To: Lorenzo <email@hidden>
> Cc: email@hidden
> Subject: Re: Too many vertexes
> 
> That problem isn't related to available memory or the gpu memory. The
> whole thing takes
> 
> sizeof(GLfloat) * 3 * 480000 bytes which is way more than what you're
> allowed to statically allocate.
> use a GLfloat pointer like this
> 
> typedef struct {
> GLfloat coords[3];
> } vertex_t;
> 
> GLfloat *dataPtr = malloc(mTotVertexes * vertex_t);
> 
> What you're doiing is actually allocating the thing twice. Once
> statically with the declaration
> GLfloat vertexes[mTotVertexex][3]; //evaluates to static allocation
> of vertexes[480000][3]
> 
> this memory (if you could allocate it statically) would not be used
> by the rest of your program since you are reallocating it dynamically.
> 
> Question: why the double *?
> 
> Rewrite of your code... Should work
> 
>>   int         mTotVertexes = 480000;
>>     GLfloat     *vertexes;
>>     glBufferData(GL_ARRAY_BUFFER, (sizeof(GLfloat) * mTotVertexes *
>> 3),
>>                  vertexes, GL_STATIC_DRAW);
>> 
>> So I have tried to calloc the array this way.
>> 
>>     vertexes = (GLfloat *)malloc(mTotVertexes * 3 * sizeof(GLfloat));
> 
> Remember: you can use a simple vector (1d) to store objects
> (vertexes) with more than one coordinate.
> To iterate through the vector and set/get axis coordinates
> 
> for(i=0;i<mTotVertexes;i+=3) {
> x = vertexes[+0];
> y = vertexes[i+1];
> z = vertexes[i+2];
> }
> 
> And finally (THIS IS REALLY IMPORTANT): Do not ever do this
> vertexes[i] = (GLfloat*)calloc(3, sizeof(GLfloat));
> don't ever iterate through an array and allocate memory for each
> item. If you want to do this, you might as well use a linked list.
> The whole purpose of using arrays/vbos is to get a continuous sector
> in memory which can be easily copied back and forth with a single
> memcpy. By dynamically allocating EACH vertex's coordinates, you're
> incresing the probabilities of NOT having your data in a continuous
> block. The end result is a delay between reads/writes of each vertex
> while the gpu uses dma to search the address of the vertex before
> copy ( i think).
> 
> Cheers,
> Filipe
> 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden

References: 
 >Re: Too many vertexes (From: Filipe Varela <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.