Panagiotis Christopoulos Charitos 14 лет назад
Родитель
Сommit
d03c8964ee

+ 2 - 2
shaders/BsRefract.glsl

@@ -1,8 +1,8 @@
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 #pragma anki include "shaders/SimpleVert.glsl"
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 uniform sampler2D fai;
 

+ 11 - 11
shaders/DpGeneric.glsl

@@ -1,7 +1,7 @@
 /// Control defines:
 /// ALPHA_TESTING
 
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 uniform mat4 modelViewProjectionMat;
 
@@ -14,14 +14,14 @@ in vec3 position;
 
 void main()
 {
-	#if defined(ALPHA_TESTING)
-		vTexCoords = texCoords;
-	#endif
+#if defined(ALPHA_TESTING)
+	vTexCoords = texCoords;
+#endif
 
 	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 }
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 #if defined(ALPHA_TESTING)
 	uniform sampler2D diffuseMap;
@@ -31,10 +31,10 @@ void main()
 
 void main()
 {
-	#if defined(ALPHA_TESTING)
-		if(texture2D(diffuseMap, vTexCoords).a < alphaTestingTolerance)
-		{
-			discard;
-		}
-	#endif
+#if defined(ALPHA_TESTING)
+	if(texture2D(diffuseMap, vTexCoords).a < alphaTestingTolerance)
+	{
+		discard;
+	}
+#endif
 }

+ 4 - 3
shaders/GaussianBlurGeneric.glsl

@@ -1,12 +1,13 @@
 /// @file
-/// Generic shader program for Gaussian blur inspired by Daniel Rakos' article
+/// Generic shader program for Gaussian blur inspired by Daniel Rakos'
+/// article
 /// http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
 ///
 /// Switches: VPASS or HPASS, COL_RGBA or COL_RGB or COL_R
 ///
 /// This is an optimized version. See the clean one at r213
 
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 layout(location = 0) in vec2 position;
 
@@ -30,7 +31,7 @@ void main()
 }
 
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 
 // Preprocessor switches sanity checks

+ 135 - 0
shaders/MaterialFragmentFunctions.glsl

@@ -0,0 +1,135 @@
+#pragma anki include "shaders/Pack.glsl"
+
+
+#define MAX_SHININESS 128.0
+
+
+//==============================================================================
+// getNormalFromTexture                                                        =
+//==============================================================================
+/// @param[in] normal The fragment's normal in view space
+/// @param[in] tangent The tangent
+/// @param[in] tangent Extra stuff for the tangent
+/// @param[in] map The map
+/// @param[in] texCoords Texture coordinates
+vec3 getNormalFromTexture(in vec3 normal, in vec3 tangent, in float tangentW,
+	in sampler2D map, in vec2 texCoords)
+{
+#if !defined(DEPTH_PASS)
+	vec3 n = normalize(normal);
+	vec3 t = normalize(tangent);
+	vec3 b = cross(n, t) * tangentW;
+
+	mat3 tbnMat = mat3(t, b, n);
+
+	vec3 nAtTangentspace = (texture2D(map, texCoords).rgb - 0.5) * 2.0;
+
+	return normalize(tbnMat * nAtTangentspace);
+#else
+	return vec3(0.0);
+#endif
+}
+
+
+//==============================================================================
+// getNormalSimple                                                             =
+//==============================================================================
+/// Just normalize
+vec3 getNormalSimple(in vec3 normal)
+{
+#if !defined(DEPTH_PASS)
+	return normalize(normal);
+#else
+	return vec3(0.0);
+#endif
+}
+
+
+//==============================================================================
+// getEnvironmentColor                                                         =
+//==============================================================================
+/// Environment mapping calculations
+/// @param[in] vertPosViewSpace Fragment position in view space
+/// @param[in] normal Fragment's normal in view space as well
+/// @param[in] map The env map
+/// @return The color
+vec3 getEnvironmentColor(in vec3 vertPosViewSpace, in vec3 normal,
+	in sampler2D map)
+{
+#if !defined(DEPTH_PASS)
+	// In case of normal mapping I could play with vertex's normal but this 
+	// gives better results and its allready computed
+	
+	vec3 u = normalize(vertPosViewSpace);
+	vec3 r = reflect(u, normal);
+	r.z += 1.0;
+	float m = 2.0 * length(r);
+	vec2 semTexCoords = r.xy / m + 0.5;
+
+	vec3 semCol = texture2D(map, semTexCoords).rgb;
+	return semCol;
+#else
+	return vec3(0.0);
+#endif
+}
+
+
+//==============================================================================
+// getDiffuseColorAndDoAlphaTesting                                            =
+//==============================================================================
+/// Using a 4-channel texture and a tolerance discard the fragment if the 
+/// texture's alpha is less than the tolerance
+/// @param[in] map The diffuse map
+/// @param[in] tolerance Tolerance value
+/// @param[in] texCoords Texture coordinates
+/// @return The RGB channels of the map
+vec3 getDiffuseColorAndDoAlphaTesting(
+	in sampler2D map,
+	in vec2 texCoords,
+	in float tolerance)
+{
+#if !defined(DEPTH_PASS)
+	vec4 col = texture2D(map, texCoords);
+	if(col.a < tolerance)
+	{
+		discard;
+	}
+	return col.rgb;
+#else
+	float a = texture2D(map, texCoords).a;
+	if(a < tolerance)
+	{
+		discard;
+	}
+	return vec3(0.0);
+#endif
+}
+
+
+//==============================================================================
+// readColor3FromTexture                                                       =
+//==============================================================================
+/// Just read the RGB color from texture
+vec3 readColor3FromTexture(in sampler2D tex, in vec2 texCoords)
+{
+#if !defined(DEPTH_PASS)
+	return texture2D(tex, texCoords).rgb;
+#else
+	return vec3(0.0);
+#endif
+}
+
+
+//==============================================================================
+// writeFais                                                                   =
+//==============================================================================
+/// XXX
+void writeFais(in vec3 diffCol, in vec3 normal, in vec3 specularCol,
+	in float shininess, in float blurring)
+{
+#if !defined(DEPTH_PASS)
+	fMsNormalFai = vec3(packNormal(normal), blurring);
+	fMsDiffuseFai = diffCol;
+	fMsSpecularFai = vec4(specularCol, shininess / MAX_SHININESS);
+#endif
+}

