diff src/scripts/graphics.lua @ 1390:6f1ac9fc80da

Improved error handling and error messages when love.graphics.newShader fails
author Alex Szpakowski <slime73@gmail.com>
date Mon, 18 Mar 2013 22:55:41 -0300
parents 2f09d864fbed
children a742f6edaf92
line wrap: on
line diff
--- a/src/scripts/graphics.lua	Mon Mar 18 16:15:21 2013 -0300
+++ b/src/scripts/graphics.lua	Mon Mar 18 22:55:41 2013 -0300
@@ -1361,9 +1361,11 @@
 	end
 
 	function love.graphics._shaderCodeToGLSL(vertexcode, pixelcode)
+		local vertexarg, pixelarg = vertexcode, pixelcode
+
 		if vertexcode then
 			local s = vertexcode:gsub("\r\n\t", " ")
-			s = s:gsub("%w+(%s+)%(", "")
+			s = s:gsub("(%w+)(%s+)%(", "%1(")
 			if s:match("vec4%s*effect%(") then
 				pixelcode = vertexcode -- first argument contains pixel shader code
 			end
@@ -1371,9 +1373,10 @@
 				vertexcode = nil -- first argument doesn't contain vertex shader code
 			end
 		end
+
 		if pixelcode then
 			local s = pixelcode:gsub("\r\n\t", " ")
-			s = s:gsub("%w+(%s+)%(", "")
+			s = s:gsub("(%w+)(%s+)%(", "%1(")
 			if s:match("vec4%s*position%(") then
 				vertexcode = pixelcode -- second argument contains vertex shader code
 			end
@@ -1385,6 +1388,7 @@
 		if vertexcode then
 			vertexcode = createVertexCode(vertexcode)
 		end
+
 		if pixelcode then
 			pixelcode = createPixelCode(pixelcode)
 		end
@@ -1464,19 +1468,9 @@
 
 	local newShader = love.graphics.newShader
 	function love.graphics.newShader(vertexcode, pixelcode)
-		love.graphics.newShader = function(vertexcode, pixelcode)
-			if love.filesystem then
-				if vertexcode and love.filesystem.exists(vertexcode) then
-					vertexcode = love.filesystem.read(vertexcode)
-				end
-				if pixelcode and love.filesystem.exists(pixelcode) then
-					pixelcode = love.filesystem.read(pixelcode)
-				end
-			end
-			return newShader(vertexcode, pixelcode)
-		end
+		love.graphics.newShader = newShader
 
-		local shader = love.graphics.newShader(vertexcode, pixelcode)
+		local shader = newShader(vertexcode, pixelcode)
 		local meta = getmetatable(shader)
 		meta.send = shader_dispatch_send
 		meta.sendBoolean = meta.sendFloat