Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:32:06+00:00 2026-05-27T10:32:06+00:00

I just started OpenGL for iPhone, using GLKit. My programming background is almost just

  • 0

I just started OpenGL for iPhone, using GLKit. My programming background is almost just java and objective c with little,little experiences with C, C++ over ten years ago. All what remained is a remote memory of how I struggled with pointers – and I think I failed.

Now it seems as if it all comes back to me …

I went to some iterations of the great, great tutorial series of Ian Terrel, which really helped me (Thanks!!!).

This question is about the following parts of the code (which is mostly directly taken from the tutorials):

@interface AAAShape : NSObject
{
  NSMutableData *vertexData;
  // ...
}
@property(readonly) int vertexCount;
@property(readonly) GLKVector2 *vertices; 
//...    
@end

@implementation AAAShape
//...


-(GLKVector2 *)vertices
{
  if(!vertexData)
  {
    vertexData = [NSMutableData dataWithLength:sizeof(GLKVector2)*self.vertexCount];
  }
  return [vertexData mutableBytes];
}

-(void)renderInScene:(AAAScene *)scene 
{
  //... Effect Stuff
  //...
  glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
  //...
}
//...
@end

//Using the Shape: 
//(AATriangle is of AAAShape and implements the vertextCount with "return 3;")    
AAATriangle *triangle = [[AAATriangle alloc]init];

triangle.vertices[0] = GLKVector2Make(2., .0);
triangle.vertices[1] = GLKVector2Make(-2., .0);
triangle.vertices[2] = GLKVector2Make(.0, -3.);
//...

All of this works really fine, but then I stumbled upon the following in Apple’s OpenGl Guide:

[…], but is inefficient. Each time DrawModel is called, the index
and vertex data are copied to OpenGL ES, and transferred to the
graphics hardware.[…] can impact performance. […]your application
should store its vertex data in a vertex buffer object (VBO). […]

The suggested code sample there, for doing that (other sources showing nearly the same) looks like this:

GLuint    vertexBuffer;
void CreateVertexBuffers()
{

    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

} 

and later drawing with:

void DrawModelUsingVertexBuffers()
{
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glVertexAttribPointer(ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(vertexStruct), (void*)offsetof(vertexStruct,position));
    glEnableVertexAttribArray(ATTRIB_POSITION);
   //...
 }

I’ve a few questions about it:

  • How significant are the mentioned performance impacts? Is it necessary to change the code?
  • What the … is really going on in the first code samples above (Ian’s/my code)?
    • Why is it possible to set vertices[i] if vertices is readonly and where and how memory is allocated for vertices?
  • Where could I put the code above (the buffer-creating and -binding stuff) in Ian’s/my approach and why is there no connection (in means of variables are method calls or something) between the binding and the drawing?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:32:07+00:00Added an answer on May 27, 2026 at 10:32 am
    • How significant are the mentioned performance impacts? Is it necessary to change the code?

    If the data is constantly changing, there is little gained from a VBO. If however the geometry is static it makes a huge difference, as it saves precious bandwidth between CPU and GPU not to copy it all the time.

    • What the … is really going on in the first code samples above (Ian’s/my code)?

    An array is filled with the vertex data. Then a pointer in OpenGL is set to that data. When glDraw… is called, the pointers are dereferenced, and the data fetch from process memory to the render side, processed there in drawing operations.

    • Why is it possible to set vertices[i] if vertices is readonly and where and how memory is allocated for vertices?

    Because only the pointer is readonly. The variable it points to is read/write

    • Where could I put the code above (the buffer-creating and -binding stuff) in Ian’s/my approach

    glGenBuffers and glBufferData go to the vertex data creation. glVertexPointer stays where it is. and glBindBuffer is used at both sites.

    and why is there no connection (in means of variables are method calls or something) between the binding and the drawing?

    I’m note sure what you mean by that question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started using Java (for Android, if that matters) and all I want is
I am just getting started with using opengl in my apps and I get
I just started with OpenGL programming and I am building a clock application. I
So I just started switching over from SDL to OpenGL today and I'm having
I've just started with opengl but I ran into some strange behaviour. Below I
Just started with JQuery and I've managed to pass a parameter using POST, firebug
Just started coding in AS3 with FlashDevelop and coming from a C# background, I
Have just started using Google Chrome , and noticed in parts of our site,
I just started thinking about creating/customizing a web crawler today, and know very little
I recently started working with OpenGL ES for the iPhone, and I am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.