~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/libGLESv2/mathutil.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
 
3
// Use of this source code is governed by a BSD-style license that can be
 
4
// found in the LICENSE file.
 
5
//
 
6
 
 
7
// mathutil.h: Math and bit manipulation functions.
 
8
 
 
9
#ifndef LIBGLESV2_MATHUTIL_H_
 
10
#define LIBGLESV2_MATHUTIL_H_
 
11
 
 
12
#include <intrin.h>
 
13
#include <math.h>
 
14
#include <windows.h>
 
15
 
 
16
namespace gl
 
17
{
 
18
inline bool isPow2(int x)
 
19
{
 
20
    return (x & (x - 1)) == 0 && (x != 0);
 
21
}
 
22
 
 
23
inline int log2(int x)
 
24
{
 
25
    int r = 0;
 
26
    while ((x >> r) > 1) r++;
 
27
    return r;
 
28
}
 
29
 
 
30
inline unsigned int ceilPow2(unsigned int x)
 
31
{
 
32
    if (x != 0) x--;
 
33
    x |= x >> 1;
 
34
    x |= x >> 2;
 
35
    x |= x >> 4;
 
36
    x |= x >> 8;
 
37
    x |= x >> 16;
 
38
    x++;
 
39
 
 
40
    return x;
 
41
}
 
42
 
 
43
template<typename T, typename MIN, typename MAX>
 
44
inline T clamp(T x, MIN min, MAX max)
 
45
{
 
46
    return x < min ? min : (x > max ? max : x);
 
47
}
 
48
 
 
49
inline float clamp01(float x)
 
50
{
 
51
    return clamp(x, 0.0f, 1.0f);
 
52
}
 
53
 
 
54
template<const int n>
 
55
inline unsigned int unorm(float x)
 
56
{
 
57
    const unsigned int max = 0xFFFFFFFF >> (32 - n);
 
58
 
 
59
    if (x > 1)
 
60
    {
 
61
        return max;
 
62
    }
 
63
    else if (x < 0)
 
64
    {
 
65
        return 0;
 
66
    }
 
67
    else
 
68
    {
 
69
        return (unsigned int)(max * x + 0.5f);
 
70
    }
 
71
}
 
72
 
 
73
inline bool supportsSSE2()
 
74
{
 
75
    static bool checked = false;
 
76
    static bool supports = false;
 
77
 
 
78
    if (checked)
 
79
    {
 
80
        return supports;
 
81
    }
 
82
 
 
83
    int info[4];
 
84
    __cpuid(info, 0);
 
85
    
 
86
    if (info[0] >= 1)
 
87
    {
 
88
        __cpuid(info, 1);
 
89
 
 
90
        supports = (info[3] >> 26) & 1;
 
91
    }
 
92
 
 
93
    checked = true;
 
94
 
 
95
    return supports;
 
96
}
 
97
}
 
98
 
 
99
#endif   // LIBGLESV2_MATHUTIL_H_