2013-09-30 19:37:13 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "test-random.h"
|
|
|
|
|
2013-11-13 05:24:20 -08:00
|
|
|
const char *random_getname(const char *locale)
|
|
|
|
{
|
|
|
|
return "Random;";
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
struct random_tex *random_create(const char *settings, obs_source_t source)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
struct random_tex *rt = bmalloc(sizeof(struct random_tex));
|
|
|
|
uint32_t *pixels = bmalloc(20*20*4);
|
2013-11-01 14:33:00 -07:00
|
|
|
char *effect_file;
|
2013-09-30 19:37:13 -07:00
|
|
|
size_t x, y;
|
|
|
|
|
|
|
|
memset(rt, 0, sizeof(struct random_tex));
|
|
|
|
|
|
|
|
for (y = 0; y < 20; y++) {
|
|
|
|
for (x = 0; x < 20; x++) {
|
|
|
|
uint32_t pixel = 0xFF000000;
|
|
|
|
pixel |= (rand()%256);
|
|
|
|
pixel |= (rand()%256) << 8;
|
|
|
|
pixel |= (rand()%256) << 16;
|
2013-10-16 23:31:18 -07:00
|
|
|
//pixel |= 0xFFFFFFFF;
|
2013-09-30 19:37:13 -07:00
|
|
|
pixels[y*20 + x] = pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
|
2013-10-16 23:31:18 -07:00
|
|
|
rt->texture = gs_create_texture(20, 20, GS_RGBA, 1,
|
|
|
|
(const void**)&pixels, 0);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(pixels);
|
|
|
|
|
|
|
|
if (!rt->texture) {
|
|
|
|
random_destroy(rt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-01 14:33:00 -07:00
|
|
|
effect_file = obs_find_plugin_file("test-input/draw.effect");
|
|
|
|
rt->whatever = gs_create_effect_from_file(effect_file, NULL);
|
|
|
|
bfree(effect_file);
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!rt->whatever) {
|
|
|
|
random_destroy(rt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
gs_leavecontext();
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void random_destroy(struct random_tex *rt)
|
|
|
|
{
|
|
|
|
if (rt) {
|
2013-10-14 12:37:52 -07:00
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
effect_destroy(rt->whatever);
|
|
|
|
texture_destroy(rt->texture);
|
|
|
|
bfree(rt);
|
2013-10-14 12:37:52 -07:00
|
|
|
|
|
|
|
gs_leavecontext();
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t random_get_output_flags(struct random_tex *rt)
|
|
|
|
{
|
|
|
|
return SOURCE_VIDEO;
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
void random_video_render(struct random_tex *rt, obs_source_t filter_target)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
technique_t tech = effect_gettechnique(rt->whatever, "Default");
|
2013-10-16 23:31:18 -07:00
|
|
|
effect_settexture(rt->whatever, effect_getparambyidx(rt->whatever, 1),
|
|
|
|
rt->texture);
|
2013-09-30 19:37:13 -07:00
|
|
|
technique_begin(tech);
|
|
|
|
technique_beginpass(tech, 0);
|
|
|
|
|
2013-11-26 21:26:14 -08:00
|
|
|
gs_draw_sprite(rt->texture, 0, 0, 0);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
technique_endpass(tech);
|
|
|
|
technique_end(tech);
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:21:42 -07:00
|
|
|
uint32_t random_getwidth(struct random_tex *rt)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
return texture_getwidth(rt->texture);
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:21:42 -07:00
|
|
|
uint32_t random_getheight(struct random_tex *rt)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
return texture_getheight(rt->texture);
|
|
|
|
}
|