Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

CJK overflow #5873

Closed
Closed

Description

@brunoabinader

This issue tracks the GL native-related tasks from mapbox/mapbox-gl-js#2930:

Activity

  1. added
    GL JS parity
    Core
    on Aug 5, 2016
  2. changed the title [-]CJF overflow[/-] [+]CJK overflow[/+] on Aug 5, 2016
  3. lbud commented on Aug 8, 2016

    @lbud
    Contributor

    @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
    void glVertexAttribPointer( GLuint index,
                                GLint size,
                                GLenum type,
                                GLboolean normalized,
                                GLsizei stride,
                                const GLvoid * pointer);
    
    

    [source]

    Right now we're attaching our a_data1 attributes as

    glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)
    
    • 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.

  4. 1ec5 commented on Aug 10, 2016

    @1ec5
    Contributor

    Related: #1681

  5. amyleew commented on Aug 11, 2016

    @amyleew
    Contributor

    Completed and merged #5908

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreGL JS parity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions