|
|
|
|
243
|
indexBuffer->Flush();
|
243
|
indexBuffer->Flush();
|
244
|
|
244
|
|
245
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
245
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
|
|
246
|
+ // setup shader
|
246
|
pipelineDescriptor.vertexFunction = vertShaderFunction;
|
247
|
pipelineDescriptor.vertexFunction = vertShaderFunction;
|
247
|
pipelineDescriptor.fragmentFunction = fragShaderFunction;
|
248
|
pipelineDescriptor.fragmentFunction = fragShaderFunction;
|
|
|
249
|
+ // setup color-attachment render-targets
|
248
|
pipelineDescriptor.colorAttachments.Resize(1);
|
250
|
pipelineDescriptor.colorAttachments.Resize(1);
|
249
|
pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
|
251
|
pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
|
250
|
pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = false;
|
252
|
pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = false;
|
251
|
pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
|
253
|
pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
|
252
|
pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
|
254
|
pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
|
253
|
- pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::D32Float; // no depth buffer
|
|
|
254
|
- pipelineDescriptor.vertexDescriptor.attributes = {
|
|
|
|
|
255
|
+ // setup depth-stencil
|
|
|
256
|
+ pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::D32Float;
|
|
|
257
|
+ pipelineDescriptor.depthStencilDescriptor.depthWriteEnabled = true;
|
|
|
258
|
+ pipelineDescriptor.depthStencilDescriptor.depthCompareFunction = DKCompareFunctionLessEqual;
|
|
|
259
|
+ // setup vertex buffer and attributes
|
|
|
260
|
+ pipelineDescriptor.vertexDescriptor.attributes = {
|
255
|
{ DKVertexFormat::Float3, offsetof(SampleObjMesh::Vertex, inPos), 0, 0 },
|
261
|
{ DKVertexFormat::Float3, offsetof(SampleObjMesh::Vertex, inPos), 0, 0 },
|
256
|
{ DKVertexFormat::Float3, offsetof(SampleObjMesh::Vertex, inColor), 0, 1 },
|
262
|
{ DKVertexFormat::Float3, offsetof(SampleObjMesh::Vertex, inColor), 0, 1 },
|
257
|
{ DKVertexFormat::Float2, offsetof(SampleObjMesh::Vertex, intexCoord), 0, 2 },
|
263
|
{ DKVertexFormat::Float2, offsetof(SampleObjMesh::Vertex, intexCoord), 0, 2 },
|
|
|
|
|
259
|
pipelineDescriptor.vertexDescriptor.layouts = {
|
265
|
pipelineDescriptor.vertexDescriptor.layouts = {
|
260
|
{ DKVertexStepRate::Vertex, sizeof(SampleObjMesh::Vertex), 0 },
|
266
|
{ DKVertexStepRate::Vertex, sizeof(SampleObjMesh::Vertex), 0 },
|
261
|
};
|
267
|
};
|
|
|
268
|
+ // setup topology and rasterization
|
262
|
pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
|
269
|
pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
|
263
|
pipelineDescriptor.frontFace = DKFrontFace::CCW;
|
270
|
pipelineDescriptor.frontFace = DKFrontFace::CCW;
|
264
|
pipelineDescriptor.triangleFillMode = DKTriangleFillMode::Fill;
|
271
|
pipelineDescriptor.triangleFillMode = DKTriangleFillMode::Fill;
|
|
|
|
|
266
|
pipelineDescriptor.cullMode = DKCullMode::Back;
|
273
|
pipelineDescriptor.cullMode = DKCullMode::Back;
|
267
|
pipelineDescriptor.rasterizationEnabled = true;
|
274
|
pipelineDescriptor.rasterizationEnabled = true;
|
268
|
|
275
|
|
269
|
-
|
|
|
270
|
- pipelineDescriptor.depthStencilDescriptor.depthWriteEnabled = true;
|
|
|
271
|
- pipelineDescriptor.depthStencilDescriptor.depthCompareFunction = DKCompareFunction::DKCompareFunctionLess;
|
|
|
272
|
- pipelineDescriptor.depthStencilDescriptor.frontFaceStencil.stencilCompareFunction = DKCompareFunction::DKCompareFunctionNever;
|
|
|
273
|
- pipelineDescriptor.depthStencilDescriptor.backFaceStencil.stencilCompareFunction = DKCompareFunction::DKCompareFunctionNever;
|
|
|
274
|
-
|
|
|
275
|
DKPipelineReflection reflection;
|
276
|
DKPipelineReflection reflection;
|
276
|
DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
|
277
|
DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
|
277
|
if (pipelineState)
|
278
|
if (pipelineState)
|
|
|
|
|
333
|
DKObject<DKTexture> depthBuffer = nullptr;
|
334
|
DKObject<DKTexture> depthBuffer = nullptr;
|
334
|
|
335
|
|
335
|
DKCamera camera;
|
336
|
DKCamera camera;
|
336
|
- DKVector3 cameraPosition = { 0, 0, 10 };
|
|
|
|
|
337
|
+ DKVector3 cameraPosition = { 0, 5, 10 };
|
337
|
DKVector3 cameraTartget = { 0, 0, 0 };
|
338
|
DKVector3 cameraTartget = { 0, 0, 0 };
|
338
|
|
339
|
|
339
|
- DKAffineTransform3 tm(DKLinearTransform3().Scale(4));
|
|
|
|
|
340
|
+ DKAffineTransform3 tm(DKLinearTransform3().Scale(5).Rotate(DKVector3(-1,0,0), DKGL_PI * 0.5));
|
340
|
|
341
|
|
341
|
DKTimer timer;
|
342
|
DKTimer timer;
|
342
|
timer.Reset();
|
343
|
timer.Reset();
|