diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 3bdccab8e..551a80902 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -644,12 +644,42 @@ texture_t gs_create_volumetexture_from_file(const char *file, uint32_t flags) return NULL; } -void gs_draw_sprite(texture_t tex) +static inline void assign_sprite_uv(float *start, float *end, bool flip) +{ + if (!flip) { + *start = 0.0f; + *end = 1.0f; + } else { + *start = 1.0f; + *end = 0.0f; + } +} + +static inline void build_sprite(struct vb_data *data, float fcx, float fcy, + uint32_t flip) +{ + struct vec2 *tvarray = data->tvarray[0].array; + float start_u, end_u; + float start_v, end_v; + + assign_sprite_uv(&start_u, &end_u, (flip & GS_FLIP_U) != 0); + assign_sprite_uv(&start_v, &end_v, (flip & GS_FLIP_V) != 0); + + vec3_zero(data->points); + vec3_set(data->points+1, fcx, 0.0f, 0.0f); + vec3_set(data->points+2, 0.0f, fcy, 0.0f); + vec3_set(data->points+3, fcx, fcy, 0.0f); + vec2_set(tvarray, start_u, start_v); + vec2_set(tvarray+1, end_u, start_v); + vec2_set(tvarray+2, start_u, end_v); + vec2_set(tvarray+3, end_u, end_v); +} + +void gs_draw_sprite(texture_t tex, uint32_t flip) { graphics_t graphics = thread_graphics; float fcx, fcy; struct vb_data *data; - struct vec2 *tvarray; assert(tex); @@ -662,15 +692,7 @@ void gs_draw_sprite(texture_t tex) fcy = (float)texture_getheight(tex); data = vertexbuffer_getdata(graphics->sprite_buffer); - tvarray = data->tvarray[0].array; - vec3_zero(data->points); - vec3_set(data->points+1, fcx, 0.0f, 0.0f); - vec3_set(data->points+2, 0.0f, fcy, 0.0f); - vec3_set(data->points+3, fcx, fcy, 0.0f); - vec2_zero(tvarray); - vec2_set(tvarray+1, 1.0f, 0.0f); - vec2_set(tvarray+2, 0.0f, 1.0f); - vec2_set(tvarray+3, 1.0f, 1.0f); + build_sprite(data, fcx, fcy, flip); vertexbuffer_flush(graphics->sprite_buffer, false); gs_load_vertexbuffer(graphics->sprite_buffer); gs_load_indexbuffer(NULL); diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index c74dadff2..48c4139df 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -479,7 +479,10 @@ EXPORT texture_t gs_create_cubetexture_from_file(const char *flie, EXPORT texture_t gs_create_volumetexture_from_file(const char *flie, uint32_t flags); -EXPORT void gs_draw_sprite(texture_t tex); +#define GS_FLIP_U (1<<0) +#define GS_FLIP_V (1<<1) + +EXPORT void gs_draw_sprite(texture_t tex, uint32_t flip); EXPORT void gs_draw_cube_backdrop(texture_t cubetex, const struct quat *rot, float left, float right, float top, float bottom, float znear); diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 73ba4125c..509acf4bc 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -411,7 +411,7 @@ static void obs_source_draw_texture(texture_t tex, struct source_frame *frame) param = effect_getparambyname(effect, "diffuse"); effect_settexture(effect, param, tex); - gs_draw_sprite(tex); + gs_draw_sprite(tex, frame->flip ? GS_FLIP_V : 0); technique_endpass(tech); technique_end(tech); @@ -427,10 +427,8 @@ static void obs_source_render_async_video(obs_source_t source) if (!source->timing_set && source->audio_buffer.num) obs_source_flush_audio_buffer(source); - if (set_texture_size(source, frame)) { - source->flip = frame->flip; + if (set_texture_size(source, frame)) obs_source_draw_texture(source->output_texture, frame); - } obs_source_releaseframe(source, frame); } diff --git a/libobs/obs-source.h b/libobs/obs-source.h index 046abf612..b68e9d350 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -214,7 +214,6 @@ struct obs_source { uint64_t last_frame_timestamp; uint64_t last_sys_timestamp; texture_t output_texture; - bool flip; audio_line_t audio_line; DARRAY(struct audiobuf) audio_buffer; diff --git a/test/test-input/test-filter.c b/test/test-input/test-filter.c index d4e336d88..d94b0d4fe 100644 --- a/test/test-input/test-filter.c +++ b/test/test-input/test-filter.c @@ -69,7 +69,7 @@ void test_video_render(struct test_filter *tf) technique_begin(tech); technique_beginpass(tech, 0); - gs_draw_sprite(tex); + gs_draw_sprite(tex, 0); technique_endpass(tech); technique_end(tech); diff --git a/test/test-input/test-random.c b/test/test-input/test-random.c index ca0c9834e..ce07486d4 100644 --- a/test/test-input/test-random.c +++ b/test/test-input/test-random.c @@ -68,7 +68,7 @@ void random_video_render(struct random_tex *rt, obs_source_t filter_target) technique_begin(tech); technique_beginpass(tech, 0); - gs_draw_sprite(rt->texture); + gs_draw_sprite(rt->texture, 0); technique_endpass(tech); technique_end(tech);