Răsfoiți Sursa

*Trying to remove FFP from shders. Be ready for GL3.x
*The moved common crap to the new utility dir
*Work in progress: Making renderer a class. Dir: renderer2
*Other minor changes

Panagiotis Christopoulos Charitos 16 ani în urmă
părinte
comite
0c0596d1fd
53 a modificat fișierele cu 1031 adăugiri și 622 ștergeri
  1. 18 14
      shaders/is_lp_generic.glsl
  2. 10 0
      shaders/is_lp_point.glsl
  3. 11 1
      shaders/is_lp_spot.glsl
  4. 12 2
      shaders/is_lp_spot_shad.glsl
  5. 33 0
      shaders/median_filter.glsl
  6. 31 24
      shaders/ms_mp_generic.glsl
  7. 15 10
      shaders/simple_texturing.glsl
  8. 4 1
      shaders/simple_vert.glsl
  9. 9 4
      src/main.cpp
  10. 2 3
      src/math/m_misc.h
  11. 4 4
      src/math/m_misc.inl.h
  12. 2 2
      src/math/mat3.h
  13. 3 3
      src/math/mat3.inl.h
  14. 3 2
      src/math/mat4.h
  15. 14 4
      src/math/mat4.inl.h
  16. 2 2
      src/math/quat.h
  17. 5 5
      src/math/quat.inl.h
  18. 1 1
      src/math/vec2.h
  19. 1 1
      src/math/vec2.inl.h
  20. 7 7
      src/math/vec3.h
  21. 17 17
      src/math/vec3.inl.h
  22. 1 1
      src/math/vec4.h
  23. 2 2
      src/math/vec4.inl.h
  24. 48 53
      src/renderer/r_is.cpp
  25. 2 2
      src/renderer/r_is_shadows.cpp
  26. 2 2
      src/renderer/r_ms.cpp
  27. 1 8
      src/renderer/r_pps.cpp
  28. 3 13
      src/renderer/r_pps_hdr.cpp
  29. 1 4
      src/renderer/r_pps_lscatt.cpp
  30. 5 14
      src/renderer/r_pps_ssao.cpp
  31. 3 6
      src/renderer/r_private.h
  32. 22 12
      src/renderer/renderer.cpp
  33. 8 5
      src/renderer/renderer.h
  34. 4 0
      src/renderer2/r_is.cpp
  35. 73 0
      src/renderer2/r_ms.cpp
  36. 50 0
      src/renderer2/renderer.cpp
  37. 257 0
      src/renderer2/renderer.hpp
  38. 3 3
      src/uncategorized/camera.cpp
  39. 11 11
      src/uncategorized/collision.cpp
  40. 0 152
      src/uncategorized/common.cpp
  41. 7 10
      src/uncategorized/common.h
  42. 11 15
      src/uncategorized/material.cpp
  43. 20 11
      src/uncategorized/material.h
  44. 26 38
      src/uncategorized/mesh.cpp
  45. 8 7
      src/uncategorized/particles.cpp
  46. 4 2
      src/uncategorized/resource.h
  47. 2 1
      src/uncategorized/shader_parser.cpp
  48. 8 4
      src/uncategorized/shader_prog.cpp
  49. 52 77
      src/uncategorized/smodel.cpp
  50. 1 6
      src/uncategorized/texture.cpp
  51. 25 56
      src/utility/u_string.h
  52. 147 0
      src/utility/util.cpp
  53. 20 0
      src/utility/util.h

+ 18 - 14
shaders/is_lp_generic.glsl

@@ -2,13 +2,16 @@
 
 #pragma anki attribute view_vector 0
 attribute vec3 view_vector;
+#pragma anki attribute position 1
+attribute vec2 position;
+
 varying vec2 tex_coords;
 varying vec3 vpos;
 
 void main()
 {
 	vpos = view_vector;
-	vec2 vert_pos = gl_Vertex.xy; // the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
+	vec2 vert_pos = position; // the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
 	tex_coords = vert_pos;
 	vec2 vert_pos_ndc = vert_pos*2.0 - 1.0;
 	gl_Position = vec4( vert_pos_ndc, 0.0, 1.0 );
@@ -19,15 +22,16 @@ void main()
 
 #pragma anki include "shaders/pack.glsl"
 
-#pragma anki uniform ms_normal_fai 0
-#pragma anki uniform ms_diffuse_fai 1
-#pragma anki uniform ms_specular_fai 2
-#pragma anki uniform ms_depth_fai 3
+// uniforms
 uniform sampler2D ms_normal_fai, ms_diffuse_fai, ms_specular_fai, ms_depth_fai;
-#pragma anki uniform planes 4
 uniform vec2 planes; // for the calculation of frag pos in view space
 uniform sampler2D light_tex;
 uniform sampler2DShadow shadow_map;
+uniform vec3 light_pos;
+uniform float light_inv_radius;
+uniform vec3 light_diffuse_col;
+uniform vec3 light_specular_col;
+uniform mat4 tex_projection_mat;
 
 varying vec2 tex_coords;
 varying vec3 vpos; // for the calculation of frag pos in view space
@@ -61,8 +65,7 @@ return the attenuation factor fiven the distance from the frag to the light sour
 */
 float Attenuation( in float _frag_light_dist )
 {
-	float _inv_light_radius = gl_LightSource[0].position.w;
-	return clamp(1.0 - _inv_light_radius * sqrt(_frag_light_dist), 0.0, 1.0);
+	return clamp(1.0 - light_inv_radius * sqrt(_frag_light_dist), 0.0, 1.0);
 	//return 1.0 - _frag_light_dist * _inv_light_radius;
 }
 
@@ -78,7 +81,7 @@ it returns a blured shadow
 float PCF_Off( in vec3 _shadow_uv )
 {
 	return shadow2D(shadow_map, _shadow_uv ).r;
-}
+}
 
 
 float PCF_Low( in vec3 _shadow_uv )
@@ -179,7 +182,7 @@ Phong
 vec3 Phong( in vec3 _frag_pos_vspace, out float _frag_light_dist )
 {
 	// get the lambert term
-	vec3 _light_pos_eyespace = gl_LightSource[0].position.xyz;
+	vec3 _light_pos_eyespace = light_pos;
 	vec3 _light_frag_vec = _light_pos_eyespace - _frag_pos_vspace;
 
 	_frag_light_dist = dot( _light_frag_vec, _light_frag_vec ); // instead of using normalize(_frag_light_dist) we brake the operation...
@@ -197,7 +200,7 @@ vec3 Phong( in vec3 _frag_pos_vspace, out float _frag_light_dist )
 
 	// diffuce lighting
 	vec3 _diffuse = texture2D( ms_diffuse_fai, tex_coords ).rgb;
-	_diffuse = (_diffuse * gl_LightSource[0].diffuse.rgb);
+	_diffuse = (_diffuse * light_diffuse_col);
 	vec3 _color = _diffuse * _lambert_term;
 
 	// specular lighting
@@ -208,7 +211,7 @@ vec3 Phong( in vec3 _frag_pos_vspace, out float _frag_light_dist )
 	vec3 _eye_vec = normalize( -_frag_pos_vspace );
 	vec3 _h = normalize( _light_dir + _eye_vec );
 	float _spec_intensity = pow(max(0.0, dot(_normal, _h)), _shininess);
-	_color += _specular * vec3(gl_LightSource[0].specular) * (_spec_intensity * _lambert_term);
+	_color += _specular * light_specular_col * (_spec_intensity * _lambert_term);
 
 	return _color;
 }
@@ -239,7 +242,7 @@ void main()
 	// SPOT LIGHT                                                                                                                       =
 	//===================================================================================================================================
 	#elif defined(_SPOT_LIGHT_)
-		vec4 _tex_coord2 = gl_TextureMatrix[0] * vec4(_frag_pos_vspace, 1.0);
+		vec4 _tex_coord2 = tex_projection_mat * vec4(_frag_pos_vspace, 1.0);
 		vec3 _tex_coords3 = _tex_coord2.xyz / _tex_coord2.w;
 
 		if
@@ -249,12 +252,13 @@ void main()
 			_tex_coords3.x < 1.0 &&
 			_tex_coords3.y > 0.0 &&
 			_tex_coords3.y < 1.0 &&
-			_tex_coord2.w < 1.0/gl_LightSource[0].position.w
+			_tex_coord2.w < 1.0/light_inv_radius
 		)
 		{
 			#if defined( _SHADOW_ )
 				#if defined( _SHADOW_MAPPING_PCF_ )
 					float _shadow_color = PCF_Low( _tex_coords3 );
+					//float _shadow_color = MedianFilterPCF( shadow_map, _tex_coords3 );
 				#else
 					float _shadow_color = PCF_Off( _tex_coords3 );
 				#endif

+ 10 - 0
shaders/is_lp_point.glsl

@@ -1,3 +1,13 @@
 #define _POINT_LIGHT_
 
+#pragma anki uniform ms_normal_fai 0
+#pragma anki uniform ms_diffuse_fai 1
+#pragma anki uniform ms_specular_fai 2
+#pragma anki uniform ms_depth_fai 3
+#pragma anki uniform planes 4
+#pragma anki uniform light_pos 5
+#pragma anki uniform light_inv_radius 6
+#pragma anki uniform light_diffuse_col 7
+#pragma anki uniform light_specular_col 8
+
 #pragma anki include "shaders/is_lp_generic.glsl"

+ 11 - 1
shaders/is_lp_spot.glsl

@@ -1,5 +1,15 @@
 #define _SPOT_LIGHT_
 
-#pragma anki uniform light_tex 5
+#pragma anki uniform ms_normal_fai 0
+#pragma anki uniform ms_diffuse_fai 1
+#pragma anki uniform ms_specular_fai 2
+#pragma anki uniform ms_depth_fai 3
+#pragma anki uniform planes 4
+#pragma anki uniform light_pos 5
+#pragma anki uniform light_inv_radius 6
+#pragma anki uniform light_diffuse_col 7
+#pragma anki uniform light_specular_col 8
+#pragma anki uniform light_tex 9
+#pragma anki uniform tex_projection_mat 10
 
 #pragma anki include "shaders/is_lp_generic.glsl"

+ 12 - 2
shaders/is_lp_spot_shad.glsl

@@ -1,7 +1,17 @@
 #define _SPOT_LIGHT_
 #define _SHADOW_
 
-#pragma anki uniform light_tex 5
-#pragma anki uniform shadow_map 6
+#pragma anki uniform ms_normal_fai 0
+#pragma anki uniform ms_diffuse_fai 1
+#pragma anki uniform ms_specular_fai 2
+#pragma anki uniform ms_depth_fai 3
+#pragma anki uniform planes 4
+#pragma anki uniform light_pos 5
+#pragma anki uniform light_inv_radius 6
+#pragma anki uniform light_diffuse_col 7
+#pragma anki uniform light_specular_col 8
+#pragma anki uniform light_tex 9
+#pragma anki uniform tex_projection_mat 10
+#pragma anki uniform shadow_map 11
 
 #pragma anki include "shaders/is_lp_generic.glsl"

+ 33 - 0
shaders/median_filter.glsl

@@ -114,3 +114,36 @@ float MedianAndBlurA( in sampler2D tex, in vec2 tex_coords )
   mnmx3(v[3], v[4], v[8]);
   return v[4]*0.5 + sum/18.0;
 }
+
+
+//=====================================================================================================================================
+// MedianFilterPCF                                                                                                                    =
+//=====================================================================================================================================
+float MedianFilterPCF( in sampler2DShadow tex, in vec3 tex_coords )
+{
+	vec2 tex_inv_size = 1.0/vec2(textureSize(tex, 0));
+  float v[9];
+
+  // Add the pixels which make up our window to the pixel array.
+	for(int dX = -1; dX <= 1; ++dX)
+	{
+		for(int dY = -1; dY <= 1; ++dY)
+		{
+			vec2 offset = vec2(float(dX), float(dY));
+
+			// If a pixel in the window is located at (x+dX, y+dY), put it at index (dX + R)(2R + 1) + (dY + R) of the
+			// pixel array. This will fill the pixel array, with the top left pixel of the window at pixel[0] and the
+			// bottom right pixel of the window at pixel[N-1].
+			v[(dX + 1) * 3 + (dY + 1)] = shadow2D(tex, tex_coords + vec3(offset * tex_inv_size, 0.0)).r;
+		}
+	}
+
+  float temp;
+
+  // Starting with a subset of size 6, remove the min and max each time
+  mnmx6(v[0], v[1], v[2], v[3], v[4], v[5]);
+  mnmx5(v[1], v[2], v[3], v[4], v[6]);
+  mnmx4(v[2], v[3], v[4], v[7]);
+  mnmx3(v[3], v[4], v[8]);
+  return v[4];
+}

+ 31 - 24
shaders/ms_mp_generic.glsl

@@ -20,15 +20,22 @@
  */
 #pragma anki include "shaders/hw_skinning.glsl"
 
-varying vec3 normal;
+// attributes
+attribute vec3 position;
+attribute vec3 normal;
+attribute vec2 tex_coords;
+attribute vec4 tangent;
 
-varying vec2 tex_coords_v2f;
-uniform vec2 tex_coords;
+// uniforms
+uniform mat4 MVP_mat;
+uniform mat4 MV_mat;
+uniform mat3 N_mat;
 
-attribute vec4 tangent;
+// varyings
+varying vec3 normal_v2f;
+varying vec2 tex_coords_v2f;
 varying vec3 tangent_v2f;
 varying float w_v2f;
-
 varying vec3 eye_v2f; ///< In tangent space
 varying vec3 vert_pos_eye_space_v2f;
 
@@ -48,31 +55,31 @@ void main()
 
 		HWSkinning( _rot, _tsl );
 
-		normal = gl_NormalMatrix * ( _rot * gl_Normal );
+		normal_v2f = gl_NormalMatrix * ( _rot * normal );
 
 		#if NEEDS_TANGENT
 			tangent_v2f = gl_NormalMatrix * ( _rot * vec3(tangent) );
 		#endif
 
