Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Wed, 10 May 2017 21:51:27 +0000 (07:51 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 10 May 2017 21:53:03 +0000 (07:53 +1000)
1  2 
source/blender/gpu/intern/gpu_buffers.c

index 7a5ed4784d4ac7fb23cf2afc66c6dec0177daf66,6a2aa106f6a46a4923c01ef4665872e3c12c2ae4..707bdf7d829dfbc78469ac3f3e76899f2e4bb77c
@@@ -1104,41 -1057,40 +1104,44 @@@ void GPU_update_mesh_pbvh_buffers
  
                copy_v4_v4(buffers->diffuse_color, diffuse_color);
  
+               uchar diffuse_color_ub[4];
+               rgba_float_to_uchar(diffuse_color_ub, diffuse_color);
                /* Build VBO */
 -              if (buffers->vert_buf)
 -                      GPU_buffer_free(buffers->vert_buf);
 -              buffers->vert_buf = GPU_buffer_alloc(sizeof(VertexBufferFormat) * totelem);
 -              vert_data = GPU_buffer_lock(buffers->vert_buf, GPU_BINDING_ARRAY);
 +              VERTEXBUFFER_DISCARD_SAFE(buffers->vert_buf);
  
 -              if (vert_data) {
 +              /* match 'VertexBufferFormat' */
 +              VertexFormat format = {0};
 +              VertexBufferAttrID vbo_id;
 +              gpu_pbvh_vert_format_init__gwn(&format, &vbo_id);
 +
 +              buffers->vert_buf = VertexBuffer_create_with_format(&format);
 +              VertexBuffer_allocate_data(buffers->vert_buf, totelem);
 +
 +              if (buffers->vert_buf->data) {
                        /* Vertex data is shared if smooth-shaded, but separate
                         * copies are made for flat shading because normals
                         * shouldn't be shared. */
                        if (buffers->smooth) {
 -                              for (i = 0; i < totvert; ++i) {
 +                              for (uint i = 0; i < totvert; ++i) {
                                        const MVert *v = &mvert[vert_indices[i]];
 -                                      VertexBufferFormat *out = vert_data + i;
 -
 -                                      copy_v3_v3(out->co, v->co);
 -                                      memcpy(out->no, v->no, sizeof(short) * 3);
 +                                      VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.pos, i, v->co);
 +                                      VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.nor, i, v->no);
                                }
  
 -                              for (i = 0; i < buffers->face_indices_len; i++) {
 +                              for (uint i = 0; i < buffers->face_indices_len; i++) {
                                        const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
                                        for (uint j = 0; j < 3; j++) {
-                                               int v_orig = buffers->mloop[lt->tri[j]].v;
-                                               int v_index = face_vert_indices[i][j];
-                                               uchar color_ub[3];
 -                                              VertexBufferFormat *out = vert_data + face_vert_indices[i][j];
 -
++                                              int vidx = face_vert_indices[i][j];
                                                if (vmask) {
-                                                       gpu_color_from_mask_copy(vmask[v_orig], diffuse_color, color_ub);
 -                                                      uint v_index = buffers->mloop[lt->tri[j]].v;
 -                                                      gpu_color_from_mask_copy(vmask[v_index], diffuse_color, out->color);
++                                                      int v_index = buffers->mloop[lt->tri[j]].v;
++                                                      uchar color_ub[3];
++                                                      gpu_color_from_mask_copy(vmask[v_index], diffuse_color, color_ub);
++                                                      VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.col, vidx, color_ub);
                                                }
                                                else {
-                                                       rgb_float_to_uchar(color_ub, diffuse_color);
 -                                                      copy_v3_v3_uchar(out->color, diffuse_color_ub);
++                                                      VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.col, vidx, diffuse_color_ub);
                                                }
-                                               VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.col, v_index, color_ub);
                                        }
                                }
                        }
  
                                        for (uint j = 0; j < 3; j++) {
                                                const MVert *v = &mvert[vtri[j]];
 -                                              VertexBufferFormat *out = vert_data;
  
 -                                              copy_v3_v3(out->co, v->co);
 -                                              copy_v3_v3_short(out->no, no);
 -                                              copy_v3_v3_uchar(out->color, color_ub);
 +                                              VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.pos, vbo_index, v->co);
 +                                              VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.nor, vbo_index, no);
-                                               uchar color_ub[3]; \
-                                               if (vmask)
-                                                       gpu_color_from_mask_copy(fmask, diffuse_color, color_ub);
-                                               else
-                                                       rgb_float_to_uchar(color_ub, diffuse_color);
 +                                              VertexBuffer_set_attrib(buffers->vert_buf, vbo_id.col, vbo_index, color_ub);
  
 -                                              vert_data++;
 +                                              vbo_index++;
                                        }
                                }
                        }