Compare commits

...

2 Commits

Author SHA1 Message Date
59d13684be Improve typing in render. 2023-01-04 12:41:05 +01:00
d6ec77207f Cleanup includes. 2023-01-04 10:22:12 +01:00
3 changed files with 27 additions and 29 deletions

View File

@ -86,16 +86,21 @@ enum : rk_uint {
typedef rk_ushort rk_vertex_index; typedef rk_ushort rk_vertex_index;
typedef rk_ushort rk_mesh_index; typedef rk_ushort rk_mesh_index;
// param input types must be size compatible with an array of rk_param_input
typedef rk_uint rk_param_input;
#define RK_CHECK_PARAM_INPUT_TYPE(_t) static_assert(!(sizeof(_t) % sizeof(rk_param_input)))
struct rk_mesh { struct rk_mesh {
rk_uint base_index; rk_uint base_index;
rk_uint ntriangles; rk_uint ntriangles;
}; };
// param input types must be size compatible with an array of rk_param_input
typedef rk_uint rk_param_input;
template<typename _input_type>
void rk_param_get_input_size(unsigned & _size, unsigned & _len) {
static_assert((sizeof(_input_type) % sizeof(rk_param_input)) == 0);
_size = sizeof(_input_type);
_len = sizeof(_input_type) / sizeof(rk_param_input);
}
RK_EXPORT void rk_render_initialize( RK_EXPORT void rk_render_initialize(
rk_bool debug); rk_bool debug);

View File

@ -689,8 +689,8 @@ rk_batch_t rk_create_batch(
param->offset = offset; param->offset = offset;
switch (*f & RK_PARAM_FORMAT_MASK) { switch (*f & RK_PARAM_FORMAT_MASK) {
case RK_PARAM_FORMAT_VEC3_FLOAT: case RK_PARAM_FORMAT_VEC3_FLOAT:
param->src_size = sizeof(rk_vec3); rk_param_get_input_size<rk_vec3>(param->src_size, param->src_len);
param->dst_size = sizeof(rk_vec3_float); rk_param_get_output_size<rk_vec3_float>(param->dst_size, param->dst_len);
param->packer = rk_pack_vec3_float; param->packer = rk_pack_vec3_float;
glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size); glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size);
glEnableVertexAttribArray(attrib); glEnableVertexAttribArray(attrib);
@ -698,8 +698,8 @@ rk_batch_t rk_create_batch(
glVertexAttribBinding(attrib++, binding); glVertexAttribBinding(attrib++, binding);
break; break;
case RK_PARAM_FORMAT_VEC3_SHORT: case RK_PARAM_FORMAT_VEC3_SHORT:
param->src_size = sizeof(rk_vec3); rk_param_get_input_size<rk_vec3>(param->src_size, param->src_len);
param->dst_size = sizeof(rk_vec3_short); rk_param_get_output_size<rk_vec3_short>(param->dst_size, param->dst_len);
param->packer = norm ? rk_pack_vec3_short_norm : rk_pack_vec3_short; param->packer = norm ? rk_pack_vec3_short_norm : rk_pack_vec3_short;
glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size); glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size);
glEnableVertexAttribArray(attrib); glEnableVertexAttribArray(attrib);
@ -707,8 +707,8 @@ rk_batch_t rk_create_batch(
glVertexAttribBinding(attrib++, binding); glVertexAttribBinding(attrib++, binding);
break; break;
case RK_PARAM_FORMAT_VEC3_INT10: case RK_PARAM_FORMAT_VEC3_INT10:
param->src_size = sizeof(rk_vec3); rk_param_get_input_size<rk_vec3>(param->src_size, param->src_len);
param->dst_size = sizeof(rk_vec3_int10); rk_param_get_output_size<rk_vec3_int10>(param->dst_size, param->dst_len);
param->packer = norm ? rk_pack_vec3_int10_norm : rk_pack_vec3_int10; param->packer = norm ? rk_pack_vec3_int10_norm : rk_pack_vec3_int10;
glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size); glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size);
glEnableVertexAttribArray(attrib); glEnableVertexAttribArray(attrib);
@ -716,8 +716,8 @@ rk_batch_t rk_create_batch(
glVertexAttribBinding(attrib++, binding); glVertexAttribBinding(attrib++, binding);
break; break;
case RK_PARAM_FORMAT_MAT3_FLOAT: case RK_PARAM_FORMAT_MAT3_FLOAT:
param->src_size = sizeof(rk_mat3); rk_param_get_input_size<rk_mat3>(param->src_size, param->src_len);
param->dst_size = sizeof(rk_mat3_float); rk_param_get_output_size<rk_mat3_float>(param->dst_size, param->dst_len);
param->packer = rk_pack_mat3_float; param->packer = rk_pack_mat3_float;
glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size); glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size);
glEnableVertexAttribArray(attrib); glEnableVertexAttribArray(attrib);
@ -731,8 +731,8 @@ rk_batch_t rk_create_batch(
glVertexAttribBinding(attrib++, binding); glVertexAttribBinding(attrib++, binding);
break; break;
case RK_PARAM_FORMAT_MAT3_INT10: case RK_PARAM_FORMAT_MAT3_INT10:
param->src_size = sizeof(rk_mat3); rk_param_get_input_size<rk_mat3>(param->src_size, param->src_len);
param->dst_size = sizeof(rk_mat3_int10); rk_param_get_output_size<rk_mat3_int10>(param->dst_size, param->dst_len);
param->packer = norm ? rk_pack_mat3_int10_norm : rk_pack_mat3_int10; param->packer = norm ? rk_pack_mat3_int10_norm : rk_pack_mat3_int10;
glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size); glBindVertexBuffer(binding, batch->params_buffer, param->offset, param->dst_size);
glEnableVertexAttribArray(attrib); glEnableVertexAttribArray(attrib);
@ -747,8 +747,6 @@ rk_batch_t rk_create_batch(
break; break;
} }
glVertexBindingDivisor(binding, 1); glVertexBindingDivisor(binding, 1);
param->src_len = param->src_size / sizeof(rk_param_input);
param->dst_len = param->dst_size / sizeof(rk_param_output);
param->source = new rk_param_input[max_size * param->src_len]; param->source = new rk_param_input[max_size * param->src_len];
memset(param->source, 0xFF, max_size * param->src_size); memset(param->source, 0xFF, max_size * param->src_size);
offset += max_size * param->dst_size; offset += max_size * param->dst_size;

