* External glsl embedding is completed, Linux build requires testing. 4.x-dev

Wed, 18 Jan 2017 23:22:59 +0300

author
cemkalyoncu
date
Wed, 18 Jan 2017 23:22:59 +0300
branch
4.x-dev
changeset 984
4aa9eabe2b1a
parent 983
d38838abf15e
child 985
311a9c67426e

* External glsl embedding is completed, Linux build requires testing.

.hgignore file | annotate | diff | comparison | revisions
Scripts/Macros.cmake file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Shaders.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Shaders/Alpha_F.glsl file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Shaders/Fill_F.glsl file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Shaders/NoTex_V.glsl file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Shaders/Simple_F.glsl file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/dir.cmake file | annotate | diff | comparison | revisions
Tools/ShaderEmbedder/Source/Main.cpp file | annotate | diff | comparison | revisions
--- a/.hgignore	Wed Jan 18 07:52:40 2017 +0300
+++ b/.hgignore	Wed Jan 18 23:22:59 2017 +0300
@@ -25,6 +25,6 @@
 Package/
 codelite/
 Docs/xml
-Source/Gorgon/Graphics/ShaderSrc.cpi
+*.gen
 syntax: regexp
 .*\.kdev4(_.*)?
--- a/Scripts/Macros.cmake	Wed Jan 18 07:52:40 2017 +0300
+++ b/Scripts/Macros.cmake	Wed Jan 18 23:22:59 2017 +0300
@@ -13,23 +13,29 @@
 	
 	IF(${wd} MATCHES ".+")
 		SET(LocalFixed)
