Skip to content

Commit

Permalink
Merge pull request jkuhlmann#180 from prideout/master
Browse files Browse the repository at this point in the history
Fix unpack_floats() for signed integers.
  • Loading branch information
jkuhlmann authored Jun 14, 2022
2 parents be2ef0f + 5493f49 commit 280ab89
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern "C" {
#endif

typedef size_t cgltf_size;
typedef long long int cgltf_ssize;
typedef float cgltf_float;
typedef int cgltf_int;
typedef unsigned int cgltf_uint;
Expand Down Expand Up @@ -2121,7 +2122,7 @@ void cgltf_node_transform_world(const cgltf_node* node, cgltf_float* out_matrix)
}
}

static cgltf_size cgltf_component_read_index(const void* in, cgltf_component_type component_type)
static cgltf_ssize cgltf_component_read_integer(const void* in, cgltf_component_type component_type)
{
switch (component_type)
{
Expand All @@ -2132,7 +2133,7 @@ static cgltf_size cgltf_component_read_index(const void* in, cgltf_component_typ
case cgltf_component_type_r_32u:
return *((const uint32_t*) in);
case cgltf_component_type_r_32f:
return (cgltf_size)*((const float*) in);
return (cgltf_ssize)*((const float*) in);
case cgltf_component_type_r_8:
return *((const int8_t*) in);
case cgltf_component_type_r_8u:
Expand All @@ -2142,6 +2143,23 @@ static cgltf_size cgltf_component_read_index(const void* in, cgltf_component_typ
}
}

static cgltf_size cgltf_component_read_index(const void* in, cgltf_component_type component_type)
{
switch (component_type)
{
case cgltf_component_type_r_16u:
return *((const uint16_t*) in);
case cgltf_component_type_r_32u:
return *((const uint32_t*) in);
case cgltf_component_type_r_32f:
return (cgltf_size)*((const float*) in);
case cgltf_component_type_r_8u:
return *((const uint8_t*) in);
default:
return 0;
}
}

static cgltf_float cgltf_component_read_float(const void* in, cgltf_component_type component_type, cgltf_bool normalized)
{
if (component_type == cgltf_component_type_r_32f)
Expand All @@ -2167,7 +2185,7 @@ static cgltf_float cgltf_component_read_float(const void* in, cgltf_component_ty
}
}

return (cgltf_float)cgltf_component_read_index(in, component_type);
return (cgltf_float)cgltf_component_read_integer(in, component_type);
}

static cgltf_size cgltf_component_size(cgltf_component_type component_type);
Expand Down

0 comments on commit 280ab89

Please sign in to comment.