Cleanup: GPU: rename bglPolygonOffset to GPU_polygon_offset
And move it to GPU module.
This commit is contained in:
parent
acad0d75b1
commit
02c09773ea
Notes:
blender-bot
2023-02-13 21:28:15 +01:00
Referenced by issue #79885, Icon Background Opaque for Animation channels
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
Loading…
Reference in New Issue