+ if (retrace::profilingMemoryUsage) {
+ CallQuery& query = callQueries.back();
+ query.vsizeStart = os::getVsize();
+ query.rssStart = os::getRss();
+ }
+}
+
+void
+endProfile(trace::Call &call, bool isDraw) {
+
+ /* CPU profiling for all calls */
+ if (retrace::profilingCpuTimes) {
+ CallQuery& query = callQueries.back();
+ query.cpuEnd = getCurrentTime();
+ }
+
+ /* GPU profiling only for draw calls */
+ if (isDraw) {
+ if (retrace::profilingGpuTimes) {
+ glEndQuery(GL_TIME_ELAPSED);
+ }
+
+ if (retrace::profilingPixelsDrawn) {
+ glEndQuery(GL_SAMPLES_PASSED);
+ }
+ }
+
+ if (retrace::profilingMemoryUsage) {
+ CallQuery& query = callQueries.back();
+ query.vsizeEnd = os::getVsize();
+ query.rssEnd = os::getRss();
+ }
+}
+
+void
+initContext() {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
+
+ /* Ensure we have adequate extension support */
+ assert(currentContext);
+ supportsTimestamp = currentContext->hasExtension("GL_ARB_timer_query");
+ supportsElapsed = currentContext->hasExtension("GL_EXT_timer_query") || supportsTimestamp;
+ supportsOcclusion = currentContext->hasExtension("GL_ARB_occlusion_query");
+ supportsDebugOutput = currentContext->hasExtension("GL_ARB_debug_output");
+ supportsARBShaderObjects = currentContext->hasExtension("GL_ARB_shader_objects");
+
+ /* Check for timer query support */
+ if (retrace::profilingGpuTimes) {
+ if (!supportsTimestamp && !supportsElapsed) {
+ std::cout << "Error: Cannot run profile, GL_EXT_timer_query extension is not supported." << std::endl;
+ exit(-1);
+ }
+
+ GLint bits = 0;
+ glGetQueryiv(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &bits);
+
+ if (!bits) {
+ std::cout << "Error: Cannot run profile, GL_QUERY_COUNTER_BITS == 0." << std::endl;
+ exit(-1);
+ }
+ }
+
+ /* Check for occlusion query support */
+ if (retrace::profilingPixelsDrawn && !supportsOcclusion) {
+ std::cout << "Error: Cannot run profile, GL_ARB_occlusion_query extension is not supported." << std::endl;
+ exit(-1);