diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-07-16 21:24:05 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-07-18 04:43:51 +0300 |
commit | 02c09773ea07c8c0a3d7be63abdfd963a9452402 (patch) | |
tree | 5cd052db8fc0dd71072f90dd22175e314a134f5c /source | |
parent | acad0d75b1448550c863ac8002bba4284d30d10d (diff) |
Cleanup: GPU: rename bglPolygonOffset to GPU_polygon_offset
And move it to GPU module.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 5 | ||||
-rw-r--r-- | source/blender/editors/gpencil/annotate_draw.c | 7 | ||||
-rw-r--r-- | source/blender/editors/gpencil/drawgpencil.c | 7 | ||||
-rw-r--r-- | source/blender/editors/include/BIF_glutil.h | 7 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 62 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_utils.c | 4 | ||||
-rw-r--r-- | source/blender/gpu/GPU_matrix.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_matrix.c | 66 |
9 files changed, 81 insertions, 82 deletions
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index aa8dd2f7fa4..095e928aa74 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -22,6 +22,7 @@ #include "DRW_render.h" +#include "GPU_matrix.h" #include "GPU_shader.h" #include "GPU_texture.h" @@ -31,8 +32,6 @@ #include "BKE_global.h" #include "BKE_object.h" -#include "BIF_glutil.h" - #include "draw_common.h" #if 0 @@ -280,7 +279,7 @@ DRWView *DRW_view_create_with_zoffset(const DRWView *parent_view, viewdist = 1.0f / max_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1])); } - winmat[3][2] -= bglPolygonOffsetCalc((float *)winmat, viewdist, offset); + winmat[3][2] -= GPU_polygon_offset_calc(winmat, viewdist, offset); return DRW_view_create_sub(parent_view, viewmat, winmat); } diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c index 8c8e6da75c0..df479325027 100644 --- a/source/blender/editors/gpencil/annotate_draw.c +++ b/source/blender/editors/gpencil/annotate_draw.c @@ -53,9 +53,8 @@ #include "WM_api.h" -#include "BIF_glutil.h" - #include "GPU_immediate.h" +#include "GPU_matrix.h" #include "GPU_state.h" #include "ED_gpencil.h" @@ -561,7 +560,7 @@ static void annotation_draw_strokes(const bGPDframe *gpf, /* first arg is normally rv3d->dist, but this isn't * available here and seems to work quite well without */ - bglPolygonOffset(1.0f, 1.0f); + GPU_polygon_offset(1.0f, 1.0f); } /* 3D Lines - OpenGL primitives-based */ @@ -577,7 +576,7 @@ static void annotation_draw_strokes(const bGPDframe *gpf, if (no_xray) { GPU_depth_test(false); - bglPolygonOffset(0.0, 0.0); + GPU_polygon_offset(0.0f, 0.0f); } } else { diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 4df071c84f8..9d11c1c2a25 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -60,9 +60,8 @@ #include "WM_api.h" -#include "BIF_glutil.h" - #include "GPU_immediate.h" +#include "GPU_matrix.h" #include "GPU_state.h" #include "ED_gpencil.h" @@ -353,7 +352,7 @@ static void gpencil_draw_strokes(tGPDdraw *tgpw) /* first arg is normally rv3d->dist, but this isn't * available here and seems to work quite well without */ - bglPolygonOffset(1.0f, 1.0f); + GPU_polygon_offset(1.0f, 1.0f); } /* 3D Stroke */ @@ -396,7 +395,7 @@ static void gpencil_draw_strokes(tGPDdraw *tgpw) if (no_xray) { GPU_depth_test(false); - bglPolygonOffset(0.0, 0.0); + GPU_polygon_offset(0.0f, 0.0f); } } /* if only one stroke, exit from loop */ diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index 04f9edeaf3a..1eb22fb34e2 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -172,13 +172,6 @@ void ED_draw_imbuf_ctx_clipping(const struct bContext *C, int ED_draw_imbuf_method(struct ImBuf *ibuf); -/* OpenGL drawing utility functions. Do not use these in new code, these - * are intended to be moved or removed in the future. */ - -/* own working polygon offset */ -float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist); -void bglPolygonOffset(float viewdist, float dist); - void immDrawBorderCorners(unsigned int pos, const struct rcti *border, float zoomx, float zoomy); #ifdef __cplusplus diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 27e5a53a526..79ec8dde009 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -473,68 +473,6 @@ void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state, color); } -/* *************** glPolygonOffset hack ************* */ - -float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist) -{ - /* Seems like we have a factor of 2 more offset than 2.79 for some reason. Correct for this. */ - dist *= 0.5f; - - if (winmat[15] > 0.5f) { -#if 1 - return 0.00001f * dist * viewdist; // ortho tweaking -#else - static float depth_fac = 0.0f; - if (depth_fac == 0.0f) { - int depthbits; - glGetIntegerv(GL_DEPTH_BITS, &depthbits); - depth_fac = 1.0f / (float)((1 << depthbits) - 1); - } - offs = (-1.0 / winmat[10]) * dist * depth_fac; - - UNUSED_VARS(viewdist); -#endif - } - - /* This adjustment effectively results in reducing the Z value by 0.25%. - * - * winmat[14] actually evaluates to `-2 * far * near / (far - near)`, - * is very close to -0.2 with default clip range, - * and is used as the coefficient multiplied by `w / z`, - * thus controlling the z dependent part of the depth value. - */ - return winmat[14] * -0.0025f * dist; -} - -/** - * \note \a viewdist is only for ortho at the moment. - */ -void bglPolygonOffset(float viewdist, float dist) -{ - static float winmat[16], offset = 0.0f; - - if (dist != 0.0f) { - // glEnable(GL_POLYGON_OFFSET_FILL); - // glPolygonOffset(-1.0, -1.0); - - /* hack below is to mimic polygon offset */ - GPU_matrix_projection_get(winmat); - - /* dist is from camera to center point */ - - float offs = bglPolygonOffsetCalc(winmat, viewdist, dist); - - winmat[14] -= offs; - offset += offs; - } - else { - winmat[14] += offset; - offset = 0.0; - } - - GPU_matrix_projection_set(winmat); -} - /* **** Color management helper functions for GLSL display/transform ***** */ /* Draw given image buffer on a screen using GLSL for display transform */ diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 0d121b23c71..bd2323f47f4 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -220,7 +220,7 @@ void view3d_region_operator_needs_opengl(wmWindow *UNUSED(win), ARegion *region) } /** - * Use instead of: ``bglPolygonOffset(rv3d->dist, ...)`` see bug [#37727] + * Use instead of: ``GPU_polygon_offset(rv3d->dist, ...)`` see bug [#37727] */ void ED_view3d_polygon_offset(const RegionView3D *rv3d, const float dist) { @@ -241,7 +241,7 @@ void ED_view3d_polygon_offset(const RegionView3D *rv3d, const float dist) } } - bglPolygonOffset(viewdist, dist); + GPU_polygon_offset(viewdist, dist); } bool ED_view3d_context_activate(bContext *C) diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h index 2899fba46e4..56d640ea0e4 100644 --- a/source/blender/gpu/GPU_matrix.h +++ b/source/blender/gpu/GPU_matrix.h @@ -147,6 +147,10 @@ const float (*GPU_matrix_normal_inverse_get(float m[3][3]))[3]; void GPU_matrix_bind(const struct GPUShaderInterface *); bool GPU_matrix_dirty_get(void); /* since last bind */ +/* own working polygon offset */ +float GPU_polygon_offset_calc(const float (*winmat)[4], float viewdist, float dist); +void GPU_polygon_offset(float viewdist, float dist); + /* Python API needs to be able to inspect the stack so errors raise exceptions * instead of crashing. */ #ifdef USE_GPU_PY_MATRIX_API diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index f07e3ed70d7..7e6d47636f6 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -55,6 +55,7 @@ #include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_glew.h" +#include "GPU_matrix.h" #include "GPU_platform.h" #include "GPU_texture.h" diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c index 2687f56ad27..8df7c7c5d2f 100644 --- a/source/blender/gpu/intern/gpu_matrix.c +++ b/source/blender/gpu/intern/gpu_matrix.c @@ -738,3 +738,69 @@ int GPU_matrix_stack_level_get_projection(void) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Polygon Offset Hack + * + * Workaround the fact that PolygonOffset is implementation dependant. + * We modify the projection matrix (winmat) in order to change the final depth a tiny amount. + * \{ */ + +float GPU_polygon_offset_calc(const float (*winmat)[4], float viewdist, float dist) +{ + /* Seems like we have a factor of 2 more offset than 2.79 for some reason. Correct for this. */ + dist *= 0.5f; + + if (winmat[3][3] > 0.5f) { +#if 1 + return 0.00001f * dist * viewdist; // ortho tweaking +#else + static float depth_fac = 0.0f; + if (depth_fac == 0.0f) { + int depthbits; + glGetIntegerv(GL_DEPTH_BITS, &depthbits); + depth_fac = 1.0f / (float)((1 << depthbits) - 1); + } + offs = (-1.0 / winmat[2][2]) * dist * depth_fac; + + UNUSED_VARS(viewdist); +#endif + } + + /* This adjustment effectively results in reducing the Z value by 0.25%. + * + * winmat[4][3] actually evaluates to `-2 * far * near / (far - near)`, + * is very close to -0.2 with default clip range, + * and is used as the coefficient multiplied by `w / z`, + * thus controlling the z dependent part of the depth value. + */ + return winmat[3][2] * -0.0025f * dist; +} + +/** + * \note \a viewdist is only for ortho at the moment. + */ +void GPU_polygon_offset(float viewdist, float dist) +{ + static float winmat[4][4], offset = 0.0f; + + if (dist != 0.0f) { + /* hack below is to mimic polygon offset */ + GPU_matrix_projection_get(winmat); + + /* dist is from camera to center point */ + + float offs = GPU_polygon_offset_calc(winmat, viewdist, dist); + + winmat[3][2] -= offs; + offset += offs; + } + else { + winmat[3][2] += offset; + offset = 0.0; + } + + GPU_matrix_projection_set(winmat); +} + +/** \} */ |