GPU: Add immediate drawing of textured rectangle

New function called immRectf_with_texco(), which resides next to the other
immRectf utilities.

Currently used in a single place in the sequencer, but it will be used in
a few other places in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/138222
This commit is contained in:
Sergey Sharybin
2025-05-01 08:40:18 +02:00
committed by Sergey Sharybin
parent 4a0391c4a1
commit d568b78717
3 changed files with 22 additions and 15 deletions

View File

@@ -485,8 +485,6 @@ static void sequencer_draw_display_buffer(const bContext *C,
immUniformColor3f(1.0f, 1.0f, 1.0f);
}
immBegin(GPU_PRIM_TRI_FAN, 4);
rctf preview;
rctf canvas;
sequencer_preview_get_rect(&preview, scene, region, sseq, draw_overlay, draw_backdrop);
@@ -498,19 +496,7 @@ static void sequencer_draw_display_buffer(const bContext *C,
BLI_rctf_init(&canvas, 0.0f, 1.0f, 0.0f, 1.0f);
}
immAttr2f(texCoord, canvas.xmin, canvas.ymin);
immVertex2f(pos, preview.xmin, preview.ymin);
immAttr2f(texCoord, canvas.xmin, canvas.ymax);
immVertex2f(pos, preview.xmin, preview.ymax);
immAttr2f(texCoord, canvas.xmax, canvas.ymax);
immVertex2f(pos, preview.xmax, preview.ymax);
immAttr2f(texCoord, canvas.xmax, canvas.ymin);
immVertex2f(pos, preview.xmax, preview.ymin);
immEnd();
immRectf_with_texco(pos, texCoord, preview, canvas);
GPU_texture_unbind(texture);
GPU_texture_free(texture);

View File

@@ -12,10 +12,13 @@
#include "BLI_sys_types.h"
struct rctf;
/* Draw 2D rectangles (replaces glRect functions) */
/* caller is responsible for vertex format & shader */
void immRectf(uint pos, float x1, float y1, float x2, float y2);
void immRecti(uint pos, int x1, int y1, int x2, int y2);
void immRectf_with_texco(uint pos, uint tex_coord, const rctf &p, const rctf &uv);
/**
* Same as #immRectf / #immRecti but does not call #immBegin / #immEnd.

View File

@@ -12,6 +12,7 @@
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_rect.h"
#include "BLI_utildefines.h"
#include "GPU_immediate.hh"
@@ -118,6 +119,23 @@ void immRecti_fast_with_color(
immVertex2i(pos, x1, y2);
}
void immRectf_with_texco(const uint pos, const uint tex_coord, const rctf &p, const rctf &uv)
{
immBegin(GPU_PRIM_TRI_FAN, 4);
immAttr2f(tex_coord, uv.xmin, uv.ymin);
immVertex2f(pos, p.xmin, p.ymin);
immAttr2f(tex_coord, uv.xmin, uv.ymax);
immVertex2f(pos, p.xmin, p.ymax);
immAttr2f(tex_coord, uv.xmax, uv.ymax);
immVertex2f(pos, p.xmax, p.ymax);
immAttr2f(tex_coord, uv.xmax, uv.ymin);
immVertex2f(pos, p.xmax, p.ymin);
immEnd();
}
#if 0 /* more complete version in case we want that */
void immRecti_complete(int x1, int y1, int x2, int y2, const float color[4])
{