enum piglit_result piglit_display(void) { bool pass = true; GLuint ids[10]; GLint param; /* Throw some invalid inputs at glCreateQueries */ /* n is negative */ glCreateQueries(GL_SAMPLES_PASSED, -1, ids); SUBTEST(GL_INVALID_VALUE, pass, "n < 0"); /* invalid target */ glCreateQueries(GL_RGBA, 0, ids); SUBTEST(GL_INVALID_ENUM, pass, "invalid target"); /* Throw some valid inputs at glCreateQueries. */ /* n is zero */ glCreateQueries(GL_SAMPLES_PASSED, 0, NULL); SUBTEST(GL_NO_ERROR, pass, "n == 0"); /* n is more than 1 */ glCreateQueries(GL_SAMPLES_PASSED, 10, ids); SUBTEST(GL_NO_ERROR, pass, "n > 1"); /* test the default state of dsa-created query objects */ SUBTESTCONDITION(glIsQuery(ids[2]), pass, "IsQuery()"); glGetQueryObjectiv(ids[2], GL_QUERY_RESULT_AVAILABLE, ¶m); piglit_check_gl_error(GL_NO_ERROR); SUBTESTCONDITION(param == GL_TRUE, pass, "default AVAILABLE state(%d) == TRUE", param); glGetQueryObjectiv(ids[2], GL_QUERY_RESULT, ¶m); piglit_check_gl_error(GL_NO_ERROR); SUBTESTCONDITION(param == 0, pass, "default RESULT(%d) == 0", param); /* test the target */ glGetQueryObjectiv(ids[2], GL_QUERY_TARGET, ¶m); piglit_check_gl_error(GL_NO_ERROR); SUBTESTCONDITION(param == GL_SAMPLES_PASSED, pass, "TARGET(%s) == " "GL_SAMPLES_PASSED", piglit_get_gl_enum_name(param)); /* clean up */ glDeleteQueries(10, ids); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
int main(int /*argc*/, char ** /*argv*/) { BaseApp app; ProgramObject program; auto mainWindow = app.getMainWindow(); std::string prefix = app.getResourceDir() + "Shaders/Examples/e06_ModelLoader/"; PerspectiveCamera cam; OrbitManipulator manipulator(&cam); manipulator.setupCallbacks(app); NodeShared root; GLuint query[2]; app.addInitCallback([&]() { auto vs = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "phong.vert")); auto fs = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "phong.frag")); program = createProgram(vs, fs); root = Loader::scene(app.getResourceDir() + "Models/sponza/sponza.fbx"); glCreateQueries(GL_TIMESTAMP, 2, query); SDL_GL_SetSwapInterval(0); }); app.addResizeCallback([&](int w, int h) { glViewport(0, 0, w, h); cam.setAspect(float(w) / float(h)); }); app.addDrawCallback([&]() { glQueryCounter(query[0], GL_TIMESTAMP); glClearColor(0.2, 0.2, 0.2, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); //bunny program.use(); program.setMatrix4fv("p", value_ptr(cam.getProjection())); program.setMatrix4fv("v", value_ptr(cam.getView())); drawNode(program, root); glQueryCounter(query[1], GL_TIMESTAMP); GLuint64 time1, time2; glGetQueryObjectui64v(query[0], GL_QUERY_RESULT, &time1); glGetQueryObjectui64v(query[1], GL_QUERY_RESULT, &time2); std::string s = "fps: " + std::to_string(1e9 / (time2 - time1)) + " (" + std::to_string(ImGui::GetIO().Framerate) + ")"; label(s, 0, 0, 300, 100); }); return app.run(); }
void AbstractQuery::createImplementationDSA() { glCreateQueries(_target, 1, &_id); }
static GLuint allocateQuery() { GLuint result; glCreateQueries(GL_TIME_ELAPSED, 1, &result); return result; }
static void createObjects(GLsizei n, GLuint* objects) { glCreateQueries(target, n, objects); }