-		vec3 pos_lspace = ( _rot * gl_Vertex.xyz) + _tsl;
+		vec3 pos_lspace = ( _rot * position) + _tsl;
 		gl_Position =  gl_ModelViewProjectionMatrix * vec4(pos_lspace, 1.0);
 
 	// if DONT have hardware skinning
 	#else
-		normal = gl_NormalMatrix * gl_Normal;
+		normal_v2f = gl_NormalMatrix * normal;
 
 		#if NEEDS_TANGENT
 			tangent_v2f = gl_NormalMatrix * vec3(tangent);
 		#endif
 
-		gl_Position = ftransform();
+		gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
 	#endif
 
 
 	// calculate the rest
 
 	#if NEEDS_TEX_MAPPING
-		tex_coords_v2f = gl_MultiTexCoord0.xy;
+		tex_coords_v2f = tex_coords;
 	#endif
 
 
@@ -82,14 +89,14 @@ void main()
 
 
 	#if defined( _ENVIRONMENT_MAPPING_ )
-		vert_pos_eye_space_v2f = vec3( gl_ModelViewMatrix * gl_Vertex );
+		vert_pos_eye_space_v2f = vec3( gl_ModelViewMatrix * vec4(position, 1.0) );
 	#endif
 
 
 	#if defined( _PARALLAX_MAPPING_ )
-		vec3 t = gl_NormalMatrix * tangent.xyz;
+		/*vec3 t = gl_NormalMatrix * tangent.xyz;
 		vec3 n = normal;
-		vec3 b = cross( n, t ) /* tangent.w*/;
+		vec3 b = cross( n, t )  tangent.w;
 
 		vec3 eye_pos = gl_Position.xyz - gl_ModelViewMatrixInverse[3].xyz;
 		eye_pos = eye_pos - ( gl_ModelViewMatrixInverse * gl_Vertex ).xyz;
@@ -97,7 +104,7 @@ void main()
 		mat3 tbn_mat = mat3( t, b, n );
 		eye = tbn_mat * eye_pos;
 		//eye.y = -eye.y;
-		//eye.x = -eye.x;
+		//eye.x = -eye.x;*/
 	#endif
 }
 
@@ -105,13 +112,13 @@ void main()
 #pragma anki frag_shader_begins
 
 /**
-Note: The process of calculating the diffuse color for the diffuse MSFAI is divided into two parts. The first happens before the
-normal calculation and the other just after it. In the first part we read the texture (or the gl_Color) and we set the _diff_color.
-In case of grass we discard. In the second part we calculate a SEM color and we combine it with the _diff_color. We cannot put
-the second part before normal calculation because SEM needs the _new_normal. Also we cannot put the first part after normal
-calculation because in case of grass we will waste calculations for the normal. For that two reasons we split the diffuse
-calculations in two parts
-*/
+ * Note: The process of calculating the diffuse color for the diffuse MSFAI is divided into two parts. The first happens before the
+ * normal calculation and the other just after it. In the first part we read the texture (or the gl_Color) and we set the _diff_color.
+ * In case of grass we discard. In the second part we calculate a SEM color and we combine it with the _diff_color. We cannot put
+ * the second part before normal calculation because SEM needs the _new_normal. Also we cannot put the first part after normal
+ * calculation because in case of grass we will waste calculations for the normal. For that two reasons we split the diffuse
+ * calculations in two parts
+ */
 
 #pragma anki include "shaders/pack.glsl"
 
@@ -127,7 +134,7 @@ uniform sampler2D specular_map;
 uniform sampler2D height_map;
 uniform sampler2D environment_map;
 
-varying vec3 normal;
+varying vec3 normal_v2f;
 varying vec3 tangent_v2f;
 varying float w_v2f;
 varying vec2 tex_coords_v2f;
@@ -188,7 +195,7 @@ void main()
 	// Either use a normap map and make some calculations or use the vertex normal                                                      =
 	//===================================================================================================================================
 	#if defined( _HAS_NORMAL_MAP_ )
-		vec3 _n = normalize( normal );
+		vec3 _n = normalize( normal_v2f );
 		vec3 _t = normalize( tangent_v2f );
 		vec3 _b = cross(_n, _t) * w_v2f;
 
@@ -198,7 +205,7 @@ void main()
 
 		vec3 _new_normal = normalize( _tbn_mat * _n_at_tangentspace );
 	#else
-		vec3 _new_normal = normalize(normal);
+		vec3 _new_normal = normalize(normal_v2f);
 	#endif
 
 

+ 15 - 10
shaders/simple_texturing.glsl

@@ -1,13 +1,17 @@
 #pragma anki vert_shader_begins
 
-varying vec2 tex_coords;
-varying vec3 normal;
+attribute vec3 position;
+attribute vec3 normal;
+attribute vec2 tex_coords;
+
+varying vec2 tex_coords_v2f;
+varying vec3 normal_v2f;
 
 void main()
 {
-	tex_coords = gl_MultiTexCoord0.xy;
-	normal = gl_NormalMatrix * gl_Normal;
-	gl_Position = ftransform();
+	tex_coords_v2f = tex_coords;
+	normal_v2f = gl_NormalMatrix * normal;
+	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
 }
 
 #pragma anki frag_shader_begins
@@ -15,18 +19,19 @@ void main()
 #pragma anki include "shaders/pack.glsl"
 
 uniform sampler2D diffuse_map, noise_map;
-varying vec2 tex_coords;
-varying vec3 normal;
+varying vec2 tex_coords_v2f;
+varying vec3 normal_v2f;
 
 void main()
 {
 	/*vec3 _noise = DecodeNormal( texture2D( noise_map, gl_FragCoord.xy*vec2( 1.0/R_W, 1.0/R_H ) ).rg ).rgb;
 	_noise = _noise * 2 - 1;
 	_noise *= 7.0;*/
-	vec4 _texel = texture2D( diffuse_map, (gl_FragCoord.xy+(normal.xy*2))*vec2( 1.0/R_W, 1.0/R_H ) );
+
+	vec4 _texel = texture2D( diffuse_map, (gl_FragCoord.xy+(normal_v2f.xy*2))*vec2( 1.0/R_W, 1.0/R_H ) );
 
 
-	//vec4 _texel = texture2D( diffuse_map, tex_coords );
+	//vec4 _texel = texture2D( diffuse_map, tex_coords_v2f ) / 2;
 
-	gl_FragColor = _texel;
+	gl_FragData[0] = _texel;
 }

+ 4 - 1
shaders/simple_vert.glsl

@@ -5,11 +5,14 @@
  * position. The vertex positions of the quad are from 0.0 to 1.0 for both axis.
  */
 
+#pragma anki attribute position 0
+attribute vec2 position;
+
 varying vec2 tex_coords;
 
 void main()
 {
-	vec2 vert_pos = gl_Vertex.xy; // the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
+	vec2 vert_pos = position; // the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
 	tex_coords = vert_pos;
 	vec2 vert_pos_ndc = vert_pos*2.0 - 1.0;
 	gl_Position = vec4( vert_pos_ndc, 0.0, 1.0 );

+ 9 - 4
src/main.cpp

@@ -109,7 +109,7 @@ void Init()
 	point_lights[0].SetDiffuseColor( vec3_t( 1.0, 0.0, 0.0)*1 );
 	point_lights[0].translation_lspace = vec3_t( -1.0, 2.4, 1.0 );
 	point_lights[0].radius = 2.0;
-	point_lights[1].SetSpecularColor( vec3_t( 0.0, 0.0, 1.0)*4 );
+	point_lights[1].SetSpecularColor( vec3_t( 0.0, 1.0, 0.0)*1 );
 	point_lights[1].SetDiffuseColor( vec3_t( 3.0, 0.1, 0.1) );
 	point_lights[1].translation_lspace = vec3_t( 2.5, 1.4, 1.0 );
 	point_lights[1].radius = 3.0;
@@ -172,6 +172,7 @@ void Init()
 
 	scene::smodels.Register( &mdl );
 	scene::meshes.Register( &sarge );
+	//scene::meshes.Register( &sphere );
 	//scene::Register( &imp );
 	scene::meshes.Register( &floor__ );
 	scene::meshes.Register( &mcube );
@@ -280,9 +281,13 @@ int main( int /*argc*/, char* /*argv*/[] )
 		// std stuff follow
 		SDL_GL_SwapBuffers();
 		r::PrintLastError();
-		if( r::frames_num == 10 ) r::TakeScreenshot("gfx/screenshot.tga");
-		hndl::WaitForNextFrame();
-		//if( r::frames_num == 5000 ) break;
+		if( 0 )
+		{
+			if( r::frames_num == 10 ) r::TakeScreenshot("gfx/screenshot.tga");
+			hndl::WaitForNextFrame();
+		}
+		else
+			if( r::frames_num == 5000 ) break;
 	}while( true );
 	PRINT( "Exiting main loop (" << hndl::GetTicks()-ticks << ")" );
 

+ 2 - 3
src/math/m_misc.h

@@ -24,14 +24,13 @@ bool  IsZero( float f );
 float Max( float a, float b );
 float Min( float a, float b );
 
-
 /**
  * CombineTransformations
  * mat4(t0,r0,s0)*mat4(t1,r1,s1) == mat4(tf,rf,sf)
  */
 void CombineTransformations( const vec3_t& t0, const mat3_t& r0, float s0,
-                                    const vec3_t& t1, const mat3_t& r1, float s1,
-                                    vec3_t& tf, mat3_t& rf, float& sf );
+                             const vec3_t& t1, const mat3_t& r1, float s1,
+                             vec3_t& tf, mat3_t& rf, float& sf );
 
 /// CombineTransformations as the above but without scale
 void CombineTransformations( const vec3_t& t0, const mat3_t& r0, const vec3_t& t1, const mat3_t& r1, vec3_t& tf, mat3_t& rf);

+ 4 - 4
src/math/m_misc.inl.h

@@ -124,10 +124,10 @@ M_INLINE float Min( float a, float b ) { return (a<b) ? a : b; }
 //  CombineTransformations
 //  mat4(t0,r0,s0)*mat4(t1,r1,s1) == mat4(tf,rf,sf)
 M_INLINE void CombineTransformations( const vec3_t& t0, const mat3_t& r0, float s0,
-                             const vec3_t& t1, const mat3_t& r1, float s1,
-                             vec3_t& tf, mat3_t& rf, float& sf )
+                                      const vec3_t& t1, const mat3_t& r1, float s1,
+                                      vec3_t& tf, mat3_t& rf, float& sf )
 {
-	tf = t1.Transformed( t0, r0, s0 );
+	tf = t1.GetTransformed( t0, r0, s0 );
 	rf = r0 * r1;
 	sf = s0 * s1;
 }
@@ -135,7 +135,7 @@ M_INLINE void CombineTransformations( const vec3_t& t0, const mat3_t& r0, float
 //  CombineTransformations as the above but without scale
 M_INLINE void CombineTransformations( const vec3_t& t0, const mat3_t& r0, const vec3_t& t1, const mat3_t& r1, vec3_t& tf, mat3_t& rf)
 {
-	tf = t1.Transformed( t0, r0 );
+	tf = t1.GetTransformed( t0, r0 );
 	rf = r0 * r1;
 }
 

+ 2 - 2
src/math/mat3.h

@@ -72,12 +72,12 @@ class mat3_t
 		void   RotateYAxis( float rad );
 		void   RotateZAxis( float rad );
 		void   Transpose();
-		mat3_t Transposed() const;
+		mat3_t GetTransposed() const;
 		void   Reorthogonalize();
 		void   Print() const;
 		float  Det() const;
 		void   Invert();
-		mat3_t Inverted() const;		
+		mat3_t GetInverse() const;
 		static const mat3_t& GetZero();
 		static const mat3_t& GetIdentity();		
 };

+ 3 - 3
src/math/mat3.inl.h

@@ -499,7 +499,7 @@ M_INLINE void mat3_t::Transpose()
 }
 
 // Transposed
