Compare commits
2 Commits
af25548752
...
8f3612bed2
Author | SHA1 | Date | |
---|---|---|---|
8f3612bed2 | |||
a4bd4a88cc |
15
__init__.py
15
__init__.py
@ -38,10 +38,10 @@ TEXTURE_FLAG_MIN_LINEAR = _flag(2)
|
|||||||
TEXTURE_FLAG_MAG_NEAREST = 0
|
TEXTURE_FLAG_MAG_NEAREST = 0
|
||||||
TEXTURE_FLAG_MAG_LINEAR = _flag(3)
|
TEXTURE_FLAG_MAG_LINEAR = _flag(3)
|
||||||
|
|
||||||
VERTEX_FORMAT_VEC2_FLOAT = 1
|
VERTEX_FORMAT_VEC3_FLOAT = 1
|
||||||
VERTEX_FORMAT_VEC2_USHORT = 2
|
VERTEX_FORMAT_VEC3_INT10 = 2
|
||||||
VERTEX_FORMAT_VEC3_FLOAT = 3
|
VERTEX_FORMAT_VEC3_UINT10 = 3
|
||||||
VERTEX_FORMAT_VEC3_INT10 = 4
|
VERTEX_FORMAT_NORMALIZE = _flag(7)
|
||||||
|
|
||||||
def vertex_format(*format):
|
def vertex_format(*format):
|
||||||
return array('B', format).tobytes()
|
return array('B', format).tobytes()
|
||||||
@ -344,16 +344,15 @@ _draw_batch.argtypes = (
|
|||||||
ctypes.c_void_p, # batch
|
ctypes.c_void_p, # batch
|
||||||
ctypes.c_uint, # size
|
ctypes.c_uint, # size
|
||||||
ctypes.c_void_p, # flags
|
ctypes.c_void_p, # flags
|
||||||
ctypes.c_void_p, # texlevels
|
|
||||||
ctypes.c_void_p, # meshes
|
ctypes.c_void_p, # meshes
|
||||||
ctypes.c_void_p, # translations
|
ctypes.c_void_p, # translations
|
||||||
ctypes.c_void_p) # orientations
|
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)
|
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
|
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)
|
_floatp(orientations) if orientations else None)
|
||||||
|
|
||||||
unselect_vertices = _lib.rk_unselect_vertices
|
unselect_vertices = _lib.rk_unselect_vertices
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
#include "math.hpp"
|
#include "math.hpp"
|
||||||
|
|
||||||
//TODO: benchmark this ctypes interface against pure python maths
|
|
||||||
|
|
||||||
void rk_mat3_rotation(
|
void rk_mat3_rotation(
|
||||||
rk_mat3 & ret,
|
rk_mat3 & ret,
|
||||||
rk_vec3 const & axis,
|
rk_vec3 const & axis,
|
||||||
|
@ -311,17 +311,14 @@ rk_vertices_t rk_create_vertices(
|
|||||||
}
|
}
|
||||||
rk_uint vertex_size = 0;
|
rk_uint vertex_size = 0;
|
||||||
for (rk_vertex_format const * f = format; *f; ++f) {
|
for (rk_vertex_format const * f = format; *f; ++f) {
|
||||||
switch (*f) {
|
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||||
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;
|
|
||||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||||
vertex_size += sizeof(float) * 3;
|
vertex_size += sizeof(rk_vec3);
|
||||||
break;
|
break;
|
||||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||||
|
vertex_size += sizeof(rk_int);
|
||||||
|
break;
|
||||||
|
case RK_VERTEX_FORMAT_VEC3_UINT10:
|
||||||
vertex_size += sizeof(rk_uint);
|
vertex_size += sizeof(rk_uint);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -346,30 +343,24 @@ rk_vertices_t rk_create_vertices(
|
|||||||
rk_uint offset = 0;
|
rk_uint offset = 0;
|
||||||
for (rk_vertex_format const * f = format; *f; ++f, ++vertices->layout) {
|
for (rk_vertex_format const * f = format; *f; ++f, ++vertices->layout) {
|
||||||
glEnableVertexAttribArray(vertices->layout);
|
glEnableVertexAttribArray(vertices->layout);
|
||||||
switch (*f) {
|
GLboolean const normalize = (*f & RK_VERTEX_FORMAT_NORMALIZE) != 0;
|
||||||
case RK_VERTEX_FORMAT_VEC2_FLOAT:
|
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||||
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;
|
|
||||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||||
glVertexAttribFormat(vertices->layout, 3, GL_FLOAT, GL_FALSE, offset);
|
glVertexAttribFormat(vertices->layout, 3, GL_FLOAT, normalize, offset);
|
||||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
offset += sizeof(rk_vec3);
|
||||||
offset += sizeof(float) * 3;
|
|
||||||
break;
|
break;
|
||||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||||
glVertexAttribFormat(vertices->layout, GL_BGRA, GL_INT_2_10_10_10_REV, GL_TRUE, offset);
|
glVertexAttribFormat(vertices->layout, 4, GL_INT_2_10_10_10_REV, normalize, offset);
|
||||||
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
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);
|
offset += sizeof(rk_uint);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||||
}
|
}
|
||||||
glBindVertexBuffer(RK_VERTICES_BINDING, vertices->vertices, 0, vertices->vertex_size);
|
glBindVertexBuffer(RK_VERTICES_BINDING, vertices->vertices, 0, vertices->vertex_size);
|
||||||
glGenBuffers(1, &vertices->indices);
|
glGenBuffers(1, &vertices->indices);
|
||||||
@ -393,10 +384,10 @@ rk_batch_t rk_create_batch(
|
|||||||
rk_uint translation_size = 0;
|
rk_uint translation_size = 0;
|
||||||
switch (translation_format) {
|
switch (translation_format) {
|
||||||
case RK_BATCH_TRANSLATION_FORMAT_FLOAT:
|
case RK_BATCH_TRANSLATION_FORMAT_FLOAT:
|
||||||
translation_size = sizeof(float) * 4;
|
translation_size = sizeof(rk_translation_float);
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
||||||
translation_size = sizeof(rk_short) * 4;
|
translation_size = sizeof(rk_translation_short);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_batch(): invalid translation format.");
|
rk_printf("rk_create_batch(): invalid translation format.");
|
||||||
@ -409,10 +400,10 @@ rk_batch_t rk_create_batch(
|
|||||||
orientation_size = 0;
|
orientation_size = 0;
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
||||||
orientation_size = sizeof(float) * 3;
|
orientation_size = sizeof(rk_orientation_float);
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||||
orientation_size = sizeof(rk_uint);
|
orientation_size = sizeof(rk_orientation_int10);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_batch(): invalid orientation format.");
|
rk_printf("rk_create_batch(): invalid orientation format.");
|
||||||
@ -433,10 +424,10 @@ rk_batch_t rk_create_batch(
|
|||||||
glEnableVertexAttribArray(translation_layout);
|
glEnableVertexAttribArray(translation_layout);
|
||||||
switch (translation_format) {
|
switch (translation_format) {
|
||||||
case RK_BATCH_TRANSLATION_FORMAT_FLOAT:
|
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;
|
break;
|
||||||
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
glVertexAttribBinding(translation_layout, RK_PARAMS_BINDING);
|
glVertexAttribBinding(translation_layout, RK_PARAMS_BINDING);
|
||||||
@ -549,13 +540,12 @@ static void rk_batch_convert_params(
|
|||||||
rk_ushort const * const _indices,
|
rk_ushort const * const _indices,
|
||||||
rk_ubyte * const _params,
|
rk_ubyte * const _params,
|
||||||
rk_vec3 const * const translations,
|
rk_vec3 const * const translations,
|
||||||
rk_ushort const * const texlevels,
|
|
||||||
rk_vec3 const * const orientations) {
|
rk_vec3 const * const orientations) {
|
||||||
_instance_params_t * params = reinterpret_cast<_instance_params_t *>(_params);
|
_instance_params_t * params = reinterpret_cast<_instance_params_t *>(_params);
|
||||||
rk_ushort const * const last = _indices + count;
|
rk_ushort const * const last = _indices + count;
|
||||||
for (rk_ushort const * indices = _indices; indices < last; ++indices, ++params) {
|
for (rk_ushort const * indices = _indices; indices < last; ++indices, ++params) {
|
||||||
rk_uint const index = *indices;
|
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_uint const count,
|
||||||
rk_ushort const * const _indices,
|
rk_ushort const * const _indices,
|
||||||
rk_ubyte * const _params,
|
rk_ubyte * const _params,
|
||||||
rk_vec3 const * const translations,
|
rk_vec3 const * const translations) {
|
||||||
rk_ushort const * const texlevels) {
|
|
||||||
_instance_params_t * params = reinterpret_cast<_instance_params_t *>(_params);
|
_instance_params_t * params = reinterpret_cast<_instance_params_t *>(_params);
|
||||||
rk_ushort const * const last = _indices + count;
|
rk_ushort const * const last = _indices + count;
|
||||||
for (rk_ushort const * indices = _indices; indices < last; ++indices, ++params) {
|
for (rk_ushort const * indices = _indices; indices < last; ++indices, ++params) {
|
||||||
rk_uint const index = *indices;
|
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_batch_t _batch,
|
||||||
rk_uint size,
|
rk_uint size,
|
||||||
rk_instance_flags const * flags,
|
rk_instance_flags const * flags,
|
||||||
rk_ushort const * texlevels,
|
|
||||||
rk_mesh const * meshes,
|
rk_mesh const * meshes,
|
||||||
rk_vec3 const * translations,
|
rk_vec3 const * translations,
|
||||||
rk_vec3 const * orientations) {
|
rk_vec3 const * orientations) {
|
||||||
rk_batch & batch = *reinterpret_cast<rk_batch *>(_batch);
|
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) {
|
!rk_current_shader || !rk_current_vertices) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -604,15 +592,15 @@ void rk_draw_batch(
|
|||||||
switch (batch.orientation_format) {
|
switch (batch.orientation_format) {
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_NONE:
|
case RK_BATCH_ORIENTATION_FORMAT_NONE:
|
||||||
rk_batch_convert_params<rk_translation_float>(
|
rk_batch_convert_params<rk_translation_float>(
|
||||||
count, batch.indices, batch.params, translations, texlevels);
|
count, batch.indices, batch.params, translations);
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
||||||
rk_batch_convert_params<rk_params_float_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;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||||
rk_batch_convert_params<rk_params_float_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;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -620,15 +608,15 @@ void rk_draw_batch(
|
|||||||
switch (batch.orientation_format) {
|
switch (batch.orientation_format) {
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_NONE:
|
case RK_BATCH_ORIENTATION_FORMAT_NONE:
|
||||||
rk_batch_convert_params<rk_translation_short>(
|
rk_batch_convert_params<rk_translation_short>(
|
||||||
count, batch.indices, batch.params, translations, texlevels);
|
count, batch.indices, batch.params, translations);
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
case RK_BATCH_ORIENTATION_FORMAT_FLOAT:
|
||||||
rk_batch_convert_params<rk_params_short_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;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||||
rk_batch_convert_params<rk_params_short_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;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -76,11 +76,9 @@ struct rk_batch {
|
|||||||
|
|
||||||
struct rk_translation_float {
|
struct rk_translation_float {
|
||||||
rk_vec3 xyz;
|
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;
|
xyz = translation;
|
||||||
l = static_cast<float>(texlevel);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,13 +86,13 @@ struct rk_translation_short {
|
|||||||
rk_short x;
|
rk_short x;
|
||||||
rk_short y;
|
rk_short y;
|
||||||
rk_short z;
|
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);
|
x = static_cast<rk_short>(translation.x);
|
||||||
y = static_cast<rk_short>(translation.y);
|
y = static_cast<rk_short>(translation.y);
|
||||||
z = static_cast<rk_short>(translation.z);
|
z = static_cast<rk_short>(translation.z);
|
||||||
l = texlevel;
|
pad = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,7 +104,6 @@ struct rk_orientation_float {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct rk_orientation_int10 {
|
struct rk_orientation_int10 {
|
||||||
rk_uint xyz;
|
rk_uint xyz;
|
||||||
|
|
||||||
@ -122,8 +119,8 @@ struct rk_params {
|
|||||||
_translation_t translation;
|
_translation_t translation;
|
||||||
_orientation_t orientation;
|
_orientation_t orientation;
|
||||||
|
|
||||||
inline void set(rk_vec3 const & translation, rk_ushort const texlevel, rk_vec3 const & orientation) {
|
inline void set(rk_vec3 const & translation, rk_vec3 const & orientation) {
|
||||||
this->translation.set(translation, texlevel);
|
this->translation.set(translation);
|
||||||
this->orientation.set(orientation);
|
this->orientation.set(orientation);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -47,10 +47,12 @@ enum rk_texture_flags : rk_uint {
|
|||||||
|
|
||||||
enum rk_vertex_format : rk_ubyte {
|
enum rk_vertex_format : rk_ubyte {
|
||||||
RK_VERTEX_FORMAT_END = 0,
|
RK_VERTEX_FORMAT_END = 0,
|
||||||
RK_VERTEX_FORMAT_VEC2_FLOAT = 1,
|
RK_VERTEX_FORMAT_VEC3_FLOAT = 1,
|
||||||
RK_VERTEX_FORMAT_VEC2_USHORT = 2,
|
RK_VERTEX_FORMAT_VEC3_INT10 = 2,
|
||||||
RK_VERTEX_FORMAT_VEC3_FLOAT = 3,
|
RK_VERTEX_FORMAT_VEC3_UINT10 = 3,
|
||||||
RK_VERTEX_FORMAT_VEC3_INT10 = 4,
|
|
||||||
|
RK_VERTEX_FORMAT_NORMALIZE = RK_FLAG(7),
|
||||||
|
RK_VERTEX_FORMAT_MASK = RK_VERTEX_FORMAT_NORMALIZE - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
enum rk_instance_flags : rk_ubyte {
|
enum rk_instance_flags : rk_ubyte {
|
||||||
@ -155,7 +157,6 @@ RK_EXPORT void rk_draw_batch(
|
|||||||
rk_batch_t batch,
|
rk_batch_t batch,
|
||||||
rk_uint size,
|
rk_uint size,
|
||||||
rk_instance_flags const * flags,
|
rk_instance_flags const * flags,
|
||||||
rk_ushort const * texlevels,
|
|
||||||
rk_mesh const * meshes,
|
rk_mesh const * meshes,
|
||||||
rk_vec3 const * translations,
|
rk_vec3 const * translations,
|
||||||
rk_vec3 const * orientations);
|
rk_vec3 const * orientations);
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//TODO: use glm types
|
|
||||||
|
|
||||||
#ifndef _RK_ENGINE_TYPES_H
|
#ifndef _RK_ENGINE_TYPES_H
|
||||||
#define _RK_ENGINE_TYPES_H
|
#define _RK_ENGINE_TYPES_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user