Compare commits
No commits in common. "7384a014ff0ec184bc970be39cf6d7e6e1fae6b4" and "39c449a763d50b0dbdce58f8bf253aeb2ecd4fab" have entirely different histories.
7384a014ff
...
39c449a763
38
__init__.py
38
__init__.py
@ -268,28 +268,34 @@ TEXTURE_FLAG_MAG_NEAREST = 0
|
||||
TEXTURE_FLAG_MAG_LINEAR = _flag(3)
|
||||
|
||||
VERTEX_FORMAT_VEC3_FLOAT = 1
|
||||
VERTEX_FORMAT_VEC3_SHORT = 2
|
||||
VERTEX_FORMAT_VEC3_INT10 = 3
|
||||
VERTEX_FORMAT_VEC3_UINT10 = 4
|
||||
VERTEX_FORMAT_MAT3_FLOAT = 5
|
||||
VERTEX_FORMAT_MAT3_INT10 = 6
|
||||
VERTEX_FORMAT_VEC3_INT10 = 2
|
||||
VERTEX_FORMAT_VEC3_UINT10 = 3
|
||||
VERTEX_FORMAT_NORMALIZE = _flag(7)
|
||||
_VERTEX_FORMAT_MASK = VERTEX_FORMAT_NORMALIZE - 1
|
||||
|
||||
def vertex_format(*format):
|
||||
return array('B', format).tobytes()
|
||||
|
||||
_VERTEX_TYPES = (
|
||||
None,
|
||||
vec3, # VERTEX_FORMAT_VEC3_FLOAT
|
||||
vec3, # VERTEX_FORMAT_VEC3_SHORT
|
||||
vec3, # VERTEX_FORMAT_VEC3_INT10
|
||||
vec3, # VERTEX_FORMAT_VEC3_UINT10
|
||||
mat3, # VERTEX_FORMAT_MAT3_FLOAT
|
||||
mat3) # VERTEX_FORMAT_MAT3_INT10
|
||||
PARAM_FORMAT_VEC3_FLOAT = 1
|
||||
PARAM_FORMAT_VEC3_SHORT = 2
|
||||
PARAM_FORMAT_VEC3_INT10 = 3
|
||||
PARAM_FORMAT_MAT3_FLOAT = 4
|
||||
PARAM_FORMAT_MAT3_INT10 = 5
|
||||
PARAM_FORMAT_NORMALIZE = _flag(7)
|
||||
_PARAM_FORMAT_MASK = PARAM_FORMAT_NORMALIZE - 1
|
||||
|
||||
def vertex_type(format):
|
||||
return _VERTEX_TYPES[format & _VERTEX_FORMAT_MASK]
|
||||
_PARAMS_TYPES = (
|
||||
None,
|
||||
vec3, # PARAM_FORMAT_VEC3_FLOAT
|
||||
vec3, # PARAM_FORMAT_VEC3_SHORT
|
||||
vec3, # PARAM_FORMAT_VEC3_INT10
|
||||
mat3, # PARAM_FORMAT_MAT3_FLOAT
|
||||
mat3) # PARAM_FORMAT_MAT3_INT10
|
||||
|
||||
def param_type(format):
|
||||
return _PARAMS_TYPES[format & _PARAM_FORMAT_MASK]
|
||||
|
||||
def params_format(*format):
|
||||
return array('B', format).tobytes()
|
||||
|
||||
INSTANCE_FLAG_SPAWNED = _flag(0)
|
||||
INSTANCE_FLAG_VISIBLE = _flag(1)
|
||||
|
@ -29,7 +29,7 @@ typedef rk_handle_t rk_batch_t;
|
||||
|
||||
typedef rk_uint rk_texture_format;
|
||||
|
||||
enum : rk_texture_format {
|
||||
enum : rk_uint {
|
||||
RK_TEXTURE_FORMAT_SRGB8_A8 = 0,
|
||||
RK_TEXTURE_FORMAT_RGBA8 = 1,
|
||||
RK_TEXTURE_FORMAT_RGB10_A2 = 2,
|
||||
@ -38,7 +38,7 @@ enum : rk_texture_format {
|
||||
|
||||
typedef rk_uint rk_texture_flags;
|
||||
|
||||
enum : rk_texture_flags {
|
||||
enum : rk_uint {
|
||||
RK_TEXTURE_FLAG_3D = RK_FLAG(0),
|
||||
RK_TEXTURE_FLAG_MIPMAPS = RK_FLAG(1),
|
||||
RK_TEXTURE_FLAG_MIN_NEAREST = 0,
|
||||
@ -49,34 +49,45 @@ enum : rk_texture_flags {
|
||||
|
||||
typedef rk_ubyte rk_vertex_format;
|
||||
|
||||
enum : rk_vertex_format {
|
||||
enum : rk_ubyte {
|
||||
RK_VERTEX_FORMAT_VEC3_FLOAT = 1,
|
||||
RK_VERTEX_FORMAT_VEC3_SHORT = 2,
|
||||
RK_VERTEX_FORMAT_VEC3_INT10 = 3,
|
||||
RK_VERTEX_FORMAT_VEC3_UINT10 = 4,
|
||||
RK_VERTEX_FORMAT_MAT3_FLOAT = 5,
|
||||
RK_VERTEX_FORMAT_MAT3_INT10 = 6,
|
||||
RK_VERTEX_FORMAT_VEC3_INT10 = 2,
|
||||
RK_VERTEX_FORMAT_VEC3_UINT10 = 3,
|
||||
RK_VERTEX_FORMAT_NORMALIZE = RK_FLAG(7),
|
||||
RK_VERTEX_FORMAT_MASK = RK_VERTEX_FORMAT_NORMALIZE - 1
|
||||
};
|
||||
|
||||
typedef rk_ubyte rk_param_format;
|
||||
|
||||
enum : rk_ubyte {
|
||||
RK_PARAM_FORMAT_VEC3_FLOAT = 1,
|
||||
RK_PARAM_FORMAT_VEC3_SHORT = 2,
|
||||
RK_PARAM_FORMAT_VEC3_INT10 = 3,
|
||||
RK_PARAM_FORMAT_MAT3_FLOAT = 4,
|
||||
RK_PARAM_FORMAT_MAT3_INT10 = 5,
|
||||
RK_PARAM_FORMAT_NORMALIZE = RK_FLAG(7),
|
||||
RK_PARAM_FORMAT_MASK = RK_PARAM_FORMAT_NORMALIZE - 1
|
||||
};
|
||||
|
||||
typedef rk_ubyte rk_instance_flags;
|
||||
|
||||
enum : rk_instance_flags {
|
||||
enum : rk_ubyte {
|
||||
RK_INSTANCE_FLAG_SPAWNED = RK_FLAG(0),
|
||||
RK_INSTANCE_FLAG_VISIBLE = RK_FLAG(1),
|
||||
RK_INSTANCE_FLAGS_SPAWNED_VISIBLE = RK_INSTANCE_FLAG_SPAWNED | RK_INSTANCE_FLAG_VISIBLE
|
||||
};
|
||||
|
||||
typedef rk_ushort rk_instance_index;
|
||||
|
||||
enum : rk_uint {
|
||||
RK_BATCH_MAX_SIZE = 65536
|
||||
RK_BATCH_MAX_SIZE = 1 << (sizeof(rk_instance_index) * 8)
|
||||
};
|
||||
|
||||
typedef rk_ushort rk_vertex_index;
|
||||
typedef rk_ushort rk_mesh_index;
|
||||
typedef rk_ushort rk_instance_index;
|
||||
typedef rk_uint rk_vertex_input;
|
||||
typedef rk_uint rk_vertex_output;
|
||||
typedef rk_vertex_input rk_param_input;
|
||||
|
||||
struct rk_mesh {
|
||||
rk_uint base_index;
|
||||
@ -126,14 +137,14 @@ RK_EXPORT rk_vertices_t rk_create_vertices(
|
||||
RK_EXPORT rk_batch_t rk_create_batch(
|
||||
rk_vertices_t vertices,
|
||||
rk_uint max_size,
|
||||
rk_vertex_format const * params_format);
|
||||
rk_param_format const * params_format);
|
||||
|
||||
RK_EXPORT void rk_fill_batch(
|
||||
rk_batch_t batch,
|
||||
rk_uint count,
|
||||
rk_instance_flags const * flags,
|
||||
rk_mesh_index const * meshes,
|
||||
rk_vertex_input const * const * params);
|
||||
rk_param_input const * const * params);
|
||||
|
||||
RK_EXPORT void rk_clear_buffer(
|
||||
rk_bool pixels,
|
||||
|
@ -424,7 +424,7 @@ static void rk_buckets_alloc(
|
||||
rk_batch_t rk_create_batch(
|
||||
rk_vertices_t _vertices,
|
||||
rk_uint max_size,
|
||||
rk_vertex_format const * params_format) {
|
||||
rk_param_format const * params_format) {
|
||||
rk_vertices * const vertices = reinterpret_cast<rk_vertices *>(_vertices);
|
||||
if (!vertices || !max_size || max_size > RK_BATCH_MAX_SIZE) {
|
||||
rk_printf("rk_create_batch(): invalid params.");
|
||||
@ -447,21 +447,21 @@ rk_batch_t rk_create_batch(
|
||||
unsigned nparams = 0;
|
||||
unsigned params_size = 0;
|
||||
if (params_format) {
|
||||
for (rk_vertex_format const * f = params_format; *f; ++f, ++nparams) {
|
||||
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||
for (rk_param_format const * f = params_format; *f; ++f, ++nparams) {
|
||||
switch (*f & RK_PARAM_FORMAT_MASK) {
|
||||
case RK_PARAM_FORMAT_VEC3_FLOAT:
|
||||
params_size += rk_vec3_float::get_output_size();
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_SHORT:
|
||||
case RK_PARAM_FORMAT_VEC3_SHORT:
|
||||
params_size += rk_vec3_short::get_output_size();
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||
case RK_PARAM_FORMAT_VEC3_INT10:
|
||||
params_size += rk_vec3_int10::get_output_size();
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_MAT3_FLOAT:
|
||||
case RK_PARAM_FORMAT_MAT3_FLOAT:
|
||||
params_size += rk_mat3_float::get_output_size();
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_MAT3_INT10:
|
||||
case RK_PARAM_FORMAT_MAT3_INT10:
|
||||
params_size += rk_mat3_int10::get_output_size();
|
||||
break;
|
||||
default:
|
||||
@ -551,13 +551,13 @@ rk_batch_t rk_create_batch(
|
||||
if (nparams) {
|
||||
offset = 0;
|
||||
rk_parameter * param = batch->params;
|
||||
for (rk_vertex_format const * f = params_format; *f; ++f, ++param, ++binding) {
|
||||
GLboolean const norm = (*f & RK_VERTEX_FORMAT_NORMALIZE) != 0;
|
||||
for (rk_param_format const * f = params_format; *f; ++f, ++param, ++binding) {
|
||||
GLboolean const norm = (*f & RK_PARAM_FORMAT_NORMALIZE) != 0;
|
||||
param->dirty = false;
|
||||
param->binding = binding;
|
||||
param->offset = offset;
|
||||
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||
switch (*f & RK_PARAM_FORMAT_MASK) {
|
||||
case RK_PARAM_FORMAT_VEC3_FLOAT:
|
||||
param->src_size = rk_vec3_float::get_input_size();
|
||||
param->dst_size = rk_vec3_float::get_output_size();
|
||||
param->packer = rk_vec3_float::param_packer;
|
||||
@ -566,7 +566,7 @@ rk_batch_t rk_create_batch(
|
||||
glVertexAttribFormat(attrib, 3, GL_FLOAT, GL_FALSE, 0);
|
||||
glVertexAttribBinding(attrib++, binding);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_SHORT:
|
||||
case RK_PARAM_FORMAT_VEC3_SHORT:
|
||||
param->src_size = rk_vec3_short::get_input_size();
|
||||
param->dst_size = rk_vec3_short::get_output_size();
|
||||
param->packer = norm ? rk_vec3_short_norm::param_packer : rk_vec3_short::param_packer;
|
||||
@ -575,7 +575,7 @@ rk_batch_t rk_create_batch(
|
||||
glVertexAttribFormat(attrib, 3, GL_SHORT, norm, 0);
|
||||
glVertexAttribBinding(attrib++, binding);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||
case RK_PARAM_FORMAT_VEC3_INT10:
|
||||
param->src_size = rk_vec3_int10::get_input_size();
|
||||
param->dst_size = rk_vec3_int10::get_output_size();
|
||||
param->packer = norm ? rk_vec3_int10_norm::param_packer : rk_vec3_int10::param_packer;
|
||||
@ -584,7 +584,7 @@ rk_batch_t rk_create_batch(
|
||||
glVertexAttribFormat(attrib, 4, GL_INT_2_10_10_10_REV, norm, 0);
|
||||
glVertexAttribBinding(attrib++, binding);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_MAT3_FLOAT:
|
||||
case RK_PARAM_FORMAT_MAT3_FLOAT:
|
||||
param->src_size = rk_mat3_float::get_input_size();
|
||||
param->dst_size = rk_mat3_float::get_output_size();
|
||||
param->packer = rk_mat3_float::param_packer;
|
||||
@ -599,7 +599,7 @@ rk_batch_t rk_create_batch(
|
||||
glVertexAttribFormat(attrib, 3, GL_FLOAT, GL_FALSE, rk_mat3_float::get_output_offset(2));
|
||||
glVertexAttribBinding(attrib++, binding);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_MAT3_INT10:
|
||||
case RK_PARAM_FORMAT_MAT3_INT10:
|
||||
param->src_size = rk_mat3_int10::get_input_size();
|
||||
param->dst_size = rk_mat3_int10::get_output_size();
|
||||
param->packer = norm ? rk_mat3_int10_norm::param_packer : rk_mat3_int10::param_packer;
|
||||
@ -616,9 +616,9 @@ rk_batch_t rk_create_batch(
|
||||
break;
|
||||
}
|
||||
glVertexBindingDivisor(binding, 1);
|
||||
param->src_len = param->src_size / sizeof(rk_vertex_output);
|
||||
param->dst_len = param->dst_size / sizeof(rk_vertex_output);
|
||||
param->source = new rk_vertex_input[max_size * param->src_len];
|
||||
param->src_len = param->src_size / sizeof(rk_param_output);
|
||||
param->dst_len = param->dst_size / sizeof(rk_param_output);
|
||||
param->source = new rk_param_input[max_size * param->src_len];
|
||||
memset(param->source, 0xFF, max_size * param->src_size);
|
||||
offset += max_size * param->dst_size;
|
||||
}
|
||||
@ -674,7 +674,7 @@ static void rk_pack_batch(
|
||||
if (param->dirty) {
|
||||
param->dirty = false;
|
||||
if (batch.ninstances) {
|
||||
rk_vertex_output * const dst = reinterpret_cast<rk_vertex_output *>(
|
||||
rk_param_output * const dst = reinterpret_cast<rk_param_output *>(
|
||||
glMapBufferRange(GL_ARRAY_BUFFER, param->offset, batch.ninstances * param->dst_size,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT));
|
||||
if (dst) {
|
||||
@ -695,7 +695,7 @@ void rk_fill_batch(
|
||||
rk_uint count,
|
||||
rk_instance_flags const * flags,
|
||||
rk_mesh_index const * meshes,
|
||||
rk_vertex_input const * const * params) {
|
||||
rk_param_input const * const * params) {
|
||||
rk_batch const * const batch = reinterpret_cast<rk_batch const *>(_batch);
|
||||
if (!batch || !count || count > batch->max_size) {
|
||||
rk_printf("rk_fill_batch(): invalid params.");
|
||||
@ -706,7 +706,7 @@ void rk_fill_batch(
|
||||
if (batch->nparams) {
|
||||
got_all_params = (params != nullptr);
|
||||
if (params) {
|
||||
for (rk_vertex_input const * const * param = params; param < params + batch->nparams; ++param) {
|
||||
for (rk_param_input const * const * param = params; param < params + batch->nparams; ++param) {
|
||||
bool const got_param = (*param != nullptr);
|
||||
got_any_params |= got_param;
|
||||
got_all_params &= got_param;
|
||||
@ -730,7 +730,7 @@ void rk_fill_batch(
|
||||
if (batch->nparams) {
|
||||
rk_parameter const * const last_param = batch->params + batch->nparams;
|
||||
if (got_any_params) {
|
||||
rk_vertex_input const * const * src = params;
|
||||
rk_param_input const * const * src = params;
|
||||
for (rk_parameter const * param = batch->params; param < last_param; ++param, ++src) {
|
||||
param->dirty =
|
||||
((*src && rk_cmp_memcpy(param->source, *src, batch->count * param->src_len)) || need_sorting);
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
static_assert(sizeof(rk_vertex_output) == 4);
|
||||
|
||||
typedef rk_vertex_output rk_param_output;
|
||||
|
||||
struct rk_shader {
|
||||
GLuint vertex;
|
||||
GLuint fragment;
|
||||
@ -63,8 +65,8 @@ struct rk_command {
|
||||
typedef void (*rk_packer)(
|
||||
unsigned const, // count
|
||||
rk_instance_index const * const __restrict, // indices
|
||||
rk_vertex_output * __restrict, // dst
|
||||
rk_vertex_input const * const __restrict); // src
|
||||
rk_param_output * __restrict, // dst
|
||||
rk_param_input const * const __restrict); // src
|
||||
|
||||
struct rk_parameter {
|
||||
mutable bool dirty;
|
||||
@ -74,7 +76,7 @@ struct rk_parameter {
|
||||
unsigned src_len;
|
||||
unsigned dst_size;
|
||||
unsigned dst_len;
|
||||
rk_vertex_input * source;
|
||||
rk_param_input * source;
|
||||
rk_packer packer;
|
||||
};
|
||||
|
||||
|
@ -231,8 +231,8 @@ struct rk_format {
|
||||
static void param_packer(
|
||||
unsigned const count,
|
||||
rk_instance_index const * const __restrict indices,
|
||||
rk_vertex_output * __restrict _dst,
|
||||
rk_vertex_input const * const __restrict _src) {
|
||||
rk_param_output * __restrict _dst,
|
||||
rk_param_input const * const __restrict _src) {
|
||||
rk_instance_index const * const last_index = indices + count;
|
||||
output_format * __restrict dst = reinterpret_cast<output_format *>(_dst);
|
||||
input_format const * const __restrict src = reinterpret_cast<input_format const *>(_src);
|
||||
|
Loading…
Reference in New Issue
Block a user