Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert GFX texture into an image #495

Open
Kryptos-FR opened this issue Dec 15, 2022 · 2 comments
Open

Convert GFX texture into an image #495

Kryptos-FR opened this issue Dec 15, 2022 · 2 comments
Labels
Theme: Graphics Graphics related

Comments

@Kryptos-FR
Copy link
Contributor

No description provided.

@guusw guusw added the Theme: Graphics Graphics related label Dec 15, 2022
@guusw
Copy link
Member

guusw commented Dec 15, 2022

Hey team! Please add your planning poker estimate with Zenhub @Kryptos-FR @sinkingsugar @tdbe

@guusw
Copy link
Member

guusw commented Dec 15, 2022

Quote from some discussion:

This should be a shard that takes a texture and basically runs this code:

WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(
    device, &(WGPUCommandEncoderDescriptor){.label = NULL});
    
wgpuCommandEncoderCopyTextureToBuffer(
    encoder,
    &(WGPUImageCopyTexture){
        .texture = texture,
        .mipLevel = 0,
        .origin =
            (WGPUOrigin3D){
                .x = 0,
                .y = 0,
                .z = 0,
            },
    },
    &(WGPUImageCopyBuffer){
        .buffer = outputBuffer,
        .layout =
            (WGPUTextureDataLayout){
                .offset = 0,
                .bytesPerRow = bufferDimensions.padded_bytes_per_row,
                .rowsPerImage = 0,
            }},
    &textureExtent);

WGPUQueue queue = wgpuDeviceGetQueue(device);
WGPUCommandBuffer cmdBuffer = wgpuCommandEncoderFinish(
    encoder, &(WGPUCommandBufferDescriptor){.label = NULL});
wgpuQueueSubmit(queue, 1, &cmdBuffer);

wgpuBufferMapAsync(outputBuffer, WGPUMapMode_Read, 0, bufferSize,
                    readBufferMap, NULL);
wgpuDevicePoll(device, true, NULL);

uint8_t *data =
    (uint8_t *)wgpuBufferGetMappedRange(outputBuffer, 0, bufferSize);
    
const char *filename = "red.png";
save_png(filename, data, &bufferDimensions);

wgpuBufferUnmap(outputBuffer);

from the (src\gfx\rust\wgpu-native\examples\capture\main.c) wgpu-native sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Theme: Graphics Graphics related
Projects
None yet
Development

No branches or pull requests

2 participants