Cleanup: GPU: Use explicit clear value in GPU_clear* commands

This replace `GPU_clear()` by `GPU_clear_color()` and `GPU_clear_depth()`.
Since we always set the clear value before clearing, it is unecessary
to track the clear color state.
Moreover, it makes it clearer what we clear the framebuffer to.
This commit is contained in:
Clément Foucault 2020-08-23 11:11:27 +02:00
parent 846cac94db
commit f18e537451
Notes: blender-bot 2023-02-14 08:42:54 +01:00
Referenced by issue #80138, Node Editor: Add Frame turns background gray
Referenced by issue #80094, Various Asserts during selection
Referenced by issue #79934, Protruding curves on RGB Curves node
33 changed files with 30 additions and 86 deletions

View File

@ -1593,7 +1593,6 @@ void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph,
* be to do that in the colormanagmeent shader. */
GPU_offscreen_bind(ofs, false);
GPU_clear_color(0.0f, 0.0f, 0.0f, 1.0f);
GPU_clear(GPU_COLOR_BIT);
/* Premult Alpha over black background. */
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
}

View File

@ -455,7 +455,7 @@ static bool gpencil_render_offscreen(tGPDfill *tgpf)
GPU_matrix_identity_set();
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
GPU_clear(GPU_COLOR_BIT | GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
ED_view3d_update_viewmat(
tgpf->depsgraph, tgpf->scene, tgpf->v3d, tgpf->region, NULL, winmat, NULL, true);

View File

@ -431,12 +431,9 @@ void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3],
// (for anything fancy use UI_GetThemeColor[Fancy] then BLF_color)
void UI_FontThemeColor(int fontid, int colorid);
// clear the openGL ClearColor using the input colorid
// clear the framebuffer using the input colorid
void UI_ThemeClearColor(int colorid);
// clear the openGL ClearColor using the input colorid using optional transparency
void UI_ThemeClearColorAlpha(int colorid, float alpha);
// internal (blender) usage only, for init and set active
void UI_SetTheme(int spacetype, int regionid);

View File

@ -1442,10 +1442,6 @@ void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
void UI_panels_draw(const bContext *C, ARegion *region)
{
if (region->alignment != RGN_ALIGN_FLOAT) {
UI_ThemeClearColor(TH_BACK);
}
/* Draw panels, selected on top. Also in reverse order, because
* UI blocks are added in reverse order and we need child panels
* to draw on top. */

View File

@ -217,8 +217,7 @@ static void hud_region_draw(const bContext *C, ARegion *region)
{
UI_view2d_view_ortho(&region->v2d);
wmOrtho2_region_pixelspace(region);
GPU_clear_color(0, 0, 0, 0.0f);
GPU_clear(GPU_COLOR_BIT);
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
if ((region->flag & RGN_FLAG_HIDDEN) == 0) {
ui_draw_menu_back(NULL,

View File

@ -1474,13 +1474,6 @@ void UI_ThemeClearColor(int colorid)
GPU_clear_color(col[0], col[1], col[2], 1.0f);
}
void UI_ThemeClearColorAlpha(int colorid, float alpha)
{
float col[3];
UI_GetThemeColor3fv(colorid, col);
GPU_clear_color(col[0], col[1], col[2], alpha);
}
int UI_ThemeMenuShadowWidth(void)
{
bTheme *btheme = UI_GetTheme();

View File

@ -339,7 +339,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R
GPU_offscreen_bind(oglrender->ofs, true);
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
GPU_clear(GPU_COLOR_BIT | GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
GPU_matrix_reset();
wmOrtho2(0, scene->r.xsch, 0, scene->r.ysch);

View File

@ -351,11 +351,9 @@ static void region_draw_status_text(ScrArea *area, ARegion *region)
if (overlap) {
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
GPU_clear(GPU_COLOR_BIT);
}
else {
UI_ThemeClearColor(TH_HEADER);
GPU_clear(GPU_COLOR_BIT);
}
int fontid = BLF_set_default();
@ -519,7 +517,6 @@ void ED_region_do_draw(bContext *C, ARegion *region)
if (area && area_is_pseudo_minimized(area)) {
UI_ThemeClearColor(TH_EDITOR_OUTLINE);
GPU_clear(GPU_COLOR_BIT);
return;
}
/* optional header info instead? */
@ -2529,11 +2526,9 @@ static void region_clear_color(const bContext *C, const ARegion *region, ThemeCo
float back[4];
UI_GetThemeColor4fv(colorid, back);
GPU_clear_color(back[3] * back[0], back[3] * back[1], back[3] * back[2], back[3]);
GPU_clear(GPU_COLOR_BIT);
}
else {
UI_ThemeClearColor(colorid);
GPU_clear(GPU_COLOR_BIT);
}
}

View File

@ -606,8 +606,8 @@ void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, uin
GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, true, false, err_out);
GPU_offscreen_bind(offscreen, true);
GPU_clear_color(0.0, 0.0, 0.0, 0.0);
GPU_clear(GPU_COLOR_BIT | GPU_DEPTH_BIT);
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
GPU_clear_depth(1.0f);
screen_preview_draw(screen, size_x, size_y);

View File

@ -191,7 +191,6 @@ static void action_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);
@ -278,7 +277,6 @@ static void action_channel_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);

View File

@ -926,7 +926,6 @@ static void clip_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
/* data... */
movieclip_main_area_set_view2d(C, region);
@ -1054,7 +1053,6 @@ static void graph_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);
@ -1099,7 +1097,6 @@ static void dopesheet_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);
@ -1172,7 +1169,6 @@ static void clip_channels_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);

