Commit 680c085b authored by Administrator's avatar Administrator
Browse files

draw with triangle index and color constant buffer

parent 74ff7e8a
......@@ -118,34 +118,28 @@ void Graphics::DrawTestTriangle(float angle, float x, float y)
float y;
float z;
} pos;
struct
{
float r;
float g;
float b;
} color;
};
// create vertex buffer (8 vertices for one cube)
const Vertex vertices[] =
{
// left bottom back
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f },
{ -1.0f, -1.0f, -1.0f },
// right bottom back
{ 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, -1.0f, -1.0f },
// left top back
{ -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f },
{ -1.0f, 1.0f, -1.0f },
// right top back
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f },
{ 1.0f, 1.0f, -1.0f },
// left bottom front
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
{ -1.0f, -1.0f, 1.0f },
// right bottom front
{ 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f },
// left top front
{ -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f },
{ -1.0f, 1.0f, 1.0f },
// right top front
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f },
};
wrl::ComPtr<ID3D11Buffer> pVertexBuffer;
D3D11_BUFFER_DESC bd = {};
......@@ -235,6 +229,47 @@ void Graphics::DrawTestTriangle(float angle, float x, float y)
// Bind constant buffer to vertex
pContext->VSSetConstantBuffers(0u, 1u, pConstantBuffer.GetAddressOf());
// Create constant buffer for color
struct ColorConstantBuffer
{
struct
{
float r;
float g;
float b;
float a;
} face_colors[6];
};
const ColorConstantBuffer ccb =
{
{
{ 1.0f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f },
{ 0.0f, 1.0f, 1.0f },
}
};
wrl::ComPtr<ID3D11Buffer> pColorConstantBuffer;
D3D11_BUFFER_DESC ccbd = {};
ccbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
ccbd.Usage = D3D11_USAGE_DEFAULT;
ccbd.CPUAccessFlags = 0u;
ccbd.MiscFlags = 0u;
ccbd.ByteWidth = sizeof(ccb);
ccbd.StructureByteStride = 0u;
D3D11_SUBRESOURCE_DATA ccsd = {};
ccsd.pSysMem = &ccb;
GFX_THROW_INFO(pDevice->CreateBuffer(&ccbd, &ccsd, &pColorConstantBuffer));
// Bind constant buffer to vertex
pContext->PSSetConstantBuffers(0u, 1u, pColorConstantBuffer.GetAddressOf());
// create pixel shader
wrl::ComPtr<ID3D11PixelShader> pPixelShader;
wrl::ComPtr<ID3DBlob> pBlob;
......@@ -258,7 +293,7 @@ void Graphics::DrawTestTriangle(float angle, float x, float y)
const D3D11_INPUT_ELEMENT_DESC ied[] =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
//{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
GFX_THROW_INFO(pDevice->CreateInputLayout(
ied, (UINT)std::size(ied),
......
float4 main( float3 color : Color) : SV_Target
cbuffer CBuf
{
return float4(color, 1.0f);
float4 face_color[6];
};
//float4 main( float3 color : Color) : SV_Target
float4 main(uint tid: SV_PrimitiveID) : SV_Target
{
//return float4(color, 1.0f);
return face_color[tid/2];
}
\ No newline at end of file
......@@ -180,6 +180,8 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="VertexShader.hlsl">
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
......
struct VSOut
{
float3 color : Color;
float4 pos : SV_Position;
};
cbuffer CBuf
{
matrix transform;
};
VSOut main( float3 pos : Position, float3 color : Color )
float4 main( float3 pos : Position ): SV_Position
{
VSOut vso;
vso.pos = mul( float4(pos, 1.0f), transform );
vso.color = color;
return vso;
return mul(float4(pos, 1.0f), transform);;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment