Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/test_utils/draw_call_perf_utils.cpp
1693 views
1
//
2
// Copyright 2017 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
// draw_call_perf_utils.cpp:
7
// Common utilities for performance tests that need to do a large amount of draw calls.
8
//
9
10
#include "draw_call_perf_utils.h"
11
12
#include <vector>
13
14
#include "util/shader_utils.h"
15
16
namespace
17
{
18
constexpr char kSimpleScaleAndOffsetVS[] = R"(attribute vec2 vPosition;
19
uniform float uScale;
20
uniform float uOffset;
21
void main()
22
{
23
gl_Position = vec4(vPosition * vec2(uScale) + vec2(uOffset), 0, 1);
24
})";
25
26
constexpr char kSimpleDrawVS[] = R"(attribute vec2 vPosition;
27
const float scale = 0.5;
28
const float offset = -0.5;
29
30
void main()
31
{
32
gl_Position = vec4(vPosition * vec2(scale) + vec2(offset), 0, 1);
33
})";
34
35
constexpr char kSimpleTexCoordVS[] = R"(attribute vec2 vPosition;
36
varying vec2 texCoord;
37
void main()
38
{
39
gl_Position = vec4(vPosition, 0, 1);
40
texCoord = vPosition * 0.5 + vec2(0.5);
41
})";
42
43
constexpr char kSimpleFS[] = R"(precision mediump float;
44
void main()
45
{
46
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
47
})";
48
49
constexpr char kSimpleTextureFS[] = R"(precision mediump float;
50
varying vec2 texCoord;
51
uniform sampler2D tex;
52
void main()
53
{
54
gl_FragColor = texture2D(tex, texCoord);
55
})";
56
57
constexpr char kDoubleTextureFS[] = R"(precision mediump float;
58
varying vec2 texCoord;
59
uniform sampler2D tex1;
60
uniform sampler2D tex2;
61
void main()
62
{
63
gl_FragColor = texture2D(tex1, texCoord) + texture2D(tex2, texCoord);
64
})";
65
66
void Generate2DTriangleData(size_t numTris, std::vector<float> *floatData)
67
{
68
for (size_t triIndex = 0; triIndex < numTris; ++triIndex)
69
{
70
floatData->push_back(1.0f);
71
floatData->push_back(2.0f);
72
73
floatData->push_back(0.0f);
74
floatData->push_back(0.0f);
75
76
floatData->push_back(2.0f);
77
floatData->push_back(0.0f);
78
}
79
}
80
81
} // anonymous namespace
82
83
GLuint SetupSimpleScaleAndOffsetProgram()
84
{
85
GLuint program = CompileProgram(kSimpleScaleAndOffsetVS, kSimpleFS);
86
if (program == 0u)
87
{
88
return program;
89
}
90
91
// Use the program object
92
glUseProgram(program);
93
94
GLfloat scale = 0.5f;
95
GLfloat offset = -0.5f;
96
97
glUniform1f(glGetUniformLocation(program, "uScale"), scale);
98
glUniform1f(glGetUniformLocation(program, "uOffset"), offset);
99
return program;
100
}
101
102
GLuint SetupSimpleDrawProgram()
103
{
104
GLuint program = CompileProgram(kSimpleDrawVS, kSimpleFS);
105
if (program == 0u)
106
{
107
return program;
108
}
109
110
// Use the program object
111
glUseProgram(program);
112
113
return program;
114
}
115
116
GLuint SetupSimpleTextureProgram()
117
{
118
GLuint program = CompileProgram(kSimpleTexCoordVS, kSimpleTextureFS);
119
if (program == 0u)
120
{
121
return program;
122
}
123
124
// Use the program object
125
glUseProgram(program);
126
127
return program;
128
}
129
130
GLuint SetupDoubleTextureProgram()
131
{
132
GLuint program = CompileProgram(kSimpleTexCoordVS, kDoubleTextureFS);
133
if (program == 0u)
134
{
135
return program;
136
}
137
138
// Use the program object
139
glUseProgram(program);
140
141
return program;
142
}
143
144
GLuint Create2DTriangleBuffer(size_t numTris, GLenum usage)
145
{
146
GLuint buffer = 0u;
147
glGenBuffers(1, &buffer);
148
glBindBuffer(GL_ARRAY_BUFFER, buffer);
149
150
std::vector<GLfloat> floatData;
151
Generate2DTriangleData(numTris, &floatData);
152
153
// To avoid generating GL errors when testing validation-only with zero triangles.
154
if (floatData.empty())
155
{
156
floatData.push_back(0.0f);
157
}
158
159
glBufferData(GL_ARRAY_BUFFER, floatData.size() * sizeof(GLfloat), &floatData[0], usage);
160
161
return buffer;
162
}
163
164
void CreateColorFBO(GLsizei width, GLsizei height, GLuint *fbo, GLuint *texture)
165
{
166
glGenFramebuffers(1, fbo);
167
glBindFramebuffer(GL_FRAMEBUFFER, *fbo);
168
glGenTextures(1, texture);
169
glBindTexture(GL_TEXTURE_2D, *texture);
170
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
171
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *texture, 0);
172
}
173
174