+ 7 - 2
shaders/MaterialFragmentVariables.glsl

@@ -1,14 +1,19 @@
 /// @name Varyings
 /// @{
+in vec2 vTexCoords;
+#if !defined(DEPTH_PASS)
 in vec3 vNormal;
 in vec3 vTangent;
 in float vTangentW;
-in vec2 vTexCoords;
 in vec3 vVertPosViewSpace;
+#endif
 /// @}
 
-if !defined(DEPTH_PASS)
+/// @name Fragment out
+/// @{
+#if !defined(DEPTH_PASS)
 layout(location = 0) out vec3 fMsNormalFai;
 layout(location = 1) out vec3 fMsDiffuseFai;
 layout(location = 2) out vec4 fMsSpecularFai;
 #endif
+/// @}

+ 16 - 13
shaders/MaterialVert.glsl → shaders/MaterialVertex.glsl

@@ -4,28 +4,31 @@
 /// @name Attributes
 /// @{
 in vec3 position;
-in vec3 normal;
 in vec2 texCoords;
+#if !defined(DEPTH_PASS)
+in vec3 normal;
 in vec4 tangent;
+#endif
 /// @}
 
 /// @name Uniforms
 /// @{
-uniform mat4 modelMat;
-uniform mat4 viewMat;
-uniform mat4 projectionMat;
-uniform mat4 modelViewMat;
-uniform mat3 normalMat;
 uniform mat4 modelViewProjectionMat;
+#if !defined(DEPTH_PASS)
+uniform mat3 normalMat;
+uniform mat4 modelViewMat;
+#endif
 /// @}
 
 /// @name Varyings
 /// @{
-out vec3 vNormal;
 out vec2 vTexCoords;
+#if !defined(DEPTH_PASS)
+out vec3 vNormal;
 out vec3 vTangent;
 out float vTangentW;
 out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
+#endif
 /// @}
 
 
@@ -35,16 +38,16 @@ out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
 //==============================================================================
 void main()
 {
+#if !defined(DEPTH_PASS)
 	// calculate the vert pos, normal and tangent
 	vNormal = normalMat * normal;
 
-	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
-
-	// calculate the rest
-	vTexCoords = texCoords;
-
 	vTangent = normalMat * vec3(tangent);
 	vTangentW = tangent.w;
-
+	
 	vVertPosViewSpace = vec3(modelViewMat * vec4(position, 1.0));
+#endif
+
+	vTexCoords = texCoords;
+	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 }

+ 1 - 2
shaders/MsMpGeneric.glsl

@@ -11,8 +11,7 @@
 #	error "Cannot have ALPHA_TESTING without DIFFUSE_MAPPING"
 #endif
  
-#if defined(DIFFUSE_MAPPING) || defined(NORMAL_MAPPING) || \
-	defined(SPECULAR_MAPPING)
+#if defined(DIFFUSE_MAPPING) || defined(NORMAL_MAPPING) || defined(SPECULAR_MAPPING)
 #	define NEEDS_TEX_MAPPING 1
 #else
 #	define NEEDS_TEX_MAPPING 0

+ 23 - 18
shaders/PpsBlurGeneric.glsl

@@ -1,15 +1,18 @@
-/// For information about the blurring you can see the code and the comments of GaussianBlurGeneric.glsl
+/// For information about the blurring you can see the code and the comments
+/// of GaussianBlurGeneric.glsl
 
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 layout(location = 0) in vec2 position;
 
 out vec2 vTexCoords;
 out vec2 vOffsets; ///< For side pixels
 
-uniform float imgDimension = 0.0; ///< the img width for hspass or the img height for vpass
+/// The img width for hspass or the img height for vpass
+uniform float imgDimension = 0.0;
 
