Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(73)

Side by Side Diff: src/libGLESv2/mathutil.h

Issue 3265041: All surfaces follow D3D Y convention (Closed) Base URL: http://angleproject.googlecode.com/svn/trunk/
Patch Set: '' Created 14 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 1 //
2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 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 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 // 5 //
6 6
7 // mathutil.h: Math and bit manipulation functions. 7 // mathutil.h: Math and bit manipulation functions.
8 8
9 #ifndef LIBGLESV2_MATHUTIL_H_ 9 #ifndef LIBGLESV2_MATHUTIL_H_
10 #define LIBGLESV2_MATHUTIL_H_ 10 #define LIBGLESV2_MATHUTIL_H_
11 11
12 #include <math.h> 12 #include <math.h>
13 #include <windows.h>
13 14
14 namespace gl 15 namespace gl
15 { 16 {
16 inline bool isPow2(int x) 17 inline bool isPow2(int x)
17 { 18 {
18 return (x & (x - 1)) == 0 && (x != 0); 19 return (x & (x - 1)) == 0 && (x != 0);
19 } 20 }
20 21
21 inline int log2(int x) 22 inline int log2(int x)
22 { 23 {
23 int r = 0; 24 int r = 0;
24 while ((x >> r) > 1) r++; 25 while ((x >> r) > 1) r++;
25 return r; 26 return r;
26 } 27 }
27 28
28 inline unsigned int ceilPow2(unsigned int x) 29 inline unsigned int ceilPow2(unsigned int x)
29 { 30 {
30 if (x != 0) x--; 31 if (x != 0) x--;
31 x |= x >> 1; 32 x |= x >> 1;
32 x |= x >> 2; 33 x |= x >> 2;
33 x |= x >> 4; 34 x |= x >> 4;
34 x |= x >> 8; 35 x |= x >> 8;
35 x |= x >> 16; 36 x |= x >> 16;
36 x++; 37 x++;
37 38
38 return x; 39 return x;
39 } 40 }
40 41
42 template<typename T, typename MIN, typename MAX>
dgkoch 2010/12/23 20:19:23 Do you really want to allow different types for mi
apatrick1 2011/01/07 23:40:22 int min = 0; LONG max = 1; clamp(0.5, min, max);
dgkoch 2011/01/11 20:00:07 Fair enough. Can leave it then.
43 inline T clamp(T x, MIN min, MAX max)
44 {
45 return x < min ? min : (x > max ? max : x);
46 }
47
41 inline float clamp01(float x) 48 inline float clamp01(float x)
42 { 49 {
43 return x < 0 ? 0 : (x > 1 ? 1 : x); 50 return clamp(x, 0.0f, 1.0f);
44 } 51 }
45 52
46 template<const int n> 53 template<const int n>
47 inline unsigned int unorm(float x) 54 inline unsigned int unorm(float x)
48 { 55 {
49 const unsigned int max = 0xFFFFFFFF >> (32 - n); 56 const unsigned int max = 0xFFFFFFFF >> (32 - n);
50 57
51 if (x > 1) 58 if (x > 1)
52 { 59 {
53 return max; 60 return max;
54 } 61 }
55 else if (x < 0) 62 else if (x < 0)
56 { 63 {
57 return 0; 64 return 0;
58 } 65 }
59 else 66 else
60 { 67 {
61 return (unsigned int)(max * x + 0.5f); 68 return (unsigned int)(max * x + 0.5f);
62 } 69 }
63 } 70 }
71
72 inline RECT transformPixelRect(GLint x, GLint y, GLint w, GLint h, GLint surface Height)
73 {
74 RECT rect = {x,
75 surfaceHeight - y - h,
76 x + w,
77 surfaceHeight - y};
78 return rect;
79 }
80
81 inline int transformPixelYOffset(GLint yoffset, GLint h, GLint surfaceHeight)
82 {
83 return surfaceHeight - yoffset - h;
84 }
85
86 inline GLenum adjustWinding(GLenum winding)
87 {
88 ASSERT(winding == GL_CW || winding == GL_CCW);
89 return winding == GL_CW ? GL_CCW : GL_CW;
90 }
64 } 91 }
65 92
66 #endif // LIBGLESV2_MATHUTIL_H_ 93 #endif // LIBGLESV2_MATHUTIL_H_
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b