static inline void obs_source_draw_texture(struct obs_source *source, effect_t effect, float *color_matrix, float const *color_range_min, float const *color_range_max) { texture_t tex = source->async_texture; eparam_t param; if (source->async_convert_texrender) tex = texrender_gettexture(source->async_convert_texrender); if (color_range_min) { size_t const size = sizeof(float) * 3; param = effect_getparambyname(effect, "color_range_min"); effect_setval(effect, param, color_range_min, size); } if (color_range_max) { size_t const size = sizeof(float) * 3; param = effect_getparambyname(effect, "color_range_max"); effect_setval(effect, param, color_range_max, size); } if (color_matrix) { param = effect_getparambyname(effect, "color_matrix"); effect_setval(effect, param, color_matrix, sizeof(float) * 16); } param = effect_getparambyname(effect, "image"); effect_settexture(effect, param, tex); gs_draw_sprite(tex, source->async_flip ? GS_FLIP_V : 0, 0, 0); }
static void obs_source_draw_texture(texture_t tex, struct source_frame *frame) { effect_t effect = obs->video.default_effect; bool yuv = is_yuv(frame->format); const char *type = yuv ? "DrawYUV" : "DrawRGB"; technique_t tech; eparam_t param; if (!upload_frame(tex, frame)) return; tech = effect_gettechnique(effect, type); technique_begin(tech); technique_beginpass(tech, 0); if (yuv) { param = effect_getparambyname(effect, "yuv_matrix"); effect_setval(effect, param, frame->yuv_matrix, sizeof(float) * 16); } param = effect_getparambyname(effect, "diffuse"); effect_settexture(effect, param, tex); gs_draw_sprite(tex, frame->flip ? GS_FLIP_V : 0, 0, 0); technique_endpass(tech); technique_end(tech); }
static inline void render_output_texture(struct obs_core_video *video, int cur_texture, int prev_texture) { texture_t texture = video->render_textures[prev_texture]; texture_t target = video->output_textures[cur_texture]; uint32_t width = texture_getwidth(target); uint32_t height = texture_getheight(target); /* TODO: replace with actual downscalers or unpackers */ effect_t effect = video->default_effect; technique_t tech = effect_gettechnique(effect, "DrawMatrix"); eparam_t image = effect_getparambyname(effect, "image"); eparam_t matrix = effect_getparambyname(effect, "color_matrix"); size_t passes, i; if (!video->textures_rendered[prev_texture]) return; gs_setrendertarget(target, NULL); set_render_size(width, height); /* TODO: replace with programmable code */ const float mat_val[16] = { -0.100644f, -0.338572f, 0.439216f, 0.501961f, 0.182586f, 0.614231f, 0.062007f, 0.062745f, 0.439216f, -0.398942f, -0.040274f, 0.501961f, 0.000000f, 0.000000f, 0.000000f, 1.000000f }; effect_setval(effect, matrix, mat_val, sizeof(mat_val)); effect_settexture(effect, image, texture); passes = technique_begin(tech); for (i = 0; i < passes; i++) { technique_beginpass(tech, i); gs_draw_sprite(texture, 0, width, height); technique_endpass(tech); } technique_end(tech); video->textures_output[cur_texture] = true; }