-M_INLINE mat3_t mat3_t::Transposed() const
+M_INLINE mat3_t mat3_t::GetTransposed() const
 {
 	mat3_t m3;
 	m3[0] = ME[0];
@@ -565,7 +565,7 @@ M_INLINE float mat3_t::Det() const
 
 // Invert
 // using Gramer's method ( Inv(A) = ( 1/Det(A) ) * Adj(A)  )
-M_INLINE mat3_t mat3_t::Inverted() const
+M_INLINE mat3_t mat3_t::GetInverse() const
 {
 	mat3_t result;
 
@@ -598,7 +598,7 @@ M_INLINE mat3_t mat3_t::Inverted() const
 // see above
 M_INLINE void mat3_t::Invert()
 {
-	ME = Inverted();
+	ME = GetInverse();
 }
 
 // GetZero

+ 3 - 2
src/math/mat4.h

@@ -68,11 +68,12 @@ class mat4_t
 		void   SetTranslationPart( const vec3_t& v3 );
 		vec3_t GetTranslationPart() const;
 		void   Transpose();
-		mat4_t Transposed() const;
+		mat4_t GetTransposed() const;
 		void   Print() const;
 		float  Det() const;
 		void   Invert();
-		mat4_t Inverted() const;
+		mat4_t GetInverse() const;
+		mat4_t GetInverseTransformation() const;
 		mat4_t Lerp( const mat4_t& b, float t ) const;
 		static mat4_t CombineTransformations( const mat4_t& m0, const mat4_t& m1 );  // 12 muls, 27 adds. Something like m4 = m0 * m1 ...
 		                                                                             // ...but without touching the 4rth row and allot faster

+ 14 - 4
src/math/mat4.inl.h

@@ -394,9 +394,9 @@ M_INLINE void mat4_t::Transpose()
 	ME(3,2) = tmp;
 }
 
-// Transposed
+// GetTransposed
 // return the transposed
-M_INLINE mat4_t mat4_t::Transposed() const
+M_INLINE mat4_t mat4_t::GetTransposed() const
 {
 	mat4_t m4;
 	m4[0] = ME[0];
@@ -524,11 +524,11 @@ M_INLINE float mat4_t::Det() const
 // Invert
 M_INLINE void mat4_t::Invert()
 {
-	ME = Inverted();
+	ME = GetInverse();
 }
 
 // Inverted
-M_INLINE mat4_t mat4_t::Inverted() const
+M_INLINE mat4_t mat4_t::GetInverse() const
 {
 	float tmp[12];
 	float det;
@@ -606,6 +606,16 @@ M_INLINE mat4_t mat4_t::Inverted() const
 	return m4;
 }
 
+
+// GetInverseTransformation
+M_INLINE mat4_t mat4_t::GetInverseTransformation() const
+{
+	mat3_t inverted_rot = (GetRotationPart()).GetTransposed();
+	vec3_t inverted_tsl = GetTranslationPart();
+	inverted_tsl = -( inverted_rot * inverted_tsl );
+	return mat4_t( inverted_tsl, inverted_rot );
+}
+
 // Lerp
 M_INLINE mat4_t mat4_t::Lerp( const mat4_t& b, float t ) const
 {

+ 2 - 2
src/math/quat.h

@@ -39,11 +39,11 @@ class quat_t
 		void   Conjugate();
 		quat_t Conjugated() const;
 		void   Normalize();
-		quat_t Normalized() const;
+		quat_t GetNormalized() const;
 		void   Print() const;
 		float  Dot( const quat_t& b ) const;
 		quat_t Slerp( const quat_t& q1, float t ) const; // returns Slerp( this, q1, t )
-		quat_t Rotated( const quat_t& b ) const;
+		quat_t GetRotated( const quat_t& b ) const;
 		void   Rotate( const quat_t& b );
 };
 

+ 5 - 5
src/math/quat.inl.h

@@ -170,15 +170,15 @@ M_INLINE quat_t quat_t::Conjugated() const
 }
 
 // Normalized
-M_INLINE quat_t quat_t::Normalized() const
+M_INLINE quat_t quat_t::GetNormalized() const
 {
-	return quat_t( vec4_t(ME).Normalized() );
+	return quat_t( vec4_t(ME).GetNormalized() );
 }
 
 // Normalize
 M_INLINE void quat_t::Normalize()
 {
-	ME = Normalized();
+	ME = GetNormalized();
 }
 
 // Length
@@ -223,7 +223,7 @@ M_INLINE void quat_t::CalcFrom2Vec3( const vec3_t& from, const vec3_t& to )
 }
 
 // Rotated
-M_INLINE quat_t quat_t::Rotated( const quat_t& b ) const
+M_INLINE quat_t quat_t::GetRotated( const quat_t& b ) const
 {
 	return ME * b;
 }
@@ -231,7 +231,7 @@ M_INLINE quat_t quat_t::Rotated( const quat_t& b ) const
 // Rotate
 M_INLINE void quat_t::Rotate( const quat_t& b )
 {
-	ME = Rotated( b );
+	ME = GetRotated( b );
 }
 
 // Dot

+ 1 - 1
src/math/vec2.h

@@ -53,7 +53,7 @@ class vec2_t
 		float  Length() const;
 		void   SetZero();
 		void   Normalize();
-		vec2_t Normalized() const;
+		vec2_t GetNormalized() const;
 		float  Dot( const vec2_t& b ) const;
 		void   Print() const;
 };

+ 1 - 1
src/math/vec2.inl.h

@@ -187,7 +187,7 @@ M_INLINE void vec2_t::Normalize()
 }
 
 // Normalized (return the normalized)
-M_INLINE vec2_t vec2_t::Normalized() const
+M_INLINE vec2_t vec2_t::GetNormalized() const
 {
 	return ME * InvSqrt( x*x + y*y );
 }

+ 7 - 7
src/math/vec3.h

@@ -55,22 +55,22 @@ class vec3_t
 		float  LengthSquared() const;
 		float  DistanceSquared( const vec3_t& b ) const;
 		void   Normalize();
-		vec3_t Normalized() const;
+		vec3_t GetNormalized() const;
 		vec3_t Project( const vec3_t& to_this ) const;
-		vec3_t Rotated( const quat_t& q ) const; // returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
+		vec3_t GetRotated( const quat_t& q ) const; // returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
 		void   Rotate( const quat_t& q );
 		vec3_t Lerp( const vec3_t& v1, float t ) const; // return Lerp( this, v1, t )
 		void   Print() const;
 		// transformations. The faster way is by far the mat4 * vec3 or the Transformed( vec3_t, mat3_t )
-		vec3_t Transformed( const vec3_t& translate, const mat3_t& rotate, float scale ) const;
+		vec3_t GetTransformed( const vec3_t& translate, const mat3_t& rotate, float scale ) const;
 		void   Transform( const vec3_t& translate, const mat3_t& rotate, float scale );
-		vec3_t Transformed( const vec3_t& translate, const mat3_t& rotate ) const;
+		vec3_t GetTransformed( const vec3_t& translate, const mat3_t& rotate ) const;
 		void   Transform( const vec3_t& translate, const mat3_t& rotate );
-		vec3_t Transformed( const vec3_t& translate, const quat_t& rotate, float scale ) const;
+		vec3_t GetTransformed( const vec3_t& translate, const quat_t& rotate, float scale ) const;
 		void   Transform( const vec3_t& translate, const quat_t& rotate, float scale );
-		vec3_t Transformed( const vec3_t& translate, const quat_t& rotate ) const;
+		vec3_t GetTransformed( const vec3_t& translate, const quat_t& rotate ) const;
 		void   Transform( const vec3_t& translate, const quat_t& rotate );
-		vec3_t Transformed( const mat4_t& transform ) const;  // 9 muls, 9 adds
+		vec3_t GetTransformed( const mat4_t& transform ) const;  // 9 muls, 9 adds
 		void   Transform( const mat4_t& transform );
 };
 

+ 17 - 17
src/math/vec3.inl.h

@@ -244,7 +244,7 @@ M_INLINE void vec3_t::Normalize()
 }
 
 // Normalized (return the normalized)
-M_INLINE vec3_t vec3_t::Normalized() const
+M_INLINE vec3_t vec3_t::GetNormalized() const
 {
 	return ME * InvSqrt( x*x + y*y + z*z );
 }
@@ -256,7 +256,7 @@ M_INLINE vec3_t vec3_t::Project( const vec3_t& to_this ) const
 }
 
 // Rotated
-M_INLINE vec3_t vec3_t::Rotated( const quat_t& q ) const
+M_INLINE vec3_t vec3_t::GetRotated( const quat_t& q ) const
 {
 	DEBUG_ERR( !IsZero(1.0f-q.Length()) ); // Not normalized quat
 
@@ -274,7 +274,7 @@ M_INLINE vec3_t vec3_t::Rotated( const quat_t& q ) const
 // Rotate
 M_INLINE void vec3_t::Rotate( const quat_t& q )
 {
-	ME = Rotated(q);
+	ME = GetRotated(q);
 }
 
 // Print
@@ -291,8 +291,8 @@ M_INLINE vec3_t vec3_t::Lerp( const vec3_t& v1, float t ) const
 	return (ME*(1.0f-t))+(v1*t);
 }
 
-// Transformed [mat3]
-M_INLINE vec3_t vec3_t::Transformed( const vec3_t& translate, const mat3_t& rotate, float scale ) const
+// GetTransformed [mat3]
+M_INLINE vec3_t vec3_t::GetTransformed( const vec3_t& translate, const mat3_t& rotate, float scale ) const
 {
 	return (rotate * (ME * scale)) + translate;
 }
@@ -300,11 +300,11 @@ M_INLINE vec3_t vec3_t::Transformed( const vec3_t& translate, const mat3_t& rota
 // Transform [mat3]
 M_INLINE void vec3_t::Transform( const vec3_t& translate, const mat3_t& rotate, float scale )
 {
-	ME = Transformed( translate, rotate, scale );
+	ME = GetTransformed( translate, rotate, scale );
 }
 
-// Transformed [mat3] no scale
-M_INLINE vec3_t vec3_t::Transformed( const vec3_t& translate, const mat3_t& rotate ) const
+// GetTransformed [mat3] no scale
+M_INLINE vec3_t vec3_t::GetTransformed( const vec3_t& translate, const mat3_t& rotate ) const
 {
 	return (rotate * ME) + translate;
 }
@@ -312,23 +312,23 @@ M_INLINE vec3_t vec3_t::Transformed( const vec3_t& translate, const mat3_t& rota
 // Transform [mat3] no scale
 M_INLINE void vec3_t::Transform( const vec3_t& translate, const mat3_t& rotate )
 {
-	ME = Transformed( translate, rotate );
+	ME = GetTransformed( translate, rotate );
 }
 
-// Transformed [quat]
-M_INLINE vec3_t vec3_t::Transformed( const vec3_t& translate, const quat_t& rotate, float scale ) const
+// GetTransformed [quat]
+M_INLINE vec3_t vec3_t::GetTransformed( const vec3_t& translate, const quat_t& rotate, float scale ) const
 {
-	return (ME * scale).Rotated(rotate) + translate;
+	return (ME * scale).GetRotated(rotate) + translate;
 }
 
 // Transform [quat3] no scale
 M_INLINE void vec3_t::Transform( const vec3_t& translate, const quat_t& rotate, float scale )
 {
-	ME = Transformed( translate, rotate, scale );
+	ME = GetTransformed( translate, rotate, scale );
 }
 
-// Transformed [mat4]
-M_INLINE vec3_t vec3_t::Transformed( const mat4_t& transform ) const
+// GetTransformed [mat4]
+M_INLINE vec3_t vec3_t::GetTransformed( const mat4_t& transform ) const
 {
 	return vec3_t(
 		transform(0,0)*x + transform(0,1)*y + transform(0,2)*z + transform(0,3),
@@ -337,10 +337,10 @@ M_INLINE vec3_t vec3_t::Transformed( const mat4_t& transform ) const
 	);
 }
 
-// Transformed [mat4]
+// GetTransformed [mat4]
 M_INLINE void vec3_t::Transform( const mat4_t& transform )
 {
-	ME = Transformed( transform );
+	ME = GetTransformed( transform );
 }
 
 

+ 1 - 1
src/math/vec4.h

@@ -50,7 +50,7 @@ class vec4_t
 		bool operator !=( const vec4_t& b ) const;
 		// other
 		float  Length() const;
-		vec4_t Normalized() const;
+		vec4_t GetNormalized() const;
 		void   Normalize();
 		void   Print() const;
 		float  Dot( const vec4_t& b ) const;

+ 2 - 2
src/math/vec4.inl.h

@@ -211,7 +211,7 @@ M_INLINE float vec4_t::Length() const
 }
 
 // Normalized
-M_INLINE vec4_t vec4_t::Normalized() const
+M_INLINE vec4_t vec4_t::GetNormalized() const
 {
 	return ME * InvSqrt( x*x +y*y + z*z + w*w );
 }
@@ -219,7 +219,7 @@ M_INLINE vec4_t vec4_t::Normalized() const
 // Normalize
 M_INLINE void vec4_t::Normalize()
 {
-	ME = Normalized();
+	ME *= InvSqrt( x*x +y*y + z*z + w*w );
 }
 
 // Print

+ 48 - 53
src/renderer/r_is.cpp

@@ -101,7 +101,7 @@ static void CalcViewVector( const camera_t& cam )
 		vec.y = (2.0*(pixels[i][1]-viewport[1]))/viewport[3] - 1.0;
 		vec.z = 1.0;
 
-		view_vectors[i] = vec.Transformed( cam.GetInvProjectionMatrix() );
+		view_vectors[i] = vec.GetTransformed( cam.GetInvProjectionMatrix() );
 		// end of optimized code
 	}
 }
@@ -194,14 +194,7 @@ static void AmbientPass( const camera_t& /*cam*/, const vec3_t& color )
 	shdr_is_ambient->LocTexUnit( shdr_is_ambient->GetUniformLocation(1), r::ms::diffuse_fai, 0 );
 
 	// Draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-
-	glDrawArrays( GL_QUADS, 0, 4 );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( shdr_is_ambient->GetAttributeLocation(0) );
 }
 
 
@@ -466,26 +459,23 @@ static void PointLightPass( const camera_t& cam, const point_light_t& light )
 	shader.LocTexUnit( shader.GetUniformLocation(3), r::ms::depth_fai, 3 );
 	glUniform2fv( shader.GetUniformLocation(4), 1, &planes[0] );
 
-
-	vec3_t light_pos_eye_space = light.translation_wspace.Transformed( cam.GetViewMatrix() );
-
-	glLightfv( GL_LIGHT0, GL_POSITION, &vec4_t(light_pos_eye_space, 1/light.radius)[0] );
-	glLightfv( GL_LIGHT0, GL_DIFFUSE,  &(vec4_t( light.GetDiffuseColor(), 1.0 ))[0] );
-	glLightfv( GL_LIGHT0, GL_SPECULAR,  &(vec4_t( light.GetSpecularColor(), 1.0 ))[0] );
+	vec3_t light_pos_eye_space = light.translation_wspace.GetTransformed( cam.GetViewMatrix() );
+	glUniform3fv( shader.GetUniformLocation(5), 1, &light_pos_eye_space[0] );
+	glUniform1f( shader.GetUniformLocation(6), 1.0/light.radius );
+	glUniform3fv( shader.GetUniformLocation(7), 1, &vec3_t(light.GetDiffuseColor())[0] );
+	glUniform3fv( shader.GetUniformLocation(8), 1, &vec3_t(light.GetSpecularColor())[0] );
 
 	//** render quad **
