Hongtae Kim 5 年 前
コミット
60573dbba3

+ 6
- 6
Samples/Common/util.h ファイルの表示

220
     for (int i = 0; i < shader->InputAttributes().Count(); ++i)
220
     for (int i = 0; i < shader->InputAttributes().Count(); ++i)
221
     {
221
     {
222
         const DKShaderAttribute& attr = shader->InputAttributes().Value(i);
222
         const DKShaderAttribute& attr = shader->InputAttributes().Value(i);
223
-        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
224
-            i, (const wchar_t*)attr.name, attr.location);
223
+        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (type:%s, location:%u)",
224
+            i, (const wchar_t*)attr.name, ShaderDataTypeStr(attr.type), attr.location);
225
     }
225
     }
226
     DKLog(c, "---------------------------------------------------------");
226
     DKLog(c, "---------------------------------------------------------");
227
     DKLog(c, "Shader<%ls.SPIR-V>.OutputAttributes: %d",
227
     DKLog(c, "Shader<%ls.SPIR-V>.OutputAttributes: %d",
229
     for (int i = 0; i < shader->OutputAttributes().Count(); ++i)
229
     for (int i = 0; i < shader->OutputAttributes().Count(); ++i)
230
     {
230
     {
231
         const DKShaderAttribute& attr = shader->OutputAttributes().Value(i);
231
         const DKShaderAttribute& attr = shader->OutputAttributes().Value(i);
232
-        DKLog(c, "  [out] ShaderAttribute[%d]: \"%ls\" (location:%u)",
233
-            i, (const wchar_t*)attr.name, attr.location);
232
+        DKLog(c, "  [out] ShaderAttribute[%d]: \"%ls\" (type:%s, location:%u)",
233
+            i, (const wchar_t*)attr.name, ShaderDataTypeStr(attr.type), attr.location);
234
     }
234
     }
235
     DKLog(c, "---------------------------------------------------------");
235
     DKLog(c, "---------------------------------------------------------");
236
     DKLog(c, "Shader<%ls.SPIR-V>.Resources: %d",
236
     DKLog(c, "Shader<%ls.SPIR-V>.Resources: %d",
254
     for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
254
     for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
255
     {
255
     {
256
         const DKShaderAttribute& attr = reflection->inputAttributes.Value(i);
256
         const DKShaderAttribute& attr = reflection->inputAttributes.Value(i);
257
-        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
258
-            i, (const wchar_t*)attr.name, attr.location);
257
+        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (type:%s, location:%u)",
258
+            i, (const wchar_t*)attr.name, ShaderDataTypeStr(attr.type), attr.location);
259
     }
259
     }
260
     DKLog(c, "---------------------------------------------------------");
260
     DKLog(c, "---------------------------------------------------------");
261
     DKLog(c, "PipelineReflection.Resources: %d", reflection->resources.Count());
261
     DKLog(c, "PipelineReflection.Resources: %d", reflection->resources.Count());

Samples/Data/texture.frag → Samples/Data/shaders/texture.frag ファイルの表示


Samples/Data/texture.frag.spv → Samples/Data/shaders/texture.frag.spv ファイルの表示


Samples/Data/texture.vert → Samples/Data/shaders/texture.vert ファイルの表示


Samples/Data/texture.vert.spv → Samples/Data/shaders/texture.vert.spv ファイルの表示


Samples/Data/triangle.frag → Samples/Data/shaders/triangle.frag ファイルの表示


Samples/Data/triangle.frag.spv → Samples/Data/shaders/triangle.frag.spv ファイルの表示


Samples/Data/triangle.vert → Samples/Data/shaders/triangle.vert ファイルの表示


Samples/Data/triangle.vert.spv → Samples/Data/shaders/triangle.vert.spv ファイルの表示


バイナリ
Samples/Data/textures/deathstar3.png ファイルの表示


+ 40
- 10
Samples/Texture/Texture.cpp ファイルの表示

1
-
1
+#include <cstddef>
2
 #include "app.h"
2
 #include "app.h"
3
 #include "util.h"
3
 #include "util.h"
4
 
4
 
10
 	DKAtomicNumber32 runningRenderThread;
10
 	DKAtomicNumber32 runningRenderThread;
11
 
11
 
12
 public:
12
 public:
13
+    DKObject<DKTexture> LoadTexture2D(DKGraphicsDevice* device, DKData* data)
14
+    {
15
+        DKObject<DKImage> image = DKImage::Create(data);
16
+        if (image)
17
+        {
18
+            DKTextureDescriptor texDesc = {};
19
+            texDesc.textureType = DKTexture::Type2D;
20
+            texDesc.pixelFormat = DKPixelFormat::RGBA8Unorm;
21
+            texDesc.width = image->Width();
22
+            texDesc.height = image->Height();
23
+            texDesc.depth = 1;
24
+            texDesc.mipmapLevels = 1;
25
+            texDesc.sampleCount = 1;
26
+            texDesc.arrayLength = 1;
27
+            texDesc.usage = DKTexture::UsageCopyDestination | DKTexture::UsageSampled;
28
+            DKObject<DKTexture> tex = device->CreateTexture(texDesc);
29
+            if (tex)
30
+            {
31
+                DKLog("Texture created!");
32
+            }
33
+        }
34
+        return nullptr;
35
+    }
13
 	void RenderThread(void)
36
 	void RenderThread(void)
14
 	{
37
 	{
15
-		DKObject<DKData> vertData = resourcePool.LoadResourceData("triangle.vert.spv");
16
-		DKObject<DKData> fragData = resourcePool.LoadResourceData("triangle.frag.spv");
38
+		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/texture.vert.spv");
39
+		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/texture.frag.spv");
17
 		DKShader vertShader(vertData);
40
 		DKShader vertShader(vertData);
18
 		DKShader fragShader(fragData);
41
 		DKShader fragShader(fragData);
19
 
42
 
20
 		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
43
 		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
44
+
45
+        // create texture
46
+        DKObject<DKTexture> texture = LoadTexture2D(device, resourcePool.LoadResourceData("textures/deathstar3.png"));
47
+
21
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
48
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
22
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
49
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
23
 
50
 
36
 
63
 
37
 		struct Vertex
64
 		struct Vertex
38
 		{
65
 		{
39
-			DKVector3 position;
40
-			DKVector3 color;
66
+			DKVector3 inPos;
67
+            DKVector2 inUV;
68
+            DKVector3 inNormal;
41
 		};
69
 		};
42
 		DKArray<Vertex> vertexData =
70
 		DKArray<Vertex> vertexData =
43
 		{
71
 		{
44
-			{ {  0.0f, -0.5f, 0.0f },{ 1.0f, 1.0f, 1.0f } },
45
-			{ {  0.5f,  0.5f, 0.0f },{ 0.0f, 1.0f, 0.0f } },
46
-			{ { -0.5f,  0.5f, 0.0f },{ 0.0f, 0.0f, 1.0f } }
72
+            { {  1.0f,  1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
73
+            { { -1.0f,  1.0f, 0.0f }, { 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } },
74
+            { { -1.0f, -1.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } },
75
+            { {  1.0f, -1.0f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }
47
 		};
76
 		};
48
 		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
77
 		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
49
-		DKArray<uint32_t> indexData = { 0, 1, 2 };
78
+        DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
50
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
79
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
51
 
80
 
52
 		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
81
 		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
65
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
94
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
66
 		pipelineDescriptor.vertexDescriptor.attributes = {
95
 		pipelineDescriptor.vertexDescriptor.attributes = {
67
 			{ DKVertexFormat::Float3, 0, 0, 0 },
96
 			{ DKVertexFormat::Float3, 0, 0, 0 },
68
-			{ DKVertexFormat::Float3, sizeof(DKVector3), 0, 1 },
97
+            { DKVertexFormat::Float2, offsetof(Vertex, inUV), 0, 1 },
98
+			{ DKVertexFormat::Float3, offsetof(Vertex, inNormal), 0, 2 },
69
 		};
99
 		};
70
 		pipelineDescriptor.vertexDescriptor.layouts = {
100
 		pipelineDescriptor.vertexDescriptor.layouts = {
71
 			{ DKVertexStepRate::Vertex, sizeof(Vertex), 0 },
101
 			{ DKVertexStepRate::Vertex, sizeof(Vertex), 0 },

+ 2
- 2
Samples/Triangle/Triangle.cpp ファイルの表示

12
 public:
12
 public:
13
 	void RenderThread(void)
13
 	void RenderThread(void)
14
 	{
14
 	{
15
-		DKObject<DKData> vertData = resourcePool.LoadResourceData("triangle.vert.spv");
16
-		DKObject<DKData> fragData = resourcePool.LoadResourceData("triangle.frag.spv");
15
+		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/triangle.vert.spv");
16
+		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/triangle.frag.spv");
17
 		DKShader vertShader(vertData);
17
 		DKShader vertShader(vertData);
18
 		DKShader fragShader(fragData);
18
 		DKShader fragShader(fragData);
19
 
19