| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsPrerequisites.h" |
| 6 | #include "GUI/BsGUISkin.h" |
| 7 | #include "Utility/BsModule.h" |
| 8 | #include "Math/BsVector2I.h" |
| 9 | #include "BsApplication.h" |
| 10 | |
| 11 | #include "ThirdParty/json.hpp" |
| 12 | |
| 13 | namespace bs |
| 14 | { |
| 15 | /** @addtogroup Resources-Engine |
| 16 | * @{ |
| 17 | */ |
| 18 | |
| 19 | /** Types of builtin meshes that are always available. */ |
| 20 | enum class BuiltinMesh |
| 21 | { |
| 22 | Box, Sphere, Cone, Cylinder, Quad, Disc |
| 23 | }; |
| 24 | |
| 25 | /** Types of builtin textures that are always available. */ |
| 26 | enum class BuiltinTexture |
| 27 | { |
| 28 | White, Black, Normal |
| 29 | }; |
| 30 | |
| 31 | /** Types of builtin shaders that are always available. */ |
| 32 | enum class BS_SCRIPT_EXPORT() BuiltinShader |
| 33 | { |
| 34 | Custom, |
| 35 | /** Physically based shader used for opaque 3D geometry. */ |
| 36 | Standard, |
| 37 | /** Physically based shader used for transparent 3D geometry. */ |
| 38 | Transparent, |
| 39 | /** Special shader used for rendering particles without any lighting, with support for transparency. */ |
| 40 | ParticlesUnlit, |
| 41 | /** |
| 42 | * Special shader used for rendering particles with lighting using the forward rendering pipeline (supports |
| 43 | * transparency). |
| 44 | */ |
| 45 | ParticlesLit, |
| 46 | /** |
| 47 | * Special shader used for rendering particles with lighting using the deferred rendering pipeline (no support |
| 48 | * for transparency). |
| 49 | */ |
| 50 | ParticlesLitOpaque, |
| 51 | /** Special shader used for rendering decals that project onto other geometry. */ |
| 52 | Decal |
| 53 | }; |
| 54 | |
| 55 | /** Holds references to built-in resources used by the core engine. */ |
| 56 | class BS_EXPORT BuiltinResources : public bs::Module<BuiltinResources> |
| 57 | { |
| 58 | public: |
| 59 | BuiltinResources(); |
| 60 | ~BuiltinResources(); |
| 61 | |
| 62 | /** Returns the default skin used by engine GUI elements. */ |
| 63 | const HGUISkin& getGUISkin() const { return mSkin; } |
| 64 | |
| 65 | /** Returns an empty skin used to be used when no other is available. */ |
| 66 | const HGUISkin& getEmptyGUISkin() const { return mEmptySkin; } |
| 67 | |
| 68 | /** Returns a small entirely white texture. */ |
| 69 | const HSpriteTexture& getWhiteSpriteTexture() const { return mWhiteSpriteTexture; } |
| 70 | |
| 71 | /** Returns a 2x2 sprite texture that can be used when no other is available. */ |
| 72 | const HSpriteTexture& getDummySpriteTexture() const { return mDummySpriteTexture; } |
| 73 | |
| 74 | /** Returns a dummy 2x2 texture that may be used when no other is available. Don't modify the returned texture. */ |
| 75 | const HTexture& getDummyTexture() const { return mDummyTexture; } |
| 76 | |
| 77 | /** Returns image data for an arrow cursor, along with its hotspot. */ |
| 78 | const PixelData& getCursorArrow(Vector2I& hotSpot); |
| 79 | |
| 80 | /** Returns image data for an arrow with dragged object cursor, along with its hotspot. */ |
| 81 | const PixelData& getCursorArrowDrag(Vector2I& hotSpot); |
| 82 | |
| 83 | /** Returns image data for a wait cursor, along with its hotspot. */ |
| 84 | const PixelData& getCursorWait(Vector2I& hotSpot); |
| 85 | |
| 86 | /** Returns image data for an "I" beam cursor, along with its hotspot. */ |
| 87 | const PixelData& getCursorIBeam(Vector2I& hotSpot); |
| 88 | |
| 89 | /** Returns image data for a NESW resize cursor, along with its hotspot. */ |
| 90 | const PixelData& getCursorSizeNESW(Vector2I& hotSpot); |
| 91 | |
| 92 | /** Returns image data for a NS resize cursor, along with its hotspot. */ |
| 93 | const PixelData& getCursorSizeNS(Vector2I& hotSpot); |
| 94 | |
| 95 | /** Returns image data for a NWSE resize cursor, along with its hotspot. */ |
| 96 | const PixelData& getCursorSizeNWSE(Vector2I& hotSpot); |
| 97 | |
| 98 | /** Returns image data for a WE resize cursor, along with its hotspot. */ |
| 99 | const PixelData& getCursorSizeWE(Vector2I& hotSpot); |
| 100 | |
| 101 | /** Returns image data for a deny cursor, along with its hotspot. */ |
| 102 | const PixelData& getCursorDeny(Vector2I& hotSpot); |
| 103 | |
| 104 | /** Returns image data for a move left-right cursor, along with its hotspot. */ |
| 105 | const PixelData& getCursorMoveLeftRight(Vector2I& hotSpot); |
| 106 | |
| 107 | /** Returns the default application icon. */ |
| 108 | const PixelData& getFrameworkIcon(); |
| 109 | |
| 110 | /** Returns one of the builtin shader types. */ |
| 111 | HShader getBuiltinShader(BuiltinShader type) const; |
| 112 | |
| 113 | /** Creates a material used for textual sprite rendering (for example text in GUI). */ |
| 114 | HMaterial createSpriteTextMaterial() const; |
| 115 | |
| 116 | /** Creates a material used for image sprite rendering (for example images in GUI). */ |
| 117 | HMaterial createSpriteImageMaterial() const; |
| 118 | |
| 119 | /** Creates a material used for antialiased line rendering (for example curve rendering in GUI). */ |
| 120 | HMaterial createSpriteLineMaterial() const; |
| 121 | |
| 122 | /** Retrieves one of the builtin meshes. */ |
| 123 | HMesh getMesh(BuiltinMesh mesh) const; |
| 124 | |
| 125 | /** |
| 126 | * Loads a shader at the specified path. |
| 127 | * |
| 128 | * @param[in] path Path relative to the default shader folder with no file extension. |
| 129 | */ |
| 130 | HShader getShader(const Path& path) const; |
| 131 | |
| 132 | /** Returns the default font used by the engine. */ |
| 133 | HFont getDefaultFont() const { return mFont; } |
| 134 | |
| 135 | /** Retrieves one of the builtin textures. */ |
| 136 | static HTexture getTexture(BuiltinTexture type); |
| 137 | |
| 138 | /** Returns absolute path to the builtin shader folder where raw shader files are located. */ |
| 139 | static Path getRawShaderFolder(); |
| 140 | |
| 141 | /** Returns absolute path to the builtin shader include folder. */ |
| 142 | static Path getShaderIncludeFolder(); |
| 143 | |
| 144 | /** Returns absolute path to the builtin icons folder. */ |
| 145 | static Path getIconFolder(); |
| 146 | |
| 147 | #if BS_IS_BANSHEE3D || defined BS_IS_ASSET_TOOL |
| 148 | /** Returns absolute path to the editor builtin shader include folder. */ |
| 149 | static Path getEditorShaderIncludeFolder(); |
| 150 | |
| 151 | #endif |
| 152 | |
| 153 | static constexpr const char* IconTextureName = "bsfIcon.png" ; |
| 154 | static constexpr const char* MultiLineLabelStyle = "MultiLineLabel" ; |
| 155 | |
| 156 | static constexpr const char* SHADER_FOLDER = "Shaders/" ; |
| 157 | static constexpr const char* CURSOR_FOLDER = "Cursors/" ; |
| 158 | static constexpr const char* ICON_FOLDER = "Icons/" ; |
| 159 | static constexpr const char* ICON3D_FOLDER = "Icons3D/" ; |
| 160 | static constexpr const char* SKIN_FOLDER = "Skin/" ; |
| 161 | static constexpr const char* ANIMATED_SPRITES_FOLDER = "AnimatedSprites/" ; |
| 162 | static constexpr const char* SHADER_INCLUDE_FOLDER = "Shaders/Includes/" ; |
| 163 | static constexpr const char* MESH_FOLDER = "Meshes/" ; |
| 164 | static constexpr const char* TEXTURE_FOLDER = "Textures/" ; |
| 165 | static constexpr const char* SPRITE_FOLDER = "Sprites/" ; |
| 166 | |
| 167 | static constexpr const char* MESH_SPHERE_FILE = u8"Sphere.asset" ; |
| 168 | static constexpr const char* MESH_BOX_FILE = u8"Box.asset" ; |
| 169 | static constexpr const char* MESH_CONE_FILE = u8"Cone.asset" ; |
| 170 | static constexpr const char* MESH_CYLINDER_FILE = u8"Cylinder.asset" ; |
| 171 | static constexpr const char* MESH_QUAD_FILE = u8"Quad.asset" ; |
| 172 | static constexpr const char* MESH_DISC_FILE = u8"Disc.asset" ; |
| 173 | |
| 174 | static constexpr const char* TEXTURE_WHITE_FILE = u8"White.asset" ; |
| 175 | static constexpr const char* TEXTURE_BLACK_FILE = u8"Black.asset" ; |
| 176 | static constexpr const char* TEXTURE_NORMAL_FILE = u8"Normal.asset" ; |
| 177 | |
| 178 | static constexpr const char* DEFAULT_FONT_NAME = u8"arial.ttf" ; |
| 179 | static constexpr const UINT32 DEFAULT_FONT_SIZE = 8; |
| 180 | |
| 181 | static constexpr const char* GUI_SKIN_FILE = u8"GUISkin" ; |
| 182 | private: |
| 183 | /** Loads a GUI skin texture with the specified filename. */ |
| 184 | HSpriteTexture getSkinTexture(const String& name) const; |
| 185 | |
| 186 | /** Loads a cursor texture with the specified filename. */ |
| 187 | HTexture getCursorTexture(const String& name) const; |
| 188 | |
| 189 | HGUISkin mEmptySkin; |
| 190 | HGUISkin mSkin; |
| 191 | HFont mFont; |
| 192 | |
| 193 | SPtr<PixelData> mCursorArrow; |
| 194 | SPtr<PixelData> mCursorArrowDrag; |
| 195 | SPtr<PixelData> mCursorArrowLeftRight; |
| 196 | SPtr<PixelData> mCursorIBeam; |
| 197 | SPtr<PixelData> mCursorDeny; |
| 198 | SPtr<PixelData> mCursorWait; |
| 199 | SPtr<PixelData> mCursorSizeNESW; |
| 200 | SPtr<PixelData> mCursorSizeNS; |
| 201 | SPtr<PixelData> mCursorSizeNWSE; |
| 202 | SPtr<PixelData> mCursorSizeWE; |
| 203 | SPtr<PixelData> mFrameworkIcon; |
| 204 | |
| 205 | HSpriteTexture mWhiteSpriteTexture; |
| 206 | HSpriteTexture mDummySpriteTexture; |
| 207 | |
| 208 | HTexture mDummyTexture; |
| 209 | |
| 210 | HShader mShaderSpriteText; |
| 211 | HShader mShaderSpriteImage; |
| 212 | HShader mShaderSpriteLine; |
| 213 | HShader mShaderDiffuse; |
| 214 | HShader mShaderTransparent; |
| 215 | HShader mShaderParticlesUnlit; |
| 216 | HShader mShaderParticlesLit; |
| 217 | HShader mShaderParticlesLitOpaque; |
| 218 | HShader mShaderDecal; |
| 219 | |
| 220 | SPtr<ResourceManifest> mResourceManifest; |
| 221 | |
| 222 | Path mBuiltinRawDataFolder; |
| 223 | Path mBuiltinDataFolder; |
| 224 | Path mEngineSkinSpritesFolder; |
| 225 | Path mEngineShaderFolder; |
| 226 | Path mEngineMeshFolder; |
| 227 | Path mEngineCursorFolder; |
| 228 | |
| 229 | Path ResourceManifestPath; |
| 230 | |
| 231 | static const String WhiteTex; |
| 232 | |
| 233 | static const String CursorArrowTex; |
| 234 | static const String CursorArrowDragTex; |
| 235 | static const String CursorArrowLeftRightTex; |
| 236 | static const String CursorIBeamTex; |
| 237 | static const String CursorDenyTex; |
| 238 | static const String CursorWaitTex; |
| 239 | static const String CursorSizeNESWTex; |
| 240 | static const String CursorSizeNSTex; |
| 241 | static const String CursorSizeNWSETex; |
| 242 | static const String CursorSizeWETex; |
| 243 | |
| 244 | static const Vector2I CursorArrowHotspot; |
| 245 | static const Vector2I CursorArrowDragHotspot; |
| 246 | static const Vector2I CursorArrowLeftRightHotspot; |
| 247 | static const Vector2I CursorIBeamHotspot; |
| 248 | static const Vector2I CursorDenyHotspot; |
| 249 | static const Vector2I CursorWaitHotspot; |
| 250 | static const Vector2I CursorSizeNESWHotspot; |
| 251 | static const Vector2I CursorSizeNSHotspot; |
| 252 | static const Vector2I CursorSizeNWSEHotspot; |
| 253 | static const Vector2I CursorSizeWEHotspot; |
| 254 | |
| 255 | static const String ShaderSpriteTextFile; |
| 256 | static const String ShaderSpriteImageFile; |
| 257 | static const String ShaderSpriteLineFile; |
| 258 | }; |
| 259 | |
| 260 | /** Provides easy access to BuiltinResources. */ |
| 261 | BS_EXPORT BuiltinResources& gBuiltinResources(); |
| 262 | |
| 263 | /** @} */ |
| 264 | } |
| 265 | |