为什么我在所有像素的双for循环中使用SDL2和SDL_RenderCopy得到糟糕的性能
Why do I get bad performance with SDL2 and SDL_RenderCopy inside a double for loop over all pixels?
我正在使用SDL2编程一个光线投射游戏。当绘制地板时,我需要在像素上调用SDL_RenderCopy。这将导致瓶颈,使帧率下降到10fps以下。我正在寻找提高性能的方法,但似乎找不到。
下面是性能下降的粗略概述:
int main() {
while(true) {
for(x=0; x<800; x++) {
for(y=0; y<600; y++) {
SDL_Rect src = { 0, 0, 1, 1 };
SDL_Rect dst = { x, y, 1, 1 };
SDL_RenderCopy(ren, tx, &src, &dst); // this drops the framerate below 10
}
}
SDL_RenderPresent(ren);
}
}
你可能应该使用纹理流。基本上,你将创建一个SDL_TEXTUREACCESS_STREAMING
类型的SDL_Texture
,然后每一帧你"锁定"纹理,更新你需要的像素,然后再次"解锁"纹理。然后在单个SDL_RenderCopy
调用中渲染纹理。
- LazyFoo示例http://lazyfoo.net/tutorials/SDL/42_texture_streaming/index.php
- 探索银河系-http://slouken.blogspot.co.uk/2011/02/streaming -纹理- - sdl 13. - html
除此之外,每帧调用SDL_RenderCopy
48万次总是会杀死你的帧率
你在每一帧中调用SDL_RenderCopy()
,所以600 * 800 = 48万次!性能下降是正常的
相关文章:
- 如何创建事件驱动的 SDL2 应用程序
- 使用 SDL2 和SDL_image C++加载图像
- 将 SDL2 与 CMake 链接起来
- SDL2 透明背景
- 如何在使用 SDL2 的 Eclipse 中构建 c++ 程序
- 不带轮询的 SDL2 事件回调
- C++ SDL2:如何将矩形渲染到多个视口中
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- SDL2 二维纹理分配/池化
- 如何使用 sdl2 快速绘制像素网格?
- 看不到文件'SDL2.lib'
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- SDL2 无法正确绘制矩形
- 实施英特尔实感和 SDL2 时出现问题
- 找不到 sdl2.dll
- SDL2 程序只写入部分字符串
- 为什么在使用 SDL2 时仍然收到'undefined reference'链接器错误?
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- SDL2 (C++) 如何使图像变小
- SDL2 不是基于 VS 代码构建的