-const vec2 BLURRING_OFFSET = vec2(1.3846153846, 3.2307692308); ///< The offset of side pixels
+/// The offset of side pixels
+const vec2 BLURRING_OFFSET = vec2(1.3846153846, 3.2307692308);
 
 
 void main()
@@ -22,7 +25,7 @@ void main()
 }
 
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 
 uniform sampler2D img; ///< Input FAI
@@ -54,19 +57,21 @@ void main()
 		// side pixels
 		for(int i = 0; i < 2; i++)
 		{
-			#if defined(HPASS)
-				vec2 texCoords = vec2(vTexCoords.x + vOffsets[i] * blurringDist, vTexCoords.y);
-				col += texture2D(img, texCoords).rgb * WEIGHTS[i];
-
-				texCoords.x = vTexCoords.x - blurringDist * vOffsets[i];
-				col += texture2D(img, texCoords).rgb * WEIGHTS[i];
-			#elif defined(VPASS)
-				vec2 texCoords = vec2(vTexCoords.x, vTexCoords.y + blurringDist * vOffsets[i]);
-				col += texture2D(img, texCoords).rgb * WEIGHTS[i];
-
-				texCoords.y = vTexCoords.y - blurringDist * vOffsets[i];
-				col += texture2D(img, texCoords).rgb * WEIGHTS[i];
-			#endif
+#if defined(HPASS)
+			vec2 texCoords = vec2(vTexCoords.x + vOffsets[i] * blurringDist,
+				vTexCoords.y);
+			col += texture2D(img, texCoords).rgb * WEIGHTS[i];
+
+			texCoords.x = vTexCoords.x - blurringDist * vOffsets[i];
+			col += texture2D(img, texCoords).rgb * WEIGHTS[i];
+#elif defined(VPASS)
+			vec2 texCoords = vec2(vTexCoords.x,
+				vTexCoords.y + blurringDist * vOffsets[i]);
+			col += texture2D(img, texCoords).rgb * WEIGHTS[i];
+
+			texCoords.y = vTexCoords.y - blurringDist * vOffsets[i];
+			col += texture2D(img, texCoords).rgb * WEIGHTS[i];
+#endif
 		}
 
 		fFragColor = col;

+ 4 - 3
shaders/PpsHdr.glsl

@@ -1,8 +1,8 @@
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 #pragma anki include "shaders/SimpleVert.glsl"
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 uniform sampler2D fai; ///< Its the IS FAI
 uniform float exposure;
@@ -16,7 +16,8 @@ void main()
 	vec3 color = texture2D(fai, vTexCoords).rgb;
 	float luminance = dot(vec3(0.30, 0.59, 0.11), color);
 	const float brightMax = 4.0;
-	float yd = exposure * (exposure / brightMax + 1.0) / (exposure + 1.0) * luminance;
+	float yd = exposure * (exposure / brightMax + 1.0) /
+		(exposure + 1.0) * luminance;
 	color *= yd;
 	fColor = color;
 }

+ 15 - 15
shaders/PpsPostPass.glsl

@@ -1,8 +1,8 @@
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 #pragma anki include "shaders/SimpleVert.glsl"
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 #pragma anki include "shaders/photoshop_filters.glsl"
 
@@ -14,9 +14,9 @@ in vec2 vTexCoords;
 layout(location = 0) out vec3 fFragColor;
 
 
-//======================================================================================================================
-// GrayScale                                                                                                           =
-//======================================================================================================================
+//==============================================================================
+// GrayScale                                                                   =
+//==============================================================================
 vec3 grayScale(in vec3 col)
 {
 	float grey = (col.r + col.g + col.b) * 0.333333333; // aka: / 3.0
@@ -24,9 +24,9 @@ vec3 grayScale(in vec3 col)
 }
 
 
-//======================================================================================================================
-// saturation                                                                                                          =
-//======================================================================================================================
+//==============================================================================
+// saturation                                                                  =
+//==============================================================================
 vec3 saturation(in vec3 col, in float factor)
 {
 	const vec3 lumCoeff = vec3(0.2125, 0.7154, 0.0721);
@@ -36,9 +36,9 @@ vec3 saturation(in vec3 col, in float factor)
 }
 
 
-//======================================================================================================================
-// main                                                                                                                =
-//======================================================================================================================
+//==============================================================================
+// main                                                                        =
+//==============================================================================
 void main(void)
 {
 	fFragColor = texture2D(ppsPrePassFai, vTexCoords).rgb;
@@ -48,10 +48,10 @@ void main(void)
 	color.g = pow(color.g, 1.0 / gamma);
 	color.b = pow(color.b, 1.0 / gamma);*/
 
-	#if defined(HDR_ENABLED)
-		vec3 hdr = texture2D(ppsHdrFai, vTexCoords).rgb;
-		fFragColor += hdr;
-	#endif
+#if defined(HDR_ENABLED)
+	vec3 hdr = texture2D(ppsHdrFai, vTexCoords).rgb;
+	fFragColor += hdr;
+#endif
 
 	fFragColor = BlendHardLight(vec3(0.6, 0.62, 0.4), fFragColor);
 }

