Sign in to follow this  

texturing VBO problems

This topic is 4305 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

I just recently converted our project to use VBO's for our terrain rendering. I build the VBO's as the Octree is being constructed. The geometry is rendering fine, however the texture is now not showing at all, instead we simply have a flat colored terrain. I was using indexed vertex arrays as such:
[source lang = "cpp"] 
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, fVerts);
glNormalPointer(GL_FLOAT, 0, fNormals);
glTexCoordPointer(2, GL_FLOAT, 0, fTexCoords);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID[0]);
glDrawElements(GL_TRIANGLES, uiFaceListCount * 3, GL_UNSIGNED_INT, pFaceList);
But now that I am using VBOs I do the following.
[source lang = "cpp"]
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, fTexCoords);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pNode->GetBufferID())
			glDrawElements(GL_TRIANGLES, uiFaceListCount * 3, GL_UNSIGNED_INT, 0);


I'm not sure if I have to handle textures differently when using VBOs or not. Is there some way to map them to the VBO? Any help is appreciated. Thanks

Share this post


Link to post
Share on other sites
Well I got the textures working correctly by actually storing texture coords in a VBO of their own. However, with texturing on my framerate drops from ~150 to under 5. I'm apparently doing something wrong here. My guess is that I'm either mapping the texture coordinates way too often or that they are very unorganized so my cache misses are through the roof.

It doesn't make sense that it should be that big of a hit though. Any ideas?

Share this post


Link to post
Share on other sites
OK. This is quite a bit of code, I in fact am building the vbo's in my Octree, which means I have to have a VBO per Octree node. I also build VBOs of texture coordinates, which is where the problem is lying, because my texture maps completely incorrectly right now. But here is the code.

Setup of VBOs in the octree (be warned, this is beefy):

[source lang = "cpp"]
// This isn't the complete function, I am trying to only show relavent code

if (pNode->m_uiNumFaces > 0)
{
glGenBuffers(1, &pNode->BufferID);
glGenBuffers(1, &pNode->TexBufferID);
pNode->m_uiFaceList = new unsigned int [pNode->m_uiNumFaces * 3];
pNode->m_fTexCoords = new float [pNode->m_uiNumFaces * 2 * 3];

for (int i = 0; i < uiNumFaces; i++)
{
if (pNode->m_bArray[i])
{
// give me the appropriate faces
pNode->m_uiFaceList[nCount++] = uiFaceList[i*3];
pNode->m_uiFaceList[nCount++] = uiFaceList[i*3+1];
pNode->m_uiFaceList[nCount++] = uiFaceList[i*3+2];

// and texture coords
pNode->m_fTexCoords[tCount++] = fTexCoords[uiFaceList[i*3]*2];
pNode->m_fTexCoords[tCount++] = fTexCoords[uiFaceList[i*3]*2+1];

pNode->m_fTexCoords[tCount++] = fTexCoords[uiFaceList[i*3+1]*2];
pNode->m_fTexCoords[tCount++] = fTexCoords[uiFaceList[i*3+1]*2+1];

pNode->m_fTexCoords[tCount++] = fTexCoords[uiFaceList[i*3+2]*2];
pNode->m_fTexCoords[tCount++] = fTexCoords[uiFaceList[i*3+2]*2+1];
}
}

// bind our face list
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pNode->BufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * pNode->m_uiNumFaces * 3, pNode->m_uiFaceList, GL_STATIC_DRAW);
// bind our texture coords
glBindBuffer(GL_ARRAY_BUFFER_ARB, pNode->TexBufferID);
glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(float) * pNode->m_uiNumFaces * 3 * 2, pNode->m_fTexCoords, GL_STATIC_DRAW_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, 0);

pNode->m_fCenter.x = (pNode->GetMin()[0] + pNode->GetMax()[0]) / 2;
pNode->m_fCenter.y = (pNode->GetMin()[1] + pNode->GetMax()[1]) / 2;
pNode->m_fCenter.z = (pNode->GetMin()[2] + pNode->GetMax()[2]) / 2;

pNode->m_fRadius = sqrt(((pNode->m_fCenter.x - pNode->GetMax()[0]) * (pNode->m_fCenter.x - pNode->GetMax()[0]) +
(pNode->m_fCenter.y - pNode->GetMax()[1]) * (pNode->m_fCenter.y - pNode->GetMax()[1]) +
(pNode->m_fCenter.z - pNode->GetMax()[2]) * (pNode->m_fCenter.z - pNode->GetMax()[2])));
}

// we're done here
return;
}

//....
}



And now the drawing code (again, a little beefy):
[source lang = "cpp"]
void RenderOctreeNode(COctree *pNode)
{
if (!pNode)
return;

if (pNode->IsLeaf())
{
if (!pNode->HasFaces()) return;

//DrawBoundingBox(pNode->GetMin(), pNode->GetMax());

float fRadius = pNode->GetRadius(pNode);
Vec3f fCenter = pNode->GetCenter(pNode);

if (pFrustum->Inside(fCenter.x, fCenter.y, fCenter.z, fRadius))
{
unsigned int uiFaceListCount = pNode->GetNumFaces();

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pNode->GetBufferID());
glBindBuffer(GL_ARRAY_BUFFER_ARB, pNode->GetTexID());
glTexCoordPointer(2, GL_FLOAT, 0, 0);

glDrawElements(GL_TRIANGLES, uiFaceListCount * 3, GL_UNSIGNED_INT, 0);

numTris += uiFaceListCount;
numNodes++;
}
}
else
{
COctree **ppChildren = pNode->GetChildren();
RenderOctreeNode(ppChildren[FRONT_TOP_LEFT]);
RenderOctreeNode(ppChildren[FRONT_TOP_RIGHT]);
RenderOctreeNode(ppChildren[BACK_TOP_RIGHT]);
RenderOctreeNode(ppChildren[BACK_TOP_LEFT]);

RenderOctreeNode(ppChildren[FRONT_BOTTOM_LEFT]);
RenderOctreeNode(ppChildren[FRONT_BOTTOM_RIGHT]);
RenderOctreeNode(ppChildren[BACK_BOTTOM_RIGHT]);
RenderOctreeNode(ppChildren[BACK_BOTTOM_LEFT]);
}
}


Share this post


Link to post
Share on other sites

This topic is 4305 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this