Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-07-17 20:03:30 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-07-18 04:43:52 +0300
commita6bd7777c20aa229ae9c4cdd537e94cf8a9c7edf (patch)
tree839f559613038d8ec17e18b7bc85b1a231bf01a4 /source
parent35f1b3e43b37006486b94675466cf4260087e269 (diff)
Cleanup: GPU: Encapsulate glViewport calls
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/intern/draw_manager.c10
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c2
-rw-r--r--source/blender/gpu/GPU_state.h1
-rw-r--r--source/blender/gpu/intern/gpu_select_pick.c4
-rw-r--r--source/blender/gpu/intern/gpu_select_sample_query.c4
-rw-r--r--source/blender/gpu/intern/gpu_state.c5
-rw-r--r--source/blender/windowmanager/intern/wm_gesture.c10
-rw-r--r--source/blender/windowmanager/intern/wm_playanim.c4
-rw-r--r--source/blender/windowmanager/intern/wm_subwindow.c6
9 files changed, 26 insertions, 20 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 5359f649d6b..fcedc6bf0c7 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -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);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 579b5929c15..f77bb394567 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -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);
diff --git a/source/blender/gpu/GPU_state.h b/source/blender/gpu/GPU_state.h
index 36a82e31521..4aa88d2e037 100644
--- a/source/blender/gpu/GPU_state.h
+++ b/source/blender/gpu/GPU_state.h
@@ -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);
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 3e5fc1ab19e..c6d8545527c 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -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. */
diff --git a/source/blender/gpu/intern/gpu_select_sample_query.c b/source/blender/gpu/intern/gpu_select_sample_query.c
index b20b6cac36b..70ad2f6759e 100644
--- a/source/blender/gpu/intern/gpu_select_sample_query.c
+++ b/source/blender/gpu/intern/gpu_select_sample_query.c
@@ -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 */
diff --git a/source/blender/gpu/intern/gpu_state.c b/source/blender/gpu/intern/gpu_state.c
index 8dc246904df..1e79212fc4e 100644
--- a/source/blender/gpu/intern/gpu_state.c
+++ b/source/blender/gpu/intern/gpu_state.c
@@ -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);
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c
index e7cb1c00605..eee93fc9459 100644
--- a/source/blender/windowmanager/intern/wm_gesture.c
+++ b/source/blender/windowmanager/intern/wm_gesture.c
@@ -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 */
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index bdc61153f07..6aeabf3a0ae 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -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();
diff --git a/source/blender/windowmanager/intern/wm_subwindow.c b/source/blender/windowmanager/intern/wm_subwindow.c
index 5483d79c075..490f45b270f 100644
--- a/source/blender/windowmanager/intern/wm_subwindow.c
+++ b/source/blender/windowmanager/intern/wm_subwindow.c
@@ -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);