Cleanup: GPU: Encapsulate glViewport calls
This commit is contained in:
parent
35f1b3e43b
commit
a6bd7777c2
|
@ -1793,9 +1793,6 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
|
|||
|
||||
ViewportEngineData *data = drw_viewport_engine_data_ensure(draw_engine_type);
|
||||
|
||||
/* set default viewport */
|
||||
glViewport(0, 0, size[0], size[1]);
|
||||
|
||||
/* Main rendering. */
|
||||
rctf view_rect;
|
||||
rcti render_rect;
|
||||
|
@ -1809,12 +1806,15 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
|
|||
/* Reset state before drawing */
|
||||
DRW_state_reset();
|
||||
|
||||
/* set default viewport */
|
||||
GPU_viewport(0, 0, size[0], size[1]);
|
||||
|
||||
/* Init render result. */
|
||||
RenderResult *render_result = RE_engine_begin_result(engine,
|
||||
0,
|
||||
0,
|
||||
(int)size[0],
|
||||
(int)size[1],
|
||||
size[0],
|
||||
size[1],
|
||||
view_layer->name,
|
||||
/* RR_ALL_VIEWS */ NULL);
|
||||
|
||||
|
|
|
@ -1772,7 +1772,7 @@ void ED_gpencil_brush_draw_eraser(Brush *brush, int x, int y)
|
|||
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
||||
|
||||
float viewport_size[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport_size);
|
||||
GPU_viewport_size_get_f(viewport_size);
|
||||
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
||||
|
||||
immUniformColor4f(1.0f, 0.39f, 0.39f, 0.78f);
|
||||
|
|
|
@ -63,6 +63,7 @@ void GPU_program_point_size(bool enable);
|
|||
void GPU_scissor(int x, int y, int width, int height);
|
||||
void GPU_scissor_get_f(float coords[4]);
|
||||
void GPU_scissor_get_i(int coords[4]);
|
||||
void GPU_viewport(int x, int y, int width, int height);
|
||||
void GPU_viewport_size_get_f(float coords[4]);
|
||||
void GPU_viewport_size_get_i(int coords[4]);
|
||||
void GPU_color_mask(bool r, bool g, bool b, bool a);
|
||||
|
|
|
@ -320,7 +320,7 @@ void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, c
|
|||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
float viewport[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport);
|
||||
GPU_viewport_size_get_f(viewport);
|
||||
|
||||
ps->src.clip_rect = *input;
|
||||
ps->src.rect_len = rect_len;
|
||||
|
@ -330,7 +330,7 @@ void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, c
|
|||
ps->gl.clip_readpixels[2] = BLI_rcti_size_x(&ps->src.clip_rect);
|
||||
ps->gl.clip_readpixels[3] = BLI_rcti_size_y(&ps->src.clip_rect);
|
||||
|
||||
glViewport(UNPACK4(ps->gl.clip_readpixels));
|
||||
GPU_viewport(UNPACK4(ps->gl.clip_readpixels));
|
||||
|
||||
/* It's possible we don't want to clear depth buffer,
|
||||
* so existing elements are masked by current z-buffer. */
|
||||
|
|
|
@ -94,8 +94,8 @@ void gpu_select_query_begin(
|
|||
* We need to get the region of the viewport so that our geometry doesn't
|
||||
* get rejected before the depth test. Should probably cull rect against
|
||||
* the viewport but this is a rare case I think */
|
||||
glGetFloatv(GL_VIEWPORT, viewport);
|
||||
glViewport(viewport[0], viewport[1], BLI_rcti_size_x(input), BLI_rcti_size_y(input));
|
||||
GPU_viewport_size_get_f(viewport);
|
||||
GPU_viewport(viewport[0], viewport[1], BLI_rcti_size_x(input), BLI_rcti_size_y(input));
|
||||
|
||||
/* occlusion queries operates on fragments that pass tests and since we are interested on all
|
||||
* objects in the view frustum independently of their order, we need to disable the depth test */
|
||||
|
|
|
@ -151,6 +151,11 @@ void GPU_scissor(int x, int y, int width, int height)
|
|||
glScissor(x, y, width, height);
|
||||
}
|
||||
|
||||
void GPU_viewport(int x, int y, int width, int height)
|
||||
{
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
void GPU_scissor_get_f(float coords[4])
|
||||
{
|
||||
glGetFloatv(GL_SCISSOR_BOX, coords);
|
||||
|
|
|
@ -209,7 +209,7 @@ static void wm_gesture_draw_line(wmGesture *gt)
|
|||
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
||||
|
||||
float viewport_size[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport_size);
|
||||
GPU_viewport_size_get_f(viewport_size);
|
||||
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
||||
|
||||
immUniform1i("colors_len", 2); /* "advanced" mode */
|
||||
|
@ -252,7 +252,7 @@ static void wm_gesture_draw_rect(wmGesture *gt)
|
|||
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
||||
|
||||
float viewport_size[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport_size);
|
||||
GPU_viewport_size_get_f(viewport_size);
|
||||
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
||||
|
||||
immUniform1i("colors_len", 2); /* "advanced" mode */
|
||||
|
@ -291,7 +291,7 @@ static void wm_gesture_draw_circle(wmGesture *gt)
|
|||
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
||||
|
||||
float viewport_size[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport_size);
|
||||
GPU_viewport_size_get_f(viewport_size);
|
||||
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
||||
|
||||
immUniform1i("colors_len", 2); /* "advanced" mode */
|
||||
|
@ -408,7 +408,7 @@ static void wm_gesture_draw_lasso(wmGesture *gt, bool filled)
|
|||
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
||||
|
||||
float viewport_size[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport_size);
|
||||
GPU_viewport_size_get_f(viewport_size);
|
||||
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
||||
|
||||
immUniform1i("colors_len", 2); /* "advanced" mode */
|
||||
|
@ -442,7 +442,7 @@ static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt)
|
|||
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
||||
|
||||
float viewport_size[4];
|
||||
glGetFloatv(GL_VIEWPORT, viewport_size);
|
||||
GPU_viewport_size_get_f(viewport_size);
|
||||
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
||||
|
||||
immUniform1i("colors_len", 2); /* "advanced" mode */
|
||||
|
|
|
@ -1060,7 +1060,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
|||
/* zoom always show entire image */
|
||||
ps->zoom = MIN2(zoomx, zoomy);
|
||||
|
||||
glViewport(0, 0, ps->win_x, ps->win_y);
|
||||
GPU_viewport(0, 0, ps->win_x, ps->win_y);
|
||||
glScissor(0, 0, ps->win_x, ps->win_y);
|
||||
|
||||
playanim_gl_matrix();
|
||||
|
@ -1322,7 +1322,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
|
|||
|
||||
int win_x, win_y;
|
||||
playanim_window_get_size(&win_x, &win_y);
|
||||
glViewport(0, 0, win_x, win_y);
|
||||
GPU_viewport(0, 0, win_x, win_y);
|
||||
glScissor(0, 0, win_x, win_y);
|
||||
playanim_gl_matrix();
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ void wmViewport(const rcti *winrct)
|
|||
int width = BLI_rcti_size_x(winrct) + 1;
|
||||
int height = BLI_rcti_size_y(winrct) + 1;
|
||||
|
||||
glViewport(winrct->xmin, winrct->ymin, width, height);
|
||||
GPU_viewport(winrct->xmin, winrct->ymin, width, height);
|
||||
glScissor(winrct->xmin, winrct->ymin, width, height);
|
||||
|
||||
wmOrtho2_pixelspace(width, height);
|
||||
|
@ -79,7 +79,7 @@ void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct
|
|||
scissor_height += 1;
|
||||
}
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
GPU_viewport(0, 0, width, height);
|
||||
glScissor(x, y, scissor_width, scissor_height);
|
||||
|
||||
wmOrtho2_pixelspace(width, height);
|
||||
|
@ -91,7 +91,7 @@ void wmWindowViewport(wmWindow *win)
|
|||
int width = WM_window_pixels_x(win);
|
||||
int height = WM_window_pixels_y(win);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
GPU_viewport(0, 0, width, height);
|
||||
glScissor(0, 0, width, height);
|
||||
|
||||
wmOrtho2_pixelspace(width, height);
|
||||
|
|
Loading…
Reference in New Issue