PDA

View Full Version : glEnableVertexAttribArray?



Golgoth
06-15-2006, 06:08 PM
Hi all!

can I use those:
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
with:
glEnableVertexAttribArray(6); < -- Tangents

or do I need to convert them all to VertexAttribArray?

Mars_999
06-15-2006, 08:08 PM
no you don't need to convert them all. Just upload your tangent vector with the glEnableVertexAttribArray() along with the rest of the setup code you need with that function and all should be fine.

Golgoth
06-15-2006, 08:39 PM
Hi Marss! would you mind ginving me a feedback on this?!

here is my VOB code:



#define TANGENT_ARRAY 6

void OpenGL::SetClientBuffer(Primitive *in_primitive)
{
m_CurrentColor = in_primitive->GetColor();
m_CurrentFogCoord = in_primitive->GetFogCoord();
m_CurrentNormal = in_primitive->GetNormal();
m_CurrentTangent = in_primitive->GetTangent();
m_CurrentUV = in_primitive->GetUV(0);
m_CurrentVertex = in_primitive->GetVertex();

GLuint &amp;l_buffer = in_primitive->GetBufferArray();
if (l_buffer == 0)
glGenBuffers((GLsizei) 1, &amp;l_buffer);

glBindBuffer(GL_ARRAY_BUFFER, l_buffer);

if (in_primitive->IsState(STATE_RESET_BUFFER))
{
GLuint &amp;l_offsUVs = in_primitive->GetUVId();
GLuint &amp;l_offsCol = in_primitive->GetColorId();
GLuint &amp;l_offsFog = in_primitive->GetFogCoordId();
GLuint &amp;l_offsNor = in_primitive->GetNormalId();
GLuint &amp;l_offsTan = in_primitive->GetTangentId();
GLuint &amp;l_offsVer = in_primitive->GetVertexId();

GLuint l_sizeCol = in_primitive->GetColorCount() * sizeof(Color);
GLuint l_sizeFog = in_primitive->GetFogCoordCount() * sizeof(GLfloat);
GLuint l_sizeNor = in_primitive->GetNormalCount() * sizeof(Vector3);
GLuint l_sizeTan = in_primitive->GetNormalCount() * sizeof(Vector3);
GLuint l_sizeUV0 = in_primitive->GetUVCount() * sizeof(Vector2);
GLuint l_sizeVer = in_primitive->GetVertexCount() * sizeof(Vector3);

GLuint l_sizeUVs = 0;
for (GLint i = 0; i < GetMaxTextures(); ++i)
if (in_primitive->GetUV(i) != NULL)
l_sizeUVs += l_sizeUV0;

l_offsUVs = 0;
l_offsCol = l_offsUVs + l_sizeUVs;
l_offsFog = l_offsCol + l_sizeCol;
l_offsNor = l_offsFog + l_sizeFog;
l_offsTan = l_offsNor + l_sizeNor;
l_offsVer = l_offsTan + l_sizeTan;

GLuint l_sizeVOB = l_offsVer + l_sizeVer;
glBufferData(GL_ARRAY_BUFFER, l_sizeVOB, NULL, in_primitive->GetBufferType());

Vector2 *l_uv = NULL;
for (GLint i = 0; i < GetMaxTextures(); ++i)
{
l_uv = in_primitive->GetUV(i);
if (l_uv != NULL)
glBufferSubData(GL_ARRAY_BUFFER, (i * l_sizeUVs), l_sizeUVs, l_uv);
}

glBufferSubData(GL_ARRAY_BUFFER, l_offsCol, l_sizeCol, m_CurrentColor);
glBufferSubData(GL_ARRAY_BUFFER, l_offsFog, l_sizeFog, m_CurrentFogCoord);
glBufferSubData(GL_ARRAY_BUFFER, l_offsNor, l_sizeNor, m_CurrentNormal);
glBufferSubData(GL_ARRAY_BUFFER, l_offsTan, l_sizeTan, m_CurrentTangent);
glBufferSubData(GL_ARRAY_BUFFER, l_offsVer, l_sizeVer, m_CurrentVertex);
}

...SNIP

if (m_CurrentTangent)
{
glEnableVertexAttribArray(TANGENT_ARRAY);
glVertexAttribPointer(TANGENT_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), BUFFER_OFFSET(in_primitive->GetTangentId()));
}
else
glDisableVertexAttribArray(TANGENT_ARRAY);

...SNIP

Mars_999
06-15-2006, 08:52 PM
Not sure what you want me to look at but after a quick glance, your call to glVertexAttribPointer() the BUFFER_OFFSET() needs a byte offset and not a memory address like VA do. So with your GetTangentID() is this returning something like this


sizeof(float) * 6;I am assuming 6, due to you probably like me, have vertices, normals, tangents, texcoords... I also am assuming Vector3 is a struct that holds all your vertex data?

Golgoth
06-15-2006, 09:13 PM
thx Marss!
GetTangentID() = in_primitive->GetTangentCount() * sizeof(Vector3);

which is the buffer offset... in fact I should rename to: GetTangentBufferOffset()


I am assuming 6I use 6 because i read that 1 to 5 are used for standard gl_* arrays... 6 and 7 are free... 8 and up are for matrices... correct?


I also am assuming Vector3 is a struct that holds all your vertex data?for tangents yes... but not for all data see l_size* variables.

Im trying to retrieve tangents in glsl... it is not working yet, so im still digging... to know that this piece of code is correct will definitely help!

thx again

06-16-2006, 08:58 AM
to know that this piece of code is correct will definitely help!don't post code and then ask people if it's correct!

rtfm... try it for yourself... debug it yourself...

only post a question if you really can't figure it out or make it work on your own. don't waste people's time...

Golgoth
06-16-2006, 10:41 AM
... excuse me???... please, feel free not to waist your time writing 2d comment like this one... unregistered...

I ve got it working, this thread is closed.

thx again for your inputs!