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 8125713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:54:22+00:00 2026-06-06T06:54:22+00:00

I trying to implement some relatively simple 2D sprite batching in OpenGL ES 2.0

  • 0

I trying to implement some relatively simple 2D sprite batching in OpenGL ES 2.0 using vertex buffer objects. However, my geometry is not drawing correctly and some error I can’t seem to locate is causing the GL ES analyzer in Instruments to report:

Draw Call Exceeded Array Buffer Bounds

A draw call accessed a vertex outside the range of an array buffer in use. This is a serious error, and may result in a crash.

I’ve tested my drawing with the same vertex layout by drawing single quads at a time instead of batching and it draws as expected.

// This technique doesn't necessarily result in correct layering, 
// but for this game it is unlikely that the same texture will 
// need to be drawn both in front of and behind other images.
while (!renderQueue.empty()) 
{
    vector<GLfloat> batchVertices;
    GLuint texture = renderQueue.front()->textureName;

    // find all the draw descriptors with the same texture as the first 
    // item in the vector and batch them together, back to front
    for (int i = 0; i < renderQueue.size(); i++) 
    {
        if (renderQueue[i]->textureName == texture)
        {
            for (int vertIndex = 0; vertIndex < 24; vertIndex++) 
            {
                batchVertices.push_back(renderQueue[i]->vertexData[vertIndex]);
            }

            // Remove the item as it has been added to the batch to be drawn 
            renderQueue.erase(renderQueue.begin() + i);
            i--;
        }
    }

    int elements = batchVertices.size();
    GLfloat *batchVertArray = new GLfloat[elements];
    memcpy(batchVertArray, &batchVertices[0], elements * sizeof(GLfloat));

    // Draw the batch
    bindTexture(texture);
    glBufferData(GL_ARRAY_BUFFER, elements, batchVertArray, GL_STREAM_DRAW);
    prepareToDraw();
    glDrawArrays(GL_TRIANGLES, 0, elements / BufferStride);

    delete [] batchVertArray;
}

Other info of plausible relevance: renderQueue is a vector of DrawDescriptors. BufferStride is 4, as my vertex buffer format is interleaved position2, texcoord2: X,Y,U,V…

Thank you.

  • 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-06-06T06:54:24+00:00Added an answer on June 6, 2026 at 6:54 am

    glBufferData expects its second argument to be the size of the data in bytes. The correct way to copy your vertex data to the GPU would therefore be:

    glBufferData(GL_ARRAY_BUFFER, elements * sizeof(GLfloat), batchVertArray, GL_STREAM_DRAW);
    

    Also make sure that the correct vertex buffer is bound when calling glBufferData.

    On a performance note, allocating a temporary array is absolutely unnecessary here. Just use the vector directly:

    glBufferData(GL_ARRAY_BUFFER, batchVertices.size() * sizeof(GLfloat), &batchVertices[0], GL_STREAM_DRAW);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement some simple caching into my application and I'm having some
I'm trying to implement some automated getter and setter for php objects. My target
I am trying to implement some custom security code into SSRS 2008 (not R2)
While trying to implement some jQuery UI Tabs using AJAX I keep running into
I am trying to implement some simple tooltip (TipTip) effect, but for some weird
I'm trying to implement some shaders from online tutorials (lighthouse3d.com) in my OpenGL ES
I'm trying to implement some very simple line drawing animation for my iPhone app.
im trying to implement some behaviors when a mapview element scrolls... by coding a
I'm trying to implement some rudimentary tabs in a Cocoa editor I'm working on.
I am trying to implement some unit testing for an old framework. I am

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.