2013-04-17 23:29:41 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Copyright 2013 Dolphin Emulator Project
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Licensed under GPLv2
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Refer to the license.txt file included.
 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-09 17:30:05 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <string> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-17 05:18:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "Common/MathUtil.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "Common/StringUtil.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-17 05:18:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoBackends/OGL/ProgramShaderCache.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoBackends/OGL/Render.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoBackends/OGL/StreamBuffer.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoCommon/Debugger.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoCommon/DriverDetails.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoCommon/ImageWrite.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "VideoCommon/PixelShaderManager.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-19 12:14:09 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "VideoCommon/Statistics.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-17 05:18:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "VideoCommon/VertexShaderManager.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-10 15:58:44 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-11-30 21:00:21 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								namespace  OGL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-21 00:15:48 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-22 10:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  const  u32  UBO_LENGTH  =  32 * 1024 * 1024 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-25 13:20:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-14 13:58:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								u32  ProgramShaderCache : : s_ubo_buffer_size ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-07 17:19:47 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								s32  ProgramShaderCache : : s_ubo_align ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-31 23:11:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  StreamBuffer  * s_buffer ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-04 23:30:13 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  num_failures  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-31 23:11:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-07-08 15:58:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  LinearDiskCache < SHADERUID ,  u8 >  g_program_disk_cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  GLuint  CurrentProgram  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ProgramShaderCache : : PCache  ProgramShaderCache : : pshaders ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ProgramShaderCache : : PCacheEntry *  ProgramShaderCache : : last_entry ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								SHADERUID  ProgramShaderCache : : last_uid ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-29 21:00:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								UidChecker < PixelShaderUid , PixelShaderCode >  ProgramShaderCache : : pixel_uid_checker ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								UidChecker < VertexShaderUid , VertexShaderCode >  ProgramShaderCache : : vertex_uid_checker ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 15:32:38 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  s_glsl_header [ 1024 ]  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-07-08 14:29:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  std : : string  GetGLSLVersionString ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GLSL_VERSION  v  =  g_ogl_config . eSupportedGLSLVersion ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									switch ( v ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  GLSLES_300 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  " #version 300 es " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  GLSLES_310 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  " #version 310 es " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  GLSL_130 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  " #version 130 " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  GLSL_140 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  " #version 140 " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  GLSL_150 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  " #version 150 " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Shouldn't ever hit this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  " #version ERROR " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  SHADER : : SetProgramVariables ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-07 00:29:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Bind UBO and texture samplers
 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! g_ActiveConfig . backend_info . bSupportsBindingLayout ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 11:08:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-07 00:29:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// glsl shader must be bind to set samplers if we don't support binding layout
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										Bind ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										GLint  PSBlock_id  =  glGetUniformBlockIndex ( glprogid ,  " PSBlock " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GLint  VSBlock_id  =  glGetUniformBlockIndex ( glprogid ,  " VSBlock " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( PSBlock_id  ! =  - 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											glUniformBlockBinding ( glprogid ,  PSBlock_id ,  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( VSBlock_id  ! =  - 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											glUniformBlockBinding ( glprogid ,  VSBlock_id ,  2 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-06-07 00:29:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Bind Texture Sampler
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										for  ( int  a  =  0 ;  a  < =  9 ;  + + a ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											char  name [ 8 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											snprintf ( name ,  8 ,  " samp%d " ,  a ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-06-07 00:29:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											// Still need to get sampler locations since we aren't binding them statically in the shaders
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											int  loc  =  glGetUniformLocation ( glprogid ,  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( loc  ! =  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												glUniform1i ( loc ,  a ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-31 02:34:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  SHADER : : SetProgramBindings ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-31 02:34:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-14 20:00:33 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( g_ActiveConfig . backend_info . bSupportsDualSourceBlend ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-31 02:34:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-02 16:56:08 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// So we do support extended blending
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// So we need to set a few more things here.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// Bind our out locations
 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glBindFragDataLocationIndexed ( glprogid ,  0 ,  0 ,  " ocol0 " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glBindFragDataLocationIndexed ( glprogid ,  0 ,  1 ,  " ocol1 " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-20 14:00:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-31 02:34:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Need to set some attribute locations
 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_POSITION_ATTRIB ,  " rawpos " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-24 02:30:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_POSMTX_ATTRIB ,    " posmtx " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_COLOR0_ATTRIB ,    " color0 " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_COLOR1_ATTRIB ,    " color1 " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_NORM0_ATTRIB ,     " rawnorm0 " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_NORM1_ATTRIB ,     " rawnorm1 " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glBindAttribLocation ( glprogid ,  SHADER_NORM2_ATTRIB ,     " rawnorm2 " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( int  i  =  0 ;  i  <  8 ;  i + + ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-14 22:59:08 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										char  attrib_name [ 8 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( attrib_name ,  8 ,  " tex%d " ,  i ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glBindAttribLocation ( glprogid ,  SHADER_TEXTURE0_ATTRIB + i ,  attrib_name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-14 22:59:08 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 11:14:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  SHADER : : Bind ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( CurrentProgram  ! =  glprogid ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-02 20:11:46 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										INCSTAT ( stats . thisFrame . numShaderChanges ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glUseProgram ( glprogid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										CurrentProgram  =  glprogid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  ProgramShaderCache : : UploadConstants ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( PixelShaderManager : : dirty  | |  VertexShaderManager : : dirty ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-07 17:19:47 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										auto  buffer  =  s_buffer - > Map ( s_ubo_buffer_size ,  s_ubo_align ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 18:02:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										memcpy ( buffer . first , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											& PixelShaderManager : : constants ,  sizeof ( PixelShaderConstants ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 18:02:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										memcpy ( buffer . first  +  ROUND_UP ( sizeof ( PixelShaderConstants ) ,  s_ubo_align ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											& VertexShaderManager : : constants ,  sizeof ( VertexShaderConstants ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-16 11:27:58 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										s_buffer - > Unmap ( s_ubo_buffer_size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glBindBufferRange ( GL_UNIFORM_BUFFER ,  1 ,  s_buffer - > m_buffer ,  buffer . second , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													sizeof ( PixelShaderConstants ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glBindBufferRange ( GL_UNIFORM_BUFFER ,  2 ,  s_buffer - > m_buffer ,  buffer . second  +  ROUND_UP ( sizeof ( PixelShaderConstants ) ,  s_ubo_align ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													sizeof ( VertexShaderConstants ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										PixelShaderManager : : dirty  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										VertexShaderManager : : dirty  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-05-23 21:07:01 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ADDSTAT ( stats . thisFrame . bytesUniformStreamed ,  s_ubo_buffer_size ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 04:32:57 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								GLuint  ProgramShaderCache : : GetCurrentProgram ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  CurrentProgram ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:15:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								SHADER *  ProgramShaderCache : : SetShader ( DSTALPHA_MODE  dstAlphaMode ,  u32  components ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									SHADERUID  uid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GetShaderId ( & uid ,  dstAlphaMode ,  components ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-26 22:16:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Check if the shader is already set
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( last_entry ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( uid  = =  last_uid ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											GFX_DEBUGGER_PAUSE_AT ( NEXT_PIXEL_SHADER_CHANGE ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											last_entry - > shader . Bind ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  & last_entry - > shader ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 20:33:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									last_uid  =  uid ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 20:33:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Check if shader is already in cache
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									PCache : : iterator  iter  =  pshaders . find ( uid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( iter  ! =  pshaders . end ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 04:32:57 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										PCacheEntry  * entry  =  & iter - > second ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										last_entry  =  entry ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GFX_DEBUGGER_PAUSE_AT ( NEXT_PIXEL_SHADER_CHANGE ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										last_entry - > shader . Bind ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  & last_entry - > shader ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 20:33:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Make an entry in the table
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									PCacheEntry &  newentry  =  pshaders [ uid ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									last_entry  =  & newentry ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									newentry . in_cache  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 20:33:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-26 22:16:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									VertexShaderCode  vcode ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									PixelShaderCode  pcode ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GenerateVertexShaderCode ( vcode ,  components ,  API_OPENGL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GeneratePixelShaderCode ( pcode ,  dstAlphaMode ,  API_OPENGL ,  components ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 20:33:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( g_ActiveConfig . bEnableShaderDebugging ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-26 22:16:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										newentry . shader . strvprog  =  vcode . GetBuffer ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										newentry . shader . strpprog  =  pcode . GetBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 05:13:05 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 11:08:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# if defined(_DEBUG) || defined(DEBUGFAST) 
 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( g_ActiveConfig . iLog  &  CONF_SAVESHADERS ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										static  int  counter  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										std : : string  filename  =   StringFromFormat ( " %svs_%04i.txt " ,  File : : GetUserPath ( D_DUMP_IDX ) . c_str ( ) ,  counter + + ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										SaveData ( filename ,  vcode . GetBuffer ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										filename  =  StringFromFormat ( " %sps_%04i.txt " ,  File : : GetUserPath ( D_DUMP_IDX ) . c_str ( ) ,  counter + + ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										SaveData ( filename ,  pcode . GetBuffer ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# endif 
 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! CompileShader ( newentry . shader ,  vcode . GetBuffer ( ) ,  pcode . GetBuffer ( ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										GFX_DEBUGGER_PAUSE_AT ( NEXT_ERROR ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-09 21:14:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									INCSTAT ( stats . numPixelShadersCreated ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									SETSTAT ( stats . numPixelShadersAlive ,  pshaders . size ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GFX_DEBUGGER_PAUSE_AT ( NEXT_PIXEL_SHADER_CHANGE ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									last_entry - > shader . Bind ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  & last_entry - > shader ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:15:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								bool  ProgramShaderCache : : CompileShader ( SHADER &  shader ,  const  char *  vcode ,  const  char *  pcode ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GLuint  vsid  =  CompileSingleShader ( GL_VERTEX_SHADER ,  vcode ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GLuint  psid  =  CompileSingleShader ( GL_FRAGMENT_SHADER ,  pcode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 20:33:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! vsid  | |  ! psid ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glDeleteShader ( vsid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glDeleteShader ( psid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-09-10 12:17:38 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLuint  pid  =  shader . glprogid  =  glCreateProgram ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glAttachShader ( pid ,  vsid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glAttachShader ( pid ,  psid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-25 15:14:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( g_ogl_config . bSupportsGLSLCache ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glProgramParameteri ( pid ,  GL_PROGRAM_BINARY_RETRIEVABLE_HINT ,  GL_TRUE ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									shader . SetProgramBindings ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glLinkProgram ( pid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// original shaders aren't needed any more
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glDeleteShader ( vsid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glDeleteShader ( psid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:26:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLint  linkStatus ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glGetProgramiv ( pid ,  GL_LINK_STATUS ,  & linkStatus ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-07 12:47:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLsizei  length  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glGetProgramiv ( pid ,  GL_INFO_LOG_LENGTH ,  & length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:26:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( linkStatus  ! =  GL_TRUE  | |  ( length  >  1  & &  DEBUG_GLSL ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-07 12:47:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GLsizei  charsWritten ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GLchar *  infoLog  =  new  GLchar [ length ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glGetProgramInfoLog ( pid ,  length ,  & charsWritten ,  infoLog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-07 12:47:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ERROR_LOG ( VIDEO ,  " Program info log: \n %s " ,  infoLog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										std : : string  filename  =  StringFromFormat ( " %sbad_p_%d.txt " ,  File : : GetUserPath ( D_DUMP_IDX ) . c_str ( ) ,  num_failures + + ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:37:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										std : : ofstream  file ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										OpenFStream ( file ,  filename ,  std : : ios_base : : out ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-16 21:05:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										file  < <  s_glsl_header  < <  vcode  < <  s_glsl_header  < <  pcode  < <  infoLog ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:37:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										file . close ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( linkStatus  ! =  GL_TRUE ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-18 11:47:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											PanicAlert ( " Failed to link shaders! \n This usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series. \n \n If you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums. \n \n Debug info (%s, %s, %s): \n %s " , 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												filename . c_str ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-18 11:47:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												g_ogl_config . gl_vendor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												g_ogl_config . gl_renderer , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												g_ogl_config . gl_version , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												infoLog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:37:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										delete  [ ]  infoLog ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-07 12:47:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( linkStatus  ! =  GL_TRUE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// Compile failed
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ERROR_LOG ( VIDEO ,  " Program linking failed; see info log " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// Don't try to use this shader
 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glDeleteProgram ( pid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-07 12:47:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									shader . SetProgramVariables ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								GLuint  ProgramShaderCache : : CompileSingleShader ( GLuint  type ,  const  char *  code ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLuint  result  =  glCreateShader ( type ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * src [ ]  =  { s_glsl_header ,  code } ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-09 21:14:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glShaderSource ( result ,  2 ,  src ,  nullptr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glCompileShader ( result ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:26:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLint  compileStatus ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glGetShaderiv ( result ,  GL_COMPILE_STATUS ,  & compileStatus ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLsizei  length  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glGetShaderiv ( result ,  GL_INFO_LOG_LENGTH ,  & length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-18 10:24:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( DriverDetails : : HasBug ( DriverDetails : : BUG_BROKENINFOLOG ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										length  =  1024 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:26:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( compileStatus  ! =  GL_TRUE  | |  ( length  >  1  & &  DEBUG_GLSL ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GLsizei  charsWritten ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GLchar *  infoLog  =  new  GLchar [ length ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glGetShaderInfoLog ( result ,  length ,  & charsWritten ,  infoLog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 22:21:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ERROR_LOG ( VIDEO ,  " %s Shader info log: \n %s " ,  type = = GL_VERTEX_SHADER  ?  " VS "  :  " PS " ,  infoLog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										std : : string  filename  =  StringFromFormat ( " %sbad_%s_%04i.txt " , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											File : : GetUserPath ( D_DUMP_IDX ) . c_str ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											type = = GL_VERTEX_SHADER  ?  " vs "  :  " ps " , 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-04 23:30:13 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											num_failures + + ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:37:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										std : : ofstream  file ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										OpenFStream ( file ,  filename ,  std : : ios_base : : out ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-16 21:05:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										file  < <  s_glsl_header  < <  code  < <  infoLog ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-07 20:37:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										file . close ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( compileStatus  ! =  GL_TRUE ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-18 11:47:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											PanicAlert ( " Failed to compile %s shader! \n This usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series. \n \n If you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums. \n \n Debug info (%s, %s, %s): \n %s " , 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												type  = =  GL_VERTEX_SHADER  ?  " vertex "  :  " pixel " , 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												filename . c_str ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-18 11:47:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												g_ogl_config . gl_vendor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												g_ogl_config . gl_renderer , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												g_ogl_config . gl_version , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												infoLog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										delete [ ]  infoLog ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( compileStatus  ! =  GL_TRUE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// Compile failed
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ERROR_LOG ( VIDEO ,  " Shader compilation failed; see info log " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// Don't try to use this shader
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glDeleteShader ( result ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-26 04:53:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 14:54:44 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  ProgramShaderCache : : GetShaderId ( SHADERUID *  uid ,  DSTALPHA_MODE  dstAlphaMode ,  u32  components ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-26 22:16:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GetPixelShaderUid ( uid - > puid ,  dstAlphaMode ,  API_OPENGL ,  components ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GetVertexShaderUid ( uid - > vuid ,  components ,  API_OPENGL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-29 21:00:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( g_ActiveConfig . bEnableShaderDebugging ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										PixelShaderCode  pcode ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GeneratePixelShaderCode ( pcode ,  dstAlphaMode ,  API_OPENGL ,  components ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										pixel_uid_checker . AddToIndexAndCheck ( pcode ,  uid - > puid ,  " Pixel " ,  " p " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										VertexShaderCode  vcode ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										GenerateVertexShaderCode ( vcode ,  components ,  API_OPENGL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										vertex_uid_checker . AddToIndexAndCheck ( vcode ,  uid - > vuid ,  " Vertex " ,  " v " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-29 14:54:44 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ProgramShaderCache : : PCacheEntry  ProgramShaderCache : : GetShaderProgram ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  * last_entry ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  ProgramShaderCache : : Init ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// We have to get the UBO alignment here because
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// if we generate a buffer that isn't aligned
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// then the UBO will fail.
 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glGetIntegerv ( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT ,  & s_ubo_align ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s_ubo_buffer_size  =  ROUND_UP ( sizeof ( PixelShaderConstants ) ,  s_ubo_align )  +  ROUND_UP ( sizeof ( VertexShaderConstants ) ,  s_ubo_align ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// We multiply by *4*4 because we need to get down to basic machine units.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// So multiply by four to get how many floats we have from vec4s
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Then once more to get bytes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									s_buffer  =  StreamBuffer : : Create ( GL_UNIFORM_BUFFER ,  UBO_LENGTH ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Read our shader cache, only if supported
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 16:45:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( g_ogl_config . bSupportsGLSLCache  & &  ! g_Config . bEnableShaderDebugging ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 04:19:11 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										GLint  Supported ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										glGetIntegerv ( GL_NUM_PROGRAM_BINARY_FORMATS ,  & Supported ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! Supported ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ERROR_LOG ( VIDEO ,  " GL_ARB_get_program_binary is supported, but no binary format is known. So disable shader cache. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-25 15:14:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											g_ogl_config . bSupportsGLSLCache  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:50:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! File : : Exists ( File : : GetUserPath ( D_SHADERCACHE_IDX ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-12 15:33:41 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												File : : CreateDir ( File : : GetUserPath ( D_SHADERCACHE_IDX ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-06-03 01:08:54 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											std : : string  cache_filename  =  StringFromFormat ( " %sogl-%s-shaders.cache " ,  File : : GetUserPath ( D_SHADERCACHE_IDX ) . c_str ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												SConfig : : GetInstance ( ) . m_LocalCoreStartupParameter . m_strUniqueID . c_str ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ProgramShaderCacheInserter  inserter ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											g_program_disk_cache . OpenAndRead ( cache_filename ,  inserter ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										SETSTAT ( stats . numPixelShadersAlive ,  pshaders . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 04:19:11 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									CreateHeader ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-15 14:22:40 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									CurrentProgram  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-09 21:14:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									last_entry  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  ProgramShaderCache : : Shutdown ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// store all shaders in cache on disk
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 16:45:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( g_ogl_config . bSupportsGLSLCache  & &  ! g_Config . bEnableShaderDebugging ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 11:08:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 06:25:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										for  ( auto &  entry  :  pshaders ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 10:27:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( entry . second . in_cache ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 06:25:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											GLint  binary_size ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 06:25:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											glGetProgramiv ( entry . second . shader . glprogid ,  GL_PROGRAM_BINARY_LENGTH ,  & binary_size ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-11 00:30:55 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! binary_size ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 06:25:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											u8  * data  =  new  u8 [ binary_size + sizeof ( GLenum ) ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											u8  * binary  =  data  +  sizeof ( GLenum ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											GLenum  * prog_format  =  ( GLenum * ) data ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-09 21:14:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											glGetProgramBinary ( entry . second . shader . glprogid ,  binary_size ,  nullptr ,  prog_format ,  binary ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 06:25:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											g_program_disk_cache . Append ( entry . first ,  data ,  binary_size + sizeof ( GLenum ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											delete  [ ]  data ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 10:27:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-11 04:11:57 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										g_program_disk_cache . Sync ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										g_program_disk_cache . Close ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-15 17:10:43 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glUseProgram ( 0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 06:25:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( auto &  entry  :  pshaders ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										entry . second . Destroy ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									pshaders . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-04-29 21:00:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									pixel_uid_checker . Invalidate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									vertex_uid_checker . Invalidate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									delete  s_buffer ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-09 21:14:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s_buffer  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-30 21:00:21 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  ProgramShaderCache : : CreateHeader ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-08 14:50:58 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									GLSL_VERSION  v  =  g_ogl_config . eSupportedGLSLVersion ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									snprintf ( s_glsl_header ,  sizeof ( s_glsl_header ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-06 03:12:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n "  // ubo
 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-21 11:48:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n "  // early-z
 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-05 10:38:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n "  // 420pack
 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-01 12:45:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n "  // msaa
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" %s \n "  // sample shading
 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-07 00:29:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n "  // Sampler binding
 
							 
						 
					
						
							
								
									
										
										
										
											2014-11-13 23:26:49 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n "  // storage buffer
 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Precision defines for GLSL ES
 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-06 03:12:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-07 00:52:34 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-06 03:12:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Silly differences
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define float2 vec2 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define float3 vec3 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define float4 vec4 \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-14 15:06:47 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" #define uint2 uvec2 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define uint3 uvec3 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define uint4 uvec4 \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-25 15:49:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" #define int2 ivec2 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define int3 ivec3 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define int4 ivec4 \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-18 07:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// hlsl to glsl function translation
 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-18 12:42:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" #define frac fract \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" #define lerp mix \n " 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-18 07:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-26 12:48:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Terrible hacks, look at DriverDetails.h
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" %s \n "  // replace textureSize as constant
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" %s \n "  // wipe out all centroid usages
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-19 17:30:39 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  GetGLSLVersionString ( ) . c_str ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 16:38:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  v < GLSL_140  ?  " #extension GL_ARB_uniform_buffer_object : enable "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-21 11:48:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  g_ActiveConfig . backend_info . bSupportsEarlyZ  ?  " #extension GL_ARB_shader_image_load_store : enable "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  ( g_ActiveConfig . backend_info . bSupportsBindingLayout  & &  v  <  GLSLES_310 )  ?  " #extension GL_ARB_shading_language_420pack : enable "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-01 12:45:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  ( g_ogl_config . bSupportsMSAA  & &  v  <  GLSL_150 )  ?  " #extension GL_ARB_texture_multisample : enable "  :  " " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										,  ( g_ogl_config . bSupportSampleShading )  ?  " #extension GL_ARB_sample_shading : enable "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-07 00:29:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  g_ActiveConfig . backend_info . bSupportsBindingLayout  ?  " #define SAMPLER_BINDING(x) layout(binding = x) "  :  " #define SAMPLER_BINDING(x) " 
							 
						 
					
						
							
								
									
										
										
										
											2014-11-13 23:26:49 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  g_ActiveConfig . backend_info . bSupportsBBox  ?  " #extension GL_ARB_shader_storage_buffer_object : enable "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-30 13:58:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  v > = GLSLES_300  ?  " precision highp float; "  :  " " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										,  v > = GLSLES_300  ?  " precision highp int; "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-19 17:30:39 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  DriverDetails : : HasBug ( DriverDetails : : BUG_BROKENTEXTURESIZE )  ?  " #define textureSize(x, y) ivec2(1, 1) "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-25 15:52:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										,  DriverDetails : : HasBug ( DriverDetails : : BUG_BROKENCENTROID )  ?  " #define centroid "  :  " " 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 21:34:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:15:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  ProgramShaderCache : : ProgramShaderCacheInserter : : Read ( const  SHADERUID &  key ,  const  u8 *  value ,  u32  value_size ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  u8  * binary  =  value + sizeof ( GLenum ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GLenum  * prog_format  =  ( GLenum * ) value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GLint  binary_size  =  value_size - sizeof ( GLenum ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 01:23:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									PCacheEntry  entry ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									entry . in_cache  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									entry . shader . glprogid  =  glCreateProgram ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									glProgramBinary ( entry . shader . glprogid ,  * prog_format ,  binary ,  binary_size ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									GLint  success ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									glGetProgramiv ( entry . shader . glprogid ,  GL_LINK_STATUS ,  & success ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( success ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										pshaders [ key ]  =  entry ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										entry . shader . SetProgramVariables ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 16:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										glDeleteProgram ( entry . shader . glprogid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-15 14:09:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-13 13:12:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-12-26 00:15:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // namespace OGL