|
|
|
|
6
|
#endif
|
6
|
#endif
|
7
|
#include <DK.h>
|
7
|
#include <DK.h>
|
8
|
|
8
|
|
|
|
9
|
+
|
9
|
class TestApp1 : public DKApplication
|
10
|
class TestApp1 : public DKApplication
|
10
|
{
|
11
|
{
|
11
|
DKObject<DKWindow> window;
|
12
|
DKObject<DKWindow> window;
|
|
|
|
|
31
|
DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
|
32
|
DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
|
32
|
DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
|
33
|
DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
|
33
|
|
34
|
|
|
|
35
|
+ struct Vertex
|
|
|
36
|
+ {
|
|
|
37
|
+ DKVector3 position;
|
|
|
38
|
+ DKVector3 color;
|
|
|
39
|
+ };
|
|
|
40
|
+ DKArray<Vertex> vertexData =
|
|
|
41
|
+ {
|
|
|
42
|
+ { { 1.0f, 1.0f, 0.0f },{ 1.0f, 0.0f, 0.0f } },
|
|
|
43
|
+ { { -1.0f, 1.0f, 0.0f },{ 0.0f, 1.0f, 0.0f } },
|
|
|
44
|
+ { { 0.0f, -1.0f, 0.0f },{ 0.0f, 0.0f, 1.0f } }
|
|
|
45
|
+ };
|
|
|
46
|
+ uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
|
|
|
47
|
+ DKArray<uint32_t> indexData = { 0, 1, 2 };
|
|
|
48
|
+ uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
|
|
|
49
|
+
|
|
|
50
|
+ DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
|
|
|
51
|
+ memcpy(vertexBuffer->Lock(), vertexData, vertexBufferSize);
|
|
|
52
|
+ vertexBuffer->Unlock();
|
|
|
53
|
+
|
|
|
54
|
+ DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
|
|
|
55
|
+ memcpy(indexBuffer->Lock(), indexData, indexBufferSize);
|
|
|
56
|
+ indexBuffer->Unlock();
|
34
|
|
57
|
|
35
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
58
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
36
|
pipelineDescriptor.vertexFunction = vertShaderFunction;
|
59
|
pipelineDescriptor.vertexFunction = vertShaderFunction;
|
|
|
|
|
38
|
pipelineDescriptor.colorAttachments.Resize(1);
|
61
|
pipelineDescriptor.colorAttachments.Resize(1);
|
39
|
pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
|
62
|
pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
|
40
|
pipelineDescriptor.rasterizationEnabled = true;
|
63
|
pipelineDescriptor.rasterizationEnabled = true;
|
41
|
-
|
|
|
|
|
64
|
+ pipelineDescriptor.vertexDescriptor.attributes = {
|
|
|
65
|
+ { DKVertexFormat::Float4, 0, 0, 0 },
|
|
|
66
|
+ { DKVertexFormat::Float4, sizeof(DKVector3), 0, 1 },
|
|
|
67
|
+ };
|
|
|
68
|
+ pipelineDescriptor.vertexDescriptor.layouts = {
|
|
|
69
|
+ { DKVertexStepRate::Vertex, 0, 0 },
|
|
|
70
|
+ };
|
42
|
|
71
|
|
43
|
DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, NULL);
|
72
|
DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, NULL);
|
44
|
|
73
|
|