DRW: generalize selecting between regular/clipped shaders
Each engine was doing this on its own. Move to DRWContextState, use an enum.
This commit is contained in:
@@ -567,6 +567,16 @@ bool DRW_state_show_text(void);
|
||||
bool DRW_state_draw_support(void);
|
||||
bool DRW_state_draw_background(void);
|
||||
|
||||
/**
|
||||
* Support selecting shaders with different options compiled in.
|
||||
* Needed for clipping support because it means using a separate set of shaders.
|
||||
*/
|
||||
typedef enum eDRW_ShaderSlot {
|
||||
DRW_SHADER_SLOT_DEFAULT = 0,
|
||||
DRW_SHADER_SLOT_CLIPPED = 1,
|
||||
} eDRW_ShaderSlot;
|
||||
#define DRW_SHADER_SLOT_LEN 2
|
||||
|
||||
/* Avoid too many lookups while drawing */
|
||||
typedef struct DRWContextState {
|
||||
|
||||
@@ -586,6 +596,8 @@ typedef struct DRWContextState {
|
||||
|
||||
eObjectMode object_mode;
|
||||
|
||||
eDRW_ShaderSlot shader_slot;
|
||||
|
||||
/* Last resort (some functions take this as an arg so we can't easily avoid).
|
||||
* May be NULL when used for selection or depth buffer. */
|
||||
const struct bContext *evil_C;
|
||||
|
||||
@@ -543,6 +543,11 @@ static void drw_context_state_init(void)
|
||||
else {
|
||||
DST.draw_ctx.object_pose = NULL;
|
||||
}
|
||||
|
||||
DST.draw_ctx.shader_slot = DRW_SHADER_SLOT_DEFAULT;
|
||||
if (DST.draw_ctx.rv3d && DST.draw_ctx.rv3d->rflag & RV3D_CLIPPING) {
|
||||
DST.draw_ctx.shader_slot = DRW_SHADER_SLOT_CLIPPED;
|
||||
}
|
||||
}
|
||||
|
||||
/* It also stores viewport variable to an immutable place: DST
|
||||
|
||||
@@ -105,8 +105,7 @@ static struct {
|
||||
* init in EDIT_LATTICE_engine_init();
|
||||
* free in EDIT_LATTICE_engine_free(); */
|
||||
|
||||
/* 0: normal, 1: clipped. */
|
||||
EDIT_LATTICE_Shaders sh_data[2];
|
||||
EDIT_LATTICE_Shaders sh_data[DRW_SHADER_SLOT_LEN];
|
||||
|
||||
} e_data = {NULL}; /* Engine data */
|
||||
|
||||
@@ -119,14 +118,6 @@ typedef struct EDIT_LATTICE_PrivateData {
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
|
||||
static int EDIT_LATTICE_sh_data_index_from_rv3d(const RegionView3D *rv3d)
|
||||
{
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Init Textures, Framebuffers, Storage and Shaders.
|
||||
* It is called for every frames.
|
||||
* (Optional) */
|
||||
@@ -154,7 +145,7 @@ static void EDIT_LATTICE_engine_init(void *vedata)
|
||||
*/
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
EDIT_LATTICE_Shaders *sh_data = &e_data.sh_data[EDIT_LATTICE_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
EDIT_LATTICE_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
|
||||
if (is_clip) {
|
||||
DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
|
||||
@@ -191,7 +182,7 @@ static void EDIT_LATTICE_cache_init(void *vedata)
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
EDIT_LATTICE_Shaders *sh_data = &e_data.sh_data[EDIT_LATTICE_sh_data_index_from_rv3d(rv3d)];
|
||||
EDIT_LATTICE_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
if (!stl->g_data) {
|
||||
/* Alloc transient pointers */
|
||||
|
||||
@@ -126,8 +126,7 @@ typedef struct EDIT_MESH_Shaders {
|
||||
|
||||
/* *********** STATIC *********** */
|
||||
static struct {
|
||||
/* 0: normal, 1: clipped. */
|
||||
EDIT_MESH_Shaders sh_data[2];
|
||||
EDIT_MESH_Shaders sh_data[DRW_SHADER_SLOT_LEN];
|
||||
|
||||
/* temp buffer texture */
|
||||
struct GPUTexture *occlude_wire_depth_tx;
|
||||
@@ -164,14 +163,6 @@ typedef struct EDIT_MESH_PrivateData {
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
|
||||
static int EDIT_MESH_sh_data_index_from_rv3d(const RegionView3D *rv3d)
|
||||
{
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int EDIT_MESH_sh_index(ToolSettings *tsettings, RegionView3D *rv3d, bool supports_fast_mode)
|
||||
{
|
||||
int result = tsettings->selectmode << 1;
|
||||
@@ -263,7 +254,7 @@ static void EDIT_MESH_engine_init(void *vedata)
|
||||
EDIT_MESH_FramebufferList *fbl = ((EDIT_MESH_Data *)vedata)->fbl;
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[EDIT_MESH_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
|
||||
|
||||
const float *viewport_size = DRW_viewport_size_get();
|
||||
@@ -364,7 +355,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
||||
Scene *scene = draw_ctx->scene;
|
||||
ToolSettings *tsettings = scene->toolsettings;
|
||||
const int fast_mode = rv3d->rflag & RV3D_NAVIGATING;
|
||||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[EDIT_MESH_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
ledge_sh = EDIT_MESH_ensure_shader(sh_data, tsettings, rv3d, false, true);
|
||||
tri_sh = EDIT_MESH_ensure_shader(sh_data, tsettings, rv3d, true, false);
|
||||
@@ -455,7 +446,7 @@ static void EDIT_MESH_cache_init(void *vedata)
|
||||
RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
Scene *scene = draw_ctx->scene;
|
||||
ToolSettings *tsettings = scene->toolsettings;
|
||||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[EDIT_MESH_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
static float zero = 0.0f;
|
||||
|
||||
if (!stl->g_data) {
|
||||
|
||||
@@ -327,8 +327,7 @@ static struct {
|
||||
struct GPUVertFormat *empty_image_format;
|
||||
struct GPUVertFormat *empty_image_wire_format;
|
||||
|
||||
/* 0: normal, 1: clipped. */
|
||||
OBJECT_Shaders sh_data[2];
|
||||
OBJECT_Shaders sh_data[DRW_SHADER_SLOT_LEN];
|
||||
|
||||
float camera_pos[3];
|
||||
float grid_settings[5];
|
||||
@@ -368,14 +367,6 @@ static void DRW_shgroup_empty_ex(OBJECT_ShadingGroupList *sgl, float mat[4][4],
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
|
||||
static int OBJECT_sh_data_index_from_rv3d(const RegionView3D *rv3d)
|
||||
{
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void OBJECT_engine_init(void *vedata)
|
||||
{
|
||||
OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
|
||||
@@ -416,7 +407,7 @@ static void OBJECT_engine_init(void *vedata)
|
||||
|
||||
/* Shaders */
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
OBJECT_Shaders *sh_data = &e_data.sh_data[OBJECT_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
if (!sh_data->outline_resolve) {
|
||||
/* Outline */
|
||||
@@ -971,7 +962,7 @@ static void OBJECT_cache_init(void *vedata)
|
||||
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
||||
OBJECT_PrivateData *g_data;
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
OBJECT_Shaders *sh_data = &e_data.sh_data[OBJECT_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
const float outline_width = UI_GetThemeValuef(TH_OUTLINE_WIDTH);
|
||||
const bool do_outline_expand = (U.pixelsize > 1.0) || (outline_width > 2.0f);
|
||||
@@ -2866,9 +2857,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
|
||||
ModifierData *md = NULL;
|
||||
int theme_id = TH_UNDEFINED;
|
||||
const int ob_visibility = DRW_object_visibility_in_active_context(ob);
|
||||
|
||||
/* TODO(campbell): we shouldn't need to get this per object. */
|
||||
OBJECT_Shaders *sh_data = &e_data.sh_data[OBJECT_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
/* Handle particles first in case the emitter itself shouldn't be rendered. */
|
||||
if (ob_visibility & OB_VISIBLE_PARTICLES) {
|
||||
|
||||
@@ -79,8 +79,7 @@ typedef struct OVERLAY_Shaders {
|
||||
|
||||
/* *********** STATIC *********** */
|
||||
static struct {
|
||||
/* 0: normal, 1: clipped. */
|
||||
OVERLAY_Shaders sh_data[2];
|
||||
OVERLAY_Shaders sh_data[DRW_SHADER_SLOT_LEN];
|
||||
} e_data = {NULL};
|
||||
|
||||
extern char datatoc_common_world_clip_lib_glsl[];
|
||||
@@ -94,14 +93,6 @@ extern char datatoc_overlay_face_wireframe_geom_glsl[];
|
||||
extern char datatoc_overlay_face_wireframe_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_depth_only_frag_glsl[];
|
||||
|
||||
static int OVERLAY_sh_data_index_from_rv3d(const RegionView3D *rv3d)
|
||||
{
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Functions */
|
||||
static void overlay_engine_init(void *vedata)
|
||||
{
|
||||
@@ -109,7 +100,7 @@ static void overlay_engine_init(void *vedata)
|
||||
OVERLAY_StorageList *stl = data->stl;
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
OVERLAY_Shaders *sh_data = &e_data.sh_data[OVERLAY_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
|
||||
|
||||
if (is_clip) {
|
||||
@@ -162,7 +153,7 @@ static void overlay_cache_init(void *vedata)
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
OVERLAY_Shaders *sh_data = &e_data.sh_data[OVERLAY_sh_data_index_from_rv3d(rv3d)];
|
||||
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
const DRWContextState *DCS = DRW_context_state_get();
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ typedef struct PAINT_VERTEX_Shaders {
|
||||
/* *********** STATIC *********** */
|
||||
|
||||
static struct {
|
||||
PAINT_VERTEX_Shaders sh_data[2];
|
||||
PAINT_VERTEX_Shaders sh_data[DRW_SHADER_SLOT_LEN];
|
||||
} e_data = {NULL}; /* Engine data */
|
||||
|
||||
typedef struct PAINT_VERTEX_PrivateData {
|
||||
@@ -96,18 +96,10 @@ typedef struct PAINT_VERTEX_PrivateData {
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
|
||||
static int PAINT_VERTEX_sh_data_index_from_rv3d(const RegionView3D *rv3d)
|
||||
{
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
PAINT_VERTEX_Shaders *sh_data = &e_data.sh_data[PAINT_VERTEX_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
PAINT_VERTEX_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
|
||||
|
||||
if (is_clip) {
|
||||
@@ -147,7 +139,7 @@ static void PAINT_VERTEX_cache_init(void *vedata)
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
const View3D *v3d = draw_ctx->v3d;
|
||||
const RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
PAINT_VERTEX_Shaders *sh_data = &e_data.sh_data[PAINT_VERTEX_sh_data_index_from_rv3d(rv3d)];
|
||||
PAINT_VERTEX_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
if (!stl->g_data) {
|
||||
/* Alloc transient pointers */
|
||||
|
||||
@@ -86,7 +86,7 @@ typedef struct PAINT_WEIGHT_Shaders {
|
||||
/* *********** STATIC *********** */
|
||||
|
||||
static struct {
|
||||
PAINT_WEIGHT_Shaders sh_data[2];
|
||||
PAINT_WEIGHT_Shaders sh_data[DRW_SHADER_SLOT_LEN];
|
||||
|
||||
int actdef;
|
||||
} e_data = {NULL}; /* Engine data */
|
||||
@@ -100,18 +100,10 @@ typedef struct PAINT_WEIGHT_PrivateData {
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
|
||||
static int PAINT_WEIGHT_sh_data_index_from_rv3d(const RegionView3D *rv3d)
|
||||
{
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void PAINT_WEIGHT_engine_init(void *UNUSED(vedata))
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[PAINT_WEIGHT_sh_data_index_from_rv3d(draw_ctx->rv3d)];
|
||||
PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
|
||||
|
||||
if (is_clip) {
|
||||
@@ -151,7 +143,7 @@ static void PAINT_WEIGHT_cache_init(void *vedata)
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
const View3D *v3d = draw_ctx->v3d;
|
||||
RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[PAINT_WEIGHT_sh_data_index_from_rv3d(rv3d)];
|
||||
PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
|
||||
if (!stl->g_data) {
|
||||
/* Alloc transient pointers */
|
||||
|
||||
Reference in New Issue
Block a user