<p><strong>Is it possible, in OpenGL (specifically in WebGL), to use a single value from buffer for multiple shader iterations? Like to put the same element from buffer into shader attribute multiple times?</strong>
Like:</p>
<p>glVertexAttribPointer(*, 0.5, *, *, *, *)</p>
<p>Here what I have now:</p>
<pre class="lang-js prettyprint-override"><code>//buffer 1
[
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
    62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 
    41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
]
// buffer 2
[
    -1, 1,
    1, -1,
    // ...
    1, 1,
]
</code></pre>
<p>Here what I want to have:</p>
<pre class="lang-js prettyprint-override"><code>//buffer 1
[
    0,
    4,
    62, 
    41,
    0,
    0,
    1,
]
// buffer 2
[
    -1, 1,
    1, -1,
    // ...
    1, 1,
]
</code></pre>
<p>I don't know how fit the second one with OpenGL API</p>
<p>I'm writing to my buffer1 a lot using CPU (glBufferSubData), that's why I need what I need.</p>
<p>I'll appreciate any <code>C OpenGL</code> / <code>JS WebGL</code> code</p>

CC BY-SA 4.0
2022-08-22T19:26:07.037Z
What is the relationship between these values and the primitives you want to generate?
Nicol Bolas
CC BY-SA 4.0
2022-08-22T20:13:54.827Z
I'm making grid of blocks. Buffer1 is block id buffer. block id determines what UV area of tileset texture to use for drawing. but since I'm only able to draw square using at least 6 vertices + GL_TRIANGLES, I have to put at least 6 same block Ids in buffer per 1 block. You want to suggest another solution for drawing block grid?
Forprix
CC BY-SA 4.0
2022-08-22T20:32:50.913Z
I think yes!
I also wrote this theory)
user18795
CC BY-SA 4.0
2022-08-23T11:00:26.190Z
If the grid is regular then there are several ways that don't use *any* buffers. For example, you can use the gl_VertexID and the modulo operator along with integer math to identify each vertex. Essentially you are giving every vertex in the grid a unique id then using that ID to compute the vertex location.
pmw1234
<opengl><glsl><c++><webgl><javascript>
How do I make "attribute vec0.5" in GLSL. Sorry if it confuses
Forprix
# How do I make "attribute vec0.5" in GLSL. Sorry if it confuses

(Asked by: username_0 on 2022-08-22)

**Is it possible, in OpenGL (specifically in WebGL), to use a single value from buffer for multiple shader iterations? Like to put the same element from buffer into shader attribute multiple times?**
Like:

glVertexAttribPointer(\*, 0.5, \*, \*, \*, \*)

Here what I have now:

```js
//buffer 1
[
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
    62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 
    41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
]
// buffer 2
[
    -1, 1,
    1, -1,
    // ...
    1, 1,
]

```

Here what I want to have:

```js
//buffer 1
[
    0,
    4,
    62, 
    41,
    0,
    0,
    1,
]
// buffer 2
[
    -1, 1,
    1, -1,
    // ...
    1, 1,
]

```

I don't know how fit the second one with OpenGL API

I'm writing to my buffer1 a lot using CPU (glBufferSubData), that's why I need what I need.

I'll appreciate any `C OpenGL` / `JS WebGL` code

**Tags:** opengl, glsl, c++, webgl, javascript

> **Comments:**
> **username_1**: What is the relationship between these values and the primitives you want to generate?  
> **username_0**: I'm making grid of blocks. Buffer1 is block id buffer. block id determines what UV area of tileset texture to use for drawing. but since I'm only able to draw square using at least 6 vertices + GL_TRIANGLES, I have to put at least 6 same block Ids in buffer per 1 block. You want to suggest another solution for drawing block grid?  
> **username_2**: I think yes! I also wrote this theory)  
> **username_3**: If the grid is regular then there are several ways that don't use *any* buffers. For example, you can use the gl_VertexID and the modulo operator along with integer math to identify each vertex. Essentially you are giving every vertex in the grid a unique id then using that ID to compute the vertex location.  

---

## 0 answers

