init
This commit is contained in:
commit
444f800536
122 changed files with 17137 additions and 0 deletions
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];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue