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;
}