Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
92ccc201
Commit
92ccc201
authored
Jul 17, 2013
by
Maciej Sumiński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Headers containing shader program sources are generated using CMake.
parent
bbc0e8eb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
61 deletions
+55
-61
Shaders.cmake
CMakeModules/Shaders.cmake
+44
-0
CMakeLists.txt
common/CMakeLists.txt
+11
-8
make_shader_src_h.sh
common/gal/opengl/make_shader_src_h.sh
+0
-53
No files found.
CMakeModules/Shaders.cmake
0 → 100644
View file @
92ccc201
# CMake script file to process a GLSL source file, so it can be included
# in C array and compiled in to an application.
# number of input files
list
(
LENGTH inputFiles shadersNumber
)
# write header
file
(
WRITE
${
outputFile
}
"// Do not edit this file, it is autogenerated by CMake.
#ifndef SHADER_SRC_H
#define SHADER_SRC_H
const unsigned int shaders_number =
${
shadersNumber
}
;
const char *shaders_src[] = {
\n
"
)
foreach
(
inputFile
${
inputFiles
}
)
# put the input file name into the output file
file
(
APPEND
${
outputFile
}
"
\n
//
${
inputFile
}
"
)
# process the input file
file
(
READ
${
inputFile
}
contents
)
# remove /* */ comments
string
(
REGEX REPLACE
"/
\\
*.*
\\
*/"
""
contents
"
${
contents
}
"
)
# remove // comments
string
(
REGEX REPLACE
"//[^
\n
]*"
""
contents
"
${
contents
}
"
)
# remove whitespaces at the beginning of each line
string
(
REGEX REPLACE
"
\n
([
\t
])*"
"
\n
"
contents
"
${
contents
}
"
)
# remove unnecessary spaces
string
(
REGEX REPLACE
" *([
\\
*/+&
\\
|,=<>
\(\)
]) *"
"
\\
1"
contents
"
${
contents
}
"
)
# remove empty lines & wrap every line in "" and add '\n' at the end of each line
string
(
REGEX REPLACE
"
\n
+"
"
\\\\
n
\"\n\"
"
contents
"
${
contents
}
"
)
# remove unnecessary " & \n from the beginning and the end of contents
string
(
REGEX REPLACE
"^
\\\\
n
\"
"
""
contents
"
${
contents
}
"
)
string
(
REGEX REPLACE
"
\"
$"
","
contents
"
${
contents
}
"
)
file
(
APPEND
${
outputFile
}
"
${
contents
}
"
)
endforeach
(
inputFile
${
inputFiles
}
)
# write footer
file
(
APPEND
${
outputFile
}
"};
#endif /* SHADER_SRC_H */"
)
common/CMakeLists.txt
View file @
92ccc201
...
...
@@ -11,17 +11,20 @@ include_directories(
${
INC_AFTER
}
)
# Generate files containing shader programs
add_custom_command
(
# Generate header files containing shader programs
# Order of input files is significant
add_custom_command
(
OUTPUT gal/opengl/shader_src.h
DEPENDS gal/opengl/make_shader_src_h.sh
COMMAND
${
CMAKE_COMMAND
}
-DinputFiles=
"
${
PROJECT_SOURCE_DIR
}
/common/gal/opengl/shader.vert
\\
;
${
PROJECT_SOURCE_DIR
}
/common/gal/opengl/shader.frag"
-DoutputFile=
"shader_src.h"
-P
${
CMAKE_MODULE_PATH
}
/Shaders.cmake
WORKING_DIRECTORY
${
PROJECT_SOURCE_DIR
}
/common/gal/opengl
COMMAND
${
SHELL
}
ARGS
${
PROJECT_SOURCE_DIR
}
/common/gal/opengl/make_shader_src_h.sh
COMMENT
"Generating headers containing GLSL source code"
)
add_custom_target
(
ShaderHeader
ALL
add_custom_target
(
shader_headers
ALL
DEPENDS gal/opengl/shader_src.h
)
...
...
@@ -40,7 +43,7 @@ set(GAL_SRCS
)
add_library
(
gal STATIC
${
GAL_SRCS
}
)
add_dependencies
(
gal
ShaderHeader
)
add_dependencies
(
gal
shader_headers
)
if
(
WIN32
)
add_definitions
(
-DGLEW_STATIC
)
...
...
common/gal/opengl/make_shader_src_h.sh
deleted
100755 → 0
View file @
bbc0e8eb
#!/bin/bash
# Make a header file containing GLSL source code
echo
"Generating headers containing GLSL source code.."
# Source files to be included
SHADER_SRC
=(
"shader.vert"
"shader.frag"
)
# Number of shaders
SHADERS_NUMBER
=
${#
SHADER_SRC
[@]
}
OUTPUT
=
"shader_src.h"
UPDATE
=
false
# Check if it is necessary to regenerate headers
for
filename
in
"
${
SHADER_SRC
[@]
}
"
do
if
[[
$filename
-nt
$OUTPUT
]]
;
then
UPDATE
=
true
fi
done
if
[[
$UPDATE
==
false
]]
;
then
echo
"Headers are up-to-date."
exit
fi
# Prepare GLSL source to be included in C array
function
processSrc
{
# 1st part: remove /* */ comments
# 2nd part: remove // comments
# 3rd part: remove blank lines (or containing only whitespaces)
# 4th & 5th part: wrap every line in quotation marks
sed
'/\/\*/,/\*\//d; s/[ \t]*\/\/.*$//; /^[ \t]*$/d; s/^[ \t]*/"/; s/[ \t]*$/\\n"/'
$1
>>
$OUTPUT
echo
","
>>
$OUTPUT
}
# Header
echo
"#ifndef SHADER_SRC_H
#define SHADER_SRC_H
const unsigned int shaders_number =
$SHADERS_NUMBER
;
const char *shaders_src[] = {"
>
$OUTPUT
# Main contents
for
filename
in
"
${
SHADER_SRC
[@]
}
"
do
processSrc
$filename
done
# Footer
echo
"};
#endif /* SHADER_SRC_H */"
>>
$OUTPUT
echo
"Done."
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment