• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // MatrixLoadTest.cpp: Tests basic usage of glColor4(f|ub|x).
8 
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11 
12 #include "common/matrix_utils.h"
13 #include "util/random_utils.h"
14 
15 #include <stdint.h>
16 
17 using namespace angle;
18 
19 class MatrixLoadTest : public ANGLETest
20 {
21   protected:
MatrixLoadTest()22     MatrixLoadTest()
23     {
24         setWindowWidth(32);
25         setWindowHeight(32);
26         setConfigRedBits(8);
27         setConfigGreenBits(8);
28         setConfigBlueBits(8);
29         setConfigAlphaBits(8);
30         setConfigDepthBits(24);
31     }
32 };
33 
34 // Checks that a matrix can be loaded.
TEST_P(MatrixLoadTest,Basic)35 TEST_P(MatrixLoadTest, Basic)
36 {
37     angle::Mat4 testMatrix(0.0f, 4.0f, 8.0f, 12.0f, 1.0f, 5.0f, 9.0f, 10.0f, 2.0f, 6.0f, 10.0f,
38                            14.0f, 3.0f, 7.0f, 11.0f, 15.0f);
39 
40     angle::Mat4 outputMatrix;
41 
42     glLoadMatrixf(testMatrix.data());
43     EXPECT_GL_NO_ERROR();
44 
45     glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
46     EXPECT_GL_NO_ERROR();
47 
48     EXPECT_EQ(testMatrix, outputMatrix);
49 }
50 
51 // Checks that loading a matrix doesn't affect the matrix below in the stack.
TEST_P(MatrixLoadTest,PushPop)52 TEST_P(MatrixLoadTest, PushPop)
53 {
54     glPushMatrix();
55 
56     angle::Mat4 testMatrix(0.0f, 4.0f, 8.0f, 12.0f, 1.0f, 5.0f, 9.0f, 10.0f, 2.0f, 6.0f, 10.0f,
57                            14.0f, 3.0f, 7.0f, 11.0f, 15.0f);
58 
59     angle::Mat4 outputMatrix;
60 
61     glLoadMatrixf(testMatrix.data());
62     EXPECT_GL_NO_ERROR();
63 
64     glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
65     EXPECT_GL_NO_ERROR();
66 
67     EXPECT_EQ(testMatrix, outputMatrix);
68 
69     glPopMatrix();
70 
71     glGetFloatv(GL_MODELVIEW_MATRIX, outputMatrix.data());
72     EXPECT_GL_NO_ERROR();
73     EXPECT_EQ(angle::Mat4(), outputMatrix);
74 }
75 
76 // Checks that matrices can be loaded for each type of matrix.
TEST_P(MatrixLoadTest,Modes)77 TEST_P(MatrixLoadTest, Modes)
78 {
79     angle::Mat4 testMatrix(0.0f, 4.0f, 8.0f, 12.0f, 1.0f, 5.0f, 9.0f, 10.0f, 2.0f, 6.0f, 10.0f,
80                            14.0f, 3.0f, 7.0f, 11.0f, 15.0f);
81     angle::Mat4 outputMatrix;
82 
83     std::vector<std::pair<GLenum, GLenum>> modeTypes = {{GL_PROJECTION, GL_PROJECTION_MATRIX},
84                                                         {GL_MODELVIEW, GL_MODELVIEW_MATRIX},
85                                                         {GL_TEXTURE, GL_TEXTURE_MATRIX}};
86 
87     for (auto modeType : modeTypes)
88     {
89         auto mode       = modeType.first;
90         auto matrixType = modeType.second;
91 
92         glMatrixMode(mode);
93         EXPECT_GL_NO_ERROR();
94         glGetFloatv(matrixType, outputMatrix.data());
95         EXPECT_GL_NO_ERROR();
96         EXPECT_EQ(angle::Mat4(), outputMatrix);
97 
98         glLoadMatrixf(testMatrix.data());
99         glGetFloatv(matrixType, outputMatrix.data());
100         EXPECT_GL_NO_ERROR();
101         EXPECT_EQ(testMatrix, outputMatrix);
102     }
103 }
104 
105 ANGLE_INSTANTIATE_TEST_ES1(MatrixLoadTest);
106