Browse Source

*Fixed a bug in tokenizer (XOR)
*Working on depth passes

Panagiotis Christopoulos Charitos 16 years ago
parent
commit
b3465e5eac

+ 39 - 10
src/resources/material.cpp

@@ -7,6 +7,10 @@
 #include "shader_prog.h"
 #include "renderer.h"
 
+
+#define MTL_ERROR( x ) ERROR( "Material (" << GetPath() << GetName() << "): " << x );
+
+
 /*
 =======================================================================================================================================
 Blending dtuff                                                                                                                        =
@@ -65,10 +69,10 @@ bool material_t::Load( const char* filename )
 	{
 		token = &scanner.GetNextToken();
 
-		//** SHADER **
-		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SHADER" ) )
+		//** SHADER_PROG **
+		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SHADER_PROG" ) )
 		{
-			if( shader_prog ) ERROR( "Shader allready loaded" );
+			if( shader_prog ) ERROR( "Shader program allready loaded" );
 
 			token = &scanner.GetNextToken();
 			if( token->code != scanner_t::TC_STRING )
@@ -78,6 +82,19 @@ bool material_t::Load( const char* filename )
 			}
 			shader_prog = rsrc::shaders.Load( token->value.string );
 		}
+		/*//** DEPTH_SHADER_PROG **
+		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "DEPTH_SHADER_PROG" ) )
+		{
+			if( depth.shader_prog ) ERROR( "Depth shader program allready loaded" );
+
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_STRING )
+			{
+				PARSE_ERR_EXPECTED( "string" );
+				return false;
+			}
+			depth.shader_prog = rsrc::shaders.Load( token->value.string );
+		}*/
 		//** BLENDS **
 		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "BLENDS" ) )
 		{
@@ -263,6 +280,10 @@ bool material_t::Load( const char* filename )
 							return false;
 						}
 						break;
+					// vec2
+					case user_defined_var_t::VT_VEC2:
+						ERROR( "Unimplemented" );
+						break;
 					// vec3
 					case user_defined_var_t::VT_VEC3:
 						if( !ParseArrOfNumbers<float>( scanner, true, true, 3, &var.value.vec3[0] ) ) return false;
@@ -290,22 +311,28 @@ bool material_t::Load( const char* filename )
 
 	}while( true );
 
-	return InitTheOther();
+	return AdditionalInit();
 }
 
 
 //=====================================================================================================================================
-// InitTheOther                                                                                                                       =
+// AdditionalInit                                                                                                                     =
 //=====================================================================================================================================
-bool material_t::InitTheOther()
+bool material_t::AdditionalInit()
 {
-	// sanity check
+	// sanity checks
 	if( !shader_prog )
 	{
-		ERROR( "Material file (\"" << GetPath() << GetName() << "\") without shader is like cake without sugar" );
+		MTL_ERROR( "Without shader is like cake without sugar (missing SHADER_PROG)" );
 		return false;
 	}
 
+	/*if( !depth.shader_prog )
+	{
+		MTL_ERROR( "Without depth shader is like cake without shadow (missing DEPTH_SHADER_PROG)" );
+		return false;
+	}*/
+
 	// for all user defined vars get their location
 	shader_prog->Bind();
 	for( uint i=0; i<user_defined_vars.size(); i++ )
@@ -313,8 +340,8 @@ bool material_t::InitTheOther()
 		int loc = shader_prog->GetUniformLocation( user_defined_vars[i].name.c_str() );
 		if( loc == -1 )
 		{
-			ERROR( "Material \"" << GetPath() << GetName() << "\", shader \"" << shader_prog->GetName() << "\" and user defined var \"" <<
-			       user_defined_vars[i].name << "\" do not combine. Incorect location" );
+			MTL_ERROR( "Shader \"" << shader_prog->GetName() << "\" and user defined var \"" << user_defined_vars[i].name <<
+			           "\" do not combine. Incorrect location" );
 			return false;
 		}
 		user_defined_vars[i].uniform_location = loc;
@@ -378,6 +405,8 @@ void material_t::SetToDefault()
 	grass_map = NULL;
 	casts_shadow = true;
 	refracts = false;
+	/*depth.shader_prog = NULL;
+	depth.alpha_testing_map = NULL;*/
 }
 
 

+ 4 - 3
src/resources/material.h

@@ -100,21 +100,22 @@ class material_t: public resource_t
 			{
 				int alpha_testing_map;
 			} uni_locs;