+ 2 - 6
shaders/PpsPrePass.glsl

@@ -1,8 +1,8 @@
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 #pragma anki include "shaders/SimpleVert.glsl"
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 uniform sampler2D isFai;
 uniform sampler2D ppsSsaoFai;
@@ -11,10 +11,6 @@ in vec2 vTexCoords;
 
 layout(location = 0) out vec3 fFragColor;
 
-
-//======================================================================================================================
-// main                                                                                                                =
-//======================================================================================================================
 void main(void)
 {
 	fFragColor = texture2D(isFai, vTexCoords).rgb;

+ 2 - 2
shaders/PpsSideBlur.glsl

@@ -1,10 +1,10 @@
 // The final pass
 
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 #pragma anki include "shaders/SimpleVert.glsl"
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 in vec2 vTexCoords;
 

+ 2 - 2
shaders/TfHwSkinningGeneric.glsl

@@ -1,7 +1,7 @@
 /// @file
 ///
 /// Switches: NORMAL_ENABLED, TANGENT_ENABLED
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 
 //
@@ -68,7 +68,7 @@ void main()
 	#endif
 }
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 void main()
 {

+ 2 - 2
shaders/UiText.glsl

@@ -1,4 +1,4 @@
-#pragma anki vertShaderBegins
+#pragma anki start vertexShader
 
 layout(location = 0) in vec2 position;
 
@@ -15,7 +15,7 @@ void main(void)
 	gl_Position = vec4(transformation * pos3d, 1.0);
 }
 
-#pragma anki fragShaderBegins
+#pragma anki start fragmentShader
 
 in vec2 vTexCoords;
 

+ 2 - 2
src/CMakeLists.txt

@@ -9,8 +9,8 @@ SUBDIRS(${ANKI_DIRS})
 
 ADD_EXECUTABLE(anki Main.cpp)
 
-SET(ANKI_LIBS Scripting Core Renderer Scene Ui Events 
-	Input Physics Resources Misc GfxApi Collision Math Core Util)
+SET(ANKI_LIBS Scripting Renderer Scene Ui Events 
+	Input Physics Resources Core Misc GfxApi Collision Math Util)
 
 TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} BulletSoftBody BulletDynamics 
 	BulletCollision LinearMath GLEW GLU GL jpeg SDL png python2.6

+ 8 - 111
src/Core/App.cpp

@@ -1,3 +1,7 @@
+#include "App.h"
+#include "Logger.h"
+#include "Core/Globals.h"
+#include "Util/Exception.h"
 #include <GL/glew.h>
 #include <sstream>
 #include <SDL/SDL.h>
@@ -5,17 +9,6 @@
 #include <iomanip>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
-#include "App.h"
-#include "Renderer/RendererInitializer.h"
-#include "Renderer/MainRenderer.h"
-#include "Scripting/ScriptingEngine.h"
-#include "StdinListener.h"
-#include "Input/Input.h"
-#include "Logger.h"
-#include "Core/Globals.h"
-#include "ParallelJobs/Manager.h"
-#include "Renderer/Drawers/PhysDbgDrawer.h"
-#include "Scene/Scene.h"
 
 
 //==============================================================================
@@ -69,54 +62,14 @@ void App::init(int argc, char* argv[])
 	LoggerSingleton::getInstance().getSignal().connect(
 		boost::bind(&App::handleMessageHanlderMsgs, this, _1, _2, _3, _4));
 
-	INFO("Initializing the engine...");
-
 	parseCommandLineArgs(argc, argv);
-
 	printAppInfo();
-
-	// dirs
 	initDirs();
-
-	// create the subsystems. WATCH THE ORDER
-	const char* commonPythonCode =
-		"import sys\n"
-		"from Anki import *\n"
-		"\n"
-		"class StdoutCatcher:\n"
-		"\tdef write(self, str_):\n"
-		"\t\tif str_ == \"\\n\": return\n"
-		"\t\tline = sys._getframe(1).f_lineno\n"
-		"\t\tfile = sys._getframe(1).f_code.co_filename\n"
-		"\t\tfunc = sys._getframe(1).f_code.co_name\n"
-		"\t\tLoggerSingleton.getInstance().write(file, line, "
-		"func, str_ + \"\\n\")\n"
-		"\n"
-		"class StderrCatcher:\n"
-		"\tdef write(self, str_):\n"
-		"\t\tline = sys._getframe(1).f_lineno\n"
-		"\t\tfile = sys._getframe(1).f_code.co_filename\n"
-		"\t\tfunc = sys._getframe(1).f_code.co_name\n"
-		"\t\tLoggerSingleton.getInstance().write(file, line, func, str_)\n"
-		"\n"
-		"sys.stdout = StdoutCatcher()\n"
-		"sys.stderr = StderrCatcher()\n";
-
-	ScriptingEngineSingleton::getInstance().execScript(commonPythonCode);
-
-	StdinListenerSingleton::getInstance().start();
-
 	initWindow();
