2024-04-14 16:11:15 -03:00
|
|
|
#include "blendstate-dx.hpp"
|
2024-04-14 21:23:09 -03:00
|
|
|
#include "device-dx.hpp"
|
2024-04-14 16:11:15 -03:00
|
|
|
#include "rasterizerstate-dx.hpp"
|
2024-04-15 09:53:26 -03:00
|
|
|
#include "depthstencilstate-dx.hpp"
|
2024-04-14 21:23:09 -03:00
|
|
|
#include "samplerstate-dx.hpp"
|
|
|
|
#include "spritebatch-dx.hpp"
|
2024-04-14 16:11:15 -03:00
|
|
|
#include "texture-dx.hpp"
|
|
|
|
|
|
|
|
using DxSpriteBatch = DirectX::SpriteBatch;
|
|
|
|
using DxSpriteSortMode = DirectX::SpriteSortMode;
|
|
|
|
using DxMatrix = DirectX::FXMMATRIX;
|
|
|
|
using DxSpriteEffects = DirectX::SpriteEffects;
|
|
|
|
using DirectX::XMFLOAT2;
|
|
|
|
using DirectX::FXMVECTOR;
|
|
|
|
using DirectX::XMVECTORF32;
|
|
|
|
using DirectX::GXMVECTOR;
|
|
|
|
|
|
|
|
namespace xna {
|
|
|
|
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
|
2024-04-25 14:51:33 -03:00
|
|
|
if (!device._context)
|
|
|
|
return;
|
|
|
|
|
2024-04-14 16:11:15 -03:00
|
|
|
_dxspriteBatch = New<DxSpriteBatch>(device._context);
|
|
|
|
|
|
|
|
Viewport(device.Viewport());
|
|
|
|
}
|
|
|
|
|
2024-04-15 09:53:26 -03:00
|
|
|
void SpriteBatch::Begin(SpriteSortMode sortMode, BlendState* blendState, SamplerState* samplerState, DepthStencilState* depthStencil, RasterizerState* rasterizerState, Matrix const& transformMatrix) {
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DxSpriteSortMode sort;
|
|
|
|
ConvertSpriteSort(sortMode, sort);
|
|
|
|
|
|
|
|
const auto& t = transformMatrix;
|
|
|
|
DxMatrix matrix = DxMatrix(
|
|
|
|
t.M11, t.M12, t.M13, t.M14,
|
|
|
|
t.M21, t.M22, t.M23, t.M24,
|
|
|
|
t.M31, t.M32, t.M33, t.M34,
|
|
|
|
t.M41, t.M42, t.M43, t.M44);
|
|
|
|
|
|
|
|
|
|
|
|
_dxspriteBatch->Begin(
|
|
|
|
sort,
|
2024-04-24 14:40:14 -03:00
|
|
|
blendState ? blendState->dxBlendState : nullptr,
|
2024-04-14 16:11:15 -03:00
|
|
|
samplerState ? samplerState->_samplerState : nullptr,
|
2024-04-25 14:51:33 -03:00
|
|
|
depthStencil ? depthStencil->dxDepthStencil : nullptr,
|
|
|
|
rasterizerState ? rasterizerState->dxRasterizerState : nullptr,
|
2024-04-14 16:11:15 -03:00
|
|
|
nullptr,
|
|
|
|
matrix
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::End() {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_dxspriteBatch->End();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Color const& color) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
2024-04-14 16:11:15 -03:00
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
_dxspriteBatch->Draw(
|
2024-05-04 21:07:39 -03:00
|
|
|
texture.dxShaderResourceView,
|
2024-04-14 16:11:15 -03:00
|
|
|
_position,
|
|
|
|
_color
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
2024-04-14 16:11:15 -03:00
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
RECT _sourceRect{};
|
|
|
|
|
|
|
|
if (sourceRectangle) {
|
|
|
|
_sourceRect.top = sourceRectangle->Y;
|
|
|
|
_sourceRect.left = sourceRectangle->X;
|
|
|
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
|
|
|
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
|
|
|
|
};
|
|
|
|
|
|
|
|
_dxspriteBatch->Draw(
|
2024-05-04 21:07:39 -03:00
|
|
|
texture.dxShaderResourceView,
|
2024-04-14 16:11:15 -03:00
|
|
|
_position,
|
|
|
|
sourceRectangle ? &_sourceRect : nullptr,
|
|
|
|
_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
|
|
|
const auto _origin = XMFLOAT2(origin.X, origin.Y);
|
2024-04-14 16:11:15 -03:00
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
RECT _sourceRect{};
|
|
|
|
|
|
|
|
if (sourceRectangle) {
|
|
|
|
_sourceRect.top = sourceRectangle->Y;
|
|
|
|
_sourceRect.left = sourceRectangle->X;
|
|
|
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
|
|
|
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
|
|
|
|
};
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
const DxSpriteEffects _effects = static_cast<DxSpriteEffects>(effects);
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
_dxspriteBatch->Draw(
|
2024-05-04 21:07:39 -03:00
|
|
|
texture.dxShaderResourceView,
|
2024-04-14 16:11:15 -03:00
|
|
|
_position,
|
|
|
|
sourceRectangle ? &_sourceRect : nullptr,
|
|
|
|
_color,
|
|
|
|
rotation,
|
|
|
|
_origin,
|
|
|
|
scale,
|
|
|
|
_effects,
|
|
|
|
layerDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
|
|
|
const auto _origin = XMFLOAT2(origin.X, origin.Y);
|
2024-04-14 16:11:15 -03:00
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
RECT _sourceRect{};
|
|
|
|
|
|
|
|
if (sourceRectangle) {
|
|
|
|
_sourceRect.top = sourceRectangle->Y;
|
|
|
|
_sourceRect.left = sourceRectangle->X;
|
|
|
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
|
|
|
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
|
|
|
|
};
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
const auto _effects = static_cast<DxSpriteEffects>(effects);
|
2024-04-14 16:11:15 -03:00
|
|
|
const XMFLOAT2 _scale = { scale.X, scale.Y };
|
|
|
|
|
|
|
|
_dxspriteBatch->Draw(
|
2024-05-04 21:07:39 -03:00
|
|
|
texture.dxShaderResourceView,
|
2024-04-14 16:11:15 -03:00
|
|
|
_position,
|
|
|
|
sourceRectangle ? &_sourceRect : nullptr,
|
|
|
|
_color,
|
|
|
|
rotation,
|
|
|
|
_origin,
|
|
|
|
_scale,
|
|
|
|
_effects,
|
|
|
|
layerDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Color const& color) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
|
|
|
RECT _destinationRect{};
|
|
|
|
_destinationRect.left = destinationRectangle.X;
|
|
|
|
_destinationRect.top = destinationRectangle.Y;
|
|
|
|
_destinationRect.right = destinationRectangle.X + destinationRectangle.Width;
|
|
|
|
_destinationRect.bottom = destinationRectangle.Y + destinationRectangle.Height;
|
|
|
|
|
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
_dxspriteBatch->Draw(texture.dxShaderResourceView, _destinationRect, _color);
|
2024-04-14 16:11:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
|
|
|
RECT _destinationRect{};
|
|
|
|
_destinationRect.left = destinationRectangle.X;
|
|
|
|
_destinationRect.top = destinationRectangle.Y;
|
|
|
|
_destinationRect.right = destinationRectangle.X + destinationRectangle.Width;
|
|
|
|
_destinationRect.bottom = destinationRectangle.Y + destinationRectangle.Height;
|
|
|
|
|
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
RECT _sourceRect{};
|
|
|
|
|
|
|
|
if (sourceRectangle) {
|
|
|
|
_sourceRect.top = sourceRectangle->Y;
|
|
|
|
_sourceRect.left = sourceRectangle->X;
|
|
|
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
|
|
|
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
|
|
|
|
};
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
_dxspriteBatch->Draw(texture.dxShaderResourceView, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color);
|
2024-04-14 16:11:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!texture.dxShaderResourceView)
|
2024-04-14 16:11:15 -03:00
|
|
|
return;
|
|
|
|
|
|
|
|
RECT _destinationRect{};
|
|
|
|
_destinationRect.left = destinationRectangle.X;
|
|
|
|
_destinationRect.top = destinationRectangle.Y;
|
|
|
|
_destinationRect.right = destinationRectangle.X + destinationRectangle.Width;
|
|
|
|
_destinationRect.bottom = destinationRectangle.Y + destinationRectangle.Height;
|
|
|
|
|
|
|
|
const auto v4 = color.ToVector4();
|
2024-04-14 21:23:09 -03:00
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
RECT _sourceRect{};
|
|
|
|
|
|
|
|
if (sourceRectangle) {
|
|
|
|
_sourceRect.top = sourceRectangle->Y;
|
|
|
|
_sourceRect.left = sourceRectangle->X;
|
|
|
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
|
|
|
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto _origin = XMFLOAT2(origin.X, origin.Y);
|
2024-04-14 21:23:09 -03:00
|
|
|
const auto _effects = static_cast<DxSpriteEffects>(effects);
|
2024-04-14 16:11:15 -03:00
|
|
|
|
|
|
|
_dxspriteBatch->Draw(
|
2024-05-04 21:07:39 -03:00
|
|
|
texture.dxShaderResourceView,
|
2024-04-14 16:11:15 -03:00
|
|
|
_destinationRect,
|
|
|
|
sourceRectangle ? &_sourceRect : nullptr,
|
|
|
|
_color,
|
|
|
|
rotation,
|
|
|
|
_origin,
|
|
|
|
_effects,
|
|
|
|
layerDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::Viewport(xna::Viewport const& value) {
|
|
|
|
if (!_dxspriteBatch)
|
|
|
|
return;
|
|
|
|
|
|
|
|
D3D11_VIEWPORT _view{};
|
|
|
|
_view.TopLeftX = value.X;
|
|
|
|
_view.TopLeftY = value.Y;
|
|
|
|
_view.Width = value.Width;
|
|
|
|
_view.Height = value.Height;
|
|
|
|
_view.MinDepth = value.MinDetph;
|
|
|
|
_view.MaxDepth = value.MaxDepth;
|
|
|
|
|
|
|
|
_dxspriteBatch->SetViewport(_view);
|
|
|
|
}
|
2024-04-14 21:23:09 -03:00
|
|
|
|
|
|
|
void SpriteBatch::DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color) {
|
|
|
|
if (!_dxspriteBatch || !spriteFont._dxSpriteFont)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
|
|
|
const auto v4 = color.ToVector4();
|
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
|
|
|
|
|
|
|
spriteFont._dxSpriteFont->DrawString(
|
|
|
|
_dxspriteBatch.get(),
|
|
|
|
text.c_str(),
|
|
|
|
_position,
|
|
|
|
_color
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatch::DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position,
|
|
|
|
Color const& color, float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) {
|
|
|
|
if (!_dxspriteBatch || !spriteFont._dxSpriteFont)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
|
|
|
const auto _origin = XMFLOAT2(origin.X, origin.Y);
|
|
|
|
const auto v4 = color.ToVector4();
|
|
|
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
|
|
|
const auto _effects = static_cast<DxSpriteEffects>(effects);
|
|
|
|
|
|
|
|
spriteFont._dxSpriteFont->DrawString(
|
|
|
|
_dxspriteBatch.get(),
|
|
|
|
text.c_str(),
|
|
|
|
_position,
|
|
|
|
_color,
|
|
|
|
rotation,
|
|
|
|
_origin,
|
|
|
|
scale,
|
|
|
|
_effects,
|
|
|
|
layerDepth
|
|
|
|
);
|
|
|
|
}
|
2024-04-14 16:11:15 -03:00
|
|
|
}
|