+		SET(LocalShaders)
 		FOREACH(L ${Local}) 
 			IF(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${wd}/${L}")
+			ELSEIF(L MATCHES ".*\\.glsl")
+				LIST(APPEND LocalShaders "${wd}/${L}")
 			ELSE()
 				LIST(APPEND LocalFixed "${wd}/${L}")
 			ENDIF()
 		ENDFOREACH()
 	ELSE()
 		SET(LocalFixed)
+		SET(LocalShaders)
 		FOREACH(L ${Local}) 
 			IF(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${wd}/${L}")
+			ELSEIF(L MATCHES ".*\\.glsl")
+				LIST(APPEND LocalShaders ${L})
 			ELSE()
 				LIST(APPEND LocalFixed ${L})
 			ENDIF()
 		ENDFOREACH()
 	ENDIF()
 
-	LIST(APPEND All ${LocalFixed})
+	LIST(APPEND All ${LocalFixed} ${LocalShaders})
 	LIST(LENGTH LocalFixed len)
 	IF(len GREATER 7)
 		SET(headergrpfiles)
@@ -49,6 +55,8 @@
 		SOURCE_GROUP("${srcgrp}" FILES ${LocalFixed})
 	ENDIF()
 	
+	SOURCE_GROUP("${srcgrp}\\Shaders" FILES ${LocalShaders})
+	
 	FOREACH(S ${Local})
 		IF(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${wd}/${S}")
 			IF("${wd}" MATCHES "^[^\\/]+")
@@ -78,7 +86,9 @@
 	DoSource()
 ENDMACRO()
 
-MACRO(EmbedShader out)
+list(APPEND deps ShaderEmbedder)
+
+MACRO(EmbedShaders out for) #inputs
 	set(listv)
 	
 	foreach(a ${ARGN})
@@ -87,17 +97,14 @@
 	
 	add_custom_command(
 		OUTPUT ${CMAKE_SOURCE_DIR}/${wd}/${out}
-		COMMAND "${CMAKE_SOURCE_DIR}/Tools/ShaderEmbedder/Bin/ShaderEmbedder" ${CMAKE_SOURCE_DIR}/${wd}/${out} ${ARGN}
-		DEPENDS ${listv}
+		COMMAND "${CMAKE_SOURCE_DIR}/Tools/ShaderEmbedder/Bin/ShaderEmbedder" ${out} ${ARGN}
+		DEPENDS ShaderEmbedder ${listv}
 		WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${wd}"
 		COMMENT "Embedding shaders into ${out}"
 	)
 	
-	STRING(REPLACE "/" "_" myd ${wd})
+	list(APPEND Local ${ARGN})
+	list(APPEND Local ${out})
 	
-	add_custom_target("${myd}_${out}"
-		DEPENDS "${CMAKE_SOURCE_DIR}/Tools/ShaderEmbedder/Bin/ShaderEmbedder" ${CMAKE_SOURCE_DIR}/${wd}/${out} ${listv}
-	)
-	
-	list(APPEND deps "${myd}_${out}")
+	set_property(SOURCE ${CMAKE_SOURCE_DIR}/${wd}/${for} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/${wd}/${out})
 ENDMACRO()
--- a/Source/Gorgon/Graphics/Shaders.cpp	Wed Jan 18 07:52:40 2017 +0300
+++ b/Source/Gorgon/Graphics/Shaders.cpp	Wed Jan 18 23:22:59 2017 +0300
@@ -5,145 +5,8 @@
 
 namespace Gorgon { namespace Graphics {
 
-//#include "ShaderSrc.cpi"
-	const std::string Simple_V = R"shader(
-#version 130
-in int vertex_index;
-uniform vec3 vertex_coords[4];
uniform vec2 tex_coords[4];
-out vec2 texcoord;
-void mainx()
{
	gl_Position = vec4(vertex_coords[vertex_index], 1.0f);
-    texcoord = tex_coords[vertex_index];
}
-)shader";
-
-	const std::string NoTex_V = R"shader(
-#version 130
-
-in int vertex_index;
-
-uniform vec3 vertex_coords[4];
-
-void main()
-{
-	gl_Position = vec4(vertex_coords[vertex_index], 1.0f);
-}
-)shader";
-
-	const std::string Simple_F = R"shader(
-#version 130
-
-in vec2 texcoord;
-
-uniform sampler2D diffuse;
-uniform vec4      tint;
-
-out vec4 output_color;
-
-void main()
-{
-	output_color = texture(diffuse, texcoord) * tint;
-}
-)shader";
-
-	const std::string Alpha_F = R"shader(
-#version 130
-
-in vec2 texcoord;
-
-uniform sampler2D diffuse;
-uniform vec4      tint;
-
-out vec4 output_color;
-
-void main()
-{
-    output_color = vec4(tint.rgb, texture(diffuse, texcoord).a * tint.a);
-}
-)shader";
-
-	const std::string Fill_F = R"shader(
-#version 130
-
-uniform vec4      tint;
-
-out vec4 output_color;
-
-void main()
-{
-    output_color = tint;
-}
-)shader";
-
-	const std::string TiledAtlasFragSrcCode = R"shader(
-#version 130
-
-in vec2 texcoord;
-
-uniform sampler2D diffuse;
-uniform vec4      tint;
-uniform vec2	  size;
-
-out vec4 output_color;
-
-void main()
-{
-    output_color = texture(diffuse, vec2(mod(texcoord.x, size.x), mod(texcoord.y, size.y)) * tint;
-}
-)shader";
-
-	const std::string TiledAtlasAlphaFragSrcCode = R"shader(
-#version 130
-
-in vec2 texcoord;
-
-uniform sampler2D diffuse;
-uniform vec4      tint;
-
-out vec4 output_color;
-
-void main()
-{
-    output_color = vec4(tint.rgb, texture(diffuse, vec2(mod(texcoord.x, size.x), mod(texcoord.y, size.y)).a * tint.a);
-}
-)shader";
-
-	const std::string MaskedVertSrcCode = R"shader(
-#version 130
-
-in int vertex_index;
-
-uniform vec3 vertex_coords[4];
-uniform vec2 tex_coords[4];
-uniform vec2 mask_coords[4];
-
-out vec2 diffuse_texcoord;
-out vec2 mask_texcoord;
-
-void main()
-{
-	gl_Position = vec4(vertex_coords[vertex_index], 1.0f);
-
-    diffuse_texcoord = tex_coords[vertex_index];
-    mask_texcoord = mask_coords[vertex_index];
-}
-)shader";
-
-    const std::string MaskedFragmentSrcCode = R"shader(
-#version 130
-
-in vec2 diffuse_texcoord;
-in vec2 mask_texcoord;
-
-uniform sampler2D diffuse;
-uniform sampler2D mask;
-
-out vec4 output_color;
-
-void main()
-{
-    output_color = tint * vec4(texture(diffuse, diffuse_texcoord).rgb, texture(diffuse, diffuse_texcoord).a*texture(mask, mask_texcoord).a);
-}
-)shader";
-
+#include "ShaderSrc.strings.gen"
+	
 
 	SimpleShader::SimpleShader() : Shader("Gorgon::Graphics::Simple") {
 		InitializeWithSource(Simple_V, Simple_F);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Gorgon/Graphics/Shaders/Alpha_F.glsl	Wed Jan 18 23:22:59 2017 +0300
@@ -0,0 +1,13 @@
+#version 130
+
+in vec2 texcoord;
+
+uniform sampler2D diffuse;
+uniform vec4      tint;
+
+out vec4 output_color;
+
+void main()
+{
+    output_color = vec4(tint.rgb, texture(diffuse, texcoord).a * tint.a);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Gorgon/Graphics/Shaders/Fill_F.glsl	Wed Jan 18 23:22:59 2017 +0300
@@ -0,0 +1,10 @@
+#version 130
+
+uniform vec4      tint;
+
+out vec4 output_color;
+
+void main()
+{
+    output_color = tint;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Gorgon/Graphics/Shaders/NoTex_V.glsl	Wed Jan 18 23:22:59 2017 +0300
@@ -0,0 +1,10 @@
+#version 130
+
+in int vertex_index;
+
+uniform vec3 vertex_coords[4];
+
+void main()
+{
+	gl_Position = vec4(vertex_coords[vertex_index], 1.0f);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Gorgon/Graphics/Shaders/Simple_F.glsl	Wed Jan 18 23:22:59 2017 +0300
@@ -0,0 +1,13 @@
+#version 130
+
+in vec2 texcoord;
+
+uniform sampler2D diffuse;
+uniform vec4      tint;
+
+out vec4 output_color;
+
+void main()
+{
+	output_color = texture(diffuse, texcoord) * tint;
+}
--- a/Source/Gorgon/Graphics/dir.cmake	Wed Jan 18 07:52:40 2017 +0300
+++ b/Source/Gorgon/Graphics/dir.cmake	Wed Jan 18 23:22:59 2017 +0300
@@ -19,9 +19,12 @@
 	Shaders.cpp
 	Texture.h
 	TextureTargets.h
-	Shaders/Simple_V.glsl
-	
-	ShaderSrc.cpi
 )
 
-EmbedShader(ShaderSrc.cpi "Shaders/Simple_V.glsl")
\ No newline at end of file
+EmbedShaders(ShaderSrc.strings.gen Shaders.cpp 
+	"Shaders/Simple_V.glsl"
+	"Shaders/NoTex_V.glsl"	
+	"Shaders/Simple_F.glsl"	
+	"Shaders/Alpha_F.glsl"	
+	"Shaders/Fill_F.glsl"	
+)
\ No newline at end of file
--- a/Tools/ShaderEmbedder/Source/Main.cpp	Wed Jan 18 07:52:40 2017 +0300
+++ b/Tools/ShaderEmbedder/Source/Main.cpp	Wed Jan 18 23:22:59 2017 +0300
@@ -16,7 +16,7 @@
 	}
 	
 	std::string outputfilename = argv[1];
-	std::ofstream out(outputfilename);
+	std::ofstream out(outputfilename, std::ios::binary);
 	
 	if(!out.is_open()) {
 		std::cerr << "Cannot open output file \"" << outputfilename << "\" to write." << std::endl;
@@ -44,9 +44,11 @@
 		auto &inputfile = *file.stream;
 		
 		auto name = file.name;
+
 		if(name.find_last_of('/') != name.npos) {
-			name = name.substr(name.find_last_not_of('/'));
+			name = name.substr(name.find_last_of('/')+1);
 		}
+
 		name = name.substr(0, name.find_first_of('.'));
 		
 		out << std::endl << "const std::string " << name << " = R\"thisisalongtoken(";

mercurial