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 | #pragma once |
22 | |
23 | #include "image/Image.h" |
24 | #include "image/ImageData.h" |
25 | #include "Texture.h" |
26 | #include "common/Optional.h" |
27 | #include "common/StringMap.h" |
28 | |
29 | namespace love |
30 | { |
31 | namespace graphics |
32 | { |
33 | |
34 | class Graphics; |
35 | |
36 | class Canvas : public Texture |
37 | { |
38 | public: |
39 | |
40 | static love::Type type; |
41 | |
42 | enum MipmapMode |
43 | { |
44 | MIPMAPS_NONE, |
45 | MIPMAPS_MANUAL, |
46 | MIPMAPS_AUTO, |
47 | MIPMAPS_MAX_ENUM |
48 | }; |
49 | |
50 | enum SettingType |
51 | { |
52 | SETTING_WIDTH, |
53 | SETTING_HEIGHT, |
54 | SETTING_LAYERS, |
55 | SETTING_MIPMAPS, |
56 | SETTING_FORMAT, |
57 | SETTING_TYPE, |
58 | SETTING_DPI_SCALE, |
59 | SETTING_MSAA, |
60 | SETTING_READABLE, |
61 | SETTING_MAX_ENUM |
62 | }; |
63 | |
64 | struct Settings |
65 | { |
66 | int width = 1; |
67 | int height = 1; |
68 | int layers = 1; // depth for 3D textures |
69 | MipmapMode mipmaps = MIPMAPS_NONE; |
70 | PixelFormat format = PIXELFORMAT_NORMAL; |
71 | TextureType type = TEXTURE_2D; |
72 | float dpiScale = 1.0f; |
73 | int msaa = 0; |
74 | OptionalBool readable; |
75 | }; |
76 | |
77 | Canvas(const Settings &settings); |
78 | virtual ~Canvas(); |
79 | |
80 | MipmapMode getMipmapMode() const; |
81 | int getRequestedMSAA() const; |
82 | |
83 | virtual love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect); |
84 | virtual void generateMipmaps() = 0; |
85 | |
86 | virtual int getMSAA() const = 0; |
87 | virtual ptrdiff_t getRenderTargetHandle() const = 0; |
88 | |
89 | void draw(Graphics *gfx, Quad *q, const Matrix4 &t) override; |
90 | void drawLayer(Graphics *gfx, int layer, Quad *q, const Matrix4 &t) override; |
91 | |
92 | static int canvasCount; |
93 | |
94 | static bool getConstant(const char *in, MipmapMode &out); |
95 | static bool getConstant(MipmapMode in, const char *&out); |
96 | static std::vector<std::string> getConstants(MipmapMode); |
97 | |
98 | static bool getConstant(const char *in, SettingType &out); |
99 | static bool getConstant(SettingType in, const char *&out); |
100 | static const char *getConstant(SettingType in); |
101 | static std::vector<std::string> getConstants(SettingType); |
102 | |
103 | protected: |
104 | |
105 | Settings settings; |
106 | |
107 | private: |
108 | |
109 | static StringMap<MipmapMode, MIPMAPS_MAX_ENUM>::Entry mipmapEntries[]; |
110 | static StringMap<MipmapMode, MIPMAPS_MAX_ENUM> mipmapModes; |
111 | |
112 | static StringMap<SettingType, SETTING_MAX_ENUM>::Entry settingTypeEntries[]; |
113 | static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes; |
114 | |
115 | }; // Canvas |
116 | |
117 | } // graphics |
118 | } // love |
119 | |