|
@@ -305,7 +305,9 @@ void DirectX11::initialize(
|
|
|
vp->Height = (float)this->backBufferSize.y;
|
|
vp->Height = (float)this->backBufferSize.y;
|
|
|
vp->MinDepth = 0.0f;
|
|
vp->MinDepth = 0.0f;
|
|
|
vp->MaxDepth = 1.0f;
|
|
vp->MaxDepth = 1.0f;
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->RSSetViewports(1, vp);
|
|
d3d11Context->RSSetViewports(1, vp);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
// Create the render target view with the back buffer pointer.
|
|
// Create the render target view with the back buffer pointer.
|
|
|
deviceLock.lock();
|
|
deviceLock.lock();
|
|
@@ -388,7 +390,9 @@ void DirectX11::initialize(
|
|
|
MB_ICONERROR);
|
|
MB_ICONERROR);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->OMSetDepthStencilState(depthStencilState, 1);
|
|
d3d11Context->OMSetDepthStencilState(depthStencilState, 1);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
// Initialize the depth stencil view.
|
|
// Initialize the depth stencil view.
|
|
|
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
|
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
|
@@ -414,7 +418,9 @@ void DirectX11::initialize(
|
|
|
MB_ICONERROR);
|
|
MB_ICONERROR);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->OMSetRenderTargets(1, &rtview, dsView);
|
|
d3d11Context->OMSetRenderTargets(1, &rtview, dsView);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
|
|
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
|
|
|
// Clear the second depth stencil state before setting the parameters.
|
|
// Clear the second depth stencil state before setting the parameters.
|
|
@@ -523,13 +529,15 @@ void DirectX11::initialize(
|
|
|
|
|
|
|
|
deviceLock.lock();
|
|
deviceLock.lock();
|
|
|
d3d11Device->CreateBlendState(&blendState, &blendStateAlphaBlend);
|
|
d3d11Device->CreateBlendState(&blendState, &blendStateAlphaBlend);
|
|
|
- deviceLock.unlock();
|
|
|
|
|
d3d11Context->OMSetBlendState(blendStateAlphaBlend, 0, 0xFFFFFFFF);
|
|
d3d11Context->OMSetBlendState(blendStateAlphaBlend, 0, 0xFFFFFFFF);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
// Setup Render Objekt
|
|
// Setup Render Objekt
|
|
|
|
|
|
|
|
vertexShader->useShader();
|
|
vertexShader->useShader();
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->PSSetSamplers(0, 1, &sampleState);
|
|
d3d11Context->PSSetSamplers(0, 1, &sampleState);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
pixelShader->useShader();
|
|
pixelShader->useShader();
|
|
|
|
|
|
|
|
D3D11_RASTERIZER_DESC rasterDesc;
|
|
D3D11_RASTERIZER_DESC rasterDesc;
|
|
@@ -559,9 +567,9 @@ void DirectX11::initialize(
|
|
|
rasterDesc.SlopeScaledDepthBias = 0.0f;
|
|
rasterDesc.SlopeScaledDepthBias = 0.0f;
|
|
|
deviceLock.lock();
|
|
deviceLock.lock();
|
|
|
d3d11Device->CreateRasterizerState(&rasterDesc, &meshRS);
|
|
d3d11Device->CreateRasterizerState(&rasterDesc, &meshRS);
|
|
|
- deviceLock.unlock();
|
|
|
|
|
|
|
|
|
|
d3d11Context->RSSetState(texturRS);
|
|
d3d11Context->RSSetState(texturRS);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
Image* b = new Image();
|
|
Image* b = new Image();
|
|
|
b->newImage(10, 10, 0xFFFFFFFF);
|
|
b->newImage(10, 10, 0xFFFFFFFF);
|
|
@@ -680,8 +688,11 @@ void DirectX11::beginFrame(bool fill2D, bool fill3D, int fillColor)
|
|
|
color[1] = ((fillColor >> 8) & 0xFF) / 255.f; // G
|
|
color[1] = ((fillColor >> 8) & 0xFF) / 255.f; // G
|
|
|
color[2] = (fillColor & 0xFF) / 255.f; // B
|
|
color[2] = (fillColor & 0xFF) / 255.f; // B
|
|
|
color[3] = ((fillColor >> 24) & 0xFF) / 255.f; // A
|
|
color[3] = ((fillColor >> 24) & 0xFF) / 255.f; // A
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->ClearRenderTargetView(rtview, color);
|
|
d3d11Context->ClearRenderTargetView(rtview, color);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
}
|
|
}
|
|
|
|
|
+ deviceLock.lock();
|
|
|
// Bind the render target view and depth stencil buffer to the output render
|
|
// Bind the render target view and depth stencil buffer to the output render
|
|
|
// pipeline.
|
|
// pipeline.
|
|
|
d3d11Context->OMSetRenderTargets(1, &rtview, dsView);
|
|
d3d11Context->OMSetRenderTargets(1, &rtview, dsView);
|
|
@@ -690,6 +701,7 @@ void DirectX11::beginFrame(bool fill2D, bool fill3D, int fillColor)
|
|
|
dsView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
|
|
dsView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
|
|
|
// Set the depth stencil state.
|
|
// Set the depth stencil state.
|
|
|
d3d11Context->OMSetDepthStencilState(depthStencilState, 1);
|
|
d3d11Context->OMSetDepthStencilState(depthStencilState, 1);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void DirectX11::renderObject(Model3D* zObj)
|
|
void DirectX11::renderObject(Model3D* zObj)
|
|
@@ -714,7 +726,9 @@ void DirectX11::renderObject(Model3D* zObj)
|
|
|
= (unsigned)zObj->zModelData()->zDXVertexBuffer()->getElementLength();
|
|
= (unsigned)zObj->zModelData()->zDXVertexBuffer()->getElementLength();
|
|
|
ID3D11Buffer* vBuffer
|
|
ID3D11Buffer* vBuffer
|
|
|
= ((DX11Buffer*)zObj->zModelData()->zDXVertexBuffer())->zBuffer();
|
|
= ((DX11Buffer*)zObj->zModelData()->zDXVertexBuffer())->zBuffer();
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->IASetVertexBuffers(0, 1, &vBuffer, &es, &offset);
|
|
d3d11Context->IASetVertexBuffers(0, 1, &vBuffer, &es, &offset);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
Model3DTexture* zTexture = zObj->zTexture();
|
|
Model3DTexture* zTexture = zObj->zTexture();
|
|
|
int ind = 0;
|
|
int ind = 0;
|
|
|
int current = 0;
|
|
int current = 0;
|
|
@@ -725,7 +739,9 @@ void DirectX11::renderObject(Model3D* zObj)
|
|
|
if (zEffectTexture && zEffectTexture->needsUpdate())
|
|
if (zEffectTexture && zEffectTexture->needsUpdate())
|
|
|
zEffectTexture->updateTextur();
|
|
zEffectTexture->updateTextur();
|
|
|
v[0] = *zEffectTexture;
|
|
v[0] = *zEffectTexture;
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->PSSetShaderResources(3, 1, v);
|
|
d3d11Context->PSSetShaderResources(3, 1, v);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
TextureEffect e = {1, zObj->getEffectPercentage()};
|
|
TextureEffect e = {1, zObj->getEffectPercentage()};
|
|
|
if (pixelShader)
|
|
if (pixelShader)
|
|
|
pixelShader->fillConstBuffer((char*)&e, 3, sizeof(TextureEffect));
|
|
pixelShader->fillConstBuffer((char*)&e, 3, sizeof(TextureEffect));
|
|
@@ -741,9 +757,11 @@ void DirectX11::renderObject(Model3D* zObj)
|
|
|
f = DXGI_FORMAT_R16_UINT;
|
|
f = DXGI_FORMAT_R16_UINT;
|
|
|
if (zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 1)
|
|
if (zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 1)
|
|
|
f = DXGI_FORMAT_R8_UINT;
|
|
f = DXGI_FORMAT_R8_UINT;
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->IASetIndexBuffer(
|
|
d3d11Context->IASetIndexBuffer(
|
|
|
((DX11Buffer*)zObj->zModelData()->zDXIndexBuffer())->zBuffer(), f, 0);
|
|
((DX11Buffer*)zObj->zModelData()->zDXIndexBuffer())->zBuffer(), f, 0);
|
|
|
d3d11Context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
|
d3d11Context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
zObj->beforeRender(this, vertexShader, pixelShader);
|
|
zObj->beforeRender(this, vertexShader, pixelShader);
|
|
|
for (auto i = zObj->zModelData()->getPolygons(); i; ++i)
|
|
for (auto i = zObj->zModelData()->getPolygons(); i; ++i)
|
|
|
{
|
|
{
|
|
@@ -757,11 +775,14 @@ void DirectX11::renderObject(Model3D* zObj)
|
|
|
v[0] = *(DX11Texture*)t;
|
|
v[0] = *(DX11Texture*)t;
|
|
|
v[1] = *diffuseLights;
|
|
v[1] = *diffuseLights;
|
|
|
v[2] = *pointLights;
|
|
v[2] = *pointLights;
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->PSSetShaderResources(0, 3, v);
|
|
d3d11Context->PSSetShaderResources(0, 3, v);
|
|
|
d3d11Context->DrawIndexed(i->indexAnz, current, 0);
|
|
d3d11Context->DrawIndexed(i->indexAnz, current, 0);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->RSSetState(meshRS);
|
|
d3d11Context->RSSetState(meshRS);
|
|
|
ID3D11ShaderResourceView* v[3];
|
|
ID3D11ShaderResourceView* v[3];
|
|
|
v[0] = *(DX11Texture*)defaultTexture;
|
|
v[0] = *(DX11Texture*)defaultTexture;
|
|
@@ -770,6 +791,7 @@ void DirectX11::renderObject(Model3D* zObj)
|
|
|
d3d11Context->PSSetShaderResources(0, 3, v);
|
|
d3d11Context->PSSetShaderResources(0, 3, v);
|
|
|
d3d11Context->DrawIndexed(i->indexAnz, current, 0);
|
|
d3d11Context->DrawIndexed(i->indexAnz, current, 0);
|
|
|
d3d11Context->RSSetState(texturRS);
|
|
d3d11Context->RSSetState(texturRS);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
ind++;
|
|
ind++;
|
|
@@ -810,7 +832,9 @@ bool DirectX11::isInFrustrum(
|
|
|
|
|
|
|
|
void DirectX11::renderKamera(Cam3D* zKamera)
|
|
void DirectX11::renderKamera(Cam3D* zKamera)
|
|
|
{
|
|
{
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->RSSetViewports(1, (D3D11_VIEWPORT*)zKamera->zViewPort());
|
|
d3d11Context->RSSetViewports(1, (D3D11_VIEWPORT*)zKamera->zViewPort());
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
Mat4<float> tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
|
|
Mat4<float> tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
|
|
|
|
|
|
|
@@ -962,16 +986,20 @@ void DirectX11::renderKamera(Cam3D* zKamera, Texture* zTarget)
|
|
|
deviceLock.unlock();
|
|
deviceLock.unlock();
|
|
|
if (result != S_OK)
|
|
if (result != S_OK)
|
|
|
throw "could not create render target view for given texture";
|
|
throw "could not create render target view for given texture";
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->OMSetRenderTargets(1, &texturRtView, txtDsView);
|
|
d3d11Context->OMSetRenderTargets(1, &texturRtView, txtDsView);
|
|
|
|
|
|
|
|
float color[4] = {0, 0, 0, 0};
|
|
float color[4] = {0, 0, 0, 0};
|
|
|
d3d11Context->ClearRenderTargetView(texturRtView, color);
|
|
d3d11Context->ClearRenderTargetView(texturRtView, color);
|
|
|
d3d11Context->ClearDepthStencilView(
|
|
d3d11Context->ClearDepthStencilView(
|
|
|
txtDsView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
|
|
txtDsView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
renderKamera(zKamera);
|
|
renderKamera(zKamera);
|
|
|
result = d3d11SpawChain->Present(0, 0);
|
|
result = d3d11SpawChain->Present(0, 0);
|
|
|
if (result != S_OK) throw "could not present the rendered content";
|
|
if (result != S_OK) throw "could not present the rendered content";
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->OMSetRenderTargets(1, &rtview, dsView);
|
|
d3d11Context->OMSetRenderTargets(1, &rtview, dsView);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
texturRtView->Release();
|
|
texturRtView->Release();
|
|
|
txtDsView->Release();
|
|
txtDsView->Release();
|
|
|
txtDepthStencilBuffer->Release();
|
|
txtDepthStencilBuffer->Release();
|
|
@@ -980,11 +1008,15 @@ void DirectX11::renderKamera(Cam3D* zKamera, Texture* zTarget)
|
|
|
void DirectX11::presentFrame()
|
|
void DirectX11::presentFrame()
|
|
|
{
|
|
{
|
|
|
// Set the depth stencil state.
|
|
// Set the depth stencil state.
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->OMSetDepthStencilState(depthDisabledStencilState, 1);
|
|
d3d11Context->OMSetDepthStencilState(depthDisabledStencilState, 1);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
uiTexture->updateTextur();
|
|
uiTexture->updateTextur();
|
|
|
|
|
|
|
|
|
|
+ deviceLock.lock();
|
|
|
d3d11Context->RSSetViewports(1, vp);
|
|
d3d11Context->RSSetViewports(1, vp);
|
|
|
|
|
+ deviceLock.unlock();
|
|
|
|
|
|
|
|
float screenAspect = (float)backBufferSize.x / (float)backBufferSize.y;
|
|
float screenAspect = (float)backBufferSize.x / (float)backBufferSize.y;
|
|
|
Mat4<float> view
|
|
Mat4<float> view
|