Jump to content
  • Advertisement
Sign in to follow this  
MattSmith_79985

DX11 Couple of DX10 Questions

This topic is 2596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So When I first learned Direct X it was DX11, but there wasn't a TON of resources available so I started going off Frank Luna's DX10 book. I feel that I understand everything besides a "few" select things (mainly differences between DX10 and 11)

Anyways here they go:
For Vertex and Index buffers I noticed this:


D3D10_BUFFER_DESC vbd;
vbd.Usage = D3D10_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * mNumVertices;
vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = &vertices[0]; <-------
HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));


What exactly does the piece I have an arrow pointed at do? I think in DX11 it was something completely different (like 3 lines worth) I think we used something like:


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);



ok secondly is dealing with HLSL in DX11 I would compile the shader and do something like this:


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);



but in the DX10 code it's like:


D3D10_TECHNIQUE_DESC techDesc;
mTech->GetDesc( &techDesc );
for(UINT p = 0; p < techDesc.Passes; ++p)
{
mWVP = mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mTech->GetPassByIndex( p )->Apply(0);
mLand.draw();
}



and this:


mTech = mFX->GetTechniqueByName("ColorTech");

mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix();



I've looked around the book, and it doesnt really explain what these do.
also here's the HLSL for reference for the DX10 book


//=============================================================================
// color.fx by Frank Luna (C) 2008 All Rights Reserved.
//
// Transforms and colors geometry.
//=============================================================================


cbuffer cbPerObject
{
float4x4 gWVP;
};

void VS(float3 iPosL : POSITION,
float4 iColor : COLOR,
out float4 oPosH : SV_POSITION,
out float4 oColor : COLOR)
{
// Transform to homogeneous clip space.
oPosH = mul(float4(iPosL, 1.0f), gWVP);

// Just pass vertex color into the pixel shader.
oColor = iColor;
}

float4 PS(float4 posH : SV_POSITION,
float4 color : COLOR) : SV_Target
{
return color;
}
/*
RasterizerState Wireframe
{
FillMode = Wireframe;
CullMode = Back;
FrontCounterClockwise = false;
};*/

technique10 ColorTech
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );

//SetRasterizerState(Wireframe);
}
}



I've never seen a "technique" mentioned in DX11....and i'd def. never seen anything like this:

mTech = mFX->GetTechniqueByName("ColorTech");

mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix();

seems like creating an input layout and such is ALOT easier in DX11...

anyone care to explain what these are?

Share this post


Link to post
Share on other sites
Advertisement
The line where the arrow is pointing at just stores the adress of your first vertex in vinitData.pSysMem.
This is one of the things that vinitData stores.
If I am not wrong you can also just map it like in DX11.

The part you show about HLSL in DX11 is when initializing, while the DX10 code you posted is for drawing it.

The techniques are indead not used in DX11 (although you can use them).
In DX11 you work directly with the pixel and vertex shader, you can also do this in DX10 and then you don't have to use techniques.

I don't have much experience with it so I don't know whether you can use those variables without an effect in DX10.

Sorry that I edited this post a few times, but I accidentaly posted it to early.

Share this post


Link to post
Share on other sites
[color="#1C2837"][color="#000000"]vinitData Is a pointer to the initial data to place inside the buffer once it's been created

And techniques are ways of calling different shaders for example...


technique10 Tech1
{
Pass P0
{
SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PixelShaderWithNoEffects())); <---
}
}

technique10 Tech2
{
Pass P0
{

SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PixelShaderWithEffects())); <---
}
}

And then in your main code you would just select a technique on which you would want to use

Share this post


Link to post
Share on other sites
You can still use memcpy to map data into a buffer... just the 2nd parameter in [color="#1C2837"][font="CourierNew, monospace"][color="#000000"]md3dDevice[color="#666600"]->[color="#660066"]CreateBuffer[color="#666600"](&[color="#000000"]vbd[color="#666600"], [color="#666600"]&[color="#000000"]vinitData[color="#666600"], [color="#666600"]&[color="#000000"]mVB) is used to set initial data in the buffer you can just set it to NULL [/font][font="CourierNew, monospace"][color="#000000"]md3dDevice[color="#666600"]->[color="#660066"]CreateBuffer[color="#666600"](&[color="#000000"]vbd[color="#666600"],[color="#000000"] NULL[color="#666600"], [color="#666600"]&[color="#000000"]mVB)[/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][color="#000000"]Oh and fail in my last post...[/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][color="#000000"]Edit:[/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][color="#000000"]Here's an example of copying data in dx10[/font]
[font="CourierNew, monospace"] [/font][font="CourierNew, monospace"]
bool CVertexBuffer::MapIndexData(UINT numIndex, void* pData)
{
void* pVoid;
IndexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer
memcpy(pVoid, pData, sizeof(int) * numIndex); // copy the vertices to the buffer
IndexBuffer->Unmap();

this->numIndexes = numIndex;

return true;
}
[/font]

Share this post


Link to post
Share on other sites

^^ Ya thats what I did in the DX11. Ok that makes sense then.

the technique thing.......for DX10 is a whole different other mess tho.


Haha, yeah it's basically just a way to call different shader functions. It's mainly used for selecting which shaders to use on different graphics cards... If i remember correctly DX actually provides you with a function that decides which technique is better.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!