Sfoglia il codice sorgente

setup vertex, index buffer

Hongtae Kim 6 anni fa
parent
commit
22f434db31
1 ha cambiato i file con 30 aggiunte e 1 eliminazioni
  1. 30
    1
      TestApp1/TestApp1.cpp

+ 30
- 1
TestApp1/TestApp1.cpp Vedi File

@@ -6,6 +6,7 @@
6 6
 #endif
7 7
 #include <DK.h>
8 8
 
9
+
9 10
 class TestApp1 : public DKApplication
10 11
 {
11 12
 	DKObject<DKWindow> window;
@@ -31,6 +32,28 @@ public:
31 32
 		DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
32 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 58
 		DKRenderPipelineDescriptor pipelineDescriptor;
36 59
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
@@ -38,7 +61,13 @@ public:
38 61
 		pipelineDescriptor.colorAttachments.Resize(1);
39 62
 		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
40 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 72
 		DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, NULL);
44 73