Browse Source

Shader fixes.

Mark Sibly 7 years ago
parent
commit
a2c1f54e04

+ 30 - 15
modules/mojo/graphics/shader.monkey2

@@ -211,7 +211,7 @@ Class Shader
 		
 		
 			def=def.Trim()
 			def=def.Trim()
 			If Not def Continue
 			If Not def Continue
-			
+
 			if Not def.Contains( " " ) def+=" 1"
 			if Not def.Contains( " " ) def+=" 1"
 			
 			
 			_defs+="#define "+def+"~n"
 			_defs+="#define "+def+"~n"
@@ -346,15 +346,16 @@ Class Shader
 	'
 	'
 	Method SplitSource:String[]( source:String )
 	Method SplitSource:String[]( source:String )
 		
 		
-		Local i0:=_source.Find( "~n//@vertex" )
+		Local i0:=source.Find( "~n//@vertex" )
 		If i0=-1 
 		If i0=-1 
 			Print "Shader source:~n"+source
 			Print "Shader source:~n"+source
-			Assert( False,"Can't find //@vertex chunk" )
+			RuntimeError( "Can't find //@vertex chunk" )
 		Endif
 		Endif
-		Local i1:=source.Find( "~n//@fragment" )
+		
+		Local i1:=source.Find( "~n//@fragment",i0+1 )
 		If i1=-1
 		If i1=-1
 			Print "Shader source:~n"+source
 			Print "Shader source:~n"+source
-			Assert( False,"Can't find //@fragment chunk" )
+			RuntimeError( "Can't find //@fragment chunk" )
 		Endif
 		Endif
 			
 			
 		Local cs:=source.Slice( 0,i0 )+"~n"
 		Local cs:=source.Slice( 0,i0 )+"~n"
@@ -364,23 +365,37 @@ Class Shader
 		Local chunks:=New String[3]
 		Local chunks:=New String[3]
 		
 		
 		'Find //@imports in common section
 		'Find //@imports in common section
-		Repeat
-			Local i:=cs.Find( "~n//@import" )
-			If i=-1 Exit
 		
 		
-			Local p:=cs.Slice( 10 ).Trim()
-			If Not p.StartsWith( "~q" ) Or Not p.EndsWith( "~q" )
+		i0=0
+		
+		Repeat
+			i0=cs.Find( "~n//@import",i0 )
+			If i0=-1 Exit
+			
+			Local i1:=cs.Find( "~n",i0+1 )
+			If i1=-1 RuntimeError( "Malformed @import directive in shader" )
+				
+			Local f:=cs.Slice( i0+11,i1 ).Trim()
+			i0=i1
+			
+			If Not f.StartsWith( "~q" ) Or Not f.EndsWith( "~q" )
+				RuntimeError( "Malformed @import directive in shader" )
 				Exit
 				Exit
 			Endif
 			Endif
-			p=p.Slice(1,-1)
-			Local s:=LoadString( "asset::shaders/"+p )
-			If Not s Exit
-		
-			Local tchunks:=SplitSource( s )
+			
+			f=f.Slice(1,-1)
+			Local path:="asset::shaders/imports/"+f+".glsl"
+			Local src:=LoadString( path )
+			Assert( src,"Can't import shader from "+path )
+			
+			Local tchunks:=SplitSource( src )
+			
 			chunks[0]+=tchunks[0]
 			chunks[0]+=tchunks[0]
 			chunks[1]+=tchunks[1]
 			chunks[1]+=tchunks[1]
 			chunks[2]+=tchunks[2]
 			chunks[2]+=tchunks[2]
 			
 			
+'			Print "Imported "+f
+		
 		Forever
 		Forever
 		
 		
 		chunks[0]+=cs
 		chunks[0]+=cs

+ 1 - 1
modules/mojo/graphics/texture.monkey2

@@ -406,7 +406,7 @@ Class Texture Extends Resource
 	Method Modified( r:Recti )
 	Method Modified( r:Recti )
 		
 		
 		If _managed 
 		If _managed 
-			Print "Texture Modified - Update managed"
+'			Print "Texture Modified - Update managed"
 			glReadPixels( r.X,r.Y,r.Width,r.Height,GL_RGBA,GL_UNSIGNED_BYTE,_managed.PixelPtr( r.X,r.Y ) )
 			glReadPixels( r.X,r.Y,r.Width,r.Height,GL_RGBA,GL_UNSIGNED_BYTE,_managed.PixelPtr( r.X,r.Y ) )
 		Endif
 		Endif
 
 

+ 1 - 2
modules/mojo/graphics/uniformblock.monkey2

@@ -230,7 +230,6 @@ Class UniformBlock Extends Resource
 	End
 	End
 
 
 	Method GetTexture:Texture( uniform:String )
 	Method GetTexture:Texture( uniform:String )
-		
 		Local id:=GetUniformId( uniform,Type.Texture )
 		Local id:=GetUniformId( uniform,Type.Texture )
 		Return _uniforms[id].texture
 		Return _uniforms[id].texture
 	End
 	End
@@ -297,7 +296,7 @@ Class UniformBlock Extends Resource
 
 
 #If __DEBUG__		
 #If __DEBUG__		
 		Assert( id,"Uniform '"+name+"' not found" )
 		Assert( id,"Uniform '"+name+"' not found" )
-		Assert( _uniforms[id].type,"Uniform '"+name+"' does not found in UniformBlock" )
+		Assert( _uniforms[id].type,"Uniform '"+name+"' not found in UniformBlock" )
 		Assert( _uniforms[id].type=type,"Uniform '"+name+"' has incorrect type '"+_typenames[_uniforms[id].type]="', expecting type '"+_typenames[type]+"'" )
 		Assert( _uniforms[id].type=type,"Uniform '"+name+"' has incorrect type '"+_typenames[_uniforms[id].type]="', expecting type '"+_typenames[type]+"'" )
 #endif
 #endif
 		Return id
 		Return id