1# [description] 2# Verify that gl_ClipDistance works properly when used as a function 3# "inout" parameter. 4# 5# This test initializes gl_ClipDistance with the negative of the 6# desired clipping values, then calls a function which negates each 7# element of the array. 8# 9# Then it checks two things: 10# - That the desired values wound up in gl_ClipDistance 11# - That clipping occurred as expected 12# 13# To check that clipping occurred as expected, the 8 gl_ClipDistance 14# values are used to clip a rectangle to an octagon shape. 15# 16# The octagon is centered at (0.5, 0.5), and has a small radius 17# (distance from center to perpendicular edge) of 0.4. 18 19[require] 20GLSL >= 1.30 21 22[vertex shader] 23#version 130 24 25out float gl_ClipDistance[8]; 26 27void foo(inout float clip_distance[8]) 28{ 29 for (int i = 0; i < 8; ++i) { 30 clip_distance[i] = -clip_distance[i]; 31 } 32} 33 34void main(void) 35{ 36 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 37 38 // Compute 2D cordinates relative to a center point of (0.5, 39 // 0.5). 40 vec2 coord = gl_Vertex.xy - vec2(0.5, 0.5); 41 42 float desired_values[8]; 43 44 for (int i = 0; i < 8; ++i) { 45 // Compute a unit vector in the direction i*45deg from 46 // the x axis. 47 float angle = i*(3.141592653589793/4); 48 vec2 u = vec2(cos(angle), sin(angle)); 49 50 // Reject points whose 2D coordinate, projected onto 51 // that unit vector, is greater than 0.4. 52 desired_values[i] = 0.4 - dot(u, coord); 53 gl_ClipDistance[i] = -desired_values[i]; 54 } 55 56 foo(gl_ClipDistance); 57 58 for (int i = 0; i < 8; ++i) { 59 if (desired_values[i] != gl_ClipDistance[i]) { 60 gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0); 61 return; 62 } 63 } 64 gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0); 65} 66 67[fragment shader] 68#version 130 69void main(void) 70{ 71 gl_FragColor = gl_Color; 72} 73 74[test] 75clear color 0.0 0.0 0.0 0.0 76clear 77ortho 0 1 0 1 78enable GL_CLIP_PLANE0 79enable GL_CLIP_PLANE1 80enable GL_CLIP_PLANE2 81enable GL_CLIP_PLANE3 82enable GL_CLIP_PLANE4 83enable GL_CLIP_PLANE5 84enable GL_CLIP_PLANE6 85enable GL_CLIP_PLANE7 86draw rect 0.0 0.0 1.0 1.0 87 88# Test points inside each octagon edge 89relative probe rgba (0.850, 0.500) (0.0, 1.0, 0.0, 1.0) 90relative probe rgba (0.747, 0.747) (0.0, 1.0, 0.0, 1.0) 91relative probe rgba (0.500, 0.850) (0.0, 1.0, 0.0, 1.0) 92relative probe rgba (0.253, 0.747) (0.0, 1.0, 0.0, 1.0) 93relative probe rgba (0.150, 0.500) (0.0, 1.0, 0.0, 1.0) 94relative probe rgba (0.253, 0.253) (0.0, 1.0, 0.0, 1.0) 95relative probe rgba (0.500, 0.150) (0.0, 1.0, 0.0, 1.0) 96relative probe rgba (0.747, 0.253) (0.0, 1.0, 0.0, 1.0) 97 98# Test points outside each octagon edge 99relative probe rgba (0.950, 0.500) (0.0, 0.0, 0.0, 0.0) 100relative probe rgba (0.818, 0.818) (0.0, 0.0, 0.0, 0.0) 101relative probe rgba (0.500, 0.950) (0.0, 0.0, 0.0, 0.0) 102relative probe rgba (0.182, 0.818) (0.0, 0.0, 0.0, 0.0) 103relative probe rgba (0.050, 0.500) (0.0, 0.0, 0.0, 0.0) 104relative probe rgba (0.182, 0.182) (0.0, 0.0, 0.0, 0.0) 105relative probe rgba (0.500, 0.050) (0.0, 0.0, 0.0, 0.0) 106relative probe rgba (0.818, 0.182) (0.0, 0.0, 0.0, 0.0) 107