Browse Source

*Migration to new shaders Pt2
*Added gstring.h to eventualy replace all char* and stl::string

Panagiotis Christopoulos Charitos 16 years ago
parent
commit
4b5c5afb09

+ 0 - 2
src/main.cpp

@@ -253,8 +253,6 @@ int main( int /*argc*/, char* /*argv*/[] )
 
 
 		r::Render( main_cam );
 		r::Render( main_cam );
 
 
-
-
 		//map.octree.root->bounding_box.Render();
 		//map.octree.root->bounding_box.Render();
 
 
 		// print some debug stuff
 		// print some debug stuff

+ 3 - 0
src/old_src/2009-5-11/renderer.cpp

@@ -144,7 +144,10 @@ void PrintLastError()
 {
 {
 	GLenum errid = glGetError();
 	GLenum errid = glGetError();
 	if( errid != GL_NO_ERROR )
 	if( errid != GL_NO_ERROR )
+	{
+		int x = 10;
 		ERROR( "GL_ERR: " << gluErrorString( errid ) );
 		ERROR( "GL_ERR: " << gluErrorString( errid ) );
+	}
 }
 }
 
 
 
 

+ 1 - 1
src/renderer/r_is.cpp

@@ -163,7 +163,7 @@ Init
 void Init()
 void Init()
 {
 {
 	// load the shaders
 	// load the shaders
-	shdr_is_ambient = rsrc::shaders.Load( "shaders/is_ambient_pass.glsl" );
+	shdr_is_ambient = rsrc::shaders.Load( "shaders/is_ap.glsl" );
 	shdr_is_lp_point_light = rsrc::shaders.Load( "shaders/is_lp_point.glsl" );
 	shdr_is_lp_point_light = rsrc::shaders.Load( "shaders/is_lp_point.glsl" );
 	shdr_is_lp_spot_light_nos = rsrc::shaders.Load( "shaders/is_lp_spot.glsl" );
 	shdr_is_lp_spot_light_nos = rsrc::shaders.Load( "shaders/is_lp_spot.glsl" );
 	shdr_is_lp_spot_light_s = rsrc::shaders.Load( "shaders/is_lp_spot_shad.glsl" );
 	shdr_is_lp_spot_light_s = rsrc::shaders.Load( "shaders/is_lp_spot_shad.glsl" );

+ 1 - 1
src/renderer/renderer.cpp

@@ -145,7 +145,7 @@ void Init()
 	// misc
 	// misc
 	shdr_final = rsrc::shaders.Load( "shaders/final.glsl" );
 	shdr_final = rsrc::shaders.Load( "shaders/final.glsl" );
 
 
-	// init deffered stages
+	// init deferred stages
 	// WARNING: the order of the inits is crucial!!!!!
 	// WARNING: the order of the inits is crucial!!!!!
 	r::ms::Init();
 	r::ms::Init();
 	r::is::Init();
 	r::is::Init();

+ 1 - 1
src/tokenizer/scanner.cpp

@@ -98,7 +98,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['/'] = ascii_lookup_table['~'] = ascii_lookup_table['%'] = ascii_lookup_table['#'] = AC_SPECIAL;
 
 
-	ascii_lookup_table['\t'] = ascii_lookup_table[' '] = ascii_lookup_table['\0'] = AC_WHITESPACE;
+	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
 	ascii_lookup_table['\n'] = AC_ERROR; // newline is unacceptable char
 	                   
 	                   
 	ascii_lookup_table['\"']          = AC_DOUBLEQUOTE;
 	ascii_lookup_table['\"']          = AC_DOUBLEQUOTE;

+ 1 - 1
src/uncategorized/common.h

@@ -206,7 +206,7 @@ inline void PrintMallInfo( const mallinfo_t& minfo )
 inline void PrintMallInfoDiff( const mallinfo_t& prev, const mallinfo_t& now )
 inline void PrintMallInfoDiff( const mallinfo_t& prev, const mallinfo_t& now )
 {
 {
 	mallinfo_t diff;
 	mallinfo_t diff;
-	diff.ordblks = now.uordblks-prev.uordblks;
+	diff.uordblks = now.uordblks-prev.uordblks;
 	diff.fordblks = now.fordblks-prev.fordblks;
 	diff.fordblks = now.fordblks-prev.fordblks;
 	diff.arena = now.arena-prev.arena;
 	diff.arena = now.arena-prev.arena;
 	PrintMallInfo( diff );
 	PrintMallInfo( diff );

+ 319 - 0
src/uncategorized/gstring.h

@@ -0,0 +1,319 @@
+#ifndef _GSTRING_H_
+#define _GSTRING_H_
+
+#include <iostream>
+#include <cstdlib>
+#include <string.h>
+
+using namespace std;
+
+
+class string_t
+{
+	private:
+		char* data;
+		bool const_data;
+		uint length;
+		
+	public:
+		// friends
+		friend ostream& operator <<( ostream& output, const string_t& str );
+		friend string_t operator +( const string_t& a, const string_t& b );
+		friend string_t operator +( const char* a, const string_t& b );
+		friend string_t operator +( char a, const string_t& b );
+		friend string_t operator +( const string_t& a, const char* b );
+		friend string_t operator +( const string_t& a, char b );
+
+		// constructor []
+		string_t(): data(NULL), const_data(true), length(0) {}
+				
+		// constructor [const char*] 
+		string_t( const char* pchar )
+		{
+			data = const_cast<char*>(pchar);
+			const_data = true;
+			length = strlen(pchar);
+			DEBUG_ERR( Length()<1 );
+		}		
+		
+		// constructor [char*]
+		string_t( char* pchar )
+		{
+			length = strlen( pchar );
+			const_data = false;
+			DEBUG_ERR( Length()<1 );
+			data = (char*) malloc( (Length()+1)*sizeof(char) );
+			memcpy( data, pchar, Length()+1 );
+		}		
+		
+		// constructor [string_t]
+		string_t( const string_t& b )
+		{
+			const_data = b.const_data;
+			length = b.Length();
+			if( b.const_data )
+				data = b.data;
+			else
+			{
+				data = (char*) malloc( (Length()+1)*sizeof(char) );
+				memcpy( data, b.data, Length()+1 );
+			}
+		}	
+		
+		// constructor [char]
+		string_t( char char_ )
+		{
+			DEBUG_ERR( char_ == '\0' );
+			data = (char*) malloc( 2*sizeof(char) );
+			data[0] = char_;
+			data[1] = '\0';
+		}	
+		
+		// destructor
+		virtual ~string_t()
+		{
+			if( length!=0 && !const_data )
+				free( data );
+		}
+		
+		// []
+		const char& operator []( uint i ) const { DEBUG_ERR(i>=length); return data[i]; }
+		char& operator []( uint i ) { DEBUG_ERR(i>=length); return data[i]; }
+		
+		// = [string_t]
+		string_t& operator =( const string_t& b )
+		{
+			if( data!=NULL && !const_data )
+				free( data );
+			const_data = b.const_data;
+			length = b.Length();
+			if( b.const_data )
+				data = b.data;
+			else
+			{
+				data = (char*) malloc( (length+1)*sizeof(char) );
+				memcpy( data, b.data, length+1 );
+			}
+			return (*this);
+		}
+			
+		// = [char*]
+		string_t& operator =( char* pchar )
+		{
+			if( data!=NULL && !const_data )
+				free( data );
+			length = strlen( pchar );
+			const_data = false;
+			DEBUG_ERR( Length()<1 );
+			data = (char*) malloc( (Length()+1)*sizeof(char) );
+			memcpy( data, pchar, Length()+1 );
+			return (*this);
+		}
+		
+		// = [const char*]
+		string_t& operator =( const char* pchar )
+		{
+			if( data!=NULL && !const_data )
+				free( data );
+			data = const_cast<char*>(pchar);
+			const_data = true;
+			length = strlen(pchar);
+			DEBUG_ERR( Length()<1 );
+			return (*this);
+		}
+		
+		// = [char]
+		string_t& operator =( char char_ )
+		{
+			if( data!=NULL && !const_data )
+				free( data );
+			DEBUG_ERR( char_ == '\0' );
+			data = (char*) malloc( 2*sizeof(char) );
+			data[0] = char_;
+			data[1] = '\0';
+			return (*this);
+		}
+		
+		// += [string_t]
+		string_t& operator +=( const string_t& str )
+		{
+			if( const_data )
+			{
+				char* data_ = (char*) malloc( (length+str.length+1)*sizeof(char) );
+				memcpy( data_, data, length );
+				data = data_;
+				const_data = false;
+			}
+			else
+			{
+				data = (char*) realloc( data, (length+str.length+1)*sizeof(char) );
+			}
+			memcpy( data+length, str.data, (str.length+1)/sizeof(char) );
+			length += str.length;
+			return (*this);
+		}
+			
+		// += [char*]
+		string_t& operator +=( const char* pchar )
+		{
+			uint pchar_len = strlen( pchar );
+			if( const_data )
+			{
+				char* data_ = (char*) malloc( (length+pchar_len+1)*sizeof(char) );
+				memcpy( data_, data, length );
+				data = data_;
+				const_data = false;
+			}
+			else
+			{
+				data = (char*) realloc( data, (length+pchar_len+1)*sizeof(char) );
+			}
+			memcpy( data+length, pchar, (pchar_len+1)/sizeof(char) );
+			length += pchar_len;
+			return (*this);
+		}
+		
+		// += [char]
+		string_t& operator +=( const char char_ )
+		{
+			if( const_data )
+			{
+				char* data_ = (char*) malloc( (length+2)*sizeof(char) );
+				memcpy( data_, data, length );
+				data = data_;
+				const_data = false;
+			}
+			else
+			{
+				data = (char*) realloc( data, (length+2)*sizeof(char) );
+			}
+			data[length] = char_;
+			data[length+1] = '\0';
+			++length;
+			return (*this);
+		}
+		
+		// Clear
+		void Clear()
+		{
+			DEBUG_ERR( (data==NULL && length!=0) || (data!=NULL && length==0) );
+			if( data != NULL )
+			{
+				if( !const_data )
+					free( data );
+				const_data = true;
+				length = 0;
+				data = NULL;
+			}
+		}
+			
+		// CStr
+		const char* CStr() const
+		{
+			DEBUG_ERR( data == NULL );
+			return data;
+		}
+		
+		// Length
+		uint Length() const
+		{
+			DEBUG_ERR( data!=NULL && length!=strlen(data) );
+			return length;
+		}
+		
+		// Find
+		uint Find( char c, uint pos = 0 ) const
+		{
+			DEBUG_ERR( pos >= length ); // not my bug
+			char* pc = data + pos;
+			while( *pc!=c && *pc!='\0' )
+			{
+				++pc;
+			}
+			return pc - data;
+		}
+};
+
+
+/// string_t + string_t
+inline string_t operator +( const string_t& a, const string_t& b )
+{
+	string_t out;
+	out.const_data = false;
+	out.data = (char*) malloc( (a.length+b.length+1)*sizeof(char) );
+	memcpy( out.data, a.data, a.length );
+	memcpy( out.data+a.length, b.data, b.length+1 );
+	out.length = a.length+b.length;
+	return out;
+}
+
+
+/// char* + string_t
+inline string_t operator +( const char* a, const string_t& b )
+{
+	DEBUG_ERR( strlen(a)<1 || b.length<1 ); // not my bug
+	string_t out;
+	uint a_length = strlen( a );
+	out.length = a_length+b.length;
+	out.const_data = false;
+	out.data = (char*) malloc( (out.length+1)*sizeof(char) );
+	memcpy( out.data, a, a_length );
+	if( b.length > 0 )
+		memcpy( out.data+a_length, b.data, b.length+1 );
+	else
+		out.data[out.length] = '\0';
+	return out;
+}
+
+
+/// char + string_t
+inline string_t operator +( char a, const string_t& b )
+{
+	string_t out;
+	out.const_data = false;
+	out.data = (char*) malloc( (b.length+2)*sizeof(char) );
+	out.data[0] = a;
+	memcpy( out.data+1, b.data, b.length+1 );
+	out.length = 1+b.length;
+	return out;
+}
+
+
+/// string_t + char*
+inline string_t operator +( const string_t& a, const char* b )
+{
+	DEBUG_ERR( a.length<1 || strlen(b)<1 ); // not my bug
+	string_t out;
+	uint b_length = strlen( b );
+	out.const_data = false;
+	out.length = a.length+b_length;
+	out.data = (char*) malloc( (out.length+1)*sizeof(char) );
+	memcpy( out.data, a.data, a.length );
+	memcpy( out.data+a.length, b, b_length+1 );
+	return out;
+}
+
+
+/// string_t + char
+inline string_t operator +( const string_t& a, char b )
+{
+	DEBUG_ERR( a.length<1 ); // not my bug
+	string_t out;
+	out.const_data = false;
+	out.data = (char*) malloc( (a.length+2)*sizeof(char) );
+	memcpy( out.data, a.data, a.length );
+	out.data[a.length] = b;
+	out.data[a.length+1] = '\0';
+	out.length = a.length+1;
+	return out;
+}
+
+
+/// For cout support
+inline ostream& operator <<( ostream& output, const string_t& str ) 
+{
+	output << str.data;
+	return output;
+}
+
+#endif

+ 6 - 4
src/uncategorized/shader_prog.cpp

@@ -41,7 +41,7 @@ uint shader_prog_t::CreateAndCompileShader( const char* source_code, int type )
 		info_log = (char*)malloc( (info_len+1)*sizeof(char) );
 		info_log = (char*)malloc( (info_len+1)*sizeof(char) );
 		glGetShaderInfoLog( gl_id, info_len, &chars_written, info_log );
 		glGetShaderInfoLog( gl_id, info_len, &chars_written, info_log );
 		
 		
-		char* shader_type;
+		const char* shader_type;
 		switch( type )
 		switch( type )
 		{
 		{
 			case GL_VERTEX_SHADER:
 			case GL_VERTEX_SHADER:
@@ -105,6 +105,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 	GLint size;
 	GLint size;
 	GLenum type;
 	GLenum type;
 
 
+
 	// attrib locations
 	// attrib locations
 	glGetProgramiv( gl_id, GL_ACTIVE_ATTRIBUTES, &num );
 	glGetProgramiv( gl_id, GL_ACTIVE_ATTRIBUTES, &num );
 	for( int i=0; i<num; i++ ) // loop all attributes
 	for( int i=0; i<num; i++ ) // loop all attributes
@@ -113,7 +114,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 		name_[ length ] = '\0';
 		name_[ length ] = '\0';
 
 
 		// check if its FFP location
 		// check if its FFP location
-		if( GetAttributeLocationSilently(name_) == -1 )
+		if( glGetAttribLocation(gl_id, name_) == -1 )
 		{
 		{
 			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
 			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
 			continue;
 			continue;
@@ -131,7 +132,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 		name_[ length ] = '\0';
 		name_[ length ] = '\0';
 
 
 		// check if its FFP location
 		// check if its FFP location
-		if( GetUniformLocationSilently(name_) == -1 )
+		if( glGetUniformLocation(gl_id, name_) == -1 )
 		{
 		{
 			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
 			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
 			continue;
 			continue;
@@ -147,6 +148,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 //=====================================================================================================================================
 //=====================================================================================================================================
 bool shader_prog_t::FillTheCustomLocationsVectors( const shader_parser_t& pars )
 bool shader_prog_t::FillTheCustomLocationsVectors( const shader_parser_t& pars )
 {
 {
+	Bind();
 	uint max = 0;
 	uint max = 0;
 
 
 	// uniforms
 	// uniforms
@@ -213,7 +215,7 @@ bool shader_prog_t::Load( const char* filename )
 
 
 	if( !pars.ParseFile( filename ) ) return false;
 	if( !pars.ParseFile( filename ) ) return false;
 
 
-	PRINT( pars.frag_shader_source )
+	//PRINT( pars.frag_shader_source )
 
 
 	// create, compile, attach and link
 	// create, compile, attach and link
 	uint vert_gl_id = CreateAndCompileShader( pars.vert_shader_source.c_str(), GL_VERTEX_SHADER );
 	uint vert_gl_id = CreateAndCompileShader( pars.vert_shader_source.c_str(), GL_VERTEX_SHADER );

+ 0 - 1
src/uncategorized/smodel.cpp

@@ -754,7 +754,6 @@ void smodel_t::Render()
 	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
 	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
 	glDisableVertexAttribArray( loc );*/
 	glDisableVertexAttribArray( loc );*/
 
 
-
 	glUniformMatrix3fv( material->skinning_rotations_uni_loc, model_data->skeleton_data->bones.size(), 1, &(bone_rotations[0])[0] );
 	glUniformMatrix3fv( material->skinning_rotations_uni_loc, model_data->skeleton_data->bones.size(), 1, &(bone_rotations[0])[0] );
 	glUniform3fv( material->skinning_translations_uni_loc, model_data->skeleton_data->bones.size(), &(bone_translations[0])[0] );
 	glUniform3fv( material->skinning_translations_uni_loc, model_data->skeleton_data->bones.size(), &(bone_translations[0])[0] );