Exemplo n.º 1
0
void obs_source_process_filter(obs_source_t filter, effect_t effect,
		uint32_t width, uint32_t height, enum gs_color_format format,
		enum allow_direct_render allow_direct)
{
	obs_source_t target, parent;
	uint32_t     target_flags, parent_flags;
	int          cx, cy;
	bool         use_matrix, expects_def, can_directly;

	if (!filter) return;

	target       = obs_filter_gettarget(filter);
	parent       = obs_filter_getparent(filter);
	target_flags = target->info.output_flags;
	parent_flags = parent->info.output_flags;
	cx           = obs_source_getwidth(target);
	cy           = obs_source_getheight(target);
	use_matrix   = !!(target_flags & OBS_SOURCE_COLOR_MATRIX);
	expects_def  = !(parent_flags & OBS_SOURCE_CUSTOM_DRAW);
	can_directly = allow_direct == ALLOW_DIRECT_RENDERING;

	/* if the parent does not use any custom effects, and this is the last
	 * filter in the chain for the parent, then render the parent directly
	 * using the filter effect instead of rendering to texture to reduce
	 * the total number of passes */
	if (can_directly && expects_def && target == parent) {
		render_filter_bypass(target, effect, use_matrix);
		return;
	}

	if (!filter->filter_texrender)
		filter->filter_texrender = texrender_create(format,
				GS_ZS_NONE);

	if (texrender_begin(filter->filter_texrender, cx, cy)) {
		gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
		if (expects_def && parent == target)
			obs_source_default_render(parent, use_matrix);
		else
			obs_source_video_render(target);
		texrender_end(filter->filter_texrender);
	}

	/* --------------------------- */

	render_filter_tex(texrender_gettexture(filter->filter_texrender),
			effect, width, height, use_matrix);
}
Exemplo n.º 2
0
static vec2 GetItemSize(obs_sceneitem_t item)
{
	obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(item);
	vec2 size;

	if (boundsType != OBS_BOUNDS_NONE) {
		obs_sceneitem_get_bounds(item, &size);
	} else {
		obs_source_t source = obs_sceneitem_getsource(item);
		vec2 scale;

		obs_sceneitem_getscale(item, &scale);
		size.x = float(obs_source_getwidth(source))  * scale.x;
		size.y = float(obs_source_getheight(source)) * scale.y;
	}

	return size;
}
Exemplo n.º 3
0
void obs_source_process_filter(obs_source_t filter, texrender_t texrender,
                               effect_t effect, uint32_t width, uint32_t height,
                               enum allow_direct_render allow_direct)
{
    obs_source_t target       = obs_filter_gettarget(filter);
    obs_source_t parent       = obs_filter_getparent(filter);
    uint32_t     target_flags = obs_source_get_output_flags(target);
    uint32_t     parent_flags = obs_source_get_output_flags(parent);
    int          cx           = obs_source_getwidth(target);
    int          cy           = obs_source_getheight(target);
    bool         yuv          = (target_flags & SOURCE_YUV) != 0;
    bool         expects_def  = (parent_flags & SOURCE_DEFAULT_EFFECT) != 0;
    bool         can_directly = allow_direct == ALLOW_DIRECT_RENDERING;

    /* if the parent does not use any custom effects, and this is the last
     * filter in the chain for the parent, then render the parent directly
     * using the filter effect instead of rendering to texture to reduce
     * the total number of passes */
    if (can_directly && expects_def && target == parent) {
        render_filter_bypass(target, effect, width, height, yuv);
        return;
    }

    if (texrender_begin(texrender, cx, cy)) {
        gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
        if (expects_def && parent == target)
            obs_source_default_render(parent, yuv);
        else
            obs_source_video_render(target);
        texrender_end(texrender);
    }

    /* --------------------------- */

    render_filter_tex(texrender_gettexture(texrender), effect,
                      width, height, yuv);
}
Exemplo n.º 4
0
void OBSBasicPreview::StretchItem(const vec2 &pos)
{
	Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
	obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(stretchItem);
	uint32_t stretchFlags = (uint32_t)stretchHandle;
	bool shiftDown = (modifiers & Qt::ShiftModifier);
	vec3 tl, br, pos3;

	vec3_zero(&tl);
	vec3_set(&br, stretchItemSize.x, stretchItemSize.y, 0.0f);

	vec3_set(&pos3, pos.x, pos.y, 0.0f);
	vec3_transform(&pos3, &pos3, &screenToItem);

	if (stretchFlags & ITEM_LEFT)
		tl.x = pos3.x;
	else if (stretchFlags & ITEM_RIGHT)
		br.x = pos3.x;

	if (stretchFlags & ITEM_TOP)
		tl.y = pos3.y;
	else if (stretchFlags & ITEM_BOTTOM)
		br.y = pos3.y;

	if (!(modifiers & Qt::ControlModifier))
		SnapStretchingToScreen(tl, br);

	obs_source_t source = obs_sceneitem_getsource(stretchItem);

	vec2 baseSize;
	vec2_set(&baseSize,
		float(obs_source_getwidth(source)),
		float(obs_source_getheight(source)));

	vec2 size;
	vec2_set(&size,br. x - tl.x, br.y - tl.y);

	if (boundsType != OBS_BOUNDS_NONE) {
		if (shiftDown)
			ClampAspect(tl, br, size, baseSize);

		if (tl.x > br.x) std::swap(tl.x, br.x);
		if (tl.y > br.y) std::swap(tl.y, br.y);

		vec2_abs(&size, &size);

		obs_sceneitem_set_bounds(stretchItem, &size);
	} else {
		if (!shiftDown)
			ClampAspect(tl, br, size, baseSize);

		vec2_div(&size, &size, &baseSize);
		obs_sceneitem_setscale(stretchItem, &size);
	}

	pos3 = CalculateStretchPos(tl, br);
	vec3_transform(&pos3, &pos3, &itemToScreen);

	vec2 newPos;
	vec2_set(&newPos, std::round(pos3.x), std::round(pos3.y));
	obs_sceneitem_setpos(stretchItem, &newPos);
}