gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, GLenum currentValueType, GLint start, GLsizei count, GLsizei instances, unsigned int offset, const uint8_t *sourceData) { if (!mBuffer) { return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized."); } int inputStride = static_cast<int>(ComputeVertexAttributeStride(attrib)); // This will map the resource if it isn't already mapped. ANGLE_TRY(mapResource()); uint8_t *output = mMappedResourceData + offset; const uint8_t *input = sourceData; if (instances == 0 || attrib.divisor == 0) { input += inputStride * start; } gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValueType); const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel; const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormatType, featureLevel); ASSERT(vertexFormatInfo.copyFunction != NULL); vertexFormatInfo.copyFunction(input, inputStride, count, output); return gl::NoError(); }
image::Image * getSubResourceImage(ID3D10Device *pDevice, ID3D10Resource *pResource, DXGI_FORMAT Format, UINT ArraySlice, UINT MipSlice) { image::Image *image = NULL; UINT SubResource; D3D10_MAPPED_TEXTURE3D MappedSubResource; HRESULT hr; if (!pResource) { return NULL; } ResourceDesc Desc; getResourceDesc(pResource, &Desc); assert(ArraySlice < Desc.ArraySize); assert(MipSlice < Desc.MipLevels); assert(Desc.SampleDesc.Count > 0); SubResource = ArraySlice*Desc.MipLevels + MipSlice; /* * Resolve the subresource. */ ResourceDesc ResolvedDesc = Desc; ResolvedDesc.Width = std::max(Desc.Width >> MipSlice, 1U); ResolvedDesc.Height = std::max(Desc.Height >> MipSlice, 1U); ResolvedDesc.Depth = std::max(Desc.Depth >> MipSlice, 1U); ResolvedDesc.ArraySize = 1; ResolvedDesc.MipLevels = 1; ResolvedDesc.SampleDesc.Count = 1; ResolvedDesc.SampleDesc.Quality = 0; ResolvedDesc.Usage = D3D10_USAGE_DEFAULT; ResolvedDesc.BindFlags = 0; ResolvedDesc.CPUAccessFlags = 0; ResolvedDesc.MiscFlags = 0; com_ptr<ID3D10Resource> pResolvedResource; if (Desc.SampleDesc.Count == 1) { pResolvedResource = pResource; } else { hr = createResource(pDevice, &ResolvedDesc, &pResolvedResource); if (FAILED(hr)) { return NULL; } pDevice->ResolveSubresource(pResolvedResource, 0, pResource, SubResource, Format); SubResource = 0; } /* * Stage the subresource. */ ResourceDesc StagingDesc = ResolvedDesc; StagingDesc.Usage = D3D10_USAGE_STAGING; StagingDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; com_ptr<ID3D10Resource> pStagingResource; hr = createResource(pDevice, &StagingDesc, &pStagingResource); if (FAILED(hr)) { return NULL; } pDevice->CopySubresourceRegion(pStagingResource, 0, 0, 0, 0, pResolvedResource, SubResource, NULL); /* * Map and read the subresource. */ hr = mapResource(pStagingResource, 0, D3D10_MAP_READ, 0, &MappedSubResource); if (FAILED(hr)) { goto no_map; } image = ConvertImage(Format, MappedSubResource.pData, MappedSubResource.RowPitch, StagingDesc.Width, StagingDesc.Height); unmapResource(pStagingResource, 0); no_map: return image; }