1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // CurrentTextureCoordsTest.cpp: Tests basic usage of glMultiTexCoord4(f|x).
8 
9 #include "test_utils/ANGLETest.h"
10 
11 #include "common/vector_utils.h"
12 #include "test_utils/gl_raii.h"
13 #include "util/random_utils.h"
14 
15 #include <array>
16 
17 #include <stdint.h>
18 
19 using namespace angle;
20 
21 using TextureCoord = std::array<float, 4>;
22 
23 class CurrentTextureCoordsTest : public ANGLETest
24 {
25   protected:
CurrentTextureCoordsTest()26     CurrentTextureCoordsTest()
27     {
28         setWindowWidth(32);
29         setWindowHeight(32);
30         setConfigRedBits(8);
31         setConfigGreenBits(8);
32         setConfigBlueBits(8);
33         setConfigAlphaBits(8);
34         setConfigDepthBits(24);
35     }
36 };
37 
38 // State query: Checks the initial state is correct.
TEST_P(CurrentTextureCoordsTest,InitialState)39 TEST_P(CurrentTextureCoordsTest, InitialState)
40 {
41     GLint maxUnits = 0;
42     glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxUnits);
43     EXPECT_GL_NO_ERROR();
44 
45     const TextureCoord kZero = {0.0f, 0.0f, 0.0f, 0.0f};
46     TextureCoord actualTexCoord;
47 
48     for (GLint i = 0; i < maxUnits; i++)
49     {
50         glActiveTexture(GL_TEXTURE0 + i);
51         EXPECT_GL_NO_ERROR();
52         glGetFloatv(GL_CURRENT_TEXTURE_COORDS, actualTexCoord.data());
53         EXPECT_GL_NO_ERROR();
54         EXPECT_EQ(kZero, actualTexCoord);
55     }
56 }
57 
58 // Checks that errors are generated if the texture unit specified is invalid.
TEST_P(CurrentTextureCoordsTest,Negative)59 TEST_P(CurrentTextureCoordsTest, Negative)
60 {
61     GLint maxUnits = 0;
62     glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxUnits);
63     EXPECT_GL_NO_ERROR();
64 
65     glMultiTexCoord4f(GL_TEXTURE0 - 1, 1.0f, 0.0f, 0.0f, 0.0f);
66     EXPECT_GL_ERROR(GL_INVALID_ENUM);
67 
68     glMultiTexCoord4f(GL_TEXTURE0 + maxUnits, 1.0f, 0.0f, 0.0f, 0.0f);
69     EXPECT_GL_ERROR(GL_INVALID_ENUM);
70 }
71 
72 // Tests setting and getting the current texture coordinates for each unit and with float/fixed
73 // inputs.
TEST_P(CurrentTextureCoordsTest,Set)74 TEST_P(CurrentTextureCoordsTest, Set)
75 {
76     float epsilon  = 0.00001f;
77     GLint maxUnits = 0;
78     glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxUnits);
79     EXPECT_GL_NO_ERROR();
80 
81     TextureCoord actualTexCoord;
82 
83     for (int i = 0; i < maxUnits; i++)
84     {
85         glActiveTexture(GL_TEXTURE0 + i);
86         glMultiTexCoord4f(GL_TEXTURE0 + i, 0.1f, 0.2f, 0.3f, 0.4f);
87         glGetFloatv(GL_CURRENT_TEXTURE_COORDS, actualTexCoord.data());
88         EXPECT_EQ((TextureCoord{0.1f, 0.2f, 0.3f, 0.4f}), actualTexCoord);
89 
90         glMultiTexCoord4x(GL_TEXTURE0 + i, 0x10000, 0x0, 0x3333, 0x5555);
91         glGetFloatv(GL_CURRENT_TEXTURE_COORDS, actualTexCoord.data());
92         EXPECT_NEAR(1.0f, actualTexCoord[0], epsilon);
93         EXPECT_NEAR(0.0f, actualTexCoord[1], epsilon);
94         EXPECT_NEAR(0.2f, actualTexCoord[2], epsilon);
95         EXPECT_NEAR(1.0f / 3.0f, actualTexCoord[3], epsilon);
96     }
97 }
98 
99 ANGLE_INSTANTIATE_TEST_ES1(CurrentTextureCoordsTest);
100