test-random.c 1.9 KB

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