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
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2017-04-19 11:13:10 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-04-19 16:22:58 +0300
commitba4d23fe37ee626c92c61bf0f78f64dcc2d95114 (patch)
tree68e34d845b87dbaa19b24dd04952aa71068ca16c /source/blender
parent781108cdc6095f126ad0c77411d39acb52f11aa0 (diff)
Fix node editor drawing when built with core profile
There are two major things in this commit. First one is to have proper stack for projection matrices. This is something what OpenGL specification grants to have at least 2 elements for and what is required to have for proper editor drawing without refactoring the way how we restore projection matrix. Supporting this stack have following advantages: - Our GPU stack is closer to OpenGL specs, making it easier to follow by other developers who are always familiar with OpenGL. - Makes it easier to port all editors to a new API. - Should help us getting rid of extra matrix push/pop added in various commits to 2.8 branch. The new API follows the following convention: - gpuPushMatrix/gpuPopMatrix ALWAYS deals with model view matrix and nothing more. While this name does not fully indicate that it's only model view matrix operator, it matches behavior of other matrix operations such as transform which also doesn't indicate what matrix type they are operating on. - Projection matrix has dedicated calls for push/pop which are gpuPushProjectionMatrix/gpuPopProjectionMatrix.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/space_node/drawnode.c4
-rw-r--r--source/blender/editors/space_node/node_draw.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_draw_legacy.c10
-rw-r--r--source/blender/gpu/GPU_matrix.h4
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c66
-rw-r--r--source/blender/windowmanager/intern/wm_playanim.c4
6 files changed, 66 insertions, 26 deletions
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index f4ed3c06328..3b3a11f3269 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3176,7 +3176,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
float x, y;
glMatrixMode(GL_PROJECTION);
- gpuPushMatrix();
+ gpuPushProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPushMatrix();
@@ -3264,7 +3264,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
}
glMatrixMode(GL_PROJECTION);
- gpuPopMatrix();
+ gpuPopProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPopMatrix();
}
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index cb5f434849e..f80d47b1974 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -1189,7 +1189,7 @@ void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2])
void node_draw_default(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key)
{
glMatrixMode(GL_PROJECTION);
- gpuPushMatrix();
+ gpuPushProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPushMatrix();
@@ -1199,7 +1199,7 @@ void node_draw_default(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTr
node_draw_basis(C, ar, snode, ntree, node, key);
glMatrixMode(GL_PROJECTION);
- gpuPopMatrix();
+ gpuPopProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPopMatrix();
}
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
index e01ac976f95..0d59b9afb14 100644
--- a/source/blender/editors/space_view3d/view3d_draw_legacy.c
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -755,7 +755,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
- gpuPushMatrix();
+ gpuPushProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPushMatrix();
ED_region_pixelspace(ar);
@@ -778,7 +778,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
zoomx, zoomy, col);
glMatrixMode(GL_PROJECTION);
- gpuPopMatrix();
+ gpuPopProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPopMatrix();
@@ -1823,7 +1823,7 @@ void ED_view3d_draw_offscreen(
}
glMatrixMode(GL_PROJECTION);
- gpuPushMatrix();
+ gpuPushProjectionMatrix();
gpuLoadIdentity();
glMatrixMode(GL_MODELVIEW);
gpuPushMatrix();
@@ -2533,7 +2533,7 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar)
bool clip_border = (render_border && !BLI_rcti_compare(&ar->drawrct, &border_rect));
glMatrixMode(GL_PROJECTION);
- gpuPushMatrix();
+ gpuPushProjectionMatrix();
gpuLoadIdentity();
glMatrixMode(GL_MODELVIEW);
gpuPushMatrix();
@@ -2565,7 +2565,7 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar)
view3d_main_region_draw_info(C, scene, ar, v3d, grid_unit, render_border);
glMatrixMode(GL_PROJECTION);
- gpuPopMatrix();
+ gpuPopProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
gpuPopMatrix();
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 93bb1dd4051..749784c9a2c 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -87,6 +87,10 @@ void gpuScale2f(float x, float y);
void gpuScale2fv(const float vec[2]);
void gpuRotate2D(float deg);
+/* Projection Matrix (2D or 3D) */
+
+void gpuPushProjectionMatrix(void);
+void gpuPopProjectionMatrix(void);
/* 3D Projection Matrix */
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index d958b012fa2..deb920c2582 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -44,11 +44,14 @@
typedef float Mat4[4][4];
typedef float Mat3[3][3];
-typedef struct {
- Mat4 ModelViewStack[MATRIX_STACK_DEPTH];
- Mat4 ProjectionMatrix;
+typedef struct MatrixStack {
+ Mat4 stack[MATRIX_STACK_DEPTH];
+ unsigned int top;
+} MatrixStack;
- unsigned top; /* of ModelView stack */
+typedef struct {
+ MatrixStack model_view_stack;
+ MatrixStack projection_stack;
bool dirty;
@@ -66,20 +69,23 @@ typedef struct {
{0.0f, 0.0f, 0.0f, 1.0f}}
static MatrixState state = {
- .ModelViewStack = {MATRIX_4X4_IDENTITY},
- .ProjectionMatrix = MATRIX_4X4_IDENTITY,
- .top = 0,
+ .model_view_stack = {{MATRIX_4X4_IDENTITY}, 0},
+ .projection_stack = {{MATRIX_4X4_IDENTITY}, 0},
.dirty = true
};
#undef MATRIX_4X4_IDENTITY
-#define ModelView state.ModelViewStack[state.top]
-#define Projection state.ProjectionMatrix
+#define ModelViewStack state.model_view_stack
+#define ModelView ModelViewStack.stack[ModelViewStack.top]
+
+#define ProjectionStack state.projection_stack
+#define Projection ProjectionStack.stack[ProjectionStack.top]
void gpuMatrixReset(void)
{
- state.top = 0;
+ state.model_view_stack.top = 0;
+ state.projection_stack.top = 0;
unit_m4(ModelView);
unit_m4(Projection);
state.dirty = true;
@@ -119,9 +125,9 @@ void gpuPushMatrix(void)
}
#endif
- BLI_assert(state.top < MATRIX_STACK_DEPTH);
- state.top++;
- copy_m4_m4(ModelView, state.ModelViewStack[state.top - 1]);
+ BLI_assert(ModelViewStack.top < MATRIX_STACK_DEPTH);
+ ModelViewStack.top++;
+ copy_m4_m4(ModelView, ModelViewStack.stack[ModelViewStack.top - 1]);
}
void gpuPopMatrix(void)
@@ -134,8 +140,38 @@ void gpuPopMatrix(void)
}
#endif
- BLI_assert(state.top > 0);
- state.top--;
+ BLI_assert(ModelViewStack.top > 0);
+ ModelViewStack.top--;
+ state.dirty = true;
+}
+
+void gpuPushProjectionMatrix(void)
+{
+#if SUPPORT_LEGACY_MATRIX
+ {
+ glPushMatrix();
+ state.dirty = true;
+ return;
+ }
+#endif
+
+ BLI_assert(ProjectionStack.top < MATRIX_STACK_DEPTH);
+ ProjectionStack.top++;
+ copy_m4_m4(Projection, ProjectionStack.stack[ProjectionStack.top - 1]);
+}
+
+void gpuPopProjectionMatrix(void)
+{
+#if SUPPORT_LEGACY_MATRIX
+ {
+ glPopMatrix();
+ state.dirty = true;
+ return;
+ }
+#endif
+
+ BLI_assert(ProjectionStack.top > 0);
+ ProjectionStack.top--;
state.dirty = true;
}
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index c9ce5d140a5..ebc79986198 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -361,7 +361,7 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
fac = 2.0f * fac - 1.0f;
glMatrixMode(GL_PROJECTION); /* TODO: convert this nasty code */
- gpuPushMatrix();
+ gpuPushProjectionMatrix();
gpuLoadIdentity();
glMatrixMode(GL_MODELVIEW);
gpuPushMatrix();
@@ -381,7 +381,7 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
gpuPopMatrix();
glMatrixMode(GL_PROJECTION);
- gpuPopMatrix();
+ gpuPopProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
}