1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Implementa SpriteBatch com um GraphicsResource

This commit is contained in:
Danilo 2024-06-06 14:28:00 -03:00
parent d21d93eaf8
commit 0065bf80e9
4 changed files with 22 additions and 8 deletions

View File

@ -123,17 +123,17 @@ namespace xna {
impl->_dxSpriteFont->SetLineSpacing(static_cast<float>(value));
}
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
if (!device.impl->_context)
SpriteBatch::SpriteBatch(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
if (!device->impl->_context)
return;
implementation = uNew<PlatformImplementation>();
implementation->_dxspriteBatch = New<DxSpriteBatch>(
//ID3D11DeviceContext* deviceContext
device.impl->_context
device->impl->_context
);
Viewport(device.Viewport());
Viewport(device->Viewport());
}
void SpriteBatch::Begin(SpriteSortMode sortMode, BlendState* blendState, SamplerState* samplerState, DepthStencilState* depthStencil, RasterizerState* rasterizerState, Matrix const& transformMatrix) {

View File

@ -5,11 +5,15 @@
#include "../common/numerics.hpp"
#include "../common/color.hpp"
#include <optional>
#include "../graphics/gresource.hpp"
namespace xna {
class SpriteBatch {
//Enables a group of sprites to be drawn using the same settings.
class SpriteBatch : public GraphicsResource {
public:
SpriteBatch(GraphicsDevice& device);
SpriteBatch(sptr<GraphicsDevice> const& device);
//Begins a sprite batch operation.
void Begin(
SpriteSortMode sortMode = SpriteSortMode::Deferred,
BlendState* blendState = nullptr,
@ -19,8 +23,14 @@ namespace xna {
//Effect
Matrix const& transformMatrix = Matrix::Identity()
);
//Flushes the sprite batch and restores the device state to how it was before Begin was called.
void End();
//
// Draw - Adds a sprite to a batch of sprites to be rendered.
//
void Draw(uptr<Texture2D> const& texture, Vector2 const& position, Color const& color) { Draw(*texture, position, color); }
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Color const& color) { Draw(*texture, position, color); }
void Draw(Texture2D& texture, Vector2 const& position, Color const& color);
@ -58,6 +68,10 @@ namespace xna {
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth);
//
// DrawString - Adds a string to a batch of sprites to be rendered.
//
void DrawString(uptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color) { DrawString(*spriteFont, text, position, color); }
void DrawString(sptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color) { DrawString(*spriteFont, text, position, color); }
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color);

View File

@ -25,7 +25,7 @@ namespace xna {
}
void LoadContent() override {
spriteBatch = New<SpriteBatch>(*graphicsDevice);
spriteBatch = New<SpriteBatch>(graphicsDevice);
auto texture = Content()->Load<PTexture2D>("Idle");
Game::LoadContent();
}

View File

@ -31,7 +31,7 @@ namespace PlatformerStarterKit {
}
void LoadContent() override {
spriteBatch = New<SpriteBatch>(*graphicsDevice);
spriteBatch = New<SpriteBatch>(graphicsDevice);
// Load fonts
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");