Commit Graph

115 Commits

Author SHA1 Message Date
Alex Szpakowski 864147c38c love.graphics: move more platform-independent code out of the opengl backend
--HG--
branch : minor
2017-07-22 23:34:39 -03:00
Alex Szpakowski 34f25bd6c8 ESSL: always enable standard derivative functionality (dFdx, dFdy, fwidth) when available. Added 'shaderderivatives' graphics feature enum.
--HG--
branch : minor
2017-07-09 16:55:21 -03:00
Alex Szpakowski 54a049e206 Restructured internal code for graphics capabilities. Added love.graphics.getTextureTypes which returns a table of Texture Type to boolean supported fields.
--HG--
branch : minor
2017-06-27 22:26:30 -03:00
Alex Szpakowski 9fe81ad922 Allow a temporary/internal depth buffer to be used when a Canvas is active, similar to how temporary stencil buffers are allowed.
Syntax is setCanvas{canvas [, depth=true, stencil=true]} or setCanvas{canvas, depthstencil=true}.

--HG--
branch : minor
2017-06-10 14:25:22 -03:00
Alex Szpakowski e03c763215 Fix love.graphics.drawLayer.
--HG--
branch : minor
2017-05-20 15:37:29 -03:00
Alex Szpakowski 7694edfd52 Auto-batched draws (except for love.graphics.print, for now) are affected by 3D transforms.
--HG--
branch : minor
2017-05-17 22:03:09 -03:00
Alex Szpakowski ac697ddb0f Clean up love’s internal Vector code a bit, and rename it to Vector2 so it’s more obvious what it is.
--HG--
branch : minor
2017-05-16 22:07:01 -03:00
Alex Szpakowski b019a4a64c Cleaned up texture VRAM usage tracking.
--HG--
branch : minor
2017-05-06 23:56:10 -03:00
Alex Szpakowski 621fb24ba1 Require stencil=true to be specified in setCanvas if stenciling is used while a Canvas is active and there is no custom stencil buffer.
--HG--
branch : minor
2017-04-29 21:29:37 -03:00
Alex Szpakowski fd64999748 Allow calling love.graphics.drawLayer(arraycanvas, layer) when rendering to a different layer of the same Canvas.
--HG--
branch : minor
2017-04-29 13:35:07 -03:00
Alex Szpakowski 70b32c47ce Error if a non-2D/affine matrix is used with auto-batched draws, since they perform CPU-side matrix transforms on 2-component vectors.
--HG--
branch : minor
2017-04-23 00:12:57 -03:00
Alex Szpakowski 7161d600b7 Add mipmapping support to Canvases.
- Added an optional mipmap index argument to the non-table variant of love.graphics.setCanvas, and an optional ‘mipmap’ field to the table variant.
- Canvas:setMipmapFilter now works.
- Added Canvas:generateMipmaps.
- Added Canvas:getMipmapMode.
- Added a new ‘mipmaps’ enum field to the table passed into love.graphics.newCanvas. Accepted values are “none” (default), “manual”, and “auto”.

If a Canvas has the manual mipmap mode, you will either need to render to a mipmap level or call Canvas:generateMipmaps. If it has the auto mode, mipmaps will be automatically generated after rendering to that Canvas. Generating mipmaps is not free.

--HG--
branch : minor
2017-04-15 01:58:03 -03:00
Alex Szpakowski a0ef2ac28b Add Depth compare / shadow sampler support. Officially this is only supported in glsl3 shaders.
- Add Texture:setDepthSampleMode(comparemode). Only works on textures with depth pixel formats. A texture with the depth sample mode set will only work with a depth sampler.
- Add DepthImage, DepthArrayImage, and DepthCubeImage sampler keywords to glsl3.

