OBS图形及渲染
+ -

GPU转换surface-obs_init_textures

2024-10-16 1 0
static bool obs_init_textures(struct obs_video_info *ovi)
{
    struct obs_core_video *video = &obs->video;

    for (size_t i = 0; i < NUM_TEXTURES; i++) {
#ifdef _WIN32
        if (video->using_nv12_tex)
        {
            //NV12是显卡支持的,故只有一个
            video->copy_surfaces[i][0] = gs_stagesurface_create_nv12(ovi->output_width,ovi->output_height);
            if (!video->copy_surfaces[i][0])
                return false;

        }
        else
        {
#endif
            if (video->gpu_conversion)
            {
                //YUV就需要好2-3个
                if (!obs_init_gpu_copy_surfaces(ovi, i))
                    return false;
            }
            else
            {
                //rgb只要一个
                video->copy_surfaces[i][0] =gs_stagesurface_create(ovi->output_width,ovi->output_height, GS_RGBA);
                if (!video->copy_surfaces[i][0])
                    return false;
            }
#ifdef _WIN32
        }
#endif
    }

//渲染目标纹理RGB
    video->render_texture = gs_texture_create(ovi->base_width, ovi->base_height, GS_RGBA, 1,  NULL, GS_RENDER_TARGET);
    if (!video->render_texture)
        return false;

//输出纹理RGB
    video->output_texture = gs_texture_create(ovi->output_width, ovi->output_height, GS_RGBA, 1, NULL, GS_RENDER_TARGET);
    if (!video->output_texture)
        return false;

    return true;
}

表面可能有多个:

static bool obs_init_gpu_copy_surfaces(struct obs_video_info *ovi, size_t i)
{
    struct obs_core_video *video = &obs->video;

    video->copy_surfaces[i][0] = gs_stagesurface_create(ovi->output_width, ovi->output_height, GS_R8);
    if (!video->copy_surfaces[i][0])
        return false;

    const struct video_output_info *info =    video_output_get_info(video->video);
    switch (info->format)
    {
    case VIDEO_FORMAT_I420:
        video->copy_surfaces[i][1] = gs_stagesurface_create(ovi->output_width/2, ovi->output_height/2, GS_R8);
        if (!video->copy_surfaces[i][1])
            return false;

        video->copy_surfaces[i][2] = gs_stagesurface_create(ovi->output_width/2, ovi->output_height/2, GS_R8);
        if (!video->copy_surfaces[i][2])
            return false;
        break;
    case VIDEO_FORMAT_NV12:
        video->copy_surfaces[i][1] = gs_stagesurface_create(ovi->output_width/2, ovi->output_height/2, GS_R8G8);
        if (!video->copy_surfaces[i][1])
            return false;
        break;
    case VIDEO_FORMAT_I444:
        video->copy_surfaces[i][1] = gs_stagesurface_create(ovi->output_width, ovi->output_height, GS_R8);
        if (!video->copy_surfaces[i][1])
            return false;

        video->copy_surfaces[i][2] = gs_stagesurface_create(ovi->output_width, ovi->output_height, GS_R8);
        if (!video->copy_surfaces[i][2])
            return false;
        break;
    default:
        break;
    }

    return true;
}

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!