64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import os
|
|
|
|
GEN_SOURCE_PREFIX = """// IAEngine: 2D Game Engine by IA
|
|
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// ----------------------------------------------------------------------
|
|
// GENERATED FILE. DO NOT EDIT.
|
|
// ----------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include <IAEngine/Base.hpp>
|
|
|
|
namespace ia::iae
|
|
{
|
|
"""
|
|
|
|
GEN_SOURCE_SUFFIX = """} // namespace ia::iae\n"""
|
|
GEN_SOURCE_PATH = "Src/IAEngine/imp/hpp/EmbeddedShaders.hpp"
|
|
SHADER_SOURCE_PATH = "Src/IAEngine/imp/glsl"
|
|
|
|
SHADER_SOURCE_FILES = [
|
|
"UnlitMesh/UnlitMesh.vert",
|
|
"UnlitMesh/UnlitMesh.frag",
|
|
"PostProcessing/PostProcess.vert",
|
|
"PostProcessing/PostProcess.frag"
|
|
]
|
|
|
|
def file_to_source_array(arrayName, filePath):
|
|
data = b''
|
|
with open(filePath, 'rb') as f:
|
|
data = f.read()
|
|
res = f"CONSTEXPR UINT8 {arrayName}[{len(data)}] = {{\n"
|
|
for d in data:
|
|
res += f"{hex(d)},"
|
|
res += "};\n"
|
|
return res
|
|
|
|
def main():
|
|
with open(GEN_SOURCE_PATH, 'w') as outFile:
|
|
outFile.write(GEN_SOURCE_PREFIX)
|
|
for fileName in SHADER_SOURCE_FILES:
|
|
p = f"{SHADER_SOURCE_PATH}/{fileName}"
|
|
os.system(f"glslc {p} -o {p}.spv")
|
|
src = file_to_source_array(f"SHADER_SOURCE_{fileName.split('/')[-1].upper().replace('.', '_')}", f"{p}.spv")
|
|
outFile.write(f"{src}\n")
|
|
os.remove(f"{p}.spv")
|
|
outFile.write(GEN_SOURCE_SUFFIX)
|
|
|
|
main()
|