Stores meshes into vertices.
This commit is contained in:
parent
66980e6ea9
commit
d0741afda7
14
__init__.py
14
__init__.py
@ -44,6 +44,10 @@ def _ushort_addr(x):
|
||||
assert x.typecode == 'H'
|
||||
return x.buffer_info()[0]
|
||||
|
||||
def _uint_addr(x):
|
||||
assert x.typecode == 'I'
|
||||
return x.buffer_info()[0]
|
||||
|
||||
def _float_addr(x):
|
||||
assert x.typecode == 'f'
|
||||
return x.buffer_info()[0]
|
||||
@ -371,10 +375,13 @@ _create_vertices.argtypes = (
|
||||
ctypes.c_uint, # nvertices
|
||||
ctypes.c_void_p, # vertices
|
||||
ctypes.c_uint, # nindices
|
||||
ctypes.c_void_p) # indices
|
||||
ctypes.c_void_p, # vertices
|
||||
ctypes.c_uint, # nmeshes
|
||||
ctypes.c_void_p) # meshes
|
||||
|
||||
def create_vertices(format, nvertices, vertices, indices):
|
||||
return _create_vertices(format, nvertices, _ubyte_addr(vertices), len(indices), _ushort_addr(indices))
|
||||
def create_vertices(format, nvertices, vertices, indices, meshes):
|
||||
return _create_vertices(format,
|
||||
nvertices, _ubyte_addr(vertices), len(indices), _ushort_addr(indices), len(meshes), _uint_addr(meshes))
|
||||
|
||||
create_batch = _engine.rk_create_batch
|
||||
create_batch.restype = _handle
|
||||
@ -382,7 +389,6 @@ create_batch.errcheck = _check_handle
|
||||
create_batch.argtypes = (
|
||||
ctypes.c_void_p, # vertices
|
||||
ctypes.c_uint, # max_size
|
||||
ctypes.c_uint, # max_meshes
|
||||
ctypes.c_char_p) # params_format
|
||||
|
||||
clear_buffer = _engine.rk_clear_buffer
|
||||
|
@ -116,12 +116,13 @@ RK_EXPORT rk_vertices_t rk_create_vertices(
|
||||
rk_uint nvertices,
|
||||
rk_ubyte const * vertices,
|
||||
rk_uint nindices,
|
||||
rk_ushort const * indices);
|
||||
rk_ushort const * indices,
|
||||
rk_uint nmeshes,
|
||||
rk_mesh const * meshes);
|
||||
|
||||
RK_EXPORT rk_batch_t rk_create_batch(
|
||||
rk_vertices_t vertices,
|
||||
rk_uint max_size,
|
||||
rk_uint max_meshes,
|
||||
rk_param_format const * params_format);
|
||||
|
||||
RK_EXPORT void rk_clear_buffer(
|
||||
|
@ -314,7 +314,9 @@ rk_vertices_t rk_create_vertices(
|
||||
rk_uint nvertices,
|
||||
rk_ubyte const * _vertices,
|
||||
rk_uint nindices,
|
||||
rk_ushort const * indices) {
|
||||
rk_ushort const * indices,
|
||||
rk_uint nmeshes,
|
||||
rk_mesh const * meshes) {
|
||||
if (!format || !nvertices || !_vertices || !nindices || !indices) {
|
||||
rk_printf("rk_create_vertices(): invalid params.");
|
||||
return RK_INVALID_HANDLE;
|
||||
@ -345,12 +347,15 @@ rk_vertices_t rk_create_vertices(
|
||||
rk_vertices * const vertices = new rk_vertices;
|
||||
vertices->nvertices = nvertices;
|
||||
vertices->nindices = nindices;
|
||||
vertices->nmeshes = nmeshes;
|
||||
vertices->format = new rk_vertex_format[format_size + 1];
|
||||
memcpy(vertices->format, format, (format_size + 1) * sizeof(rk_vertex_format));
|
||||
vertices->vertices = new rk_ubyte[nvertices * vertex_size];
|
||||
memcpy(vertices->vertices, _vertices, nvertices * vertex_size);
|
||||
vertices->indices = new rk_ushort[nindices];
|
||||
memcpy(vertices->indices, indices, nindices * sizeof(rk_ushort));
|
||||
vertices->meshes = new rk_mesh[nmeshes];
|
||||
memcpy(vertices->meshes, meshes, nmeshes * sizeof(rk_mesh));
|
||||
vertices->vertices_buffer = 0;
|
||||
vertices->indices_buffer = 0;
|
||||
return reinterpret_cast<rk_vertices_t>(vertices);
|
||||
@ -490,7 +495,6 @@ static void rk_pack_mat3_int10_norm(
|
||||
rk_batch_t rk_create_batch(
|
||||
rk_vertices_t _vertices,
|
||||
rk_uint max_size,
|
||||
rk_uint max_meshes,
|
||||
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) {
|
||||
@ -544,12 +548,12 @@ rk_batch_t rk_create_batch(
|
||||
batch->ncommands = 0;
|
||||
batch->ninstances = 0;
|
||||
batch->max_size = max_size;
|
||||
batch->max_meshes = max_meshes;
|
||||
batch->max_meshes = vertices->nmeshes;
|
||||
batch->nparams = nparams;
|
||||
batch->flags = new rk_instance_flags[max_size];
|
||||
batch->meshes = new rk_mesh[max_size];
|
||||
batch->indices = new rk_ushort[max_size];
|
||||
batch->commands = new rk_command[max_meshes];
|
||||
batch->commands = new rk_command[batch->max_meshes];
|
||||
if (nparams) {
|
||||
batch->params = new rk_parameter[nparams];
|
||||
} else {
|
||||
@ -573,7 +577,7 @@ rk_batch_t rk_create_batch(
|
||||
if (rk_MultiDrawElementsIndirect) {
|
||||
glGenBuffers(1, &batch->commands_buffer);
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, batch->commands_buffer);
|
||||
glBufferData(GL_DRAW_INDIRECT_BUFFER, max_meshes * sizeof(rk_command), nullptr, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_DRAW_INDIRECT_BUFFER, batch->max_meshes * sizeof(rk_command), nullptr, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
|
||||
}
|
||||
if (nparams) {
|
||||
|
@ -41,9 +41,11 @@ struct rk_triangles {
|
||||
struct rk_vertices {
|
||||
unsigned nvertices;
|
||||
unsigned nindices;
|
||||
unsigned nmeshes;
|
||||
rk_vertex_format * format;
|
||||
rk_ubyte * vertices;
|
||||
rk_ushort * indices;
|
||||
rk_mesh * meshes;
|
||||
GLuint vertices_buffer;
|
||||
GLuint indices_buffer;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user