-		} dp;*/
-		material_t* dp_material;
+		} depth;*/
 
 	//===================================================================================================================================
 	// funcs                                                                                                                            =
 	//===================================================================================================================================
 	protected:
 		void SetToDefault();
-		bool InitTheOther(); ///< The func is for not polluting Load with extra code
+		bool AdditionalInit(); ///< The func is for not polluting Load with extra code
 		
 	public:
 		material_t() { SetToDefault(); }
 		void Setup();
 		bool Load( const char* filename );
 		void Unload();
+
+		bool HasHWSkinning() const { return attrib_locs.vert_weight_bones_num != -1; }
 };
 
 

+ 2 - 2
src/resources/shader_prog.cpp

@@ -4,8 +4,8 @@
 #include "texture.h"
 
 
-#define SHADER_ERROR( x ) ERROR( "Shader prog \"" << GetName() << "\": " << x )
-#define SHADER_WARNING( x ) WARNING( "Shader prog \"" << GetName() << "\": " << x )
+#define SHADER_ERROR( x ) ERROR( "Shader (" << GetName() << "): " << x )
+#define SHADER_WARNING( x ) WARNING( "Shader (" << GetName() << "): " << x )
 
 
 

+ 1 - 1
src/scene/mesh_node.cpp

@@ -50,7 +50,7 @@ void mesh_node_t::Render()
 		              &(skel_controller->skel_node->skel_anim_controller->bone_translations[0])[0] );
 
 		// then the attributes
-		DEBUG_ERR( mtl->attrib_locs.vert_weight_bones_num == -1 );
+		DEBUG_ERR( !mtl->HasHWSkinning() );
 
 		mesh->vbos.vert_weights.Bind();
 		glEnableVertexAttribArray( mtl->attrib_locs.vert_weight_bones_num );

+ 1 - 0
src/tokenizer/scanner.cpp

@@ -97,6 +97,7 @@ void scanner_t::InitAsciiMap()
 	ascii_lookup_table['!'] = ascii_lookup_table['<'] = ascii_lookup_table['>'] = ascii_lookup_table['|'] = AC_SPECIAL;
 	ascii_lookup_table['&'] = ascii_lookup_table['+'] = ascii_lookup_table['-'] = ascii_lookup_table['*'] = AC_SPECIAL;
 	ascii_lookup_table['/'] = ascii_lookup_table['~'] = ascii_lookup_table['%'] = ascii_lookup_table['#'] = AC_SPECIAL;
+	ascii_lookup_table['^'] = AC_SPECIAL;
 
 	ascii_lookup_table['\t'] = ascii_lookup_table[' '] = ascii_lookup_table['\0'] = ascii_lookup_table['\r'] = AC_WHITESPACE;
 	ascii_lookup_table['\n'] = AC_ERROR; // newline is unacceptable char

+ 5 - 5
src/utility/common.h

@@ -74,22 +74,22 @@ extern string GetFunctionFromPrettyFunction( const char* pretty_function );
 #endif
 
 #define GENERAL_ERR( x, y, col ) \
-	cout << col << "**" << x << "** (" << __FILENAME__ << ":" << __LINE__ << " " << __G_FUNCTION__ << "): " << y << COL_DEFAULT << endl;
+	cerr << col << x << " (" << __FILENAME__ << ":" << __LINE__ << " " << __G_FUNCTION__ << "): " << y << COL_DEFAULT << endl;
 
 /// in ERROR you can write something like this: ERROR( "tralala" << 10 << ' ' )
-#define ERROR( x ) GENERAL_ERR( "ERROR", x, COL_ERROR )
+#define ERROR( x ) GENERAL_ERR( "Error", x, COL_ERROR )
 
 /// WARNING
-#define WARNING( x ) GENERAL_ERR( "WARNG", x, COL_WARNING );
+#define WARNING( x ) GENERAL_ERR( "Warning", x, COL_WARNING );
 
 /// FATAL ERROR
-#define FATAL( x ) { GENERAL_ERR( "FATAL", x << ". Bye!", COL_FATAL ); exit( EXIT_FAILURE ); };
+#define FATAL( x ) { GENERAL_ERR( "Fatal", x << ". Bye!", COL_FATAL ); exit( EXIT_FAILURE ); };
 
 /// DEBUG_ERR
 #ifdef _DEBUG_
 	#define DEBUG_ERR( x ) \
 		if( x ) \
-			GENERAL_ERR( "ASSRT", #x, COL_DEBUG_ERR );
+			GENERAL_ERR( "Assertion", #x, COL_DEBUG_ERR );
 #else
     #define DEBUG_ERR( x )
 #endif