<blockquote>
  <p>Is it even possible to have opengl assume that the Z is always 0?</p>
</blockquote>

<p>Yes it is. Just set the component count to 2 in <code>glVertexAttribPointer</code> and the other 2 components (<code>z</code> and <code>w</code>) will be auto filled with 0 and 1 resp.</p>

<blockquote>
  <p>Is it possible to reuse the color like to hat? </p>
</blockquote>

<p>No it is not. Opengl (and most other graphics apis) require that each vertex is referenced by only a single index.</p>

CC BY-SA 3.0
2016-05-13T11:55:50.033Z
You could pass the color data in a constant buffer rather than vertex data. If they are all the same.
RichieSams
CC BY-SA 3.0
2016-05-13T18:02:20.797Z
If GL ES 3.0 is a possibility, you could also use geometry instancing, but it doesn't seem to be available in GL ES 2.0 as far as I can tell from some googling.
Nathan Reed
CC BY-SA 3.0
2016-05-14T00:12:35.043Z
@Ratchet freak OK I re-strategised my plan! Thank you for letting me know.  If you are willing I made a new one because I am stuck on that one, I need to get good at vertex buffers somehow.
J.Doe
CC BY-SA 3.0
2016-05-14T00:12:37.637Z
http://stackoverflow.com/questions/37221027/how-to-write-complicated-vertex-buffers
J.Doe
CC BY-SA 3.0
2016-05-13T09:27:56.793Z
2016-05-13T09:27:56.793Z
ratchet freak
<p>I am making a 2d game in opengl es 2.0</p>

<p>Inside are tons of rectangles defined by 4 points and one 4 component color. </p>

<p>I am using vertex buffer objects, and I have heard that it is efficent to interlace the data. </p>

<p>So like traditionally you would do</p>

<pre><code>Corner.x
Corner.y
Corner.z
Corner.rgba
(repeat for each corner) 
</code></pre>

<p>However in my situations two assumptions can be made that can probably make things faster</p>

<pre><code>1. All the rectangles z values are 0
2. All corners of the rectangle have the same color. 
</code></pre>

<p>Is it possible, and what would it look like to have a buffer object structured like this. </p>

<pre><code>Corner.xy
Corner.xy
Corner.xy
Corner.xy
Color.rgba? 
</code></pre>

<p>Is it even possible to have opengl assume that the Z is always 0? Is it possible to reuse the color like to hat? </p>

<opengl-es>
Interlacing vertex buffer data with extra efficiency
J.Doe
# Interlacing vertex buffer data with extra efficiency

(Asked by: username_0 on 2016-05-12)

I am making a 2d game in opengl es 2.0

Inside are tons of rectangles defined by 4 points and one 4 component color.

I am using vertex buffer objects, and I have heard that it is efficent to interlace the data.

So like traditionally you would do

```
Corner.x
Corner.y
Corner.z
Corner.rgba
(repeat for each corner) 

```

However in my situations two assumptions can be made that can probably make things faster

```
1. All the rectangles z values are 0
2. All corners of the rectangle have the same color. 

```

Is it possible, and what would it look like to have a buffer object structured like this.

```
Corner.xy
Corner.xy
Corner.xy
Corner.xy
Color.rgba? 

```

Is it even possible to have opengl assume that the Z is always 0? Is it possible to reuse the color like to hat?

**Tags:** opengl-es


---

## 1 answers

### Answer by username_1 on 2016-05-13. Score: 3 | Accepted answer

> Is it even possible to have opengl assume that the Z is always 0?

Yes it is. Just set the component count to 2 in `glVertexAttribPointer` and the other 2 components (`z` and `w`) will be auto filled with 0 and 1 resp.

> Is it possible to reuse the color like to hat?

No it is not. Opengl (and most other graphics apis) require that each vertex is referenced by only a single index.

> **Comments:**
> **username_2**: You could pass the color data in a constant buffer rather than vertex data. If they are all the same.  
> **username_3**: If GL ES 3.0 is a possibility, you could also use geometry instancing, but it doesn't seem to be available in GL ES 2.0 as far as I can tell from some googling.  
> **username_0**: @username_1 username_1 OK I re-strategised my plan! Thank you for letting me know.  If you are willing I made a new one because I am stuck on that one, I need to get good at vertex buffers somehow.  
> **username_0**: http://stackoverflow.com/questions/37221027/how-to-write-complicated-vertex-buffers  

---

