"Some" Simple Beginner questions

Started by
2 comments, last by Juliean 12 years, 11 months ago
So im still learning but I think i've got a grasp of most things DX11 (Well....beginner things) And I REALLY do apologize for all the questions.....but I'd rather understand EVERYTHING before I move on.
I have 2 main functions (well 3 technically) that set up everything. I have Initgraphics(), InitD3D(), and Initpipeline()

D3D sets up the swap chain, viewport, depth buffer and back buffer. (I understand all this.....your setting stuff up, makes sense)
Initgraphics() Creates the Verticies (for the cube/whatever im drawing) and then creates the vertex buffer and copies it in.


// create the vertex buffer
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));

bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VERTEX) * 24;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

dev->CreateBuffer(&bd, NULL, &pVBuffer);

// copy the vertices into the buffer
D3D11_MAPPED_SUBRESOURCE ms;
devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms); // map the buffer
memcpy(ms.pData, OurVertices, sizeof(OurVertices)); // copy the data
devcon->Unmap(pVBuffer, NULL);


it also does the same thing for the Index buffer.

I also have initpipeline() (see code below)


// compile the shaders
ID3D10Blob *VS, *PS;
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, 0, 0);
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, 0, &PS, 0, 0);

// create the shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

// set the shader objects
devcon->VSSetShader(pVS, 0, 0);
devcon->PSSetShader(pPS, 0, 0);

// create the input element object
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
};

// use the input element descriptions to create the input layout
dev->CreateInputLayout(ied, 3, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout);
devcon->IASetInputLayout(pLayout);

// create the constant buffer
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));

bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = 176;
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;

dev->CreateBuffer(&bd, NULL, &pCBuffer);

devcon->VSSetConstantBuffers(0, 1, &pCBuffer);



Which from my understanding, compiles the shaders, makes the shader objects, creates the elements object and descriptions (Can someone explain what exactly this is?) and the Constant Buffer (which I only somewhat understand).

I guess my question(s) is.....when do these things need to change. I have a grip on the vertex and index buffers.....like I understand WHAT they are, but when would you change them? Same goes for Depth buffer and Constant Buffer, when would I ever want to change that (I understand back buffer). I know in my RenderFrame() function I select which ones to use using below,: right?. Im assuming I would change the Constant Buffer anytime I need to apply a new shader to an object?



devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);
devcon->IASetIndexBuffer(pIBuffer, DXGI_FORMAT_R32_UINT, 0);



Secondly, Do I only need to compile the shaders once and make the objects once? (unless I use different shader files presumably...maybe one for lights for one object and one for textures for a different object)....and what the heck does this:


// create the input element object
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
};

// use the input element descriptions to create the input layout
dev->CreateInputLayout(ied, 3, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout);
devcon->IASetInputLayout(pLayout);




Stuff mean?. Also what is a Stencil Buffer.....im not really sure I understand why you create it (Does it ever need to change for that matter?) Sorry for all the questions but im just trying to "understand" EVERYTHING.
And yes this question is on gamedev.stackexchange, but I figure i'd post it here as well (to get as much information as possible).

Thanks
Advertisement
I have a grip on the vertex and index buffers.....like I understand WHAT they are, but when would you change them? [/quote]

Well in the best case you won't change them at all. As for a beginner, you will most likely be changing it for every model you display. Basically, every model has it's own vertex and index buffer. Thats what they are for, holding indices and vertices of every model = object in your game. Vertex buffer switches are expensive, so if you want to have the best performance you would have to put all objects vertices into one large vertex buffer. However this isn't that easy, and I haven't figured out myself yet how to do this.

Secondly, Do I only need to compile the shaders once and make the objects once?[/quote]

If by object you mean model, then yes. No need for dublicate data. You want to have textures loaded only once too, just a note.

and what the heck does this:
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
Stuff mean?[/quote]

Thats the vertex description. It tells you which information your vertices are holding/have to hold. In that case it is position, normal and texture coordinate. You can have many more stuff like tangents, binormals, etc.. I don't know directx 11 that well but DXGI_FORMAT_R32G32B32_FLOAT means that 3 components are available, as you need them for position. For texcoord you only need 2. Anyway I'm not so sure your code is correct, like why doesn't it end with any end-macro? maybe you don't need to do that in dx11 anymore..

Also what is a Stencil Buffer[/quote]

A stencil buffer is a surface much like the depth buffer. You can enable it to write to it and perform operations on it. You need it for certain neat special effects like shadow volumes..
Awesome thanks for all your answers. But say for each model you have a Vertex/Index Buffer.....how do you like make sure that model uses "THAT" specific buffer and whichever specific HLSL

im trying to wrap my head around putting maybe 2 difference textures on 2 different objects and what would need to be changed in my code.
Well there are functions to achieve that. I don't know what it is in DirectX11, but for DirectX9 its device->SetVertexBuffer/SetVertexShader/SetPixelShader. That commands do exactly what their name says. Try either google for these commands, look up msdn or just write -> behind your device (I quess its the "device-context" in DX11?) and wait what your IDE is saying.

This topic is closed to new replies.

Advertisement