vrend: replace if-chain by using switch/case

if-chains can usually not be optimized very well, switch/case might be
implemented as a jump table.

v2: Add a break in bese before default (Chia-I Wu)

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
Gert Wollny 4 years ago
parent 46be8896a5
commit 1b51495bd1
  1. 76
      src/vrend_renderer.c

@ -2611,41 +2611,47 @@ int vrend_create_vertex_elements_state(struct vrend_context *ctx,
} }
type = GL_FALSE; type = GL_FALSE;
if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { switch (desc->channel[0].type) {
if (desc->channel[0].size == 32) case UTIL_FORMAT_TYPE_FLOAT:
type = GL_FLOAT; switch (desc->channel[0].size) {
else if (desc->channel[0].size == 64) case 16: type = GL_HALF_FLOAT; break;
type = GL_DOUBLE; case 32: type = GL_FLOAT; break;
else if (desc->channel[0].size == 16) case 64: type = GL_DOUBLE; break;
type = GL_HALF_FLOAT; }
} else if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && break;
desc->channel[0].size == 8) case UTIL_FORMAT_TYPE_UNSIGNED:
type = GL_UNSIGNED_BYTE; switch (desc->channel[0].size) {
else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && case 8: type = GL_UNSIGNED_BYTE; break;
desc->channel[0].size == 8) case 16: type = GL_UNSIGNED_SHORT; break;
type = GL_BYTE; case 32: type = GL_UNSIGNED_INT; break;
else if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && }
desc->channel[0].size == 16) break;
type = GL_UNSIGNED_SHORT; case UTIL_FORMAT_TYPE_SIGNED:
else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && switch (desc->channel[0].size) {
desc->channel[0].size == 16) case 8: type = GL_BYTE; break;
type = GL_SHORT; case 16: type = GL_SHORT; break;
else if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && case 32: type = GL_INT; break;
desc->channel[0].size == 32) }
type = GL_UNSIGNED_INT; break;
else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && default:
desc->channel[0].size == 32) switch (elements[i].src_format) {
type = GL_INT; case PIPE_FORMAT_R10G10B10A2_SSCALED:
else if (elements[i].src_format == PIPE_FORMAT_R10G10B10A2_SSCALED || case PIPE_FORMAT_R10G10B10A2_SNORM:
elements[i].src_format == PIPE_FORMAT_R10G10B10A2_SNORM || case PIPE_FORMAT_B10G10R10A2_SNORM:
elements[i].src_format == PIPE_FORMAT_B10G10R10A2_SNORM) type = GL_INT_2_10_10_10_REV;
type = GL_INT_2_10_10_10_REV; break;
else if (elements[i].src_format == PIPE_FORMAT_R10G10B10A2_USCALED || case PIPE_FORMAT_R10G10B10A2_USCALED:
elements[i].src_format == PIPE_FORMAT_R10G10B10A2_UNORM || case PIPE_FORMAT_R10G10B10A2_UNORM:
elements[i].src_format == PIPE_FORMAT_B10G10R10A2_UNORM) case PIPE_FORMAT_B10G10R10A2_UNORM:
type = GL_UNSIGNED_INT_2_10_10_10_REV; type = GL_UNSIGNED_INT_2_10_10_10_REV;
else if (elements[i].src_format == PIPE_FORMAT_R11G11B10_FLOAT) break;
type = GL_UNSIGNED_INT_10F_11F_11F_REV; case PIPE_FORMAT_R11G11B10_FLOAT:
type = GL_UNSIGNED_INT_10F_11F_11F_REV;
break;
default:
;
}
}
if (type == GL_FALSE) { if (type == GL_FALSE) {
vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_VERTEX_FORMAT, elements[i].src_format); vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_VERTEX_FORMAT, elements[i].src_format);

Loading…
Cancel
Save