Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
752 B
2
Indexable
Never
import bpy
import gpu

def draw():
    framebuffer = gpu.state.active_framebuffer_get()

    viewport_info = gpu.state.viewport_get()
    width = viewport_info[2]
    height = viewport_info[3]

    framebuffer_image.scale(width, height)
    
    pixelBuffer = framebuffer.read_color(0, 0, width, height, 4, 0, 'FLOAT')
    
    pixelBuffer.dimensions = width * height * 4
    framebuffer_image.pixels.foreach_set(pixelBuffer)

if __name__ == "__main__":
    if not "color_buffer_copy" in bpy.data.images:
        framebuffer_image = bpy.data.images.new("color_buffer_copy" , 32, 32, float_buffer=True)
    else:
        framebuffer_image = bpy.data.images["color_buffer_copy"]

    bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'PRE_VIEW')