Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
numanicloud committed Jul 7, 2018
2 parents 40b7c36 + 26848a6 commit 5e8636c
Show file tree
Hide file tree
Showing 60 changed files with 607 additions and 229 deletions.
2 changes: 2 additions & 0 deletions Dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ add_subdirectory(unitTest_Engine_cpp_gtest/)
# Tool
if (BUILD_TOOL)
add_subdirectory(ImagePackageGenerator/)
set_target_properties(PSDParser PROPERTIES LIBRARY_OUTPUT_DIRECTORY "bin/" )

endif()

if (BUILD_TOOL_3D)
Expand Down
1 change: 1 addition & 0 deletions Dev/asd_cpp/core/Graphics/2D/asd.PostEffectRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace asd {
{
Vector3DF Pos;
Vector2DF UV;
Vector2DF UVSub1;
Color Color_;

Vertex() {}
Expand Down
9 changes: 5 additions & 4 deletions Dev/asd_cpp/core/Graphics/2D/asd.Renderer2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ namespace asd {
*/
virtual void ClearCache() = 0;


virtual void AddSpriteWithMaterial(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Material2D* material, AlphaBlendMode alphaBlend, int32_t priority) = 0;

/**
@brief スプライト描画をキャッシュに追加する。
@param positions 頂点座標
Expand All @@ -70,7 +67,11 @@ namespace asd {
*/
virtual void AddSprite(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Texture2D* texture, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) = 0;

virtual void AddText(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) = 0;
virtual void AddSpriteWithMaterial(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Vector2DF uvSub1[4], Texture2D* texture, Material2D* material, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) = 0;

virtual void AddText(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, bool isRichTextMode, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) = 0;

virtual void AddTextWithMaterial(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, Material2D* material, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, bool isRichTextMode, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) = 0;
};

//----------------------------------------------------------------------------------
Expand Down
112 changes: 93 additions & 19 deletions Dev/asd_cpp/core/Graphics/2D/asd.Renderer2D_Imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
//----------------------------------------------------------------------------------
namespace asd {

static int32_t to_number(char16_t c1)
{
if (u'0' < c1 && c1 <= u'9') return c1 - u'0';
if (u'a' < c1 && c1 <= u'f') return c1 - u'a';
if (u'A' < c1 && c1 <= u'F') return c1 - u'A';
return 0;
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -95,6 +103,7 @@ namespace asd {
std::vector<asd::VertexLayout> vl;
vl.push_back(asd::VertexLayout("Pos", asd::VertexLayoutFormat::R32G32B32_FLOAT));
vl.push_back(asd::VertexLayout("UV", asd::VertexLayoutFormat::R32G32_FLOAT));
vl.push_back(asd::VertexLayout("UVSubA", asd::VertexLayoutFormat::R32G32_FLOAT));
vl.push_back(asd::VertexLayout("Color", asd::VertexLayoutFormat::R8G8B8A8_UNORM));

std::vector<asd::Macro> macro_tex;
Expand Down Expand Up @@ -263,39 +272,39 @@ namespace asd {
}
}

void Renderer2D_Imp::AddSpriteWithMaterial(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Material2D* material, AlphaBlendMode alphaBlend, int32_t priority)
void Renderer2D_Imp::AddSprite(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Texture2D* texture, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter, TextureWrapType wrap)
{
Event e;
e.Type = Event::EventType::Sprite;

e.Data.Sprite.IsLinearColor = false;
memcpy(e.Data.Sprite.Positions, positions, sizeof(asd::Vector2DF) * 4);
memcpy(e.Data.Sprite.Colors, colors, sizeof(asd::Color) * 4);
memcpy(e.Data.Sprite.UV, uv, sizeof(asd::Vector2DF) * 4);
e.Data.Sprite.AlphaBlendState = alphaBlend;
e.Data.Sprite.TexturePtr = nullptr;
e.Data.Sprite.Material2DPtr = material;
e.Data.Sprite.TexturePtr = texture;
e.Data.Sprite.Material2DPtr = nullptr;
e.Data.Sprite.Filter = filter;
e.Data.Sprite.Wrap = wrap;

SafeAddRef(e.Data.Sprite.TexturePtr);
SafeAddRef(e.Data.Sprite.Material2DPtr);

AddEvent(priority, e);
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void Renderer2D_Imp::AddSprite(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Texture2D* texture, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter, TextureWrapType wrap)
void Renderer2D_Imp::AddSpriteWithMaterial(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Vector2DF uvSub1[4], Texture2D* texture, Material2D* material, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter, TextureWrapType wrap)
{
Event e;
e.Type = Event::EventType::Sprite;

e.Data.Sprite.IsLinearColor = false;
memcpy(e.Data.Sprite.Positions, positions, sizeof(asd::Vector2DF) * 4);
memcpy(e.Data.Sprite.Colors, colors, sizeof(asd::Color) * 4);
memcpy(e.Data.Sprite.UV, uv, sizeof(asd::Vector2DF) * 4);
memcpy(e.Data.Sprite.UVSub1, uvSub1, sizeof(asd::Vector2DF) * 4);
e.Data.Sprite.AlphaBlendState = alphaBlend;
e.Data.Sprite.TexturePtr = texture;
e.Data.Sprite.Material2DPtr = nullptr;
e.Data.Sprite.Material2DPtr = material;
e.Data.Sprite.Filter = filter;
e.Data.Sprite.Wrap = wrap;

Expand All @@ -305,7 +314,12 @@ namespace asd {
AddEvent(priority, e);
}

void Renderer2D_Imp::AddText(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, TextureFilterType filter, TextureWrapType wrap)
void Renderer2D_Imp::AddText(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, bool isRichTextMode, TextureFilterType filter, TextureWrapType wrap)
{
AddTextWithMaterial(parentMatrix, matrix, centerPosition, turnLR, turnUL, color, font, text, nullptr, writingDirection, alphaBlend, priority, lineSpacing, letterSpacing, isRichTextMode, filter, wrap);
}

void Renderer2D_Imp::AddTextWithMaterial(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, Material2D* material, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, bool isRichTextMode, TextureFilterType filter, TextureWrapType wrap)
{
Vector2DF drawPosition = Vector2DF(0, 0);

Expand All @@ -321,15 +335,48 @@ namespace asd {
font_Imp->AddCharactorsDynamically(text);
font_Imp->UpdateTextureDynamically();

auto textSize = font_Imp->CalcTextureSize(text, writingDirection);

for (int textIndex = 0;; ++textIndex)
{
if (text[textIndex] == 0) break;

if (text[textIndex] != '\n' && !font_Imp->HasGlyphData(text[textIndex]))
if (isRichTextMode)
{
continue;
if (text[textIndex] == u'\\')
{
auto currentText = std::u16string(text + textIndex);

if (text[textIndex + 1] == u'\\')
{
// backslash x 2
textIndex++;
}
else if (currentText[1] == u'c' && currentText.size() > 10)
{
// backslash + c
textIndex += 2;

// load color
auto r = to_number(currentText[2]) * 16 + to_number(currentText[3]);
auto g = to_number(currentText[4]) * 16 + to_number(currentText[5]);
auto b = to_number(currentText[6]) * 16 + to_number(currentText[7]);
auto a = to_number(currentText[8]) * 16 + to_number(currentText[9]);

for (auto& c : colors)
{
c = Color(r, g, b, a);
}

textIndex += 8;
}
}
}
else if (text[textIndex] == '\n')

RectI glyphSrc;
Texture2D* texture = nullptr;

if (text[textIndex] == '\n')
{
if (writingDirection == WritingDirection::Horizontal)
{
Expand All @@ -345,17 +392,24 @@ namespace asd {

continue;
}
else if (font_Imp->GetImageGlyph(text[textIndex]) != nullptr)
{
texture = font_Imp->GetImageGlyph(text[textIndex]);
glyphSrc = RectI(0, 0, texture->GetSize().X, texture->GetSize().Y);
}
else if (font_Imp->HasGlyphData(text[textIndex]))
{
auto glyphData = font_Imp->GetGlyphData(text[textIndex]);
glyphSrc = glyphData.GetSrc();
texture = font_Imp->GetTexture(glyphData.GetSheetNum()).get();
}

const GlyphData glyphData = font_Imp->GetGlyphData(text[textIndex]);
auto texture = font_Imp->GetTexture(glyphData.GetSheetNum());


if (texture == nullptr)
{
continue;
}

const auto glyphSrc = glyphData.GetSrc();

std::array<Vector2DF, 4> position;

{
Expand Down Expand Up @@ -401,8 +455,21 @@ namespace asd {
std::swap(uvs.at(1), uvs.at(2));
}
}

std::array<Vector2DF, 4> uv_sub1s;
{
uv_sub1s.at(0) = Vector2DF(drawPosition.X, drawPosition.Y);
uv_sub1s.at(1) = Vector2DF(drawPosition.X + glyphSrc.Width, drawPosition.Y);
uv_sub1s.at(2) = Vector2DF(drawPosition.X + glyphSrc.Width, drawPosition.Y + glyphSrc.Height);
uv_sub1s.at(3) = Vector2DF(drawPosition.X, drawPosition.Y + glyphSrc.Height);

for (auto& uv : uv_sub1s)
{
uv /= textSize.To2DF();
}
}

AddSprite(position.data(), &colors[0], uvs.data(), texture.get(), alphaBlend, priority, filter, wrap);
AddSpriteWithMaterial(position.data(), &colors[0], uvs.data(), uv_sub1s.data(), texture, material, alphaBlend, priority, filter, wrap);

if (writingDirection == WritingDirection::Horizontal)
{
Expand Down Expand Up @@ -554,6 +621,8 @@ namespace asd {
buf[ind + i].Position.Z = 0.5f;
buf[ind + i].UV.X = e->Data.Sprite.UV[i].X;
buf[ind + i].UV.Y = e->Data.Sprite.UV[i].Y;
buf[ind + i].UVSub1.X = e->Data.Sprite.UVSub1[i].X;
buf[ind + i].UVSub1.Y = e->Data.Sprite.UVSub1[i].Y;

if (m_graphics->GetOption().ColorSpace == ColorSpaceType::GammaSpace)
{
Expand Down Expand Up @@ -635,6 +704,11 @@ namespace asd {
{
shader->SetTexture("g_texture", m_state.TexturePtr, m_state.Filter, m_state.Wrap, 0);
}
else if (m_state.Material2DPtr != nullptr && m_state.TexturePtr != nullptr)
{

}

m_graphics->SetVertexBuffer(m_vertexBuffer.get());
m_graphics->SetIndexBuffer(m_indexBuffer.get());
m_graphics->SetShader(shader);
Expand Down
10 changes: 7 additions & 3 deletions Dev/asd_cpp/core/Graphics/2D/asd.Renderer2D_Imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace asd {
{
Vector3DF Position;
Vector2DF UV;
Vector2DF UVSub1;
Color Color_;
};

Expand Down Expand Up @@ -78,6 +79,7 @@ namespace asd {
bool IsLinearColor;
color Colors[4];
vector2DF UV[4];
vector2DF UVSub1[4];
Texture2D* TexturePtr;
Material2D* Material2DPtr;
AlphaBlendMode AlphaBlendState;
Expand Down Expand Up @@ -157,11 +159,13 @@ namespace asd {

void ClearCache();

void AddSpriteWithMaterial(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Material2D* material, AlphaBlendMode alphaBlend, int32_t priority) override;

void AddSprite(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Texture2D* texture, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) override;

void AddText(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) override;
void AddSpriteWithMaterial(Vector2DF positions[4], Color colors[4], Vector2DF uv[4], Vector2DF uvSub1[4], Texture2D* texture, Material2D* material, AlphaBlendMode alphaBlend, int32_t priority, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) override;

void AddText(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, bool isRichTextMode, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) override;

void AddTextWithMaterial(Matrix33& parentMatrix, Matrix33& matrix, Vector2DF centerPosition, bool turnLR, bool turnUL, Color color, Font* font, const achar* text, Material2D* material, WritingDirection writingDirection, AlphaBlendMode alphaBlend, int32_t priority, float lineSpacing, float letterSpacing, bool isRichTextMode, TextureFilterType filter = TextureFilterType::Nearest, TextureWrapType wrap = TextureWrapType::Clamp) override;

void AddEffect(::Effekseer::Handle handle, int32_t priority);

Expand Down
19 changes: 19 additions & 0 deletions Dev/asd_cpp/core/Graphics/Resource/asd.Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,24 @@ namespace asd
@return 文字の描画領域
*/
virtual Vector2DI CalcTextureSize(const achar* text, WritingDirection writingDirection) = 0;

/**
@brief 指定した文字の代わりに画像を表示する組み合わせを追加する。
@param c 文字
@param texture 画像
*/
virtual void AddImageGlyph(const achar* c, Texture2D* texture) = 0;

#if !SWIG
/**
@brief 指定した文字の代わりに画像を表示する組み合わせを追加する。
@param c 文字
@param texture 画像
*/
void AddImageGlyph(const achar* c, std::shared_ptr<Texture2D> texture)
{
AddImageGlyph(c, texture.get());
}
#endif
};
}
19 changes: 16 additions & 3 deletions Dev/asd_cpp/core/Graphics/Resource/asd.Font_Imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,22 @@ namespace asd {
return m_glyphs.find(c) != m_glyphs.end();
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Texture2D* Font_Imp::GetImageGlyph(char16_t c)
{
auto imageGlyph = m_imageGlyphs.find(c);
if (imageGlyph == m_imageGlyphs.end()) return nullptr;
return (*imageGlyph).second.get();
}

void Font_Imp::AddImageGlyph(const achar* c, Texture2D* texture)
{
if (texture == nullptr) return;

SafeAddRef(texture);
auto image = CreateSharedPtrWithReleaseDLL(texture);
m_imageGlyphs[c[0]] = image;
}

void Font_Imp::Reload(const achar* affFilePathChar, std::vector<uint8_t> data)
{
if (isDynamic) return;
Expand Down
5 changes: 5 additions & 0 deletions Dev/asd_cpp/core/Graphics/Resource/asd.Font_Imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace asd {

std::vector<std::shared_ptr<Texture2D>> m_textures;
std::map<achar, GlyphData> m_glyphs;
std::map<char16_t, std::shared_ptr<Texture2D>> m_imageGlyphs;

public:

Expand Down Expand Up @@ -89,6 +90,10 @@ namespace asd {
GlyphData GetGlyphData(achar c);
bool HasGlyphData(achar c) const;

Texture2D* GetImageGlyph(char16_t c);

void AddImageGlyph(const achar* c, Texture2D* texture) override;

// リロード
void Reload(const achar* affFilePathChar, std::vector<uint8_t> data);
#endif
Expand Down
Loading

0 comments on commit 5e8636c

Please sign in to comment.