Mercurial > love-experiments
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1389:ac121b0d7258 | 1390:6f1ac9fc80da |
|---|---|
| 1359 } | 1359 } |
| 1360 return table_concat(pixelcodes, "\n") | 1360 return table_concat(pixelcodes, "\n") |
| 1361 end | 1361 end |
| 1362 | 1362 |
| 1363 function love.graphics._shaderCodeToGLSL(vertexcode, pixelcode) | 1363 function love.graphics._shaderCodeToGLSL(vertexcode, pixelcode) |
| 1364 local vertexarg, pixelarg = vertexcode, pixelcode | |
| 1365 | |
| 1364 if vertexcode then | 1366 if vertexcode then |
| 1365 local s = vertexcode:gsub("\r\n\t", " ") | 1367 local s = vertexcode:gsub("\r\n\t", " ") |
| 1366 s = s:gsub("%w+(%s+)%(", "") | 1368 s = s:gsub("(%w+)(%s+)%(", "%1(") |
| 1367 if s:match("vec4%s*effect%(") then | 1369 if s:match("vec4%s*effect%(") then |
| 1368 pixelcode = vertexcode -- first argument contains pixel shader code | 1370 pixelcode = vertexcode -- first argument contains pixel shader code |
| 1369 end | 1371 end |
| 1370 if not s:match("vec4%s*position%(") then | 1372 if not s:match("vec4%s*position%(") then |
| 1371 vertexcode = nil -- first argument doesn't contain vertex shader code | 1373 vertexcode = nil -- first argument doesn't contain vertex shader code |
| 1372 end | 1374 end |
| 1373 end | 1375 end |
| 1376 | |
| 1374 if pixelcode then | 1377 if pixelcode then |
| 1375 local s = pixelcode:gsub("\r\n\t", " ") | 1378 local s = pixelcode:gsub("\r\n\t", " ") |
| 1376 s = s:gsub("%w+(%s+)%(", "") | 1379 s = s:gsub("(%w+)(%s+)%(", "%1(") |
| 1377 if s:match("vec4%s*position%(") then | 1380 if s:match("vec4%s*position%(") then |
| 1378 vertexcode = pixelcode -- second argument contains vertex shader code | 1381 vertexcode = pixelcode -- second argument contains vertex shader code |
| 1379 end | 1382 end |
| 1380 if not s:match("vec4%s*effect%(") then | 1383 if not s:match("vec4%s*effect%(") then |
| 1381 pixelcode = nil -- second argument doesn't contain pixel shader code | 1384 pixelcode = nil -- second argument doesn't contain pixel shader code |
| 1383 end | 1386 end |
| 1384 | 1387 |
| 1385 if vertexcode then | 1388 if vertexcode then |
| 1386 vertexcode = createVertexCode(vertexcode) | 1389 vertexcode = createVertexCode(vertexcode) |
| 1387 end | 1390 end |
| 1391 | |
| 1388 if pixelcode then | 1392 if pixelcode then |
| 1389 pixelcode = createPixelCode(pixelcode) | 1393 pixelcode = createPixelCode(pixelcode) |
| 1390 end | 1394 end |
| 1391 | 1395 |
| 1392 return vertexcode, pixelcode | 1396 return vertexcode, pixelcode |
| 1462 end | 1466 end |
| 1463 end | 1467 end |
| 1464 | 1468 |
| 1465 local newShader = love.graphics.newShader | 1469 local newShader = love.graphics.newShader |
| 1466 function love.graphics.newShader(vertexcode, pixelcode) | 1470 function love.graphics.newShader(vertexcode, pixelcode) |
| 1467 love.graphics.newShader = function(vertexcode, pixelcode) | 1471 love.graphics.newShader = newShader |
| 1468 if love.filesystem then | 1472 |
| 1469 if vertexcode and love.filesystem.exists(vertexcode) then | 1473 local shader = newShader(vertexcode, pixelcode) |
| 1470 vertexcode = love.filesystem.read(vertexcode) | |
| 1471 end | |
| 1472 if pixelcode and love.filesystem.exists(pixelcode) then | |
| 1473 pixelcode = love.filesystem.read(pixelcode) | |
| 1474 end | |
| 1475 end | |
| 1476 return newShader(vertexcode, pixelcode) | |
| 1477 end | |
| 1478 | |
| 1479 local shader = love.graphics.newShader(vertexcode, pixelcode) | |
| 1480 local meta = getmetatable(shader) | 1474 local meta = getmetatable(shader) |
| 1481 meta.send = shader_dispatch_send | 1475 meta.send = shader_dispatch_send |
| 1482 meta.sendBoolean = meta.sendFloat | 1476 meta.sendBoolean = meta.sendFloat |
| 1483 return shader | 1477 return shader |
| 1484 end | 1478 end |
