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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "test_utils/ANGLETest.h"
using namespace angle;
class PBOExtensionTest : public ANGLETest
{
protected:
PBOExtensionTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
virtual void SetUp()
{
ANGLETest::SetUp();
if (extensionEnabled("NV_pixel_buffer_object"))
{
glGenBuffers(1, &mPBO);
glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
glBufferData(GL_PIXEL_PACK_BUFFER, 4 * getWindowWidth() * getWindowHeight(), NULL, GL_STATIC_DRAW);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
const char *vertexShaderSrc = SHADER_SOURCE
(
attribute vec4 aTest;
attribute vec2 aPosition;
varying vec4 vTest;
void main()
{
vTest = aTest;
gl_Position = vec4(aPosition, 0.0, 1.0);
gl_PointSize = 1.0;
}
);
const char *fragmentShaderSrc = SHADER_SOURCE
(
precision mediump float;
varying vec4 vTest;
void main()
{
gl_FragColor = vTest;
}
);
mProgram = CompileProgram(vertexShaderSrc, fragmentShaderSrc);
glGenBuffers(1, &mPositionVBO);
glBindBuffer(GL_ARRAY_BUFFER, mPositionVBO);
glBufferData(GL_ARRAY_BUFFER, 128, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
ASSERT_GL_NO_ERROR();
}
virtual void TearDown()
{
ANGLETest::TearDown();
glDeleteBuffers(1, &mPBO);
glDeleteProgram(mProgram);
}
GLuint mPBO;
GLuint mProgram;
GLuint mPositionVBO;
};
TEST_P(PBOExtensionTest, PBOWithOtherTarget)
{
if (extensionEnabled("NV_pixel_buffer_object"))
{
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_GL_NO_ERROR();
glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, mPBO);
GLvoid *mappedPtr = glMapBufferRangeEXT(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT);
unsigned char *dataPtr = static_cast<unsigned char *>(mappedPtr);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(255, dataPtr[0]);
EXPECT_EQ(0, dataPtr[1]);
EXPECT_EQ(0, dataPtr[2]);
EXPECT_EQ(255, dataPtr[3]);
glUnmapBufferOES(GL_ARRAY_BUFFER);
}
EXPECT_GL_NO_ERROR();
}
TEST_P(PBOExtensionTest, PBOWithExistingData)
{
if (extensionEnabled("NV_pixel_buffer_object"))
{
// Clear backbuffer to red
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_GL_NO_ERROR();
// Read 16x16 region from red backbuffer to PBO
glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0);
// Clear backbuffer to green
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_GL_NO_ERROR();
// Read 16x16 region from green backbuffer to PBO at offset 16
glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(16));
GLvoid * mappedPtr = glMapBufferRangeEXT(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT);
unsigned char *dataPtr = static_cast<unsigned char *>(mappedPtr);
EXPECT_GL_NO_ERROR();
// Test pixel 0 is red (existing data)
EXPECT_EQ(255, dataPtr[0]);
EXPECT_EQ(0, dataPtr[1]);
EXPECT_EQ(0, dataPtr[2]);
EXPECT_EQ(255, dataPtr[3]);
// Test pixel 16 is green (new data)
EXPECT_EQ(0, dataPtr[16 * 4 + 0]);
EXPECT_EQ(255, dataPtr[16 * 4 + 1]);
EXPECT_EQ(0, dataPtr[16 * 4 + 2]);
EXPECT_EQ(255, dataPtr[16 * 4 + 3]);
glUnmapBufferOES(GL_PIXEL_PACK_BUFFER);
}
EXPECT_GL_NO_ERROR();
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(PBOExtensionTest, ES2_D3D11(), ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
|