Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
I'll try to keep this generic enough for anyone who knows Objective-C, where the problem is rooted (or maybe it's just in C?), and I'll avoid as much OpenGL as possible while still providing context.
I'm storing vertex data for a 3D object in a GLfloat
array like this
GLfloat teapot[] = { 1.0, 0.0, .... 0.0 };
(with real values omitted for brevity)
I'm then making a call like this
[self drawObject:teapot];
for the method defined like this
-(void) drawObject:(GLfloat *)object {
NSLog(@"%ld %ld", sizeof(object), sizeof(teapot));
}
Of course, the goal is to draw stuff, but it doesn't work properly because sizeof(object)
doesn't return the correct value. (I've similarly omitted all drawing code since it is irrelevant here, except that it requires using sizeof()
for glDrawArrays()
.
The output from NSLog()
looks something like this:
sizeof object = 4, sizeof teapot = 6336
showing that the size of the passed object
is different from the size of calling teapot
directly. It's weird because the reference works correctly, i.e. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, object)
works just fine, so it's definitely reading in the object. At present, I have to also pass in the size of the object as an integer just to get glDrawArrays
to work, which is kind of tacky. The passed code looks like this
[self drawObject:teapot ofSize:(int)sizeof(teapot)];
whereas I would really want to avoid passing the additional parameter.
Any ideas? Thanks for your time.