-	initRenderer();
-	ParallelJobs::ManagerSingleton::getInstance().init(4);
-	SceneSingleton::getInstance().getPhysMasterContainer().setDebugDrawer(
-		new R::PhysDbgDrawer(R::MainRendererSingleton::getInstance().getDbg()));
 
 	// other
 	activeCam = NULL;
 	timerTick = 1.0 / 40.0; // in sec. 1.0 / period
-
-	INFO("Engine initialization ends");
 }
 
 
@@ -201,36 +154,6 @@ void App::initDirs()
 }
 
 
-//==============================================================================
-// initRenderer                                                                =
-//==============================================================================
-void App::initRenderer()
-{
-	R::RendererInitializer initializer;
-	initializer.ms.ez.enabled = true;
-	initializer.dbg.enabled = true;
-	initializer.is.sm.bilinearEnabled = true;
-	initializer.is.sm.enabled = true;
-	initializer.is.sm.pcfEnabled = true;
-	initializer.is.sm.resolution = 1024;
-	initializer.is.sm.level0Distance = 3.0;
-	initializer.pps.hdr.enabled = true;
-	initializer.pps.hdr.renderingQuality = 0.25;
-	initializer.pps.hdr.blurringDist = 1.0;
-	initializer.pps.hdr.blurringIterationsNum = 2;
-	initializer.pps.hdr.exposure = 4.0;
-	initializer.pps.ssao.blurringIterationsNum = 4;
-	initializer.pps.ssao.enabled = true;
-	initializer.pps.ssao.renderingQuality = 0.3;
-	initializer.pps.bl.enabled = true;
-	initializer.pps.bl.blurringIterationsNum = 2;
-	initializer.pps.bl.sideBlurFactor = 1.0;
-	initializer.mainRendererQuality = 1.0;
-
-	R::MainRendererSingleton::getInstance().init(initializer);
-}
-
-
 //==============================================================================
 // togleFullScreen                                                             =
 //==============================================================================
@@ -275,12 +198,13 @@ void App::quit(int code)
 void App::printAppInfo()
 {
 	std::stringstream msg;
-	msg << "App info: Build: ";
+	msg << "App info: ";
 #if defined(NDEBUG)
-	msg << "release, ";
+	msg << "Release";
 #else
-	msg << "debug, ";
+	msg << "Debug";
 #endif
+	msg << " build, ";
 	msg << "platform ";
 #if defined(PLATFORM_LINUX)
 	msg << "Linux, ";
@@ -321,30 +245,3 @@ uint App::getDesktopHeight() const
 	//SDL_GetDesktopDisplayMode(&mode);
 	return mode.h;
 }
-
-
-//==============================================================================
-// execStdinScpripts                                                           =
-//==============================================================================
-void App::execStdinScpripts()
-{
-	while(1)
-	{
-		std::string cmd = StdinListenerSingleton::getInstance().getLine();
-
-		if(cmd.length() < 1)
-		{
-			break;
-		}
-
-		try
-		{
-			ScriptingEngineSingleton::getInstance().execScript(cmd.c_str(),
-				"command line input");
-		}
-		catch(Exception& e)
-		{
-			ERROR(e.what());
-		}
-	}
-}

+ 0 - 6
src/Core/App.h

@@ -5,8 +5,6 @@
 #include <boost/filesystem.hpp>
 #include "Util/StdTypes.h"
 #include "Util/Accessors.h"
-#include "Util/Exception.h"
-#include "Util/Singleton.h"
 
 
 class StdinListener;
@@ -44,10 +42,6 @@ class App
 		/// Wrapper for an SDL function that swaps the buffers
 		void swapBuffers();
 
-		/// The func pools the stdinListener for string in the console, if
-		/// there are any it executes them with scriptingEngine
-		void execStdinScpripts();
-
 		static void printAppInfo();
 
 		uint getDesktopWidth() const;

+ 4 - 2
src/GfxApi/BufferObjects/Vao.cpp

@@ -1,6 +1,7 @@
-#include "GfxApi/BufferObjects/Vao.h"
+#include "Vao.h"
 #include "Vbo.h"
 #include "Util/Exception.h"
+#include "Resources/AttributeShaderProgramVariable.h"
 
 
 //==============================================================================
