Linux: Remove xmmintrin.h usage

This commit is contained in:
Sour 2018-06-19 17:24:07 -04:00
parent 3736cc108c
commit 106c3c908a
3 changed files with 10 additions and 100 deletions

View file

@ -216,9 +216,8 @@ void SdlRenderer::DrawPauseScreen(bool disableOverlay)
SDL_FreeSurface(surf);
}
XMVECTOR stringDimensions = _largeFont->MeasureString(L"PAUSE");
float* measureF = (float*)&stringDimensions;
_largeFont->DrawString(_sdlRenderer, L"PAUSE", (int)(_screenWidth / 2 - measureF[0] / 2), (int)(_screenHeight / 2 - measureF[1] / 2 - 8), 250, 235, 215);
XMFLOAT2 size = _largeFont->MeasureString(L"PAUSE");
_largeFont->DrawString(_sdlRenderer, L"PAUSE", (int)(_screenWidth / 2 - size.x / 2), (int)(_screenHeight / 2 - size.y / 2 - 8), 250, 235, 215);
string utf8Message = EmulationSettings::GetPauseScreenMessage();
if(utf8Message.size() > 0) {
@ -237,9 +236,7 @@ void SdlRenderer::DrawString(std::wstring message, int x, int y, uint8_t r, uint
float SdlRenderer::MeasureString(std::wstring text)
{
XMVECTOR measure = _spriteFont->MeasureString(text.c_str());
float* measureF = (float*)&measure;
return measureF[0];
return _spriteFont->MeasureString(text.c_str()).x;
}
bool SdlRenderer::ContainsCharacter(wchar_t character)

View file

@ -25,29 +25,6 @@
#include "SpriteFont.h"
XMVECTOR XMVectorMax(FXMVECTOR V1,FXMVECTOR V2)
{
return _mm_max_ps( V1, V2 );
}
XMVECTOR XMVectorSet(float x, float y, float z, float w)
{
return _mm_set_ps( w, z, y, x );
}
XMVECTOR XMVectorZero()
{
return _mm_setzero_ps();
}
#define XM_PERMUTE_PS( v, c ) _mm_shuffle_ps( v, v, c )
void XMStoreFloat2(XMFLOAT2* pDestination, FXMVECTOR V)
{
XMVECTOR T = XM_PERMUTE_PS( V, _MM_SHUFFLE( 1, 1, 1, 1 ) );
_mm_store_ss( &pDestination->x, V );
_mm_store_ss( &pDestination->y, T );
}
// Internal SpriteFont implementation class.
class SpriteFont::Impl
{
@ -251,9 +228,9 @@ void SpriteFont::DrawString(SDL_Renderer *renderer, wchar_t const* text, int x,
});
}
XMVECTOR SpriteFont::MeasureString(wchar_t const* text) const
XMFLOAT2 SpriteFont::MeasureString(wchar_t const* text) const
{
XMVECTOR result = XMVectorZero();
XMFLOAT2 result;
pImpl->ForEachGlyph(text, [&](Glyph const* glyph, float x, float y, float advance)
{
@ -262,86 +239,35 @@ XMVECTOR SpriteFont::MeasureString(wchar_t const* text) const
h = std::max(h, pImpl->lineSpacing);
result = XMVectorMax(result, XMVectorSet(x + w, y + h, 0, 0));
result.x = std::max(result.x, x + w);
result.y = std::max(result.y, y + h);
});
return result;
}
RECT SpriteFont::MeasureDrawBounds(wchar_t const* text, XMFLOAT2 const& position) const
{
RECT result = { UINT32_MAX, UINT32_MAX, 0, 0 };
pImpl->ForEachGlyph(text, [&](Glyph const* glyph, float x, float y, float advance)
{
float w = (float)(glyph->Subrect.right - glyph->Subrect.left);
float h = (float)(glyph->Subrect.bottom - glyph->Subrect.top);
float minX = position.x + x;
float minY = position.y + y + glyph->YOffset;
float maxX = std::max(minX + advance, minX + w);
float maxY = minY + h;
if (minX < result.left)
result.left = long(minX);
if (minY < result.top)
result.top = long(minY);
if (result.right < maxX)
result.right = long(maxX);
if (result.bottom < maxY)
result.bottom = long(maxY);
});
if (result.left == UINT32_MAX)
{
result.left = 0;
result.top = 0;
}
return result;
}
RECT SpriteFont::MeasureDrawBounds(wchar_t const* text, FXMVECTOR position) const
{
XMFLOAT2 pos;
XMStoreFloat2(&pos, position);
return MeasureDrawBounds(text, pos);
}
// Spacing properties
float SpriteFont::GetLineSpacing() const
{
return pImpl->lineSpacing;
}
void SpriteFont::SetLineSpacing(float spacing)
{
pImpl->lineSpacing = spacing;
}
// Font properties
wchar_t SpriteFont::GetDefaultCharacter() const
{
return pImpl->defaultGlyph ? (wchar_t)pImpl->defaultGlyph->Character : 0;
}
void SpriteFont::SetDefaultCharacter(wchar_t character)
{
pImpl->SetDefaultCharacter(character);
}
bool SpriteFont::ContainsCharacter(wchar_t character) const
{
return std::binary_search(pImpl->glyphs.begin(), pImpl->glyphs.end(), character);

View file

@ -19,7 +19,6 @@
#pragma once
#include <xmmintrin.h>
#include <SDL2/SDL.h>
#include <string>
#include <memory>
@ -30,10 +29,6 @@
#include <string>
using std::string;
#define FXMVECTOR __m128
#define GXMVECTOR __m128
#define XMVECTOR __m128
struct RECT
{
uint32_t left;
@ -44,8 +39,8 @@ struct RECT
struct XMFLOAT2
{
float x;
float y;
float x = 0.0f;
float y = 0.0f;
XMFLOAT2() {}
XMFLOAT2(float _x, float _y) : x(_x), y(_y) {}
@ -54,11 +49,6 @@ struct XMFLOAT2
XMFLOAT2& operator= (const XMFLOAT2& Float2) { x = Float2.x; y = Float2.y; return *this; }
};
XMVECTOR XMVectorMax(FXMVECTOR V1,FXMVECTOR V2);
XMVECTOR XMVectorSet(float x, float y, float z, float w);
XMVECTOR XMVectorZero();
void XMStoreFloat2(XMFLOAT2* pDestination, FXMVECTOR V);
class SpriteFont
{
public:
@ -76,10 +66,7 @@ public:
void DrawString(SDL_Renderer *renderer, wchar_t const* text, int x, int y, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255) const;
XMVECTOR MeasureString(wchar_t const* text) const;
RECT MeasureDrawBounds(wchar_t const* text, XMFLOAT2 const& position) const;
RECT MeasureDrawBounds(wchar_t const* text, FXMVECTOR position) const;
XMFLOAT2 MeasureString(wchar_t const* text) const;
// Spacing properties
float GetLineSpacing() const;