From 58810f98069912d2d2c652ca26138541b634de61 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 26 Nov 2013 22:26:14 -0700 Subject: [PATCH] changed gs_draw_sprite to allow custom sizes, added output textures to the core, and adjusted the test code to accommodate the changes --- libobs/graphics/graphics.c | 7 ++++--- libobs/graphics/graphics.h | 11 +++++++++-- libobs/obs-data.h | 4 +++- libobs/obs-source.c | 4 +++- test/osx/test.mm | 14 ++++++++------ test/test-input/test-filter.c | 2 +- test/test-input/test-random.c | 2 +- test/win/test.cpp | 2 ++ 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 551a80902..f2951de4a 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -675,7 +675,8 @@ static inline void build_sprite(struct vb_data *data, float fcx, float fcy, vec2_set(tvarray+3, end_u, end_v); } -void gs_draw_sprite(texture_t tex, uint32_t flip) +void gs_draw_sprite(texture_t tex, uint32_t flip, uint32_t width, + uint32_t height) { graphics_t graphics = thread_graphics; float fcx, fcy; @@ -688,8 +689,8 @@ void gs_draw_sprite(texture_t tex, uint32_t flip) return; } - fcx = (float)texture_getwidth(tex); - fcy = (float)texture_getheight(tex); + fcx = width ? (float)width : (float)texture_getwidth(tex); + fcy = height ? (float)height : (float)texture_getheight(tex); data = vertexbuffer_getdata(graphics->sprite_buffer); build_sprite(data, fcx, fcy, flip); diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index 94e8f6bc8..3b7263580 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -429,7 +429,6 @@ struct gs_init_data { uint32_t adapter; }; - EXPORT int gs_create(graphics_t *graphics, const char *module, struct gs_init_data *data); EXPORT void gs_destroy(graphics_t graphics); @@ -490,7 +489,15 @@ EXPORT texture_t gs_create_volumetexture_from_file(const char *flie, #define GS_FLIP_U (1<<0) #define GS_FLIP_V (1<<1) -EXPORT void gs_draw_sprite(texture_t tex, uint32_t flip); +/** + * Draws a 2D sprite + * + * If width or height is 0, the width or height of the texture will be used. + * The flip value specifies whether the texture shoudl be flipped on the U or V + * axis with GS_FLIP_U and GS_FLIP_V. + */ +EXPORT void gs_draw_sprite(texture_t tex, uint32_t flip, uint32_t width, + uint32_t height); 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-data.h b/libobs/obs-data.h index 4846294ca..270218233 100644 --- a/libobs/obs-data.h +++ b/libobs/obs-data.h @@ -30,7 +30,7 @@ #include "obs-module.h" #include "obs-source.h" #include "obs-output.h" -/*#include "obs-service.h"*/ +#include "obs-service.h" #define NUM_TEXTURES 2 @@ -46,6 +46,8 @@ struct obs_display { struct obs_video { graphics_t graphics; stagesurf_t copy_surfaces[NUM_TEXTURES]; + texture_t render_textures[NUM_TEXTURES]; + texture_t output_textures[NUM_TEXTURES]; effect_t default_effect; bool textures_copied[NUM_TEXTURES]; bool copy_mapped; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 7fc74af15..333c57ca4 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -17,6 +17,8 @@ #include "media-io/format-conversion.h" #include "util/platform.h" +#include "graphics/matrix3.h" +#include "graphics/vec3.h" #include "obs.h" #include "obs-data.h" @@ -452,7 +454,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, frame->flip ? GS_FLIP_V : 0); + gs_draw_sprite(tex, frame->flip ? GS_FLIP_V : 0, 0, 0); technique_endpass(tech); technique_end(tech); diff --git a/test/osx/test.mm b/test/osx/test.mm index e38ea653a..b900b6228 100644 --- a/test/osx/test.mm +++ b/test/osx/test.mm @@ -41,14 +41,16 @@ static void CreateOBS(NSWindow *win) struct obs_video_info ovi; ovi.adapter = 0; - ovi.base_width = cx; - ovi.base_height = cy; ovi.fps_num = 30000; ovi.fps_den = 1001; ovi.graphics_module = "libobs-opengl"; ovi.output_format = VIDEO_FORMAT_RGBA; + ovi.base_width = cx; + ovi.base_height = cy; ovi.output_width = cx; ovi.output_height = cy; + ovi.window_width = cx; + ovi.window_height = cy; ovi.window.view = [win contentView]; if (!obs_reset_video(&ovi)) @@ -142,15 +144,15 @@ static void test() /* ------------------------------------------------------ */ /* create source */ - SourceContext source = autorelease(obs_source_create(SOURCE_INPUT, - "random", NULL)); + SourceContext source = autorelease(obs_source_create( + SOURCE_INPUT, "random", NULL)); if (!source) throw "Couldn't create random test source"; /* ------------------------------------------------------ */ /* create filter */ - SourceContext filter = autorelease(obs_source_create(SOURCE_FILTER, - "test", NULL)); + SourceContext filter = autorelease(obs_source_create( + SOURCE_FILTER, "test", NULL)); if (!filter) throw "Couldn't create test filter"; obs_source_filter_add(source.get(), filter.get()); diff --git a/test/test-input/test-filter.c b/test/test-input/test-filter.c index 38a519d96..715c6e02b 100644 --- a/test/test-input/test-filter.c +++ b/test/test-input/test-filter.c @@ -78,7 +78,7 @@ void test_video_render(struct test_filter *tf) technique_begin(tech); technique_beginpass(tech, 0); - gs_draw_sprite(tex, 0); + gs_draw_sprite(tex, 0, 0, 0); technique_endpass(tech); technique_end(tech); diff --git a/test/test-input/test-random.c b/test/test-input/test-random.c index a4d3e14c5..2e4c4035e 100644 --- a/test/test-input/test-random.c +++ b/test/test-input/test-random.c @@ -77,7 +77,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, 0); + gs_draw_sprite(rt->texture, 0, 0, 0); technique_endpass(tech); technique_end(tech); diff --git a/test/win/test.cpp b/test/win/test.cpp index 974fc2078..8607aa647 100644 --- a/test/win/test.cpp +++ b/test/win/test.cpp @@ -78,6 +78,8 @@ static void CreateOBS(HWND hwnd) ovi.fps_num = 30000; ovi.fps_den = 1001; ovi.graphics_module = "libobs-opengl"; + ovi.window_width = rc.right; + ovi.window_height = rc.bottom; ovi.output_format = VIDEO_FORMAT_RGBA; ovi.output_width = rc.right; ovi.output_height = rc.bottom;