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:
parent
d21d93eaf8
commit
0065bf80e9
@ -123,17 +123,17 @@ namespace xna {
|
|||||||
impl->_dxSpriteFont->SetLineSpacing(static_cast<float>(value));
|
impl->_dxSpriteFont->SetLineSpacing(static_cast<float>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
|
SpriteBatch::SpriteBatch(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||||
if (!device.impl->_context)
|
if (!device->impl->_context)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
implementation = uNew<PlatformImplementation>();
|
implementation = uNew<PlatformImplementation>();
|
||||||
implementation->_dxspriteBatch = New<DxSpriteBatch>(
|
implementation->_dxspriteBatch = New<DxSpriteBatch>(
|
||||||
//ID3D11DeviceContext* deviceContext
|
//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) {
|
void SpriteBatch::Begin(SpriteSortMode sortMode, BlendState* blendState, SamplerState* samplerState, DepthStencilState* depthStencil, RasterizerState* rasterizerState, Matrix const& transformMatrix) {
|
||||||
|
@ -5,11 +5,15 @@
|
|||||||
#include "../common/numerics.hpp"
|
#include "../common/numerics.hpp"
|
||||||
#include "../common/color.hpp"
|
#include "../common/color.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include "../graphics/gresource.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class SpriteBatch {
|
//Enables a group of sprites to be drawn using the same settings.
|
||||||
|
class SpriteBatch : public GraphicsResource {
|
||||||
public:
|
public:
|
||||||
SpriteBatch(GraphicsDevice& device);
|
SpriteBatch(sptr<GraphicsDevice> const& device);
|
||||||
|
|
||||||
|
//Begins a sprite batch operation.
|
||||||
void Begin(
|
void Begin(
|
||||||
SpriteSortMode sortMode = SpriteSortMode::Deferred,
|
SpriteSortMode sortMode = SpriteSortMode::Deferred,
|
||||||
BlendState* blendState = nullptr,
|
BlendState* blendState = nullptr,
|
||||||
@ -19,8 +23,14 @@ namespace xna {
|
|||||||
//Effect
|
//Effect
|
||||||
Matrix const& transformMatrix = Matrix::Identity()
|
Matrix const& transformMatrix = Matrix::Identity()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Flushes the sprite batch and restores the device state to how it was before Begin was called.
|
||||||
void End();
|
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(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(sptr<Texture2D> const& texture, Vector2 const& position, Color const& color) { Draw(*texture, position, color); }
|
||||||
void Draw(Texture2D& texture, Vector2 const& position, Color const& 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,
|
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color,
|
||||||
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth);
|
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(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(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);
|
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color);
|
||||||
|
@ -25,7 +25,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoadContent() override {
|
void LoadContent() override {
|
||||||
spriteBatch = New<SpriteBatch>(*graphicsDevice);
|
spriteBatch = New<SpriteBatch>(graphicsDevice);
|
||||||
auto texture = Content()->Load<PTexture2D>("Idle");
|
auto texture = Content()->Load<PTexture2D>("Idle");
|
||||||
Game::LoadContent();
|
Game::LoadContent();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace PlatformerStarterKit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoadContent() override {
|
void LoadContent() override {
|
||||||
spriteBatch = New<SpriteBatch>(*graphicsDevice);
|
spriteBatch = New<SpriteBatch>(graphicsDevice);
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");
|
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user