-	int loc = shader.GetAttributeLocation(0); // view_vector
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	glEnableVertexAttribArray( loc );
+	glEnableVertexAttribArray( shader.GetAttributeLocation(0) );
+	glEnableVertexAttribArray( shader.GetAttributeLocation(1) );
 
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glVertexAttribPointer( loc, 3, GL_FLOAT, 0, 0, &view_vectors[0] );
+	glVertexAttribPointer( shader.GetAttributeLocation(0), 3, GL_FLOAT, false, 0, &view_vectors[0] );
+	glVertexAttribPointer( shader.GetAttributeLocation(1), 2, GL_FLOAT, false, 0, &quad_vert_cords[0] );
 
 	glDrawArrays( GL_QUADS, 0, 4 );
 
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableVertexAttribArray( loc );
+	glDisableVertexAttribArray( shader.GetAttributeLocation(0) );
+	glDisableVertexAttribArray( shader.GetAttributeLocation(1) );
 
 	//glDisable( GL_SCISSOR_TEST );
 	glDisable( GL_STENCIL_TEST );
@@ -519,17 +509,6 @@ static void SpotLightPass( const camera_t& cam, const spot_light_t& light )
 		glDisable( GL_DEPTH_TEST );
 	}
 
-	//** set texture matrix for shadowmap projection **
-	// Bias * P_light * V_light * inv( V_cam )
-	const float mBias[] = {0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0};
-	glActiveTexture( GL_TEXTURE0 );
-	glMatrixMode( GL_TEXTURE );
-	glLoadMatrixf( mBias );
-	r::MultMatrix( light.camera.GetProjectionMatrix() );
-	r::MultMatrix( light.camera.GetViewMatrix() );
-	r::MultMatrix( cam.transformation_wspace );
-	glMatrixMode(GL_MODELVIEW);
-
 	//** set the shader and uniforms **
 	const shader_prog_t* shdr; // because of the huge name
 
@@ -546,44 +525,60 @@ static void SpotLightPass( const camera_t& cam, const spot_light_t& light )
 
 	DEBUG_ERR( light.texture == NULL ); // No texture attached to the light
 
+	// the planes
+	//glUniform2fv( shdr->GetUniformLocation("planes"), 1, &planes[0] );
+	glUniform2fv( shdr->GetUniformLocation(4), 1, &planes[0] );
+
+	// the light params
+	vec3_t light_pos_eye_space = light.translation_wspace.GetTransformed( cam.GetViewMatrix() );
+	glUniform3fv( shdr->GetUniformLocation(5), 1, &light_pos_eye_space[0] );
+	glUniform1f( shdr->GetUniformLocation(6), 1.0/light.GetDistance() );
+	glUniform3fv( shdr->GetUniformLocation(7), 1, &vec3_t(light.GetDiffuseColor())[0] );
+	glUniform3fv( shdr->GetUniformLocation(8), 1, &vec3_t(light.GetSpecularColor())[0] );
+
 	// set the light texture
-	shdr->LocTexUnit( shdr->GetUniformLocation(5), *light.texture, 4 );
+	shdr->LocTexUnit( shdr->GetUniformLocation(9), *light.texture, 4 );
 	// before we render disable anisotropic in the light.texture because it produces artefacts. ToDo: see if this is unececeary in future drivers
 	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
-	// the planes
-	//glUniform2fv( shdr->GetUniformLocation("planes"), 1, &planes[0] );
-	glUniform2fv( shdr->GetUniformLocation(4), 1, &planes[0] );
 
-	// the pos and max influence distance
-	vec3_t light_pos_eye_space = light.translation_wspace.Transformed( cam.GetViewMatrix() );
-	glLightfv( GL_LIGHT0, GL_POSITION, &vec4_t(light_pos_eye_space, 1.0/light.GetDistance())[0] );
+	//** set texture matrix for shadowmap projection **
+	// Bias * P_light * V_light * inv( V_cam )
+	//const float mBias[] = {0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0};
+	static mat4_t bias_m4( 0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0 );
+	mat4_t tex_projection_mat;
+	tex_projection_mat = bias_m4 * light.camera.GetProjectionMatrix() * light.camera.GetViewMatrix() * cam.transformation_wspace;
+	glUniformMatrix4fv( shdr->GetUniformLocation(10), 1, true, &tex_projection_mat[0] );
 
-	// the colors
-	glLightfv( GL_LIGHT0, GL_DIFFUSE,  &(vec4_t( light.GetDiffuseColor(), 1.0 ))[0] );
-	glLightfv( GL_LIGHT0, GL_SPECULAR,  &(vec4_t( light.GetSpecularColor(), 1.0 ))[0] );
+	/*
+	const float mBias[] = {0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0};
+	glActiveTexture( GL_TEXTURE0 );
+	glMatrixMode( GL_TEXTURE );
+	glLoadMatrixf( mBias );
+	r::MultMatrix( light.camera.GetProjectionMatrix() );
+	r::MultMatrix( light.camera.GetViewMatrix() );
+	r::MultMatrix( cam.transformation_wspace );
+	glMatrixMode(GL_MODELVIEW);*/
 
 	// the shadow stuff
 	// render depth to texture and then bind it
 	if( light.casts_shadow )
 	{
-		shdr->LocTexUnit( shdr->GetUniformLocation(6), r::is::shadows::shadow_map, 5 );
+		shdr->LocTexUnit( shdr->GetUniformLocation(11), r::is::shadows::shadow_map, 5 );
 	}
 
 	//** render quad **
-	int loc = shdr_is_lp_spot_light_nos->GetAttributeLocation(0); // view_vector
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	glEnableVertexAttribArray( loc );
+	glEnableVertexAttribArray( shdr->GetAttributeLocation(0) );
+	glEnableVertexAttribArray( shdr->GetAttributeLocation(1) );
 
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glVertexAttribPointer( loc, 3, GL_FLOAT, 0, 0, &view_vectors[0] );
+	glVertexAttribPointer( shdr->GetAttributeLocation(0), 3, GL_FLOAT, false, 0, &view_vectors[0] );
+	glVertexAttribPointer( shdr->GetAttributeLocation(1), 2, GL_FLOAT, false, 0, &quad_vert_cords[0] );
 
 	glDrawArrays( GL_QUADS, 0, 4 );
 
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableVertexAttribArray( loc );
+	glDisableVertexAttribArray( shdr->GetAttributeLocation(0) );
+	glDisableVertexAttribArray( shdr->GetAttributeLocation(1) );
 
 	// restore texture matrix
 	glMatrixMode( GL_TEXTURE );

+ 2 - 2
src/renderer/r_is_shadows.cpp

@@ -95,8 +95,8 @@ void RunPass( const camera_t& cam )
 	glEnable( GL_DEPTH_TEST );
 	glDisable( GL_BLEND );
 
-	// for artefacts
-	glPolygonOffset( 2.0f, 2.0f ); // keep the values as low as possible!!!!
+	// for artifacts
+	glPolygonOffset( 2.0, 2.0 ); // keep the values as low as possible!!!!
 	glEnable( GL_POLYGON_OFFSET_FILL );
 
 	// render all meshes

+ 2 - 2
src/renderer/r_ms.cpp

@@ -1,6 +1,6 @@
 /**
-The file contains functions and vars used for the deferred shading material stage.
-*/
+ * The file contains functions and vars used for the deferred shading material stage.
+ */
 
 #include "renderer.h"
 #include "camera.h"

+ 1 - 8
src/renderer/r_pps.cpp

@@ -148,14 +148,7 @@ void RunStage( const camera_t& cam )
 
 
 	// draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-
-	glDrawArrays( GL_QUADS, 0, 4 );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( shdr_post_proc_stage->GetAttributeLocation(0) );
 
 	// unbind FBO
 	fbo.Unbind();

+ 3 - 13
src/renderer/r_pps_hdr.cpp

@@ -107,10 +107,7 @@ void RunPass( const camera_t& /*cam*/ )
 	pass0_shdr->LocTexUnit( pass0_shdr->GetUniformLocation(0), r::is::fai, 0 );
 
 	// Draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( pass0_shdr->GetAttributeLocation(0) );
 
 
 	// pass 1
@@ -121,10 +118,7 @@ void RunPass( const camera_t& /*cam*/ )
 	pass1_shdr->LocTexUnit( pass1_shdr->GetUniformLocation(0), pass0_fai, 0 );
 
 	// Draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( pass1_shdr->GetAttributeLocation(0) );
 
 
 	// pass 2
@@ -135,11 +129,7 @@ void RunPass( const camera_t& /*cam*/ )
 	pass2_shdr->LocTexUnit( pass2_shdr->GetUniformLocation(0), pass1_fai, 0 );
 
 	// Draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );
-
+	r::DrawQuad( pass2_shdr->GetAttributeLocation(0) );
 
 	// end
 	fbo_t::Unbind();

+ 1 - 4
src/renderer/r_pps_lscatt.cpp

@@ -89,10 +89,7 @@ void RunPass( const camera_t& /*cam*/ )
 	shdr->LocTexUnit( is_fai_uni_loc, r::is::fai, 1 );
 
 	// Draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( shdr->GetAttributeLocation(0) );
 
 	// end
 	fbo.Unbind();

+ 5 - 14
src/renderer/r_pps_ssao.cpp

@@ -82,8 +82,8 @@ void Init()
 
 	// create the texes
 	fai.CreateEmpty( wwidth, wheight, GL_ALPHA8, GL_ALPHA );
-	fai.TexParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-	fai.TexParameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+	fai.TexParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+	fai.TexParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
 
 	// attach
 	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.GetGLID(), 0 );
@@ -132,29 +132,20 @@ void RunPass( const camera_t& cam )
 	glDisable( GL_BLEND );
 	glDisable( GL_DEPTH_TEST );
 
-	// set the shader
+	// fill SSAO FAI
 	shdr_ppp_ssao->Bind();
-
 	glUniform2fv( shdr_ppp_ssao->GetUniformLocation(0), 1, &(vec2_t(cam.GetZNear(), cam.GetZFar()))[0] );
 	shdr_ppp_ssao->LocTexUnit( shdr_ppp_ssao->GetUniformLocation(1), ms::depth_fai, 0 );
 	shdr_ppp_ssao->LocTexUnit( shdr_ppp_ssao->GetUniformLocation(2), *noise_map, 1 );
 	shdr_ppp_ssao->LocTexUnit( shdr_ppp_ssao->GetUniformLocation(3), ms::normal_fai, 2 );
-
-	// Draw quad
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( shdr_ppp_ssao->GetAttributeLocation(0) ); // Draw quad
 
 
 	// second pass. blur
 	blur_fbo.Bind();
 	blur_shdr->Bind();
 	blur_shdr->LocTexUnit( blur_shdr->GetUniformLocation(0), fai, 0 );
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( blur_shdr->GetAttributeLocation(0) ); // Draw quad
 
 	// end
 	fbo_t::Unbind();

+ 3 - 6
src/renderer/r_private.h

