Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2020-09-11 08:59:48 +0300
committerJeroen Bakker <jeroen@blender.org>2020-09-11 09:08:46 +0300
commitd6525e8d133b787655bdb2c2fcef218591a457c3 (patch)
treeb4dbb06b75005deee918d7816c074a5735be930c /source/blender/draw/intern/draw_manager_text.c
parentd023c4104cb642c839d5868411a3b719f3528421 (diff)
Use DrawManager for Image/UV Editor
This project moves the current UV/Image editor drawing to the draw manager. Why would we do this: **Performance**: Current implementation would draw each texel per time. Multiple texels could be drawn per pixel what would overwrite the previous result. You can notice this when working with large textures. Repeat image drawing made this visible by drawing for a small period of time and stop drawing the rest. Now the rendering is fast and all repeated images are drawn. **Alpha drawing**: Current implementation would draw directly in display space. Giving incorrect results when displaying alpha transparent images. This addresses {T52680}, {T74709}, {T79518} The image editor now can show emission only colors. See {D8234} for examples. **Current Limitations** Using images that are larger than supported by your GPU are resized (eg larger than 16000x16000 are resized to 8k). This leaves some blurring artifacts. It is a low priority to add support back of displaying individual pixels of huge images. There is a design task {T80113} with more detail. **Implementation overview** Introduced an Image Engine in the draw module. this engine is responsible for drawing the texture in the main area of the UV/Image editor. The overlay engine has a edit_uv overlay which is responsible to draw the UV's, shadows and overlays specifically for the UV Image editor. The background + checker pattern is drawn by the overlay_background. The patch will allow us to share overlays between the 3d viewport and UV/Image editor more easily. In most cases we just need to switch the `pos` with the `u` attribute in the vertex shader. The project can be activated in the user preferences as experimental features. In a later commit this will be reversed. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D8234
Diffstat (limited to 'source/blender/draw/intern/draw_manager_text.c')
-rw-r--r--source/blender/draw/intern/draw_manager_text.c130
1 files changed, 80 insertions, 50 deletions
diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c
index adcac15ab85..e3d0dab6767 100644
--- a/source/blender/draw/intern/draw_manager_text.c
+++ b/source/blender/draw/intern/draw_manager_text.c
@@ -24,6 +24,7 @@
#include "BLI_math.h"
#include "BLI_memiter.h"
+#include "BLI_rect.h"
#include "BLI_string.h"
#include "BKE_editmesh.h"
@@ -122,76 +123,105 @@ void DRW_text_cache_add(DRWTextStore *dt,
}
}
-void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d)
+static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region)
{
- RegionView3D *rv3d = region->regiondata;
ViewCachedString *vos;
- int tot = 0;
-
- /* project first and test */
BLI_memiter_handle it;
- BLI_memiter_iter_init(dt->cache_strings, &it);
- while ((vos = BLI_memiter_iter_step(&it))) {
- if (ED_view3d_project_short_ex(
- region,
- (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob,
- (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0,
- vos->vec,
- vos->sco,
- V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) ==
- V3D_PROJ_RET_OK) {
- tot++;
- }
- else {
- vos->sco[0] = IS_CLIPPED;
- }
- }
+ int col_pack_prev = 0;
- if (tot) {
- int col_pack_prev = 0;
+ float original_proj[4][4];
+ GPU_matrix_projection_get(original_proj);
+ wmOrtho2_region_pixelspace(region);
- /* Disable clipping for text */
- if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- GPU_clip_distances(0);
- }
+ GPU_matrix_push();
+ GPU_matrix_identity_set();
- float original_proj[4][4];
- GPU_matrix_projection_get(original_proj);
- wmOrtho2_region_pixelspace(region);
+ const int font_id = BLF_default();
- GPU_matrix_push();
- GPU_matrix_identity_set();
+ const uiStyle *style = UI_style_get();
- const int font_id = BLF_default();
+ BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi);
- const uiStyle *style = UI_style_get();
+ BLI_memiter_iter_init(dt->cache_strings, &it);
+ while ((vos = BLI_memiter_iter_step(&it))) {
+ if (vos->sco[0] != IS_CLIPPED) {
+ if (col_pack_prev != vos->col.pack) {
+ BLF_color4ubv(font_id, vos->col.ub);
+ col_pack_prev = vos->col.pack;
+ }
+
+ BLF_position(
+ font_id, (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1] + vos->yoffs), 2.0f);
+
+ ((vos->flag & DRW_TEXT_CACHE_ASCII) ? BLF_draw_ascii : BLF_draw)(
+ font_id,
+ (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str,
+ vos->str_len);
+ }
+ }
- BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi);
+ GPU_matrix_pop();
+ GPU_matrix_projection_set(original_proj);
+}
+void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d)
+{
+ ViewCachedString *vos;
+ if (v3d) {
+ RegionView3D *rv3d = region->regiondata;
+ int tot = 0;
+ /* project first and test */
+ BLI_memiter_handle it;
BLI_memiter_iter_init(dt->cache_strings, &it);
while ((vos = BLI_memiter_iter_step(&it))) {
- if (vos->sco[0] != IS_CLIPPED) {
- if (col_pack_prev != vos->col.pack) {
- BLF_color4ubv(font_id, vos->col.ub);
- col_pack_prev = vos->col.pack;
- }
+ if (ED_view3d_project_short_ex(
+ region,
+ (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob,
+ (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0,
+ vos->vec,
+ vos->sco,
+ V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) ==
+ V3D_PROJ_RET_OK) {
+ tot++;
+ }
+ else {
+ vos->sco[0] = IS_CLIPPED;
+ }
+ }
- BLF_position(
- font_id, (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1] + vos->yoffs), 2.0f);
+ if (tot) {
+ /* Disable clipping for text */
+ const bool rv3d_clipping_enabled = RV3D_CLIPPING_ENABLED(v3d, rv3d);
+ if (rv3d_clipping_enabled) {
+ GPU_clip_distances(0);
+ }
+
+ drw_text_cache_draw_ex(dt, region);
- ((vos->flag & DRW_TEXT_CACHE_ASCII) ? BLF_draw_ascii : BLF_draw)(
- font_id,
- (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str,
- vos->str_len);
+ if (rv3d_clipping_enabled) {
+ GPU_clip_distances(6);
}
}
+ }
+ else {
+ /* project first */
+ BLI_memiter_handle it;
+ BLI_memiter_iter_init(dt->cache_strings, &it);
+ View2D *v2d = &region->v2d;
+ float viewmat[4][4];
+ rctf region_space = {0.0f, region->winx, 0.0f, region->winy};
+ BLI_rctf_transform_calc_m4_pivot_min(&v2d->cur, &region_space, viewmat);
- GPU_matrix_pop();
- GPU_matrix_projection_set(original_proj);
+ while ((vos = BLI_memiter_iter_step(&it))) {
+ float p[3];
+ copy_v3_v3(p, vos->vec);
+ mul_m4_v3(viewmat, p);
- if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
- GPU_clip_distances(6);
+ vos->sco[0] = p[0];
+ vos->sco[1] = p[1];
}
+
+ drw_text_cache_draw_ex(dt, region);
}
}