init
This commit is contained in:
commit
444f800536
122 changed files with 17137 additions and 0 deletions
4
Chapter01/01_CMake/CMakeLists.txt
Normal file
4
Chapter01/01_CMake/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
project(Chapter01)
|
||||
include(../../CMake/CommonMacros.txt)
|
||||
SETUP_APP(Ch01_Sample01_Cmake "Chapter 01")
|
||||
6
Chapter01/01_CMake/src/main.cpp
Normal file
6
Chapter01/01_CMake/src/main.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "stdio.h"
|
||||
|
||||
int main() {
|
||||
printf("Hello World!\n");
|
||||
return 0;
|
||||
}
|
||||
7
Chapter01/02_GLFW/CMakeLists.txt
Normal file
7
Chapter01/02_GLFW/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
project(Chapter01)
|
||||
include(../../CMake/CommonMacros.txt)
|
||||
SETUP_APP(Ch01_Sample02_GLFW "Chapter 01")
|
||||
|
||||
target_include_directories(Ch01_Sample02_GLFW PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
target_link_libraries(Ch01_Sample02_GLFW SharedUtils)
|
||||
17
Chapter01/02_GLFW/src/main.cpp
Normal file
17
Chapter01/02_GLFW/src/main.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <cstdint>
|
||||
#include <shared/HelpersGLFW.h>
|
||||
|
||||
int main() {
|
||||
uint32_t width = 1280;
|
||||
uint32_t height = 720;
|
||||
|
||||
GLFWwindow *window = initWindow("GLFW Example", width, height);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
7
Chapter01/03_Taskflow/CMakeLists.txt
Normal file
7
Chapter01/03_Taskflow/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
project(Chapter01)
|
||||
include(../../CMake/CommonMacros.txt)
|
||||
SETUP_APP(Ch01_03_Taskflow "Chapter 01")
|
||||
|
||||
target_include_directories(Ch01_03_Taskflow PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
target_link_libraries(Ch01_03_Taskflow SharedUtils)
|
||||
17
Chapter01/03_Taskflow/src/main.cpp
Normal file
17
Chapter01/03_Taskflow/src/main.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <cstdio>
|
||||
#include <taskflow/taskflow.hpp>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
tf::Executor executor;
|
||||
tf::Taskflow taskflow;
|
||||
|
||||
auto [A, B, C, D] = taskflow.emplace(
|
||||
[]() { std::cout << "TaskA\n"; }, []() { std::cout << "TaskB\n"; },
|
||||
[]() { std::cout << "TaskC\n"; }, []() { std::cout << "TaskD\n"; });
|
||||
|
||||
A.precede(B, C);
|
||||
D.succeed(B, C);
|
||||
|
||||
executor.run(taskflow).wait();
|
||||
return 0;
|
||||
}
|
||||
7
Chapter01/04_GLSLang/CMakeLists.txt
Normal file
7
Chapter01/04_GLSLang/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
project(Chapter01)
|
||||
include(../../CMake/CommonMacros.txt)
|
||||
SETUP_APP(Ch01_04_GLSLang "Chapter 01")
|
||||
|
||||
target_include_directories(Ch01_04_GLSLang PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
target_link_libraries(Ch01_04_GLSLang SharedUtils)
|
||||
39
Chapter01/04_GLSLang/src/main.cpp
Normal file
39
Chapter01/04_GLSLang/src/main.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "glslang/Include/glslang_c_interface.h"
|
||||
#include "glslang/Public/resource_limits_c.h"
|
||||
#include "vulkan/VulkanUtils.h"
|
||||
#include <cstdio>
|
||||
#include <shared/HelpersGLFW.h>
|
||||
#include <shared/Utils.h>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
void saveSpirvBinaryFile(const char *filename, const uint8_t *code,
|
||||
size_t size) {
|
||||
FILE *f = fopen(filename, "wb");
|
||||
fwrite(code, sizeof(uint8_t), size, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void testShaderCompilation(const char *sourceFilename,
|
||||
const char *destFilename) {
|
||||
std::string shaderSource = readShaderFile(sourceFilename);
|
||||
std::vector<uint8_t> spirv;
|
||||
|
||||
lvk::Result res = lvk::compileShader(
|
||||
vkShaderStageFromFileName(sourceFilename), shaderSource.c_str(), &spirv,
|
||||
glslang_default_resource());
|
||||
|
||||
saveSpirvBinaryFile(destFilename, spirv.data(), spirv.size());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
glslang_initialize_process();
|
||||
|
||||
testShaderCompilation("Chapter01/04_GLSLang/src/main.vert",
|
||||
".cache/04_GLSLang.vert.bin");
|
||||
testShaderCompilation("Chapter01/04_GLSLang/src/main.frag",
|
||||
".cache/04_GLSLang.frag.bin");
|
||||
|
||||
glslang_finalize_process();
|
||||
return 0;
|
||||
}
|
||||
11
Chapter01/04_GLSLang/src/main.frag
Normal file
11
Chapter01/04_GLSLang/src/main.frag
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(texCoord.x, texCoord.y, 1.0, 1.0);
|
||||
}
|
||||
28
Chapter01/04_GLSLang/src/main.vert
Normal file
28
Chapter01/04_GLSLang/src/main.vert
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
layout(location = 1) out vec2 texCoord;
|
||||
|
||||
vec2 positions[3] = vec2[](
|
||||
vec2(0.0, -0.5),
|
||||
vec2(0.5, 0.5),
|
||||
vec2(-0.5, 0.5)
|
||||
);
|
||||
|
||||
vec3 colors[3] = vec3[](
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec3(0.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
vec2 texcoords[3] = vec2[](
|
||||
vec2(1.0f, 0.0f),
|
||||
vec2(0.0f, 0.0f),
|
||||
vec2(0.0f, 1.0f)
|
||||
);
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||
fragColor = colors[gl_VertexIndex];
|
||||
texCoord = texcoords[gl_VertexIndex];
|
||||
}
|
||||
7
Chapter01/05_BC7Compression/CMakeLists.txt
Normal file
7
Chapter01/05_BC7Compression/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
project(Chapter01)
|
||||
include(../../CMake/CommonMacros.txt)
|
||||
SETUP_APP(Ch01_05_BC7Compression "Chapter 01")
|
||||
|
||||
target_include_directories(Ch01_05_BC7Compression PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
target_link_libraries(Ch01_05_BC7Compression SharedUtils)
|
||||
95
Chapter01/05_BC7Compression/src/main.cpp
Normal file
95
Chapter01/05_BC7Compression/src/main.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ktx-software/lib/gl_format.h>
|
||||
#include <ktx-software/lib/vkformat_enum.h>
|
||||
#include <ktx.h>
|
||||
|
||||
#include <stb/stb_image.h>
|
||||
#include <stb/stb_image_resize2.h>
|
||||
|
||||
#include <lvk/LVK.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
const int numChannels = 4;
|
||||
int origW, origH;
|
||||
const uint8_t *pixels =
|
||||
stbi_load("data/wood.jpg", &origW, &origH, nullptr, numChannels);
|
||||
|
||||
assert(pixels);
|
||||
|
||||
const uint32_t numMipLevels = lvk::calcNumMipLevels(origW, origH);
|
||||
|
||||
ktxTextureCreateInfo createInfoKTX2 = {
|
||||
.glInternalformat = GL_RGBA8,
|
||||
.vkFormat = VK_FORMAT_BC7_UNORM_BLOCK,
|
||||
.baseWidth = (uint32_t)origW,
|
||||
.baseHeight = (uint32_t)origH,
|
||||
.baseDepth = 1u,
|
||||
.numDimensions = 2u,
|
||||
.numLevels = numMipLevels,
|
||||
.numLayers = 1u,
|
||||
.numFaces = 1u,
|
||||
.generateMipmaps = KTX_FALSE,
|
||||
};
|
||||
ktxTexture2 *textureKTX2 = nullptr;
|
||||
(void)LVK_VERIFY(ktxTexture2_Create(&createInfoKTX2,
|
||||
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
|
||||
&textureKTX2) == KTX_SUCCESS);
|
||||
|
||||
int w = origW;
|
||||
int h = origH;
|
||||
|
||||
for (uint32_t i = 0; i != numMipLevels; ++i) {
|
||||
size_t offset = 0;
|
||||
ktxTexture_GetImageOffset(ktxTexture(textureKTX2), i, 0, 0, &offset);
|
||||
|
||||
stbir_resize_uint8_linear((const unsigned char *)pixels, origW, origH, 0,
|
||||
ktxTexture_GetData(ktxTexture(textureKTX2)) +
|
||||
offset,
|
||||
w, h, 0, STBIR_RGBA);
|
||||
|
||||
h = h > 1 ? h >> 1 : 1;
|
||||
w = w > 1 ? w >> 1 : 1;
|
||||
}
|
||||
|
||||
(void)LVK_VERIFY(ktxTexture2_CompressBasis(textureKTX2, 255) == KTX_SUCCESS);
|
||||
(void)LVK_VERIFY(ktxTexture2_TranscodeBasis(textureKTX2, KTX_TTF_BC7_RGBA,
|
||||
0) == KTX_SUCCESS);
|
||||
|
||||
// convert to KTX1
|
||||
ktxTextureCreateInfo createInfoKTX1 = {
|
||||
.glInternalformat = GL_COMPRESSED_RGBA_BPTC_UNORM,
|
||||
.vkFormat = VK_FORMAT_BC7_UNORM_BLOCK,
|
||||
.baseWidth = (uint32_t)origW,
|
||||
.baseHeight = (uint32_t)origH,
|
||||
.baseDepth = 1u,
|
||||
.numDimensions = 2u,
|
||||
.numLevels = numMipLevels,
|
||||
.numLayers = 1u,
|
||||
.numFaces = 1u,
|
||||
.generateMipmaps = KTX_FALSE,
|
||||
};
|
||||
ktxTexture1 *textureKTX1 = nullptr;
|
||||
(void)LVK_VERIFY(ktxTexture1_Create(&createInfoKTX1,
|
||||
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
|
||||
&textureKTX1) == KTX_SUCCESS);
|
||||
|
||||
for (uint32_t i = 0; i != numMipLevels; ++i) {
|
||||
size_t offset1 = 0;
|
||||
(void)LVK_VERIFY(ktxTexture_GetImageOffset(ktxTexture(textureKTX1), i, 0, 0,
|
||||
&offset1) == KTX_SUCCESS);
|
||||
size_t offset2 = 0;
|
||||
(void)LVK_VERIFY(ktxTexture_GetImageOffset(ktxTexture(textureKTX2), i, 0, 0,
|
||||
&offset2) == KTX_SUCCESS);
|
||||
memcpy(ktxTexture_GetData(ktxTexture(textureKTX1)) + offset1,
|
||||
ktxTexture_GetData(ktxTexture(textureKTX2)) + offset2,
|
||||
ktxTexture_GetImageSize(ktxTexture(textureKTX1), i));
|
||||
}
|
||||
|
||||
ktxTexture_WriteToNamedFile(ktxTexture(textureKTX1), ".cache/image.ktx");
|
||||
ktxTexture_Destroy(ktxTexture(textureKTX1));
|
||||
ktxTexture_Destroy(ktxTexture(textureKTX2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue