瀏覽代碼

no message

Hongtae Kim 5 年之前
父節點
當前提交
60573dbba3

+ 6
- 6
Samples/Common/util.h 查看文件

@@ -220,8 +220,8 @@ void PrintShaderReflection(const DKShader* shader, DKLogCategory c = DKLogCatego
220 220
     for (int i = 0; i < shader->InputAttributes().Count(); ++i)
221 221
     {
222 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 226
     DKLog(c, "---------------------------------------------------------");
227 227
     DKLog(c, "Shader<%ls.SPIR-V>.OutputAttributes: %d",
@@ -229,8 +229,8 @@ void PrintShaderReflection(const DKShader* shader, DKLogCategory c = DKLogCatego
229 229
     for (int i = 0; i < shader->OutputAttributes().Count(); ++i)
230 230
     {
231 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 235
     DKLog(c, "---------------------------------------------------------");
236 236
     DKLog(c, "Shader<%ls.SPIR-V>.Resources: %d",
@@ -254,8 +254,8 @@ void PrintPipelineReflection(const DKPipelineReflection* reflection, DKLogCatego
254 254
     for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
255 255
     {
256 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 260
     DKLog(c, "---------------------------------------------------------");
261 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,4 +1,4 @@
1
-
1
+#include <cstddef>
2 2
 #include "app.h"
3 3
 #include "util.h"
4 4
 
@@ -10,14 +10,41 @@ class TextureDemo : public SampleApp
10 10
 	DKAtomicNumber32 runningRenderThread;
11 11
 
12 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 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 40
 		DKShader vertShader(vertData);
18 41
 		DKShader fragShader(fragData);
19 42
 
20 43
 		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
44
+
45
+        // create texture
46
+        DKObject<DKTexture> texture = LoadTexture2D(device, resourcePool.LoadResourceData("textures/deathstar3.png"));
47
+
21 48
 		DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
22 49
 		DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
23 50
 
@@ -36,17 +63,19 @@ public:
36 63
 
37 64
 		struct Vertex
38 65
 		{
39
-			DKVector3 position;
40
-			DKVector3 color;
66
+			DKVector3 inPos;
67
+            DKVector2 inUV;
68
+            DKVector3 inNormal;
41 69
 		};
42 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 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 79
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
51 80
 
52 81
 		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
@@ -65,7 +94,8 @@ public:
65 94
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
66 95
 		pipelineDescriptor.vertexDescriptor.attributes = {
67 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 100
 		pipelineDescriptor.vertexDescriptor.layouts = {
71 101
 			{ DKVertexStepRate::Vertex, sizeof(Vertex), 0 },

+ 2
- 2
Samples/Triangle/Triangle.cpp 查看文件

@@ -12,8 +12,8 @@ class TriangleDemo : public SampleApp
12 12
 public:
13 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 17
 		DKShader vertShader(vertData);
18 18
 		DKShader fragShader(fragData);
19 19