obs-studio/test/test-input/test-filter.c

81 lines
1.7 KiB
C
Raw Normal View History

2013-09-30 19:37:13 -07:00
#include "test-filter.h"
struct test_filter *test_create(const char *settings, obs_source_t source)
2013-09-30 19:37:13 -07:00
{
struct test_filter *tf = bmalloc(sizeof(struct test_filter));
char *effect_file;
2013-09-30 19:37:13 -07:00
memset(tf, 0, sizeof(struct test_filter));
gs_entercontext(obs_graphics());
effect_file = obs_find_plugin_file("test-input/test.effect");
2013-09-30 19:37:13 -07:00
tf->source = source;
tf->whatever = gs_create_effect_from_file(effect_file, NULL);
bfree(effect_file);
2013-09-30 19:37:13 -07:00
if (!tf->whatever) {
test_destroy(tf);
return NULL;
}
tf->texrender = texrender_create(GS_RGBA, GS_ZS_NONE);
gs_leavecontext();
2013-09-30 19:37:13 -07:00
return tf;
}
void test_destroy(struct test_filter *tf)
{
if (tf) {
gs_entercontext(obs_graphics());
2013-09-30 19:37:13 -07:00
effect_destroy(tf->whatever);
texrender_destroy(tf->texrender);
bfree(tf);
gs_leavecontext();
2013-09-30 19:37:13 -07:00
}
}
uint32_t test_get_output_flags(struct test_filter *tf)
{
return SOURCE_VIDEO;
}
void test_video_tick(struct test_filter *tf, float seconds)
{
texrender_reset(tf->texrender);
}
void test_video_render(struct test_filter *tf)
{
obs_source_t filter_target = obs_filter_gettarget(tf->source);
int cx = obs_source_getwidth(filter_target);
int cy = obs_source_getheight(filter_target);
2013-09-30 19:37:13 -07:00
float fcx = (float)cx;
float fcy = (float)cy;
technique_t tech;
texture_t tex;
if (texrender_begin(tf->texrender, cx, cy)) {
gs_ortho(0.0f, fcx, 0.0f, fcy, -100.0f, 100.0f);
obs_source_video_render(filter_target);
2013-09-30 19:37:13 -07:00
texrender_end(tf->texrender);
}
/* --------------------------- */
tex = texrender_gettexture(tf->texrender);
tech = effect_gettechnique(tf->whatever, "Default");
effect_settexture(tf->whatever, effect_getparambyidx(tf->whatever, 1),
tex);
technique_begin(tech);
technique_beginpass(tech, 0);
2013-10-26 15:05:51 -07:00
gs_draw_sprite(tex, 0);
2013-09-30 19:37:13 -07:00
technique_endpass(tech);
technique_end(tech);
}