0
$\begingroup$

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:

//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:

//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

$\endgroup$
4
  • $\begingroup$ What is the relationship between these values and the primitives you want to generate? $\endgroup$ Aug 22, 2022 at 19:26
  • $\begingroup$ 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? $\endgroup$
    – Forprix
    Aug 22, 2022 at 20:13
  • $\begingroup$ I think yes! I also wrote this theory) $\endgroup$
    – user18795
    Aug 22, 2022 at 20:32
  • 1
    $\begingroup$ 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. $\endgroup$
    – pmw1234
    Aug 23, 2022 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.