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

  • SEARCH
  • Home
  • 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 4325406
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:15:44+00:00 2026-05-21T09:15:44+00:00

I’m most likely going about this the wrong way, but I was wondering if

  • 0

I’m most likely going about this the wrong way, but I was wondering if anyone has some advice for how to keep track of where a non-unique element is within a vector?

I’m using glDrawArraysInstanced and using a vector to store translations (i.e. the first element is the x translation, the second y, the third z, repeat) that offset the position of a particular instance. This vector is put into a buffer and the drawing works as expected with a good performance boost from using the instancing. I don’t want to set the positions based on gl_InstanceID because the ID shifts depending on the number of instances drawn but I need the instances to stay consistent.

The problem comes in when trying to make the number of instances dynamic; I need to be able to add and remove elements in the vector efficiently without rebuilding the entire vector each time something changes. I’m not sure how to determine exactly where the translation is inside of the vector, however.


As an example:

  • Instance 0 uses translations 0,1,2
  • Instance 1 uses translations 3,4,5
  • Instance 2 uses translations 6,7,8

Want to delete Instance 1:

I can store the index of the x component of the translation when the translations are first constructed, so I know I need to .erase 3 elements starting at 3.

Want to delete Instance 2:

How do I know what the starting index is for this instance? The indices stored during construction are no longer valid.


I know this case is trivial and I can just subtract from the initial stored index, but if I have say 40,000 instances is there an efficient way to always know where the specific translation for that instance is within the vector? After several additions/deletions of instances the indices can shift around a fair amount.

Note: I want to use the vector because OpenGL needs float* to fill the buffer. I could easily use a map between an instance and it’s positions, but at some point I’d still need to get all of the positions together for rendering. If I’m missing something obvious on this point though please let me know. Swapping out the buffer doesn’t seem to impact performance much, but rebuilding the entire positions vector when something changes is far too slow.

Hope this isn’t too much of a wall of text.. any help would be appreciated.

  • 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-21T09:15:45+00:00Added an answer on May 21, 2026 at 9:15 am

    Use “GLDrawElementsInstanced” instead so that there is no need to change the translation vector (just reorder the indices).

    Update: (Real answer:)

    Bind the transformation buffer (with ALL transformations including invisible instances) as TBO, then access it as a texture in a shader. Supply an index attribute per instance (glVertexAttribDivisor=1) to use as a coordinate to fetch from your translation texture.

    This way you’ll need to modify only the index buffer and append new translations to the translation buffer. At some points you can perform a cleanup procedure of the translation buffer by removing unused values.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into

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.