Explorar o código

Migrating to new shader format (Pt1)

Panagiotis Christopoulos Charitos %!s(int64=16) %!d(string=hai) anos
pai
achega
403a5aab33

+ 0 - 1
src/main.cpp

@@ -14,7 +14,6 @@
 #include "primitives.h"
 #include "texture.h"
 #include "mesh.h"
-#include "shaders.h"
 #include "lights.h"
 #include "collision.h"
 #include "smodel.h"

+ 1 - 1
src/old_src/2009-5-11/hud.cpp

@@ -162,7 +162,7 @@ void Init()
 	font_map = ass::LoadTxtr( "gfx/fontmapa.tga" );
 	font_map->TexParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
 	font_map->TexParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	shader = ass::LoadShdr( "shaders/txt.shdr" );
+	shader = ass::LoadShdr( "shaders/txt.glsl" );
 	SetPos( 0.0f, 0.0f );
 	SetFontWidth( 0.05f );
 	SetColor( vec4_t(1.0f, 1.0f, 1.0f, 1.0f) );

+ 1 - 1
src/old_src/main_parallax.cpp

@@ -63,7 +63,7 @@ int main( int argc, char* argv[] )
 	normal_map = ass::LoadTxtr( "textures/stone.001.norm.tga" );
 	height_map = ass::LoadTxtr( "textures/stone.001.height.tga" );
 
-	shdr_parallax = ass::LoadShdr( "shaders/old/parallax.shdr" );
+	shdr_parallax = ass::LoadShdr( "shaders/old/parallax.glsl" );
 
 
 	scene::Register( &floor__ );

+ 1 - 1
src/renderer/r_dbg.cpp

@@ -55,7 +55,7 @@ void Init()
 	fbo.Unbind();
 
 	// shader
-	shdr = rsrc::shaders.Load( "shaders/dbg.shdr" );
+	shdr = rsrc::shaders.Load( "shaders/dbg.glsl" );
 }
 
 

+ 4 - 4
src/renderer/r_is.cpp

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

+ 3 - 3
src/renderer/r_is_shadows.cpp

@@ -62,9 +62,9 @@ void Init()
 	fbo.Unbind();
 
 	// shaders
-	shdr_depth = rsrc::shaders.Load( "shaders/dp.shdr" );
-	shdr_depth_grass = rsrc::shaders.Load( "shaders/dp_grass.shdr" );
-	shdr_depth_hw_skinning = rsrc::shaders.Load( "shaders/dp_hw_skinning.shdr" );
+	shdr_depth = rsrc::shaders.Load( "shaders/dp.glsl" );
+	shdr_depth_grass = rsrc::shaders.Load( "shaders/dp_grass.glsl" );
+	shdr_depth_hw_skinning = rsrc::shaders.Load( "shaders/dp_hw_skinning.glsl" );
 }
 
 

+ 2 - 2
src/renderer/r_ms_earlyz.cpp

@@ -51,8 +51,8 @@ void Init()
 	fbo.Unbind();
 
 	// shaders
-	shdr_dp = rsrc::shaders.Load( "shaders/dp.shdr" );
-	shdr_dp_grass = rsrc::shaders.Load( "shaders/dp_grass.shdr" );
+	shdr_dp = rsrc::shaders.Load( "shaders/dp.glsl" );
+	shdr_dp_grass = rsrc::shaders.Load( "shaders/dp_grass.glsl" );
 }
 
 

+ 1 - 1
src/renderer/r_pps.cpp

@@ -62,7 +62,7 @@ void Init()
 
 
 	// init the shader and it's vars
-	shdr_post_proc_stage = rsrc::shaders.Load( "shaders/pps.shdr" );
+	shdr_post_proc_stage = rsrc::shaders.Load( "shaders/pps.glsl" );
 	shdr_post_proc_stage->Bind();
 
 	shdr_vars::is_fai = shdr_post_proc_stage->GetUniformLocation( "is_fai" );

+ 2 - 2
src/renderer/r_pps_bloom.cpp

