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 // PointSpriteTest.cpp: Tests basic usage of GLES1 point sprites.
8
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11
12 #include "util/random_utils.h"
13
14 #include <stdint.h>
15
16 using namespace angle;
17
18 class PointSpriteTest : public ANGLETest
19 {
20 protected:
PointSpriteTest()21 PointSpriteTest()
22 {
23 setWindowWidth(1);
24 setWindowHeight(1);
25 setConfigRedBits(8);
26 setConfigGreenBits(8);
27 setConfigBlueBits(8);
28 setConfigAlphaBits(8);
29 setConfigDepthBits(24);
30 }
31 };
32
33 // Checks that triangles are not treated as point sprites, and that cached state
34 // is properly invalidated when the primitive mode changes.
TEST_P(PointSpriteTest,TrianglesNotTreatedAsPointSprites)35 TEST_P(PointSpriteTest, TrianglesNotTreatedAsPointSprites)
36 {
37 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
38
39 glEnable(GL_POINT_SPRITE_OES);
40 glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);
41
42 glEnable(GL_TEXTURE_2D);
43
44 GLuint tex;
45 glGenTextures(1, &tex);
46 glBindTexture(GL_TEXTURE_2D, tex);
47
48 // A 3x3 texture where the top right corner is green. Rendered with
49 // triangles + texture coordinate 1,1 this is always green, but rendered as
50 // a point sprite, red will be used as we are using nearest filtering and we
51 // would be favoring only the red parts of the image in point coordinates.
52 GLubyte texture[] = {
53 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
54 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
55 };
56
57 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
58 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 3, 3, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
59 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
63
64 // The first coordinate, 0.9f 0.9f should be sufficiently shifted to the right
65 // that the green part of the point sprite is hidden.
66 std::vector<float> mPositions = {
67 0.9f, 0.9f, -0.9f, 0.9f, 0.9f, -0.9f,
68 };
69
70 glEnableClientState(GL_VERTEX_ARRAY);
71 glMultiTexCoord4f(GL_TEXTURE0, 1.0f, 1.0f, 0.0f, 0.0f);
72 glVertexPointer(2, GL_FLOAT, 0, mPositions.data());
73
74 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
75
76 glDrawArrays(GL_TRIANGLES, 0, 3);
77
78 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
79
80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
81
82 glDrawArrays(GL_POINTS, 0, 1);
83
84 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
85 }
86
87 ANGLE_INSTANTIATE_TEST_ES1(PointSpriteTest);
88