From 4646ecf74917d5cee0a4f0d330a1306acd086a61 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Wed, 22 Mar 2017 15:52:48 -0400 Subject: OpenGL: use new API for persp & ortho projection Still using legacy GL within the GPU library itself, but we'll be able to switch soon. Part of T49450 --- source/blender/editors/space_view3d/view3d_view.c | 4 +- source/blender/gpu/intern/gpu_matrix.c | 60 ++++++++++++++++++++++ source/blender/windowmanager/WM_api.h | 4 +- source/blender/windowmanager/intern/wm_subwindow.c | 20 +------- 4 files changed, 64 insertions(+), 24 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index f0ea7fce0d7..d648e43977b 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -927,10 +927,10 @@ void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rcti *rect) } if (is_ortho) { - wmOrtho(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend); + gpuOrtho(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend); } else { - wmFrustum(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend); + gpuFrustum(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend); } /* update matrix in 3d view region */ diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c index eecb87a74c0..5f6c1ed279b 100644 --- a/source/blender/gpu/intern/gpu_matrix.c +++ b/source/blender/gpu/intern/gpu_matrix.c @@ -578,6 +578,26 @@ static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3 void gpuOrtho(float left, float right, float bottom, float top, float near, float far) { +#if SUPPORT_LEGACY_MATRIX + if (state.mode == MATRIX_MODE_INACTIVE) { + GLenum mode; + glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode); + if (mode != GL_PROJECTION) { + glMatrixMode(GL_PROJECTION); + } + + glLoadIdentity(); + glOrtho(left, right, bottom, top, near, far); + + if (mode != GL_PROJECTION_MATRIX) { + glMatrixMode(mode); /* restore */ + } + + state.dirty = true; + return; + } +#endif + BLI_assert(state.mode == MATRIX_MODE_3D); mat4_ortho_set(Projection3D, left, right, bottom, top, near, far); CHECKMAT(Projection3D); @@ -586,6 +606,26 @@ void gpuOrtho(float left, float right, float bottom, float top, float near, floa void gpuOrtho2D(float left, float right, float bottom, float top) { +#if SUPPORT_LEGACY_MATRIX + if (state.mode == MATRIX_MODE_INACTIVE) { + GLenum mode; + glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode); + if (mode != GL_PROJECTION) { + glMatrixMode(GL_PROJECTION); + } + + glLoadIdentity(); + glOrtho(left, right, bottom, top, -1.0f, 1.0f); + + if (mode != GL_PROJECTION_MATRIX) { + glMatrixMode(mode); /* restore */ + } + + state.dirty = true; + return; + } +#endif + /* TODO: this function, but correct */ BLI_assert(state.mode == MATRIX_MODE_2D); Mat4 m; @@ -597,6 +637,26 @@ void gpuOrtho2D(float left, float right, float bottom, float top) void gpuFrustum(float left, float right, float bottom, float top, float near, float far) { +#if SUPPORT_LEGACY_MATRIX + if (state.mode == MATRIX_MODE_INACTIVE) { + GLenum mode; + glGetIntegerv(GL_MATRIX_MODE, (GLint*)&mode); + if (mode != GL_PROJECTION) { + glMatrixMode(GL_PROJECTION); + } + + glLoadIdentity(); + glFrustum(left, right, bottom, top, near, far); + + if (mode != GL_PROJECTION_MATRIX) { + glMatrixMode(mode); /* restore */ + } + + state.dirty = true; + return; + } +#endif + BLI_assert(state.mode == MATRIX_MODE_3D); mat4_frustum_set(Projection3D, left, right, bottom, top, near, far); CHECKMAT(Projection3D); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index f264af899da..bae2aea4d27 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -422,9 +422,7 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid); void wmSubWindowSet (struct wmWindow *win, int swinid); void wmSubWindowScissorSet (struct wmWindow *win, int swinid, const struct rcti *srct, bool srct_pad); - /* OpenGL utilities with safety check + working in modelview matrix mode */ -void wmFrustum (float x1, float x2, float y1, float y2, float n, float f); -void wmOrtho (float x1, float x2, float y1, float y2, float n, float f); + /* OpenGL utilities with safety check */ void wmOrtho2 (float x1, float x2, float y1, float y2); /* use for conventions (avoid hard-coded offsets all over) */ void wmOrtho2_region_pixelspace(const struct ARegion *ar); diff --git a/source/blender/windowmanager/intern/wm_subwindow.c b/source/blender/windowmanager/intern/wm_subwindow.c index 489f0b8013f..d73aa107cab 100644 --- a/source/blender/windowmanager/intern/wm_subwindow.c +++ b/source/blender/windowmanager/intern/wm_subwindow.c @@ -332,31 +332,13 @@ void wmSubWindowSet(wmWindow *win, int swinid) wmSubWindowScissorSet(win, swinid, NULL, true); } -void wmFrustum(float x1, float x2, float y1, float y2, float n, float f) -{ - glMatrixMode(GL_PROJECTION); - gpuLoadIdentity(); - glFrustum(x1, x2, y1, y2, n, f); - glMatrixMode(GL_MODELVIEW); -} - -void wmOrtho(float x1, float x2, float y1, float y2, float n, float f) -{ - glMatrixMode(GL_PROJECTION); - gpuLoadIdentity(); - - glOrtho(x1, x2, y1, y2, n, f); - - glMatrixMode(GL_MODELVIEW); -} - void wmOrtho2(float x1, float x2, float y1, float y2) { /* prevent opengl from generating errors */ if (x1 == x2) x2 += 1.0f; if (y1 == y2) y2 += 1.0f; - wmOrtho(x1, x2, y1, y2, -100, 100); + gpuOrtho(x1, x2, y1, y2, -100, 100); } static void wmOrtho2_offset(const float x, const float y, const float ofs) -- cgit v1.2.3