anopgl
08-22-2011, 01:29 AM
Hi
I'm drawing terrain using vertex arrays and texture is stored in PBO and everything works fine. Problem is when I store vertex data in VBO.
I suspect that problem that I need 2 buffers to be binded at the same time, PBO for texture and VBO for vertexes and it makes a confuse. When I bind these 2 buffers together outcome is completely erased texture (some mixed colors)
How to bind several buffers at the time without disturbing each other?
Thanks
BionicBytes
08-22-2011, 02:31 AM
Can you post some relevant code, ie the bits where you define the VBO and PBO, plus the bits of code where you load data into the buffers, and finally the drawing code.
anopgl
08-22-2011, 03:15 AM
Creating PBO
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &TextureId);
glBindTexture(GL_TEXTURE_2D, TextureId));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,TextureSizeX,TextureSizeY,
0,GL_RGB, GL_UNSIGNED_BYTE, pixTexture);
//store on pbo
glGenBuffers(1,&PboId);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,PboId);
glBufferData(GL_PIXEL_UNPACK_BUFFER,PboSize,pixTex ture,GL_STATIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);
if(pixTexture) free(pixTexture); pixTexture = NULL;
creating VBO
glGenBuffers(1,&VboId);
glBindBuffer(GL_ARRAY_BUFFER, VboId);
glBufferData(GL_ARRAY_BUFFER,
NumVertices*( sizeof(float) * 3)), pVertices,GL_STATIC_DRAW);
before drawing
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,0,pNormals);
glBindBuffer(GL_ARRAY_BUFFER, VboId);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT,0,BUFFER_OFFSET(0));
glEnableClientState(GL_INDEX_ARRAY);
glIndexPointer(GL_UNSIGNED_INT,0,pIndexes);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,G_iPbo);
glBindTexture(GL_TEXTURE_2D, TextureId);
glColor3f(1.0f, 1.0f, 1.0f);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glTexCoordPointer(2,GL_FLOAT,0,pTexCoord);
drawing -
notice - I'm keeping index array on CPU and not making it index buffer
We can assume that all the index (Offset , NumSteps) are correct since it works perfect when I turn off VBO
I'm not posting all the drawing loop since it's a bit complicated
but the relevant line is this
glDrawRangeElements(GL_TRIANGLE_STRIP,pIndexes[Offset+1],
pIndexes[Offset+NumSteps-2],
NumSteps, GL_UNSIGNED_INT,
pIndexes+Offset);
disabling , unbinding
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);
Thanks.
BionicBytes
08-22-2011, 03:49 AM
This could be your problem:
glIndexPointer(GL_UNSIGNED_INT,0,pIndexes);
glIndexPointer has nothing to do with vertex indicies (actually to do with colour indexes).
See here for a description (http://www.opengl.org/sdk/docs/man/xhtml/glIndexPointer.xml)
When you enable VBO rendering, you can still use CPU vertex indicies as a starter-for-ten. Then the next step is to also upload the indicies as a buffer object.
Also note that when you do want your vertex indicies to be uploaded as a buffer object, there is a separate element buffer binding point for that - so you will need another buffer object. I use the term EBO (Element Buffer Object).
anopgl
08-22-2011, 04:18 AM
Thank you for you pointing it out about glIndexPointer(GL_UNSIGNED_INT,0,pIndexes)! I really misinterpreted it and it's removed now,but it luckily didnt do any harm so far.
My problem is solved - the reason was weird - appears that you have to bind PBO first than all VBO and "vertex array state stuff"
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.