Mercurial > love-experiments
comparison src/scripts/graphics.lua @ 1401:bee3f7b0dca0 MRTs
fixed canvas:clear() when multi-canvas rendering is active, changed some names and wording
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Tue, 26 Mar 2013 04:58:43 -0300 |
| parents | fa3eabb3602a |
| children | a96b4e6c9a7e |
comparison
equal
deleted
inserted
replaced
| 1400:3462663e4d83 | 1401:bee3f7b0dca0 |
|---|---|
| 1336 // fix crashing issue in OSX when _tex0_ is unused within effect() | 1336 // fix crashing issue in OSX when _tex0_ is unused within effect() |
| 1337 float dummy = texture2D(_tex0_, vec2(.5)).r; | 1337 float dummy = texture2D(_tex0_, vec2(.5)).r; |
| 1338 gl_FragColor = effect(VaryingColor, _tex0_, VaryingTexCoord.st, gl_FragCoord.xy); | 1338 gl_FragColor = effect(VaryingColor, _tex0_, VaryingTexCoord.st, gl_FragCoord.xy); |
| 1339 }]], | 1339 }]], |
| 1340 | 1340 |
| 1341 FOOTER_MRT = [[ | 1341 FOOTER_MULTI_CANVAS = [[ |
| 1342 void main() { | 1342 void main() { |
| 1343 // fix crashing issue in OSX when _tex0_ is unused within effect() | 1343 // fix crashing issue in OSX when _tex0_ is unused within effect() |
| 1344 float dummy = texture2D(_tex0_, vec2(.5)).r; | 1344 float dummy = texture2D(_tex0_, vec2(.5)).r; |
| 1345 effects(VaryingColor, _tex0_, VaryingTexCoord.st, gl_FragCoord.xy); | 1345 effects(VaryingColor, _tex0_, VaryingTexCoord.st, gl_FragCoord.xy); |
| 1346 }]], | 1346 }]], |
| 1355 GLSL_VERTEX.FOOTER, | 1355 GLSL_VERTEX.FOOTER, |
| 1356 } | 1356 } |
| 1357 return table_concat(vertexcodes, "\n") | 1357 return table_concat(vertexcodes, "\n") |
| 1358 end | 1358 end |
| 1359 | 1359 |
| 1360 local function createPixelCode(pixelcode, is_mrt) | 1360 local function createPixelCode(pixelcode, is_multicanvas) |
| 1361 local pixelcodes = { | 1361 local pixelcodes = { |
| 1362 GLSL_VERSION, | 1362 GLSL_VERSION, |
| 1363 GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, | 1363 GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, |
| 1364 "#line 0", | 1364 "#line 0", |
| 1365 pixelcode, | 1365 pixelcode, |
| 1366 is_mrt and GLSL_PIXEL.FOOTER_MRT or GLSL_PIXEL.FOOTER, | 1366 is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, |
| 1367 } | 1367 } |
| 1368 return table_concat(pixelcodes, "\n") | 1368 return table_concat(pixelcodes, "\n") |
| 1369 end | 1369 end |
| 1370 | 1370 |
| 1371 local function isVertexCode(code) | 1371 local function isVertexCode(code) |
| 1373 end | 1373 end |
| 1374 | 1374 |
| 1375 local function isPixelCode(code) | 1375 local function isPixelCode(code) |
| 1376 if code:match("vec4%s*effect%(") then | 1376 if code:match("vec4%s*effect%(") then |
| 1377 return true | 1377 return true |
| 1378 elseif code:match("void%s*effects%(") then -- multiple render targets (MRT) | 1378 elseif code:match("void%s*effects%(") then -- render to multiple canvases simultaniously |
| 1379 return true, true | 1379 return true, true |
| 1380 else | 1380 else |
| 1381 return false | 1381 return false |
| 1382 end | 1382 end |
| 1383 end | 1383 end |
| 1384 | 1384 |
| 1385 function love.graphics._shaderCodeToGLSL(arg1, arg2) | 1385 function love.graphics._shaderCodeToGLSL(arg1, arg2) |
| 1386 local vertexcode, pixelcode | 1386 local vertexcode, pixelcode |
| 1387 local is_mrt = false -- whether pixel code has "effects" function instead of "effect" | 1387 local is_multicanvas = false -- whether pixel code has "effects" function instead of "effect" |
| 1388 | 1388 |
| 1389 if arg1 then | 1389 if arg1 then |
| 1390 local s = arg1:gsub("\r\n\t", " ") -- convert whitespace to spaces for parsing | 1390 local s = arg1:gsub("\r\n\t", " ") -- convert whitespace to spaces for parsing |
| 1391 s = s:gsub("(%w+)(%s+)%(", "%1(") -- convert "func ()" to "func()" | 1391 s = s:gsub("(%w+)(%s+)%(", "%1(") -- convert "func ()" to "func()" |
| 1392 | 1392 |
| 1393 if isVertexCode(s) then | 1393 if isVertexCode(s) then |
| 1394 vertexcode = arg1 -- first arg contains vertex shader code | 1394 vertexcode = arg1 -- first arg contains vertex shader code |
| 1395 end | 1395 end |
| 1396 | 1396 |
| 1397 local ispixel, isMRT = isPixelCode(s) | 1397 local ispixel, isMultiCanvas = isPixelCode(s) |
| 1398 if ispixel then | 1398 if ispixel then |
| 1399 pixelcode = arg1 -- first arg contains pixel shader code | 1399 pixelcode = arg1 -- first arg contains pixel shader code |
| 1400 is_mrt = isMRT | 1400 is_multicanvas = isMultiCanvas |
| 1401 end | 1401 end |
| 1402 end | 1402 end |
| 1403 | 1403 |
| 1404 if arg2 then | 1404 if arg2 then |
| 1405 local s = arg2:gsub("\r\n\t", " ") -- convert whitespace to spaces for parsing | 1405 local s = arg2:gsub("\r\n\t", " ") -- convert whitespace to spaces for parsing |
| 1407 | 1407 |
| 1408 if isVertexCode(s) then | 1408 if isVertexCode(s) then |
| 1409 vertexcode = arg2 -- second arg contains vertex shader code | 1409 vertexcode = arg2 -- second arg contains vertex shader code |
| 1410 end | 1410 end |
| 1411 | 1411 |
| 1412 local ispixel, isMRT = isPixelCode(s) | 1412 local ispixel, isMultiCanvas = isPixelCode(s) |
| 1413 if ispixel then | 1413 if ispixel then |
| 1414 pixelcode = arg2 -- second arg contains pixel shader code | 1414 pixelcode = arg2 -- second arg contains pixel shader code |
| 1415 is_mrt = isMRT | 1415 is_multicanvas = isMultiCanvas |
| 1416 end | 1416 end |
| 1417 end | 1417 end |
| 1418 | 1418 |
| 1419 if vertexcode then | 1419 if vertexcode then |
| 1420 vertexcode = createVertexCode(vertexcode) | 1420 vertexcode = createVertexCode(vertexcode) |
| 1421 end | 1421 end |
| 1422 if pixelcode then | 1422 if pixelcode then |
| 1423 pixelcode = createPixelCode(pixelcode, is_mrt) | 1423 pixelcode = createPixelCode(pixelcode, is_multicanvas) |
| 1424 end | 1424 end |
| 1425 | 1425 |
| 1426 return vertexcode, pixelcode | 1426 return vertexcode, pixelcode |
| 1427 end | 1427 end |
| 1428 | 1428 |
