Use configure-time constant for the host's endianness
This commit is contained in:
parent
d4019706a8
commit
828f970da5
@ -35,6 +35,11 @@ set(ALL_SRC_FILES ${ALL_SRC_FILES})
|
|||||||
# Find bit size of the target architecture
|
# Find bit size of the target architecture
|
||||||
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
|
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
|
||||||
|
|
||||||
|
# Test if host's architecture is big-endian
|
||||||
|
include(TestBigEndian)
|
||||||
|
test_big_endian(GMIO_HOST_IS_BIG_ENDIAN)
|
||||||
|
|
||||||
|
# Find available C99 features
|
||||||
if(NOT BUILD_STRICT_C90)
|
if(NOT BUILD_STRICT_C90)
|
||||||
# Have <stdint.h> ?
|
# Have <stdint.h> ?
|
||||||
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#cmakedefine GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC
|
#cmakedefine GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC
|
||||||
|
|
||||||
|
#cmakedefine GMIO_HOST_IS_BIG_ENDIAN
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
# if defined(__i386__) || defined(__ppc__)
|
# if defined(__i386__) || defined(__ppc__)
|
||||||
# define GMIO_TARGET_ARCH_BIT_SIZE 32
|
# define GMIO_TARGET_ARCH_BIT_SIZE 32
|
||||||
|
@ -33,6 +33,14 @@ enum gmio_endianness
|
|||||||
|
|
||||||
typedef enum gmio_endianness gmio_endianness_t;
|
typedef enum gmio_endianness gmio_endianness_t;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
#ifdef GMIO_HOST_IS_BIG_ENDIAN
|
||||||
|
GMIO_HOST_ENDIANNESS = GMIO_BIG_ENDIAN
|
||||||
|
#else
|
||||||
|
GMIO_HOST_ENDIANNESS = GMIO_LITTLE_ENDIAN
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
GMIO_C_LINKAGE_BEGIN
|
GMIO_C_LINKAGE_BEGIN
|
||||||
|
|
||||||
/*! Returns endianness (byte order) of the host's CPU architecture */
|
/*! Returns endianness (byte order) of the host's CPU architecture */
|
||||||
|
@ -72,10 +72,8 @@ int gmio_stlb_read(
|
|||||||
const gmio_stlb_read_options_t* options)
|
const gmio_stlb_read_options_t* options)
|
||||||
{
|
{
|
||||||
/* Constants */
|
/* Constants */
|
||||||
const gmio_endianness_t host_byte_order =
|
|
||||||
gmio_host_endianness();
|
|
||||||
const gmio_endianness_t byte_order =
|
const gmio_endianness_t byte_order =
|
||||||
options != NULL ? options->byte_order : host_byte_order;
|
options != NULL ? options->byte_order : GMIO_HOST_ENDIANNESS;
|
||||||
const uint32_t max_facet_count_per_read =
|
const uint32_t max_facet_count_per_read =
|
||||||
trsf != NULL ?
|
trsf != NULL ?
|
||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(
|
||||||
@ -92,7 +90,7 @@ int gmio_stlb_read(
|
|||||||
return error;
|
return error;
|
||||||
|
|
||||||
/* Initialize rparams */
|
/* Initialize rparams */
|
||||||
if (host_byte_order != byte_order)
|
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||||
rparams.fix_endian_func = gmio_stl_triangle_bswap;
|
rparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||||
|
|
||||||
/* Read header */
|
/* Read header */
|
||||||
@ -107,7 +105,7 @@ int gmio_stlb_read(
|
|||||||
return GMIO_STLB_READ_FACET_COUNT_ERROR;
|
return GMIO_STLB_READ_FACET_COUNT_ERROR;
|
||||||
|
|
||||||
memcpy(&total_facet_count, trsf->buffer, sizeof(uint32_t));
|
memcpy(&total_facet_count, trsf->buffer, sizeof(uint32_t));
|
||||||
if (host_byte_order != byte_order)
|
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||||
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
||||||
|
|
||||||
/* Callback to notify triangle count and header data */
|
/* Callback to notify triangle count and header data */
|
||||||
|
@ -73,10 +73,8 @@ int gmio_stlb_write(
|
|||||||
const gmio_stlb_write_options_t* options)
|
const gmio_stlb_write_options_t* options)
|
||||||
{
|
{
|
||||||
/* Constants */
|
/* Constants */
|
||||||
const gmio_endianness_t host_byte_order =
|
|
||||||
gmio_host_endianness();
|
|
||||||
const gmio_endianness_t byte_order =
|
const gmio_endianness_t byte_order =
|
||||||
options != NULL ? options->byte_order : host_byte_order;
|
options != NULL ? options->byte_order : GMIO_HOST_ENDIANNESS;
|
||||||
const uint8_t* header_data =
|
const uint8_t* header_data =
|
||||||
options != NULL ? options->header_data : NULL;
|
options != NULL ? options->header_data : NULL;
|
||||||
const uint32_t facet_count =
|
const uint32_t facet_count =
|
||||||
@ -93,7 +91,7 @@ int gmio_stlb_write(
|
|||||||
return error;
|
return error;
|
||||||
|
|
||||||
/* Initialize wparams */
|
/* Initialize wparams */
|
||||||
if (host_byte_order != byte_order)
|
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||||
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||||
wparams.facet_count = gmio_size_to_uint32(
|
wparams.facet_count = gmio_size_to_uint32(
|
||||||
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
|
Loading…
Reference in New Issue
Block a user