summaryrefslogtreecommitdiff
path: root/tests/java_api/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp.rscript
blob: 28b00bdcf1909dbce65d5fcb2bc06cf38f3f7f25 (plain)
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
#include "shared.rsh"

static bool test_clamp_vector() {
    bool failed = false;

    float2 src2 = { 2.0f, 2.0f};
    float2 min2 = { 0.5f, -3.0f};
    float2 max2 = { 1.0f, 9.0f};

    float2 res2 = clamp(src2, min2, max2);
    _RS_ASSERT(res2.x == 1.0f);
    _RS_ASSERT(res2.y == 2.0f);


    float3 src3 = { 2.0f, 2.0f, 1.0f};
    float3 min3 = { 0.5f, -3.0f, 3.0f};
    float3 max3 = { 1.0f, 9.0f, 4.0f};

    float3 res3 = clamp(src3, min3, max3);
    _RS_ASSERT(res3.x == 1.0f);
    _RS_ASSERT(res3.y == 2.0f);
    _RS_ASSERT(res3.z == 3.0f);


    float4 src4 = { 2.0f, 2.0f, 1.0f, 4.0f };
    float4 min4 = { 0.5f, -3.0f, 3.0f, 4.0f };
    float4 max4 = { 1.0f, 9.0f, 4.0f, 4.0f };

    float4 res4 = clamp(src4, min4, max4);
    _RS_ASSERT(res4.x == 1.0f);
    _RS_ASSERT(res4.y == 2.0f);
    _RS_ASSERT(res4.z == 3.0f);
    _RS_ASSERT(res4.w == 4.0f);

    if (failed) {
        rsDebug("test_clamp_vector FAILED", 0);
    }
    else {
        rsDebug("test_clamp_vector PASSED", 0);
    }

    return failed;
}

void clamp_test() {
    bool failed = false;
    failed |= test_clamp_vector();

    if (failed) {
        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
    }
    else {
        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
    }
}