gbm: Create a gbm_device getter for stride
[mesa.git] / src / mesa / program / prog_noise.c
index 1713ddb5f344dfe870e963ffa579a042000cc47d..e2e209e5bd3b58202ff9805ab43a03acb5b40845 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
  *
  * Copyright (C) 2006  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /*
@@ -76,7 +76,7 @@
  * A vector-valued noise over 3D accesses it 96 times, and a
  * float-valued 4D noise 64 times. We want this to fit in the cache!
  */
-unsigned char perm[512] = { 151, 160, 137, 91, 90, 15,
+static const unsigned char perm[512] = { 151, 160, 137, 91, 90, 15,
    131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8,
       99, 37, 240, 21, 10, 23,
    190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35,
@@ -188,7 +188,7 @@ grad4(int hash, float x, float y, float z, float t)
  * Details can be found where this table is used, in the 4D noise method.
  * TODO: This should not be required, backport it from Bill's GLSL code!
  */
-static unsigned char simplex[64][4] = {
+static const unsigned char simplex[64][4] = {
    {0, 1, 2, 3}, {0, 1, 3, 2}, {0, 0, 0, 0}, {0, 2, 3, 1},
    {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 2, 3, 0},
    {0, 2, 1, 3}, {0, 0, 0, 0}, {0, 3, 1, 2}, {0, 3, 2, 1},
@@ -257,12 +257,12 @@ _mesa_noise2(GLfloat x, GLfloat y)
    float y0 = y - Y0;
 
    float x1, y1, x2, y2;
-   int ii, jj;
+   unsigned int ii, jj;
    float t0, t1, t2;
 
    /* For the 2D case, the simplex shape is an equilateral triangle. */
    /* Determine which simplex we are in. */
-   int i1, j1;                  /* Offsets for second (middle) corner of simplex in (i,j) coords */
+   unsigned int i1, j1;         /* Offsets for second (middle) corner of simplex in (i,j) coords */
    if (x0 > y0) {
       i1 = 1;
       j1 = 0;
@@ -282,8 +282,8 @@ _mesa_noise2(GLfloat x, GLfloat y)
    y2 = y0 - 1.0f + 2.0f * G2;
 
    /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
-   ii = i % 256;
-   jj = j % 256;
+   ii = i & 0xff;
+   jj = j & 0xff;
 
    /* Calculate the contribution from the three corners */
    t0 = 0.5f - x0 * x0 - y0 * y0;
@@ -344,13 +344,13 @@ _mesa_noise3(GLfloat x, GLfloat y, GLfloat z)
    float z0 = z - Z0;
 
    float x1, y1, z1, x2, y2, z2, x3, y3, z3;
-   int ii, jj, kk;
+   unsigned int ii, jj, kk;
    float t0, t1, t2, t3;
 
    /* For the 3D case, the simplex shape is a slightly irregular tetrahedron. */
    /* Determine which simplex we are in. */
-   int i1, j1, k1;              /* Offsets for second corner of simplex in (i,j,k) coords */
-   int i2, j2, k2;              /* Offsets for third corner of simplex in (i,j,k) coords */
+   unsigned int i1, j1, k1;     /* Offsets for second corner of simplex in (i,j,k) coords */
+   unsigned int i2, j2, k2;     /* Offsets for third corner of simplex in (i,j,k) coords */
 
 /* This code would benefit from a backport from the GLSL version! */
    if (x0 >= y0) {
@@ -423,9 +423,9 @@ _mesa_noise3(GLfloat x, GLfloat y, GLfloat z)
    z3 = z0 - 1.0f + 3.0f * G3;
 
    /* Wrap the integer indices at 256 to avoid indexing perm[] out of bounds */
-   ii = i % 256;
-   jj = j % 256;
-   kk = k % 256;
+   ii = i & 0xff;
+   jj = j & 0xff;
+   kk = k & 0xff;
 
    /* Calculate the contribution from the four corners */
    t0 = 0.6f - x0 * x0 - y0 * y0 - z0 * z0;
@@ -522,12 +522,12 @@ _mesa_noise4(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    int c6 = (z0 > w0) ? 1 : 0;
    int c = c1 + c2 + c3 + c4 + c5 + c6;
 
-   int i1, j1, k1, l1;  /* The integer offsets for the second simplex corner */
-   int i2, j2, k2, l2;  /* The integer offsets for the third simplex corner */
-   int i3, j3, k3, l3;  /* The integer offsets for the fourth simplex corner */
+   unsigned int i1, j1, k1, l1;  /* The integer offsets for the second simplex corner */
+   unsigned int i2, j2, k2, l2;  /* The integer offsets for the third simplex corner */
+   unsigned int i3, j3, k3, l3;  /* The integer offsets for the fourth simplex corner */
 
    float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
-   int ii, jj, kk, ll;
+   unsigned int ii, jj, kk, ll;
    float t0, t1, t2, t3, t4;
 
    /*
@@ -573,10 +573,10 @@ _mesa_noise4(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
    w4 = w0 - 1.0f + 4.0f * G4;
 
    /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
-   ii = i % 256;
-   jj = j % 256;
-   kk = k % 256;
-   ll = l % 256;
+   ii = i & 0xff;
+   jj = j & 0xff;
+   kk = k & 0xff;
+   ll = l & 0xff;
 
    /* Calculate the contribution from the five corners */
    t0 = 0.6f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;