#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_GRAPHICS_SOURCE 1 #include "Direct3D11RasterizerResources.h" #include "Observers/Direct3D11Texture2Observer.h" #include "Observers/Direct3D11IndexBufferObserver.h" #include "Observers/Direct3D11VertexBufferObserver.h" #include "Observers/Direct3D11ConstantBufferObserver.h" #include "Observers/Direct3D11PixelShaderObserver.h" #include "Observers/Direct3D11VertexShaderObserver.h" #include "Observers/Direct3D11RenderTarget2Observer.h" #include "Observers/Direct3D11PolygonOptionsObserver.h" #include "Observers/Direct3D11SamplerOptionsObserver.h" namespace Nuclex { namespace Graphics { namespace Rasterization { // ------------------------------------------------------------------------------------------- // Direct3D11RasterizerResources::Direct3D11RasterizerResources() : IndexBufferHolder(this), VertexBufferHolder(this), ConstantBufferHolder(this), VertexShaderHolder(this), PixelShaderHolder(this), Texture2Holder(this), RenderTarget2Holder(this), PolygonOptionsHolder(this), SamplerOptionsHolder(this) {} // ------------------------------------------------------------------------------------------- // Direct3D11RasterizerResources::~Direct3D11RasterizerResources() { this->IndexBufferHolder.EvictAll(); this->VertexBufferHolder.EvictAll(); this->ConstantBufferHolder.EvictAll(); this->VertexShaderHolder.EvictAll(); this->PixelShaderHolder.EvictAll(); this->Texture2Holder.EvictAll(); this->RenderTarget2Holder.EvictAll(); this->PolygonOptionsHolder.EvictAll(); this->SamplerOptionsHolder.EvictAll(); } // ------------------------------------------------------------------------------------------- // void Direct3D11RasterizerResources::Prepare(const std::shared_ptr &resource) { Resource *unwrappedResource = resource.get(); auto vertexBuffer = dynamic_cast(unwrappedResource); if(vertexBuffer != nullptr) { this->VertexBufferHolder.Prepare(vertexBuffer); return; } auto indexBuffer = dynamic_cast(unwrappedResource); if(indexBuffer != nullptr) { this->IndexBufferHolder.Prepare(indexBuffer); return; } auto constantBuffer = dynamic_cast(unwrappedResource); if(constantBuffer != nullptr) { this->ConstantBufferHolder.Prepare(constantBuffer); return; } auto renderTarget2 = dynamic_cast(unwrappedResource); if(renderTarget2 != nullptr) { this->RenderTarget2Holder.Prepare(renderTarget2); return; } auto texture2 = dynamic_cast(unwrappedResource); if(texture2 != nullptr) { this->Texture2Holder.Prepare(texture2); return; } auto vertexShader = dynamic_cast(unwrappedResource); if(vertexShader != nullptr) { this->VertexShaderHolder.Prepare(vertexShader); return; } auto pixelShader = dynamic_cast(unwrappedResource); if(pixelShader != nullptr) { this->PixelShaderHolder.Prepare(pixelShader); return; } auto polygonOptions = dynamic_cast(unwrappedResource); if(polygonOptions != nullptr) { this->PolygonOptionsHolder.Prepare(polygonOptions); return; } auto samplerOptions = dynamic_cast(unwrappedResource); if(samplerOptions != nullptr) { this->SamplerOptionsHolder.Prepare(samplerOptions); return; } throw std::runtime_error("Unsupported resource type"); } // ------------------------------------------------------------------------------------------- // void Direct3D11RasterizerResources::Evict(const std::shared_ptr &resource) { Resource *unwrappedResource = resource.get(); auto vertexBuffer = dynamic_cast(unwrappedResource); if(vertexBuffer != nullptr) { this->VertexBufferHolder.Evict(vertexBuffer); return; } auto indexBuffer = dynamic_cast(unwrappedResource); if(indexBuffer != nullptr) { this->IndexBufferHolder.Evict(indexBuffer); return; } auto constantBuffer = dynamic_cast(unwrappedResource); if(constantBuffer != nullptr) { this->ConstantBufferHolder.Evict(constantBuffer); return; } auto renderTarget2 = dynamic_cast(unwrappedResource); if(renderTarget2 != nullptr) { this->RenderTarget2Holder.Evict(renderTarget2); return; } auto texture = dynamic_cast(unwrappedResource); if(texture != nullptr) { this->Texture2Holder.Evict(texture); return; } auto vertexShader = dynamic_cast(unwrappedResource); if(vertexShader != nullptr) { this->VertexShaderHolder.Evict(vertexShader); return; } auto pixelShader = dynamic_cast(unwrappedResource); if(pixelShader != nullptr) { this->PixelShaderHolder.Evict(pixelShader); return; } auto polygonOptions = dynamic_cast(unwrappedResource); if(polygonOptions != nullptr) { this->PolygonOptionsHolder.Evict(polygonOptions); return; } auto samplerOptions = dynamic_cast(unwrappedResource); if(samplerOptions != nullptr) { this->SamplerOptionsHolder.Evict(samplerOptions); return; } throw std::runtime_error("Unsupported resource type"); } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization