Commit Graph

128 Commits

Author SHA1 Message Date
Alex Szpakowski abb72cb813 Happy new year! 🥂
--HG--
branch : minor
2017-01-02 01:28:29 -04:00
Alex Szpakowski d26002f5cc Revamped and streamlined retina / high-DPI support (resolves issue #1122).
With the highdpi window flag enabled on a retina-capable display and OS, content should now appear to the user at the same size and in the same positions as with the flag disabled.

As a result, mouse and touch coordinates, Texture and graphics dimensions, and the graphics coordinate system now use pixel density-scaled units instead of pixels. Raw pixel units should generally only be used for things such as shader algorithms which execute per-pixel and rely on accurate pixel dimensions. love.window.fromPixels and friends typically don’t need to be used anymore.

Images, Canvases, and Fonts can have an optional explicit ‘pixel density’ set when creating them. This allows for easily loading high pixel density content which displays at the same size as regular or low pixel density content.

API changes:

- Added Texture:getPixelWidth/getPixelHeight/getPixelDimensions and Texture:getPixelDensity. Texture:getWidth/getHeight return the pixel density-scaled width and height (as it will appear on the screen when drawn) rather than the number of pixels on each texture dimension.

- Added love.graphics.getPixelWidth/getPixelHeight/getPixelDimensions.

- Added optional ‘pixeldensity’ field to the settings table parameter of love.graphics.newImage. It defaults to 1, or if the file the Image was loaded from has “@2x”, “@3x”, etc. at the end of its name, it uses that number as the pixel density scale by default.

- love.graphics.newCanvas now takes a table as its third parameter, with fields “format”, “msaa”, and “pixeldensity”. pixeldensity defaults to the main screen’s pixel density. The width and height parameters specify the visual size that the Canvas will be drawn at / can be drawn to (pixel density-scaled units).

- love.graphics.newVideo accepts a table as its second parameter, with optional fields “audio” and “pixeldensity”. pixeldensity defaults to 1.

- love.graphics.newFont variants have an optional pixeldensity parameter at the end of the argument list. For TrueType fonts this defaults to the current pixel density scale of the screen, and for BMFonts and ImageFonts this defaults to 1.

- Added Font:getPixelDensity.

- Renamed love.window.getPixelScale to love.window.getPixelDensity.

--HG--
branch : minor
2016-12-29 23:55:51 -04:00
Alex Szpakowski 2a47a8c9e2 Revert most render pass API changes. The APIs need more work and iteration before they’re better to use than the old setCanvas APIs.
love.graphics.captureScreenshot has not been reverted.

--HG--
branch : minor
2016-12-11 16:33:05 -04:00
Alex Szpakowski 3e80ec2257 Render pass API. Replaces love.graphics.setCanvas and friends.
- Removed love.graphics.set/getCanvas, Canvas:renderTo, Canvas:newImageData, love.graphics.clear, love.graphics.discard, and love.graphics.newScreenshot.

- Added love.graphics.beginPass and love.graphics.endPass. All rendering must happen within a pass. love.draw is now called while a render pass to the main screen is active.
- Added love.graphics.renderPass, which is a wrapper for begin/endPass which calls the supplied function argument in between a begin/end. This is similar to the old Canvas:renderTo.
- Added love.graphics.isPassActive, getPassCanvases, getPassWidth, getPassHeight, and getPassDimensions.
- Added love.graphics.captureScreenshot.

- Added a new love.run callback love.drawpasses, which is called after love.update and before love.draw. It is the place to render to Canvases using beginPass or renderPass, since love.draw now always draws to the main screen.

- Renamed the ‘canvasswitches’ field in the table returned by love.graphics.getStats to ‘renderpasses’.

love.graphics.beginPass has the following variants (and renderPass mirrors them with an additional function argument at the end):

- love.graphics.beginPass(), begins rendering to the main screen without clearing it.
- love.graphics.beginPass(r, g, b [, a]), begins rendering to the main screen and clears the screen to the specified color.

- love.graphics.beginPass(canvas [, willstencil]), begins rendering to the specified Canvas without clearing it. love.graphics.stencil can only be used within the Canvas if ‘willstencil’ is true.
- love.graphics.beginPass(canvas, r, g, b [, a] [, willstencil]), beings rendering to the specified Canvas and clears it to the specified color. love.graphics.stencil can only be used within the Canvas if ‘willstencil’ is true.

- love.graphics.beginPass(info), where ‘info’ is a table in the following form:
{
    {canvas [, r, g, b, a]}, — A canvas and an optional color to clear the Canvas to when the pass begins.
    {canvas2, [r, g, b, a]}, — Additional Canvases and optional clear colors for multi-canvas rendering.
    …,
    stencil = false, — Optional boolean field to specify whether love.graphics.stencil is allowed within this pass. False by default.
}

The pass info table can be created once up-front and used for multiple beginPass/renderPass calls.

love.graphics.endPass can take an optional callback function argument, which causes endPass to capture the contents of the Canvas drawn to in the render pass to a new ImageData and passes it to the supplied function (this replaces Canvas:newImageData). This does not work on the main screen.

love.graphics.captureScreenshot replaces love.graphics.newScreenshot. It takes a callback function argument which causes love.graphics.present to capture the contents of the screen to a new ImageData and passes it to the supplied function. captureScreenshot can only be called before drawing to the main screen begins in the current frame (e.g. in love.keypressed, love.update, etc.)

--HG--
branch : minor
2016-11-19 19:13:26 -04:00
Alex Szpakowski 60d90ca4a8 Merge default into minor
--HG--
branch : minor
2016-10-30 01:07:39 -03:00
Alex Szpakowski ec7565176e Add love.window.isMaximized 2016-10-24 21:35:22 -03:00
Alex Szpakowski b9c01b8674 Merge default into minor
--HG--
branch : minor
2016-10-21 22:04:39 -03:00
Alex Szpakowski 42be56858b Remove duplicate unused code. 2016-10-10 09:33:10 -03:00
Alex Szpakowski 03c38185f6 Fix love.window.maximize to immediately update the window dimensions instead of waiting for the next love.event.pump. Fixes issue #1221. 2016-10-10 09:14:57 -03:00
Alex Szpakowski 7eeca829e5 Fix a use of std::remove_if
--HG--
branch : minor
2016-09-12 08:11:38 -03:00
Alex Szpakowski 11328a23cf Don't consider different OpenGL versions when re-creating the window after a previous window and OpenGL context has been created. love.graphics has never supported switching GL versions mid-game, so we should prevent it from ever happening.
--HG--
branch : minor
2016-09-11 21:40:00 -03:00
Alex Szpakowski dd2a448099 The vsync field in t.window and love.window.setMode is now an integer.
0 disables vsync, 1 sets it to sync every screen refreshes, 2 sets it to sync every 2 screen refreshes (effectively setting the framerate to half the monitor's refresh rate), etc.

As a special case, -1 also attempts to use adaptive vsync (vsync enabled when FPS is >= monitor's refresh rate, disabled whe not) if the driver supports it.

--HG--
branch : minor
2016-08-29 22:52:15 -03:00
T-Bone b2291fb62a Fixes to make Löve compile on Windows 10 UWP 2016-04-07 22:56:03 +02:00
Alex Szpakowski 9ec6eceb8a Cleaned up the error message code when love.window.setMode fails. 2016-01-14 19:16:41 -04:00
Alex Szpakowski 46a2e7b85c Happy new year! 🎉 2016-01-01 00:05:06 -04:00
Alex Szpakowski efa08b1e44 Fixed a compile failure on Android (thanks xenthral!) 2015-12-19 22:21:50 -04:00
Alex Szpakowski f6809f941d Cleaned up some love.window code. 2015-12-17 23:15:06 -04:00
Alex Szpakowski 4e75c7be9a Improved the window and OpenGL context creation code to try more options if the OpenGL version is too low (e.g. if the driver in Windows gave back a Microsoft GL 1.1 software context because of a high requested MSAA value.) 2015-12-17 19:03:13 -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 7b8af113da Fixed the minimum window size to re-set itself when love.window.setFullscreen(false) is called. 2015-12-13 20:50:35 -04:00
Alex Szpakowski b0c19ef2c5 Renamed love.window.set/isScreenSaverEnabled to love.window.set/isDisplaySleepEnabled. 2015-11-24 22:35:57 -04:00
Alex Szpakowski 7ebef76b24 Added love.window.setScreenSaverEnabled and love.window.isScreenSaverEnabled (resolves issue #1088.) 2015-11-24 22:16:40 -04:00
Alex Szpakowski d79d96a8f2 Also display graphics card information in the popup message when GL2 isn't supported. 2015-08-20 22:43:15 -03:00
Alex Szpakowski 4daa190513 Show the detected OpenGL version in the popup dialog when GL2.1 or GLES2 isn't available when the window is created. 2015-08-20 20:34:53 -03:00
Alex Szpakowski 9a1c4ad565 The iOS game list screen now also displays folders that contain main.lua. 2015-08-15 23:57:04 -03:00
Alex Szpakowski e44f20fdc6 Renamed OSX.mm/OSX.h to macosx.mm/macosx.h to match love's file naming conventions. 2015-08-15 00:41:45 -03:00
Martin Felis 6e0abae688 Implemented love.window.getPixelScale for Android. Fullscreen windows now use Android's 'immersive mode'. 2015-08-13 19:44:18 -03: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 f2b4438a57 Fixed love.window.getPosition in fullscreen mode when SDL 2.0.4 is used. 2015-08-01 16:01:59 -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 8bf8c0cd18 Hopefully work around an issue where older Intel drivers on Windows use Microsoft's OpenGL 1.1 software renderer instead of failing to create the context, when a requested framebuffer attribute value is unsupported.
Failing to create the context is preferred in that situation because love's code will then try disabling various framebuffer settings to get a hardware-accelerated context using a supported OpenGL version.
2015-07-28 11:27:45 -03:00
Alex Szpakowski f5abedaeeb Cleaned up the love.graphics code that deals with love.window to be more consistent with the rest of the codebase. 2015-07-24 21:40:55 -03:00
Alex Szpakowski 4cd725cee6 Added love.window.close (resolves issue #1059), and renamed love.window.isCreated to love.window.isOpen. 2015-07-18 13:22:55 -03:00
Alex Szpakowski b2b5a1d9df Fixed a compiler warning on Linux and iOS. 2015-06-09 21:26:41 -03:00
Alex Szpakowski 91e2227124 Fixed the behaviour of love.window.requestAttention on Windows. 2015-06-07 20:19:42 -03:00
Alex Szpakowski cf73aa0107 Added love.window.requestAttention. Bounces the dock icon in OS X and flashes the taskbar icon in Windows when called, if the program isn't in focus. 2015-06-07 19:40:46 -03:00
Alex Szpakowski a9e4be760e Updated the list of SDL backends which should default to OpenGL ES to include emscripten. 2015-06-02 23:06:31 -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
Alex Szpakowski 3704595189 Enabled OpenGL ES 3 support for Windows/Linux/Android when SDL 2.0.4+ is used, since that SDL version fixed its EGL code for GLES 3+. 2015-05-11 21:14:10 -03:00
Alex Szpakowski cf0968fc6d Avoid some VC++ compiler warnings 2015-04-02 00:28:09 -03:00
Alex Szpakowski cffa899e03 Explicitly mention SDL in the error message caused by SDL subsystem initialization failure. 2015-03-26 14:51:47 -03:00
Alex Szpakowski 14cbc91e7f Fixed a memory leak in love.graphics.newText. 2015-03-16 03:13:10 -03:00
Alex Szpakowski 06fa7bd7a4 Don't enable SDL_GL_FRAMEBUFFER_SRGB_CAPABLE in Linux when creating the window, to work around a potential bug. sRGB windows are still possible even without that. 2015-03-03 17:48:19 -04:00
Alex Szpakowski 52c4f2c119 Improved the performance of love.window.getPixelScale / toPixels / fromPixels by caching some values. Made some coordinate space-sensitive code use the proper conversions to get to the correct coordinate space.
--HG--
branch : minor
2015-02-23 17:55:30 -04:00
Alex Szpakowski e26e170f78 Enabled high-dpi code on Linux (even though SDL doesn't support it yet on Linux, as of 2.0.4.) SDL 2.0.1 or newer is now required on Linux.
I'd rather have high-dpi work on Linux without needing to rebuild love when it's eventually implemented in SDL, rather than preserve backwards-compatibility with SDL 2.0.0 on Linux (which isn't important for love 0.10.0.)

--HG--
branch : minor
2015-02-21 19:06:41 -04:00
Alex Szpakowski bf8f6f8b02 Changed the default fullscreen type from 'exclusive' to 'desktop'.
--HG--
branch : minor
2015-02-21 17:27:54 -04:00
Alex Szpakowski 33f57ce8fd OpenGL ES 3 contexts can only be reliably created on iOS (for now.)
--HG--
branch : minor
2015-02-21 17:16:40 -04:00
Alex Szpakowski 7f9abc1e77 Added love.touch module and touch screen events. Resolves issue #825.
Note: this implementation is slightly different from the implementation in the love 0.9.x Android and iOS ports!

Added love.touchpressed(id, x, y), love.touchmoved(id, x, y, dx, dy), and love.touchreleased(id, x, y, dx, dy).

id is a unique identifier for the touch press that persists until love.touchreleased. After that it is no longer unique.
x and y are the coordinates of the touch event in pixels within the window.
dx and dy are the amount in pixels that the touch has moved since the last event.

Added love.touch.getTouchCount and love.touch.getTouch(index).

love.touch.getTouch takes an index (not the same as an id. indices are not stable and don't correspond to a unique touch press.)
It returns the id of the touch and its current x and y coordinates in pixels.

--HG--
branch : minor
2015-02-16 16:29:45 -04:00
Alex Szpakowski d0e34e86f1 Changed love.window.setMode to recreate the window as well as the context if a particular context profile can't be created, to work around some limitations of the OpenGL context and window code in some SDL backends.
The window/context creation code might still need some work..

--HG--
branch : minor
2015-01-30 17:19:47 -04:00
Alex Szpakowski 84a6dd3b1c Fixed OpenGL context version checking when OpenGL ES is used.
--HG--
branch : minor
2015-01-30 04:48:09 -04:00