OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 ** Copyright (c) 2012 The Khronos Group Inc. |
| 4 ** |
| 5 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 6 ** copy of this software and/or associated documentation files (the |
| 7 ** "Materials"), to deal in the Materials without restriction, including |
| 8 ** without limitation the rights to use, copy, modify, merge, publish, |
| 9 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 10 ** permit persons to whom the Materials are furnished to do so, subject to |
| 11 ** the following conditions: |
| 12 ** |
| 13 ** The above copyright notice and this permission notice shall be included |
| 14 ** in all copies or substantial portions of the Materials. |
| 15 ** |
| 16 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 20 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 23 */ |
| 24 |
| 25 |
| 26 #ifdef GL_ES |
| 27 precision mediump float; |
| 28 #endif |
| 29 |
| 30 /* This epsilon will work as long as the magnitude of the float is < 128. |
| 31 * This can be seen by taking the spec relative mediump precision of 2^-10: |
| 32 * 0.125 / 2^-10 = 128 |
| 33 */ |
| 34 #define ERROR_EPSILON (0.125) |
| 35 |
| 36 void main (void) |
| 37 { |
| 38 float x; |
| 39 // Declare a constant 4 by 4 matrix with unique elements. |
| 40 mat4 a = mat4( 1.0, 2.0, 3.0, 4.0, |
| 41 5.0, 6.0, 7.0, 8.0, |
| 42 9.0, 10.0, 11.0, 12.0, |
| 43 13.0, 14.0, 15.0, 16.0); |
| 44 |
| 45 // Copy the matrix to another non-const matrix. |
| 46 mat4 b = a; |
| 47 |
| 48 // Check each element of the copy. |
| 49 bool elms = true; |
| 50 if(b[0][0] != 1.0) elms = false; |
| 51 if(b[0][1] != 2.0) elms = false; |
| 52 if(b[0][2] != 3.0) elms = false; |
| 53 if(b[0][3] != 4.0) elms = false; |
| 54 if(b[1][0] != 5.0) elms = false; |
| 55 if(b[1][1] != 6.0) elms = false; |
| 56 if(b[1][2] != 7.0) elms = false; |
| 57 if(b[1][3] != 8.0) elms = false; |
| 58 if(b[2][0] != 9.0) elms = false; |
| 59 if(b[2][1] != 10.0) elms = false; |
| 60 if(b[2][2] != 11.0) elms = false; |
| 61 if(b[2][3] != 12.0) elms = false; |
| 62 if(b[3][0] != 13.0) elms = false; |
| 63 if(b[3][1] != 14.0) elms = false; |
| 64 if(b[3][2] != 15.0) elms = false; |
| 65 if(b[3][3] != 16.0) elms = false; |
| 66 |
| 67 // Add up each row of the copy. |
| 68 bool rows = true; |
| 69 x = b[0][0] + b[1][0] + b[2][0] + b[3][0]; |
| 70 if(x < 28.0-ERROR_EPSILON || x > 28.0+ERROR_EPSILON) rows = false; |
| 71 x = b[0][1] + b[1][1] + b[2][1] + b[3][1]; |
| 72 if(x < 32.0-ERROR_EPSILON || x > 32.0+ERROR_EPSILON) rows = false; |
| 73 x = b[0][2] + b[1][2] + b[2][2] + b[3][2]; |
| 74 if(x < 36.0-ERROR_EPSILON || x > 36.0+ERROR_EPSILON) rows = false; |
| 75 x = b[0][3] + b[1][3] + b[2][3] + b[3][3]; |
| 76 if(x < 40.0-ERROR_EPSILON || x > 40.0+ERROR_EPSILON) rows = false; |
| 77 |
| 78 // Add up each column of the copy. |
| 79 bool cols = true; |
| 80 x = b[0][0] + b[0][1] + b[0][2] + b[0][3]; |
| 81 if(x < 10.0-ERROR_EPSILON || x > 10.0+ERROR_EPSILON) cols = false; |
| 82 x = b[1][0] + b[1][1] + b[1][2] + b[1][3]; |
| 83 if(x < 26.0-ERROR_EPSILON || x > 26.0+ERROR_EPSILON) cols = false; |
| 84 x = b[2][0] + b[2][1] + b[2][2] + b[2][3]; |
| 85 if(x < 42.0-ERROR_EPSILON || x > 42.0+ERROR_EPSILON) cols = false; |
| 86 x = b[3][0] + b[3][1] + b[3][2] + b[3][3]; |
| 87 if(x < 58.0-ERROR_EPSILON || x > 58.0+ERROR_EPSILON) cols = false; |
| 88 |
| 89 // Check if all of the operations were successful. |
| 90 float gray = elms && rows && cols ? 1.0 : 0.0; |
| 91 |
| 92 // Assign the fragment color. |
| 93 gl_FragColor = vec4(gray, gray, gray, 1.0); |
| 94 } |
| 95 |
OLD | NEW |