Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed rgb9e5 and rg11b10 packing/unpacking #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions external/glm/gtc/packing.inl
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ namespace detail

GLM_FUNC_QUALIFIER glm::uint floatTo11bit(float x)
{
if(x == 0.0f)
if(x <= 0.0f) // 11bit floats have no sign (clamp to 0)
return 0u;
else if(glm::isnan(x))
return ~0u;
else if(glm::isinf(x))
return 0x1Fu << 6u;
return ~0u; // signaling nan
else if(glm::isinf(x) || x > 65024.0f)
return 0x1Fu << 6u; // infinity

uint Pack = 0u;
memcpy(&Pack, &x, sizeof(Pack));
Expand All @@ -130,12 +130,12 @@ namespace detail

GLM_FUNC_QUALIFIER float packed11bitToFloat(glm::uint x)
{
if(x == 0)
if(x == 0u)
return 0.0f;
else if(x == ((1 << 11) - 1))
return ~0;//NaN
return std::numeric_limits<float>::signaling_NaN();//NaN
else if(x == (0x1f << 6))
return ~0;//Inf
return std::numeric_limits<float>::infinity();//Inf

uint Result = packed11ToFloat(x);

Expand All @@ -146,12 +146,12 @@ namespace detail

GLM_FUNC_QUALIFIER glm::uint floatTo10bit(float x)
{
if(x == 0.0f)
if(x <= 0.0f) // 10bit floats have no sign (clamp to 0)
return 0u;
else if(glm::isnan(x))
return ~0u;
else if(glm::isinf(x))
return 0x1Fu << 5u;
return ~0u; // signaling nan
else if(glm::isinf(x) || x > 64512.0f) // infinity or bigger than representable value
return 0x1Fu << 5u; // infinity

uint Pack = 0;
memcpy(&Pack, &x, sizeof(Pack));
Expand All @@ -163,9 +163,9 @@ namespace detail
if(x == 0)
return 0.0f;
else if(x == ((1 << 10) - 1))
return ~0;//NaN
return std::numeric_limits<float>::signaling_NaN();//NaN
else if(x == (0x1f << 5))
return ~0;//Inf
return std::numeric_limits<float>::infinity();//Inf

uint Result = packed10ToFloat(x);

Expand Down Expand Up @@ -607,14 +607,15 @@ namespace detail
GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 v)
{
return vec3(
detail::packed11bitToFloat(v >> 0),
detail::packed11bitToFloat(v >> 11),
detail::packed10bitToFloat(v >> 22));
detail::packed11bitToFloat((v >> 0) & ((1 << 11) - 1)),
detail::packed11bitToFloat((v >> 11) & ((1 << 11) - 1)),
detail::packed10bitToFloat((v >> 22) & ((1 << 10) - 1)));
}

GLM_FUNC_QUALIFIER uint32 packF3x9_E1x5(vec3 const& v)
{
float const SharedExpMax = (pow(2.0f, 9.0f - 1.0f) / pow(2.0f, 9.0f)) * pow(2.0f, 31.f - 15.f);
//float const SharedExpMax = ((pow(2.0f, 9.0f) - 1.0f) / pow(2.0f, 9.0f)) * pow(2.0f, 31.f - 15.f);
float const SharedExpMax = 65408.0f;
vec3 const Color = clamp(v, 0.0f, SharedExpMax);
float const MaxColor = max(Color.x, max(Color.y, Color.z));

Expand Down