@@ -45,7 +46,8 @@ void Vao::attachArrayBufferVbo(const Vbo& vbo, uint attribVarLocation,
 //==============================================================================
 // attachArrayBufferVbo                                                        =
 //==============================================================================
-void Vao::attachArrayBufferVbo(const Vbo& vbo, const AttributeShaderProgramVariable& attribVar,
+void Vao::attachArrayBufferVbo(const Vbo& vbo,
+	const AttributeShaderProgramVariable& attribVar,
 	GLint size, GLenum type, GLboolean normalized, GLsizei stride,
 	const GLvoid* pointer)
 {

+ 17 - 7
src/GfxApi/BufferObjects/Vao.h

@@ -3,12 +3,12 @@
 
 #include <GL/glew.h>
 #include "Util/StdTypes.h"
-#include "Resources/ShaderProgram.h"
 #include "Core/Object.h"
-#include "GfxApi/GlException.h"
+#include "../GlException.h"
 
 
 class Vbo;
+class AttributeShaderProgramVariable;
 
 
 /// Vertex array object
@@ -44,9 +44,14 @@ class Vao
 		/// vertex attributes
 		/// @param pointer Specifies a offset of the first component of the
 		/// first generic vertex attribute in the array
-		void attachArrayBufferVbo(const Vbo& vbo,
-			const AttributeShaderProgramVariable& attribVar, GLint size, GLenum type,
-			GLboolean normalized, GLsizei stride, const GLvoid* pointer);
+		void attachArrayBufferVbo(
+			const Vbo& vbo,
+			const AttributeShaderProgramVariable& attribVar,
+			GLint size,
+			GLenum type,
+			GLboolean normalized,
+			GLsizei stride,
+			const GLvoid* pointer);
 
 		/// Attach an array buffer VBO. See @link
 		/// http://www.opengl.org/sdk/docs/man3/xhtml/glVertexAttribPointer.xml
@@ -62,8 +67,13 @@ class Vao
 		/// vertex attributes
 		/// @param pointer Specifies a offset of the first component of the
 		/// first generic vertex attribute in the array
-		void attachArrayBufferVbo(const Vbo& vbo, uint attribVarLocation,
-			GLint size, GLenum type, GLboolean normalized, GLsizei stride,
+		void attachArrayBufferVbo(
+			const Vbo& vbo,
+			uint attribVarLocation,
+			GLint size,
+			GLenum type,
+			GLboolean normalized,
+			GLsizei stride,
 			const GLvoid* pointer);
 
 		/// Attach an element array buffer VBO

+ 112 - 10
src/Main.cpp

@@ -45,6 +45,8 @@
 #include "Events/MainRendererPpsHdr.h"
 #include "Resources/ShaderProgramPrePreprocessor.h"
 #include "Resources/Material2.h"
+#include "Core/ParallelJobs/Manager.h"
+#include "Renderer/Drawers/PhysDbgDrawer.h"
 
 
 // map (hard coded)
@@ -125,6 +127,9 @@ void init()
 {
 	INFO("Other init...");
 
+	Material2 mtl;
+	mtl.load("lala.mtl");
+
 	srand(unsigned(time(NULL)));
 
 	painter = new Ui::Painter(Vec2(AppSingleton::getInstance().getWindowWidth(),
@@ -378,7 +383,8 @@ void mainLoop()
 		// Update
 		//
 		mainLoopExtra();
-		AppSingleton::getInstance().execStdinScpripts();
+		void execStdinScpripts();
+		execStdinScpripts();
 		SceneSingleton::getInstance().getPhysMasterContainer().update(prevUpdateTime, crntTime);
 		SceneSingleton::getInstance().updateAllWorldStuff(prevUpdateTime, crntTime);
 		SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
@@ -457,32 +463,128 @@ void mainLoop()
 
 
 //==============================================================================
-// main                                                                        =
+// initSubsystems                                                              =
 //==============================================================================
-int main(int argc, char* argv[])
+void initSubsystems(int argc, char* argv[])
 {
-	try
+	// App
+	AppSingleton::getInstance().init(argc, argv);
+
+	// Main renderer
+	R::RendererInitializer initializer;
+	initializer.ms.ez.enabled = true;
+	initializer.dbg.enabled = true;
+	initializer.is.sm.bilinearEnabled = true;
+	initializer.is.sm.enabled = true;
+	initializer.is.sm.pcfEnabled = true;
+	initializer.is.sm.resolution = 1024;
+	initializer.is.sm.level0Distance = 3.0;
+	initializer.pps.hdr.enabled = true;
+	initializer.pps.hdr.renderingQuality = 0.25;
+	initializer.pps.hdr.blurringDist = 1.0;
+	initializer.pps.hdr.blurringIterationsNum = 2;
+	initializer.pps.hdr.exposure = 4.0;
+	initializer.pps.ssao.blurringIterationsNum = 4;
+	initializer.pps.ssao.enabled = true;
+	initializer.pps.ssao.renderingQuality = 0.3;
+	initializer.pps.bl.enabled = true;
+	initializer.pps.bl.blurringIterationsNum = 2;
+	initializer.pps.bl.sideBlurFactor = 1.0;
+	initializer.mainRendererQuality = 1.0;
+
+	R::MainRendererSingleton::getInstance().init(initializer);
+
+	// Scripting engine
+	const char* commonPythonCode =
+		"import sys\n"
+		"from Anki import *\n"
+		"\n"
+		"class StdoutCatcher:\n"
+		"    def write(self, str_):\n"
+		"        if str_ == \"\\n\": return\n"
+		"        line = sys._getframe(1).f_lineno\n"
+		"        file = sys._getframe(1).f_code.co_filename\n"
+		"        func = sys._getframe(1).f_code.co_name\n"
+		"        LoggerSingleton.getInstance().write(file, line, "
+		"func, str_ + \"\\n\")\n"
+		"\n"
+		"class StderrCatcher:\n"
+		"    def write(self, str_):\n"
+		"        line = sys._getframe(1).f_lineno\n"
+		"        file = sys._getframe(1).f_code.co_filename\n"
+		"        func = sys._getframe(1).f_code.co_name\n"
+		"        LoggerSingleton.getInstance().write(file, line, func, str_)\n"
+		"\n"
+		"sys.stdout = StdoutCatcher()\n"
+		"sys.stderr = StderrCatcher()\n";
+
+	ScriptingEngineSingleton::getInstance().execScript(commonPythonCode);
+
+	// Stdin listener
+	StdinListenerSingleton::getInstance().start();
+
+	// Parallel jobs
+	ParallelJobs::ManagerSingleton::getInstance().init(4);
+
+	// Add drawer to physics
+	SceneSingleton::getInstance().getPhysMasterContainer().setDebugDrawer(
+		new R::PhysDbgDrawer(R::MainRendererSingleton::getInstance().getDbg()));
+}
+
+
+//==============================================================================
+// execStdinScpripts                                                           =
+//==============================================================================
+/// The func pools the stdinListener for string in the console, if
+/// there are any it executes them with scriptingEngine
+void execStdinScpripts()
+{
+	while(1)
 	{
-		/*Material2 mtl;
-		mtl.load("lala.mtl");
+		std::string cmd = StdinListenerSingleton::getInstance().getLine();
 
+		if(cmd.length() < 1)
+		{
+			break;
+		}
 
-		return 0;*/
+		try
+		{
+			ScriptingEngineSingleton::getInstance().execScript(cmd.c_str(),
+				"command line input");
+		}
+		catch(Exception& e)
+		{
+			ERROR(e.what());
+		}
+	}
+}
+
+//==============================================================================
+// main                                                                        =
+//==============================================================================
+int main(int argc, char* argv[])
+{
+	int exitCode;
 
-		AppSingleton::getInstance().init(argc, argv);
+	try
+	{
+		initSubsystems(argc, argv);
 		init();
 
 		mainLoop();
 
 		INFO("Exiting...");
 		AppSingleton::getInstance().quit(EXIT_SUCCESS);
-		return 0;
+		exitCode = 0;
 	}
 	catch(std::exception& e)
 	{
 		//ERROR("Aborting: " << e.what());
 		std::cerr << "Aborting: " << e.what() << std::endl;
 		//abort();
-		return 1;
+		exitCode = 1;
 	}
+
+	return exitCode;
 }

+ 1 - 1
src/Resources/AttributeShaderProgramVariable.h

@@ -17,7 +17,7 @@ class AttributeShaderProgramVariable: public ShaderProgramVariable
 inline AttributeShaderProgramVariable::AttributeShaderProgramVariable(
 	int loc_, const char* name_,
 	GLenum glDataType_, const ShaderProgram& fatherSProg_)
-:	ShaderProgramVariable(loc_, name_, glDataType_, SVT_UNIFORM, fatherSProg_)
+:	ShaderProgramVariable(loc_, name_, glDataType_, SVT_ATTRIBUTE, fatherSProg_)
 {}
 
 

+ 12 - 8
src/Resources/Material2.cpp

@@ -177,6 +177,9 @@ void Material2::parseMaterialTag(const boost::property_tree::ptree& pt)
 	cpShaderProg.loadRsrc(cfile.c_str());
 	dpShaderProg.loadRsrc(dfile.c_str());
 
+	INFO(cpShaderProg->getShaderInfoString());
+	INFO(dpShaderProg->getShaderInfoString());
+
 	//boost::optional<>
 	getVariables(pt.get_child("shaderProgram.ins"));
 }
@@ -209,6 +212,7 @@ std::string Material2::createShaderProgSourceToCache(const std::string& source)
 		}
 
 		f.write(source.c_str(), source.length());
+		f.close();
 	}
 
 	return newfPathName.string();
@@ -261,7 +265,7 @@ void Material2::getVariables(const boost::property_tree::ptree& pt)
 			}
 
 			// Find the ptree that contains the value
-			const ptree* inPt = NULL;
+			const ptree* valuePt = NULL;
 			BOOST_FOREACH(const ptree::value_type& v, pt)
 			{
 				if(v.first != "in")
@@ -271,12 +275,12 @@ void Material2::getVariables(const boost::property_tree::ptree& pt)
 
 				if(v.second.get<std::string>("name") == svName)
 				{
-					inPt = &v.second;
+					valuePt = &v.second.get_child("value");
 					break;
 				}
 			}
 
-			if(inPt == NULL)
+			if(valuePt == NULL)
 			{
 				throw EXCEPTION("Variable not buildin and not found: " +
 					svName);
@@ -288,27 +292,27 @@ void Material2::getVariables(const boost::property_tree::ptree& pt)
 				// sampler2D
 				case GL_SAMPLER_2D:
 					mv = new UserMaterialVariable(uniC, uniD,
-						inPt->get<std::string>("sampler2D").c_str());
+						valuePt->get<std::string>("sampler2D").c_str());
 					break;
 				// float
 				case GL_FLOAT:
 					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getFloat(*inPt));
+						PropertyTree::getFloat(*valuePt));
 					break;
 				// vec2
 				case GL_FLOAT_VEC2:
 					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getVec2(*inPt));
