Skip to content

Commit

Permalink
Update experimental graphics module
Browse files Browse the repository at this point in the history
  • Loading branch information
mogemimi committed Dec 30, 2015
1 parent 02f39f8 commit e225f16
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RenderLayer {
public:
virtual ~RenderLayer() = default;

virtual void Draw(GraphicsContext & graphicsContext, Renderer & renderer) = 0;
virtual void Draw(GraphicsCommandQueue & commandQueue, Renderer & renderer) = 0;

std::int32_t DrawOrder() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void RenderLayerCompositor::RemoveLayer(std::shared_ptr<RenderLayer> const& laye
layers.erase(std::remove(std::begin(layers), std::end(layers), layer), std::end(layers));
}
//-----------------------------------------------------------------------
void RenderLayerCompositor::Draw(GraphicsContext & graphicsContext, Renderer & renderer)
void RenderLayerCompositor::Draw(GraphicsCommandQueue & commandQueue, Renderer & renderer)
{
if (needToSort) {
std::sort(std::begin(layers), std::end(layers),
Expand All @@ -38,7 +38,7 @@ void RenderLayerCompositor::Draw(GraphicsContext & graphicsContext, Renderer & r

for (auto & layer: layers) {
POMDOG_ASSERT(layer);
layer->Draw(graphicsContext, renderer);
layer->Draw(commandQueue, renderer);
}
}
//-----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RenderLayerCompositor {

void RemoveLayer(std::shared_ptr<RenderLayer> const& layer);

void Draw(GraphicsContext & graphicsContext, Renderer & renderer);
void Draw(GraphicsCommandQueue & commandQueue, Renderer & renderer);

private:
std::vector<std::shared_ptr<RenderLayer>> layers;
Expand Down
7 changes: 4 additions & 3 deletions experimental/Pomdog.Experimental/Graphics/SkinnedEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Pomdog/Content/AssetBuilders/ShaderBuilder.hpp"
#include "Pomdog/Graphics/BlendDescription.hpp"
#include "Pomdog/Graphics/DepthStencilDescription.hpp"
#include "Pomdog/Graphics/GraphicsCommandList.hpp"
#include "Pomdog/Graphics/InputLayoutHelper.hpp"
#include "Pomdog/Graphics/Shader.hpp"

Expand All @@ -22,7 +23,7 @@ class SkinnedEffect::Impl {
public:
explicit Impl(GraphicsDevice & graphicsDevice, AssetManager & assets);

void Apply(GraphicsContext & graphicsContext);
void Apply(GraphicsCommandQueue & commandQueue);

public:
std::array<std::array<Vector4, 2>, SkinnedEffect::MaxBones> bones;
Expand Down Expand Up @@ -60,7 +61,7 @@ SkinnedEffect::Impl::Impl(GraphicsDevice & graphicsDevice,
constantBuffers = builder.CreateConstantBuffers(pipelineState);
}
//-----------------------------------------------------------------------
void SkinnedEffect::Impl::Apply(GraphicsContext & graphicsContext)
void SkinnedEffect::Impl::Apply(GraphicsCommandQueue & commandQueue)
{
struct alignas(16) Constants {
Matrix4x4 WorldViewProjection;
Expand Down Expand Up @@ -128,7 +129,7 @@ void SkinnedEffect::SetBoneTransforms(Matrix3x2 const* boneTransforms, std::size
}
}
//-----------------------------------------------------------------------
void SkinnedEffect::Apply(GraphicsContext & graphicsContext)
void SkinnedEffect::Apply(GraphicsCommandQueue & commandQueue)
{
POMDOG_ASSERT(impl);
impl->Apply(graphicsContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SkinnedEffect {

void SetBoneTransforms(Matrix3x2 const* boneTransforms, std::size_t count);

void Apply(GraphicsContext & graphicsContext);
void Apply(GraphicsCommandQueue & commandQueue);

static constexpr size_t MaxBones = 96;

Expand Down
15 changes: 8 additions & 7 deletions experimental/Pomdog.Experimental/Graphics/SpriteBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Pomdog/Graphics/BufferUsage.hpp"
#include "Pomdog/Graphics/ConstantBuffer.hpp"
#include "Pomdog/Graphics/DepthStencilDescription.hpp"
#include "Pomdog/Graphics/GraphicsCommandList.hpp"
#include "Pomdog/Graphics/IndexBuffer.hpp"
#include "Pomdog/Graphics/IndexElementSize.hpp"
#include "Pomdog/Graphics/InputLayoutHelper.hpp"
Expand Down Expand Up @@ -64,7 +65,7 @@ class SpriteBatch::Impl {
};

private:
std::shared_ptr<GraphicsContext> graphicsContext;
std::shared_ptr<GraphicsCommandList> commandList;

std::vector<std::vector<SpriteInfo>> spriteQueues;
std::vector<std::shared_ptr<Texture2D>> textures;
Expand All @@ -80,7 +81,7 @@ class SpriteBatch::Impl {
SpriteSortMode sortMode;

public:
Impl(std::shared_ptr<GraphicsContext> const& graphicsContext,
Impl(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
std::shared_ptr<PipelineState> const& pipelineState,
std::shared_ptr<ConstantBufferBinding> const& constantBuffers);
Expand All @@ -104,7 +105,7 @@ class SpriteBatch::Impl {
void DrawInstance(std::shared_ptr<Texture2D> const& texture, std::vector<SpriteInfo> const& sprites);
};
//-----------------------------------------------------------------------
SpriteBatch::Impl::Impl(std::shared_ptr<GraphicsContext> const& graphicsContextIn,
SpriteBatch::Impl::Impl(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
std::shared_ptr<PipelineState> const& pipelineStateIn,
std::shared_ptr<ConstantBufferBinding> const& constantBuffersIn)
Expand Down Expand Up @@ -260,8 +261,8 @@ void SpriteBatch::Impl::DrawInstance(std::shared_ptr<Texture2D> const& texture,
inverseTextureSize,
};

auto parameter = constantBuffers->Find("SpriteBatchConstants");
parameter->SetValue(info);
auto contantBuffer = constantBuffers->Find("SpriteBatchConstants");
contantBuffer->SetValue(info);
}

POMDOG_ASSERT(sprites.size() <= MaxBatchSize);
Expand Down Expand Up @@ -359,7 +360,7 @@ void SpriteBatch::Impl::Draw(std::shared_ptr<Texture2D> const& texture,
//-----------------------------------------------------------------------
// MARK: - SpriteBatch
//-----------------------------------------------------------------------
SpriteBatch::SpriteBatch(std::shared_ptr<GraphicsContext> const& graphicsContext,
SpriteBatch::SpriteBatch(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets)
{
Expand Down Expand Up @@ -393,7 +394,7 @@ SpriteBatch::SpriteBatch(std::shared_ptr<GraphicsContext> const& graphicsContext
impl = std::make_unique<Impl>(graphicsContext, graphicsDevice, pipelineState, constantBuffers);
}
//-----------------------------------------------------------------------
SpriteBatch::SpriteBatch(std::shared_ptr<GraphicsContext> const& graphicsContext,
SpriteBatch::SpriteBatch(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
std::shared_ptr<PipelineState> const& pipelineState,
std::shared_ptr<ConstantBufferBinding> const& constantBuffers)
Expand Down
57 changes: 37 additions & 20 deletions experimental/Pomdog.Experimental/Graphics/SpriteBatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "SpriteSortMode.hpp"
#include "Pomdog/Content/AssetManager.hpp"
#include "Pomdog/Graphics/ConstantBufferBinding.hpp"
#include "Pomdog/Graphics/GraphicsContext.hpp"
#include "Pomdog/Graphics/GraphicsDevice.hpp"
#include "Pomdog/Graphics/PipelineState.hpp"
#include "Pomdog/Graphics/Texture2D.hpp"
Expand All @@ -20,11 +18,11 @@ namespace Pomdog {

class SpriteBatch {
public:
SpriteBatch(std::shared_ptr<GraphicsContext> const& graphicsContext,
SpriteBatch(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets);

SpriteBatch(std::shared_ptr<GraphicsContext> const& graphicsContext,
SpriteBatch(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
std::shared_ptr<PipelineState> const& pipelineState,
std::shared_ptr<ConstantBufferBinding> const& constantBuffers);
Expand All @@ -35,22 +33,41 @@ class SpriteBatch {

void Begin(SpriteSortMode sortMode, Matrix4x4 const& transformMatrix);

void Draw(std::shared_ptr<Texture2D> const& texture,
Rectangle const& sourceRect, Color const& color);

void Draw(std::shared_ptr<Texture2D> const& texture,
Vector2 const& position, Color const& color);

void Draw(std::shared_ptr<Texture2D> const& texture,
Vector2 const& position, Rectangle const& sourceRect, Color const& color);

void Draw(std::shared_ptr<Texture2D> const& texture,
Vector2 const& position, Rectangle const& sourceRect, Color const& color,
Radian<float> const& rotation, Vector2 const& originPivot, float scale, float layerDepth);

void Draw(std::shared_ptr<Texture2D> const& texture,
Vector2 const& position, Rectangle const& sourceRect, Color const& color,
Radian<float> const& rotation, Vector2 const& originPivot, Vector2 const& scale, float layerDepth);
void Draw(
std::shared_ptr<Texture2D> const& texture,
Rectangle const& sourceRect,
Color const& color);

void Draw(
std::shared_ptr<Texture2D> const& texture,
Vector2 const& position,
Color const& color);

void Draw(
std::shared_ptr<Texture2D> const& texture,
Vector2 const& position,
Rectangle const& sourceRect,
Color const& color);

void Draw(
std::shared_ptr<Texture2D> const& texture,
Vector2 const& position,
Rectangle const& sourceRect,
Color const& color,
Radian<float> const& rotation,
Vector2 const& originPivot,
float scale,
float layerDepth);

void Draw(
std::shared_ptr<Texture2D> const& texture,
Vector2 const& position,
Rectangle const& sourceRect,
Color const& color,
Radian<float> const& rotation,
Vector2 const& originPivot,
Vector2 const& scale,
float layerDepth);

void End();

Expand Down
12 changes: 6 additions & 6 deletions experimental/Pomdog.Experimental/Graphics/SpriteRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "Pomdog/Graphics/BlendDescription.hpp"
#include "Pomdog/Graphics/BufferUsage.hpp"
#include "Pomdog/Graphics/ConstantBuffer.hpp"
#include "Pomdog/Graphics/ConstantBufferBinding.hpp"
#include "Pomdog/Graphics/DepthStencilDescription.hpp"
#include "Pomdog/Graphics/GraphicsCommandList.hpp"
#include "Pomdog/Graphics/IndexBuffer.hpp"
#include "Pomdog/Graphics/IndexElementSize.hpp"
#include "Pomdog/Graphics/InputLayoutHelper.hpp"
Expand Down Expand Up @@ -84,7 +84,7 @@ class SpriteRenderer::Impl {
SpriteSortMode sortMode;

public:
Impl(std::shared_ptr<GraphicsContext> const& graphicsContext,
Impl(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets);

Expand All @@ -109,7 +109,7 @@ class SpriteRenderer::Impl {
void DrawInstance(std::shared_ptr<Texture2D> const& texture, std::vector<SpriteInfo> const& sprites);
};
//-----------------------------------------------------------------------
SpriteRenderer::Impl::Impl(std::shared_ptr<GraphicsContext> const& graphicsContextIn,
SpriteRenderer::Impl::Impl(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets)
: graphicsContext(graphicsContextIn)
Expand Down Expand Up @@ -200,8 +200,8 @@ void SpriteRenderer::Impl::Begin(SpriteSortMode sortModeIn, Matrix4x4 const& tra
alignas(16) Matrix4x4 projection = Matrix4x4::Transpose(
transformMatrix * projectionMatrix);

auto parameter = constantBuffers->Find("Matrices");
parameter->SetValue(projection);
auto contantBuffer = constantBuffers->Find("Matrices");
contantBuffer->SetValue(projection);
}
//-----------------------------------------------------------------------
void SpriteRenderer::Impl::End()
Expand Down Expand Up @@ -351,7 +351,7 @@ void SpriteRenderer::Impl::Draw(std::shared_ptr<Texture2D> const& texture, Matri
//-----------------------------------------------------------------------
// MARK: - SpriteRenderer
//-----------------------------------------------------------------------
SpriteRenderer::SpriteRenderer(std::shared_ptr<GraphicsContext> const& graphicsContext,
SpriteRenderer::SpriteRenderer(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets)
: impl(std::make_unique<Impl>(graphicsContext, graphicsDevice, assets))
Expand Down
3 changes: 1 addition & 2 deletions experimental/Pomdog.Experimental/Graphics/SpriteRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "SpriteSortMode.hpp"
#include "Pomdog/Content/AssetManager.hpp"
#include "Pomdog/Graphics/GraphicsContext.hpp"
#include "Pomdog/Graphics/GraphicsDevice.hpp"
#include "Pomdog/Graphics/Texture2D.hpp"
#include "Pomdog/Math/Color.hpp"
Expand All @@ -19,7 +18,7 @@ namespace Pomdog {

class SpriteRenderer {
public:
SpriteRenderer(std::shared_ptr<GraphicsContext> const& graphicsContext,
SpriteRenderer(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ InGameEditor::InGameEditor(std::shared_ptr<GameHost> const& gameHostIn)
: hierarchy(gameHostIn->Window())
, gameHost(gameHostIn)
{
auto graphicsContext = gameHost->GraphicsContext();
auto graphicsDevice = gameHost->GraphicsDevice();
auto assets = gameHost->AssetManager();
auto window = gameHost->Window();

{
spriteBatch = std::make_unique<SpriteBatch>(graphicsContext, graphicsDevice, *assets);
spriteBatch = std::make_unique<SpriteBatch>(graphicsDevice, *assets);
//spriteFont = SpriteFontLoader::Load(*assets, "BitmapFonts/UbuntuMono-Regular.fnt");
spriteFont = SpriteFontLoader::Load(*assets, "BitmapFonts/Ubuntu-Regular.fnt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,37 @@ static Matrix3x2 CreateTransformMatrix(Particle const& particle)
} // unnamed namespace
//-----------------------------------------------------------------------
ParticleBatchCommandProcessor::ParticleBatchCommandProcessor(
std::shared_ptr<GraphicsContext> const& graphicsContext,
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets)
: spriteBatch(graphicsContext, graphicsDevice, assets)
: spriteBatch(graphicsDevice, assets)
, drawCallCount(0)
{
}
//-----------------------------------------------------------------------
void ParticleBatchCommandProcessor::Begin(GraphicsContext & graphicsContext)
void ParticleBatchCommandProcessor::Begin(GraphicsCommandQueue &)
{
drawCallCount = 0;

spriteBatch.Begin(Matrix4x4::Identity);
}
//-----------------------------------------------------------------------
void ParticleBatchCommandProcessor::Draw(GraphicsContext & graphicsContext, RenderCommand & command)
void ParticleBatchCommandProcessor::Draw(GraphicsCommandQueue & commandQueue, RenderCommand & command)
{
using Detail::Rendering::ParticleBatchCommand;

auto & particleCommand = static_cast<ParticleBatchCommand &>(command);
for (auto & particle: *particleCommand.particles)
{
auto transform = CreateTransformMatrix(particle);
spriteBatch.Draw(particleCommand.texture, transform,
particleCommand.textureRegion.Subrect, particle.Color, {0.5f, 0.5f});
spriteBatch.Draw(
particleCommand.texture,
transform,
particleCommand.textureRegion.Subrect,
particle.Color,
{0.5f, 0.5f});
}
}
//-----------------------------------------------------------------------
void ParticleBatchCommandProcessor::End(GraphicsContext & graphicsContext)
void ParticleBatchCommandProcessor::End(GraphicsCommandQueue & commandQueue)
{
spriteBatch.End();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace Pomdog {

class ParticleBatchCommandProcessor final: public RenderCommandProcessor {
public:
ParticleBatchCommandProcessor(std::shared_ptr<GraphicsContext> const& graphicsContext,
ParticleBatchCommandProcessor(
std::shared_ptr<GraphicsDevice> const& graphicsDevice,
AssetManager & assets);

void Begin(GraphicsContext & graphicsContext) override;
void Begin(GraphicsCommandQueue & commandQueue) override;

void Draw(GraphicsContext & graphicsContext, RenderCommand & command) override;
void Draw(GraphicsCommandQueue & commandQueue, RenderCommand & command) override;

void End(GraphicsContext & graphicsContext) override;
void End(GraphicsCommandQueue & commandQueue) override;

int DrawCallCount() const override;

Expand Down
Loading

0 comments on commit e225f16

Please sign in to comment.