DRW: Add polygon offset mode.
authorClément Foucault <foucault.clem@gmail.com>
Tue, 11 Dec 2018 17:18:36 +0000 (18:18 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Tue, 11 Dec 2018 17:18:36 +0000 (18:18 +0100)
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_manager_exec.c

index 519c907a6a450dd5ebbb7907ece7afefee71a1e1..89aa55c56b20881541a5e4d22ae4039b530876f0 100644 (file)
@@ -283,8 +283,8 @@ typedef enum {
        DRW_STATE_CULL_FRONT    = (1 << 9),
        DRW_STATE_WIRE          = (1 << 10),
        DRW_STATE_POINT         = (1 << 11),
-       /* DRW_STATE_STIPPLE_2     = (1 << 12), */ /* Not used */
-       /* DRW_STATE_STIPPLE_3     = (1 << 13), */ /* Not used */
+       DRW_STATE_OFFSET_POSITIVE = (1 << 12), /* Polygon offset. Does not work with lines and points. */
+       DRW_STATE_OFFSET_NEGATIVE = (1 << 13), /* Polygon offset. Does not work with lines and points. */
        /* DRW_STATE_STIPPLE_4     = (1 << 14), */ /* Not used */
        DRW_STATE_BLEND         = (1 << 15),
        DRW_STATE_ADDITIVE      = (1 << 16),
index 8eefd0587192396cfcaf822c16aa1b2930cc0377..985c4a737758292ce500373ffaa5433151cd16fb 100644 (file)
@@ -342,6 +342,32 @@ void drw_state_set(DRWState state)
                }
        }
 
+       /* Polygon Offset */
+       {
+               int test;
+               if (CHANGED_ANY_STORE_VAR(
+                       DRW_STATE_OFFSET_POSITIVE |
+                       DRW_STATE_OFFSET_NEGATIVE,
+                       test)) {
+                       if (test) {
+                               glEnable(GL_POLYGON_OFFSET_FILL);
+                               /* Stencil Write */
+                               if ((state & DRW_STATE_OFFSET_POSITIVE) != 0) {
+                                       glPolygonOffset(1.0f, 1.0f);
+                               }
+                               else if ((state & DRW_STATE_OFFSET_NEGATIVE) != 0) {
+                                       glPolygonOffset(-1.0f, -1.0f);
+                               }
+                               else {
+                                       BLI_assert(0);
+                               }
+                       }
+                       else {
+                               glDisable(GL_POLYGON_OFFSET_FILL);
+                       }
+               }
+       }
+
 #undef CHANGED_TO
 #undef CHANGED_ANY
 #undef CHANGED_ANY_STORE_VAR