test-random.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <stdlib.h>
  2. #include "test-random.h"
  3. struct random_tex *random_create(const char *settings, obs_source_t source)
  4. {
  5. struct random_tex *rt = bmalloc(sizeof(struct random_tex));
  6. uint32_t *pixels = bmalloc(20*20*4);
  7. char *effect_file;
  8. size_t x, y;
  9. memset(rt, 0, sizeof(struct random_tex));
  10. for (y = 0; y < 20; y++) {
  11. for (x = 0; x < 20; x++) {
  12. uint32_t pixel = 0xFF000000;
  13. pixel |= (rand()%256);
  14. pixel |= (rand()%256) << 8;
  15. pixel |= (rand()%256) << 16;
  16. //pixel |= 0xFFFFFFFF;
  17. pixels[y*20 + x] = pixel;
  18. }
  19. }
  20. gs_entercontext(obs_graphics());
  21. rt->texture = gs_create_texture(20, 20, GS_RGBA, 1,
  22. (const void**)&pixels, 0);
  23. bfree(pixels);
  24. if (!rt->texture) {
  25. random_destroy(rt);
  26. return NULL;
  27. }
  28. effect_file = obs_find_plugin_file("test-input/draw.effect");
  29. rt->whatever = gs_create_effect_from_file(effect_file, NULL);
  30. bfree(effect_file);
  31. if (!rt->whatever) {
  32. random_destroy(rt);
  33. return NULL;
  34. }
  35. gs_leavecontext();
  36. return rt;
  37. }
  38. void random_destroy(struct random_tex *rt)
  39. {
  40. if (rt) {
  41. gs_entercontext(obs_graphics());
  42. effect_destroy(rt->whatever);
  43. texture_destroy(rt->texture);
  44. bfree(rt);
  45. gs_leavecontext();
  46. }
  47. }
  48. uint32_t random_get_output_flags(struct random_tex *rt)
  49. {
  50. return SOURCE_VIDEO;
  51. }
  52. void random_video_render(struct random_tex *rt, obs_source_t filter_target)
  53. {
  54. technique_t tech = effect_gettechnique(rt->whatever, "Default");
  55. effect_settexture(rt->whatever, effect_getparambyidx(rt->whatever, 1),
  56. rt->texture);
  57. technique_begin(tech);
  58. technique_beginpass(tech, 0);
  59. gs_draw_sprite(rt->texture, 0);
  60. technique_endpass(tech);
  61. technique_end(tech);
  62. }
  63. uint32_t random_getwidth(struct random_tex *rt)
  64. {
  65. return texture_getwidth(rt->texture);
  66. }
  67. uint32_t random_getheight(struct random_tex *rt)
  68. {
  69. return texture_getheight(rt->texture);
  70. }