-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
919 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"id": "93cbe82e-9c9b-4c25-aa55-5105c1afd0cc" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#version 330 core | ||
|
||
in vec2 texCoord; | ||
out vec4 out_color; | ||
uniform sampler2D fontAtlas; | ||
|
||
const float pxRange = 4.0; | ||
|
||
layout(std140) uniform PerElement | ||
{ | ||
vec2 xRange; | ||
vec2 yRange; | ||
vec4 color; | ||
int depth; | ||
}; | ||
|
||
float screenPxRange() | ||
{ | ||
vec2 unitRange = vec2(pxRange) / vec2(textureSize(fontAtlas, 0)); | ||
vec2 screenTexSize = vec2(1.0) / fwidth(texCoord); | ||
return max(0.5 * dot(unitRange, screenTexSize), 1.0); | ||
} | ||
|
||
float median(float r, float g, float b) | ||
{ | ||
return max(min(r, g), min(max(r, g), b)); | ||
} | ||
|
||
void main() | ||
{ | ||
vec3 msd = texture(fontAtlas, texCoord).rgb; | ||
float sd = median(msd.r, msd.g, msd.b); | ||
float screenPxDistance = screenPxRange() * (sd - 0.5); | ||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); | ||
out_color = mix(vec4(0.0), color, opacity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"id": "b5b43fcb-0ec3-4f3a-9e90-a7b0b9978cc5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#version 330 core | ||
|
||
in vec2 in_position; | ||
in vec2 in_texCoord; | ||
|
||
layout(std140) uniform PerElement | ||
{ | ||
vec2 xRange; | ||
vec2 yRange; | ||
vec4 color; | ||
int depth; | ||
}; | ||
|
||
out vec2 texCoord; | ||
|
||
uniform MVP | ||
{ | ||
mat4 mvp; | ||
}; | ||
|
||
void main() | ||
{ | ||
gl_Position = mvp * (vec4(xRange.x, yRange.x, 0, 0) + vec4(in_position, depth, 1)); | ||
texCoord = in_texCoord; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"id": "51c11c57-c819-4a51-806c-853178ec686a" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/// @file | ||
/// @brief Struct @ref cubos::engine::FontAtlas. | ||
/// @ingroup font-plugin | ||
|
||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
#include <msdf-atlas-gen/msdf-atlas-gen.h> | ||
|
||
#include <cubos/core/gl/render_device.hpp> | ||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Class that holds all the necessary data about a font atlas. This font atlas represents the texure | ||
/// created from all the different glyphs in a font, that will be then used for drawing the text. | ||
/// | ||
/// @ingroup font-plugin | ||
struct CUBOS_ENGINE_API FontAtlas | ||
{ | ||
CUBOS_REFLECT; | ||
|
||
FontAtlas(msdfgen::FontHandle* font, core::gl::RenderDevice& rd); | ||
|
||
/// @brief GPU texture containing this font atlas. | ||
cubos::core::gl::Texture2D texture; | ||
|
||
/// @brief Map from unicode characters to their respective glyph geometry data. | ||
std::unordered_map<msdf_atlas::unicode_t, msdf_atlas::GlyphGeometry> glyphs; | ||
|
||
/// @brief Information about the bitmap used to generate the texture. | ||
msdfgen::BitmapConstRef<msdfgen::byte, 3> bitmap; | ||
}; | ||
|
||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// @file | ||
/// @brief Resource @ref cubos::engine::FontAtlasStore. | ||
/// @ingroup font-plugin | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
|
||
#include <uuid.h> | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
#include <cubos/engine/font/atlas.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
struct CUBOS_ENGINE_API FontAtlasStore | ||
{ | ||
CUBOS_REFLECT; | ||
|
||
std::weak_ptr<FontAtlas> retrieve(const uuids::uuid& assetId); | ||
|
||
bool contains(const uuids::uuid& assetId) const; | ||
|
||
void store(const uuids::uuid& assetId, const std::shared_ptr<FontAtlas>& atlas); | ||
|
||
void remove(const uuids::uuid& assetId); | ||
|
||
const std::unordered_map<uuids::uuid, std::weak_ptr<FontAtlas>>& map() const; | ||
|
||
private: | ||
std::unordered_map<uuids::uuid, std::weak_ptr<FontAtlas>> mAtlas; | ||
}; | ||
|
||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// @file | ||
/// @brief Class @ref cubos::engine::FontBridge. | ||
/// @ingroup font-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/assets/bridges/file.hpp> | ||
#include <cubos/engine/font/font.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Bridge which loads and saves @ref Font assets. | ||
/// | ||
/// @ingroup font-plugin | ||
class CUBOS_ENGINE_API FontBridge : public FileBridge | ||
{ | ||
public: | ||
FontBridge() | ||
: FileBridge(core::reflection::reflect<Font>()) | ||
, mFtHandle(msdfgen::initializeFreetype()) | ||
{ | ||
} | ||
|
||
~FontBridge() override; | ||
|
||
protected: | ||
bool loadFromFile(Assets& assets, const AnyAsset& handle, core::memory::Stream& stream) override; | ||
bool saveToFile(const Assets& assets, const AnyAsset& handle, core::memory::Stream& stream) override; | ||
|
||
private: | ||
msdfgen::FreetypeHandle* mFtHandle; | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// @file | ||
/// @brief Struct @ref cubos::engine::Font. | ||
/// @ingroup font-plugin | ||
|
||
#pragma once | ||
|
||
#include <msdf-atlas-gen/msdf-atlas-gen.h> | ||
|
||
#include <cubos/core/memory/stream.hpp> | ||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Asset containing font data. | ||
/// | ||
/// @ingroup font-plugin | ||
struct CUBOS_ENGINE_API Font | ||
{ | ||
CUBOS_REFLECT; | ||
|
||
/// @brief The handle to the loaded font. | ||
msdfgen::FontHandle* fontHandle{nullptr}; | ||
|
||
explicit Font(msdfgen::FreetypeHandle* ft, core::memory::Stream& stream); | ||
Font(Font&& other) noexcept; | ||
~Font(); | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// @dir | ||
/// @brief @ref font-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup font-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/prelude.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @defgroup font-plugin Font | ||
/// @ingroup engine | ||
/// @brief Adds fonts to @b Cubos using msdfgen. | ||
/// | ||
/// ## Bridges | ||
/// - @ref FontBridge - loads @ref Font assets. | ||
/// | ||
/// ## Dependencies | ||
/// - @ref assets-plugin | ||
|
||
/// @brief Plugin entry function. | ||
/// @param cubos @b Cubos main class. | ||
/// @ingroup font-plugin | ||
CUBOS_ENGINE_API void fontPlugin(Cubos& cubos); | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// @dir | ||
/// @brief @ref ui-text-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup ui-text-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/prelude.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @defgroup ui-text-plugin | ||
/// @ingroup ui-plugins | ||
/// @brief Adds text element to UI. | ||
|
||
/// @brief Plugin entry function. | ||
/// @param cubos @b Cubos main class | ||
/// @ingroup ui-text-plugin | ||
CUBOS_ENGINE_API void uiTextPlugin(Cubos& cubos); | ||
|
||
} // namespace cubos::engine |
Oops, something went wrong.