• Create Account

### #Actualic0de

Posted 10 December 2012 - 05:01 PM

So I put all my arrays into one and here is the resulting code:

void Chunk::upload()
{
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, totalsize * sizeof(float), vertices, GL_STATIC_DRAW);
}


void Chunk::draw()
{
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, bitmap);
glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, normap);
glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, heightmap);

glBindBuffer(GL_ARRAY_BUFFER, vBuffer);

glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(v_start * sizeof(float)));
glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(t_start * sizeof(float)));
glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(n_start * sizeof(float)));
glVertexAttribPointer(attribPointer, 4, GL_FLOAT, false, 0, BUFFER_OFFSET(tan_start * sizeof(float)));
glDrawArrays(GL_TRIANGLES, 0, numtriangles*3);
}


I works fine but the problem is that I thought I could improve performance by moving the part where I set my pointers into the upload function, however for some reason It doesn't work unless I set the pointers every time I draw. Any way I can avoid setting the pointers every draw call considering they never change?

### #1ic0de

Posted 10 December 2012 - 05:01 PM

So I put all my arrays into one and here is the resulting code:

void Chunk::upload()
{
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, totalsize * sizeof(float), vertices, GL_STATIC_DRAW);
}


void Chunk::draw()
{
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, bitmap);
glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, normap);
glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, heightmap);

glBindBuffer(GL_ARRAY_BUFFER, vBuffer);

glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(v_start * sizeof(float)));
glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(t_start * sizeof(float)));
glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(n_start * sizeof(float)));
glVertexAttribPointer(attribPointer, 4, GL_FLOAT, false, 0, BUFFER_OFFSET(tan_start * sizeof(float)));
glDrawArrays(GL_TRIANGLES, 0, numtriangles*3);
}


I works fine but the problem is that I thought I could improve performance by moving the part where I set my pointers into the upload function, however for some reason It doesn't work unless I set the pointers every time I draw. Any way I can avoid setting the pointers every draw call considering they never change.

PARTNERS