@@ -81,8 +81,8 @@ void Init()
 	InitFBOs( final_fbo, final_fai );
 
 	// init shaders
-	shdr_pps_bloom_vblur = rsrc::shaders.Load( "shaders/pps_bloom_vblur.shdr" );
-	shdr_pps_bloom_final = rsrc::shaders.Load( "shaders/pps_bloom_final.shdr" );
+	shdr_pps_bloom_vblur = rsrc::shaders.Load( "shaders/pps_bloom_vblur.glsl" );
+	shdr_pps_bloom_final = rsrc::shaders.Load( "shaders/pps_bloom_final.glsl" );
 }
 
 

+ 1 - 1
src/renderer/r_pps_lscatt.cpp

@@ -62,7 +62,7 @@ void Init()
 
 
 	// init shaders
-	shdr = rsrc::shaders.Load( "shaders/pps_lscatt.shdr" );
+	shdr = rsrc::shaders.Load( "shaders/pps_lscatt.glsl" );
 	ms_depth_fai_uni_loc = shdr->GetUniformLocation( "ms_depth_fai" );
 	is_fai_uni_loc = shdr->GetUniformLocation( "is_fai" );
 }

+ 1 - 1
src/renderer/r_pps_ssao.cpp

@@ -68,7 +68,7 @@ void Init()
 
 
 	// init shaders
-	shdr_ppp_ssao = rsrc::shaders.Load( "shaders/pps_ssao.shdr" );
+	shdr_ppp_ssao = rsrc::shaders.Load( "shaders/pps_ssao.glsl" );
 
 	// load noise map and disable temporaly the texture compression and enable mipmaping
 	bool tex_compr = r::texture_compression;

+ 1 - 1
src/renderer/renderer.cpp

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

+ 1 - 1
src/renderer/renderer.h

@@ -6,7 +6,7 @@
 #include <GL/gl.h>
 #include <GL/glu.h>
 #include "gmath.h"
-#include "shaders.h"
+#include "shader_prog.h"
 
 
 

+ 1 - 1
src/uncategorized/hud.cpp

@@ -162,7 +162,7 @@ void Init()
 	font_map = rsrc::textures.Load( "gfx/fontmapa.tga" );
 	font_map->TexParameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 	//font_map->TexParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	shader = rsrc::shaders.Load( "shaders/txt.shdr" );
+	shader = rsrc::shaders.Load( "shaders/txt.glsl" );
 	SetPos( 0.0f, 0.0f );
 	SetFontWidth( 0.05f );
 	SetColor( vec4_t(1.0f, 1.0f, 1.0f, 1.0f) );

+ 1 - 1
src/uncategorized/material.cpp

@@ -4,7 +4,7 @@
 #include "scanner.h"
 #include "parser.h"
 #include "texture.h"
