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
This commit is contained in:
parent
98a0dd6888
commit
4646ecf749
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue