Edit

kc3-lang/angle/libGLESv2/mathutil.h

Branch :

  • Show log

    Commit

  • Author : daniel@transgaming.com
    Date : 2010-03-11 19:22:14
    Hash : e2b22129
    Message : Whitespace fixes. TRAC #11024 Signed-off-by: Daniel Koch Author: Andrew Lewycky <andrew.lewycky@transgaming.com> git-svn-id: https://angleproject.googlecode.com/svn/trunk@9 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • libGLESv2/mathutil.h
  • //
    // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    // mathutil.h: Math and bit manipulation functions.
    
    #ifndef LIBGLESV2_MATHUTIL_H_
    #define LIBGLESV2_MATHUTIL_H_
    
    #include <math.h>
    
    namespace gl
    {
    inline bool isPow2(int x)
    {
        return (x & (x - 1)) == 0 && (x != 0);
    }
    
    inline int log2(int x)
    {
        int r = 0;
        while ((x >> r) > 1) r++;
        return r;
    }
    
    inline float clamp01(float x)
    {
        return x < 0 ? 0 : (x > 1 ? 1 : x);
    }
    
    template<const int n>
    inline unsigned int unorm(float x)
    {
        const unsigned int max = 0xFFFFFFFF >> (32 - n);
    
        if (x > 1)
        {
            return max;
        }
        else if (x < 0)
        {
            return 0;
        }
        else
        {
            return (unsigned int)(max * x + 0.5f);
        }
    }
    }
    
    #endif   // LIBGLESV2_MATHUTIL_H_