summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md1
-rwxr-xr-xbin/build-shaders.js133
-rw-r--r--bin/lazy-update.js12
-rw-r--r--bin/package.json8
-rwxr-xr-xconfigure24
-rw-r--r--gyp/npm_install.gypi20
-rw-r--r--gyp/shaders.gypi6
-rw-r--r--mapboxgl.gyp1
-rw-r--r--scripts/build-shaders.py104
m---------test/suite0
11 files changed, 106 insertions, 205 deletions
diff --git a/.gitignore b/.gitignore
index f8bb8a0b27..bce644c7e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,13 +3,11 @@
*.o
*.actual.png
*.diff.png
-/node_modules
/mason_packages
/config.gypi
/config-ios.gypi
/config/constants_local.cpp
/build
-/bin/node_modules
/include/mbgl/shader/shaders.hpp
/src/shader/shaders_gl.cpp
/src/shader/shaders_gles2.cpp
diff --git a/README.md b/README.md
index 325a9225a1..022377e990 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,6 @@ implemented in C++11, currently targeting iOS, OS X, and Ubuntu Linux.
- `pkg-config` (for build only)
- [Homebrew](http://brew.sh) (for build on OS X)
- Python 2.x (for build only)
- - Node.js (for build only)
# Build instructions
diff --git a/bin/build-shaders.js b/bin/build-shaders.js
deleted file mode 100755
index 329f8063f7..0000000000
--- a/bin/build-shaders.js
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/usr/bin/env node
-'use strict';
-
-var fs = require('fs');
-var path = require('path');
-var mkdirp = require('mkdirp');
-
-try { var glsl = require('mapbox-glsl-optimizer'); } catch(err) {}
-
-module.exports = function(shader_type, prefix, suffix) {
- var name;
- var shaders = {};
-
- var shaderFiles = fs.readdirSync('src/shader');
-
- // Load shaders
- for (var i = 0; i < shaderFiles.length; i++) {
- var parts = shaderFiles[i].match(/^(.+)\.(vertex|fragment)\.glsl$/);
- if (parts) {
- name = parts[1];
- var type = parts[2];
- if (!(name in shaders)) {
- shaders[name] = {};
- }
- shaders[name][type] = fs.readFileSync(path.join('src/shader', shaderFiles[i]), 'utf8');
- }
- }
-
- var preamble = '';
- if (shader_type == 'gles2' || shader_type == 'gles3') {
- preamble = 'precision highp float;';
- } else {
- preamble = '#version 120';
- }
-
- for (var name in shaders) {
- shaders[name].vertex = preamble + '\n' + shaders[name].vertex;
- shaders[name].fragment = preamble + '\n' + shaders[name].fragment;
- }
-
- // Optimize shader
- if (glsl) {
- var target = shader_type == 'gles2' ? glsl.TARGET_OPENGLES20 : (shader_type == 'gles3' ? glsl.TARGET_OPENGLES30 : glsl.TARGET_OPENGL);
-
- var compiler = new glsl.Compiler(target);
- for (name in shaders) {
- var vertex_shader = new glsl.Shader(compiler, glsl.VERTEX_SHADER, shaders[name].vertex);
- if (vertex_shader.compiled()) {
- shaders[name].vertex = vertex_shader.output();
- } else {
- console.warn('failed to optimize %s vertex shader', name);
- process.exit(1);
- }
- vertex_shader.dispose();
-
- var fragment_shader = new glsl.Shader(compiler, glsl.FRAGMENT_SHADER, shaders[name].fragment);
- if (fragment_shader.compiled()) {
- shaders[name].fragment = fragment_shader.output();
- } else {
- console.warn('failed to optimize %s fragment shader', name);
- process.exit(1);
- }
- fragment_shader.dispose();
- }
- compiler.dispose();
- } else {
- console.warn('Not optimizing shaders');
- }
-
-
- // Save to file
- var lines = [];
- var consts = [];
- for (var name in shaders) {
- consts.push(name.toUpperCase() + '_SHADER');
-
- var line = '';
- line += ' {\n';
- line += ' ' + JSON.stringify(shaders[name].vertex) + ',\n';
- line += ' ' + JSON.stringify(shaders[name].fragment) + ',\n';
- line += ' }';
- lines.push(line);
- }
-
- var header = '// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n\n';
- header += '#ifndef MBGL_SHADER_SHADERS\n';
- header += '#define MBGL_SHADER_SHADERS\n';
- header += '\n';
- header += 'namespace mbgl {\n';
- header += '\n';
- header += 'struct shader_source {\n';
- header += ' const char *vertex;\n';
- header += ' const char *fragment;\n';
- header += '};\n';
- header += '\n';
- header += 'enum {\n';
- consts.push('SHADER_COUNT');
- header += ' ' + consts.join(',\n ') + '\n';
- header += '};\n';
- header += '\n';
- header += 'extern const shader_source shaders[SHADER_COUNT];\n';
- header += '\n';
- header += '}\n';
- header += '\n';
- header += '#endif\n';
-
-
- var code = '// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n';
- code += '#include <mbgl/platform/gl.hpp>\n';
- code += prefix + '\n';
- code += '#include <mbgl/shader/shaders.hpp>\n';
- code += '\n';
- code += 'namespace mbgl {\n';
- code += '\n';
- code += 'const shader_source shaders[SHADER_COUNT] = {\n';
- code += lines.join(',\n');
- code += '\n};\n';
- code += '\n}\n';
- code += suffix + '\n';
-
- var header_path = path.join(process.argv[2], 'include/mbgl/shader/shaders.hpp');
- mkdirp.sync(path.dirname(header_path));
- fs.writeFileSync(header_path, header);
- console.warn('wrote file ' + header_path);
- var file_path = path.join(process.argv[2], 'src/shader/shaders_' + shader_type + '.cpp');
- mkdirp.sync(path.dirname(file_path));
- fs.writeFileSync(file_path, code);
- console.warn('wrote file ' + file_path);
-
-};
-
-module.exports('gl', '#ifndef GL_ES_VERSION_2_0', '#endif');
-module.exports('gles2', '#ifdef GL_ES_VERSION_2_0', '#endif');
diff --git a/bin/lazy-update.js b/bin/lazy-update.js
deleted file mode 100644
index 0f3ea81ac5..0000000000
--- a/bin/lazy-update.js
+++ /dev/null
@@ -1,12 +0,0 @@
-var fs = require('fs');
-
-module.exports = function(file, content) {
- try {
- var existing = fs.readFileSync(file, 'utf8');
- if (existing != content) {
- fs.writeFileSync(file, content);
- }
- } catch(err) {
- fs.writeFileSync(file, content);
- }
-};
diff --git a/bin/package.json b/bin/package.json
deleted file mode 100644
index 1df8454600..0000000000
--- a/bin/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "name": "mbgl-native",
- "version": "0.0.1",
- "dependencies": {
- "mapbox-glsl-optimizer": "~0.1.0",
- "mkdirp": "^0.5.0"
- }
-}
diff --git a/configure b/configure
index afb94d4795..edda1c1fa1 100755
--- a/configure
+++ b/configure
@@ -11,22 +11,6 @@ function finish {
}
trap finish EXIT
-# Install node
-if [[ ! -d ~/.nvm ]]; then
- git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
-fi
-set +u
-. ~/.nvm/nvm.sh
-if [ ! `nvm use 0.10 > /dev/null; echo $?` = 0 ]; then
- >&2 echo -en "\033[1m\033[32m* "
- nvm install 0.10
- >&2 echo -en "\033[0m";
-else
- >&2 echo -en "\033[1m\033[32m* "
- nvm use 0.10
- >&2 echo -en "\033[0m";
-fi
-
# Install mason
if [[ ! -d ~/.mason ]]; then
>&2 echo -e "\033[1m\033[32m* Installing Mason\033[0m"
@@ -56,14 +40,8 @@ esac
function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; }
-NODE=`which node || abort 'Cannot find node'`
-NPM=`which npm || abort 'Cannot find npm'`
PYTHON=`which python || abort 'Cannot find python'`
->&2 echo -en "\033[1m\033[32m* Using npm "
->&2 ${NPM} --version
->&2 echo -en "\033[0m";
-
>&2 echo -en "\033[1m\033[32m* Using "
>&2 ${PYTHON} --version
>&2 echo -en "\033[0m";
@@ -84,8 +62,6 @@ CONFIG="# Do not edit. Generated by the configure script.
'libraries': []
},
'variables': {
- 'node': '${NODE}',
- 'npm': '${NPM}',
'python': '${PYTHON}',
"
diff --git a/gyp/npm_install.gypi b/gyp/npm_install.gypi
deleted file mode 100644
index ddd3081ad5..0000000000
--- a/gyp/npm_install.gypi
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- 'targets': [
- { 'target_name': 'npm_install',
- 'type': 'none',
- 'hard_dependency': 1,
- 'actions': [
- {
- 'action_name': 'npm install',
- 'inputs': [
- '../bin/package.json',
- ],
- 'outputs': [
- '../bin/node_modules',
- ],
- 'action': ['./scripts/npm_install.sh', '<@(npm)']
- }
- ],
- },
- ]
-}
diff --git a/gyp/shaders.gypi b/gyp/shaders.gypi
index 9435bd7d9c..edbcb61f23 100644
--- a/gyp/shaders.gypi
+++ b/gyp/shaders.gypi
@@ -4,13 +4,11 @@
'target_name': 'shaders',
'type': 'none',
'hard_dependency': 1,
- 'dependencies': [
- 'npm_install'
- ],
'actions': [
{
'action_name': 'Build Shaders',
'inputs': [
+ '../scripts/build-shaders.py',
'<!@(find src -name "*.glsl")'
],
'outputs': [
@@ -18,7 +16,7 @@
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp',
],
- 'action': ['<@(node)', 'bin/build-shaders.js', '<(SHARED_INTERMEDIATE_DIR)'],
+ 'action': ['<@(python)', 'scripts/build-shaders.py', '<(SHARED_INTERMEDIATE_DIR)', '<@(_inputs)'],
}
],
'direct_dependent_settings': {
diff --git a/mapboxgl.gyp b/mapboxgl.gyp
index cca803b338..69cc31016a 100644
--- a/mapboxgl.gyp
+++ b/mapboxgl.gyp
@@ -2,7 +2,6 @@
'includes': [
'./gyp/common.gypi',
'./gyp/shaders.gypi',
- './gyp/npm_install.gypi',
'./gyp/styles.gypi',
'./gyp/fixtures.gypi',
'./gyp/certificates.gypi',
diff --git a/scripts/build-shaders.py b/scripts/build-shaders.py
new file mode 100644
index 0000000000..c1d7f7f28d
--- /dev/null
+++ b/scripts/build-shaders.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+
+import sys, re, os, errno
+
+
+output_dir = sys.argv[1]
+file_names = sys.argv[2:]
+
+
+def mkdir_p(path):
+ try:
+ os.makedirs(path)
+ except OSError as exc: # Python >2.5
+ if exc.errno == errno.EEXIST and os.path.isdir(path):
+ pass
+ else: raise
+
+# Load all shaders
+shaders = {}
+for file_name in file_names:
+ parts = re.search('/(\w+)\.(vertex|fragment)\.glsl$', file_name)
+ if parts:
+ shader_name = parts.group(1)
+ shader_type = parts.group(2)
+ if not shader_name in shaders:
+ shaders[shader_name] = {}
+ with open(file_name, "r") as f:
+ shaders[shader_name][shader_type] = f.read()
+
+
+def write_header():
+ header = """// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+
+#ifndef MBGL_SHADER_SHADERS
+#define MBGL_SHADER_SHADERS
+
+namespace mbgl {
+
+struct shader_source {
+ const char *vertex;
+ const char *fragment;
+};
+
+enum {
+%s
+ SHADER_COUNT
+};
+
+extern const shader_source shaders[SHADER_COUNT];
+
+}
+
+#endif
+""" % '\n'.join([' %s_SHADER,' % name.upper() for name in shaders.keys()])
+ header_path = os.path.join(output_dir, 'include/mbgl/shader/shaders.hpp')
+ mkdir_p(os.path.dirname(header_path))
+ with open(header_path, 'w') as f: f.write(header)
+
+
+def write_source(shader_platform, prefix, suffix):
+ if shader_platform == 'gles2' or shader_platform == 'gles3':
+ # OpenGL ES
+ preamble = 'precision highp float;';
+ else:
+ # Desktop OpenGL
+ preamble = '#version 120';
+
+ shader_lines = [(""" {{
+ R"{name}_vert({preamble}\n{vertex}){name}_vert",
+ R"{name}_frag({preamble}\n{fragment}){name}_frag",
+ }},
+""").format(
+ name = shader,
+ preamble = preamble,
+ vertex = shaders[shader]['vertex'],
+ fragment = shaders[shader]['fragment']
+) for shader in shaders]
+
+ source = """// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+#include <mbgl/platform/gl.hpp>
+{prefix}
+#include <mbgl/shader/shaders.hpp>
+
+namespace mbgl {{
+
+const shader_source shaders[SHADER_COUNT] = {{
+{shaders}
+}};
+
+}}
+{suffix}
+""".format(
+ prefix = prefix,
+ suffix = suffix,
+ shaders = ''.join(shader_lines)
+)
+
+ source_path = os.path.join(output_dir, 'src/shader/shaders_' + shader_platform + '.cpp')
+ mkdir_p(os.path.dirname(source_path))
+ with open(source_path, 'w') as f: f.write(source)
+
+write_header()
+write_source('gl', '#ifndef GL_ES_VERSION_2_0', '#endif')
+write_source('gles2', '#ifdef GL_ES_VERSION_2_0', '#endif')
diff --git a/test/suite b/test/suite
-Subproject b4db0dc1dc904a17d23f99c26f0a045afcfbdb2
+Subproject 1651a3df444ff83c98f6eff00679d6b84dc8845