+						PropertyTree::getVec2(*valuePt));
 					break;
 				// vec3
 				case GL_FLOAT_VEC3:
 					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getVec3(*inPt));
+						PropertyTree::getVec3(*valuePt));
 					break;
 				// vec4
 				case GL_FLOAT_VEC4:
 					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getVec4(*inPt));
+						PropertyTree::getVec4(*valuePt));
 					break;
 				// default is error
 				default:

+ 8 - 7
src/Resources/MaterialShaderProgramCreator.cpp

@@ -314,9 +314,11 @@ void MaterialShaderProgramCreator::parseShaderProgramTag(
 {
 	using namespace boost::property_tree;
 
-	srcLines.push_back("#pragma anki start vertexShader");
-	srcLines.push_back("#pragma anki include \"shaders/MaterialVert.glsl\"");
-	srcLines.push_back("#pragma anki start fragmentShader");
+	srcLines.push_back(
+		"#pragma anki start vertexShader\n"
+		"#pragma anki include \"shaders/MaterialVertex.glsl\"\n"
+		"#pragma anki start fragmentShader\n"
+		"#pragma anki include \"shaders/MaterialFragmentVariables.glsl\"");
 
 	//
 	// <includes></includes>
@@ -371,9 +373,7 @@ void MaterialShaderProgramCreator::parseShaderProgramTag(
 	//
 	// <operators></operators>
 	//
-	srcLines.push_back("\n#pragma anki include "
-		"\"shaders/MaterialFragmentVariables.glsl\"\n"
-		"\nvoid main()\n{");
+	srcLines.push_back("\nvoid main()\n{");
 
 	const ptree& opsPt = pt.get_child("operators");
 
@@ -511,7 +511,8 @@ void MaterialShaderProgramCreator::parseOperatorTag(
 
 		}
 
-		line << v.second.data();
+		const std::string& argName = v.second.data();
+		line << argName;
 
 		// Add a comma
 		++i;

+ 11 - 10
src/Resources/ShaderProgram.cpp

@@ -1,9 +1,3 @@
-#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/foreach.hpp>
-#include <boost/functional/hash.hpp>
-#include <fstream>
-#include <sstream>
 #include "Resources/ShaderProgram.h"
 #include "ShaderProgramPrePreprocessor.h"
 #include "Core/App.h" // To get cache dir
@@ -11,6 +5,13 @@
 #include "Core/Logger.h"
 #include "Util/Util.h"
 #include "Core/Globals.h"
+#include "Util/Exception.h"
+#include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
+#include <boost/functional/hash.hpp>
+#include <fstream>
+#include <sstream>
 
 
 #define SPROG_EXCEPTION(x) EXCEPTION("Shader prog \"" + rsrcFilename + \
@@ -21,12 +22,11 @@
 // Statics                                                                     =
 //==============================================================================
 
-std::string ShaderProgram::stdSourceCode(
+const char* ShaderProgram::stdSourceCode =
 	"#version 330 core\n"
 	"precision lowp float;\n"
 	"#pragma optimize(on)\n"
-	"#pragma debug(off)\n"
-);
+	"#pragma debug(off)\n";
 
 
 //==============================================================================
@@ -162,7 +162,7 @@ void ShaderProgram::getUniAndAttribVars()
 
 	// uni locations
 	glGetProgramiv(glId, GL_ACTIVE_UNIFORMS, &num);
-	for(int i=0; i<num; i++) // loop all uniforms
+	for(int i = 0; i < num; i++) // loop all uniforms
 	{
 		glGetActiveUniform(glId, i, sizeof(name_) / sizeof(char), &length,
 			&size, &type, &name_[0]);
@@ -374,6 +374,7 @@ std::string ShaderProgram::getShaderInfoString() const
 		{
 			ss << "uniform";
 		}
+		ss << std::endl;
 	}
 
 	return ss.str();

+ 1 - 1
src/Resources/ShaderProgram.h

@@ -93,7 +93,7 @@ class ShaderProgram
 		GLuint fragShaderGlId; ///< Fragment shader OpenGL id
 
 		/// Shader source that is used in ALL shader programs
-		static std::string stdSourceCode;
+		static const char* stdSourceCode;
 
 		/// @name Containers
 		/// @{

+ 1 - 0
src/Ui/Painter.cpp

@@ -1,6 +1,7 @@
 #include "Painter.h"
 #include "GfxApi/GlStateMachine.h"
 #include "Resources/Texture.h"
+#include "Resources/ShaderProgram.h"
 #include "Core/Logger.h"
 #include "Font.h"
 #include <cstdarg>