You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
@amyleew@xrwang — here's what I'm seeing as far as updating SDFShader code in gl-native if one of you wants to take this on:
Here, a_data1 will need to be renamed in accordance with the shader attribute name change
the function call there will also need to change slightly: glVertexAttribPointer is what we use to tell the program where in a giant array of data to find the attributes for this particular SDF vertex, and its signature is
GL_UNSIGNED_BYTE is an unsigned (non-negative) 1-byte (8 bit) integer — the equivalence in gl-js is here. To account for the larger textures @xrwang changed that to Uint16, an unsigned 2-byte (16 bit) integer. There's a helpful reference for GL data types here: there you can see that if we want to change from an unsigned 8-bit integer to an unsigned 16-bit integer we'll want to switch that GL_UNSIGNED_BYTE to a GL_UNSIGNED_SHORT.
The 4 in the function call there refers to the size of that array. In the gl-js diff it looks like we're moving two of a_data's four vertex array members into a_data2 since we don't need to increase their size. That means we can change this 4 to 2. (Note: I'm not sure why a_data2 is assigned a size of 4 here — let's leave it at 4 for now (I would have expected it to be 2) rather than making it larger and follow up later if need be.)
It's important to note that normally, changing the sizes of array attributes would necessitate changing the final argument in this function call for all of the attributes following it. In this particular case it doesn't, but I'll explain why for future reference:
The last argument to this function is const GLvoid * pointer, and here it is offset + 8. offset is the pointer to where this SDF shader vertex array starts, which is why the first attribute's pointer is offset + 0 (because it's at the beginning of this vertex array), and then here's how you can figure out the rest of the offsets:
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0));
^- size of this attribute: 2 components
^- size of each component: 2 bytes (the size of a short)
v- the next attribute starts at 4 spaces/bytes after the beginning, because the above takes 2*2 spaces
MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4));
^- 2 components
^- 2 byte components
v- starts at where the previous attribute started (4 bytes in) + 2*2 (size of the last component set)
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8));
As it happens, we've both changed the data type and changed the size for a_data1 (a_texture_pos) and in doing so we're actually not changing the size in bytes of this subset of the vertex array (it was 4 (number of components) * 1 (size of a byte), and now it's 2 (number of components) * 2 (size of a short)), so the offset of the next attribute (+12) is still correct. SO, in this case we don't need to change the offset calculations :)
a text vertex buffer looks like
[x][x][x][x][x][x][x][x][x][x][x][x][x][x]
where each [x] is one byte. according to our code that breaks down to
shorts[0]: pos.x
[x][x]
shorts[1]: pos.y
[x][x]
shorts[2]: offset.x
[x][x]
shorts[3]: offset.y
[x][x]
ubytes[8]: tex.x
[x]
ubytes[9]: tex.y
[x]
ubytes[10]: labelminzoom
[x]
ubytes[11]: labelangle
[x]
ubytes[12]: minzoom
[x]
ubytes[13]: maxzoom
[x]
Since we're now using two-byte numbers for tex.x and tex.y (u_texture_pos), we need to make some changes here. We basically want to insert a third section here that is a uint16_t *ushorts. We won't stick them in the shorts section because shorts are signed (can be negative) and here we're using unsigned (non-negative) shorts. There we'll move the two texture position attributes (and since we'll still be counting by twos then, they will be shorts[4] and shorts[5]). After we add those, once we move on to the ubytes section, we'll start at (5+1)*2 => 12. So labelminzoom will be ubytes[12] and the following bytes will need to be renumbered accordingly.
Activity
[-]CJF overflow[/-][+]CJK overflow[/+]lbud commentedon Aug 8, 2016
@amyleew @xrwang — here's what I'm seeing as far as updating
SDFShadercode in gl-native if one of you wants to take this on:a_data1will need to be renamed in accordance with the shader attribute name changeglVertexAttribPointeris what we use to tell the program where in a giant array of data to find the attributes for this particular SDF vertex, and its signature is[source]
Right now we're attaching our
a_data1attributes asGL_UNSIGNED_BYTEis an unsigned (non-negative) 1-byte (8 bit) integer — the equivalence in gl-js is here. To account for the larger textures @xrwang changed that toUint16, an unsigned 2-byte (16 bit) integer. There's a helpful reference for GL data types here: there you can see that if we want to change from an unsigned 8-bit integer to an unsigned 16-bit integer we'll want to switch thatGL_UNSIGNED_BYTEto aGL_UNSIGNED_SHORT.4in the function call there refers to the size of that array. In the gl-js diff it looks like we're moving two ofa_data's four vertex array members intoa_data2since we don't need to increase their size. That means we can change this4to2. (Note: I'm not sure whya_data2is assigned a size of 4 here — let's leave it at 4 for now (I would have expected it to be 2) rather than making it larger and follow up later if need be.)The last argument to this function is
const GLvoid * pointer, and here it isoffset + 8.offsetis the pointer to where this SDF shader vertex array starts, which is why the first attribute's pointer isoffset + 0(because it's at the beginning of this vertex array), and then here's how you can figure out the rest of the offsets:As it happens, we've both changed the data type and changed the size for
a_data1(a_texture_pos) and in doing so we're actually not changing the size in bytes of this subset of the vertex array (it was 4 (number of components) * 1 (size of a byte), and now it's 2 (number of components) * 2 (size of a short)), so the offset of the next attribute (+12) is still correct. SO, in this case we don't need to change the offset calculations :)pos, the next four areoffset. Now we've taken up 8 bytes (this matches up with the offset here). Then we tell the shader program we want to start counting in one-byte increments instead of two-byte increments. Think of it like this:Since we're now using two-byte numbers for tex.x and tex.y (
u_texture_pos), we need to make some changes here. We basically want to insert a third section here that is auint16_t *ushorts. We won't stick them in theshortssection becauseshortsare signed (can be negative) and here we're using unsigned (non-negative) shorts. There we'll move the two texture position attributes (and since we'll still be counting by twos then, they will beshorts[4]andshorts[5]). After we add those, once we move on to theubytessection, we'll start at(5+1)*2=> 12. Solabelminzoomwill beubytes[12]and the following bytes will need to be renumbered accordingly.1ec5 commentedon Aug 10, 2016
Related: #1681
amyleew commentedon Aug 11, 2016
Completed and merged #5908