DXLesson 1
来源:互联网 发布:黑蚂蚁成年网络电视 编辑:程序博客网 时间:2024/06/07 18:26
今决定先看dx sample browser上的内容,毕竟好理解些。
Tutorial 0: Win32 Basics
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )??
Tutorial 1: Direct3D 11 Basics:
create three objects: a device, an immediate context, and a swap chain. The immediate context is a new object in Direct3D 11.
the immediate context is used by the application to perform rendering onto a buffer, and the devicecontains methods tocreate resources.
The swap chain is responsible for taking the buffer to which the device renders and displaying the content on the actual monitor screen. The swap chaincontains two or more buffers, mainly the front and the back.
The front bufferis what is beingpresented currently to the user. This buffer is read-only and cannot be modified. The back buffer is the render target to which the device will draw.Once it finishes the drawing operation, the swap chain will present the backbuffer by swapping the two buffers. The back buffer becomes the front buffer, and vice versa.
DXGI_SWAP_CHAIN_DESC sd; //describes the swap chain ZeroMemory( &sd, sizeof(sd) ); sd.BufferCount = 1; sd.BufferDesc.Width = 640; sd.BufferDesc.Height = 480; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;//?什么意思? swapBuffer(back和front) 输出renderBuffer类型 sd.OutputWindow = g_hWnd;//在g_hWnd这个window上 sd.SampleDesc.Count = 1;//多重采样数 multi-Sampling Nums sd.SampleDesc.Quality = 0;//关闭multi-Sampling sd.Windowed = TRUE;
if( FAILED( D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, NULL, &g_pImmediateContext ) ) ) { return FALSE; }In Direct3D 10, the device object was used to perform both rendering and resource creation. In Direct3D 11, the immediate context is used by the application to perform rendering onto a buffer, and the device contains methods to create resources.//为什么会有这样的转变呢?有什么好处呢?
create a render target view,A render target view is a type of resource view in Direct3D 11.. A resource view allows a resource to be bound to the graphics pipeline at a specific stage.Think of resource views as typecast in C. A chunk of raw memory in C can be cast to any data type.We can cast that chunk of memory to an array of integers, an array of floats, a structure, an array of structures, and so on. The raw memory itself is not very useful to us if we don't know its type. Direct3D 11 resource views act in a similar way. For instance, a 2D texture, analogous to the raw memory chunk, is the raw underlying resource. Once we have that resource we can create different resource views to bind that texture to different stages in the graphics pipeline with different formats: as a render target to which to render, as a depth stencil buffer that will receive depth information, or as a texture resource.
// Create a render target view ID3D11Texture2D *pBackBuffer;//创建一个未定型的buffer,可以为renderView ,depth stencil buffer....as typecast in C if( FAILED( g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID*)&pBackBuffer ) ) )//bind the back buffer of our swap chain as a render target.. This enables Direct3D 11 to render onto it. hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );//device create resource 实例化此buffer为RenderTargetView pBackBuffer->Release(); g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );//to bind render target view to the pipeline. ensures the output that the pipeline renders gets written to the back buffer.
小结:
1. context:perform rendering on the buffer....//context set在buffer上执行渲染
g_pImmediateContext->OMSetRenderTargets //to bind render target view to the pipeline.
2. device : create resources
g_pd3dDevice->CreateRenderTargetView
g_pd3dDevice->ClearRenderTargetView( g_pRenderTargetView, ClearColor );3. chain : taking the buffer to which the device renders and displaying the content on the actual monitor screen
g_pSwapChain->GetBuffer //to get the back buffer object.负责前后buffer的交换g_pSwapChain->Present( 0, 0 );//Present() is responsible for displaying the swap chain's back buffer content onto the screenTutorial 2: Rendering a Triangle
the application must specify a buffer size in bytes when creating a buffer resource.
how many bytes does each vertex need? To answer that question requires an understanding of vertex layout.
More often than not(通常,多半)
Vertex layout defines how these attributes lie in memory: whatdata type each attribute uses, whatsizeeach attribute has, and the order of the attributes in memory.
when we feed the GPU the vertex buffer containing our vertices, we are just feeding it a chunk of memory. The GPU must also know about the vertex layout in order to extract correct attributes out from the buffer.
(当推送含有vertex属性的buffer给GPU时,我们仅是给GPU一块内存,GPU通过vertex layout来明确vertexBuffer的属性结构)。
HRESULT??
// Compile the shader
CompileShaderFromFile(WCHAR* szFileName,LPCSTR szEntryPoint,LPCSTR szShaderModel,ID3DBlob **ppBlobOut)
文件名,shader的入口点(是vertexShader还是pixelShader),shaderModel 4.0 3.0.... ID3DBlob(翻译是 二进制大物件....)应该是说把shader编译成二进制形式,ppBlobOut用于地址索引?
0 0
- DXLesson 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1》
- 1
- 1
- 1
- 1
- (1)
- 1
- 1
- 1
- 1
- 1
- hdu3591The trouble of Xiaoqian(多重背包)
- ubuntu环境下搭建PHP环境(LAMP)
- 小试牛刀 CSS实例教程 前言与目录
- 嘿嘿~~爱你哦
- hdu4539(状态压缩)
- DXLesson 1
- Django的安装
- AJAX file uploads in Rails using attachment_fu and responds_to_parent2
- DIV+CSS布局入门示例(目录
- [ACM] hdu 1051 Wooden Sticks
- 字符串匹配之后缀树
- 字符编码(一)
- 中介者设计模式--练习
- oracle 使用order by 对汉字进行多字段排序