0
\$\begingroup\$

I'm making a Minecraft style game and currently storing 36 vertices and texture coordinates per cube. Could I make an EBO for only the position and leave the texture coordinates as they are?

OK i think thsi is how i will do it.

I would have an array of 24 vertices(3*GLfloat) and 24 texture coordinates(2*GLfloat) for the corners

then i would have an EBO pointing to the corners with 36 indices

So memory total = 24*3*4 + 24*2*4 + 36*4 = 624 bytes

instead of

36*3*4 + 36*2*4 = 720 bytes

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for posting your solution! Please not that, typically, instead of posting the answer in the question, you create an answer post and put that there: it's a perfectly valid option here :) \$\endgroup\$ Commented Jan 5, 2017 at 14:53

2 Answers 2

1
\$\begingroup\$

No, you can't, however you can make it only use 24 vertices.

You can define each face with 4 vertices:

0, 0, 0
1, 0  0
1, 1, 0
0, 1, 0

Then the ibo would contain the data

0, 1, 3,
3, 1, 2

If you define each face separately, so that there's no overlap between separate faces, you need 6 * 4 = 24 vertices

If you calculate the byte count (let's say 1 value is 4 bytes) then your current solution is 36 * (3 * 4 + 3 * 4 + 2 * 4) = 1152 bytes. With only 24 vertices and the ibo (you need 36 value in the ibo for 1 cube) that becomes 24 * (3 * 4 + 3 * 4 + 2 * 4) + 36 * 4 = 912 bytes. (I counted the vertices, normals and texture coordinates, but if you have any more data, then the gap becomes bigger)

\$\endgroup\$
4
  • \$\begingroup\$ Ok I think I could do this with 624 bytes instead of 720. Would this have a performance penalty? (I'm not using normals yet) \$\endgroup\$ Commented Jan 5, 2017 at 14:28
  • \$\begingroup\$ @BenBeazley This is just indexing, it wouldn't \$\endgroup\$ Commented Jan 5, 2017 at 14:37
  • \$\begingroup\$ &Bálint Side note, would using glushort or gluchar be a better option for indexes because i only need numbers up to 24 in the EBO \$\endgroup\$ Commented Jan 5, 2017 at 14:46
  • \$\begingroup\$ @Ben You could use glubyte if you can, but at this scale that doesn't make a difference \$\endgroup\$ Commented Jan 5, 2017 at 15:13
3
\$\begingroup\$

This is normally solved by adding an extra layer of indirection.

So, your GL_ELEMENT_ARRAY_BUFFER will point to a vertex buffer containing two ints: one of which is a lookup for the position, the other of which is a lookup for the texcoord. In your vertex shader you read these, then use them to lookup other buffers (or textures) to get the actual data.

Of course, that means that your vertex fetching is a little more complex, which may negate any theoretical performance improvement from using less data. GPUs are counter-intuitive like that: sometimes the fast path involves using more memory.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.