Cleanup: remove texlevels from instance params.
This commit is contained in:
parent
a4bd4a88cc
commit
8f3612bed2
15
__init__.py
15
__init__.py
@ -38,10 +38,10 @@ TEXTURE_FLAG_MIN_LINEAR = _flag(2)
|
||||
TEXTURE_FLAG_MAG_NEAREST = 0
|
||||
TEXTURE_FLAG_MAG_LINEAR = _flag(3)
|
||||
|
||||
VERTEX_FORMAT_VEC2_FLOAT = 1
|
||||
VERTEX_FORMAT_VEC2_USHORT = 2
|
||||
VERTEX_FORMAT_VEC3_FLOAT = 3
|
||||
VERTEX_FORMAT_VEC3_INT10 = 4
|
||||
VERTEX_FORMAT_VEC3_FLOAT = 1
|
||||
VERTEX_FORMAT_VEC3_INT10 = 2
|
||||
VERTEX_FORMAT_VEC3_UINT10 = 3
|
||||
VERTEX_FORMAT_NORMALIZE = _flag(7)
|
||||
|
||||
def vertex_format(*format):
|
||||
return array('B', format).tobytes()
|
||||
@ -344,16 +344,15 @@ _draw_batch.argtypes = (
|
||||
ctypes.c_void_p, # batch
|
||||
ctypes.c_uint, # size
|
||||
ctypes.c_void_p, # flags
|
||||
ctypes.c_void_p, # texlevels
|
||||
ctypes.c_void_p, # meshes
|
||||
ctypes.c_void_p, # translations
|
||||
ctypes.c_void_p) # orientations
|
||||
|
||||
def draw_batch(batch, flags, texlevels, meshes, translations, orientations):
|
||||
def draw_batch(batch, flags, meshes, translations, orientations):
|
||||
size = len(flags)
|
||||
assert len(texlevels) == size and len(meshes) == size and len(translations) == size * 3
|
||||
assert len(meshes) == size and len(translations) == size * 3
|
||||
assert not orientations or len(orientations) == size * 3
|
||||
_draw_batch(batch, size, _ubytep(flags), _ushortp(texlevels), _uintp(meshes), _floatp(translations),
|
||||
_draw_batch(batch, size, _ubytep(flags), _uintp(meshes), _floatp(translations),
|
||||
_floatp(orientations) if orientations else None)
|
||||
|
||||
unselect_vertices = _lib.rk_unselect_vertices
|
||||
|
@ -311,17 +311,14 @@ rk_vertices_t rk_create_vertices(
|
||||
}
|
||||
rk_uint vertex_size = 0;
|
||||
for (rk_vertex_format const * f = format; *f; ++f) {
|
||||
switch (*f) {
|
||||
case RK_VERTEX_FORMAT_VEC2_FLOAT:
|
||||
vertex_size += sizeof(float) * 2;
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC2_USHORT:
|
||||
vertex_size += sizeof(rk_ushort) * 2;
|
||||
break;
|
||||
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||
vertex_size += sizeof(float) * 3;
|
||||
vertex_size += sizeof(rk_vec3);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||
vertex_size += sizeof(rk_int);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_UINT10:
|
||||
vertex_size += sizeof(rk_uint);
|
||||
break;
|
||||
default:
|
||||
@ -346,30 +343,24 @@ rk_vertices_t rk_create_vertices(
|
||||
rk_uint offset = 0;
|
||||
for (rk_vertex_format const * f = format; *f; ++f, ++vertices->layout) {
|
||||
glEnableVertexAttribArray(vertices->layout);
|
||||
switch (*f) {
|
||||
case RK_VERTEX_FORMAT_VEC2_FLOAT:
|
||||
glVertexAttribFormat(vertices->layout, 2, GL_FLOAT, GL_FALSE, offset);
|
||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||
offset += sizeof(float) * 2;
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC2_USHORT:
|
||||
glVertexAttribFormat(vertices->layout, 2, GL_UNSIGNED_SHORT, GL_TRUE, offset);
|
||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||
offset += sizeof(rk_ushort) * 2;
|
||||
break;
|
||||
GLboolean const normalize = (*f & RK_VERTEX_FORMAT_NORMALIZE) != 0;
|
||||
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||
glVertexAttribFormat(vertices->layout, 3, GL_FLOAT, GL_FALSE, offset);
|
||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||
offset += sizeof(float) * 3;
|
||||
glVertexAttribFormat(vertices->layout, 3, GL_FLOAT, normalize, offset);
|
||||
offset += sizeof(rk_vec3);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||
glVertexAttribFormat(vertices->layout, GL_BGRA, GL_INT_2_10_10_10_REV, GL_TRUE, offset);
|
||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||
glVertexAttribFormat(vertices->layout, 4, GL_INT_2_10_10_10_REV, normalize, offset);
|
||||
offset += sizeof(rk_int);
|
||||
break;
|
||||
case RK_VERTEX_FORMAT_VEC3_UINT10:
|
||||
glVertexAttribFormat(vertices->layout, 4, GL_UNSIGNED_INT_2_10_10_10_REV, normalize, offset);
|
||||
offset += sizeof(rk_uint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||
}
|
||||
glBindVertexBuffer(RK_VERTICES_BINDING, vertices->vertices, 0, vertices->vertex_size);
|
||||
glGenBuffers(1, &vertices->indices);
|
||||
@ -393,10 +384,10 @@ rk_batch_t rk_create_batch(
|
||||
rk_uint translation_size = 0;
|
||||
switch (translation_format) {
|
||||
case RK_BATCH_TRANSLATION_FORMAT_FLOAT:
|
||||
translation_size = sizeof(float) * 4;
|
||||
translation_size = sizeof(rk_translation_float);
|
||||
break;
|
||||
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
||||
translation_size = sizeof(rk_short) * 4;
|
||||
translation_size = sizeof(rk_translation_short);
|
||||
break;
|
||||
default:
|
||||
rk_printf("rk_create_batch(): invalid translation format.");
|
||||
@ -409,10 +400,10 @@ rk_batch_t rk_create_batch(
|
||||
orientation_size = 0;
|
||||
break;
|
||||
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
||||
orientation_size = sizeof(float) * 3;
|
||||
orientation_size = sizeof(rk_orientation_float);
|
||||
break;
|
||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||
orientation_size = sizeof(rk_uint);
|
||||
orientation_size = sizeof(rk_orientation_int10);
|
||||
break;
|
||||
default:
|
||||
rk_printf("rk_create_batch(): invalid orientation format.");
|
||||
@ -433,10 +424,10 @@ rk_batch_t rk_create_batch(
|
||||
glEnableVertexAttribArray(translation_layout);
|
||||
switch (translation_format) {
|
||||
case RK_BATCH_TRANSLATION_FORMAT_FLOAT:
|
||||
glVertexAttribFormat(translation_layout, 4, GL_FLOAT, GL_FALSE, 0);
|
||||
glVertexAttribFormat(translation_layout, 3, GL_FLOAT, GL_FALSE, 0);
|
||||
break;
|
||||
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
||||
glVertexAttribFormat(translation_layout, 4, GL_SHORT, GL_FALSE, 0);
|
||||
glVertexAttribFormat(translation_layout, 3, GL_SHORT, GL_FALSE, 0);
|
||||
break;
|
||||
}
|
||||
glVertexAttribBinding(translation_layout, RK_PARAMS_BINDING);
|
||||
@ -549,13 +540,12 @@ static void rk_batch_convert_params(
|
||||
rk_ushort const * const _indices,
|
||||
rk_ubyte * const _params,
|
||||
rk_vec3 const * const translations,
|
||||
rk_ushort const * const texlevels,
|
||||
rk_vec3 const * const orientations) {
|
||||
_instance_params_t * params = reinterpret_cast<_instance_params_t *>(_params);
|
||||
rk_ushort const * const last = _indices + count;
|
||||
for (rk_ushort const * indices = _indices; indices < last; ++indices, ++params) {
|
||||
rk_uint const index = *indices;
|
||||
params->set(translations[index], texlevels[index], orientations[index]);
|
||||
params->set(translations[index], orientations[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -564,13 +554,12 @@ static void rk_batch_convert_params(
|
||||
rk_uint const count,
|
||||
rk_ushort const * const _indices,
|
||||
rk_ubyte * const _params,
|
||||
rk_vec3 const * const translations,
|
||||
rk_ushort const * const texlevels) {
|
||||
rk_vec3 const * const translations) {
|
||||
_instance_params_t * params = reinterpret_cast<_instance_params_t *>(_params);
|
||||
rk_ushort const * const last = _indices + count;
|
||||
for (rk_ushort const * indices = _indices; indices < last; ++indices, ++params) {
|
||||
rk_uint const index = *indices;
|
||||
params->set(translations[index], texlevels[index]);
|
||||
params->set(translations[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,12 +567,11 @@ void rk_draw_batch(
|
||||
rk_batch_t _batch,
|
||||
rk_uint size,
|
||||
rk_instance_flags const * flags,
|
||||
rk_ushort const * texlevels,
|
||||
rk_mesh const * meshes,
|
||||
rk_vec3 const * translations,
|
||||
rk_vec3 const * orientations) {
|
||||
rk_batch & batch = *reinterpret_cast<rk_batch *>(_batch);
|
||||
if (!size || size > batch.size || !flags || !texlevels || !meshes || !translations ||
|
||||
if (!size || size > batch.size || !flags || !meshes || !translations ||
|
||||
!rk_current_shader || !rk_current_vertices) {
|
||||
return;
|
||||
}
|
||||
@ -604,15 +592,15 @@ void rk_draw_batch(
|
||||
switch (batch.orientation_format) {
|
||||
case RK_BATCH_ORIENTATION_FORMAT_NONE:
|
||||
rk_batch_convert_params<rk_translation_float>(
|
||||
count, batch.indices, batch.params, translations, texlevels);
|
||||
count, batch.indices, batch.params, translations);
|
||||
break;
|
||||
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
||||
rk_batch_convert_params<rk_params_float_float>(
|
||||
count, batch.indices, batch.params, translations, texlevels, orientations);
|
||||
count, batch.indices, batch.params, translations, orientations);
|
||||
break;
|
||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||
rk_batch_convert_params<rk_params_float_int10>(
|
||||
count, batch.indices, batch.params, translations, texlevels, orientations);
|
||||
count, batch.indices, batch.params, translations, orientations);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -620,15 +608,15 @@ void rk_draw_batch(
|
||||
switch (batch.orientation_format) {
|
||||
case RK_BATCH_ORIENTATION_FORMAT_NONE:
|
||||
rk_batch_convert_params<rk_translation_short>(
|
||||
count, batch.indices, batch.params, translations, texlevels);
|
||||
count, batch.indices, batch.params, translations);
|
||||
break;
|
||||
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
||||
rk_batch_convert_params<rk_params_short_float>(
|
||||
count, batch.indices, batch.params, translations, texlevels, orientations);
|
||||
count, batch.indices, batch.params, translations, orientations);
|
||||
break;
|
||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||
rk_batch_convert_params<rk_params_short_int10>(
|
||||
count, batch.indices, batch.params, translations, texlevels, orientations);
|
||||
count, batch.indices, batch.params, translations, orientations);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -76,11 +76,9 @@ struct rk_batch {
|
||||
|
||||
struct rk_translation_float {
|
||||
rk_vec3 xyz;
|
||||
float l;
|
||||
|
||||
inline void set(rk_vec3 const & translation, rk_ushort const texlevel) {
|
||||
inline void set(rk_vec3 const & translation) {
|
||||
xyz = translation;
|
||||
l = static_cast<float>(texlevel);
|
||||
}
|
||||
};
|
||||
|
||||
@ -88,13 +86,13 @@ struct rk_translation_short {
|
||||
rk_short x;
|
||||
rk_short y;
|
||||
rk_short z;
|
||||
rk_ushort l;
|
||||
rk_short pad;
|
||||
|
||||
inline void set(rk_vec3 const & translation, rk_ushort const texlevel) {
|
||||
inline void set(rk_vec3 const & translation) {
|
||||
x = static_cast<rk_short>(translation.x);
|
||||
y = static_cast<rk_short>(translation.y);
|
||||
z = static_cast<rk_short>(translation.z);
|
||||
l = texlevel;
|
||||
pad = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -106,7 +104,6 @@ struct rk_orientation_float {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct rk_orientation_int10 {
|
||||
rk_uint xyz;
|
||||
|
||||
@ -122,8 +119,8 @@ struct rk_params {
|
||||
_translation_t translation;
|
||||
_orientation_t orientation;
|
||||
|
||||
inline void set(rk_vec3 const & translation, rk_ushort const texlevel, rk_vec3 const & orientation) {
|
||||
this->translation.set(translation, texlevel);
|
||||
inline void set(rk_vec3 const & translation, rk_vec3 const & orientation) {
|
||||
this->translation.set(translation);
|
||||
this->orientation.set(orientation);
|
||||
}
|
||||
};
|
||||
|
@ -47,10 +47,12 @@ enum rk_texture_flags : rk_uint {
|
||||
|
||||
enum rk_vertex_format : rk_ubyte {
|
||||
RK_VERTEX_FORMAT_END = 0,
|
||||
RK_VERTEX_FORMAT_VEC2_FLOAT = 1,
|
||||
RK_VERTEX_FORMAT_VEC2_USHORT = 2,
|
||||
RK_VERTEX_FORMAT_VEC3_FLOAT = 3,
|
||||
RK_VERTEX_FORMAT_VEC3_INT10 = 4,
|
||||
RK_VERTEX_FORMAT_VEC3_FLOAT = 1,
|
||||
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
|
||||
};
|
||||
|
||||
enum rk_instance_flags : rk_ubyte {
|
||||
@ -155,7 +157,6 @@ RK_EXPORT void rk_draw_batch(
|
||||
rk_batch_t batch,
|
||||
rk_uint size,
|
||||
rk_instance_flags const * flags,
|
||||
rk_ushort const * texlevels,
|
||||
rk_mesh const * meshes,
|
||||
rk_vec3 const * translations,
|
||||
rk_vec3 const * orientations);
|
||||
|
Loading…
Reference in New Issue
Block a user