Compare commits
No commits in common. "8f3612bed26d4bdb9f6c62541bf6068285f760b3" and "af25548752d7ae7004a937307e06bd4810e46cc7" have entirely different histories.
8f3612bed2
...
af25548752
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_VEC3_FLOAT = 1
|
VERTEX_FORMAT_VEC2_FLOAT = 1
|
||||||
VERTEX_FORMAT_VEC3_INT10 = 2
|
VERTEX_FORMAT_VEC2_USHORT = 2
|
||||||
VERTEX_FORMAT_VEC3_UINT10 = 3
|
VERTEX_FORMAT_VEC3_FLOAT = 3
|
||||||
VERTEX_FORMAT_NORMALIZE = _flag(7)
|
VERTEX_FORMAT_VEC3_INT10 = 4
|
||||||
|
|
||||||
def vertex_format(*format):
|
def vertex_format(*format):
|
||||||
return array('B', format).tobytes()
|
return array('B', format).tobytes()
|
||||||
@ -344,15 +344,16 @@ _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, meshes, translations, orientations):
|
def draw_batch(batch, flags, texlevels, meshes, translations, orientations):
|
||||||
size = len(flags)
|
size = len(flags)
|
||||||
assert len(meshes) == size and len(translations) == size * 3
|
assert len(texlevels) == size and 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), _uintp(meshes), _floatp(translations),
|
_draw_batch(batch, size, _ubytep(flags), _ushortp(texlevels), _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,6 +15,8 @@
|
|||||||
|
|
||||||
#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,14 +311,17 @@ 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 & RK_VERTEX_FORMAT_MASK) {
|
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;
|
||||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||||
vertex_size += sizeof(rk_vec3);
|
vertex_size += sizeof(float) * 3;
|
||||||
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:
|
||||||
@ -343,24 +346,30 @@ 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);
|
||||||
GLboolean const normalize = (*f & RK_VERTEX_FORMAT_NORMALIZE) != 0;
|
switch (*f) {
|
||||||
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
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;
|
||||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||||
glVertexAttribFormat(vertices->layout, 3, GL_FLOAT, normalize, offset);
|
glVertexAttribFormat(vertices->layout, 3, GL_FLOAT, GL_FALSE, offset);
|
||||||
offset += sizeof(rk_vec3);
|
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||||
|
offset += sizeof(float) * 3;
|
||||||
break;
|
break;
|
||||||
case RK_VERTEX_FORMAT_VEC3_INT10:
|
case RK_VERTEX_FORMAT_VEC3_INT10:
|
||||||
glVertexAttribFormat(vertices->layout, 4, GL_INT_2_10_10_10_REV, normalize, offset);
|
glVertexAttribFormat(vertices->layout, GL_BGRA, GL_INT_2_10_10_10_REV, GL_TRUE, offset);
|
||||||
offset += sizeof(rk_int);
|
glVertexAttribBinding(vertices->layout, RK_VERTICES_BINDING);
|
||||||
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);
|
||||||
@ -384,10 +393,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(rk_translation_float);
|
translation_size = sizeof(float) * 4;
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
||||||
translation_size = sizeof(rk_translation_short);
|
translation_size = sizeof(rk_short) * 4;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_batch(): invalid translation format.");
|
rk_printf("rk_create_batch(): invalid translation format.");
|
||||||
@ -400,10 +409,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(rk_orientation_float);
|
orientation_size = sizeof(float) * 3;
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
case RK_BATCH_ORIENTATION_FORMAT_INT10:
|
||||||
orientation_size = sizeof(rk_orientation_int10);
|
orientation_size = sizeof(rk_uint);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_batch(): invalid orientation format.");
|
rk_printf("rk_create_batch(): invalid orientation format.");
|
||||||
@ -424,10 +433,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, 3, GL_FLOAT, GL_FALSE, 0);
|
glVertexAttribFormat(translation_layout, 4, GL_FLOAT, GL_FALSE, 0);
|
||||||
break;
|
break;
|
||||||
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
case RK_BATCH_TRANSLATION_FORMAT_SHORT:
|
||||||
glVertexAttribFormat(translation_layout, 3, GL_SHORT, GL_FALSE, 0);
|
glVertexAttribFormat(translation_layout, 4, GL_SHORT, GL_FALSE, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
glVertexAttribBinding(translation_layout, RK_PARAMS_BINDING);
|
glVertexAttribBinding(translation_layout, RK_PARAMS_BINDING);
|
||||||
@ -540,12 +549,13 @@ 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], orientations[index]);
|
params->set(translations[index], texlevels[index], orientations[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,12 +564,13 @@ 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]);
|
params->set(translations[index], texlevels[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,11 +578,12 @@ 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 || !meshes || !translations ||
|
if (!size || size > batch.size || !flags || !texlevels || !meshes || !translations ||
|
||||||
!rk_current_shader || !rk_current_vertices) {
|
!rk_current_shader || !rk_current_vertices) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -592,15 +604,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);
|
count, batch.indices, batch.params, translations, texlevels);
|
||||||
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, orientations);
|
count, batch.indices, batch.params, translations, texlevels, 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, orientations);
|
count, batch.indices, batch.params, translations, texlevels, orientations);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -608,15 +620,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);
|
count, batch.indices, batch.params, translations, texlevels);
|
||||||
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, orientations);
|
count, batch.indices, batch.params, translations, texlevels, 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, orientations);
|
count, batch.indices, batch.params, translations, texlevels, orientations);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -76,9 +76,11 @@ 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) {
|
inline void set(rk_vec3 const & translation, rk_ushort const texlevel) {
|
||||||
xyz = translation;
|
xyz = translation;
|
||||||
|
l = static_cast<float>(texlevel);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,13 +88,13 @@ struct rk_translation_short {
|
|||||||
rk_short x;
|
rk_short x;
|
||||||
rk_short y;
|
rk_short y;
|
||||||
rk_short z;
|
rk_short z;
|
||||||
rk_short pad;
|
rk_ushort l;
|
||||||
|
|
||||||
inline void set(rk_vec3 const & translation) {
|
inline void set(rk_vec3 const & translation, rk_ushort const texlevel) {
|
||||||
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);
|
||||||
pad = 0;
|
l = texlevel;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,6 +106,7 @@ struct rk_orientation_float {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct rk_orientation_int10 {
|
struct rk_orientation_int10 {
|
||||||
rk_uint xyz;
|
rk_uint xyz;
|
||||||
|
|
||||||
@ -119,8 +122,8 @@ struct rk_params {
|
|||||||
_translation_t translation;
|
_translation_t translation;
|
||||||
_orientation_t orientation;
|
_orientation_t orientation;
|
||||||
|
|
||||||
inline void set(rk_vec3 const & translation, rk_vec3 const & orientation) {
|
inline void set(rk_vec3 const & translation, rk_ushort const texlevel, rk_vec3 const & orientation) {
|
||||||
this->translation.set(translation);
|
this->translation.set(translation, texlevel);
|
||||||
this->orientation.set(orientation);
|
this->orientation.set(orientation);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -47,12 +47,10 @@ 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_VEC3_FLOAT = 1,
|
RK_VERTEX_FORMAT_VEC2_FLOAT = 1,
|
||||||
RK_VERTEX_FORMAT_VEC3_INT10 = 2,
|
RK_VERTEX_FORMAT_VEC2_USHORT = 2,
|
||||||
RK_VERTEX_FORMAT_VEC3_UINT10 = 3,
|
RK_VERTEX_FORMAT_VEC3_FLOAT = 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 {
|
||||||
@ -157,6 +155,7 @@ 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,6 +13,8 @@
|
|||||||
// 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