Skip to content

Commit

Permalink
Add glTF sampler filters and wrap modes enums
Browse files Browse the repository at this point in the history
cgltf_sampler defines filter and wrap modes using cgltf_int, which
requires referencing the glTF specification to interpret those integers.
To resolve this, enumerations representing valid glTF sampler filter and
wrap modes are introduced. For backward compatibility, these
enumerations retain their original integer values to allow implicit
conversion to cgltf_int.
  • Loading branch information
matthew-rister committed Dec 8, 2024
1 parent 9bc9ea3 commit a9adbb7
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,30 @@ typedef struct cgltf_image
cgltf_extension* extensions;
} cgltf_image;

typedef enum cgltf_filter_type {
cgltf_filter_type_undefined = 0,
cgltf_filter_type_nearest = 9728,
cgltf_filter_type_linear = 9729,
cgltf_filter_type_nearest_mipmap_nearest = 9984,
cgltf_filter_type_linear_mipmap_nearest = 9985,
cgltf_filter_type_nearest_mipmap_linear = 9986,
cgltf_filter_type_linear_mipmap_linear = 9987
} cgltf_filter_type;

typedef enum cgltf_wrap_mode {
cgltf_wrap_mode_clamp_to_edge = 33071,
cgltf_wrap_mode_mirrored_repeat = 33648,
cgltf_wrap_mode_repeat = 10497,
cgltf_wrap_mode_default = cgltf_wrap_mode_repeat
} cgltf_wrap_mode;

typedef struct cgltf_sampler
{
char* name;
cgltf_int mag_filter;
cgltf_int min_filter;
cgltf_int wrap_s;
cgltf_int wrap_t;
cgltf_filter_type mag_filter;
cgltf_filter_type min_filter;
cgltf_wrap_mode wrap_s;
cgltf_wrap_mode wrap_t;
cgltf_extras extras;
cgltf_size extensions_count;
cgltf_extension* extensions;
Expand Down Expand Up @@ -4420,8 +4437,11 @@ static int cgltf_parse_json_sampler(cgltf_options* options, jsmntok_t const* tok
(void)options;
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);

out_sampler->wrap_s = 10497;
out_sampler->wrap_t = 10497;
out_sampler->mag_filter = cgltf_filter_type_undefined;
out_sampler->min_filter = cgltf_filter_type_undefined;

out_sampler->wrap_s = cgltf_wrap_mode_default;
out_sampler->wrap_t = cgltf_wrap_mode_default;

int size = tokens[i].size;
++i;
Expand All @@ -4438,28 +4458,28 @@ static int cgltf_parse_json_sampler(cgltf_options* options, jsmntok_t const* tok
{
++i;
out_sampler->mag_filter
= cgltf_json_to_int(tokens + i, json_chunk);
= (cgltf_filter_type)cgltf_json_to_int(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "minFilter") == 0)
{
++i;
out_sampler->min_filter
= cgltf_json_to_int(tokens + i, json_chunk);
= (cgltf_filter_type)cgltf_json_to_int(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "wrapS") == 0)
{
++i;
out_sampler->wrap_s
= cgltf_json_to_int(tokens + i, json_chunk);
= (cgltf_wrap_mode)cgltf_json_to_int(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "wrapT") == 0)
{
++i;
out_sampler->wrap_t
= cgltf_json_to_int(tokens + i, json_chunk);
= (cgltf_wrap_mode)cgltf_json_to_int(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extras") == 0)
Expand Down

0 comments on commit a9adbb7

Please sign in to comment.