File: gl_parameter_zoo.cpp

package info (click to toggle)
renderdoc 1.24%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 105,156 kB
  • sloc: cpp: 759,405; ansic: 309,460; python: 26,606; xml: 22,599; java: 11,365; cs: 7,181; makefile: 6,707; yacc: 5,682; ruby: 4,648; perl: 3,461; sh: 2,354; php: 2,119; lisp: 1,835; javascript: 1,524; tcl: 1,068; ml: 747
file content (259 lines) | stat: -rw-r--r-- 7,490 bytes parent folder | download
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/******************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2019-2022 Baldur Karlsson
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/

#include "gl_test.h"

#ifdef WIN64
extern "C" __declspec(dllexport) GLenum APIENTRY InternalFunction()
{
  return GL_QUERY_BUFFER;
}
#endif

RD_TEST(GL_Parameter_Zoo, OpenGLGraphicsTest)
{
  static constexpr const char *Description =
      "General tests of parameters known to cause problems - e.g. optional values that should be "
      "ignored, edge cases, special values, etc.";

  const char *vertex = R"EOSHADER(
#version 450 core

layout(location = 0) in vec3 Position;
layout(location = 1) in vec4 Color;
layout(location = 2) in vec2 UV;

uniform int mode;

out vec4 v2fcol;

void main()
{
	gl_Position = vec4(Position.xyz * (mode == 1 ? 5.0f : 1.0f), 1);
	v2fcol = Color;
}

!!!!)EOSHADER";

  const char *pixel = R"EOSHADER(
#version 450 core

in vec4 v2fcol;

layout(location = 0, index = 0) out vec4 Color;
uniform int mode;

void main()
{
  if(mode == 1)
    Color = vec4(0, 0, 1, 0.5);
  else
	  Color = v2fcol;
}

)EOSHADER";

  int main()
  {
    // don't use core profile so that we can check glGetString(GL_EXTENSIONS)
    coreProfile = false;

    // initialise, create window, create context, etc
    if(!Init())
      return 3;

    std::vector<std::string> exts;

    GLint num = 0;
    glGetIntegerv(GL_NUM_EXTENSIONS, &num);
    exts.resize(num);
    for(GLint i = 0; i < num; i++)
      exts[i] = (const char *)glGetStringi(GL_EXTENSIONS, i);

    std::string ext_string = (const char *)glGetString(GL_EXTENSIONS);

    std::vector<std::string> exts_split;
    while(!ext_string.empty())
    {
      std::string e = ext_string.substr(0, ext_string.find(' '));
      ext_string.erase(0, e.length() + 1);
      exts_split.push_back(e);
    }

    std::sort(exts_split.begin(), exts_split.end());
    std::sort(exts.begin(), exts.end());

    if(exts != exts_split)
    {
      TEST_ERROR("Extension string from glGetString doesn't match glGetStringi extensions");
      return 4;
    }

    if(std::unique(exts.begin(), exts.end()) != exts.end())
    {
      TEST_ERROR("Extensions from glGetStringi contains duplicates");
      return 5;
    }

    if(std::unique(exts_split.begin(), exts_split.end()) != exts_split.end())
    {
      TEST_ERROR("Extension string from glGetString contains duplicates");
      return 5;
    }

    GLuint trashvao = MakeVAO();
    glBindVertexArray(trashvao);

    GLuint vao = MakeVAO();
    glBindVertexArray(vao);

    GLuint vb = MakeBuffer();
    glBindBuffer(GL_ARRAY_BUFFER, vb);
    glBufferStorage(GL_ARRAY_BUFFER, sizeof(DefaultTri), DefaultTri, 0);

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0));
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f)));
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V),
                          (void *)(sizeof(Vec3f) + sizeof(Vec4f)));

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);

    GLuint program = MakeProgram();

    GLint len = (int)strlen(vertex) - 5;

    GLuint vs = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vs, 1, &vertex, &len);
    glCompileShader(vs);

    GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fs, 1, &pixel, NULL);
    glCompileShader(fs);

    glAttachShader(program, vs);
    glAttachShader(program, fs);
    glLinkProgram(program);
    glDetachShader(program, vs);
    glDetachShader(program, fs);

    glDeleteShader(vs);
    glDeleteShader(fs);

    GLuint trash = MakeBuffer();
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, trash);
    glBufferStorage(GL_PIXEL_UNPACK_BUFFER, 1024, 0, 0);
    glBindBuffer(GL_PIXEL_PACK_BUFFER, trash);

    if(GLAD_GL_ARB_query_buffer_object)
      glBindBuffer(GL_QUERY_BUFFER, trash);

#if defined(WIN64)
    PFNGLGETERRORPROC internalFunc =
        (PFNGLGETERRORPROC)GetProcAddress(GetModuleHandleA(NULL), "InternalFunction");

    if(internalFunc == NULL || internalFunc() != GL_QUERY_BUFFER)
    {
      TEST_ERROR("Couldn't query own module for a function");
      program = 0;
    }
#endif

    ActivateContext(mainWindow, NULL);
    ActivateContext(mainWindow, mainContext, true);

    while(Running())
    {
      // trash the texture pack/unpack state
      glPixelStorei(GL_UNPACK_ROW_LENGTH, screenWidth + screenHeight + 99);
      glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 5);
      glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8180);
      glPixelStorei(GL_UNPACK_SKIP_ROWS, 17);
      glPixelStorei(GL_UNPACK_ALIGNMENT, 8);

      glPixelStorei(GL_PACK_ROW_LENGTH, screenWidth + screenHeight * 1 + 37);
      glPixelStorei(GL_PACK_SKIP_PIXELS, 9734);
      glPixelStorei(GL_PACK_SKIP_ROWS, 33);
      glPixelStorei(GL_PACK_ALIGNMENT, 8);

      for(int i = 0; i < 100; i++)
        glGetError();

      glBindProgramPipeline(0);

      if(glGetError() != GL_NONE)
      {
        TEST_ERROR("Got an error from glBindProgramPipeline");
      }

      glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight));

      glBindBuffersBase(GL_SHADER_STORAGE_BUFFER, 0, 4, NULL);

      glBindVertexArray(trashvao);
      glBindVertexBuffers(0, 4, NULL, NULL, NULL);
      glBindTextures(0, 10, NULL);
      glBindSamplers(0, 10, NULL);
      glBindImageTextures(0, 4, NULL);

      glBindVertexArray(vao);

      float col[] = {1.0f, 0.0f, 1.0f, 1.0f};
      glClearBufferfv(GL_COLOR, 0, col);

      setMarker("NoScissor");
      glDisable(GL_SCISSOR_TEST);
      glScissor(0, 0, 1, 1);
      glProgramUniform1i(program, glGetUniformLocation(program, "mode"), 0);
      glDrawArrays(GL_TRIANGLES, 0, 3);

      glEnable(GL_SCISSOR_TEST);
      glScissor(0, 0, GLsizei(screenWidth), GLsizei(screenHeight));

      glClearBufferfv(GL_COLOR, 0, col);

      glBindVertexArray(vao);

      glUseProgram(program);

      glProgramUniform1i(program, glGetUniformLocation(program, "mode"), 0);
      glDrawArrays(GL_TRIANGLES, 0, 3);

      glScissor(320, 50, 1, 1);

      glProgramUniform1i(program, glGetUniformLocation(program, "mode"), 1);
      glDrawArrays(GL_TRIANGLES, 0, 3);

      if(GLAD_GL_GREMEDY_frame_terminator)
        glFrameTerminatorGREMEDY();

      Present();
    }

    return 0;
  }
};

REGISTER_TEST();