@@ -10,17 +10,14 @@ class camera_t;
 namespace r {
 
 
-extern float quad_vert_cords [4][2]; ///< The vertex coordinates for tha quad used in PPS ans IS
-
-
 /*
 =======================================================================================================================================
 externs                                                                                                                               =
 =======================================================================================================================================
 */
 
-extern void SetMat( const material_t& mat );
-
+extern void DrawQuad( int vert_coords_uni_loc );
+extern float quad_vert_cords [][2];
 
 namespace ms
 {
@@ -135,7 +132,7 @@ void RenderDepth( type_t& t )
 		r::is::shadows::shdr_depth_grass->Bind();
 		r::is::shadows::shdr_depth_grass->LocTexUnit( r::is::shadows::shdr_depth_grass->GetUniformLocation(0), *t.material->grass_map, 0 );
 	}
-	else if( t.material->needs_vert_weights )
+	else if( t.material->attribute_locs.vert_weight_bones_num != -1 )
 	{
 		r::is::shadows::shdr_depth_hw_skinning->Bind();
 	}

+ 22 - 12
src/renderer/renderer.cpp

@@ -44,6 +44,22 @@ int max_texture_units = -1;
 bool texture_compression = false;
 
 
+//=====================================================================================================================================
+// DrawQuad                                                                                                                           =
+//=====================================================================================================================================
+void DrawQuad( int vert_coords_uni_loc )
+{
+	/*glEnableClientState( GL_VERTEX_ARRAY );
+	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
+	glDrawArrays( GL_QUADS, 0, 4 );
+	glDisableClientState( GL_VERTEX_ARRAY );*/
+	glVertexAttribPointer( vert_coords_uni_loc, 2, GL_FLOAT, false, 0, quad_vert_cords );
+	glEnableVertexAttribArray( vert_coords_uni_loc );
+	glDrawArrays( GL_QUADS, 0, 4 );
+	glDisableVertexAttribArray( vert_coords_uni_loc );
+}
+
+
 /*
 =======================================================================================================================================
 BuildStdShaderPreProcStr                                                                                                              =
@@ -54,7 +70,8 @@ static void BuildStdShaderPreProcStr()
 {
 	string& tmp = std_shader_preproc_defines;
 
-	tmp  = "#version 120\n";
+	tmp  = "#version 150 compatibility\n";
+	tmp += "precision lowp float;\n";
 	tmp += "#pragma optimize(on)\n";
 	tmp += "#pragma debug(off)\n";
 	tmp += "#define R_W " + FloatToStr(r::w) + "\n";
@@ -107,8 +124,8 @@ void Init()
 	if( !glewIsSupported("GL_ARB_vertex_buffer_object") )
 		WARNING( "Vertex Buffer Objects not supported. The application may crash (and burn)" );
 
-	glClearColor( 0.1f, 0.1f, 0.1f, 0.0f );
-	glClearDepth( 1.0f );
+	glClearColor( 0.1, 0.1, 0.1, 0.0 );
+	glClearDepth( 1.0 );
 	glClearStencil( 0 );
 	glDepthFunc( GL_LEQUAL );
 
@@ -175,14 +192,7 @@ void Render( const camera_t& cam )
 	shdr_final->Bind();
 	shdr_final->LocTexUnit( shdr_final->GetUniformLocation(0), r::pps::fai, 0 );
 
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-
-	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
-
-	glDrawArrays( GL_QUADS, 0, 4 );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
+	r::DrawQuad( shdr_final->GetAttributeLocation(0) );
 }
 
 
@@ -402,7 +412,7 @@ TakeScreenshot
 */
 void TakeScreenshot( const char* filename )
 {
-	char* ext = GetFileExtension( filename );
+	char* ext = util::GetFileExtension( filename );
 	bool ret;
 
 	// exec from this extension

+ 8 - 5
src/renderer/renderer.h

@@ -37,18 +37,21 @@ extern void Init(); ///< Inits the renderer subsystem. Setting OpenGL and execut
 extern void PrepareNextFrame(); ///< Runs before rendering
 extern void PrintLastError(); ///< Prints last OpenGL error
 inline const string& GetStdShaderPreprocDefines() { extern string std_shader_preproc_defines; return std_shader_preproc_defines; }
-extern void Render( const camera_t& cam ); ///< The spine funciton of the renderer
+extern void Render( const camera_t& cam ); ///< The spine function of the renderer
 
 extern void SetGLState_Wireframe();
 extern void SetGLState_WireframeDotted();
 extern void SetGLState_Solid();
 extern void SetGLState_AlphaSolid();
 
+// matrices
+//extern
+
 // ogl and glu wrappers
-inline void   MultMatrix( const mat4_t& m4 ) { glMultMatrixf( &(m4.Transposed())(0,0) ); } ///< OpenGL wrapper
-inline void   LoadMatrix( const mat4_t& m4 ) { glLoadMatrixf( &(m4.Transposed())(0,0) ); } ///< OpenGL wrapper
-inline void   Color3( const vec3_t& v ) { glColor3fv( &((vec3_t&)v)[0] ); } ///< OpenGL wrapper
+inline void   MultMatrix( const mat4_t& m4 ) { glMultMatrixf( &(m4.GetTransposed())(0,0) ); } ///< OpenGL wrapper
+inline void   LoadMatrix( const mat4_t& m4 ) { glLoadMatrixf( &(m4.GetTransposed())(0,0) ); } ///< OpenGL wrapper
 
+inline void   Color3( const vec3_t& v ) { glColor3fv( &((vec3_t&)v)[0] ); } ///< OpenGL wrapper
 inline void   Color4( const vec4_t& v ) { glColor4fv( &((vec4_t&)v)[0] ); } ///< OpenGL wrapper
 inline void   NoShaders() { shader_prog_t::Unbind(); } ///< Unbind shaders
 extern bool   Unproject( float winX, float winY, float winZ, const mat4_t& modelview_mat, const mat4_t& projection_mat, const int* view, float& objX, float& objY, float& objZ ); ///< My version of gluUnproject
@@ -62,7 +65,7 @@ inline void SetViewport( uint x, uint y, uint w, uint h ) { glViewport(x,y,w,h);
 
 // externals that have global scope in other namespaces
 
-/// material stage namesapce
+/// material stage namespace
 namespace ms
 {
 	extern texture_t normal_fai;

Fișier diff suprimat deoarece este prea mare
+ 4 - 0
src/renderer2/r_is.cpp


+ 73 - 0
src/renderer2/r_ms.cpp

@@ -0,0 +1,73 @@
+#include "renderer.hpp"
+#include "scene.h"
+
+
+//=====================================================================================================================================
+// Init                                                                                                                               =
+//=====================================================================================================================================
+void renderer_t::material_stage_t::Init()
+{
+	// create FBO
+	fbo.Create();
+	fbo.Bind();
+
+	// inform in what buffers we draw
+	fbo.SetNumOfColorAttachements(3);
+
+	// create buffers
+	const int internal_format = GL_RGBA16F_ARB;
+	fais.normal.CreateEmpty( renderer.width, renderer.height, internal_format, GL_RGBA );
+	fais.diffuse.CreateEmpty( renderer.width, renderer.height, internal_format, GL_RGBA );
+	fais.specular.CreateEmpty( renderer.width, renderer.height, internal_format, GL_RGBA );
+
+	fais.depth.CreateEmpty( renderer.width, renderer.height, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT );
+	// you could use the above for SSAO but the difference is minimal.
+	//depth_fai.TexParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+	//depth_fai.TexParameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+
+	// attach the buffers to the FBO
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fais.normal.GetGLID(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, fais.diffuse.GetGLID(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, fais.specular.GetGLID(), 0 );
+
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, fais.depth.GetGLID(), 0 );
+
+	// test if success
+	if( !fbo.CheckStatus() )
+		FATAL( "Cannot create deferred shading material pass FBO" );
+
+	// unbind
+	fbo.Unbind();
+}
+
+
+//=====================================================================================================================================
+// Run                                                                                                                                =
+//=====================================================================================================================================
+void renderer_t::material_stage_t::Run() const
+{
+	fbo.Bind();
+
+	glClear( GL_DEPTH_BUFFER_BIT );
+	renderer.matrices.view = renderer.camera->GetViewMatrix();
+	renderer.matrices.projection = renderer.camera->GetProjectionMatrix();
+	renderer.SetViewport( 0, 0, renderer.width, renderer.height );
+
+	//glEnable( GL_DEPTH_TEST );
+	scene::skybox.Render( renderer.camera->GetViewMatrix().GetRotationPart() );
+	//glDepthFunc( GL_LEQUAL );
+
+
+	// render the meshes
+	/*for( uint i=0; i<scene::meshes.size(); i++ )
+		Render<mesh_t, false>( scene::meshes[i] );
+
+	// render the smodels
+	for( uint i=0; i<scene::smodels.size(); i++ )
+		Render<smodel_t, false>( scene::smodels[i] );*/
+
+	glPolygonMode( GL_FRONT, GL_FILL ); // the rendering above fucks the polygon mode
+
+
+	fbo.Unbind();
+}

+ 50 - 0
src/renderer2/renderer.cpp

@@ -0,0 +1,50 @@
+#include "renderer.hpp"
+
+
+float renderer_t::quad_vert_cords [][2] = { {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0} };
+
+
+//=====================================================================================================================================
+// UpdateMatrices                                                                                                                     =
+//=====================================================================================================================================
+void renderer_t::UpdateMatrices()
+{
+	const mat4_t& M = matrices.model;
+	const mat4_t& V = matrices.view;
+	const mat4_t& P = matrices.projection;
+	mat4_t& MV = matrices.model_view;
+	mat4_t& MVP = matrices.model_view_projection;
+	mat3_t& N = matrices.normal;
+
+	mat4_t& Mi = matrices.model_inv;
+	mat4_t& Vi = matrices.view_inv;
+	mat4_t& Pi = matrices.projection_inv;
+	mat4_t& MVi = matrices.model_view_inv;
+	mat4_t& MVPi = matrices.model_view_projection_inv;
+	mat3_t& Ni = matrices.normal_inv;
+
+	// matrices
+	MV = V * M;
+	MVP = P * MV;
+	N = MV.GetRotationPart();
+
+	// inv matrices
+	Mi = M.GetInverseTransformation();
+	Vi = V.GetInverseTransformation();
+	Pi = P.GetInverse();
+	MV = Mi * Vi;
+	MVPi = MVi * Pi;
+	Ni = MVi.GetRotationPart();
+}
+
+
+//=====================================================================================================================================
+// DrawQuad                                                                                                                           =
+//=====================================================================================================================================
+void renderer_t::DrawQuad()
+{
+	glEnableClientState( GL_VERTEX_ARRAY );
+	glVertexPointer( 2, GL_FLOAT, 0, quad_vert_cords );
+	glDrawArrays( GL_QUADS, 0, 4 );
+	glDisableClientState( GL_VERTEX_ARRAY );
+}

+ 257 - 0
src/renderer2/renderer.hpp

@@ -0,0 +1,257 @@
+#ifndef _RENDERER_HPP_
+#define _RENDERER_HPP_
+
+#include "common.h"
+#include "fbo.h"
+#include "texture.h"
+
+class point_light_t;
+class spot_light_t;
+
+
+struct renderer_t
+{
+	//===================================================================================================================================
+	// NESTED CLASSES FOR STAGES                                                                                                        =
+	//===================================================================================================================================
+	/// knowyourfather_t (A)
+	struct knowyourfather_t
+	{
+		renderer_t& renderer;
+		knowyourfather_t( renderer_t& r ): renderer(r) {}
+	}; // end knowyourfather_t
+
+
+	/// material stage
+	struct material_stage_t: knowyourfather_t
+	{
+		fbo_t fbo;
+
+		struct
+		{
+			texture_t normal, diffuse, specular, depth;
+		} fais;
+
+		material_stage_t( renderer_t& r ): knowyourfather_t(r) {}
+		void Init();
+		void Run() const;
+	}; // end MS
+
+
+	/// illumination stage
+	struct illumination_stage_t: knowyourfather_t
+	{
+		/// ambient pass
+		struct ambient_pass_t: knowyourfather_t
+		{
+			shader_prog_t shader_prog;
+
+			ambient_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+			void Init();
+			void Run() const;
+		}; // end AP
+
+		/// point light pass
+		struct point_light_pass_t: knowyourfather_t
+		{
+			// for stencil masking optimizations
+			static float smo_uvs_coords [];
+			static uint smo_uvs_vbo_id;
+			static void InitSMOUVS();
+			void DrawSMOUVS( const point_light_t& light );
+			void SetStencilMask( const point_light_t& light ) const;
+
+			struct
+			{
+				shader_prog_t main, smouvs;
+			} shader_progs;
+
+			point_light_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+			void Init();
+			void Run( const point_light_t& light );
+		}; // end point light pass
+
+		/// spot light pass
+		struct spot_light_pass_t: knowyourfather_t
+		{
+			void SetStencilMask( const spot_light_t& light ) const;
+
+			struct
+			{
+				shader_prog_t shadow, no_shadow, smouvs;
+			} shader_progs;
+
+			spot_light_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+			void Init() {}
+			void Run( const spot_light_t& light );
+
+		}; // end spot light pass
+
+		// data
+		fbo_t fbo;
+		texture_t fai;
+		vec3_t view_vectors[4];
+		vec2_t planes;
+
+		ambient_pass_t ap;
+		point_light_pass_t plp;
+		spot_light_pass_t slp;
+
+		illumination_stage_t( renderer_t& r ): knowyourfather_t(r), ap(r), plp(r), slp(r) {}
+		void CalcViewVector();
+		void CalcPlanes();
+		void Init();
+		void Run() const;
+	}; // end IS
+
+
+	/// blending stage
+	struct blending_stage_t: knowyourfather_t
+	{
+		/// objects that just blend
+		struct blend_pass_t: knowyourfather_t
+		{
+			struct
+			{
+				fbo_t main;
+			} fbos;
+
+			blend_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+		}; // end blend
+
+		/// objects that refract
+		struct refract_pass_t: knowyourfather_t
+		{
+			refract_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+		}; // end refract
+
+		blend_pass_t bp;
+
+		blending_stage_t( renderer_t& r ): knowyourfather_t(r), bp(r) {}
+	};
+
+
+	/// post processing stage
+	struct postprocessing_stage_t: knowyourfather_t
+	{
+			/// HDR pass
+			struct hdr_pass_t: knowyourfather_t
+			{
+				struct
+				{
+					fbo_t pass0, pass1, pass2;
+				} fbos;
+
+				struct
+				{
+					shader_prog_t pass0, pass1, pass2;
+				} shader_progs;
+
+				struct
+				{
+					texture_t pass0, pass1, pass2;
+				} fais;
+
+				hdr_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+				void Init() {};
+				void Run() const {};
+			}; // end HDR
+
+			/// SSAO pass
+			struct ssao_pass_t: knowyourfather_t
+			{
+				struct
+				{
+					fbo_t main, blured;
+				} fbos;
+
+				struct
+				{
+					shader_prog_t main, blured;
+				} shader_progs;
+
+				struct
+				{
+					texture_t main, blured;
+				} fais;
+
+				ssao_pass_t( renderer_t& r ): knowyourfather_t(r) {}
+				void Init() {};
+				void Run() const {};
+			}; // end SSAO
+
+			/// edgeaa
+			struct edgeaa_t: knowyourfather_t
+			{
+				edgeaa_t( renderer_t& r ): knowyourfather_t(r) {}
+			};
+
+			struct
+			{
+				fbo_t main;
+			} fbos;
+
+			struct
+			{
+				shader_prog_t main;
+			} shader_progs;
+
+			struct
+			{
+				texture_t main;
+			} fais;
+
+			hdr_pass_t hdr;
+			ssao_pass_t ssao;
+			edgeaa_t eaa;
+
+			postprocessing_stage_t( renderer_t& r ): knowyourfather_t(r), hdr(r), ssao(r), eaa(r) {}
+			void Init() {};
+			void Run() const {};
+	}; // end pps
+
+
+	//===================================================================================================================================
+	// DATA                                                                                                                             =
+	//===================================================================================================================================
+	material_stage_t ms;
+	illumination_stage_t is;
+	blending_stage_t bs;
+	postprocessing_stage_t pps;
+
+	camera_t* camera;
+	int width, height;
+
+	static float quad_vert_cords [][2];
+
+	struct
+	{
+		mat4_t model;
+		mat4_t view;
+		mat4_t projection;
+		mat4_t model_view;
+		mat4_t model_view_projection;
+		mat3_t normal; ///< The rotation part of model_view matrix
+
+		mat4_t model_inv;
+		mat4_t view_inv;
+		mat4_t projection_inv;
+		mat4_t model_view_inv;
+		mat4_t model_view_projection_inv;
+		mat3_t normal_inv; ///< Its also equal to the transpose of normal
+	} matrices;
+
+	//===================================================================================================================================
+	// FUNCS                                                                                                                            =
+	//===================================================================================================================================
+	renderer_t(): ms(*this), is(*this), bs(*this), pps(*this) {}
+
+	void UpdateMatrices();
+	static void SetViewport( uint x, uint y, uint w, uint h ) { glViewport(x,y,w,h); };
+	static void NoShaders() { shader_prog_t::Unbind(); }
+	static void DrawQuad();
+	void Init();
+	void Run( camera_t* cam );
+};
+
+#endif

+ 3 - 3
src/uncategorized/camera.cpp

@@ -78,7 +78,7 @@ LookAtPoint
 void camera_t::LookAtPoint( const vec3_t& point )
 {
 	const vec3_t& j = vec3_t( 0.0, 1.0, 0.0 );
-	vec3_t vdir = (point - translation_lspace).Normalized();
+	vec3_t vdir = (point - translation_lspace).GetNormalized();
 	vec3_t vup = j - vdir * j.Dot(vdir);
 	vec3_t vside = vdir.Cross( vup );
 	rotation_lspace.SetColumns( vside, vup, -vdir );
@@ -212,7 +212,7 @@ void camera_t::CalcProjectionMatrix()
 	projection_mat(3,2) = -1.0f;
 	projection_mat(3,3) = 0.0;
 
-	inv_projection_mat = projection_mat.Inverted();
+	inv_projection_mat = projection_mat.GetInverse();
 }
 
 
@@ -231,7 +231,7 @@ void camera_t::UpdateViewMatrix()
 
 
 	// The view matrix is: Mview = camera.world_transform.Inverted(). Bus instead of inverting we do the following:
-	mat3_t cam_inverted_rot = rotation_wspace.Transposed();
+	mat3_t cam_inverted_rot = rotation_wspace.GetTransposed();
 	vec3_t cam_inverted_tsl = -( cam_inverted_rot * translation_wspace );
 	view_mat = mat4_t( cam_inverted_tsl, cam_inverted_rot );
 }

+ 11 - 11
src/uncategorized/collision.cpp

@@ -505,7 +505,7 @@ lineseg_t lineseg_t::Transformed( const vec3_t& translate, const mat3_t& rotate,
 {
 	lineseg_t seg;
 
-	seg.origin = origin.Transformed( translate, rotate, scale );
+	seg.origin = origin.GetTransformed( translate, rotate, scale );
 	seg.dir = rotate * (dir * scale);
 
 	return seg;
@@ -631,7 +631,7 @@ ray_t ray_t::Transformed( const vec3_t& translate, const mat3_t& rotate, float s
 	return ray;*/
 	ray_t new_ray;
 
-	new_ray.origin = origin.Transformed( translate, rotate, scale );
+	new_ray.origin = origin.GetTransformed( translate, rotate, scale );
 	new_ray.dir = rotate * dir;
 
 	return new_ray;
@@ -798,7 +798,7 @@ plane_t plane_t::Transformed( const vec3_t& translate, const mat3_t& rotate, flo
 	plane.normal = rotate*normal;
 
 	// the offset
-	vec3_t new_trans = rotate.Transposed() * translate;
+	vec3_t new_trans = rotate.GetTransposed() * translate;
 	plane.offset = offset*scale + new_trans.Dot( normal );
 
 	return plane;
@@ -926,7 +926,7 @@ bsphere_t bsphere_t::Transformed( const vec3_t& translate, const mat3_t& rotate,
 {
 	bsphere_t new_sphere;
 
-	new_sphere.center = center.Transformed( translate, rotate, scale );
+	new_sphere.center = center.GetTransformed( translate, rotate, scale );
 	new_sphere.radius = radius * scale;
 	return new_sphere;
 }
@@ -1665,7 +1665,7 @@ obb_t obb_t::Transformed( const vec3_t& translate, const mat3_t& rotate, float s
 	obb_t res;
 
 	res.extends = extends * scale;
-	res.center = center.Transformed( translate, rotate, scale );
+	res.center = center.GetTransformed( translate, rotate, scale );
 	res.rotation = rotate * rotation;
 
 	return res;
@@ -1679,7 +1679,7 @@ PlaneTest
 */
 float obb_t::PlaneTest( const plane_t& plane ) const
 {
-	vec3_t x_normal = rotation.Transposed() * plane.normal;
+	vec3_t x_normal = rotation.GetTransposed() * plane.normal;
 	// maximum extent in direction of plane normal
 	float r = fabs(extends.x*x_normal.x)
 					+ fabs(extends.y*x_normal.y)
@@ -1714,7 +1714,7 @@ bool obb_t::Intersects( const obb_t& other ) const
 	bool parallelAxes = false;
 
 	// transpose of rotation of B relative to A, i.e. (R_b^T * R_a)^T
-	mat3_t Rt = rotation.Transposed() * other.rotation;
+	mat3_t Rt = rotation.GetTransposed() * other.rotation;
 
 	// absolute value of relative rotation matrix
 	mat3_t Rabs;
@@ -1733,7 +1733,7 @@ bool obb_t::Intersects( const obb_t& other ) const
 	}
 
 	// relative translation (in A's frame)
-	vec3_t c = rotation.Transposed()*(other.center - center);
+	vec3_t c = rotation.GetTransposed()*(other.center - center);
 
 	// separating axis A0
 	cTest = fabs(c.x);
@@ -1843,7 +1843,7 @@ bool obb_t::Intersects( const ray_t& ray ) const
 {
 	aabb_t aabb_( -extends, extends );
 	ray_t newray;
-	mat3_t rottrans = rotation.Transposed();
+	mat3_t rottrans = rotation.GetTransposed();
 
 	newray.origin = rottrans * ( ray.origin - center );
 	newray.dir = rottrans * ray.dir;
@@ -1922,7 +1922,7 @@ obb - sphere
 bool obb_t::Intersects( const bsphere_t& sphere ) const
 {
 	aabb_t aabb_( -extends, extends ); // aabb_ is in "this" frame
-	vec3_t new_center = rotation.Transposed() * (sphere.center - center);
+	vec3_t new_center = rotation.GetTransposed() * (sphere.center - center);
 	bsphere_t sphere_( new_center, sphere.radius ); // sphere1 to "this" fame
 
 	return aabb_.Intersects( sphere_ );
@@ -1954,7 +1954,7 @@ obb - sphere
 bool obb_t::SeperationTest( const bsphere_t& sphere, vec3_t& normal, vec3_t& impact_point, float& depth ) const
 {
 	aabb_t aabb_( -extends, extends ); // aabb_ is in "this" frame
-	vec3_t new_center = rotation.Transposed() * (sphere.center - center); // sphere's new center
+	vec3_t new_center = rotation.GetTransposed() * (sphere.center - center); // sphere's new center
 	bsphere_t sphere_( new_center, sphere.radius ); // sphere_ to "this" frame
 
 	UNLOCK_RENDER_SEPERATION

+ 0 - 152
src/uncategorized/common.cpp

@@ -6,158 +6,6 @@
 #include <math.h>
 #include "common.h"
 
-/*
-=======================================================================================================================================
-RandRange                                                                                                                             =
-=======================================================================================================================================
-*/
-int RandRange( int min, int max )
-{
-	return (rand() % (max-min+1)) + min ;
-}
-
-
-float RandRange( float min, float max )
-{
-	double d = max - min; // difference
-	if( d==0.0 ) return min;
-	// diferrense = mant * e^exp
-	int exp;
-	double mant = frexp( d, &exp );
-
-	int precision = 1000; // more accurate
-
-	mant *= precision;
-	double new_mant = rand() % (int)mant;
-	new_mant /= precision;
-
-	return min + (float)ldexp( new_mant, exp ); // return min + (new_mant * e^exp)
-}
-
-
-/*
-=======================================================================================================================================
-ReadFile                                                                                                                              =
-=======================================================================================================================================
-*/
-string ReadFile( const char* filename )
-{
-	ifstream file( filename );
-	if ( !file.is_open() )
-	{
-		ERROR( "Cannot open file \"" << filename << "\"" );
-		return string();
-	}
-
-	return string( (istreambuf_iterator<char>(file)), istreambuf_iterator<char>() );
-}
-
-
-//=====================================================================================================================================
-// GetFileLines                                                                                                                       =
-//=====================================================================================================================================
-vec_t<string> GetFileLines( const char* filename )
-{
-	vec_t<string> lines;
-	ifstream ifs( filename );
-	if( !ifs.is_open() )
-	{
-		ERROR( "Cannot open file \"" << filename << "\"" );
-		return lines;
-	}
-	
-  string temp;
-  while( getline( ifs, temp ) )
-  {
-  	lines.push_back( temp );
-  }
-  return lines;
-}
-
-
-/*
-=======================================================================================================================================
-CutPath                                                                                                                               =
-=======================================================================================================================================
-*/
-/// Used only to cut the path from __FILE__ and return the actual file name and some other cases
-char* CutPath( const char* path )
-{
-	char* str = (char*)path + strlen(path) - 1;
-	for(;;)
-	{
-		if( (str-path)<=-1 || *str=='/' || *str=='\\'  )  break;
-		str--;
-	}
-	return str+1;
-}
-
-
-/*
-=======================================================================================================================================
-GetPath                                                                                                                               =
-=======================================================================================================================================
-*/
-string GetPath( const char* path )
-{
-	char* str = (char*)path + strlen(path) - 1;
-	for(;;)
-	{
-		if( (str-path)<=-1 || *str=='/' || *str=='\\'  )  break;
-		-- str;
-	}
-	++str;
-	int n = str - path;
-	DEBUG_ERR( n<0 || n>100 ); // check the func. probably something wrong
-	string ret_str;
-	ret_str.assign( path, n );
-	return ret_str;
-}
-
-
-/*
-=======================================================================================================================================
-GetFunctionFromPrettyFunction                                                                                                         =
-=======================================================================================================================================
-*/
-/// The function gets __PRETTY_FUNCTION__ and strips it to get only the function name with its namespace
-string GetFunctionFromPrettyFunction( const char* pretty_function )
-{
-	string ret( pretty_function );
-
-	size_t index = ret.find( "(" );
-
-	if ( index != string::npos )
-		ret.erase( index );
-
-	index = ret.rfind( " " );
-	if ( index != string::npos )
-		ret.erase( 0, index + 1 );
-
-	return ret;
-}
-
-
-/*
-=======================================================================================================================================
-GetFileExtension                                                                                                                      =
-=======================================================================================================================================
-*/
-char* GetFileExtension( const char* path )
-{
-	char* str = (char*)path + strlen(path) - 1;
-	for(;;)
-	{
-		if( (str-path)<=-1 || *str=='.' )  break;
-		str--;
-	}
-
-	if( str == (char*)path + strlen(path) - 1 ) ERROR( "Please puth something after the '.' in path \"" << path << "\". Idiot" );
-	if( str+1 == path ) ERROR( "Path \"" << path << "\" doesnt contain a '.'. What the fuck?" );
-
-	return str+1;
-}
-
 
 /*
 =======================================================================================================================================

+ 7 - 10
src/uncategorized/common.h

@@ -35,13 +35,6 @@ typedef unsigned long int ulong;
 //=====================================================================================================================================
 template<typename type_t> class vec_t;
 
-extern int           RandRange( int min, int max );
-extern float         RandRange( float min, float max );
-extern string        ReadFile( const char* filename );
-extern vec_t<string> GetFileLines( const char* filename );
-extern char*         GetFileExtension( const char* path );
-extern char*         CutPath( const char* path );
-extern string        GetPath( const char* path );
 extern string        IntToStr( int );
 extern string        FloatToStr( float );
 
@@ -50,11 +43,15 @@ extern string        FloatToStr( float );
 // MACROS                                                                                                                             =
 //=====================================================================================================================================
 
-#define __FILENAME__ CutPath( __FILE__ )
+namespace util {
+extern char*  CutPath( const char* path );
+extern string GetFunctionFromPrettyFunction( const char* pretty_function );
+}
+
+#define __FILENAME__ util::CutPath( __FILE__ )
 
 #ifdef __GNUG__
-	extern string GetFunctionFromPrettyFunction( const char* pretty_function );
-	#define __G_FUNCTION__ GetFunctionFromPrettyFunction( __PRETTY_FUNCTION__ )
+	#define __G_FUNCTION__ util::GetFunctionFromPrettyFunction( __PRETTY_FUNCTION__ )
 #else
 	#define __G_FUNCTION__ __func__
 #endif

+ 11 - 15
src/uncategorized/material.cpp

@@ -333,23 +333,20 @@ bool material_t::InitTheOther()
 	}
 	shader->Unbind();
 
-	// get the tangents_attrib_loc
-	tangents_attrib_loc = shader->GetAttributeLocationSilently( "tangent" );
-	needs_tangents = ( tangents_attrib_loc == -1 ) ? false : true;
+	// init the attribute locations
+	attribute_locs.tanget = shader->GetAttributeLocationSilently( "tangent" );
+	attribute_locs.position = shader->GetAttributeLocationSilently( "position" );
+	attribute_locs.normal = shader->GetAttributeLocationSilently( "normal" );
+	attribute_locs.tex_coords = shader->GetAttributeLocationSilently( "tex_coords" );
 
 	// vertex weights
-	vert_weight_bones_num_attrib_loc = shader->GetAttributeLocationSilently( "vert_weight_bones_num" );
-	if( vert_weight_bones_num_attrib_loc == -1 )
+	attribute_locs.vert_weight_bones_num = shader->GetAttributeLocationSilently( "vert_weight_bones_num" );
+	if( attribute_locs.vert_weight_bones_num != -1 )
 	{
-		needs_vert_weights = false;
-	}
-	else
-	{
-		vert_weight_bone_ids_attrib_loc = shader->GetAttributeLocation( "vert_weight_bone_ids" );
-		vert_weight_weights_attrib_loc = shader->GetAttributeLocation( "vert_weight_weights" );
-		skinning_rotations_uni_loc = shader->GetUniformLocation( "skinning_rotations" );
-		skinning_translations_uni_loc = shader->GetUniformLocation( "skinning_translations" );
-		needs_vert_weights = true;
+		attribute_locs.vert_weight_bone_ids = shader->GetAttributeLocation( "vert_weight_bone_ids" );
+		attribute_locs.vert_weight_weights = shader->GetAttributeLocation( "vert_weight_weights" );
+		uniform_locs.skinning_rotations = shader->GetUniformLocation( "skinning_rotations" );
+		uniform_locs.skinning_translations = shader->GetUniformLocation( "skinning_translations" );
 	}
 
 	return true;
@@ -395,7 +392,6 @@ void material_t::SetToDefault()
 	shininess = 0.0;
 	grass_map = NULL;
 	casts_shadow = true;
-	needs_tangents = true;
 	refracts = false;
 }
 

+ 20 - 11
src/uncategorized/material.h

@@ -57,17 +57,26 @@ class material_t: public resource_t
 		int  blending_sfactor;
 		int  blending_dfactor;
 
-		// vertex
-		bool needs_tangents; ///< Whether or not to pass tangents in the shader
-		int  tangents_attrib_loc;
-		bool needs_normals;
-		bool needs_tex_coords;
-		bool needs_vert_weights;
-		int  vert_weight_bones_num_attrib_loc;
-		int  vert_weight_bone_ids_attrib_loc;
-		int  vert_weight_weights_attrib_loc;
-		int  skinning_rotations_uni_loc;
-		int  skinning_translations_uni_loc;
+		// vertex attributes
+		struct
+		{
+			int position;
+			int tanget;
+			int normal;
+			int tex_coords;
+
+			// for hw skinning
+			int vert_weight_bones_num;
+			int vert_weight_bone_ids;
+			int vert_weight_weights;
+		} attribute_locs;
+
+		// uniforms
+		struct
+		{
+			int skinning_rotations;
+			int skinning_translations;
+		} uniform_locs;
 
 		bool depth_testing;
 		bool wireframe;

+ 26 - 38
src/uncategorized/mesh.cpp

@@ -455,58 +455,46 @@ void mesh_t::Render()
 	r::MultMatrix( transformation_wspace );
 
 
-	/*GLuint loc = material->shader->GetAttributeLocation( "tangent" );
-
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_NORMAL_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	glEnableVertexAttribArray( loc );
-
-	glVertexPointer( 3, GL_FLOAT, 0, &mesh_data->vert_coords[0][0] );
-	glNormalPointer( GL_FLOAT, 0, &mesh_data->vert_normals[0][0] );
-	glTexCoordPointer( 2, GL_FLOAT, 0, &mesh_data->uvs[0] );
-	glVertexAttribPointer( loc, 4, GL_FLOAT, 0, 0, &mesh_data->vert_tangents[0] );
-
-	glDrawElements( GL_TRIANGLES, mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, &mesh_data->vert_indeces[0] );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableClientState( GL_NORMAL_ARRAY );
-	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-	glDisableVertexAttribArray( loc );*/
-	const int& loc = material->tangents_attrib_loc;
-
-	mesh_data->vbos.vert_coords.Bind();
-	glVertexPointer( 3, GL_FLOAT, 0, NULL );
+	if( material->attribute_locs.position != -1 )
+	{
+		mesh_data->vbos.vert_coords.Bind();
+		glVertexAttribPointer( material->attribute_locs.position, 3, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.position );
+	}
 
-	mesh_data->vbos.vert_normals.Bind();
-	glNormalPointer( GL_FLOAT, 0, NULL );
+	if( material->attribute_locs.normal != -1 )
+	{
+		mesh_data->vbos.vert_normals.Bind();
+		glVertexAttribPointer( material->attribute_locs.normal, 3, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.normal );
+	}
 
-	mesh_data->vbos.tex_coords.Bind();
-	glTexCoordPointer( 2, GL_FLOAT, 0, NULL );
+	if( material->attribute_locs.tex_coords != -1 )
+	{
+		mesh_data->vbos.tex_coords.Bind();
+		glVertexAttribPointer( material->attribute_locs.tex_coords, 2, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.tex_coords );
+	}
 
-	if( material->needs_tangents )
+	if( material->attribute_locs.tanget != -1 )
 	{
 		mesh_data->vbos.vert_tangents.Bind();
-		glVertexAttribPointer( loc, 4, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( loc );
+		glVertexAttribPointer( material->attribute_locs.tanget, 4, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.tanget );
 	}
 
 	mesh_data->vbos.vert_indeces.Bind();
 
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_NORMAL_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-
 	glDrawElements( GL_TRIANGLES, mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
 
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableClientState( GL_NORMAL_ARRAY );
-	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-	if( material->needs_tangents ) glDisableVertexAttribArray( loc );
 
-	vbo_t::UnbindAllTargets();
+	if( material->attribute_locs.position != -1 ) glDisableVertexAttribArray( material->attribute_locs.position );
+	if( material->attribute_locs.normal != -1 ) glDisableVertexAttribArray( material->attribute_locs.normal );
+	if( material->attribute_locs.tex_coords != -1 ) glDisableVertexAttribArray( material->attribute_locs.tex_coords );
+	if( material->attribute_locs.tanget != -1 ) glDisableVertexAttribArray( material->attribute_locs.tanget );
 
 
+	vbo_t::UnbindAllTargets();
 	glPopMatrix();
 }
 

+ 8 - 7
src/uncategorized/particles.cpp

@@ -1,5 +1,6 @@
 #include "particles.h"
 #include "renderer.h"
+#include "util.h"
 
 using namespace std;
 
@@ -129,13 +130,13 @@ ReInitParticle @ particle_emitter_t
 void particle_emitter_t::ReInitParticle( particle_t& particle )
 {
 	// life
-	particle.life = RandRange( particle_life[MIN], particle_life[MAX] );
+	particle.life = util::RandRange( particle_life[MIN], particle_life[MAX] );
 
 	// pos
 	particle.translation_lspace = vec3_t(
-		RandRange( particles_translation_lspace[MIN].x, particles_translation_lspace[MAX].x ),
-		RandRange( particles_translation_lspace[MIN].y, particles_translation_lspace[MAX].y ),
-		RandRange( particles_translation_lspace[MIN].z, particles_translation_lspace[MAX].z )
+		util::RandRange( particles_translation_lspace[MIN].x, particles_translation_lspace[MAX].x ),
+		util::RandRange( particles_translation_lspace[MIN].y, particles_translation_lspace[MAX].y ),
+		util::RandRange( particles_translation_lspace[MIN].z, particles_translation_lspace[MAX].z )
 	);
 	particle.rotation_lspace = mat3_t::GetIdentity();
 	particle.scale_lspace = 1.0;
@@ -152,9 +153,9 @@ void particle_emitter_t::ReInitParticle( particle_t& particle )
 	for( int i=0; i<PARTICLE_VELS_NUM; i++ )
 	{
 		euler_t tmp_angs = euler_t(
-			RandRange( velocities[i].angs[MIN].x, velocities[i].angs[MAX].x ),
-			RandRange( velocities[i].angs[MIN].y, velocities[i].angs[MAX].y ),
-			RandRange( velocities[i].angs[MIN].z, velocities[i].angs[MAX].z )
+			util::RandRange( velocities[i].angs[MIN].x, velocities[i].angs[MAX].x ),
+			util::RandRange( velocities[i].angs[MIN].y, velocities[i].angs[MAX].y ),
+			util::RandRange( velocities[i].angs[MIN].z, velocities[i].angs[MAX].z )
 		);
 		mat3_t m3;
 		m3 = mat3_t(tmp_angs);

+ 4 - 2
src/uncategorized/resource.h

@@ -3,6 +3,7 @@
 
 #include "common.h"
 #include "engine_class.h"
+#include "util.h"
 
 class texture_t;
 class material_t;
@@ -37,6 +38,7 @@ class resource_t
 	friend class rsrc::container_t<mesh_data_t>;
 	friend class rsrc::container_t<model_data_t>;
 	friend class rsrc::container_t<model_t>;
+	friend class shader_prog_t;
 
 	public:
 		virtual bool Load( const char* ) = 0;
@@ -130,8 +132,8 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 		*/
 		type_t* Load( const char* fname )
 		{
-			char* name = CutPath( fname );
-			string path = GetPath( fname );
+			char* name = util::CutPath( fname );
+			string path = util::GetPath( fname );
 			iterator_t it = FindByNameAndPath( name, path.c_str() );
 
 			// if allready loaded then inc the users and return the pointer

+ 2 - 1
src/uncategorized/shader_parser.cpp

@@ -2,6 +2,7 @@
 #include "shader_parser.h"
 #include "scanner.h"
 #include "parser.h"
+#include "util.h"
 
 
 //=====================================================================================================================================
@@ -53,7 +54,7 @@ vec_t<shader_parser_t::shader_var_t>::iterator shader_parser_t::FindShaderVar( v
 bool shader_parser_t::ParseFileForPragmas( const string& filename, int id )
 {
 	// load file in lines
-	vec_t<string> lines = GetFileLines( filename.c_str() );
+	vec_t<string> lines = util::GetFileLines( filename.c_str() );
 	if( lines.size() < 1 )
 	{
 		ERROR( "Cannot parse file \"" << filename << "\"" );

+ 8 - 4
src/uncategorized/shader_prog.cpp

@@ -118,7 +118,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 		int loc = glGetAttribLocation(gl_id, name_);
 		if( loc == -1 )
 		{
-			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
+			SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
 			continue;
 		}
 
@@ -137,7 +137,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 		int loc = glGetUniformLocation(gl_id, name_);
 		if( loc == -1 )
 		{
-			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
+			SHADER_WARNING( "You are using FFP uniforms (\"" << name_ << "\")" );
 			continue;
 		}
 
@@ -224,12 +224,16 @@ bool shader_prog_t::Load( const char* filename )
 //=====================================================================================================================================
 bool shader_prog_t::CustomLoad( const char* filename, const char* extra_source )
 {
+	if( GetName().length() == 0 )
+	{
+		name = util::CutPath( filename );
+		path = util::GetPath( filename );
+	}
+
 	shader_parser_t pars;
 
 	if( !pars.ParseFile( filename ) ) return false;
 
-	//r::GetStdShaderPreprocDefines().c_str()
-
 	// create, compile, attach and link
 	string preproc_source = r::GetStdShaderPreprocDefines() + extra_source;
 	uint vert_gl_id = CreateAndCompileShader( pars.vert_shader_source.c_str(), preproc_source.c_str(), GL_VERTEX_SHADER );

+ 52 - 77
src/uncategorized/smodel.cpp

@@ -63,7 +63,7 @@ bool skeleton_data_t::Load( const char* filename )
 		// matrix for real
 		bone.rot_skel_space = m4.GetRotationPart();
 		bone.tsl_skel_space = m4.GetTranslationPart();
-		mat4_t MAi( m4.Inverted() );
+		mat4_t MAi( m4.GetInverse() );
 		bone.rot_skel_space_inv = MAi.GetRotationPart();
 		bone.tsl_skel_space_inv = MAi.GetTranslationPart();
 
@@ -687,8 +687,8 @@ void smodel_t::Deform()
 			const mat3_t& rot = bone_rotations[ i ];
 			const vec3_t& transl = bone_translations[ i ];
 
-			bones[i].head = model_data->skeleton_data->bones[i].head.Transformed( transl, rot );
-			bones[i].tail = model_data->skeleton_data->bones[i].tail.Transformed( transl, rot );
+			bones[i].head = model_data->skeleton_data->bones[i].head.GetTransformed( transl, rot );
+			bones[i].tail = model_data->skeleton_data->bones[i].tail.GetTransformed( transl, rot );
 		}
 	}
 }
@@ -735,93 +735,68 @@ void smodel_t::Render()
 	glPushMatrix();
 	r::MultMatrix( transformation_wspace );
 
-	/*GLuint loc = material->tangents_attrib_loc;
-
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_NORMAL_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	glEnableVertexAttribArray( loc );
-
-	glVertexPointer( 3, GL_FLOAT, 0, &vert_coords[0][0] );
-	glNormalPointer( GL_FLOAT, 0, &vert_normals[0][0] );
-	glTexCoordPointer( 2, GL_FLOAT, 0, &model_data->mesh_data->tex_coords[0] );
-	glVertexAttribPointer( loc, 4, GL_FLOAT, 0, 0, &vert_tangents[0] );
-
-	glDrawElements( GL_TRIANGLES, model_data->mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, &model_data->mesh_data->vert_indeces[0] );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableClientState( GL_NORMAL_ARRAY );
-	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-	glDisableVertexAttribArray( loc );*/
-
-	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] );
-
-
-	glEnableClientState( GL_VERTEX_ARRAY );
-	glEnableClientState( GL_NORMAL_ARRAY );
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
 
+	// first the uniforms
+	glUniformMatrix3fv( material->uniform_locs.skinning_rotations, model_data->skeleton_data->bones.size(), 1, &(bone_rotations[0])[0] );
+	glUniform3fv( material->uniform_locs.skinning_translations, model_data->skeleton_data->bones.size(), &(bone_translations[0])[0] );
 
-	/*glVertexPointer( 3, GL_FLOAT, 0, &model_data->mesh_data->vert_coords[0][0] );
-	glNormalPointer( GL_FLOAT, 0, &model_data->mesh_data->vert_normals[0][0] );
-	glTexCoordPointer( 2, GL_FLOAT, 0, &model_data->mesh_data->tex_coords[0] );
 
-	glEnableVertexAttribArray( material->tangents_attrib_loc );
-	glVertexAttribPointer( material->tangents_attrib_loc, 4, GL_FLOAT, 0, 0, &model_data->mesh_data->vert_tangents[0] );
-
-	glEnableVertexAttribArray( material->vert_weight_bones_num_attrib_loc );
-	glVertexAttribPointer( material->vert_weight_bones_num_attrib_loc, 1, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), &model_data->mesh_data->vert_weights[0].bones_num );
-	glEnableVertexAttribArray( material->vert_weight_bone_ids_attrib_loc );
-	glVertexAttribPointer( material->vert_weight_bone_ids_attrib_loc, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), &model_data->mesh_data->vert_weights[0].bone_ids[0] );
-	glEnableVertexAttribArray( material->vert_weight_weights_attrib_loc );
-	glVertexAttribPointer( material->vert_weight_weights_attrib_loc, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), &model_data->mesh_data->vert_weights[0].weights[0] );
-
-	glDrawElements( GL_TRIANGLES, model_data->mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, &model_data->mesh_data->vert_indeces[0] );*/
-
-
-	/////////////////////////////////////////////////
-	glEnableClientState( GL_VERTEX_ARRAY );
-	model_data->mesh_data->vbos.vert_coords.Bind();
-	glVertexPointer( 3, GL_FLOAT, 0, NULL );
-
-	glEnableClientState( GL_NORMAL_ARRAY );
-	model_data->mesh_data->vbos.vert_normals.Bind();
-	glNormalPointer( GL_FLOAT, 0, NULL );
-
-	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	model_data->mesh_data->vbos.tex_coords.Bind();
-	glTexCoordPointer( 2, GL_FLOAT, 0, NULL );
+	if( material->attribute_locs.position != -1 )
+	{
+		model_data->mesh_data->vbos.vert_coords.Bind();
+		glVertexAttribPointer( material->attribute_locs.position, 3, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.position );
+	}
 
-	glEnableVertexAttribArray( material->tangents_attrib_loc );
-	model_data->mesh_data->vbos.vert_tangents.Bind();
-	glVertexAttribPointer( material->tangents_attrib_loc, 4, GL_FLOAT, false, 0, NULL );
+	if( material->attribute_locs.normal != -1 )
+	{
+		model_data->mesh_data->vbos.vert_normals.Bind();
+		glVertexAttribPointer( material->attribute_locs.normal, 3, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.normal );
+	}
 
+	if( material->attribute_locs.tex_coords != -1 )
+	{
+		model_data->mesh_data->vbos.tex_coords.Bind();
+		glVertexAttribPointer( material->attribute_locs.tex_coords, 2, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.tex_coords );
+	}
 
-	model_data->mesh_data->vbos.vert_weights.Bind();
-	glEnableVertexAttribArray( material->vert_weight_bones_num_attrib_loc );
-	glVertexAttribPointer( material->vert_weight_bones_num_attrib_loc, 1, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(0) );
-	glEnableVertexAttribArray( material->vert_weight_bone_ids_attrib_loc );
-	glVertexAttribPointer( material->vert_weight_bone_ids_attrib_loc, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(4) );
-	glEnableVertexAttribArray( material->vert_weight_weights_attrib_loc );
-	glVertexAttribPointer( material->vert_weight_weights_attrib_loc, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(20) );
+	if( material->attribute_locs.tanget != -1 )
+	{
+		model_data->mesh_data->vbos.vert_tangents.Bind();
+		glVertexAttribPointer( material->attribute_locs.tanget, 4, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.tanget );
+	}
 
+	if( material->attribute_locs.vert_weight_bones_num != -1 )
+	{
+		model_data->mesh_data->vbos.vert_weights.Bind();
+		glEnableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
+		glVertexAttribPointer( material->attribute_locs.vert_weight_bones_num, 1, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(0) );
+		glEnableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
+		glVertexAttribPointer( material->attribute_locs.vert_weight_bone_ids, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(4) );
+		glEnableVertexAttribArray( material->attribute_locs.vert_weight_weights );
+		glVertexAttribPointer( material->attribute_locs.vert_weight_weights, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(20) );
+	}
 
 	model_data->mesh_data->vbos.vert_indeces.Bind();
-	glDrawElements( GL_TRIANGLES, model_data->mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
-
-	vbo_t::UnbindAllTargets();
-	/////////////////////////////////////////////////
 
+	glDrawElements( GL_TRIANGLES, model_data->mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
 
 
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableClientState( GL_NORMAL_ARRAY );
-	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-	glDisableVertexAttribArray( material->tangents_attrib_loc );
-	glDisableVertexAttribArray( material->vert_weight_bones_num_attrib_loc );
-
+	if( material->attribute_locs.position != -1 ) glDisableVertexAttribArray( material->attribute_locs.position );
+	if( material->attribute_locs.normal != -1 ) glDisableVertexAttribArray( material->attribute_locs.normal );
+	if( material->attribute_locs.tex_coords != -1 ) glDisableVertexAttribArray( material->attribute_locs.tex_coords );
+	if( material->attribute_locs.tanget != -1 ) glDisableVertexAttribArray( material->attribute_locs.tanget );
+	if( material->attribute_locs.vert_weight_bones_num != -1 )
+	{
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_weights );
+	}
 
+	vbo_t::UnbindAllTargets();
 	glPopMatrix();
 }
 

+ 1 - 6
src/uncategorized/texture.cpp

@@ -274,7 +274,7 @@ Load
 bool image_t::Load( const char* filename )
 {
 	// get the extension
-	char* ext = GetFileExtension( filename );
+	char* ext = util::GetFileExtension( filename );
 
 	// load from this extension
 	if( strcmp( ext, "tga" ) == 0 )
@@ -350,11 +350,6 @@ bool texture_t::Load( const char* filename )
 	else
 		int_format = (img.bpp==32) ? GL_RGBA : GL_RGB;
 
-	/*if( r::mipmaping )
-		gluBuild2DMipmaps( GL_TEXTURE_2D, int_format, img.width, img.height, format, GL_UNSIGNED_BYTE, img.data );
-	else
-		glTexImage2D( GL_TEXTURE_2D, 0, int_format, img.width, img.height, 0, format, GL_UNSIGNED_BYTE, img.data );*/
-
 	glTexImage2D( GL_TEXTURE_2D, 0, int_format, img.width, img.height, 0, format, GL_UNSIGNED_BYTE, img.data );
 	if( r::mipmaping ) glGenerateMipmap(GL_TEXTURE_2D);
 

+ 25 - 56
src/uncategorized/gstring.h → src/utility/u_string.h

@@ -1,5 +1,5 @@
-#ifndef _GSTRING_H_
-#define _GSTRING_H_
+#ifndef _U_STRING_H_
+#define _U_STRING_H_
 
 #include <iostream>
 #include <cstdlib>
@@ -30,17 +30,19 @@ class string_t
 		bool const_data; ///< false means that we have allocated memory
 		uint length;
 		
-		// private stuff
-		void Init( float d )
+		// private funcs
+		template<typename type_t> string_t ConvertT( type_t t, const char* format )
 		{
-			char pc [256];
-			sprintf( pc, "%f", d );
-			length = strlen( pc );
-			const_data = false;
-			data = (char*) malloc( (length+1)*sizeof(char) );
-			memcpy( data, pc, length+1 );
+			string_t out;
+			char tmps [1024];
+			int n = sprintf( tmps, format, t );
+			out.length = n;
+			out.const_data = false;
+			out.data = malloc( (length+1)*sizeof(char) );
+			memcpy( out.data, tmps, length+1 );
+			return out;
 		}
-		
+
 	public:
 		static const uint npos = UINT_MAX;  // ToDo: change it when C++0x becomes standard
 		
@@ -223,60 +225,27 @@ class string_t
 		//================================================================================================================================
 		
 		// Convert
-		static string_t Convert( int i )
+		static string_t Convert( int i, const char* format = "%d" )
 		{
-			string_t out;
-			if( i == 0 )
-			{
-				out.data = "0";
-				out.const_data = true;
-				out.length = 1;
-			}
-			else
-			{
-				char cv [256];
-				const size_t cv_size = sizeof(cv)/sizeof(char); 
-				char* pc = &cv[ cv_size ];
-				int ii = (i<0) ? -i : i;
-				while( ii != 0 )
-				{
-					int mod = ii%10;
-					ii /= 10;
-					--pc;
-					*pc = ('0' + mod);
-				}
-				if( i < 0 )
-				{
-					--pc;
-					*pc = '-';
-				}
-				out.length = cv + cv_size - pc;
-				DEBUG_ERR( out.length >= sizeof(cv)/sizeof(char) );
-				out.const_data = false;
-				out.data = (char*) malloc( (out.length+1)*sizeof(char) );
-				memcpy( out.data, pc, out.length );
-				out.data[out.length] = '\0';
-			}
-			return out;
+			return ConvertT( i, format );
 		}
 		
+		// Convert [uint]
+		static string_t Convert( uint u, const char* format = "%u"  )
+		{
+			return ConvertT( u, format );
+		}
+
 		// Convert [float]
-		static string_t Convert( float f )
+		static string_t Convert( float f, const char* format = "%f"  )
 		{
-			string_t out;
-			char pc [256];
-			sprintf( pc, "%f", f );
-			out.length = strlen( pc );
-			out.const_data = false;
-			out.data = (char*) malloc( (out.length+1)*sizeof(char) );
-			memcpy( out.data, pc, out.length+1 );
-			return out;
+			return ConvertT( f, format );
 		}
 		
 		// Convert [double]
-		static string_t Convert( double d )
+		static string_t Convert( double d, const char* format = "%f"  )
 		{
-			return Convert( (float)d );
+			return ConvertT( d, format );
 		}
 		
 		// Clear

+ 147 - 0
src/utility/util.cpp

@@ -0,0 +1,147 @@
+#include "util.h"
+#include <math.h>
+
+
+namespace util {
+
+//=====================================================================================================================================
+// RandRange                                                                                                                          =
+//=====================================================================================================================================
+int RandRange( int min, int max )
+{
+	return (rand() % (max-min+1)) + min ;
+}
+
+
+float RandRange( float min, float max )
+{
+	double d = max - min; // difference
+	if( d==0.0 ) return min;
+	// diferrense = mant * e^exp
+	int exp;
+	double mant = frexp( d, &exp );
+
+	int precision = 1000; // more accurate
+
+	mant *= precision;
+	double new_mant = rand() % (int)mant;
+	new_mant /= precision;
+
+	return min + (float)ldexp( new_mant, exp ); // return min + (new_mant * e^exp)
+}
+
+
+//=====================================================================================================================================
+// ReadFile                                                                                                                           =
+//=====================================================================================================================================
+string ReadFile( const char* filename )
+{
+	ifstream file( filename );
+	if ( !file.is_open() )
+	{
+		ERROR( "Cannot open file \"" << filename << "\"" );
+		return string();
+	}
+
+	return string( (istreambuf_iterator<char>(file)), istreambuf_iterator<char>() );
+}
+
+
+//=====================================================================================================================================
+// GetFileLines                                                                                                                       =
+//=====================================================================================================================================
+vec_t<string> GetFileLines( const char* filename )
+{
+	vec_t<string> lines;
+	ifstream ifs( filename );
+	if( !ifs.is_open() )
+	{
+		ERROR( "Cannot open file \"" << filename << "\"" );
+		return lines;
+	}
+
+  string temp;
+  while( getline( ifs, temp ) )
+  {
+  	lines.push_back( temp );
+  }
+  return lines;
+}
+
+
+//=====================================================================================================================================
+// CutPath                                                                                                                            =
+//=====================================================================================================================================
+/// Used only to cut the path from __FILE__ and return the actual file name and some other cases
+char* CutPath( const char* path )
+{
+	char* str = (char*)path + strlen(path) - 1;
+	for(;;)
+	{
+		if( (str-path)<=-1 || *str=='/' || *str=='\\'  )  break;
+		str--;
+	}
+	return str+1;
+}
+
+
+//=====================================================================================================================================
+// GetPath                                                                                                                            =
+//=====================================================================================================================================
+string GetPath( const char* path )
+{
+	char* str = (char*)path + strlen(path) - 1;
+	for(;;)
+	{
+		if( (str-path)<=-1 || *str=='/' || *str=='\\'  )  break;
+		-- str;
+	}
+	++str;
+	int n = str - path;
+	DEBUG_ERR( n<0 || n>100 ); // check the func. probably something wrong
+	string ret_str;
+	ret_str.assign( path, n );
+	return ret_str;
+}
+
+
+//=====================================================================================================================================
+// GetFunctionFromPrettyFunction                                                                                                      =
+//=====================================================================================================================================
+/// The function gets __PRETTY_FUNCTION__ and strips it to get only the function name with its namespace
+string GetFunctionFromPrettyFunction( const char* pretty_function )
+{
+	string ret( pretty_function );
+
+	size_t index = ret.find( "(" );
+
+	if ( index != string::npos )
+		ret.erase( index );
+
+	index = ret.rfind( " " );
+	if ( index != string::npos )
+		ret.erase( 0, index + 1 );
+
+	return ret;
+}
+
+
+//=====================================================================================================================================
+// GetFileExtension                                                                                                                   =
+//=====================================================================================================================================
+char* GetFileExtension( const char* path )
+{
+	char* str = (char*)path + strlen(path) - 1;
+	for(;;)
+	{
+		if( (str-path)<=-1 || *str=='.' )  break;
+		str--;
+	}
+
+	if( str == (char*)path + strlen(path) - 1 ) ERROR( "Please puth something after the '.' in path \"" << path << "\". Idiot" );
+	if( str+1 == path ) ERROR( "Path \"" << path << "\" doesnt contain a '.'. What the fuck?" );
+
+	return str+1;
+}
+
+}

+ 20 - 0
src/utility/util.h

@@ -0,0 +1,20 @@
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+#include "common.h"
+
+namespace util {
+
+extern int   RandRange( int min, int max );
+extern float RandRange( float min, float max );
+
+extern string        ReadFile( const char* filename );
+extern vec_t<string> GetFileLines( const char* filename );
+extern char*         GetFileExtension( const char* path );
+extern char*         CutPath( const char* path );
+extern string        GetPath( const char* path );
+extern string        GetFunctionFromPrettyFunction( const char* pretty_function );
+
+}
+
+#endif

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff