表面和纹理的区别(SDL/通用) [英] Difference between surface and texture (SDL / general)

查看:28
本文介绍了表面和纹理的区别(SDL/通用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能用简单的话向我解释一下纹理和表面之间的区别是什么?我看到它在 SDL2 中用作 SDL_SurfaceSDL_Texture.SDL_Texture 是从 SDL_Surface 创建的,而 SDL_Surface 又是从图像/位图创建的.两者都是像素的集合.但我看不出它们之间的主要区别(必须用 GPU 做点什么?)

Can anyone explain to me in simple words what is the difference between texture and surface? I saw it used in SDL2 as SDL_Surface and SDL_Texture. SDL_Textureis created from SDL_Surface which in turn is created from image/bitmap. Both are collection of pixels. But I do not see the main difference between them (has to do something with GPU?)

我试着用谷歌搜索,但我发现的所有解释都太复杂了,如果不深入研究计算机图形学,就无法理解它们.

I tried to google it but all explanations I found were too complex to understand them without digging deeper into computer graphics stuff.

推荐答案

基本上你的假设必须用 GPU 做点什么?"是对的.

Basically your assumption "has to do something with GPU?" is right.

SDL_Surface 用于软件渲染.通过软件渲染,正如 saloomi2012 正确注意到的那样,您使用的是常规 RAM 来存储图像数据.因此,在大多数情况下,您可以直接访问与表面关联的数据缓冲区,修改其内容,即它使用 CPU,因此软件名称.

SDL_Surface is used in software rendering. With software rendering, as saloomi2012 correctly noticed, you are using regular RAM to store image data. Thus, in most cases you can access data buffer associated with surface directly, modifying its content, i.e. it is using CPU, hence the software name.

SDL_Texture 另一方面,用于硬件渲染,纹理存储在 VRAM 中,您无法像 那样直接访问它SDL_Surface.渲染操作由 GPU 加速,在内部使用 OpenGL 或 DirectX(仅在 Windows 上可用)API,而后者又使用您的视频硬件,因此硬件渲染名称.

SDL_Texture on the other hand, is used in a hardware rendering, textures are stored in VRAM and you don't have access to it directly as with SDL_Surface. The rendering operations are accelerated by GPU, using, internally, either OpenGL or DirectX (available only on Windows) API, which in turn are using your video hardware, hence hardware rendering name.

毋庸置疑,硬件渲染比软件渲染快几个数量级,应始终被视为主要选项.

Needless to say that hardware rendering is by orders of magnitude faster than software rendering and should be always be considered as primary option.

这篇关于表面和纹理的区别(SDL/通用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