| 303 | } |
| 304 | |
| 305 | void UI_d3d11_create_texture(UI_Context *ctx, i32 handle, u8 *data, int w, int h) { |
| 306 | UI_assert(ctx != nullptr && "UI context *ctx is a null pointer!"); |
| 307 | UI_assert(ctx->initialized && "UI context wasn't initialized!"); |
| 308 | UI_D3D11_Context *d3d_ctx = (UI_D3D11_Context *)ctx->backend_context; |
| 309 | UI_assert(d3d_ctx != nullptr && "d3d11 UI context not initialized!"); |
| 310 | UI_assert(handle >= 0 && handle < UI_MAX_TEXTURES); |
| 311 | |
| 312 | D3D11_TEXTURE2D_DESC texture_desc = {}; |
| 313 | texture_desc.Width = w; |
| 314 | texture_desc.Height = h; |
| 315 | texture_desc.MipLevels = 1; |
| 316 | texture_desc.ArraySize = 1; |
| 317 | texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; |
| 318 | texture_desc.SampleDesc.Count = 1; |
| 319 | texture_desc.Usage = D3D11_USAGE_IMMUTABLE; |
| 320 | texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; |
| 321 | |
| 322 | D3D11_SUBRESOURCE_DATA texture_SRD = {}; |
| 323 | texture_SRD.pSysMem = data; |
| 324 | texture_SRD.SysMemPitch = w * 4; |
| 325 | |
| 326 | UI_D3D11_Texture *texture = &d3d_ctx->textures[handle]; |
| 327 | texture->size = v2(w, h); |
| 328 | err(d3d_ctx->device->CreateTexture2D(&texture_desc, &texture_SRD, &texture->texture)); |
| 329 | err(d3d_ctx->device->CreateShaderResourceView(texture->texture, nullptr, &texture->srv)); |
| 330 | } |
| 331 | |
| 332 | #undef err |