-#include "shaders.h"
+#include "shader_prog.h"
 #include "renderer.h"
 
 /*

+ 1 - 1
src/uncategorized/resource.cpp

@@ -1,7 +1,7 @@
 #include "resource.h"
 #include "texture.h"
 #include "material.h"
-#include "shaders.h"
+#include "shader_prog.h"
 #include "mesh.h"
 #include "smodel.h"
 #include "model.h"

+ 12 - 9
src/uncategorized/shader_prog.cpp

@@ -1,5 +1,7 @@
 #include "shader_prog.h"
+#include "renderer.h"
 #include "shader_parser.h"
+#include "texture.h"
 
 
 #define SHADER_ERROR( x ) ERROR( "Shader prog \"" << GetName() << "\": " << x )
@@ -18,8 +20,8 @@ uint shader_prog_t::CreateAndCompileShader( const char* source_code, int type )
 	gl_id = glCreateShader( type );
 
 	// attach the source
-	source_strs[0] = source_code;
-	source_strs[1] = r::GetStdShaderPreprocDefines().c_str();
+	source_strs[1] = source_code;
+	source_strs[0] = r::GetStdShaderPreprocDefines();
 
 	// compile
 	glShaderSource( gl_id, 2, source_strs, NULL );
@@ -117,7 +119,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 			continue;
 		}
 
-		attrib_name_to_loc[ name_ ] = i
+		attrib_name_to_loc[ name_ ] = i;
 	}
 
 
@@ -135,7 +137,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 			continue;
 		}
 
-		uni_name_to_loc[ name_ ] = i
+		uni_name_to_loc[ name_ ] = i;
 	}
 }
 
@@ -145,7 +147,7 @@ void shader_prog_t::GetUniAndAttribLocs()
 //=====================================================================================================================================
 bool shader_prog_t::FillTheCustomLocationsVectors( const shader_parser_t& pars )
 {
-	int max = 0;
+	uint max = 0;
 
 	// uniforms
 	for( uint i=0; i<pars.uniforms.size(); ++i )
@@ -180,11 +182,11 @@ bool shader_prog_t::FillTheCustomLocationsVectors( const shader_parser_t& pars )
 		if( pars.attributes[i].custom_loc > max ) 
 			max = pars.attributes[i].custom_loc;
 	}
-	custom_attr_loc_to_real_loc.assign( max + 1, -1 );
+	custom_attrib_loc_to_real_loc.assign( max + 1, -1 );
 
 	for( uint i=0; i<pars.attributes.size(); ++i )
 	{
-		if( custom_attr_loc_to_real_loc[ pars.attributes[i].custom_loc ] != -1 )
+		if( custom_attrib_loc_to_real_loc[ pars.attributes[i].custom_loc ] != -1 )
 		{
 			SHADER_ERROR( "The attribute \"" << pars.attributes[i].name << "\" has the same value with another one" );
 			return false;
@@ -195,7 +197,7 @@ bool shader_prog_t::FillTheCustomLocationsVectors( const shader_parser_t& pars )
 			SHADER_ERROR( "Check the previous error" );
 			return false;
 		}
-		custom_attr_loc_to_real_loc[pars.attributes[i].custom_loc] = loc;
+		custom_attrib_loc_to_real_loc[pars.attributes[i].custom_loc] = loc;
 	}
 
 	return true;
@@ -209,8 +211,9 @@ bool shader_prog_t::Load( const char* filename )
 {
 	shader_parser_t pars;
 
-	if( !pars.LoadFile( filename ) ) return false;
+	if( !pars.ParseFile( filename ) ) return false;
 
+	PRINT( pars.frag_shader_source )
 
 	// create, compile, attach and link
 	uint vert_gl_id = CreateAndCompileShader( pars.vert_shader_source.c_str(), GL_VERTEX_SHADER );

+ 3 - 2
src/uncategorized/shader_prog.h

@@ -2,6 +2,7 @@
 #define _SHADER_PROG_H_
 
 #include <GL/glew.h>
+#include <map>
 #include "common.h"
 #include "resource.h"
 
@@ -37,8 +38,8 @@ class shader_prog_t: public resource_t
 		bool Load( const char* filename );
 		void Unload() { /* ToDo: add code */ }
 
-		int GetUniformLocation( const char* name ) const; ///< Returnes -1 if fail and throws error
-		int GetAttributeLocation( const char* name ) const; ///< Returnes -1 if fail and throws error
+		int GetUniformLocation( const char* name ) const; ///< Returns -1 if fail and throws error
+		int GetAttributeLocation( const char* name ) const; ///< Returns -1 if fail and throws error
 		int GetUniformLocationSilently( const char* name ) const;
 		int GetAttributeLocationSilently( const char* name ) const;
 

+ 1 - 1
src/uncategorized/skybox.cpp

@@ -40,7 +40,7 @@ bool skybox_t::Load( const char* filenames[6] )
 	noise->TexParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
 	noise->TexParameter( GL_TEXTURE_WRAP_T, GL_REPEAT );
 
-	shader = rsrc::shaders.Load( "shaders/ms_mp_skybox.shdr" );
+	shader = rsrc::shaders.Load( "shaders/ms_mp_skybox.glsl" );
 
 	return true;
 }