View File

@ -62,7 +62,12 @@ struct rk_command {
// param output types must be size compatible with an array of rk_param_output // param output types must be size compatible with an array of rk_param_output
typedef rk_uint rk_param_output; typedef rk_uint rk_param_output;
#define RK_CHECK_PARAM_OUTPUT_TYPE(_t) static_assert(!(sizeof(_t) % sizeof(rk_param_output))) template<typename _output_type>
void rk_param_get_output_size(unsigned & _size, unsigned & _len) {
static_assert((sizeof(_output_type) % sizeof(rk_param_output)) == 0);
_size = sizeof(_output_type);
_len = sizeof(_output_type) / sizeof(rk_param_output);
}
struct rk_vec3_float { struct rk_vec3_float {
float x; float x;
@ -96,16 +101,6 @@ struct rk_mat3_int10 {
rk_vec3_int10 z; rk_vec3_int10 z;
}; };
RK_CHECK_PARAM_INPUT_TYPE(rk_vec3_float);
RK_CHECK_PARAM_INPUT_TYPE(rk_mat3_float);
RK_CHECK_PARAM_OUTPUT_TYPE(rk_vec3_float);
RK_CHECK_PARAM_OUTPUT_TYPE(rk_vec3_short);
RK_CHECK_PARAM_OUTPUT_TYPE(rk_vec3_int10);
RK_CHECK_PARAM_OUTPUT_TYPE(rk_vec3_uint10);
RK_CHECK_PARAM_OUTPUT_TYPE(rk_mat3_float);
RK_CHECK_PARAM_OUTPUT_TYPE(rk_mat3_int10);
typedef void (*rk_packer)( typedef void (*rk_packer)(
unsigned const, // count unsigned const, // count
rk_instance_index const * const, // indices rk_instance_index const * const, // indices
@ -117,8 +112,8 @@ struct rk_parameter {
unsigned binding; unsigned binding;
unsigned offset; unsigned offset;
unsigned src_size; unsigned src_size;
unsigned dst_size;
unsigned src_len; unsigned src_len;
unsigned dst_size;
unsigned dst_len; unsigned dst_len;
rk_param_input * source; rk_param_input * source;
rk_packer packer; rk_packer packer;