Hash :
b31f532d
Author :
Date :
2011-01-19T19:02:52
All surfaces follow D3D Y convention, i.e. (0, 0) is "top-left" rather than GL's "bottom-left". This eliminates the need to flip the default FBO to the D3D convention using additional blits when presenting and reduces VRAM usage for redundant window sized surfaces. I took out the gl_Position.y flip from the vertex shader so FBOs are rendered according to D3D conventions. Texture lookups are flipped on Y to compensate. Cube map +Y and -Y faces are swapped. Y is now flipped in various other places, including uploading and reading back texture data from / to system memory, functions that take pixel space coordinates, winding order for culling, the implementation of ddy, the calculation of gl_Position and gl_FragCoord in fragment shaders and the flipping of compressed texture tiles. Review URL: http://codereview.appspot.com/3265041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@536 736b8ea6-26fd-11df-bfd4-992fa37f6226
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
//
// 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>
#include <windows.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 unsigned int ceilPow2(unsigned int x)
{
if (x != 0) x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
return x;
}
template<typename T, typename MIN, typename MAX>
inline T clamp(T x, MIN min, MAX max)
{
return x < min ? min : (x > max ? max : x);
}
inline float clamp01(float x)
{
return clamp(x, 0.0f, 1.0f);
}
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);
}
}
inline RECT transformPixelRect(GLint x, GLint y, GLint w, GLint h, GLint surfaceHeight)
{
RECT rect = {x,
surfaceHeight - y - h,
x + w,
surfaceHeight - y};
return rect;
}
inline int transformPixelYOffset(GLint yoffset, GLint h, GLint surfaceHeight)
{
return surfaceHeight - yoffset - h;
}
inline GLenum adjustWinding(GLenum winding)
{
ASSERT(winding == GL_CW || winding == GL_CCW);
return winding == GL_CW ? GL_CCW : GL_CW;
}
}
#endif // LIBGLESV2_MATHUTIL_H_