1
0
Эх сурвалжийг харах

changed gs_draw_sprite to allow custom sizes, added output textures to the core, and adjusted the test code to accommodate the changes

jp9000 12 жил өмнө
parent
commit
58810f9806

+ 4 - 3
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);
 	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;
 	graphics_t graphics = thread_graphics;
 	float fcx, fcy;
 	float fcx, fcy;
@@ -688,8 +689,8 @@ void gs_draw_sprite(texture_t tex, uint32_t flip)
 		return;
 		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);
 	data = vertexbuffer_getdata(graphics->sprite_buffer);
 	build_sprite(data, fcx, fcy, flip);
 	build_sprite(data, fcx, fcy, flip);

+ 9 - 2
libobs/graphics/graphics.h

@@ -429,7 +429,6 @@ struct gs_init_data {
 	uint32_t                adapter;
 	uint32_t                adapter;
 };
 };
 
 
-
 EXPORT int gs_create(graphics_t *graphics, const char *module,
 EXPORT int gs_create(graphics_t *graphics, const char *module,
 		struct gs_init_data *data);
 		struct gs_init_data *data);
 EXPORT void gs_destroy(graphics_t graphics);
 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_U (1<<0)
 #define GS_FLIP_V (1<<1)
 #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,
 EXPORT void gs_draw_cube_backdrop(texture_t cubetex, const struct quat *rot,
 		float left, float right, float top, float bottom, float znear);
 		float left, float right, float top, float bottom, float znear);

+ 3 - 1
libobs/obs-data.h

@@ -30,7 +30,7 @@
 #include "obs-module.h"
 #include "obs-module.h"
 #include "obs-source.h"
 #include "obs-source.h"
 #include "obs-output.h"
 #include "obs-output.h"
-/*#include "obs-service.h"*/
+#include "obs-service.h"
 
 
 #define NUM_TEXTURES 2
 #define NUM_TEXTURES 2
 
 
@@ -46,6 +46,8 @@ struct obs_display {
 struct obs_video {
 struct obs_video {
 	graphics_t                  graphics;
 	graphics_t                  graphics;
 	stagesurf_t                 copy_surfaces[NUM_TEXTURES];
 	stagesurf_t                 copy_surfaces[NUM_TEXTURES];
+	texture_t                   render_textures[NUM_TEXTURES];
+	texture_t                   output_textures[NUM_TEXTURES];
 	effect_t                    default_effect;
 	effect_t                    default_effect;
 	bool                        textures_copied[NUM_TEXTURES];
 	bool                        textures_copied[NUM_TEXTURES];
 	bool                        copy_mapped;
 	bool                        copy_mapped;

+ 3 - 1
libobs/obs-source.c

@@ -17,6 +17,8 @@
 
 
 #include "media-io/format-conversion.h"
 #include "media-io/format-conversion.h"
 #include "util/platform.h"
 #include "util/platform.h"
+#include "graphics/matrix3.h"
+#include "graphics/vec3.h"
 
 
 #include "obs.h"
 #include "obs.h"
 #include "obs-data.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");
 	param = effect_getparambyname(effect, "diffuse");
 	effect_settexture(effect, param, tex);
 	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_endpass(tech);
 	technique_end(tech);
 	technique_end(tech);

+ 8 - 6
test/osx/test.mm

@@ -41,14 +41,16 @@ static void CreateOBS(NSWindow *win)
 
 
 	struct obs_video_info ovi;
 	struct obs_video_info ovi;
 	ovi.adapter         = 0;
 	ovi.adapter         = 0;
-	ovi.base_width      = cx;
-	ovi.base_height     = cy;
 	ovi.fps_num         = 30000;
 	ovi.fps_num         = 30000;
 	ovi.fps_den         = 1001;
 	ovi.fps_den         = 1001;
 	ovi.graphics_module = "libobs-opengl";
 	ovi.graphics_module = "libobs-opengl";
 	ovi.output_format   = VIDEO_FORMAT_RGBA;
 	ovi.output_format   = VIDEO_FORMAT_RGBA;
+	ovi.base_width      = cx;
+	ovi.base_height     = cy;
 	ovi.output_width    = cx;
 	ovi.output_width    = cx;
 	ovi.output_height   = cy;
 	ovi.output_height   = cy;
+	ovi.window_width    = cx;
+	ovi.window_height   = cy;
 	ovi.window.view     = [win contentView];
 	ovi.window.view     = [win contentView];
 
 
 	if (!obs_reset_video(&ovi))
 	if (!obs_reset_video(&ovi))
@@ -142,15 +144,15 @@ static void test()
 
 
 		/* ------------------------------------------------------ */
 		/* ------------------------------------------------------ */
 		/* create source */
 		/* create source */
-		SourceContext source = autorelease(obs_source_create(SOURCE_INPUT,
-				"random", NULL));
+		SourceContext source = autorelease(obs_source_create(
+				SOURCE_INPUT, "random", NULL));
 		if (!source)
 		if (!source)
 			throw "Couldn't create random test source";
 			throw "Couldn't create random test source";
 
 
 		/* ------------------------------------------------------ */
 		/* ------------------------------------------------------ */
 		/* create filter */
 		/* create filter */
-		SourceContext filter = autorelease(obs_source_create(SOURCE_FILTER,
-				"test", NULL));
+		SourceContext filter = autorelease(obs_source_create(
+				SOURCE_FILTER, "test", NULL));
 		if (!filter)
 		if (!filter)
 			throw "Couldn't create test filter";
 			throw "Couldn't create test filter";
 		obs_source_filter_add(source.get(), filter.get());
 		obs_source_filter_add(source.get(), filter.get());

+ 1 - 1
test/test-input/test-filter.c

@@ -78,7 +78,7 @@ void test_video_render(struct test_filter *tf)
 	technique_begin(tech);
 	technique_begin(tech);
 	technique_beginpass(tech, 0);
 	technique_beginpass(tech, 0);
 
 
-	gs_draw_sprite(tex, 0);
+	gs_draw_sprite(tex, 0, 0, 0);
 
 
 	technique_endpass(tech);
 	technique_endpass(tech);
 	technique_end(tech);
 	technique_end(tech);

+ 1 - 1
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_begin(tech);
 	technique_beginpass(tech, 0);
 	technique_beginpass(tech, 0);
 
 
-	gs_draw_sprite(rt->texture, 0);
+	gs_draw_sprite(rt->texture, 0, 0, 0);
 
 
 	technique_endpass(tech);
 	technique_endpass(tech);
 	technique_end(tech);
 	technique_end(tech);

+ 2 - 0
test/win/test.cpp

@@ -78,6 +78,8 @@ static void CreateOBS(HWND hwnd)
 	ovi.fps_num         = 30000;
 	ovi.fps_num         = 30000;
 	ovi.fps_den         = 1001;
 	ovi.fps_den         = 1001;
 	ovi.graphics_module = "libobs-opengl";
 	ovi.graphics_module = "libobs-opengl";
+	ovi.window_width    = rc.right;
+	ovi.window_height   = rc.bottom;
 	ovi.output_format   = VIDEO_FORMAT_RGBA;
 	ovi.output_format   = VIDEO_FORMAT_RGBA;
 	ovi.output_width    = rc.right;
 	ovi.output_width    = rc.right;
 	ovi.output_height   = rc.bottom;
 	ovi.output_height   = rc.bottom;