Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// File: PrimitiveBatch.cpp
|
|
|
|
//
|
|
|
|
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
|
|
|
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
|
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
|
|
|
// PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkId=248929
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "PrimitiveBatch.h"
|
2014-02-25 03:02:34 +04:00
|
|
|
#include "DirectXHelpers.h"
|
2015-12-18 23:07:55 +03:00
|
|
|
#include "GraphicsMemory.h"
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
#include "PlatformHelpers.h"
|
|
|
|
|
|
|
|
using namespace DirectX;
|
|
|
|
using namespace DirectX::Internal;
|
2015-07-11 05:46:54 +03:00
|
|
|
using Microsoft::WRL::ComPtr;
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Internal PrimitiveBatch implementation class.
|
|
|
|
class PrimitiveBatchBase::Impl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Impl(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize);
|
|
|
|
|
|
|
|
void Begin();
|
|
|
|
void End();
|
|
|
|
|
|
|
|
void Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void FlushBatch();
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
ComPtr<ID3D11DeviceContextX> mDeviceContext;
|
|
|
|
#else
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
ComPtr<ID3D11DeviceContext> mDeviceContext;
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
ComPtr<ID3D11Buffer> mIndexBuffer;
|
|
|
|
ComPtr<ID3D11Buffer> mVertexBuffer;
|
|
|
|
|
|
|
|
size_t mMaxIndices;
|
|
|
|
size_t mMaxVertices;
|
|
|
|
size_t mVertexSize;
|
|
|
|
|
|
|
|
bool mInBeginEndPair;
|
|
|
|
|
|
|
|
D3D11_PRIMITIVE_TOPOLOGY mCurrentTopology;
|
|
|
|
bool mCurrentlyIndexed;
|
|
|
|
|
|
|
|
size_t mCurrentIndex;
|
|
|
|
size_t mCurrentVertex;
|
|
|
|
|
|
|
|
size_t mBaseIndex;
|
|
|
|
size_t mBaseVertex;
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
void *grfxMemoryIB;
|
|
|
|
void *grfxMemoryVB;
|
|
|
|
#else
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
D3D11_MAPPED_SUBRESOURCE mMappedIndices;
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mMappedVertices;
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Helper for creating a D3D vertex or index buffer.
|
2015-12-18 23:07:55 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
static void CreateBuffer(_In_ ID3D11DeviceX* device, size_t bufferSize, D3D11_BIND_FLAG bindFlag, _Out_ ID3D11Buffer** pBuffer)
|
|
|
|
{
|
2016-04-30 04:58:08 +03:00
|
|
|
D3D11_BUFFER_DESC desc = {};
|
2015-12-18 23:07:55 +03:00
|
|
|
|
|
|
|
desc.ByteWidth = (UINT)bufferSize;
|
|
|
|
desc.BindFlags = bindFlag;
|
|
|
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
|
|
|
|
ThrowIfFailed(
|
|
|
|
device->CreatePlacementBuffer(&desc, nullptr, pBuffer)
|
|
|
|
);
|
|
|
|
|
|
|
|
SetDebugObjectName(*pBuffer, "DirectXTK:PrimitiveBatch");
|
|
|
|
}
|
|
|
|
#else
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
static void CreateBuffer(_In_ ID3D11Device* device, size_t bufferSize, D3D11_BIND_FLAG bindFlag, _Out_ ID3D11Buffer** pBuffer)
|
|
|
|
{
|
2016-04-30 04:58:08 +03:00
|
|
|
D3D11_BUFFER_DESC desc = {};
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
desc.ByteWidth = (UINT)bufferSize;
|
|
|
|
desc.BindFlags = bindFlag;
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
|
|
|
|
ThrowIfFailed(
|
|
|
|
device->CreateBuffer(&desc, nullptr, pBuffer)
|
|
|
|
);
|
|
|
|
|
2016-03-18 01:37:22 +03:00
|
|
|
_Analysis_assume_(*pBuffer != 0);
|
|
|
|
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
SetDebugObjectName(*pBuffer, "DirectXTK:PrimitiveBatch");
|
|
|
|
}
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Constructor.
|
|
|
|
PrimitiveBatchBase::Impl::Impl(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize)
|
2015-12-18 23:07:55 +03:00
|
|
|
: mMaxIndices(maxIndices),
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
mMaxVertices(maxVertices),
|
|
|
|
mVertexSize(vertexSize),
|
|
|
|
mInBeginEndPair(false),
|
|
|
|
mCurrentTopology(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED),
|
|
|
|
mCurrentlyIndexed(false),
|
|
|
|
mCurrentIndex(0),
|
|
|
|
mCurrentVertex(0),
|
|
|
|
mBaseIndex(0),
|
|
|
|
mBaseVertex(0)
|
|
|
|
{
|
|
|
|
ComPtr<ID3D11Device> device;
|
|
|
|
deviceContext->GetDevice(&device);
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
ThrowIfFailed(deviceContext->QueryInterface(IID_GRAPHICS_PPV_ARGS(mDeviceContext.GetAddressOf())));
|
|
|
|
|
|
|
|
ComPtr<ID3D11DeviceX> deviceX;
|
|
|
|
ThrowIfFailed(device.As(&deviceX));
|
|
|
|
|
|
|
|
// If you only intend to draw non-indexed geometry, specify maxIndices = 0 to skip creating the index buffer.
|
|
|
|
if (maxIndices > 0)
|
|
|
|
{
|
|
|
|
CreateBuffer(deviceX.Get(), maxIndices * sizeof(uint16_t), D3D11_BIND_INDEX_BUFFER, &mIndexBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the vertex buffer.
|
|
|
|
CreateBuffer(deviceX.Get(), maxVertices * vertexSize, D3D11_BIND_VERTEX_BUFFER, &mVertexBuffer);
|
|
|
|
|
|
|
|
grfxMemoryIB = grfxMemoryVB = nullptr;
|
|
|
|
#else
|
|
|
|
mDeviceContext = deviceContext;
|
|
|
|
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
// If you only intend to draw non-indexed geometry, specify maxIndices = 0 to skip creating the index buffer.
|
|
|
|
if (maxIndices > 0)
|
|
|
|
{
|
|
|
|
CreateBuffer(device.Get(), maxIndices * sizeof(uint16_t), D3D11_BIND_INDEX_BUFFER, &mIndexBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the vertex buffer.
|
|
|
|
CreateBuffer(device.Get(), maxVertices * vertexSize, D3D11_BIND_VERTEX_BUFFER, &mVertexBuffer);
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Begins a batch of primitive drawing operations.
|
|
|
|
void PrimitiveBatchBase::Impl::Begin()
|
|
|
|
{
|
|
|
|
if (mInBeginEndPair)
|
|
|
|
throw std::exception("Cannot nest Begin calls");
|
|
|
|
|
2016-05-09 23:32:14 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
mDeviceContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_UNKNOWN, 0);
|
|
|
|
#else
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
// Bind the index buffer.
|
|
|
|
if (mMaxIndices > 0)
|
|
|
|
{
|
|
|
|
mDeviceContext->IASetIndexBuffer(mIndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bind the vertex buffer.
|
|
|
|
auto vertexBuffer = mVertexBuffer.Get();
|
|
|
|
UINT vertexStride = (UINT)mVertexSize;
|
|
|
|
UINT vertexOffset = 0;
|
|
|
|
|
|
|
|
mDeviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &vertexStride, &vertexOffset);
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
// If this is a deferred D3D context, reset position so the first Map calls will use D3D11_MAP_WRITE_DISCARD.
|
|
|
|
if (mDeviceContext->GetType() == D3D11_DEVICE_CONTEXT_DEFERRED)
|
|
|
|
{
|
|
|
|
mCurrentIndex = 0;
|
|
|
|
mCurrentVertex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInBeginEndPair = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ends a batch of primitive drawing operations.
|
|
|
|
void PrimitiveBatchBase::Impl::End()
|
|
|
|
{
|
|
|
|
if (!mInBeginEndPair)
|
|
|
|
throw std::exception("Begin must be called before End");
|
|
|
|
|
|
|
|
FlushBatch();
|
|
|
|
|
|
|
|
mInBeginEndPair = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Can we combine adjacent primitives using this topology into a single draw call?
|
|
|
|
static bool CanBatchPrimitives(D3D11_PRIMITIVE_TOPOLOGY topology)
|
|
|
|
{
|
|
|
|
switch (topology)
|
|
|
|
{
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_POINTLIST:
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_LINELIST:
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST:
|
|
|
|
// Lists can easily be merged.
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Strips cannot.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could also merge indexed strips by inserting degenerates,
|
|
|
|
// but that's not always a perf win, so let's keep things simple.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
#if !defined(_XBOX_ONE) || !defined(_TITLE)
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
// Helper for locking a vertex or index buffer.
|
2016-04-30 05:59:49 +03:00
|
|
|
static void LockBuffer(_In_ ID3D11DeviceContext* deviceContext, _In_ ID3D11Buffer* buffer, size_t currentPosition, _Out_ size_t* basePosition, _Out_ D3D11_MAPPED_SUBRESOURCE* mappedResource)
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
{
|
|
|
|
D3D11_MAP mapType = (currentPosition == 0) ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
|
|
|
|
|
|
|
ThrowIfFailed(
|
|
|
|
deviceContext->Map(buffer, 0, mapType, 0, mappedResource)
|
|
|
|
);
|
|
|
|
|
|
|
|
*basePosition = currentPosition;
|
|
|
|
}
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Adds new geometry to the batch.
|
2016-04-30 05:23:07 +03:00
|
|
|
_Use_decl_annotations_
|
|
|
|
void PrimitiveBatchBase::Impl::Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, uint16_t const* indices, size_t indexCount, size_t vertexCount, void** pMappedVertices)
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
{
|
|
|
|
if (isIndexed && !indices)
|
|
|
|
throw std::exception("Indices cannot be null");
|
|
|
|
|
|
|
|
if (indexCount >= mMaxIndices)
|
|
|
|
throw std::exception("Too many indices");
|
|
|
|
|
|
|
|
if (vertexCount >= mMaxVertices)
|
|
|
|
throw std::exception("Too many vertices");
|
|
|
|
|
|
|
|
if (!mInBeginEndPair)
|
|
|
|
throw std::exception("Begin must be called before Draw");
|
|
|
|
|
|
|
|
// Can we merge this primitive in with an existing batch, or must we flush first?
|
|
|
|
bool wrapIndexBuffer = (mCurrentIndex + indexCount > mMaxIndices);
|
|
|
|
bool wrapVertexBuffer = (mCurrentVertex + vertexCount > mMaxVertices);
|
|
|
|
|
|
|
|
if ((topology != mCurrentTopology) ||
|
|
|
|
(isIndexed != mCurrentlyIndexed) ||
|
|
|
|
!CanBatchPrimitives(topology) ||
|
|
|
|
wrapIndexBuffer || wrapVertexBuffer)
|
|
|
|
{
|
|
|
|
FlushBatch();
|
|
|
|
}
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
if (mCurrentTopology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
|
|
|
|
{
|
|
|
|
auto& grfxMem = GraphicsMemory::Get();
|
|
|
|
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
grfxMemoryIB = grfxMem.Allocate(mDeviceContext.Get(), mMaxIndices * sizeof(uint16_t), 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
grfxMemoryVB = grfxMem.Allocate(mDeviceContext.Get(), mMaxVertices * mVertexSize, 64);
|
|
|
|
|
|
|
|
mCurrentTopology = topology;
|
|
|
|
mCurrentlyIndexed = isIndexed;
|
2016-05-09 23:32:14 +03:00
|
|
|
mCurrentIndex = mCurrentVertex = 0;
|
2015-12-18 23:07:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy over the index data.
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
assert(grfxMemoryIB != 0);
|
|
|
|
auto outputIndices = reinterpret_cast<uint16_t*>(grfxMemoryIB) + mCurrentIndex;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < indexCount; i++)
|
|
|
|
{
|
2016-05-09 23:32:14 +03:00
|
|
|
outputIndices[i] = (uint16_t)(indices[i] + mCurrentVertex);
|
2015-12-18 23:07:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentIndex += indexCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the output vertex data location.
|
|
|
|
assert(grfxMemoryVB != 0);
|
|
|
|
*pMappedVertices = reinterpret_cast<uint8_t*>(grfxMemoryVB) + (mCurrentVertex * mVertexSize);
|
|
|
|
|
|
|
|
mCurrentVertex += vertexCount;
|
|
|
|
#else
|
2016-05-09 23:32:14 +03:00
|
|
|
if (wrapIndexBuffer)
|
|
|
|
mCurrentIndex = 0;
|
|
|
|
|
|
|
|
if (wrapVertexBuffer)
|
|
|
|
mCurrentVertex = 0;
|
|
|
|
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
// If we are not already in a batch, lock the buffers.
|
|
|
|
if (mCurrentTopology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
|
|
|
|
{
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
LockBuffer(mDeviceContext.Get(), mIndexBuffer.Get(), mCurrentIndex, &mBaseIndex, &mMappedIndices);
|
|
|
|
}
|
|
|
|
|
|
|
|
LockBuffer(mDeviceContext.Get(), mVertexBuffer.Get(), mCurrentVertex, &mBaseVertex, &mMappedVertices);
|
|
|
|
|
|
|
|
mCurrentTopology = topology;
|
|
|
|
mCurrentlyIndexed = isIndexed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy over the index data.
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
2015-12-18 23:07:55 +03:00
|
|
|
auto outputIndices = reinterpret_cast<uint16_t*>(mMappedIndices.pData) + mCurrentIndex;
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
for (size_t i = 0; i < indexCount; i++)
|
|
|
|
{
|
|
|
|
outputIndices[i] = (uint16_t)(indices[i] + mCurrentVertex - mBaseVertex);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentIndex += indexCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the output vertex data location.
|
2015-12-18 23:07:55 +03:00
|
|
|
*pMappedVertices = reinterpret_cast<uint8_t*>(mMappedVertices.pData) + (mCurrentVertex * mVertexSize);
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
mCurrentVertex += vertexCount;
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sends queued primitives to the graphics device.
|
|
|
|
void PrimitiveBatchBase::Impl::FlushBatch()
|
|
|
|
{
|
|
|
|
// Early out if there is nothing to flush.
|
|
|
|
if (mCurrentTopology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mDeviceContext->IASetPrimitiveTopology(mCurrentTopology);
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
|
|
|
if (mCurrentlyIndexed)
|
|
|
|
{
|
|
|
|
// Draw indexed geometry.
|
|
|
|
mDeviceContext->IASetPlacementIndexBuffer(mIndexBuffer.Get(), grfxMemoryIB, DXGI_FORMAT_R16_UINT);
|
|
|
|
mDeviceContext->IASetPlacementVertexBuffer(0, mVertexBuffer.Get(), grfxMemoryVB, (UINT)mVertexSize);
|
|
|
|
|
2016-05-09 23:32:14 +03:00
|
|
|
mDeviceContext->DrawIndexed((UINT)mCurrentIndex, 0, 0);
|
2015-12-18 23:07:55 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Draw non-indexed geometry.
|
|
|
|
mDeviceContext->IASetPlacementVertexBuffer(0, mVertexBuffer.Get(), grfxMemoryVB, (UINT)mVertexSize);
|
|
|
|
|
2016-05-09 23:32:14 +03:00
|
|
|
mDeviceContext->Draw((UINT)mCurrentVertex, 0);
|
2015-12-18 23:07:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
grfxMemoryIB = grfxMemoryVB = nullptr;
|
|
|
|
#else
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
mDeviceContext->Unmap(mVertexBuffer.Get(), 0);
|
|
|
|
|
|
|
|
if (mCurrentlyIndexed)
|
|
|
|
{
|
|
|
|
// Draw indexed geometry.
|
|
|
|
mDeviceContext->Unmap(mIndexBuffer.Get(), 0);
|
|
|
|
|
|
|
|
mDeviceContext->DrawIndexed((UINT)(mCurrentIndex - mBaseIndex), (UINT)mBaseIndex, (UINT)mBaseVertex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Draw non-indexed geometry.
|
|
|
|
mDeviceContext->Draw((UINT)(mCurrentVertex - mBaseVertex), (UINT)mBaseVertex);
|
|
|
|
}
|
2015-12-18 23:07:55 +03:00
|
|
|
#endif
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
|
|
|
|
mCurrentTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Public constructor.
|
|
|
|
PrimitiveBatchBase::PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize)
|
|
|
|
: pImpl(new Impl(deviceContext, maxIndices, maxVertices, vertexSize))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Move constructor.
|
|
|
|
PrimitiveBatchBase::PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom)
|
|
|
|
: pImpl(std::move(moveFrom.pImpl))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Move assignment.
|
|
|
|
PrimitiveBatchBase& PrimitiveBatchBase::operator= (PrimitiveBatchBase&& moveFrom)
|
|
|
|
{
|
|
|
|
pImpl = std::move(moveFrom.pImpl);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Public destructor.
|
|
|
|
PrimitiveBatchBase::~PrimitiveBatchBase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrimitiveBatchBase::Begin()
|
|
|
|
{
|
|
|
|
pImpl->Begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrimitiveBatchBase::End()
|
|
|
|
{
|
|
|
|
pImpl->End();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-18 23:07:55 +03:00
|
|
|
_Use_decl_annotations_
|
|
|
|
void PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, uint16_t const* indices, size_t indexCount, size_t vertexCount, void** pMappedVertices)
|
Added PrimitiveBatch for drawing user primitives.
Also now set debug object names for all D3D resources (for PIX and debug layer leak reporting)
PrimitiveBatch is a helper for easily and efficiently drawing dynamically generated
geometry such as lines or trianges. It fills the same role as the legacy D3D9
APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. Dynamic submission is a highly
effective pattern for drawing procedural geometry, and convenient for debug
rendering, but is not nearly as efficient as static vertex buffers. Excessive
dynamic submission is a common source of performance problems in apps.
PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and
NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges
adjacent draw requests, so if you call DrawLine 100 times in a row, only a
single GPU draw call will be generated.
PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and
primitive topology, then issuing the final draw call. Unlike the higher level
SpriteBatch helper, it does not provide shaders, set the input layout, or set
any state objects. PrimitiveBatch is often used in conjunction with BasicEffect
and the structures from VertexTypes.h, but it can work with any other shader or
vertex formats of your own.
2012-10-12 20:45:08 +04:00
|
|
|
{
|
|
|
|
pImpl->Draw(topology, isIndexed, indices, indexCount, vertexCount, pMappedVertices);
|
|
|
|
}
|