notJustCode.it
 
\\ Home : Articoli
More about D3D10 Device
Di robydx (del 13/03/2007 @ 22:56:15, in English, linkato 4412 volte)

Now i will explain you any troubles learned in previous tutorials. We have created our main objects: device, that manages resources, the swap chain, that is the destination in which we will see our objects, and the RenderTargetView that is the memory area in which the device will work. Now the sequence should be clear. The device reads polygons, it works on them in shader and draws pixels on RenderTargetView. At last the view will be copied on the screen with swap chain.

There is also another surface: Depth Stencil Buffer.

This buffer it’s used to maintain information about masks and deep. The vertex projection has got a range from 0 to 1 (explained in first tutorial). Each time DirectX generates a pixel it does not insert automatically in it’s side. In fact it compares the deep value with previous one to verify if this pixel has got something besides or next to him. This information it’s memorized in depth buffer. It’s then much important to create this buffer to operate with 3d objects, otherwise an object drawn at last will overwrite all the previous ones also if it is besides them. The stencil is a free surface, together depth, let us to create new masks. A Mask it’s an area that, as a filter, works with operations. Drawing an object you can set its position on stencil. In this mode you can permit drawing of next objects only in the draw area of previous objects. With this tip you can perform cuts, useful for advanced effects.

ID3D10DepthStencilView* renderTargetDepth;

D3D10_TEXTURE2D_DESC descDepth;

descDepth.Width = width;

descDepth.Height = height;

descDepth.MipLevels = 1;

descDepth.ArraySize = 1;

descDepth.Format = DXGI_FORMAT_D32_FLOAT;

descDepth.SampleDesc.Count = 1;

descDepth.SampleDesc.Quality = 0;

descDepth.Usage = D3D10_USAGE_DEFAULT;

descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;

descDepth.CPUAccessFlags = 0;

descDepth.MiscFlags = 0;

ID3D10Texture2D *pDepthBuffer;

device->CreateTexture2D( &descDepth, NULL, &pDepthBuffer );

D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;

descDSV.Format = descDepth.Format;

descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;

descDSV.Texture2D.MipSlice = 0;

device->CreateDepthStencilView( pDepthBuffer, &descDSV, &renderTargetDepth );

pDepthBuffer->Release();

This code creates a texture (a rectangular memory area that can store pictures and data). The depth stencil is a special texture created with BindFlags equal to stencil. Many important it’s the dimension (width, weight) that must be equal to device’s one, and the format. In the example I’ve used D32, then 8byte only for the depth. A format like DXGI_FORMAT_D24_UNORM_S8_UINT means 24 for depth and 8 for stencil. In help you will find all formats, and, obviously, more bits, more slow.

device->OMSetRenderTargets( 1, &this->renderTargetView, this->renderTargetDepth);

The same instruction that sets RenderTarget, set also stencil. Now the device it’s completed. We must manage another thing: the resize. The resize it’s an event generated when we resize the windows. With D3D10 it’s more simple to manage this event.

In the message LOOP, at WM_SIZE event, past this code:

this->swapChain->ResizeBuffers(1,width,height,DXGI_FORMAT_R8G8B8A8_UNORM,2);

and then we must recreate depth and stencil buffer, and reset viewport.

Enumerate video cards.

Some pc have got more than a video card. There is a way to analyze system and find all existing video card.

IDXGIFactory* factory;

CreateDXGIFactory(__uuidof(IDXGIFactory) ,(void**)&factory);

UINT i = 0;

IDXGIAdapter * pAdapter;

while(factory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND)

{

    i++;

}

factory->Release();

DXGIFactory let us to read information from system. We do not need a device to create this class (this for query video card to understand in better way how to set device). In same mode it’s possible to catalogue all supported resolution using IDXGILayout class, given by adapter.

IDXGIOutput* output;

adapter->EnumOutputs(0,&output);

DXGI_OUTPUT_DESC outputDescription;

output->GetDesc(&outputDescription);

UINT numModes;

output-> GetDisplayModeList( DXGI_FORMAT_R8G8B8A8_UNORM,DXGI_ENUM_MODES_INTERLACED , &numModes,0);

numModes now contains all number of valid display

DXGI_MODE_DESC* mode=new DXGI_MODE_DESC[numModes];

Output->GetDisplayModeList( DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED,&numModes,mode);

We allocate memory for the array that will contain all supported modality. We iterate structure one at one to have all information about video cards.

With this tutorial we have finished with device creation. In the future we will see another details on device. In next tutorial we will start to describe base functionality : text and sprite, and then we will start with real 3D.

A special thanks goes to Vincent who translate this lesson.

Code

Articolo Articolo  Storico Storico Stampa Stampa
I commenti sono disabilitati.
"L'esperienza è quella cosa meravigliosa che permette di riconoscere un errore quando lo si commette di nuovo."

F.P Jones


Cerca per parola chiave
 

Titolo
Articoli (4)
C++ (4)
Direct3D10 (30)
Direct3D11 (20)
DirectX9 (82)
DotNet (10)
English (9)
FanGames (22)
ManagedDX11 (2)
Materiale Utile (4)
News (39)
Shader Library (12)
SharpDX (1)
Software (25)
Tecnologia (19)
Varie (9)

Gli interventi più cliccati

Ultimi commenti:
If you wish to retai...
23/05/2013 @ 13:07:45
Di chanel outlet
You deficit of self-...
23/05/2013 @ 13:07:13
Di cartier watches uk
Reinforce your own l...
23/05/2013 @ 13:06:37
Di replica watches
Whenever you"re shiv...
23/05/2013 @ 13:06:11
Di swiss replica watches
It's likely you have...
23/05/2013 @ 13:05:02
Di chanel handbags
Cheap automobile ins...
23/05/2013 @ 13:04:28
Di replica watches

Titolo
Con quale tecnologia state realizzando o avete intenzione di realizzare i vostri progetti?

 DirectX11
 DirectX10
 DirectX9
 XNA
 DirectX8 o Precedenti
 OpenGL
 Motori grafici già pronti
 Altro

Titolo
Umorismo (17)

Le fotografie più cliccate



Ci sono 24 persone collegate
Sono state visualizzate  pagine

28/03/2024 @ 12:17:40
script eseguito in 56 ms