MCPcopy Create free account
hub / github.com/DavidColson/Polybox / _sg_metal_encode_texture_pixels

Function _sg_metal_encode_texture_pixels

source/graphics_platform_d3d11.cpp:336–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336static void _sg_metal_encode_texture_pixels(int x, int y, int w, int h, id<MTLTexture> mtl_src_texture, void* pixels) {
337 SOKOL_ASSERT(!_sg.mtl.in_pass);
338 _sg_metal_commit_command_buffer();
339 MTLTextureDescriptor* mtl_dst_texture_desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mtl_src_texture.pixelFormat width:w height:h mipmapped:NO];
340 mtl_dst_texture_desc.storageMode = MTLStorageModeManaged;
341 mtl_dst_texture_desc.resourceOptions = MTLResourceStorageModeManaged;
342 mtl_dst_texture_desc.usage = MTLTextureUsageShaderRead + MTLTextureUsageShaderWrite;
343 id<MTLTexture> mtl_dst_texture = [mtl_src_texture.device newTextureWithDescriptor:mtl_dst_texture_desc];
344 id<MTLCommandBuffer> cmd_buffer = [_sg.mtl.cmd_queue commandBuffer];
345 id<MTLBlitCommandEncoder> blit_encoder = [cmd_buffer blitCommandEncoder];
346 [blit_encoder copyFromTexture:mtl_src_texture
347 sourceSlice:0
348 sourceLevel:0
349 sourceOrigin:MTLOriginMake(x,y,0)
350 sourceSize:MTLSizeMake(w,h,1)
351 toTexture:mtl_dst_texture
352 destinationSlice:0
353 destinationLevel:0
354 destinationOrigin:MTLOriginMake(0,0,0)
355 ];
356 [blit_encoder synchronizeTexture:mtl_dst_texture slice:0 level:0];
357 [blit_encoder endEncoding];
358 [cmd_buffer commit];
359 [cmd_buffer waitUntilCompleted];
360
361 MTLRegion mtl_region = MTLRegionMake2D(0, 0, w, h);
362 void* temp_pixels = (void*)SOKOL_MALLOC(w * 4 * h);
363 SOKOL_ASSERT(temp_pixels);
364 [mtl_dst_texture getBytes:temp_pixels bytesPerRow:w * 4 fromRegion:mtl_region mipmapLevel:0];
365 int res = SDL_ConvertPixels(w, h, _sg_metal_texture_format_to_sdl_pixel_format(mtl_dst_texture_desc.pixelFormat), temp_pixels, w * 4, SDL_PIXELFORMAT_RGBA32, pixels, w * 4);
366 SOKOL_FREE(temp_pixels);
367 SOKOL_ASSERT(res == 0);
368 _SOKOL_UNUSED(res);
369}
370
371static void _sg_metal_query_image_pixels(_sg_image_t* img, void* pixels) {
372 id<MTLTexture> mtl_src_texture = _sg.mtl.idpool.pool[img->mtl.tex[0]];

Callers 2

_sg_metal_query_pixelsFunction · 0.85

Tested by

no test coverage detected