summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh
blob: 6637dd96386fc78d0dd1f6cbdde6e6d07a56cdcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash

# This script will generate a C file containing all the shaders used by Evas_3D

DIR=`dirname $0`

OUTPUT=${DIR}/evas_gl_3d_shaders.x

# Skip generation if there is no diff (or no git)
if ! git rev-parse 2>> /dev/null >> /dev/null ; then exit 0 ; fi
if git diff --quiet --exit-code -- "$DIR"
then
  touch "${OUTPUT}"
  exit 0
fi

exec 1<&-
exec 1>${OUTPUT}

SHADERS="$@"
vert_shaders_source=""
frag_shaders_source=""

# Write header
printf "/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */\n\n"
for shd in ${SHADERS} ; do
  lname=`basename ${shd} .shd`

  if echo ${lname} |grep _vert 2>&1 >> /dev/null ; then
    vert_shaders_source="${vert_shaders_source}    ${lname}_glsl,\n"
  fi
  if echo ${lname} |grep _frag 2>&1 >> /dev/null ; then
    frag_shaders_source="${frag_shaders_source}    ${lname}_glsl,\n"
  fi

  m4 ${DIR}/include.shd ${shd} > ${shd}.tmp

  OIFS=$IFS
  IFS=$'\n'
  printf "static const char ${lname}_glsl[] ="
  for line in `cat ${shd}.tmp` ; do
      printf "\n   \"${line}\\\n\""
  done
  printf ";\n\n"
  IFS=${OIFS}

  rm ${shd}.tmp
done

printf "static const char *vertex_shaders[] =
{\n"
      printf "${vert_shaders_source}"
printf "};\n\n"

printf "static const char *fragment_shaders[] =
{\n"
      printf "${frag_shaders_source}"
printf "};\n"