void SpriteBatch::Impl::PrepareForRendering() { #if TALON_GRAPHICS == TALON_GRAPHICS_D3D11 auto deviceContext = device->GetDeviceContext(); // TODO: Support render states (https://app.asana.com/0/1144010891804/1171962804804) ID3D11SamplerState* pSamplerState = samplerState; deviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFF); deviceContext->OMSetDepthStencilState(depthStencilState, 0); deviceContext->RSSetState(rasterizerState); deviceContext->PSSetSamplers(0, 1, &pSamplerState); #endif device->SetActiveInputLayout(spriteVertexLayout); device->SetActiveShader(ShaderType::Vertex, vertexShader); device->SetActiveShader(ShaderType::Pixel, pixelShader); device->SetActiveVertexBuffer(vertexBuffer); device->SetActiveIndexBuffer(indexBuffer); Matrix transformMatrix = GetViewportTransform(device); constantBuffer->Update(&transformMatrix); vertexShader->SetConstantBuffer(0, constantBuffer); }
//レンダリングターゲットを終了する void ShadowMapRenderTarget::EndRenderTarget(){ //デバイスとコンテキストインターフェイスの取得 auto Dev = App::GetApp()->GetDeviceResources(); auto pD3D11Device = Dev->GetD3DDevice(); auto pD3D11DeviceContext = Dev->GetD3DDeviceContext(); //レンダリングターゲットは深度ステンシルビューのみ指定 ID3D11RenderTargetView* pnullView = nullptr; pD3D11DeviceContext->OMSetRenderTargets(1, &pnullView, nullptr); //ビューポートの設定 pD3D11DeviceContext->RSSetViewports(1, &pImpl->m_ViewPort); //ラスタライザステートの設定(設定解除) pD3D11DeviceContext->RSSetState(nullptr); //シェーダーは指定しない //頂点シェーダの設定(ここでは指定しない) pD3D11DeviceContext->VSSetShader(nullptr, nullptr, 0); //ピクセルシェーダの設定(使用しない) pD3D11DeviceContext->PSSetShader(nullptr, nullptr, 0); //ジオメトリシェーダの設定(使用しない) pD3D11DeviceContext->GSSetShader(nullptr, nullptr, 0); }
void SpriteBatch::Impl::CleanupRendering() { device->SetActiveIndexBuffer(nullptr); device->SetActiveVertexBuffer(nullptr); device->SetActiveShader(ShaderType::Pixel, nullptr); device->SetActiveShader(ShaderType::Vertex, nullptr); device->SetActiveInputLayout(nullptr); #if TALON_GRAPHICS == TALON_GRAPHICS_D3D11 auto deviceContext = device->GetDeviceContext(); ID3D11SamplerState* pSamplerState = nullptr; // TODO: Support render states (https://app.asana.com/0/1144010891804/1171962804804) deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFFF); deviceContext->OMSetDepthStencilState(nullptr, 0); deviceContext->RSSetState(nullptr); deviceContext->PSSetSamplers(0, 1, &pSamplerState); #endif }
virtual void render() override { auto imc = mRenderer->getImmediateContext(); auto vs = std::dynamic_pointer_cast<TB::DirectXShader>(mVertexShader); auto ps = std::dynamic_pointer_cast<TB::DirectXShader>(mPixelShader); auto tex = std::dynamic_pointer_cast<TB::DirectXTexture>(mTexture); ID3D11Buffer* constants[] = { mViewConstants, nullptr, mWorldConstants }; ID3D11ShaderResourceView* srvs[] = { *tex }; ID3D11SamplerState* samplers[] = { TB::DirectXSamplerState::get() }; imc->RSSetState(TB::DirectXRasterizerState::get()); imc->VSSetConstantBuffers(0, 3, constants); imc->VSSetShader(*vs, nullptr, 0); imc->PSSetConstantBuffers(0, 3, constants); imc->PSSetShader(*ps, nullptr, 0); imc->PSSetShaderResources(0, 1, srvs); imc->PSSetSamplers(0, 1, samplers); mRenderer->clear(mRenderer->getBackBufferRTV(), math::float4(0.0f, 0.0f, 0.0f, 0.0f)); mRenderer->clear(mRenderer->getBackBufferDSV()); mScene->render(); }
void GameObject::Draw(){ //ゲームステージが無効ならリターン if (m_GameStgae.expired()){ return; } //デバイスの取得 auto Dev = App::GetApp()->GetDeviceResources(); auto pDx11Device = Dev->GetD3DDevice(); auto pID3D11DeviceContext = Dev->GetD3DDeviceContext(); //ステータスのポインタ auto RenderStatePtr = Dev->GetRenderState(); auto Stage = m_GameStgae.lock(); auto ViewPtr = Stage->GetView(); //ビューからカメラを取り出す auto PtrCamera = ViewPtr->GetCamera(); //カメラの取得 Matrix4X4 View, Proj; View = PtrCamera->GetViewMatrix(); Proj = PtrCamera->GetProjMatrix(); //コンスタントバッファの設定 Texture3DConstantBuffer cb1; //行列の設定(転置する) cb1.Model = Matrix4X4EX::Transpose(m_WorldMatrix); cb1.View = Matrix4X4EX::Transpose(View); cb1.Projection = Matrix4X4EX::Transpose(Proj); //ライトの設定 //ステージから0番目のライトを取り出す auto PtrLight = ViewPtr->GetMultiLight()->GetLight(0); cb1.LightDir = PtrLight->GetDirectional(); cb1.LightDir.w = 1.0f; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(CBTexture3D::GetPtr()->GetBuffer(), 0, nullptr, &cb1, 0, 0); //ストライドとオフセット UINT stride = sizeof(VertexPositionNormalTexture); UINT offset = 0; //頂点バッファの設定 pID3D11DeviceContext->IASetVertexBuffers(0, 1, m_VertexBuffer.GetAddressOf(), &stride, &offset); //インデックスバッファのセット pID3D11DeviceContext->IASetIndexBuffer(m_IndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); //描画方法(3角形) pID3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //透明処理 pID3D11DeviceContext->OMSetBlendState(RenderStatePtr->GetAlphaBlendEx(), nullptr, 0xffffffff); //デプスステンシルは使用する pID3D11DeviceContext->OMSetDepthStencilState(RenderStatePtr->GetDepthDefault(), 0); //シェーダの設定 pID3D11DeviceContext->VSSetShader(VSTexture3D::GetPtr()->GetShader(), nullptr, 0); pID3D11DeviceContext->PSSetShader(PSTexture3D::GetPtr()->GetShader(), nullptr, 0); //リニアサンプラーを設定 ID3D11SamplerState* samplerState = RenderStatePtr->GetLinearClamp(); pID3D11DeviceContext->PSSetSamplers(0, 1, &samplerState); for (auto& m : m_Materials){ //テクスチャを設定 pID3D11DeviceContext->PSSetShaderResources(0, 1, m.m_ShaderResView.GetAddressOf()); //インプットレイアウトの設定 pID3D11DeviceContext->IASetInputLayout(VSTexture3D::GetPtr()->GetInputLayout()); //コンスタントバッファの設定 ID3D11Buffer* pConstantBuffer = CBTexture3D::GetPtr()->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullFront()); //描画 pID3D11DeviceContext->DrawIndexed(m.m_IndexCount, m.m_StartIndex, 0); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullBack()); //描画 pID3D11DeviceContext->DrawIndexed(m.m_IndexCount, m.m_StartIndex,0); } //後始末 Dev->InitializeStates(RenderStatePtr); }
void CustomDrawBox::Draw(){ //デバイスの取得 auto Dev = App::GetApp()->GetDeviceResources(); auto pDx11Device = Dev->GetD3DDevice(); auto pID3D11DeviceContext = Dev->GetD3DDeviceContext(); //ステータスのポインタ auto RenderStatePtr = GetStage()->GetRenderState(); auto PtrT = GetComponent<Transform>(); //ステージからカメラを取り出す auto PtrCamera = GetStage()->GetTargetCamera(); //カメラの取得 Matrix4X4 View, Proj, WorldViewProj; View = PtrCamera->GetViewMatrix(); Proj = PtrCamera->GetProjMatrix(); //ストライドとオフセット UINT stride = sizeof(VertexPositionNormalTexture); UINT offset = 0; //頂点バッファの設定 auto PtrMeshResource = App::GetApp()->GetResource<MeshResource>(L"DEFAULT_CUBE"); pID3D11DeviceContext->IASetVertexBuffers(0, 1, PtrMeshResource->GetVertexBuffer().GetAddressOf(), &stride, &offset); //インデックスバッファのセット pID3D11DeviceContext->IASetIndexBuffer(PtrMeshResource->GetIndexBuffer().Get(), DXGI_FORMAT_R16_UINT, 0); //描画方法(3角形) pID3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //ステータスのポインタ //テクスチャを取得 ID3D11ShaderResourceView* pNull[1] = { 0 }; ID3D11SamplerState* pNullSR[1] = { 0 }; //テクスチャを設定 auto PtrTextureResource = App::GetApp()->GetResource<TextureResource>(L"TRACE_TX"); pID3D11DeviceContext->PSSetShaderResources(0, 1, PtrTextureResource->GetShaderResourceView().GetAddressOf()); //リニアサンプラーを設定 ID3D11SamplerState* samplerState = RenderStatePtr->GetLinearClamp(); pID3D11DeviceContext->PSSetSamplers(0, 1, &samplerState); //半透明処理 pID3D11DeviceContext->OMSetBlendState(RenderStatePtr->GetAlphaBlendEx(), nullptr, 0xffffffff); //デプスステンシルは使用する pID3D11DeviceContext->OMSetDepthStencilState(RenderStatePtr->GetDepthDefault(), 0); //シェーダの設定 pID3D11DeviceContext->VSSetShader(m_VirtexShader->GetShader(), nullptr, 0); pID3D11DeviceContext->PSSetShader(m_PixelShader->GetShader(), nullptr, 0); //インプットレイアウトの設定 pID3D11DeviceContext->IASetInputLayout(m_VirtexShader->GetInputLayout()); //コンスタントバッファの設定 ConstantBuffer cb1; ZeroMemory(&cb1, sizeof(cb1)); //行列の設定(転置する) cb1.World = Matrix4X4EX::Transpose(PtrT->GetWorldMatrix());; cb1.View = Matrix4X4EX::Transpose(View); cb1.Projection = Matrix4X4EX::Transpose(Proj); //ライトの設定 //ステージから0番目のライトを取り出す auto PtrLight = GetStage()->GetTargetLight(0); cb1.LightDir = PtrLight->GetDirectional(); //xとzだけ逆にする cb1.LightDir.x *= -1.0f; cb1.LightDir.z *= -1.0f; cb1.LightDir.w = 1.0f; //トータルタイムをコンスタントバッファに渡す float ElapsedTime = App::GetApp()->GetElapsedTime(); m_TotalTime += ElapsedTime; if (m_TotalTime >= 1.0f){ m_TotalTime = 0.0f; } cb1.Param.x = m_TotalTime; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(m_ConstantBuffer->GetBuffer(), 0, nullptr, &cb1, 0, 0); //コンスタントバッファの設定 ID3D11Buffer* pConstantBuffer = m_ConstantBuffer->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullFront()); //内側描画 pID3D11DeviceContext->DrawIndexed(PtrMeshResource->GetNumIndicis(), 0, 0); //ライトの向きを変える cb1.LightDir = PtrLight->GetDirectional(); cb1.LightDir.w = 1.0f; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(m_ConstantBuffer->GetBuffer(), 0, nullptr, &cb1, 0, 0); //コンスタントバッファの設定 pConstantBuffer = m_ConstantBuffer->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullBack()); //描画(外側) pID3D11DeviceContext->DrawIndexed(PtrMeshResource->GetNumIndicis(), 0, 0); //後始末 Dev->InitializeStates(RenderStatePtr); }
void SpriteBase::OnDraw() { auto TexPtr = App::GetApp()->GetResource<TextureResource>(m_TextureResName); auto Dev = App::GetApp()->GetDeviceResources(); auto pD3D11DeviceContext = Dev->GetD3DDeviceContext(); auto RenderState = Dev->GetRenderState(); //ワールド行列の決定 Mat4x4 World; World.affineTransformation2D( m_Scale, //スケーリング Vec2(0, 0), //回転の中心(重心) m_Rot, //回転角度 m_Pos //位置 ); //射影行列の決定 float w = static_cast<float>(App::GetApp()->GetGameWidth()); float h = static_cast<float>(App::GetApp()->GetGameHeight()); Mat4x4 Proj(XMMatrixOrthographicLH(w, h, -1.0, 1.0f)); //行列の合成 World *= Proj; //コンスタントバッファの準備 SpriteConstantBuffer sb; //エミッシブ加算。 sb.Emissive = m_Emissive; //行列の設定 sb.World = World; //コンスタントバッファの更新 pD3D11DeviceContext->UpdateSubresource(CBSprite::GetPtr()->GetBuffer(), 0, nullptr, &sb, 0, 0); //ストライドとオフセット UINT stride = sizeof(VertexPositionColorTexture); UINT offset = 0; //頂点バッファのセット pD3D11DeviceContext->IASetVertexBuffers(0, 1, m_SquareMesh->GetVertexBuffer().GetAddressOf(), &stride, &offset); //インデックスバッファのセット pD3D11DeviceContext->IASetIndexBuffer(m_SquareMesh->GetIndexBuffer().Get(), DXGI_FORMAT_R16_UINT, 0); //描画方法(3角形) pD3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //コンスタントバッファの設定 ID3D11Buffer* pConstantBuffer = CBSprite::GetPtr()->GetBuffer(); ID3D11Buffer* pNullConstantBuffer = nullptr; //頂点シェーダに渡す pD3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); //ピクセルシェーダに渡す pD3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //シェーダの設定 pD3D11DeviceContext->VSSetShader(VSPCTSprite::GetPtr()->GetShader(), nullptr, 0); pD3D11DeviceContext->PSSetShader(PSPCTSprite::GetPtr()->GetShader(), nullptr, 0); //インプットレイアウトの設定 pD3D11DeviceContext->IASetInputLayout(VSPCTSprite::GetPtr()->GetInputLayout()); //ブレンドステート switch (m_BlendState) { case BlendState::Opaque: pD3D11DeviceContext->OMSetBlendState(RenderState->GetOpaque(), nullptr, 0xffffffff); break; case BlendState::Trace: pD3D11DeviceContext->OMSetBlendState(RenderState->GetAlphaBlendEx(), nullptr, 0xffffffff); break; case BlendState::Additive: pD3D11DeviceContext->OMSetBlendState(RenderState->GetAdditive(), nullptr, 0xffffffff); break; } //デプスステンシルステート pD3D11DeviceContext->OMSetDepthStencilState(RenderState->GetDepthNone(), 0); //ラスタライザステート pD3D11DeviceContext->RSSetState(RenderState->GetCullBack()); //テクスチャとサンプラーの設定 ID3D11ShaderResourceView* pNull[1] = { 0 }; pD3D11DeviceContext->PSSetShaderResources(0, 1, TexPtr->GetShaderResourceView().GetAddressOf()); //ラッピングサンプラー ID3D11SamplerState* pSampler = RenderState->GetLinearWrap(); pD3D11DeviceContext->PSSetSamplers(0, 1, &pSampler); //描画 pD3D11DeviceContext->DrawIndexed(m_SquareMesh->GetNumIndicis(), 0, 0); //後始末 Dev->InitializeStates(); }