View File

@ -215,7 +215,6 @@ static void console_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
/* worlks best with no view2d matrix set */
UI_view2d_view_ortho(v2d);

View File

@ -449,7 +449,6 @@ static void file_main_region_draw(const bContext *C, ARegion *region)
FileSelectParams *params = ED_fileselect_get_params(sfile);
View2D *v2d = &region->v2d;
float col[3];
/* Needed, because filelist is not initialized on loading */
if (!sfile->files || filelist_empty(sfile->files)) {
@ -457,9 +456,7 @@ static void file_main_region_draw(const bContext *C, ARegion *region)
}
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
GPU_clear_color(col[0], col[1], col[2], 1.0f);
GPU_clear(GPU_COLOR_BIT);
UI_ThemeClearColor(TH_BACK);
/* Allow dynamically sliders to be set, saves notifiers etc. */

View File

@ -200,12 +200,9 @@ static void graph_main_region_draw(const bContext *C, ARegion *region)
Scene *scene = CTX_data_scene(C);
bAnimContext ac;
View2D *v2d = &region->v2d;
float col[3];
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
GPU_clear_color(col[0], col[1], col[2], 1.0f);
GPU_clear(GPU_COLOR_BIT);
UI_ThemeClearColor(TH_BACK);
UI_view2d_view_ortho(v2d);
@ -358,12 +355,9 @@ static void graph_channel_region_draw(const bContext *C, ARegion *region)
{
bAnimContext ac;
View2D *v2d = &region->v2d;
float col[3];
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
GPU_clear_color(col[0], col[1], col[2], 1.0f);
GPU_clear(GPU_COLOR_BIT);
UI_ThemeClearColor(TH_BACK);
UI_view2d_view_ortho(v2d);

View File

@ -650,7 +650,6 @@ static void image_main_region_draw(const bContext *C, ARegion *region)
GPU_framebuffer_bind(framebuffer_default);
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
GPU_clear(GPU_COLOR_BIT);
GPU_framebuffer_bind(framebuffer_overlay);
@ -661,7 +660,6 @@ static void image_main_region_draw(const bContext *C, ARegion *region)
UI_GetThemeColor3fv(TH_BACK, col);
srgb_to_linearrgb_v3_v3(col, col);
GPU_clear_color(col[0], col[1], col[2], 1.0f);
GPU_clear(GPU_COLOR_BIT);
GPU_depth_test(GPU_DEPTH_NONE);
image_user_refresh_scene(C, sima);

View File

@ -147,7 +147,6 @@ static int report_textview_begin(TextViewContext *tvc)
tvc->iter = reports->list.last;
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
tvc->iter_tmp = 0;
if (tvc->iter && report_textview_skip__internal(tvc)) {

View File

@ -142,7 +142,6 @@ static void info_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
/* quick way to avoid drawing if not bug enough */
if (region->winy < 16) {

View File

@ -194,7 +194,6 @@ static void nla_channel_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);
@ -238,7 +237,6 @@ static void nla_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);

View File

@ -1343,8 +1343,6 @@ static void node_draw_basis(const bContext *C,
}
}
UI_ThemeClearColor(color_id);
UI_block_end(C, node->block);
UI_block_draw(C, node->block);
node->block = NULL;
@ -1737,8 +1735,8 @@ void drawnodespace(const bContext *C, ARegion *region)
UI_view2d_view_ortho(v2d);
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
GPU_depth_test(GPU_DEPTH_NONE);
GPU_scissor_test(true);
/* XXX snode->cursor set in coordspace for placing new nodes, used for drawing noodles too */
UI_view2d_region_to_view(&region->v2d,

View File

@ -87,7 +87,6 @@ static void outliner_main_region_draw(const bContext *C, ARegion *region)
/* clear */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
draw_outliner(C);

View File

@ -127,7 +127,6 @@ static void script_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);

