美文网首页图像图形渲染DirectX
DirectX入门(一) -- 阅读微软DirectX文档

DirectX入门(一) -- 阅读微软DirectX文档

作者: 三生石上绛珠草 | 来源:发表于2016-07-12 14:42 被阅读1515次
    Paste_Image.png
    (以上图片来自Ray Trace Wiki
    微软的官方文档写的太tm好了,什么DX鬼龙书,丝毫比不上文档清晰明了,循循善诱。真心写的太tm好了!!!请戳以下链接:
    DirectX MSDN Document

    虽然是英文版,然而非常好读,比龙书神妙。龙书这种鬼东西以后就不要推荐了,本本都是坑,误人子弟。不同意者请保留意见,鄙人比较笨,就是没明白龙书的套路。(捎带提一句,编译原理的龙书也是个渣。不服的去读读《编程语言实现模式》和《The Little Schemer》。凭心而论,就算要读理论性的编译原理,虎书也比龙书高明。)

    学DX并不是为了做游戏,事实上我对于做游戏已经毫无兴趣--游戏不过是各种繁复无聊的业务逻辑的组合,没有什么乐趣可言的。也一点都不喜欢玩游戏--不喜欢游戏的情节,更不喜欢3D的游戏画面,这种体力劳动加眼睛的浪费我是实在喜欢不来。(注:不同意者请保留自己的意见。不必和我理论。我从不和与我不同意见的人理论,因为谁都说服不了谁。口舌之争纯粹无聊之举。)

    废话多了点,言归正传:我学习DX是为了做GUI库,自绘控件,这才是我真正的乐趣,哈哈哈哈。学编程要向轮子哥看齐,多造轮子,才能用上自己学到的东西,才能提升自己的元编程能力,提高自己的设计能力,提高自己的Debug能力,提高自己的单元测试能力,做一个靠谱的程序员。

    所以图形学和编译原理两样都要学,两手都要抓,两手都要硬。补了这么久的计算机基础我就是为了回来重新研究这两样东西。

    下面简要翻译一下文档的关键部分(其实看英文也简单的如同切菜)。

    初始化

    (1) 创建windows窗口和消息循环
    Now You have a window to draw in.
    (2) 获取D3D设备及其上下文接口(Get an interface for the Direct3D device and context)
    ID3D11Device : 虚拟机及其资源的抽象(provides a virtual representation of the GPU and its resources)。用于配置和获取场景中需要处理的图形的GPU资源(configure and obtain the GPU resources you need to start processing the graphics in a scene)。
    ID3D11DeviceContext : 设备上下文,代表渲染管线图形处理(represents the graphics processing for the pipeline)。用于处理图形渲染管线中各个相应的shader(着色)步骤的资源。(to process those resources at each appropriate shader stage in the graphics pipeline.)
    现在你得到了向GPU发送数据和命令的接口。(Now you have an interface to send data and give commands to the GPU.)
    (3)创建交换链(Create the swap chain):
    看见交换链这词我是直接想到了双缓冲。原理差不多。

    Now you've got a window from the operating system, a way to access the GPU and its resources, and a swap chain to display the rendering results. All that's left is to wire the whole thing together!

    (4) 创建render target(Create a render target for drawing)
    Render target : 我的理解就是画布(Canvas,Surface)。
    render-target view 就是画布的代理,想画东西想得到画布还得找代理去获取特定资源。view使得pixel shader(像素着色器)向texture(材质)写入数据当它(pixel shader)完成每像素的操作之后。
    view is a way to access a specific resource. In this case, the view enables the pixel shader to write into the texture as it completes its per-pixel operations.

    texture:材质。有人翻译成纹理,呵呵。我十分讨厌纹理这词,根本看不懂这个中文词,tm还不如不翻译呢。典型的不说人话,我想我当年看不懂龙书是有原因的,因为看的中文版。

    其他

    记录一个比较模糊的概念。当年误导了我很久。

    depth-stencil:到底是谁第一个把这词翻译成深度模板的,站出来我保证不打死你!!!当时看到深度模板的我一脸懵逼,还以为真有一个template呢,喵的!反正stencil不能翻译成模板就对了。这些误人子弟的中文翻译都该去面壁,这是断人慧根啊!

    depth-stencil buffer 是一种ID3D11Texture2D资源的特定格式。典型用于场景中的camera在远距离物体光栅化的时候决定那些像素拥有绘制优先权(说了半天就是光栅化3D图形时候决定哪些像素绘制,其实当年看过一张很形象的图。不懂光栅化的孩子请去问度娘)。后边翻译省略,初中英文水平都读得懂。我就不要断人慧根了。

    {Also create a depth-stencil buffer. A depth-stencil buffer is just a particular form of ID3D11Texture2D resource, which is typically used to determine which pixels have draw priority during rasterization based on the distance of the objects in the scene from the camera. A depth-stencil buffer can also be used for stencil effects, where specific pixels are discarded or ignored during rasterization. This buffer must be the same size as the render target. Note that you cannot read from or render to the frame buffer depth-stencil texture because it is used exclusively(专门的) by the shader pipeline before and during final rasterization.}

    以下摘录对ID3D11DeviceID3D11DeviceContext的理解,太冗长,选择不译了。前边已经译了关键词句。

    {You'll recall that there are two Direct3D interfaces that define the graphics pipeline: ID3D11Device, which provides a virtual representation of the GPU and its resources; and ID3D11DeviceContext, which represents the graphics processing for the pipeline. Typically, you use an instance of ID3D11Device to configure and obtain the GPU resources you need to start processing the graphics in a scene, and you use ID3D11DeviceContext to process those resources at each appropriate shader stage in the graphics pipeline. You usually call ID3D11Device methods infrequently—that is, only when you set up a scene or when the device changes. On the other hand, you'll call ID3D11DeviceContext every time you process a frame for display.}

    相关文章

      网友评论

        本文标题:DirectX入门(一) -- 阅读微软DirectX文档

        本文链接:https://www.haomeiwen.com/subject/lfajjttx.html