--HG--
branch : minor
2017-04-12 20:26:06 -03:00
Alex Szpakowski 018a3831cb Add a new “stencil8” pixel format for Canvases (resolves issue #1003).
Also fixed Canvas MSAA (resolves issue #1271).

stencil-formatted Canvases can’t be drawn, and can only be used as the value for a new ‘depthstencil’ field to the table-argument variant of love.graphics.setCanvas.

--HG--
branch : minor
2017-04-11 00:00:22 -03:00
Alex Szpakowski 0fde3fde35 Add new variants of love.graphics.print/printf which accept a Font argument, rather than relying on global love.graphics state to determine the Font to use.
--HG--
branch : minor
2017-03-06 23:15:10 -04:00
Alex Szpakowski 66b299822a Array textures can be easily drawn without a shader (resolves issue #1111).
Added love.graphics.drawLayer(texture, layerindex, …). ‘texture’ must be an array texture.
Added SpriteBatch:add/setLayer.

Added Quad:get/setLayer. This applies to array textures that are drawn without specifying an explicit layer index in the draw call.

Added love.graphics.newQuad variants which have layer arguments.

--HG--
branch : minor
2017-02-26 17:11:22 -04:00
Alex Szpakowski 73fd45558b Implement Array, Cubemap, and Volume texture types (issue #1111).
- Add love.graphics.newArrayImage, newCubeImage, and newVolumeImage.
- Add love.graphics.newCanvas(w, h, layers) and newCanvas(w, h, layers, settings). Add ‘type’ field to the settings table of newCanvas.

- Add new love.graphics.setCanvas variants: setCanvas(canvas, slice), and setCanvas(canvastable) where canvastable is in the format: {{canvas1, layer=2}, {canvas2, face=5}}

- Add Texture:getTextureType, getDepth, getLayerCount, getMipmapCount, and getFormat.

- Remove Image:getData and Image:refresh.
- Add Image:replacePixels(imagedata [, slice] [, mipmap]).

- Update Canvas:newImageData to accept a slice argument.

- Add love.image.newCubeFaces(imagedata).

--HG--
branch : minor
2017-02-20 14:58:13 -04:00
Alex Szpakowski 97789b18c0 Only use opengl debug groups if the LOVE_GRAPHICS_DEBUG environment variable is set to 1.
--HG--
branch : minor
2017-02-12 17:58:28 -04:00
Alex Szpakowski a3ae0e2279 Fix love.graphics.points when no per-point colors are given
--HG--
branch : minor
2017-01-29 17:47:29 -04:00
Alex Szpakowski c0e66eba83 Move backend-agnostic Mesh and SpriteBatch code out of the opengl implementation folder.
--HG--
branch : minor
2017-01-29 01:05:20 -04:00
Alex Szpakowski d990044288 love.graphics internal Buffer objects are no longer OpenGL-specific.
--HG--
branch : minor
2017-01-28 19:26:57 -04:00
Alex Szpakowski bea7cfdaab Add low-level hardware instancing support to Meshes.
Add “instancing” Graphics Feature constant.

Add love.graphics.drawInstanced(mesh, instancecount, x, y, …) which draws the mesh multiple times in a single draw call. Each instance of the mesh will appear in the exact same spot unless one of the following are used:

- Add an optional vertex attribute step type argument to Mesh:attachAttribute. “pervertex” is the default. “perinstance” causes the attribute to be per-instance instead of per-vertex, when the mesh is drawn.

- Add love_InstanceID as a built-in read only int variable in GLSL 3 vertex shaders. It is always 0 except when a Mesh is drawn with more than 1 instance specified in the draw call. It can be used to manually compute or index into per-instance values in a shader.

--HG--
branch : minor
2017-01-22 20:52:11 -04:00
Alex Szpakowski 731b5d5cf0 Added support for GLSL 3 shaders (GLSL 3.30 and GLSL ES 3.00).
To use GLSL 3 in a shader, the first line of the shader has to be: #pragma language glsl3

glsl1 is the default language.

Added “glsl3” graphics feature as part of the table returned by love.graphics.getSupported().

Added love.graphics.validateShader(boolean gles, shadercode). It returns a boolean along with an error string if the shader code has errors for its target language and platform (gles or desktop).

Implemented support for Core Profile OpenGL 3.3 in love.graphics.

--HG--
branch : minor
2017-01-22 18:54:04 -04:00
Alex Szpakowski a6669a8bb2 Merge default into minor
--HG--
branch : minor
2017-01-21 12:06:35 -04:00
Alex Szpakowski abb72cb813 Happy new year! 🥂
--HG--
branch : minor
2017-01-02 01:28:29 -04:00
Alex Szpakowski f12596dd19 More code restructuring.
Move all love.graphics functionality that doesn’t call OpenGL out of the OpenGL backend Graphics class.

--HG--
branch : minor
2016-12-30 18:36:54 -04:00
Alex Szpakowski d94b363b39 Move more love.graphics backend-agnostic module code out of the opengl implementation file.
--HG--
branch : minor
2016-12-30 14:32:11 -04:00
Alex Szpakowski 4a3889ae48 Use automatic batching for love.graphics.print/printf.
This doesn’t actually improve performance at all in most cases, but it does remove some OpenGL-specific code from the Font files, and reduces the amount of duplicated rendering code. This makes it slightly easier to add support for Core Profile OpenGL 3.

--HG--
branch : minor
2016-12-29 00:25:14 -04:00
Alex Szpakowski a78fa39113 Added “none” blend mode. This is equivalent to setBlendMode(“replace”, “premultiplied”) (which also effectively disables blending) but doesn’t require explicitly setting the alpha multiplication mode.
--HG--
branch : minor
2016-12-28 12:32:37 -04:00
Alex Szpakowski a6a7f03b3a Fix more Windows compilation issues
--HG--
branch : minor
2016-12-27 23:23:57 -04:00
Alex Szpakowski 603c3e43d5 Moved line and shape drawing code out of the opengl folder, since it no longer directly calls any OpenGL functions.
--HG--
branch : minor
2016-12-27 23:21:25 -04:00
Alex Szpakowski 0d2e08baff Implement automatic batching for points, lines, shapes, and images/quads.
The above are batched together into a single draw call when called without other drawing calls in between, as long as the following criteria are met:

- The texture is the same.
- The primitive type is the same (points cannot be batched with non-points).
- The love.graphics state is the same (aside from the current color - i.e. setColor - and the transform state).
- The active shader’s uniform values are the same.

You can examine the ‘drawcalls’ field of love.graphics.getStats() to help determine if your code is allowing for optimum batching.

--HG--
branch : minor
2016-12-27 21:02:58 -04:00
Bart van Strien 24a7a3d367 Merge minor into dynamiccore2
--HG--
branch : dynamiccore2
2016-11-26 22:19:12 +01:00
Alex Szpakowski f85ee6b504 Add some more graphics feature and limit queries (resolves issue #1234).
love.graphics.getSupported():
 - Added “fullnpot” field, is true everywhere except on some older mobile devices. If false, mipmapping and wrap modes other than “clamp” can’t be used on non-power-of-two sized textures.
 - Added “pixelshaderhighp” field, is true everywhere except some older mobile devices. If false, “highp” precision can’t be used in pixel shaders and love will default to “mediump” instead.

love.graphics.getSystemLimits():
- Added “anisotropy” field, gets the maximum amount of anisotropy you can specify in Texture:setFilter. love will clamp anisotropy arguments greater than this value.

--HG--
branch : minor
2016-11-25 19:35:07 -04:00
Bart van Strien d967a755e5 Make love::Type handle type names
TODO: Fix undefined behaviour in luax_register_type, you can't use a va_list after a reference type

--HG--
branch : dynamiccore2
2016-11-14 21:06:53 +01:00
Bart van Strien c761202486 Build type information on first use (load-time), instead of using a hardcoded list
--HG--
branch : dynamiccore2
2016-11-13 16:38:57 +01:00
Alex Szpakowski 1eed86426b Merge default into minor
--HG--
branch : minor
2016-04-02 18:27:33 -03:00
Alex Szpakowski 901cc362df Added 'shaderswitches' to love.graphics.getStats. 2016-04-02 18:14:52 -03:00
Alex Szpakowski cc1b9bc619 Moved most love.math functions out of the Math class, since they're pure functions.
--HG--
branch : minor
2016-03-28 19:46:29 -03:00
Alex Szpakowski cf4b409302 Renamed some things. 2016-02-18 22:11:41 -04:00
Alex Szpakowski 46a2e7b85c Happy new year! 🎉 2016-01-01 00:05:06 -04:00
Alex Szpakowski b48117544d Added "lighten" and "darken" blend modes (resolves issue #443).
They perform the equations res.rgba = max(dst.rgba, src.rgba) and res.rgba = min(dst.rgba, src.rgba) respectively.

They only work when the "premultiplied" blend alpha mode is used, and an error occurs otherwise.  They also aren't supported on some non-iOS OpenGL ES 2 systems. Check for support with love.graphics.getSupported().lighten.
2015-12-31 15:54:02 -04:00
Alex Szpakowski a42341aa73 Added a new variant of love.graphics.arc: arc(drawmode, arcmode, x, y, radius, angle1, angle2 [, points]).
arcmode is "open", "closed", or "pie" (with pie being the mode used for the original variant of the function).
2015-12-31 00:13:01 -04:00
Alex Szpakowski 48345bd58c Changed the optional 'multiply alpha' boolean argument in love.graphics.setBlendMode to be an enum with constants 'alphamultiply' and 'premultiplied'.
The default value for the second argument of setBlendMode is 'alphamultiply'.
2015-12-16 14:53:16 -04:00
Alex Szpakowski 0a059814e7 Revamped love.graphics.stencil and love.graphics.setStencilTest:
- Each canvas (and the screen) has an invisible stencil value associated with each pixel. Stencil values are between [0, 255].

- love.graphics.stencil takes a function argument which draws things, and makes the geometry of what's drawn set the stencil values of pixels instead of coloring the pixels.

- Its second argument is a 'stencil action' which determines what happens to the stencil values of pixels. The possible stencil actions are 'replace' (the default), 'invert', 'increment', 'decrement', 'incrementwrap', and 'decrementwrap'. If the stencil action is 'replace', the third argument of love.graphics.stencil is a number between [0, 255] which determines what the stencil value of each pixel that touches drawn objects is replaced with.

The fourth argument is a boolean which determines whether the previous stencil values of all pixels on-screen should be kept (true), or cleared to 0 (false, the default.) love.graphics.clear also clears the stencil values.

- love.graphics.setStencilTest allows for anything drawn to be affected by a comparison between the arguments to setStencilTest and the existing stencil value of the pixels that are touched by what's drawn. Its first argument is a compare mode which can be 'equal', 'notequal', 'less', 'lequal', 'gequal', or 'greater', and the second argument is an integer value (between 0 and 255) used in the comparison with the value in the stencil buffer.

For example, love.graphics.setStencilTest("greater", 0) will cause any geometry drawn afterwards to only appear on pixels whose stencil value is greater than 0.
2015-12-14 20:43:39 -04:00
Alex Szpakowski 4c82c96369 Added a new texture wrap mode "clampzero", which outputs transparent black (or opaque black for textures without an alpha channel) rather than the texture's edge colors, when it's drawn or sampled from outside of its regular texture coordinate range. 2015-11-30 02:22:20 -04:00
Alex Szpakowski a81621df82 Removed the 'multicanvas' GraphicsFeature constant since it's redundant (the love.graphics.getSystemLimits().multicanvas number can be used instead.) 2015-11-14 19:33:56 -04:00
Alex Szpakowski d215d8a91e Reworked sRGB / gamma-correct APIs:
Gamma-correct blending and shader math can be enabled globally via the new 't.gammacorrect' boolean flag in love.conf.
The new function love.graphics.isGammaCorrect will return true if it was requested in love.conf and is supported on the system.

When gamma correct rendering is enabled, colors (including the colors of pixels from images) are automatically converted from sRGB to linear RGB before use. When drawing to the main screen or to a canvas with the 'normal' or 'srgb' format, the final output colors of pixel shaders are automatically converted from linear RGB to sRGB after blending and before the color is stored in the pixel.

This lets the rendering pipeline do math using linear RGB values for colors rather than sRGB values, so the math is correct, without making users of the APIs manually linearize their colors with the love.math.gammaToLinear function (which still exists). The final output of the screen is encoded as sRGB, which is what systems expect. Canvases (except when otherwise requested) store their contents with sRGB encoding for increased precision with darker colors.

the 'srgb' window setting flag has been removed, as well as the 'srgb' image flag. A new image flag 'linear' has been added, which when set to true will cause the colors of the image to always be treated as linear RGB rather than sRGB, when gamma-correct rendering is enabled.

A new function 'Shader:sendColor' has been added, which has the same argument structure as 'Shader:send' but expects colors in the range of [0, 255]. When gamma-correct rendering is enabled it automatically gamma-corrects the given colors (by applying gammaToLinear to them.)

New shader code functions have been added: gammaToLinear, linearToGamma, gammaCorrectColor, and unGammaCorrectColor. When gamma-correct rendering is enabled, the LOVE_GAMMA_CORRECT #define is set and gammaCorrectColor and unGammaCorrectColor are aliases for gammaToLinear and linearToGamma respectively, otherwise the functions do nothing.

The new shader functions have 'precise' and 'fast' variants. If the LOVE_PRECISE_GAMMA define is set, then the normal functions default to the precise variants, otherwise they default to the fast variants. Currently the define is set in vertex shaders and not set in pixel shaders.

The default per-vertex color is automatically gamma-corrected by LÖVE when gamma correct rendering is enabled, but any custom named per-vertex attribute specified with the new custom attribute Mesh functionality won't be, unless 'gammaCorrectColor' or similar functions are explicitly used (preferably inside the vertex shader code that has the custom attribute.)
2015-08-09 21:46:21 -03:00
Alex Szpakowski 88c8e0c071 Added an optional (true by default) boolean argument to love.graphics.setBlendMode to specify whether alpha should be multiplied with rgb when blending.
Removed the 'premultiplied' blend mode, since setBlendMode("alpha", false) accomplishes the same thing now.

The 'multiply' blend mode is unaffected by the new flag, since fixed-function hardware blending can't do the equivalent of setBlendMode("multiply", true).
2015-06-24 16:47:10 -03:00
Alex Szpakowski 275a9a300f Multi-canvas rendering (love.graphics.setCanvas with multiple canvases) now allows canvases with different formats, if the system supports it. Added 'multicanvasformats' to the table returned by love.graphics.getSupported.
--HG--
branch : minor
2015-03-02 23:43:09 -04:00