浏览代码

libobs/graphics: Add gs_draw_quadf()

Adds a function to draw a sprite or quad using floating point sizes
rather than integer sizes. Also named it more appropriately.
Lain 7 月之前
父节点
当前提交
775ac56bc8

+ 1 - 1
docs/sphinx/graphics.rst

@@ -85,7 +85,7 @@ effects:  **ViewProj**, and **image**.  The **ViewProj** parameter
 combination.  The **image** parameter (which is a texture2d) is a
 commonly used parameter for the main texture; this parameter will be
 used with the functions :c:func:`obs_source_draw()`,
-:c:func:`gs_draw_sprite()`, and
+:c:func:`gs_draw_sprite()`, :c:func:`gs_draw_quadf()`, and
 :c:func:`obs_source_process_filter_end()`.
 
 Here is an example of effect parameters:

+ 22 - 2
docs/sphinx/reference-libobs-graphics-graphics.rst

@@ -420,13 +420,33 @@ Draw Functions
 .. function:: void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t height)
 
    Draws a 2D sprite.  Sets the "image" parameter of the current effect
-   to the texture and renders a quad.
+   to the texture and renders a quad. Can be omitted if drawing without
+   a texture.
 
    If width or height is 0, the width or height of the texture will be
    used.  The flip value specifies whether the texture should be flipped
    on the U or V axis with GS_FLIP_U and GS_FLIP_V.
 
-   :param tex:    Texture to draw
+   :param tex:    Texture to draw (can be NULL if drawing without a
+                  texture)
+   :param flip:   Can be 0 or a bitwise-OR combination of one of the
+                  following values:
+
+                  - GS_FLIP_U - Flips the texture horizontally
+                  - GS_FLIP_V - Flips the texture vertically
+
+   :param width:  Width
+   :param height: Height
+
+---------------------
+
+.. function:: void gs_draw_quadf(gs_texture_t *tex, uint32_t flip, float width, float height)
+
+   Same as :c:func:`gs_draw_sprite()`, but with floating point width/height
+   values instead of integer width/height values.
+
+   :param tex:    Texture to draw (can be NULL if drawing without a
+                  texture)
    :param flip:   Can be 0 or a bitwise-OR combination of one of the
                   following values:
 

+ 9 - 4
libobs/graphics/graphics.c

@@ -1004,7 +1004,7 @@ static inline void build_sprite_rect(struct gs_vb_data *data, gs_texture_t *tex,
 	build_sprite(data, fcx, fcy, start_u, end_u, start_v, end_v);
 }
 
-void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t height)
+void gs_draw_quadf(gs_texture_t *tex, uint32_t flip, float width, float height)
 {
 	graphics_t *graphics = thread_graphics;
 	float fcx, fcy;
@@ -1016,15 +1016,15 @@ void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t h
 			return;
 		}
 	} else {
-		if (!width || !height) {
+		if (width == 0.0f || height == 0.0f) {
 			blog(LOG_ERROR, "A sprite cannot be drawn without "
 					"a width/height");
 			return;
 		}
 	}
 
-	fcx = width ? (float)width : (float)gs_texture_get_width(tex);
-	fcy = height ? (float)height : (float)gs_texture_get_height(tex);
+	fcx = width != 0.0f ? width : (float)gs_texture_get_width(tex);
+	fcy = height != 0.0f ? height : (float)gs_texture_get_height(tex);
 
 	gs_matrix_push();
 	gs_matrix_scale3f(fcx, fcy, 1.0f);
@@ -1045,6 +1045,11 @@ void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t h
 	gs_matrix_pop();
 }
 
+void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t height)
+{
+	gs_draw_quadf(tex, flip, (float)width, (float)height);
+}
+
 void gs_draw_sprite_subregion(gs_texture_t *tex, uint32_t flip, uint32_t sub_x, uint32_t sub_y, uint32_t sub_cx,
 			      uint32_t sub_cy)
 {

+ 1 - 0
libobs/graphics/graphics.h

@@ -581,6 +581,7 @@ EXPORT uint8_t *gs_create_texture_file_data3(const char *file, enum gs_image_alp
  * axis with GS_FLIP_U and GS_FLIP_V.
  */
 EXPORT void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t height);
+EXPORT void gs_draw_quadf(gs_texture_t *tex, uint32_t flip, float width, float height);
 
 EXPORT void gs_draw_sprite_subregion(gs_texture_t *tex, uint32_t flip, uint32_t x, uint32_t y, uint32_t cx,
 				     uint32_t cy);