static void vrend_update_viewport_state(struct vrend_sub_context *sub_ctx)
{
   GLint cy;
   unsigned mask = sub_ctx->viewport_state_dirty;
   int idx;
   while (mask) {
      idx = u_bit_scan(&mask);

      if (sub_ctx->viewport_is_negative)
         cy = sub_ctx->vps[idx].cur_y - sub_ctx->vps[idx].height;
      else
         cy = sub_ctx->vps[idx].cur_y;
      if (idx > 0 && has_feature(feat_viewport_array))
         glViewportIndexedf(idx, sub_ctx->vps[idx].cur_x, cy, sub_ctx->vps[idx].width, sub_ctx->vps[idx].height);
      else
         glViewport(sub_ctx->vps[idx].cur_x, cy, sub_ctx->vps[idx].width, sub_ctx->vps[idx].height);

      if (idx && has_feature(feat_viewport_array))
         if (vrend_state.use_gles) {
            glDepthRangeIndexedfOES(idx, sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
         } else
            glDepthRangeIndexed(idx, sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
      else
         if (vrend_state.use_gles)
            glDepthRangefOES(sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
         else
            glDepthRange(sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
   }

   sub_ctx->viewport_state_dirty = 0;
}
static void vrend_update_viewport_state(struct vrend_sub_context *sub_ctx)
{
   GLint cy;
   unsigned mask = sub_ctx->viewport_state_dirty;
   int idx;
   while (mask) {
      idx = u_bit_scan(&mask);

      if (sub_ctx->viewport_is_negative)
         cy = sub_ctx->vps[idx].cur_y - sub_ctx->vps[idx].height;
      else
         cy = sub_ctx->vps[idx].cur_y;
      if (idx > 0 && has_feature(feat_viewport_array))
         glViewportIndexedf(idx, sub_ctx->vps[idx].cur_x, cy, sub_ctx->vps[idx].width, sub_ctx->vps[idx].height);
      else
         glViewport(sub_ctx->vps[idx].cur_x, cy, sub_ctx->vps[idx].width, sub_ctx->vps[idx].height);

      if (idx && has_feature(feat_viewport_array))
         if (vrend_state.use_gles) {
            glDepthRangeIndexedfOES(idx, sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
         } else
            glDepthRangeIndexed(idx, sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
      else
         if (vrend_state.use_gles)
            glDepthRangefOES(sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
         else
            glDepthRange(sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val);
   }

   sub_ctx->viewport_state_dirty = 0;
}