gmio_stl: minor optimizations
This commit is contained in:
parent
ae82134463
commit
762ca148cb
@ -21,9 +21,10 @@ void gmio_stl_triangle_bswap(gmio_stl_triangle_t* triangle)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint32_t* uintcoord_ptr = (uint32_t*)&(triangle->normal.x);
|
uint32_t* uintcoord_ptr = (uint32_t*)&(triangle->normal.x);
|
||||||
|
const uint16_t attr_byte_count = triangle->attribute_byte_count;
|
||||||
|
|
||||||
for (i = 0; i < 12; ++i)
|
for (i = 0; i < 12; ++i)
|
||||||
*(uintcoord_ptr + i) = gmio_uint32_bswap(*(uintcoord_ptr + i));
|
*(uintcoord_ptr + i) = gmio_uint32_bswap(*(uintcoord_ptr + i));
|
||||||
if (triangle->attribute_byte_count != 0)
|
if (attr_byte_count != 0)
|
||||||
triangle->attribute_byte_count = gmio_uint16_bswap(triangle->attribute_byte_count);
|
triangle->attribute_byte_count = gmio_uint16_bswap(attr_byte_count);
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ int gmio_stlb_read(
|
|||||||
trsf->buffer.size / GMIO_STLB_TRIANGLE_RAWSIZE)
|
trsf->buffer.size / GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||||
: 0;
|
: 0;
|
||||||
/* Variables */
|
/* Variables */
|
||||||
|
void* buffer_ptr = trsf != NULL ? trsf->buffer.ptr : NULL;
|
||||||
gmio_stlb_readwrite_helper_t rparams = {0};
|
gmio_stlb_readwrite_helper_t rparams = {0};
|
||||||
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
||||||
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
|
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
|
||||||
@ -99,13 +100,13 @@ int gmio_stlb_read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read facet count */
|
/* Read facet count */
|
||||||
if (gmio_stream_read(&trsf->stream, trsf->buffer.ptr, sizeof(uint32_t), 1)
|
if (gmio_stream_read(&trsf->stream, buffer_ptr, sizeof(uint32_t), 1)
|
||||||
!= 1)
|
!= 1)
|
||||||
{
|
{
|
||||||
return GMIO_STLB_READ_FACET_COUNT_ERROR;
|
return GMIO_STLB_READ_FACET_COUNT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&total_facet_count, trsf->buffer.ptr, sizeof(uint32_t));
|
memcpy(&total_facet_count, buffer_ptr, sizeof(uint32_t));
|
||||||
if (byte_order != GMIO_HOST_ENDIANNESS)
|
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||||
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ int gmio_stlb_read(
|
|||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(
|
||||||
gmio_stream_read(
|
gmio_stream_read(
|
||||||
&trsf->stream,
|
&trsf->stream,
|
||||||
trsf->buffer.ptr,
|
buffer_ptr,
|
||||||
GMIO_STLB_TRIANGLE_RAWSIZE,
|
GMIO_STLB_TRIANGLE_RAWSIZE,
|
||||||
max_facet_count_per_read));
|
max_facet_count_per_read));
|
||||||
if (gmio_stream_error(&trsf->stream) != 0)
|
if (gmio_stream_error(&trsf->stream) != 0)
|
||||||
@ -137,7 +138,7 @@ int gmio_stlb_read(
|
|||||||
break; /* Exit if no facet to read */
|
break; /* Exit if no facet to read */
|
||||||
|
|
||||||
if (gmio_no_error(error)) {
|
if (gmio_no_error(error)) {
|
||||||
gmio_stlb_read_facets(creator, trsf->buffer.ptr, &rparams);
|
gmio_stlb_read_facets(creator, buffer_ptr, &rparams);
|
||||||
rparams.i_facet_offset += rparams.facet_count;
|
rparams.i_facet_offset += rparams.facet_count;
|
||||||
if (gmio_transfer_is_stop_requested(trsf))
|
if (gmio_transfer_is_stop_requested(trsf))
|
||||||
error = GMIO_TRANSFER_STOPPED_ERROR;
|
error = GMIO_TRANSFER_STOPPED_ERROR;
|
||||||
|
@ -80,6 +80,7 @@ int gmio_stlb_write(
|
|||||||
const uint32_t facet_count =
|
const uint32_t facet_count =
|
||||||
mesh != NULL ? mesh->triangle_count : 0;
|
mesh != NULL ? mesh->triangle_count : 0;
|
||||||
/* Variables */
|
/* Variables */
|
||||||
|
void* buffer_ptr = trsf != NULL ? trsf->buffer.ptr : NULL;
|
||||||
gmio_stlb_readwrite_helper_t wparams = {0};
|
gmio_stlb_readwrite_helper_t wparams = {0};
|
||||||
uint32_t i_facet = 0;
|
uint32_t i_facet = 0;
|
||||||
int error = GMIO_NO_ERROR;
|
int error = GMIO_NO_ERROR;
|
||||||
@ -99,8 +100,8 @@ int gmio_stlb_write(
|
|||||||
/* Write header */
|
/* Write header */
|
||||||
if (header_data == NULL) {
|
if (header_data == NULL) {
|
||||||
/* Use buffer to store an empty header (filled with zeroes) */
|
/* Use buffer to store an empty header (filled with zeroes) */
|
||||||
memset(trsf->buffer.ptr, 0, GMIO_STLB_HEADER_SIZE);
|
memset(buffer_ptr, 0, GMIO_STLB_HEADER_SIZE);
|
||||||
header_data = (const uint8_t*)trsf->buffer.ptr;
|
header_data = (const uint8_t*)buffer_ptr;
|
||||||
}
|
}
|
||||||
if (gmio_stream_write(&trsf->stream, header_data, GMIO_STLB_HEADER_SIZE, 1)
|
if (gmio_stream_write(&trsf->stream, header_data, GMIO_STLB_HEADER_SIZE, 1)
|
||||||
!= 1)
|
!= 1)
|
||||||
@ -110,14 +111,11 @@ int gmio_stlb_write(
|
|||||||
|
|
||||||
/* Write facet count */
|
/* Write facet count */
|
||||||
if (byte_order == GMIO_LITTLE_ENDIAN)
|
if (byte_order == GMIO_LITTLE_ENDIAN)
|
||||||
gmio_encode_uint32_le(facet_count, trsf->buffer.ptr);
|
gmio_encode_uint32_le(facet_count, buffer_ptr);
|
||||||
else
|
else
|
||||||
gmio_encode_uint32_be(facet_count, trsf->buffer.ptr);
|
gmio_encode_uint32_be(facet_count, buffer_ptr);
|
||||||
if (gmio_stream_write(&trsf->stream, trsf->buffer.ptr, sizeof(uint32_t), 1)
|
if (gmio_stream_write(&trsf->stream, buffer_ptr, sizeof(uint32_t), 1) != 1)
|
||||||
!= 1)
|
|
||||||
{
|
|
||||||
return GMIO_STREAM_ERROR;
|
return GMIO_STREAM_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
/* Write triangles */
|
/* Write triangles */
|
||||||
for (i_facet = 0;
|
for (i_facet = 0;
|
||||||
@ -130,13 +128,13 @@ int gmio_stlb_write(
|
|||||||
wparams.facet_count = GMIO_MIN(wparams.facet_count,
|
wparams.facet_count = GMIO_MIN(wparams.facet_count,
|
||||||
facet_count - wparams.i_facet_offset);
|
facet_count - wparams.i_facet_offset);
|
||||||
|
|
||||||
gmio_stlb_write_facets(mesh, trsf->buffer.ptr, &wparams);
|
gmio_stlb_write_facets(mesh, buffer_ptr, &wparams);
|
||||||
wparams.i_facet_offset += wparams.facet_count;
|
wparams.i_facet_offset += wparams.facet_count;
|
||||||
|
|
||||||
/* Write buffer to stream */
|
/* Write buffer to stream */
|
||||||
if (gmio_stream_write(
|
if (gmio_stream_write(
|
||||||
&trsf->stream,
|
&trsf->stream,
|
||||||
trsf->buffer.ptr,
|
buffer_ptr,
|
||||||
GMIO_STLB_TRIANGLE_RAWSIZE,
|
GMIO_STLB_TRIANGLE_RAWSIZE,
|
||||||
wparams.facet_count)
|
wparams.facet_count)
|
||||||
!= wparams.facet_count)
|
!= wparams.facet_count)
|
||||||
|
Loading…
Reference in New Issue
Block a user