2017-10-08 02:19:25 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Generates a simple GL/EGL extension function loader.
|
|
|
|
#
|
|
|
|
# The input is a .txt file, with each function to load on its own line.
|
|
|
|
# If a line starts with a -, it is optional, and will not cause the loader
|
|
|
|
# to fail if it can't load the function. You'll need to check if that function
|
|
|
|
# is NULL before using it.
|
|
|
|
|
2018-08-24 09:33:35 +02:00
|
|
|
if [ $# -ne 2 ]; then
|
2017-10-08 02:19:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
SPEC=$1
|
2018-08-24 09:33:35 +02:00
|
|
|
OUTDIR=$2
|
2017-10-08 02:19:25 +02:00
|
|
|
|
|
|
|
BASE=$(basename "$SPEC" .txt)
|
2018-08-24 09:33:35 +02:00
|
|
|
INCLUDE_GUARD=$(printf %s_%s_H "$OUTDIR" "$BASE" | tr -c [:alnum:] _ | tr [:lower:] [:upper:])
|
2017-10-08 02:19:25 +02:00
|
|
|
|
|
|
|
DECL=""
|
|
|
|
DEFN=""
|
|
|
|
LOADER=""
|
|
|
|
|
|
|
|
DECL_FMT='extern %s %s;'
|
|
|
|
DEFN_FMT='%s %s;'
|
|
|
|
LOADER_FMT='%s = (%s)eglGetProcAddress("%s");'
|
|
|
|
CHECK_FMT='if (!%s) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Unable to load %s");
|
2017-10-08 02:19:25 +02:00
|
|
|
return false;
|
|
|
|
}'
|
|
|
|
|
|
|
|
while read -r COMMAND; do
|
2017-10-09 01:02:41 +02:00
|
|
|
OPTIONAL=0
|
|
|
|
FUNC_PTR_FMT='PFN%sPROC'
|
2017-10-08 02:19:25 +02:00
|
|
|
|
2017-10-09 01:02:41 +02:00
|
|
|
case $COMMAND in
|
|
|
|
-*)
|
|
|
|
OPTIONAL=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $COMMAND in
|
|
|
|
*WL)
|
2017-10-08 02:19:25 +02:00
|
|
|
FUNC_PTR_FMT='PFN%s'
|
2017-10-09 01:02:41 +02:00
|
|
|
;;
|
|
|
|
esac
|
2017-10-08 02:19:25 +02:00
|
|
|
|
2017-10-09 01:02:41 +02:00
|
|
|
COMMAND=${COMMAND#-}
|
2017-10-08 02:19:25 +02:00
|
|
|
FUNC_PTR=$(printf "$FUNC_PTR_FMT" "$COMMAND" | tr [:lower:] [:upper:])
|
|
|
|
|
|
|
|
DECL="$DECL$(printf "\n$DECL_FMT" "$FUNC_PTR" "$COMMAND")"
|
|
|
|
DEFN="$DEFN$(printf "\n$DEFN_FMT" "$FUNC_PTR" "$COMMAND")"
|
|
|
|
LOADER="$LOADER$(printf "\n$LOADER_FMT" "$COMMAND" "$FUNC_PTR" "$COMMAND")"
|
|
|
|
|
2017-10-09 01:02:41 +02:00
|
|
|
if [ $OPTIONAL -eq 0 ]; then
|
2017-10-08 02:19:25 +02:00
|
|
|
LOADER="$LOADER$(printf "\n$CHECK_FMT" "$COMMAND" "$COMMAND")"
|
|
|
|
fi
|
2018-08-24 09:33:35 +02:00
|
|
|
done < "$SPEC"
|
2017-10-08 02:19:25 +02:00
|
|
|
|
2018-08-24 09:33:35 +02:00
|
|
|
cat > "$OUTDIR/$BASE.h" << EOF
|
2017-11-22 02:04:29 +01:00
|
|
|
#ifndef $INCLUDE_GUARD
|
|
|
|
#define $INCLUDE_GUARD
|
2017-10-09 01:02:41 +02:00
|
|
|
|
2017-11-22 02:04:29 +01:00
|
|
|
#include <stdbool.h>
|
2019-04-21 02:35:57 +02:00
|
|
|
#include <wlr/config.h>
|
|
|
|
|
2019-10-16 15:16:53 +02:00
|
|
|
#if !WLR_HAS_X11_BACKEND && !WLR_HAS_XWAYLAND
|
|
|
|
#ifndef MESA_EGL_NO_X11_HEADERS
|
2019-04-21 02:35:57 +02:00
|
|
|
#define MESA_EGL_NO_X11_HEADERS
|
|
|
|
#endif
|
2019-10-16 15:16:53 +02:00
|
|
|
#ifndef EGL_NO_X11
|
|
|
|
#define EGL_NO_X11
|
|
|
|
#endif
|
|
|
|
#endif
|
2017-10-08 02:19:25 +02:00
|
|
|
|
2017-11-22 02:04:29 +01:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
2017-10-08 02:19:25 +02:00
|
|
|
|
2017-11-22 02:04:29 +01:00
|
|
|
bool load_$BASE(void);
|
|
|
|
$DECL
|
2017-10-08 02:19:25 +02:00
|
|
|
|
2017-11-22 02:04:29 +01:00
|
|
|
#endif
|
2017-10-08 02:19:25 +02:00
|
|
|
EOF
|
2017-11-22 02:04:29 +01:00
|
|
|
|
2018-08-24 09:33:35 +02:00
|
|
|
cat > "$OUTDIR/$BASE.c" << EOF
|
2017-11-22 02:04:29 +01:00
|
|
|
#include <wlr/util/log.h>
|
2018-08-24 09:33:35 +02:00
|
|
|
#include "$BASE.h"
|
2017-11-22 02:04:29 +01:00
|
|
|
$DEFN
|
|
|
|
|
|
|
|
bool load_$BASE(void) {
|
|
|
|
static bool done = false;
|
|
|
|
if (done) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$LOADER
|
|
|
|
|
|
|
|
done = true;
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-08 02:19:25 +02:00
|
|
|
EOF
|