- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我当时正在使用 SDL 开发应用程序并且很高兴。我注意到动画中有一些小的停顿。我已经用最少的功能编写了一个单独的项目,我发现即使是非常基本的设置也会出现这个问题。
这是代码:
#include <iostream>
#include <vector>
#include <fstream>
#include <SDL.h>
#include <glad/glad.h>
using namespace std;
// the application will close after this amount of time
const float MILISECONDS_TO_CLOSE = 10 * 1000;
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_Window* window =
SDL_CreateWindow(
"tracer",
100, 100,
800, 600,
SDL_WINDOW_OPENGL
);
SDL_GLContext context = SDL_GL_CreateContext(window);
// SDL_GL_SetSwapInterval(1); // this line mitigates the problem but just slightly
if (!gladLoadGL())
{
cout << "gladLoadGL failed" << endl;
}
const GLubyte *oglVersion = glGetString(GL_VERSION);
std::cout << "This system supports OpenGL Version: " << oglVersion << std::endl;
const GLubyte *gpuVendor = glGetString(GL_VENDOR);
std::cout << "Graphics card: " << gpuVendor << std::endl;
glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
vector<unsigned> deltas;
deltas.reserve(10 * MILISECONDS_TO_CLOSE);
static unsigned firstTime, prevTime, curTime;
firstTime = prevTime = curTime = SDL_GetTicks();
while (true)
{
// compute delta time
curTime = SDL_GetTicks();
unsigned dt = curTime - prevTime;
prevTime = curTime;
deltas.push_back(dt);
// close the application after some time
if (curTime - firstTime > MILISECONDS_TO_CLOSE) break;
// handle closing events
SDL_Event event;
if (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE || event.type == SDL_QUIT) break;
}
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window);
}
// save recorded deltas to a file
fstream f("out.txt", ios::out | ios::trunc);
for (unsigned dt : deltas) f << dt << endl;
f << flush;
f.close();
return 0;
}
程序记录 10 秒内帧之间的时间并将结果保存在文本文件中。
我用 python 绘制了数据我得到了这个:
水平轴以毫秒为单位表示帧时间。垂直轴表示自上一帧以来耗时。同样以毫秒为单位。
如您所见,帧之间的时间非常不规则,并且存在周期性尖峰(尖峰之间大约间隔 1 秒)。
我已将 CMake 项目上传到 github repository , 因此您可以根据需要进行测试。
我已经使用我的集成 GPU 和专用 GPU(Intel 530HD 和 NVIDIA GTX 960M)进行了测试。
SDL 版本为 2.0.5。
我在 Windows 10 和 Ubuntu 16.04 LTS 上测试过它。
编辑:我已将应用程序移植到 GLFW,同样的事情发生了。因此,SDL 中存在错误的可能性很小。我相应地更新了 git 仓库,现在有两个 CMake 项目。
编辑 2:我已经在另一台电脑上测试过它并且工作正常。 我不知道发生了什么。会不会是硬件问题?那为什么当我运行其他应用程序时它不会发生?
驱动问题?不太可能,因为它同时使用 Intel 和 NVIDIA GPU。此外,它发生在 Ubuntu 和 Windows 上。
最佳答案
由于 CPU 过热,我有过类似的行为(虽然有更长和更低的稳定期,而不是尖峰),因此决定暂时降低时钟频率。如果您的 PC 出现这种情况,您可以尝试升级内部冷却器或添加外部冷却器。或者只是降低房间空调的温度设置。
当然,这在夏天总是更成为一个问题。
关于c++ - SDL + OpenGL,具有周期性尖峰的不规则帧时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45885534/
我正在使用 Jmeter 测试我的站点,以查看一百个线程将如何影响站点性能,并使用 apache 和 mod_php 以及带有 fastcgi 的 nginx 对其进行了测试。我注意到 bottleb
脉冲神经网络和循环神经网络都可以对时变信息进行建模。但我不确定哪种模型相对于计算成本更好。使用更复杂的脉冲神经网络是否值得,或者循环神经网络是否可以在所需计算量少得多的情况下工作?脉冲网络收敛得更快吗
测试驱动开发人员指的是一种快速、探索性的调查,其中涉及编写代码以查看其是否有效,即峰值。 知道他们为什么想出这个词吗? 更新:肯特·贝克 (Kent Beck) 的造词对我来说看起来像是“原始”的,尽
我在开发的滚动游戏中遇到了 TiledMapRenderer 问题。我目前正在使用带有 Tmx Map 的 BatchTiledMapRenderer(我也尝试过使用普通的 TiledMapRende
正如标题所说,我运行“bundle 更新”,我的 CPU 达到峰值,但没有任何反应。我已经离开它两个小时了。有什么想法吗? 我使用 bundler 版本 1.0.15。 这是我的 Gemfile 内容
希望有人可以阐明我们遇到的这个问题,因为我在这里不知所措。 首先,一点背景: 我在几周前为我们的应用程序重写了 URL 重写并实现了它。我使用 global.asax 文件中的 Application
我是一名优秀的程序员,十分优秀!