|
@@ -65,12 +65,6 @@ public:
|
65
|
65
|
DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
|
66
|
66
|
DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
|
67
|
67
|
|
68
|
|
- // create texture
|
69
|
|
- DKObject<DKTexture> texture = LoadTexture2D(queue, resourcePool.LoadResourceData("textures/deathstar3.png"));
|
70
|
|
- // create sampler
|
71
|
|
- DKSamplerDescriptor samplerDesc = {};
|
72
|
|
- DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
|
73
|
|
-
|
74
|
68
|
// create shaders
|
75
|
69
|
DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
|
76
|
70
|
DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
|
|
@@ -95,10 +89,10 @@ public:
|
95
|
89
|
};
|
96
|
90
|
DKArray<Vertex> vertexData =
|
97
|
91
|
{
|
98
|
|
- { { 1.0f, 1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
|
99
|
|
- { { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
|
100
|
|
- { { -1.0f, -1.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
|
101
|
|
- { { 1.0f, -1.0f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }
|
|
92
|
+ { { 0.5f, 0.5f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
|
|
93
|
+ { { -0.5f, 0.5f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
|
|
94
|
+ { { -0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
|
|
95
|
+ { { 0.5f, -0.5f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } }
|
102
|
96
|
};
|
103
|
97
|
uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
|
104
|
98
|
DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
|
@@ -117,6 +111,9 @@ public:
|
117
|
111
|
pipelineDescriptor.fragmentFunction = fragShaderFunction;
|
118
|
112
|
pipelineDescriptor.colorAttachments.Resize(1);
|
119
|
113
|
pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
|
|
114
|
+ pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = true;
|
|
115
|
+ pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
|
|
116
|
+ pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
|
120
|
117
|
pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
|
121
|
118
|
pipelineDescriptor.vertexDescriptor.attributes = {
|
122
|
119
|
{ DKVertexFormat::Float3, 0, 0, 0 },
|
|
@@ -143,13 +140,21 @@ public:
|
143
|
140
|
DKShaderBindingSetLayout layout;
|
144
|
141
|
if (1)
|
145
|
142
|
{
|
146
|
|
- DKShaderBinding binding = {
|
147
|
|
- 0,
|
148
|
|
- DKShader::DescriptorTypeUniformBuffer,
|
149
|
|
- 1,
|
150
|
|
- nullptr
|
|
143
|
+ DKShaderBinding bindings[2] = {
|
|
144
|
+ {
|
|
145
|
+ 0,
|
|
146
|
+ DKShader::DescriptorTypeUniformBuffer,
|
|
147
|
+ 1,
|
|
148
|
+ nullptr
|
|
149
|
+ },
|
|
150
|
+ {
|
|
151
|
+ 1,
|
|
152
|
+ DKShader::DescriptorTypeTextureSampler,
|
|
153
|
+ 1,
|
|
154
|
+ nullptr
|
|
155
|
+ },
|
151
|
156
|
};
|
152
|
|
- layout.bindings.Add(binding);
|
|
157
|
+ layout.bindings.Add(bindings, 2);
|
153
|
158
|
}
|
154
|
159
|
DKObject<DKShaderBindingSet> bindSet = device->CreateShaderBindingSet(layout);
|
155
|
160
|
if (bindSet)
|
|
@@ -172,6 +177,15 @@ public:
|
172
|
177
|
bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
|
173
|
178
|
uboBuffer->Flush();
|
174
|
179
|
}
|
|
180
|
+
|
|
181
|
+ // create texture
|
|
182
|
+ DKObject<DKTexture> texture = LoadTexture2D(queue, resourcePool.LoadResourceData("textures/deathstar3.png"));
|
|
183
|
+ // create sampler
|
|
184
|
+ DKSamplerDescriptor samplerDesc = {};
|
|
185
|
+ DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
|
|
186
|
+
|
|
187
|
+ bindSet->SetTexture(1, texture);
|
|
188
|
+ bindSet->SetSamplerState(1, sampler);
|
175
|
189
|
}
|
176
|
190
|
|
177
|
191
|
DKTimer timer;
|