PDA

View Full Version : Sending *pointer to GLSL?



Golgoth
06-14-2006, 05:41 PM
Hi all!

I ve been reading OpenGLĀ® Shading Language, Second Edition... and its says for Uninforms variables:

All data types and arrays of all data types are supported for uniform qualified variables.My concern is this... we can sending a vector3 no problem... but what about an array of vector3... like sending Tangents to the shaders...

void glUniform3iv(GLint location, GLsizei count, const GLint *value)

the part im confused about is the *value, do I send someting like Tangent[0] as value?

thx

V-man
06-14-2006, 06:37 PM
Tangents are vertex attributes so you should send them as an array. Put them in your VBO along with your vertex position, normal, texcoord, ...

If you insist on doing it your way, then the call is

glUniform3iv(GLint location, X, &Tangent[0][0]);

where
GLint Tangent[X][3];

In your GLSL, you should have

uniform ivec3 Tangent[X];

Golgoth
06-14-2006, 07:12 PM
Tangents are vertex attributes so you should send them as an array. Put them in your VBO along with your vertex position, normal, texcoord, ...interesting, even though VOB are up and running, im not familiar with adding extra vertex attributes yet... I suppose it would be through glGetVertexAttribPointerv is that correct?

how would I send/retrieve them(the tangents) to/in the shader now? I m sorry, it must be super simple... but im not quite sure.

thx

V-man
06-15-2006, 11:26 AM
If you are using generic vertex attributes, then it's just another call to glVertexAttribPointer


glVertexAttribPointer(index, 3, GL_FLOAT, GL_FALSE, sizeof(my_vertex), myVBOOffset);


//my_vertex is
struct my_vertex
{
x, y, z;
nx, ny, nz;
s, t;
tanX, tanY, tanZ;
binX, binY, binZ;
};Sounds like glGetVertexAttribPointerv is for getting the parameters back from GL. Pretty useless.

In the GLSL code, you need to use a special name, but it slips me for the moment.

I myself use glTexCoordPointer, so in GLSL, it would be gl_MultiTexCoord0 or 1 or 2, ...

Golgoth
06-15-2006, 03:18 PM
Hi V-man! thx for your post!

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 &l_buffer = in_primitive->GetBufferArray();
if (l_buffer == 0)
glGenBuffers((GLsizei) 1, &l_buffer);

glBindBuffer(GL_ARRAY_BUFFER, l_buffer);

if (in_primitive->IsState(STATE_RESET_BUFFER))
{
GLuint &l_offsUVs = in_primitive->GetUVId();
GLuint &l_offsCol = in_primitive->GetColorId();
GLuint &l_offsFog = in_primitive->GetFogCoordId();
GLuint &l_offsNor = in_primitive->GetNormalId();
GLuint &l_offsTan = in_primitive->GetTangentId();
GLuint &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);

...SNIPIs this what you had in mind?

glBindAttribLocation to retrieve in shader?

Golgoth
06-16-2006, 11:02 AM
I ve got it working, this thread is closed. thx agian for your inputs!