Browse Source

Added -i 'include dir' argument to shaderc.

bkaradzic 12 years ago
parent
commit
a703d6129f
6 changed files with 33 additions and 25 deletions
  1. 1 1
      examples/common/common.sh
  2. 4 0
      premake/shader.mk
  3. 17 0
      src/bgfx_shader.sh
  4. 0 22
      src/common.sh
  5. BIN
      tools/bin/shaderc.exe
  6. 11 2
      tools/shaderc/shaderc.cpp

+ 1 - 1
examples/common/common.sh

@@ -3,5 +3,5 @@
  * License: http://www.opensource.org/licenses/BSD-2-Clause
  * License: http://www.opensource.org/licenses/BSD-2-Clause
  */
  */
 
 
-#include "../../src/common.sh"
+#include <bgfx_shader.sh>
 #include "shaderlib.sh"
 #include "shaderlib.sh"

+ 4 - 0
premake/shader.mk

@@ -49,6 +49,10 @@ endif
 endif
 endif
 endif
 endif
 
 
+THISDIR := $(dir $(lastword $(MAKEFILE_LIST)))
+VS_FLAGS+=-i $(THISDIR)../src/
+FS_FLAGS+=-i $(THISDIR)../src/
+
 BUILD_OUTPUT_DIR=$(addprefix ./, $(RUNTIME_DIR)/$(SHADER_PATH))
 BUILD_OUTPUT_DIR=$(addprefix ./, $(RUNTIME_DIR)/$(SHADER_PATH))
 BUILD_INTERMEDIATE_DIR=$(addprefix $(BUILD_DIR)/, $(SHADER_PATH))
 BUILD_INTERMEDIATE_DIR=$(addprefix $(BUILD_DIR)/, $(SHADER_PATH))
 
 

+ 17 - 0
src/bgfx_shader.sh

@@ -133,10 +133,16 @@ bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; }
 bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; }
 bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; }
 bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; }
 bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; }
 
 
+float mix(float _a, float _b, float _t) { return lerp(_a, _b, _t); }
 vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); }
 vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); }
 vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); }
 vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); }
 vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); }
 vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); }
 
 
+float mod(float _a, float _b) { return _a - _b * floor(_a / _b); }
+vec2 mod(vec2 _a, vec2 _b) { return _a - _b * floor(_a / _b); }
+vec3 mod(vec3 _a, vec3 _b) { return _a - _b * floor(_a / _b); }
+vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
+
 #elif BGFX_SHADER_LANGUAGE_GLSL
 #elif BGFX_SHADER_LANGUAGE_GLSL
 #	define atan2(_x, _y) atan(_x, _y)
 #	define atan2(_x, _y) atan(_x, _y)
 #	define frac(_x) fract(_x)
 #	define frac(_x) fract(_x)
@@ -156,6 +162,17 @@ vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); }
 vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); }
 vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); }
 #endif // BGFX_SHADER_LANGUAGE_HLSL
 #endif // BGFX_SHADER_LANGUAGE_HLSL
 
 
+uniform vec4 u_viewRect;
+uniform vec4 u_viewTexel;
+uniform mat4 u_view;
+uniform mat4 u_viewProj;
+uniform mat4 u_model;
+uniform mat4 u_modelView;
+uniform mat4 u_modelViewProj;
+uniform mat4 u_modelViewProjX;
+uniform mat4 u_viewProjX;
+uniform float u_alphaRef;
+
 #endif // __cplusplus
 #endif // __cplusplus
 
 
 #endif // __BGFX_SHADER_H__
 #endif // __BGFX_SHADER_H__

+ 0 - 22
src/common.sh

@@ -1,22 +0,0 @@
-/*
- * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
- * License: http://www.opensource.org/licenses/BSD-2-Clause
- */
-
-#ifndef __SHADER_COMMON_H__
-#define __SHADER_COMMON_H__
-
-#include "bgfx_shader.sh"
-
-uniform vec4 u_viewRect;
-uniform vec4 u_viewTexel;
-uniform mat4 u_view;
-uniform mat4 u_viewProj;
-uniform mat4 u_model;
-uniform mat4 u_modelView;
-uniform mat4 u_modelViewProj;
-uniform mat4 u_modelViewProjX;
-uniform mat4 u_viewProjX;
-uniform float u_alphaRef;
-
-#endif // __SHADER_COMMON_H__

BIN
tools/bin/shaderc.exe


+ 11 - 2
tools/shaderc/shaderc.cpp

@@ -999,7 +999,7 @@ bool compileHLSLShaderDx11(bx::CommandLine& _cmdLine, const std::string& _code,
 
 
 struct Preprocessor
 struct Preprocessor
 {
 {
-	Preprocessor(const char* _filePath)
+	Preprocessor(const char* _filePath, const char* _includeDir = NULL)
 		: m_tagptr(m_tags)
 		: m_tagptr(m_tags)
 		, m_scratchPos(0)
 		, m_scratchPos(0)
 		, m_fgetsPos(0)
 		, m_fgetsPos(0)
@@ -1036,6 +1036,13 @@ struct Preprocessor
 		m_tagptr->data = scratch(_filePath);
 		m_tagptr->data = scratch(_filePath);
 		m_tagptr++;
 		m_tagptr++;
 
 
+		if (NULL != _includeDir)
+		{
+			m_tagptr->tag = FPPTAG_INCLUDE_DIR;
+			m_tagptr->data = scratch(_includeDir);
+			m_tagptr++;
+		}
+
 		m_default = "#define lowp\n#define mediump\n#define highp\n";
 		m_default = "#define lowp\n#define mediump\n#define highp\n";
 	}
 	}
 
 
@@ -1243,6 +1250,7 @@ void help(const char* _error = NULL)
 		  "\n"
 		  "\n"
 		  "Options:\n"
 		  "Options:\n"
 		  "  -f <file path>                Input file path.\n"
 		  "  -f <file path>                Input file path.\n"
+		  "  -i <include path>             Include path.\n"
 		  "  -o <file path>                Output file path.\n"
 		  "  -o <file path>                Output file path.\n"
 		  "      --bin2c <file path>       Generate C header file.\n"
 		  "      --bin2c <file path>       Generate C header file.\n"
 		  "      --depends <file path>     Generate makefile style depends file.\n"
 		  "      --depends <file path>     Generate makefile style depends file.\n"
@@ -1353,8 +1361,9 @@ int main(int _argc, const char* _argv[])
 
 
 	bool depends = cmdLine.hasArg("depends");
 	bool depends = cmdLine.hasArg("depends");
 	bool preprocessOnly = cmdLine.hasArg("preprocess");
 	bool preprocessOnly = cmdLine.hasArg("preprocess");
+	const char* includeDir = cmdLine.findOption('i');
 
 
-	Preprocessor preprocessor(filePath);
+	Preprocessor preprocessor(filePath, includeDir);
 
 
 	preprocessor.setDefaultDefine("BX_PLATFORM_ANDROID");
 	preprocessor.setDefaultDefine("BX_PLATFORM_ANDROID");
 	preprocessor.setDefaultDefine("BX_PLATFORM_IOS");
 	preprocessor.setDefaultDefine("BX_PLATFORM_IOS");