Commit Graph

339 Commits

Author SHA1 Message Date
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 2392174eb2 Rounded rectangles with radius values >= the rectangle's width and height are now clamped rather than causing an error. 2015-08-01 13:31:08 -03:00
Alex Szpakowski 66942d5f31 Added the ability to use custom mipmaps in Images, via love.graphics.newImage(filename, {mipmap1, mipmap2, ...}). Resolves issue #1064.
All mipmap levels must be present if custom mipmaps are used (and their sizes must be half the size of the previous mipmap level, rounded down.)

Image:getData now returns all custom mipmaps in an Image.
2015-07-30 20:48:36 -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 0583ebe470 All vertex component arguments to Mesh:setVertex and Mesh:setVertexAttribute are now optional rather than required. Float vertex components default to 0, and byte components default to 255. 2015-06-21 11:47:56 -03:00
Alex Szpakowski 42ae9c9585 Moved the love.graphics Lua code into the graphics module folder. 2015-06-18 14:27:45 -03:00
Bart van Strien 3cb777e2b7 Add basic lua 5.3 support 2015-06-16 10:25:41 +02:00
Alex Szpakowski 8c1bc543b9 Fixed love.graphics.rectangle erroring when the width or height is 0. 2015-06-07 17:45:43 -03:00
Alex Szpakowski f334a24f79 Potentially better calculation for the default number of points in the rounded-rect variant of love.graphics.rectangle. 2015-05-27 18:30:17 -03:00
Alex Szpakowski 4fe8e7214d Error if the rx and ry parameters of love.graphics.rectangle are >= half the rectangle's width or height, respectively. 2015-05-27 17:47:51 -03:00
Alex Szpakowski 0f986b10aa Cleaned up some code, the 'ry' parameter of love.graphics.rectangle now defaults to the value of 'rx' rather than defaulting to 0. 2015-05-27 17:36:27 -03:00
muddmaker 2a4524e5c0 Make ry optional, and ellipse can replace circle. 2015-05-23 17:28:58 -07:00
muddmaker 0119e47f87 Make roudned rectangle a variant of rectangle 2015-05-23 17:05:03 -07:00
muddmaker cb3ae86726 Add rx and ry parameters to roudnedRectangle 2015-05-23 16:52:27 -07:00
muddmaker dd41ccfbf7 Fix another typo. 2015-05-23 16:20:19 -07:00
muddmaker 439cc65382 Fix typo 2015-05-23 16:06:36 -07:00
muddmaker fbc419fda6 Add eclipse and roundedRectangle to love.graphics 2015-05-23 12:52:27 -07:00
Alex Szpakowski 30b083bd23 Fixed the new love.graphics.newMesh variant that accepts a Data object. 2015-05-15 14:45:11 -03:00
Alex Szpakowski 2844499ef7 Added the ability to have custom vertex attributes in Meshes (resolves issue #768.)
Added new love.graphics.newMesh variants: newMesh(vertexformat, vertices [, drawmode, meshusage]) and newMesh(vertexformat, numvertices [, drawmode, meshusage]).

Replaced the regular love.graphics.newMesh variants with newMesh(vertices [, drawmode, meshusage]) and newMesh(numvertices [, drawmode, meshusage]). To use an image or canvas with a mesh, use Mesh:setTexture.

vertexformat is a table with the following prototype:
{
  {attributename, datatype, components},
  {attributename, datatype, components},
  ...
}

Where attributename is the name of the vertex attribute (can be the built-in names 'VertexPosition', 'VertexTexCoord', or 'VertexColor', or a custom name for use in a vertex shader), datatype is the type of values used for the attribute ('float' or 'byte'), and components is the number of components in the vertex attribute (between 1 and 4.)

The vertex format is used to determine the layout of the vertices in the mesh, for example the 'regular' newMesh variants use this vertex format:
format = {
  {"VertexPosition", "float", 2},
  {"VertexTexCoord", "float", 2},
  {"VertexColor", "byte", 4},
}

The mesh usage parameter accepts the same constants as the spritebatch usage hint in love.graphics.newSpriteBatch - "dynamic", "static", and "stream".

Mesh:setVertex now sets *all* vertex attributes for a specific vertex in the Mesh.

Added Mesh:setVertexAttribute(vertexindex, attributeindex, attributevalue1, ...), which sets the values for a specific vertex attribute in a specific vertex in the Mesh (resolves issue #784.)

Added Mesh:getVertexFormat and Mesh:flush.

Added Mesh:setAttributeEnabled(attributename, enable) and Mesh:isAttributeEnabled(attributename), to enable or disable the use of a specific attribute when drawing the Mesh.

Added Mesh:attachAttribute(attributename, mesh), which makes the Mesh use a vertex attribute from another mesh when drawing the Mesh. This can be used to separate out vertex attributes which are updated at different rates into different meshes, and to share vertex data between multiple meshes.

Removed Mesh:setVertices, Mesh:getVertices, and Mesh:setVertexColors.
2015-04-08 22:24:17 -03:00
Alex Szpakowski cf0968fc6d Avoid some VC++ compiler warnings 2015-04-02 00:28:09 -03:00
Alex Szpakowski 3aafab9607 Hopefully fixed compilation in Windows. 2015-03-26 22:16:17 -03:00
Alex Szpakowski a29b349014 Added love.math.compress(data, format [, level]) and love.math.decompress(compresseddata) / love.math.decompress(compressedstring, format).
Renamed the love.image CompressedData type to CompressedImageData.

love.math.compress returns a love.math CompressedData object which holds the newly compressed data. Currently supported formats are "lz4" and "zlib". Note that the formats are not file formats and don't compress filesystem hierarchies.
2015-03-23 11:28:14 -03:00
Alex Szpakowski e237ed2432 love.graphics.discard now accepts a table of booleans indicating which of the active canvases to discard (matches love.graphics.clear.) 2015-03-21 02:36:13 -03:00
Alex Szpakowski 14cbc91e7f Fixed a memory leak in love.graphics.newText. 2015-03-16 03:13:10 -03:00
Alex Szpakowski 468127eed4 Added a variant of love.graphics.clear which accepts a color table argument for each active canvas, allowing it to clear active canvases to different colors without having to call love.graphics.setCanvas. 2015-03-15 15:15:21 -03:00
Alex Szpakowski a119e6a862 Added an optional spacing argument to love.graphics.newImageFont, allowing additional spacing (positive or negative) to be applied to all glyphs rendered using that font. 2015-03-11 18:28:22 -03:00
Alex Szpakowski b1f4beac56 Fixed the internal color mask state not being updated when love.graphics.setColorMask is called. 2015-03-10 01:13:39 -03:00
Alex Szpakowski 2e8f19930c Fixed love.graphics.stencil 2015-03-09 23:08:42 -03:00
Alex Szpakowski 52b2701cf0 Removed love.graphics.clearStencil. love.graphics.stencil now clears the stencil buffer unless true is passed as an optional second argument ('keep the existing contents'.) 2015-03-09 23:05:29 -03:00
Alex Szpakowski 3536f2665f love.graphics.clear can accept an array of color components.
--HG--
branch : minor
2015-03-02 02:32:53 -04:00
Alex Szpakowski 2f419c1c83 Replaced most cases of type bits and type name strings in love's Lua wrapper code with type id's.
--HG--
branch : minor
2015-03-01 18:32:41 -04:00
Alex Szpakowski b52b9c7a2b Added love.graphics.discard, which discards the contents of the screen (or currently active Canvas.)
Using it just after activating a Canvas can improve performance on many mobile devices, if the conditions for using it are right.

--HG--
branch : minor
2015-02-27 04:51:38 -04:00
Alex Szpakowski 1326ae9a5d Added love.graphics.clearStencil, which only clears the stencil buffer.
--HG--
branch : minor
2015-02-27 03:58:40 -04:00
Alex Szpakowski 3efcf3901b Removed Canvas:clear. love.graphics.clear now accepts r,g,b,a values (and defaults to 0,0,0,0 with no arguments given.) love.graphics.clear clears the content of the currently active Canvas(es.)
--HG--
branch : minor
2015-02-27 03:47:25 -04:00
Alex Szpakowski ebc68023a7 Fix many warnings about implicit integer conversions when compiling for 64 bits.
--HG--
branch : minor
2015-02-20 01:20:08 -04:00
Alex Szpakowski ac2b03e8a4 Added love.graphics.isActive. love.graphics function calls (and method calls on objects created via love.graphics) are only guaranteed to work when isActive is true, otherwise bad things might happen (the program crashing, for example.)
It's usually only false when the app is inactive on iOS, and when the window hasn't been created yet.

--HG--
branch : minor
2015-02-17 02:24:09 -04:00
Alex Szpakowski 67aede6bc0 Merged default into minor
--HG--
branch : minor
2015-02-02 01:13:21 -04:00
Alex Szpakowski 665cdc4ae7 Moved the default Font logic from the graphics.lua script to the Graphics and Font module C++ code. Moved love.graphics.setNewFont from the graphics.lua script to the Graphics module Lua wrapper code. Moved the Vera.ttf data from the graphics.lua script to its own file inside the Font module. 2015-01-31 01:10:38 -04:00
Alex Szpakowski ad1fbbf3ea Merged default into minor
--HG--
branch : minor
2015-01-29 21:27:05 -04:00
Alex Szpakowski b876255442 Cleaned up some graphics code. 2015-01-24 03:39:05 -04:00
Alex Szpakowski 970704c2b7 Added Text objects via love.graphics.newText(font [, textstring]). Reworked the internal code of Font objects to use fewer individual textures and less VRAM per object, and to be compatible with OpenGL ES. Slightly improved the performance of love.graphics.print and love.graphics.printf.
Text objects are Drawable objects that represent text on the screen. They decouple text drawing from text parsing and vertex uploading, in a similar manner to SpriteBatches. They also optionally allow efficient batching of text from the same Font in different relative coordinate transformations, without having many draw calls.

Text objects currently have the following methods:

Text:set(textstring) -- replaces any existing text in the object with the new string.
Text:setf(textstring, wraplimit, alignmode) -- replaces any existing text with formatted text using the new string.

Text:getFont() -- gets the Font object used for this Text object.
Text:getWidth() -- gets the width in pixels of the most recently added text in the Text object.
Text:getHeight() -- gets the height in pixels of the most recently added text in the Text object.

Text:add(textstring, x, y, angle, sx, sy, ox, oy, kx, ky) -- adds a new string to the text object using the specified relative coordinate transformation, without replacing existing text. This behaves much like SpriteBatch:add.
Text:addf(textstring, wraplimit, alignmode, x, y, angle, sx, sy, ox, oy, kx, ky) -- adds a new formatted string to the text object using the specified relative coordinate transformation.
Text:clear() -- clears all text from the object.

--HG--
branch : minor
2015-01-23 00:47:28 -04:00
Alex Szpakowski 5df56d041a Added GLSL ES 1.00 (OpenGL ES 2) shader support.
--HG--
branch : minor
2015-01-20 22:31:54 -04:00
Alex Szpakowski 8067d42df2 Canvases now have OpenGL ES support, updated Texture:setWrap to return false for repeat wrap modes in non-power-of-two textures if OpenGL ES 2 is used and the implementation doesn't have support for repeat on NPOT textures.
--HG--
branch : minor
2015-01-20 15:13:59 -04:00
Alex Szpakowski 18ab3973e8 Added support for ETC2/EAC compressed textures. Changed the CompressedFormat enum names to capitalize the format names (e.g. "PVR1rgba4" instead of "pvr1rgba4".) Improved sRGB support for compressed textures.
--HG--
branch : minor
2015-01-20 07:53:44 -04:00
Alex Szpakowski a7e4148869 Merged default into minor
--HG--
branch : minor
2015-01-16 15:47:26 -04:00
Alex Szpakowski c7b45b3505 Updated copyright for the new year 2014-12-31 19:32:43 -04:00
Alex Szpakowski 8edb90a719 Added support for loading BMFont bitmap font files with love.graphics.newFont (see issue #190.) Some esoteric BMFont features are not supported.
Moved the Font module Lua wrapper code out of the freetype implementation folder.

--HG--
branch : minor
2014-09-28 16:00:40 -03:00
Alex Szpakowski 34688e929e Merged default into minor
--HG--
branch : minor
2014-09-28 15:56:04 -03:00
Alex Szpakowski b70f72acb3 Fixed a couple potential memory leaks if love.graphics.newShader causes an error, and cleaned up some shader-related code. 2014-09-27 02:26:58 -03:00
Alex Szpakowski aba33bf2e7 Merged default into minor
--HG--
branch : minor
2014-09-20 00:34:34 -03:00