Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

One Large VBO, many smaller IBO

This topic is 3527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Am I on crack, but aren't I supposed to be able to use one large VBO e.g. 2049x2049 for my terrain and then use many smaller IBO e.g. 65x65-2049x2049? Because its not working, I am trying to make a mapeditor and allow the user to select the size... Right now I need to make a VBO for each size and a IBO for each size which seems wasteful, and should be able to make a large VBO that is 2049x2049 and just have the IBO render the size of mesh based on user input? This is all done in one call BTW.... Thanks

Share this post


Link to post
Share on other sites
Advertisement
I use only one VBO and one IBO for all size patches. And when issuing drawing command I use offset for IBO to select correct patch for needed size.

Share this post


Link to post
Share on other sites
I am not sure we are on the same page... I want the entire terrain setup in one VBO. Then I only want to draw a 65x65 section and not draw the rest of the 2049x2049 section of terrain, but when I do this (see code below) setup the 2049x2049 VBO it only works with a 2049x2049 IBO, if I change to say 65x65 the mesh becomes all messed up and shows only a few lines....


void Renderer::Setup(void)
{
vertexStride = sizeof(float)*5;
texCoordOffset = sizeof(float)*3;
//setup the VBO for the largest mapsize
//then use IBO for each size to render that mapsize
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

SetupVBO_IBO_65();
SetupVBO_IBO_129();
SetupVBO_IBO_257();
SetupVBO_IBO_513();
SetupVBO_IBO_1025();
SetupVBO_IBO_2049();
}

void Renderer::SetupVBO_IBO_2049(void)
{
unsigned int index = 0, i = 0, j = 0;
glGenBuffers(1, &vbo[VBO_2049]);
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_2049]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*2049*2049, NULL, GL_DYNAMIC_DRAW);
float* vertBuff = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
for(i = 0; i < 2049; ++i)
{
for(j = 0; j < 2049; ++j)
{
vertBuff[index++] = float(j);
vertBuff[index++] = 0.0f;
vertBuff[index++] = float(i);
vertBuff[index++] = float(j) / float(2049-1.0f);
vertBuff[index++] = float(i) / float(2049-1.0f);
}
}
glUnmapBuffer(GL_ARRAY_BUFFER);

index = 0;
length2049 = ((2049-1) * (2049*2+2))-2;
glGenBuffers(1, &ibo[IBO_2049]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_2049]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*length2049, NULL, GL_STATIC_DRAW);
GLuint* triBuff = (GLuint*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
for(i = 0; i < 2049-1; ++i)
{
for(j = 0; j < 2049; ++j)
{
if(j == 0 && i != 0)
triBuff[index++] = j + (i*2049);
triBuff[index++] = j + (i*2049);
triBuff[index++] = j + ((i+1)*2049);
if(j == (2049-1) && i != (2049-2))
triBuff[index++] = j + ((i+1)*2049);
}
}
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
}

void Renderer::Draw(void)
{
switch(mapFileData.mapSize)
{
case 65:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_65]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_65]);
break;
case 129:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_129]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_129]);
break;
case 257:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_257]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_257]);
break;
case 513:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_513]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_513]);
break;
case 1025:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_1025]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_1025]);
break;
case 2049:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_2049]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_2049]);
break;
default:
glBindBuffer(GL_ARRAY_BUFFER, vbo[VBO_65]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo[IBO_65]);
break;
}
glVertexPointer(3, GL_FLOAT, vertexStride, BUFFER_OFFSET(0));
glTexCoordPointer(2, GL_FLOAT, vertexStride, BUFFER_OFFSET(texCoordOffset));
switch(mapFileData.mapSize)
{
case 65:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length65, length65, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
case 129:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length129, length129, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
case 257:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length257, length257, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
case 513:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length513, length513, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
case 1025:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length1025, length1025, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
case 2049:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length2049, length2049, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
default:
glDrawRangeElements(GL_TRIANGLE_STRIP, 0, length65, length65, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
break;
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!