D3D11StencilTable::D3D11StencilTable(Far::StencilTable const *stencilTable, ID3D11DeviceContext *deviceContext) { ID3D11Device *device = NULL; deviceContext->GetDevice(&device); assert(device); _numStencils = stencilTable->GetNumStencils(); if (_numStencils > 0) { std::vector<int> const &sizes = stencilTable->GetSizes(); _sizesBuffer = createBuffer(sizes, device); _offsetsBuffer = createBuffer(stencilTable->GetOffsets(), device); _indicesBuffer = createBuffer(stencilTable->GetControlIndices(), device); _weightsBuffer = createBuffer(stencilTable->GetWeights(), device); _sizes = createSRV(_sizesBuffer, DXGI_FORMAT_R32_SINT, device, stencilTable->GetSizes().size()); _offsets = createSRV(_offsetsBuffer, DXGI_FORMAT_R32_SINT, device, stencilTable->GetOffsets().size()); _indices = createSRV(_indicesBuffer, DXGI_FORMAT_R32_SINT, device, stencilTable->GetControlIndices().size()); _weights= createSRV(_weightsBuffer, DXGI_FORMAT_R32_FLOAT, device, stencilTable->GetWeights().size()); } else { _sizes = _offsets = _indices = _weights = NULL; _sizesBuffer = _offsetsBuffer = _indicesBuffer = _weightsBuffer = NULL; } }
void GpuBufferView::initialize(const SPtr<D3D11GpuBuffer>& buffer, GPU_BUFFER_VIEW_DESC& desc) { mBuffer = buffer; mDesc = desc; D3D11GpuBuffer* d3d11GpuBuffer = static_cast<D3D11GpuBuffer*>(buffer.get()); if ((desc.usage & GVU_DEFAULT) != 0) mSRV = createSRV(d3d11GpuBuffer, desc.firstElement, desc.elementWidth, desc.numElements); if((desc.usage & GVU_RANDOMWRITE) != 0) mUAV = createUAV(d3d11GpuBuffer, desc.firstElement, desc.numElements, desc.useCounter); if((desc.usage & GVU_RENDERTARGET) != 0 || (desc.usage & GVU_DEPTHSTENCIL) != 0) { BS_EXCEPT(NotImplementedException, "Invalid usage flags for a GPU buffer view."); } BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_ResourceView); }
D3D11TextureView::D3D11TextureView(const D3D11Texture* texture, const TEXTURE_VIEW_DESC& desc) : TextureView(desc), mSRV(nullptr), mUAV(nullptr), mRTV(nullptr), mWDepthWStencilView(nullptr) , mRODepthWStencilView(nullptr), mRODepthROStencilView(nullptr), mWDepthROStencilView(nullptr) { if ((mDesc.usage & GVU_RANDOMWRITE) != 0) mUAV = createUAV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices); else if ((mDesc.usage & GVU_RENDERTARGET) != 0) mRTV = createRTV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices); else if ((mDesc.usage & GVU_DEPTHSTENCIL) != 0) { mWDepthWStencilView = createDSV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, false, false); mRODepthWStencilView = createDSV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, true, false); mRODepthROStencilView = createDSV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, true, true); mWDepthROStencilView = createDSV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, false, true); } else mSRV = createSRV(texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices); }
bool Controller::init(RenderDX11* _renderer, string _workingDirectory) { m_terrain = new Terrain(); HRESULT hr; bool res; if(!_renderer) // no rendering available, go home return false; if(_workingDirectory == "") // dont set the current environment as a working directory you bozo return false; m_pWorkingDirectory = _workingDirectory; m_renderer = _renderer; /* --- Overview of how the data linking and abstraction works --- Property { struct<T>[] } --- Refs by Id (explicit) ---> Resources<T>[Id] Composition { Interface<Property>[] } --- Refs by Datatype (Id is implicit) ---> Property<T>[Id] LLC: Create raw data MLL: Create 'property struct', link to desired raw data HLC: Create 'composition struct', link to all desired properties (note: as of now only one property per type is allowed) */ /************************ LOW LEVEL CREATION *************************/ /* init default render resources */ // blendstates unsigned int ref; hr = createBlendState(ref, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, TRUE); hr = createBlendState(ref, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, FALSE); hr = createBlendState(ref, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_SRC_ALPHA, TRUE); D3D11_SAMPLER_DESC sampDesc; ZeroMemory( &sampDesc, sizeof(sampDesc)); sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampDesc.MinLOD = 0; sampDesc.MaxLOD = D3D11_FLOAT32_MAX; hr = createSamplerState(ref, sampDesc); sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; hr = createSamplerState(ref, sampDesc); // cbuffers unsigned onceRef, changeRef; hr = createCBuffer(onceRef, sizeof(CBOnce)); hr = createCBuffer(changeRef, sizeof(CBOnChange)); m_renderer->cbOnceID = onceRef; m_renderer->cbOnChangeID = changeRef; // shaders unsigned int vRef, pRef; hr = createShader<ID3D11VertexShader>(vRef, standardLayout, "defaultVS", "vs_4_0"); hr = createShader<ID3D11PixelShader>(pRef, standardLayout, "defaultPS", "ps_4_0"); // SRV's hr = createSRV(ref, "grass.png"); hr = createSRV(ref, "bozo.jpg"); /*************************** MEDIUM LEVEL LINKING ****************************/ /* Init default properties */ unsigned int sRef, mRef, tRef; // Shader Shader* s = new Shader(vRef, pRef); CModel<Shader>* cs = new CModel<Shader>("default_shader", s); // Mesh createCube(vRef, pRef); // notice reuse of paramaters Mesh* m = new Mesh(vRef, pRef, 36, ref); CModel<Mesh>* cm = new CModel<Mesh>("default_mesh", m); // Transform Transform* t = new Transform(elm::vec3(100,100,100), elm::vec3(0), elm::vec3(10)); CModel<Transform>* ct = new CModel<Transform>("default_transform", t); /* register properties */ addProperty(cs); addProperty(cm); addProperty(ct); /***************************** HIGH LEVEL COMPOSITION ******************************/ // Composition Composition* c = new Composition(); c->setName("default_object"); c->setProperty<Shader>(cs); c->setProperty<Mesh>(cm); c->setProperty<Transform>(ct); addComposition(c); return true; }