|
|
@@ -57,7 +57,6 @@
|
|
|
#include "../../Graphics/Texture3D.h"
|
|
|
#include "../../Graphics/TextureCube.h"
|
|
|
#include "../../Graphics/VertexBuffer.h"
|
|
|
-#include "../../Graphics/VertexDeclaration.h"
|
|
|
#include "../../Graphics/Zone.h"
|
|
|
#include "../../IO/File.h"
|
|
|
#include "../../IO/Log.h"
|
|
|
@@ -242,7 +241,6 @@ Graphics::Graphics(Context* context) :
|
|
|
numBatches_(0),
|
|
|
maxScratchBufferRequest_(0),
|
|
|
defaultTextureFilterMode_(FILTER_TRILINEAR),
|
|
|
- shaderProgram_(0),
|
|
|
shaderPath_("Shaders/HLSL/"),
|
|
|
shaderExtension_(".hlsl"),
|
|
|
orientations_("LandscapeLeft LandscapeRight"),
|
|
|
@@ -269,8 +267,8 @@ Graphics::~Graphics()
|
|
|
gpuObjects_.Clear();
|
|
|
}
|
|
|
|
|
|
- vertexDeclarations_.Clear();
|
|
|
- constantBuffers_.Clear();
|
|
|
+ impl_->vertexDeclarations_.Clear();
|
|
|
+ impl_->allConstantBuffers_.Clear();
|
|
|
|
|
|
for (HashMap<unsigned, ID3D11BlendState*>::Iterator i = impl_->blendStates_.Begin(); i != impl_->blendStates_.End(); ++i)
|
|
|
{
|
|
|
@@ -783,7 +781,7 @@ bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
|
|
|
|
|
|
void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
|
|
|
{
|
|
|
- if (!vertexCount || !shaderProgram_)
|
|
|
+ if (!vertexCount || !impl_->shaderProgram_)
|
|
|
return;
|
|
|
|
|
|
PrepareDraw();
|
|
|
@@ -808,7 +806,7 @@ void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCou
|
|
|
|
|
|
void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount)
|
|
|
{
|
|
|
- if (!vertexCount || !shaderProgram_)
|
|
|
+ if (!vertexCount || !impl_->shaderProgram_)
|
|
|
return;
|
|
|
|
|
|
PrepareDraw();
|
|
|
@@ -833,7 +831,7 @@ void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount
|
|
|
|
|
|
void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount)
|
|
|
{
|
|
|
- if (!vertexCount || !shaderProgram_)
|
|
|
+ if (!vertexCount || !impl_->shaderProgram_)
|
|
|
return;
|
|
|
|
|
|
PrepareDraw();
|
|
|
@@ -859,7 +857,7 @@ void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount
|
|
|
void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount,
|
|
|
unsigned instanceCount)
|
|
|
{
|
|
|
- if (!indexCount || !instanceCount || !shaderProgram_)
|
|
|
+ if (!indexCount || !instanceCount || !impl_->shaderProgram_)
|
|
|
return;
|
|
|
|
|
|
PrepareDraw();
|
|
|
@@ -885,7 +883,7 @@ void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned i
|
|
|
void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount,
|
|
|
unsigned instanceCount)
|
|
|
{
|
|
|
- if (!indexCount || !instanceCount || !shaderProgram_)
|
|
|
+ if (!indexCount || !instanceCount || !impl_->shaderProgram_)
|
|
|
return;
|
|
|
|
|
|
PrepareDraw();
|
|
|
@@ -957,16 +955,16 @@ bool Graphics::SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, unsigne
|
|
|
|
|
|
if (changed)
|
|
|
{
|
|
|
- vertexDeclarationDirty_ = true;
|
|
|
+ impl_->vertexDeclarationDirty_ = true;
|
|
|
|
|
|
- if (firstDirtyVB_ == M_MAX_UNSIGNED)
|
|
|
- firstDirtyVB_ = lastDirtyVB_ = i;
|
|
|
+ if (impl_->firstDirtyVB_ == M_MAX_UNSIGNED)
|
|
|
+ impl_->firstDirtyVB_ = impl_->lastDirtyVB_ = i;
|
|
|
else
|
|
|
{
|
|
|
- if (i < firstDirtyVB_)
|
|
|
- firstDirtyVB_ = i;
|
|
|
- if (i > lastDirtyVB_)
|
|
|
- lastDirtyVB_ = i;
|
|
|
+ if (i < impl_->firstDirtyVB_)
|
|
|
+ impl_->firstDirtyVB_ = i;
|
|
|
+ if (i > impl_->lastDirtyVB_)
|
|
|
+ impl_->lastDirtyVB_ = i;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1029,7 +1027,7 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
|
|
|
|
|
|
impl_->deviceContext_->VSSetShader((ID3D11VertexShader*)(vs ? vs->GetGPUObject() : 0), 0, 0);
|
|
|
vertexShader_ = vs;
|
|
|
- vertexDeclarationDirty_ = true;
|
|
|
+ impl_->vertexDeclarationDirty_ = true;
|
|
|
}
|
|
|
|
|
|
if (ps != pixelShader_)
|
|
|
@@ -1059,13 +1057,13 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
|
|
|
if (vertexShader_ && pixelShader_)
|
|
|
{
|
|
|
Pair<ShaderVariation*, ShaderVariation*> key = MakePair(vertexShader_, pixelShader_);
|
|
|
- ShaderProgramMap::Iterator i = shaderPrograms_.Find(key);
|
|
|
- if (i != shaderPrograms_.End())
|
|
|
- shaderProgram_ = i->second_.Get();
|
|
|
+ ShaderProgramMap::Iterator i = impl_->shaderPrograms_.Find(key);
|
|
|
+ if (i != impl_->shaderPrograms_.End())
|
|
|
+ impl_->shaderProgram_ = i->second_.Get();
|
|
|
else
|
|
|
{
|
|
|
- ShaderProgram* newProgram = shaderPrograms_[key] = new ShaderProgram(this, vertexShader_, pixelShader_);
|
|
|
- shaderProgram_ = newProgram;
|
|
|
+ ShaderProgram* newProgram = impl_->shaderPrograms_[key] = new ShaderProgram(this, vertexShader_, pixelShader_);
|
|
|
+ impl_->shaderProgram_ = newProgram;
|
|
|
}
|
|
|
|
|
|
bool vsBuffersChanged = false;
|
|
|
@@ -1073,7 +1071,7 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
|
|
|
|
|
|
for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
|
|
|
{
|
|
|
- ID3D11Buffer* vsBuffer = shaderProgram_->vsConstantBuffers_[i] ? (ID3D11Buffer*)shaderProgram_->vsConstantBuffers_[i]->
|
|
|
+ ID3D11Buffer* vsBuffer = impl_->shaderProgram_->vsConstantBuffers_[i] ? (ID3D11Buffer*)impl_->shaderProgram_->vsConstantBuffers_[i]->
|
|
|
GetGPUObject() : 0;
|
|
|
if (vsBuffer != impl_->constantBuffers_[VS][i])
|
|
|
{
|
|
|
@@ -1082,7 +1080,7 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
|
|
|
vsBuffersChanged = true;
|
|
|
}
|
|
|
|
|
|
- ID3D11Buffer* psBuffer = shaderProgram_->psConstantBuffers_[i] ? (ID3D11Buffer*)shaderProgram_->psConstantBuffers_[i]->
|
|
|
+ ID3D11Buffer* psBuffer = impl_->shaderProgram_->psConstantBuffers_[i] ? (ID3D11Buffer*)impl_->shaderProgram_->psConstantBuffers_[i]->
|
|
|
GetGPUObject() : 0;
|
|
|
if (psBuffer != impl_->constantBuffers_[PS][i])
|
|
|
{
|
|
|
@@ -1098,7 +1096,7 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
|
|
|
impl_->deviceContext_->PSSetConstantBuffers(0, MAX_SHADER_PARAMETER_GROUPS, &impl_->constantBuffers_[PS][0]);
|
|
|
}
|
|
|
else
|
|
|
- shaderProgram_ = 0;
|
|
|
+ impl_->shaderProgram_ = 0;
|
|
|
|
|
|
// Store shader combination if shader dumping in progress
|
|
|
if (shaderPrecache_)
|
|
|
@@ -1112,120 +1110,120 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
|
|
|
void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, (unsigned)(count * sizeof(float)), data);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, float value)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(float), &value);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, bool value)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(bool), &value);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Color& color)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(Color), &color);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Vector2& vector)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(Vector2), &vector);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Matrix3& matrix)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetVector3ArrayParameter(i->second_.offset_, 3, &matrix);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Vector3& vector)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(Vector3), &vector);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Matrix4& matrix)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(Matrix4), &matrix);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Vector4& vector)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(Vector4), &vector);
|
|
|
}
|
|
|
|
|
|
void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
|
|
|
{
|
|
|
HashMap<StringHash, ShaderParameter>::Iterator i;
|
|
|
- if (!shaderProgram_ || (i = shaderProgram_->parameters_.Find(param)) == shaderProgram_->parameters_.End())
|
|
|
+ if (!impl_->shaderProgram_ || (i = impl_->shaderProgram_->parameters_.Find(param)) == impl_->shaderProgram_->parameters_.End())
|
|
|
return;
|
|
|
|
|
|
ConstantBuffer* buffer = i->second_.bufferPtr_;
|
|
|
if (!buffer->IsDirty())
|
|
|
- dirtyConstantBuffers_.Push(buffer);
|
|
|
+ impl_->dirtyConstantBuffers_.Push(buffer);
|
|
|
buffer->SetParameter(i->second_.offset_, sizeof(Matrix3x4), &matrix);
|
|
|
}
|
|
|
|
|
|
@@ -1296,7 +1294,7 @@ bool Graphics::NeedParameterUpdate(ShaderParameterGroup group, const void* sourc
|
|
|
|
|
|
bool Graphics::HasShaderParameter(StringHash param)
|
|
|
{
|
|
|
- return shaderProgram_ && shaderProgram_->parameters_.Find(param) != shaderProgram_->parameters_.End();
|
|
|
+ return impl_->shaderProgram_ && impl_->shaderProgram_->parameters_.Find(param) != impl_->shaderProgram_->parameters_.End();
|
|
|
}
|
|
|
|
|
|
bool Graphics::HasTextureUnit(TextureUnit unit)
|
|
|
@@ -1341,20 +1339,20 @@ void Graphics::SetTexture(unsigned index, Texture* texture)
|
|
|
|
|
|
if (texture != textures_[index])
|
|
|
{
|
|
|
- if (firstDirtyTexture_ == M_MAX_UNSIGNED)
|
|
|
- firstDirtyTexture_ = lastDirtyTexture_ = index;
|
|
|
+ if (impl_->firstDirtyTexture_ == M_MAX_UNSIGNED)
|
|
|
+ impl_->firstDirtyTexture_ = impl_->lastDirtyTexture_ = index;
|
|
|
else
|
|
|
{
|
|
|
- if (index < firstDirtyTexture_)
|
|
|
- firstDirtyTexture_ = index;
|
|
|
- if (index > lastDirtyTexture_)
|
|
|
- lastDirtyTexture_ = index;
|
|
|
+ if (index < impl_->firstDirtyTexture_)
|
|
|
+ impl_->firstDirtyTexture_ = index;
|
|
|
+ if (index > impl_->lastDirtyTexture_)
|
|
|
+ impl_->lastDirtyTexture_ = index;
|
|
|
}
|
|
|
|
|
|
textures_[index] = texture;
|
|
|
impl_->shaderResourceViews_[index] = texture ? (ID3D11ShaderResourceView*)texture->GetShaderResourceView() : 0;
|
|
|
impl_->samplers_[index] = texture ? (ID3D11SamplerState*)texture->GetSampler() : 0;
|
|
|
- texturesDirty_ = true;
|
|
|
+ impl_->texturesDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1414,7 +1412,7 @@ void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
|
|
|
if (renderTarget != renderTargets_[index])
|
|
|
{
|
|
|
renderTargets_[index] = renderTarget;
|
|
|
- renderTargetsDirty_ = true;
|
|
|
+ impl_->renderTargetsDirty_ = true;
|
|
|
|
|
|
// If the rendertarget is also bound as a texture, replace with backup texture or null
|
|
|
if (renderTarget)
|
|
|
@@ -1444,7 +1442,7 @@ void Graphics::SetDepthStencil(RenderSurface* depthStencil)
|
|
|
if (depthStencil != depthStencil_)
|
|
|
{
|
|
|
depthStencil_ = depthStencil;
|
|
|
- renderTargetsDirty_ = true;
|
|
|
+ impl_->renderTargetsDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1456,7 +1454,7 @@ void Graphics::SetDepthStencil(Texture2D* texture)
|
|
|
|
|
|
SetDepthStencil(depthStencil);
|
|
|
// Constant depth bias depends on the bitdepth
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
}
|
|
|
|
|
|
void Graphics::SetViewport(const IntRect& rect)
|
|
|
@@ -1495,7 +1493,7 @@ void Graphics::SetBlendMode(BlendMode mode)
|
|
|
if (mode != blendMode_)
|
|
|
{
|
|
|
blendMode_ = mode;
|
|
|
- blendStateDirty_ = true;
|
|
|
+ impl_->blendStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1504,7 +1502,7 @@ void Graphics::SetColorWrite(bool enable)
|
|
|
if (enable != colorWrite_)
|
|
|
{
|
|
|
colorWrite_ = enable;
|
|
|
- blendStateDirty_ = true;
|
|
|
+ impl_->blendStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1513,7 +1511,7 @@ void Graphics::SetCullMode(CullMode mode)
|
|
|
if (mode != cullMode_)
|
|
|
{
|
|
|
cullMode_ = mode;
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1523,7 +1521,7 @@ void Graphics::SetDepthBias(float constantBias, float slopeScaledBias)
|
|
|
{
|
|
|
constantDepthBias_ = constantBias;
|
|
|
slopeScaledDepthBias_ = slopeScaledBias;
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1532,7 +1530,7 @@ void Graphics::SetDepthTest(CompareMode mode)
|
|
|
if (mode != depthTestMode_)
|
|
|
{
|
|
|
depthTestMode_ = mode;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1541,9 +1539,9 @@ void Graphics::SetDepthWrite(bool enable)
|
|
|
if (enable != depthWrite_)
|
|
|
{
|
|
|
depthWrite_ = enable;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
// Also affects whether a read-only version of depth-stencil should be bound, to allow sampling
|
|
|
- renderTargetsDirty_ = true;
|
|
|
+ impl_->renderTargetsDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1552,7 +1550,7 @@ void Graphics::SetFillMode(FillMode mode)
|
|
|
if (mode != fillMode_)
|
|
|
{
|
|
|
fillMode_ = mode;
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1587,14 +1585,14 @@ void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusiv
|
|
|
if (enable && intRect != scissorRect_)
|
|
|
{
|
|
|
scissorRect_ = intRect;
|
|
|
- scissorRectDirty_ = true;
|
|
|
+ impl_->scissorRectDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (enable != scissorTest_)
|
|
|
{
|
|
|
scissorTest_ = enable;
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1622,14 +1620,14 @@ void Graphics::SetScissorTest(bool enable, const IntRect& rect)
|
|
|
if (enable && intRect != scissorRect_)
|
|
|
{
|
|
|
scissorRect_ = intRect;
|
|
|
- scissorRectDirty_ = true;
|
|
|
+ impl_->scissorRectDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (enable != scissorTest_)
|
|
|
{
|
|
|
scissorTest_ = enable;
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1639,7 +1637,7 @@ void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, Ste
|
|
|
if (enable != stencilTest_)
|
|
|
{
|
|
|
stencilTest_ = enable;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
|
|
|
if (enable)
|
|
|
@@ -1647,38 +1645,38 @@ void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, Ste
|
|
|
if (mode != stencilTestMode_)
|
|
|
{
|
|
|
stencilTestMode_ = mode;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
if (pass != stencilPass_)
|
|
|
{
|
|
|
stencilPass_ = pass;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
if (fail != stencilFail_)
|
|
|
{
|
|
|
stencilFail_ = fail;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
if (zFail != stencilZFail_)
|
|
|
{
|
|
|
stencilZFail_ = zFail;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
if (compareMask != stencilCompareMask_)
|
|
|
{
|
|
|
stencilCompareMask_ = compareMask;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
if (writeMask != stencilWriteMask_)
|
|
|
{
|
|
|
stencilWriteMask_ = writeMask;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
if (stencilRef != stencilRef_)
|
|
|
{
|
|
|
stencilRef_ = stencilRef;
|
|
|
- stencilRefDirty_ = true;
|
|
|
- depthStateDirty_ = true;
|
|
|
+ impl_->stencilRefDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1882,7 +1880,7 @@ IntVector2 Graphics::GetRenderTargetDimensions() const
|
|
|
return IntVector2(width, height);
|
|
|
}
|
|
|
|
|
|
-void Graphics::WindowResized()
|
|
|
+void Graphics::OnWindowResized()
|
|
|
{
|
|
|
if (!impl_->device_ || !impl_->window_)
|
|
|
return;
|
|
|
@@ -1911,7 +1909,7 @@ void Graphics::WindowResized()
|
|
|
SendEvent(E_SCREENMODE, eventData);
|
|
|
}
|
|
|
|
|
|
-void Graphics::WindowMoved()
|
|
|
+void Graphics::OnWindowMoved()
|
|
|
{
|
|
|
if (!impl_->device_ || !impl_->window_ || fullscreen_)
|
|
|
return;
|
|
|
@@ -2044,30 +2042,30 @@ void Graphics::CleanupScratchBuffers()
|
|
|
|
|
|
void Graphics::CleanUpShaderPrograms(ShaderVariation* variation)
|
|
|
{
|
|
|
- for (ShaderProgramMap::Iterator i = shaderPrograms_.Begin(); i != shaderPrograms_.End();)
|
|
|
+ for (ShaderProgramMap::Iterator i = impl_->shaderPrograms_.Begin(); i != impl_->shaderPrograms_.End();)
|
|
|
{
|
|
|
if (i->first_.first_ == variation || i->first_.second_ == variation)
|
|
|
- i = shaderPrograms_.Erase(i);
|
|
|
+ i = impl_->shaderPrograms_.Erase(i);
|
|
|
else
|
|
|
++i;
|
|
|
}
|
|
|
|
|
|
if (vertexShader_ == variation || pixelShader_ == variation)
|
|
|
- shaderProgram_ = 0;
|
|
|
+ impl_->shaderProgram_ = 0;
|
|
|
}
|
|
|
|
|
|
ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size)
|
|
|
{
|
|
|
// Ensure that different shader types and index slots get unique buffers, even if the size is same
|
|
|
unsigned key = type | (index << 1) | (size << 4);
|
|
|
- HashMap<unsigned, SharedPtr<ConstantBuffer> >::Iterator i = constantBuffers_.Find(key);
|
|
|
- if (i != constantBuffers_.End())
|
|
|
+ ConstantBufferMap::Iterator i = impl_->allConstantBuffers_.Find(key);
|
|
|
+ if (i != impl_->allConstantBuffers_.End())
|
|
|
return i->second_.Get();
|
|
|
else
|
|
|
{
|
|
|
SharedPtr<ConstantBuffer> newConstantBuffer(new ConstantBuffer(context_));
|
|
|
newConstantBuffer->SetSize(size);
|
|
|
- constantBuffers_[key] = newConstantBuffer;
|
|
|
+ impl_->allConstantBuffers_[key] = newConstantBuffer;
|
|
|
return newConstantBuffer.Get();
|
|
|
}
|
|
|
}
|
|
|
@@ -2373,7 +2371,7 @@ bool Graphics::UpdateSwapChain(int width, int height)
|
|
|
impl_->depthStencilView_ = 0;
|
|
|
for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
|
|
|
impl_->renderTargetViews_[i] = 0;
|
|
|
- renderTargetsDirty_ = true;
|
|
|
+ impl_->renderTargetsDirty_ = true;
|
|
|
|
|
|
impl_->swapChain_->ResizeBuffers(1, (UINT)width, (UINT)height, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
|
|
|
|
|
|
@@ -2489,7 +2487,6 @@ void Graphics::ResetCachedState()
|
|
|
primitiveType_ = 0;
|
|
|
vertexShader_ = 0;
|
|
|
pixelShader_ = 0;
|
|
|
- shaderProgram_ = 0;
|
|
|
blendMode_ = BLEND_REPLACE;
|
|
|
textureAnisotropy_ = 1;
|
|
|
colorWrite_ = true;
|
|
|
@@ -2510,25 +2507,26 @@ void Graphics::ResetCachedState()
|
|
|
stencilCompareMask_ = M_MAX_UNSIGNED;
|
|
|
stencilWriteMask_ = M_MAX_UNSIGNED;
|
|
|
useClipPlane_ = false;
|
|
|
- renderTargetsDirty_ = true;
|
|
|
- texturesDirty_ = true;
|
|
|
- vertexDeclarationDirty_ = true;
|
|
|
- blendStateDirty_ = true;
|
|
|
- depthStateDirty_ = true;
|
|
|
- rasterizerStateDirty_ = true;
|
|
|
- scissorRectDirty_ = true;
|
|
|
- stencilRefDirty_ = true;
|
|
|
- blendStateHash_ = M_MAX_UNSIGNED;
|
|
|
- depthStateHash_ = M_MAX_UNSIGNED;
|
|
|
- rasterizerStateHash_ = M_MAX_UNSIGNED;
|
|
|
- firstDirtyTexture_ = lastDirtyTexture_ = M_MAX_UNSIGNED;
|
|
|
- firstDirtyVB_ = lastDirtyVB_ = M_MAX_UNSIGNED;
|
|
|
- dirtyConstantBuffers_.Clear();
|
|
|
+ impl_->shaderProgram_ = 0;
|
|
|
+ impl_->renderTargetsDirty_ = true;
|
|
|
+ impl_->texturesDirty_ = true;
|
|
|
+ impl_->vertexDeclarationDirty_ = true;
|
|
|
+ impl_->blendStateDirty_ = true;
|
|
|
+ impl_->depthStateDirty_ = true;
|
|
|
+ impl_->rasterizerStateDirty_ = true;
|
|
|
+ impl_->scissorRectDirty_ = true;
|
|
|
+ impl_->stencilRefDirty_ = true;
|
|
|
+ impl_->blendStateHash_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->depthStateHash_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->rasterizerStateHash_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->firstDirtyTexture_ = impl_->lastDirtyTexture_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->firstDirtyVB_ = impl_->lastDirtyVB_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->dirtyConstantBuffers_.Clear();
|
|
|
}
|
|
|
|
|
|
void Graphics::PrepareDraw()
|
|
|
{
|
|
|
- if (renderTargetsDirty_)
|
|
|
+ if (impl_->renderTargetsDirty_)
|
|
|
{
|
|
|
impl_->depthStencilView_ =
|
|
|
(depthStencil_ && depthStencil_->GetUsage() == TEXTURE_DEPTHSTENCIL) ?
|
|
|
@@ -2550,33 +2548,33 @@ void Graphics::PrepareDraw()
|
|
|
impl_->renderTargetViews_[0] = impl_->defaultRenderTargetView_;
|
|
|
|
|
|
impl_->deviceContext_->OMSetRenderTargets(MAX_RENDERTARGETS, &impl_->renderTargetViews_[0], impl_->depthStencilView_);
|
|
|
- renderTargetsDirty_ = false;
|
|
|
+ impl_->renderTargetsDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- if (texturesDirty_ && firstDirtyTexture_ < M_MAX_UNSIGNED)
|
|
|
+ if (impl_->texturesDirty_ && impl_->firstDirtyTexture_ < M_MAX_UNSIGNED)
|
|
|
{
|
|
|
// Set also VS textures to enable vertex texture fetch to work the same way as on OpenGL
|
|
|
- impl_->deviceContext_->VSSetShaderResources(firstDirtyTexture_, lastDirtyTexture_ - firstDirtyTexture_ + 1,
|
|
|
- &impl_->shaderResourceViews_[firstDirtyTexture_]);
|
|
|
- impl_->deviceContext_->VSSetSamplers(firstDirtyTexture_, lastDirtyTexture_ - firstDirtyTexture_ + 1,
|
|
|
- &impl_->samplers_[firstDirtyTexture_]);
|
|
|
- impl_->deviceContext_->PSSetShaderResources(firstDirtyTexture_, lastDirtyTexture_ - firstDirtyTexture_ + 1,
|
|
|
- &impl_->shaderResourceViews_[firstDirtyTexture_]);
|
|
|
- impl_->deviceContext_->PSSetSamplers(firstDirtyTexture_, lastDirtyTexture_ - firstDirtyTexture_ + 1,
|
|
|
- &impl_->samplers_[firstDirtyTexture_]);
|
|
|
+ impl_->deviceContext_->VSSetShaderResources(impl_->firstDirtyTexture_, impl_->lastDirtyTexture_ - impl_->firstDirtyTexture_ + 1,
|
|
|
+ &impl_->shaderResourceViews_[impl_->firstDirtyTexture_]);
|
|
|
+ impl_->deviceContext_->VSSetSamplers(impl_->firstDirtyTexture_, impl_->lastDirtyTexture_ - impl_->firstDirtyTexture_ + 1,
|
|
|
+ &impl_->samplers_[impl_->firstDirtyTexture_]);
|
|
|
+ impl_->deviceContext_->PSSetShaderResources(impl_->firstDirtyTexture_, impl_->lastDirtyTexture_ - impl_->firstDirtyTexture_ + 1,
|
|
|
+ &impl_->shaderResourceViews_[impl_->firstDirtyTexture_]);
|
|
|
+ impl_->deviceContext_->PSSetSamplers(impl_->firstDirtyTexture_, impl_->lastDirtyTexture_ - impl_->firstDirtyTexture_ + 1,
|
|
|
+ &impl_->samplers_[impl_->firstDirtyTexture_]);
|
|
|
|
|
|
- firstDirtyTexture_ = lastDirtyTexture_ = M_MAX_UNSIGNED;
|
|
|
- texturesDirty_ = false;
|
|
|
+ impl_->firstDirtyTexture_ = impl_->lastDirtyTexture_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->texturesDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- if (vertexDeclarationDirty_ && vertexShader_ && vertexShader_->GetByteCode().Size())
|
|
|
+ if (impl_->vertexDeclarationDirty_ && vertexShader_ && vertexShader_->GetByteCode().Size())
|
|
|
{
|
|
|
- if (firstDirtyVB_ < M_MAX_UNSIGNED)
|
|
|
+ if (impl_->firstDirtyVB_ < M_MAX_UNSIGNED)
|
|
|
{
|
|
|
- impl_->deviceContext_->IASetVertexBuffers(firstDirtyVB_, lastDirtyVB_ - firstDirtyVB_ + 1,
|
|
|
- &impl_->vertexBuffers_[firstDirtyVB_], &impl_->vertexSizes_[firstDirtyVB_], &impl_->vertexOffsets_[firstDirtyVB_]);
|
|
|
+ impl_->deviceContext_->IASetVertexBuffers(impl_->firstDirtyVB_, impl_->lastDirtyVB_ - impl_->firstDirtyVB_ + 1,
|
|
|
+ &impl_->vertexBuffers_[impl_->firstDirtyVB_], &impl_->vertexSizes_[impl_->firstDirtyVB_], &impl_->vertexOffsets_[impl_->firstDirtyVB_]);
|
|
|
|
|
|
- firstDirtyVB_ = lastDirtyVB_ = M_MAX_UNSIGNED;
|
|
|
+ impl_->firstDirtyVB_ = impl_->lastDirtyVB_ = M_MAX_UNSIGNED;
|
|
|
}
|
|
|
|
|
|
unsigned long long newVertexDeclarationHash = 0;
|
|
|
@@ -2592,25 +2590,25 @@ void Graphics::PrepareDraw()
|
|
|
newVertexDeclarationHash += vertexShader_->GetElementHash();
|
|
|
if (newVertexDeclarationHash != vertexDeclarationHash_)
|
|
|
{
|
|
|
- HashMap<unsigned long long, SharedPtr<VertexDeclaration> >::Iterator i =
|
|
|
- vertexDeclarations_.Find(newVertexDeclarationHash);
|
|
|
- if (i == vertexDeclarations_.End())
|
|
|
+ VertexDeclarationMap::Iterator i =
|
|
|
+ impl_->vertexDeclarations_.Find(newVertexDeclarationHash);
|
|
|
+ if (i == impl_->vertexDeclarations_.End())
|
|
|
{
|
|
|
SharedPtr<VertexDeclaration> newVertexDeclaration(new VertexDeclaration(this, vertexShader_, vertexBuffers_));
|
|
|
- i = vertexDeclarations_.Insert(MakePair(newVertexDeclarationHash, newVertexDeclaration));
|
|
|
+ i = impl_->vertexDeclarations_.Insert(MakePair(newVertexDeclarationHash, newVertexDeclaration));
|
|
|
}
|
|
|
impl_->deviceContext_->IASetInputLayout((ID3D11InputLayout*)i->second_->GetInputLayout());
|
|
|
vertexDeclarationHash_ = newVertexDeclarationHash;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- vertexDeclarationDirty_ = false;
|
|
|
+ impl_->vertexDeclarationDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- if (blendStateDirty_)
|
|
|
+ if (impl_->blendStateDirty_)
|
|
|
{
|
|
|
unsigned newBlendStateHash = (unsigned)((colorWrite_ ? 1 : 0) | (blendMode_ << 1));
|
|
|
- if (newBlendStateHash != blendStateHash_)
|
|
|
+ if (newBlendStateHash != impl_->blendStateHash_)
|
|
|
{
|
|
|
HashMap<unsigned, ID3D11BlendState*>::Iterator i = impl_->blendStates_.Find(newBlendStateHash);
|
|
|
if (i == impl_->blendStates_.End())
|
|
|
@@ -2642,19 +2640,19 @@ void Graphics::PrepareDraw()
|
|
|
}
|
|
|
|
|
|
impl_->deviceContext_->OMSetBlendState(i->second_, 0, M_MAX_UNSIGNED);
|
|
|
- blendStateHash_ = newBlendStateHash;
|
|
|
+ impl_->blendStateHash_ = newBlendStateHash;
|
|
|
}
|
|
|
|
|
|
- blendStateDirty_ = false;
|
|
|
+ impl_->blendStateDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- if (depthStateDirty_)
|
|
|
+ if (impl_->depthStateDirty_)
|
|
|
{
|
|
|
unsigned newDepthStateHash =
|
|
|
(depthWrite_ ? 1 : 0) | (stencilTest_ ? 2 : 0) | (depthTestMode_ << 2) | ((stencilCompareMask_ & 0xff) << 5) |
|
|
|
((stencilWriteMask_ & 0xff) << 13) | (stencilTestMode_ << 21) |
|
|
|
((stencilFail_ + stencilZFail_ * 5 + stencilPass_ * 25) << 24);
|
|
|
- if (newDepthStateHash != depthStateHash_ || stencilRefDirty_)
|
|
|
+ if (newDepthStateHash != impl_->depthStateHash_ || impl_->stencilRefDirty_)
|
|
|
{
|
|
|
HashMap<unsigned, ID3D11DepthStencilState*>::Iterator i = impl_->depthStates_.Find(newDepthStateHash);
|
|
|
if (i == impl_->depthStates_.End())
|
|
|
@@ -2690,14 +2688,14 @@ void Graphics::PrepareDraw()
|
|
|
}
|
|
|
|
|
|
impl_->deviceContext_->OMSetDepthStencilState(i->second_, stencilRef_);
|
|
|
- depthStateHash_ = newDepthStateHash;
|
|
|
+ impl_->depthStateHash_ = newDepthStateHash;
|
|
|
}
|
|
|
|
|
|
- depthStateDirty_ = false;
|
|
|
- stencilRefDirty_ = false;
|
|
|
+ impl_->depthStateDirty_ = false;
|
|
|
+ impl_->stencilRefDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- if (rasterizerStateDirty_)
|
|
|
+ if (impl_->rasterizerStateDirty_)
|
|
|
{
|
|
|
unsigned depthBits = 24;
|
|
|
if (depthStencil_ && depthStencil_->GetParentTexture()->GetFormat() == DXGI_FORMAT_R16_TYPELESS)
|
|
|
@@ -2707,7 +2705,7 @@ void Graphics::PrepareDraw()
|
|
|
unsigned newRasterizerStateHash =
|
|
|
(scissorTest_ ? 1 : 0) | (fillMode_ << 1) | (cullMode_ << 3) | ((scaledDepthBias & 0x1fff) << 5) |
|
|
|
((*((unsigned*)&slopeScaledDepthBias_) & 0x1fff) << 18);
|
|
|
- if (newRasterizerStateHash != rasterizerStateHash_)
|
|
|
+ if (newRasterizerStateHash != impl_->rasterizerStateHash_)
|
|
|
{
|
|
|
HashMap<unsigned, ID3D11RasterizerState*>::Iterator i = impl_->rasterizerStates_.Find(newRasterizerStateHash);
|
|
|
if (i == impl_->rasterizerStates_.End())
|
|
|
@@ -2739,13 +2737,13 @@ void Graphics::PrepareDraw()
|
|
|
}
|
|
|
|
|
|
impl_->deviceContext_->RSSetState(i->second_);
|
|
|
- rasterizerStateHash_ = newRasterizerStateHash;
|
|
|
+ impl_->rasterizerStateHash_ = newRasterizerStateHash;
|
|
|
}
|
|
|
|
|
|
- rasterizerStateDirty_ = false;
|
|
|
+ impl_->rasterizerStateDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- if (scissorRectDirty_)
|
|
|
+ if (impl_->scissorRectDirty_)
|
|
|
{
|
|
|
D3D11_RECT d3dRect;
|
|
|
d3dRect.left = scissorRect_.left_;
|
|
|
@@ -2753,12 +2751,12 @@ void Graphics::PrepareDraw()
|
|
|
d3dRect.right = scissorRect_.right_;
|
|
|
d3dRect.bottom = scissorRect_.bottom_;
|
|
|
impl_->deviceContext_->RSSetScissorRects(1, &d3dRect);
|
|
|
- scissorRectDirty_ = false;
|
|
|
+ impl_->scissorRectDirty_ = false;
|
|
|
}
|
|
|
|
|
|
- for (unsigned i = 0; i < dirtyConstantBuffers_.Size(); ++i)
|
|
|
- dirtyConstantBuffers_[i]->Apply();
|
|
|
- dirtyConstantBuffers_.Clear();
|
|
|
+ for (unsigned i = 0; i < impl_->dirtyConstantBuffers_.Size(); ++i)
|
|
|
+ impl_->dirtyConstantBuffers_[i]->Apply();
|
|
|
+ impl_->dirtyConstantBuffers_.Clear();
|
|
|
}
|
|
|
|
|
|
void Graphics::CreateResolveTexture()
|