| 1 | /** | 
|---|
| 2 | * Copyright (c) 2006-2023 LOVE Development Team | 
|---|
| 3 | * | 
|---|
| 4 | * This software is provided 'as-is', without any express or implied | 
|---|
| 5 | * warranty.  In no event will the authors be held liable for any damages | 
|---|
| 6 | * arising from the use of this software. | 
|---|
| 7 | * | 
|---|
| 8 | * Permission is granted to anyone to use this software for any purpose, | 
|---|
| 9 | * including commercial applications, and to alter it and redistribute it | 
|---|
| 10 | * freely, subject to the following restrictions: | 
|---|
| 11 | * | 
|---|
| 12 | * 1. The origin of this software must not be misrepresented; you must not | 
|---|
| 13 | *    claim that you wrote the original software. If you use this software | 
|---|
| 14 | *    in a product, an acknowledgment in the product documentation would be | 
|---|
| 15 | *    appreciated but is not required. | 
|---|
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be | 
|---|
| 17 | *    misrepresented as being the original software. | 
|---|
| 18 | * 3. This notice may not be removed or altered from any source distribution. | 
|---|
| 19 | **/ | 
|---|
| 20 |  | 
|---|
| 21 | #ifndef LOVE_GRAPHICS_OPENGL_CANVAS_H | 
|---|
| 22 | #define LOVE_GRAPHICS_OPENGL_CANVAS_H | 
|---|
| 23 |  | 
|---|
| 24 | #include "common/config.h" | 
|---|
| 25 | #include "common/Color.h" | 
|---|
| 26 | #include "common/int.h" | 
|---|
| 27 | #include "graphics/Canvas.h" | 
|---|
| 28 | #include "graphics/Volatile.h" | 
|---|
| 29 | #include "OpenGL.h" | 
|---|
| 30 |  | 
|---|
| 31 | namespace love | 
|---|
| 32 | { | 
|---|
| 33 | namespace graphics | 
|---|
| 34 | { | 
|---|
| 35 | namespace opengl | 
|---|
| 36 | { | 
|---|
| 37 |  | 
|---|
| 38 | class Canvas final : public love::graphics::Canvas, public Volatile | 
|---|
| 39 | { | 
|---|
| 40 | public: | 
|---|
| 41 |  | 
|---|
| 42 | Canvas(const Settings &settings); | 
|---|
| 43 | virtual ~Canvas(); | 
|---|
| 44 |  | 
|---|
| 45 | // Implements Volatile. | 
|---|
| 46 | bool loadVolatile() override; | 
|---|
| 47 | void unloadVolatile() override; | 
|---|
| 48 |  | 
|---|
| 49 | // Implements Texture. | 
|---|
| 50 | void setFilter(const Texture::Filter &f) override; | 
|---|
| 51 | bool setWrap(const Texture::Wrap &w) override; | 
|---|
| 52 | bool setMipmapSharpness(float sharpness) override; | 
|---|
| 53 | void setDepthSampleMode(Optional<CompareMode> mode) override; | 
|---|
| 54 | ptrdiff_t getHandle() const override; | 
|---|
| 55 |  | 
|---|
| 56 | love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect) override; | 
|---|
| 57 | void generateMipmaps() override; | 
|---|
| 58 |  | 
|---|
| 59 | int getMSAA() const override | 
|---|
| 60 | { | 
|---|
| 61 | return actualSamples; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | ptrdiff_t getRenderTargetHandle() const override | 
|---|
| 65 | { | 
|---|
| 66 | return renderbuffer != 0 ? renderbuffer : texture; | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | inline GLuint getFBO() const | 
|---|
| 70 | { | 
|---|
| 71 | return fbo; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | static PixelFormat getSizedFormat(PixelFormat format); | 
|---|
| 75 | static bool isSupported(); | 
|---|
| 76 | static bool isMultiFormatMultiCanvasSupported(); | 
|---|
| 77 | static bool isFormatSupported(PixelFormat format, bool readable); | 
|---|
| 78 | static bool isFormatSupported(PixelFormat format); | 
|---|
| 79 | static void resetFormatSupport(); | 
|---|
| 80 |  | 
|---|
| 81 | private: | 
|---|
| 82 |  | 
|---|
| 83 | struct SupportedFormat | 
|---|
| 84 | { | 
|---|
| 85 | bool readable = false; | 
|---|
| 86 | bool nonreadable = false; | 
|---|
| 87 |  | 
|---|
| 88 | bool get(bool getreadable) | 
|---|
| 89 | { | 
|---|
| 90 | return getreadable ? readable : nonreadable; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | void set(bool setreadable, bool val) | 
|---|
| 94 | { | 
|---|
| 95 | if (setreadable) | 
|---|
| 96 | readable = val; | 
|---|
| 97 | else | 
|---|
| 98 | nonreadable = val; | 
|---|
| 99 | } | 
|---|
| 100 | }; | 
|---|
| 101 |  | 
|---|
| 102 | GLuint fbo; | 
|---|
| 103 |  | 
|---|
| 104 | GLuint texture; | 
|---|
| 105 | GLuint renderbuffer; | 
|---|
| 106 |  | 
|---|
| 107 | GLenum status; | 
|---|
| 108 |  | 
|---|
| 109 | int actualSamples; | 
|---|
| 110 |  | 
|---|
| 111 | static SupportedFormat supportedFormats[PIXELFORMAT_MAX_ENUM]; | 
|---|
| 112 | static SupportedFormat checkedFormats[PIXELFORMAT_MAX_ENUM]; | 
|---|
| 113 |  | 
|---|
| 114 | }; // Canvas | 
|---|
| 115 |  | 
|---|
| 116 | } // opengl | 
|---|
| 117 | } // graphics | 
|---|
| 118 | } // love | 
|---|
| 119 |  | 
|---|
| 120 | #endif // LOVE_GRAPHICS_OPENGL_CANVAS_H | 
|---|
| 121 |  | 
|---|