Skip to content

Commit

Permalink
texture.h: Overload decode_wrapmode to support ustringhash (#4207)
Browse files Browse the repository at this point in the history
For OSL, we want to be able to decode a wrapmode directly from a
ustringhash without having to expensively convert it to ustring.

Signed-off-by: Chris Hellmuth <[email protected]>
  • Loading branch information
chellmuth authored Mar 28, 2024
1 parent 22ef9b2 commit 6179658
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/include/OpenImageIO/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define OIIO_TEXTURESYSTEM_SUPPORTS_GETATTRIBUTETYPE 1

#define OIIO_TEXTURESYSTEM_SUPPORTS_STOCHASTIC 1
#define OIIO_TEXTURESYSTEM_SUPPORTS_DECODE_BY_USTRINGHASH 1

#ifndef INCLUDED_IMATHVEC_H
// Placeholder declaration for Imath::V3f if no Imath headers have been
Expand Down Expand Up @@ -93,6 +94,7 @@ enum class Wrap {
/// "default", "black", "clamp", "periodic", "mirror".
OIIO_API Wrap decode_wrapmode (const char *name);
OIIO_API Wrap decode_wrapmode (ustring name);
OIIO_API Wrap decode_wrapmode (ustringhash name);

/// Utility: Parse a single wrap mode (e.g., "periodic") or a
/// comma-separated wrap modes string (e.g., "black,clamp") into
Expand Down Expand Up @@ -278,6 +280,10 @@ class OIIO_API TextureOpt {
{
return (Wrap)Tex::decode_wrapmode(name);
}
static Wrap decode_wrapmode(ustringhash name)
{
return (Wrap)Tex::decode_wrapmode(name);
}

/// Utility: Parse a single wrap mode (e.g., "periodic") or a
/// comma-separated wrap modes string (e.g., "black,clamp") into
Expand Down Expand Up @@ -430,6 +436,10 @@ class OIIO_API TextureOptions {
{
return (Wrap)Tex::decode_wrapmode(name);
}
static Wrap decode_wrapmode(ustringhash name)
{
return (Wrap)Tex::decode_wrapmode(name);
}

/// Utility: Parse a single wrap mode (e.g., "periodic") or a
/// comma-separated wrap modes string (e.g., "black,clamp") into
Expand Down
21 changes: 21 additions & 0 deletions src/libtexture/texoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ static const ustring wrap_type_name[] = {
ustring()
};

static const ustringhash wrap_type_hash[] = {
// MUST match the order of TextureOptions::Wrap
ustringhash("default"),
ustringhash("black"),
ustringhash("clamp"),
ustringhash("periodic"),
ustringhash("mirror"),
ustringhash("periodic_pow2"),
ustringhash("periodic_sharedborder"),
ustringhash()
};

} // end anonymous namespace


Expand Down Expand Up @@ -143,6 +155,15 @@ Tex::decode_wrapmode(ustring name)
return Tex::Wrap::Default;
}

Tex::Wrap
Tex::decode_wrapmode(ustringhash name)
{
for (int i = 0; i < (int)Tex::Wrap::Last; ++i)
if (name == wrap_type_hash[i])
return (Wrap)i;
return Tex::Wrap::Default;
}



void
Expand Down

0 comments on commit 6179658

Please sign in to comment.