View File

@ -1529,11 +1529,7 @@ static void sequencer_stop_running_jobs(const bContext *C, Scene *scene)
static void sequencer_preview_clear(void)
{
float col[3];
UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col);
GPU_clear_color(col[0], col[1], col[2], 1.0f);
GPU_clear(GPU_COLOR_BIT);
UI_ThemeClearColor(TH_SEQ_PREVIEW);
}
static void sequencer_preview_get_rect(rctf *preview,
@ -2266,7 +2262,6 @@ void draw_timeline_seq(const bContext *C, ARegion *region)
else {
GPU_clear_color(col[0], col[1], col[2], 0.0f);
}
GPU_clear(GPU_COLOR_BIT);
UI_view2d_view_ortho(v2d);
/* Get timeline boundbox, needed for the scrollers. */

View File

@ -296,7 +296,6 @@ static void text_main_region_draw(const bContext *C, ARegion *region)
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
GPU_clear(GPU_COLOR_BIT);
// UI_view2d_view_ortho(v2d);

View File

@ -2319,7 +2319,7 @@ void ED_view3d_draw_depth_gpencil(Depsgraph *depsgraph, Scene *scene, ARegion *r
/* Setup view matrix. */
ED_view3d_draw_setup_view(NULL, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL);
GPU_clear(GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);

View File

@ -553,7 +553,6 @@ void ED_uvedit_draw_main(SpaceImage *sima,
view_layer, ((View3D *)NULL), &objects_len);
if (objects_len > 0) {
GPU_clear_depth(1.0f);
GPU_clear(GPU_DEPTH_BIT);
}
/* go over all objects and create the batches + add their areas to the total */

View File

@ -225,7 +225,6 @@ void GPU_offscreen_viewport_data_get(GPUOffScreen *ofs,
void GPU_clear_color(float red, float green, float blue, float alpha);
void GPU_clear_depth(float depth);
void GPU_clear(eGPUFrameBufferBits flags);
void GPU_frontbuffer_read_pixels(
int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data);

View File

@ -1117,18 +1117,22 @@ void GPU_offscreen_viewport_data_get(GPUOffScreen *ofs,
void GPU_clear_color(float red, float green, float blue, float alpha)
{
BLI_assert((GPU_write_mask_get() & GPU_WRITE_COLOR) != 0);
GPU_context_active_get()->state_manager->apply_state();
glClearColor(red, green, blue, alpha);
glClear(GL_COLOR_BUFFER_BIT);
}
void GPU_clear_depth(float depth)
{
glClearDepth(depth);
}
BLI_assert((GPU_write_mask_get() & GPU_WRITE_DEPTH) != 0);
void GPU_clear(eGPUFrameBufferBits flags)
{
GPU_context_active_get()->state_manager->apply_state();
glClear(convert_buffer_bits_to_gl(flags));
glClearDepth(depth);
glClear(GL_DEPTH_BUFFER_BIT);
}
void GPU_frontbuffer_read_pixels(

View File

@ -339,7 +339,7 @@ void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, c
/* It's possible we don't want to clear depth buffer,
* so existing elements are masked by current z-buffer. */
GPU_clear(GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
/* scratch buffer (read new values here) */
ps->gl.rect_depth_test = depth_buf_malloc(rect_len);
@ -519,7 +519,7 @@ bool gpu_select_pick_load_id(uint id, bool end)
if (g_pick_state.mode == GPU_SELECT_PICK_ALL) {
/* we want new depths every time */
GPU_clear(GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
}
}
}

View File

@ -122,7 +122,7 @@ void gpu_select_query_begin(
else if (mode == GPU_SELECT_NEAREST_FIRST_PASS) {
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
GPU_depth_mask(true);
GPU_clear(GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
}
else if (mode == GPU_SELECT_NEAREST_SECOND_PASS) {
GPU_depth_test(GPU_DEPTH_EQUAL);

View File

@ -720,8 +720,7 @@ static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
wm_draw_region_buffer_create(region, false, false);
wm_draw_region_bind(region, 0);
GPU_clear_color(0, 0, 0, 0);
GPU_clear(GPU_COLOR_BIT);
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
ED_region_do_draw(C, region);
wm_draw_region_unbind(region);
@ -744,7 +743,6 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
* If it becomes a problem we should clear only when window size changes. */
#if 0
GPU_clear_color(0, 0, 0, 0);
GPU_clear(GPU_COLOR_BIT);
#endif
/* Blit non-overlapping area regions. */

View File

@ -310,8 +310,7 @@ static void playanim_toscreen(
CLAMP(offs_x, 0.0f, 1.0f);
CLAMP(offs_y, 0.0f, 1.0f);
GPU_clear_color(0.1, 0.1, 0.1, 0.0);
GPU_clear(GPU_COLOR_BIT);
GPU_clear_color(0.1f, 0.1f, 0.1f, 0.0f);
/* checkerboard for case alpha */
if (ibuf->planes == 32) {
@ -1313,8 +1312,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
maxwiny = ibuf->y * (1 + (maxwiny / ibuf->y));
}
GPU_clear_color(0.1, 0.1, 0.1, 0.0);
GPU_clear(GPU_COLOR_BIT);
GPU_clear_color(0.1f, 0.1f, 0.1f, 0.0f);
int win_x, win_y;
playanim_window_get_size(&win_x, &win_y);

View File

@ -645,11 +645,10 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm,
GHOST_SetWindowState(ghostwin, (GHOST_TWindowState)win->windowstate);
}
#endif
/* until screens get drawn, make it nice gray */
GPU_clear_color(0.55, 0.55, 0.55, 1.0f);
/* Crash on OSS ATI: bugs.launchpad.net/ubuntu/+source/mesa/+bug/656100 */
if (!GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE)) {
GPU_clear(GPU_COLOR_BIT);
/* until screens get drawn, make it nice gray */
GPU_clear_color(0.55f, 0.55f, 0.55f, 1.0f);
}
/* needed here, because it's used before it reads userdef */

View File

@ -126,7 +126,7 @@ void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata)
/* In case a framebuffer is still bound from drawing the last eye. */
GPU_framebuffer_restore();
/* Some systems have drawing glitches without this. */
GPU_clear(GPU_DEPTH_BIT);
GPU_clear_depth(1.0f);
/* Draws the view into the surface_data->viewport's framebuffers */
ED_view3d_draw_offscreen_simple(draw_data->depsgraph,