| 136 | // *********************************************************************** |
| 137 | |
| 138 | void ReadbackImagePixels(sg_image img_id, void* pixels) { |
| 139 | _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id); |
| 140 | |
| 141 | // create staging texture |
| 142 | ID3D11Texture2D* staging_tex = NULL; |
| 143 | D3D11_TEXTURE2D_DESC staging_desc = { |
| 144 | .Width = (UINT)img->cmn.width, |
| 145 | .Height = (UINT)img->cmn.height, |
| 146 | .MipLevels = 1, |
| 147 | .ArraySize = 1, |
| 148 | .Format = img->d3d11.format, |
| 149 | .SampleDesc = { |
| 150 | .Count = 1, |
| 151 | .Quality = 0, |
| 152 | }, |
| 153 | .Usage = D3D11_USAGE_STAGING, |
| 154 | .BindFlags = 0, |
| 155 | .CPUAccessFlags = D3D11_CPU_ACCESS_READ, |
| 156 | .MiscFlags = 0 |
| 157 | }; |
| 158 | _sg_d3d11_CreateTexture2D(_sg.d3d11.dev, &staging_desc, NULL, &staging_tex); |
| 159 | |
| 160 | // copy pixels to staging texture |
| 161 | _sg.d3d11.ctx->CopySubresourceRegion( |
| 162 | (ID3D11Resource*)staging_tex, |
| 163 | 0, 0, 0, 0, |
| 164 | (ID3D11Resource*)img->d3d11.tex2d, |
| 165 | 0, NULL); |
| 166 | |
| 167 | // map the staging texture's data to CPU-accessible memory |
| 168 | D3D11_MAPPED_SUBRESOURCE msr = {.pData = NULL}; |
| 169 | _sg_d3d11_Map(_sg.d3d11.ctx, (ID3D11Resource*)staging_tex, 0, D3D11_MAP_READ, 0, &msr); |
| 170 | |
| 171 | // copy the data into the desired buffer, converting pixels to the desired format at the same time |
| 172 | int res = SDL_ConvertPixels( |
| 173 | img->cmn.width, img->cmn.height, |
| 174 | _sg_d3d11_dxgi_format_to_sdl_pixel_format(staging_desc.Format), |
| 175 | msr.pData, msr.RowPitch, |
| 176 | SDL_PIXELFORMAT_RGBA32, |
| 177 | pixels, img->cmn.width * 4); |
| 178 | _SOKOL_UNUSED(res); |
| 179 | |
| 180 | // unmap the texture |
| 181 | _sg_d3d11_Unmap(_sg.d3d11.ctx, (ID3D11Resource*)staging_tex, 0); |
| 182 | |
| 183 | if(staging_tex) _sg_d3d11_Release(staging_tex); |
| 184 | } |
| 185 | |
| 186 | // *********************************************************************** |
| 187 |
nothing calls this directly
no test coverage detected