OpenGL: stipple support added to basic GLSL shader
authorAlexander Romanov <a.romanov@blend4web.com>
Fri, 25 Dec 2015 21:57:50 +0000 (22:57 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 26 Dec 2015 21:15:23 +0000 (22:15 +0100)
The is intended to replace the deprecated glPolygonStipple() calls with a shader
based alternative, once we switch over to GLSL shaders.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D1688

14 files changed:
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/screen/glutil.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/gpu/GPU_basic_shader.h
source/blender/gpu/intern/gpu_basic_shader.c
source/blender/gpu/intern/gpu_draw.c
source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
source/blender/windowmanager/intern/wm_stereo.c
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp

index 836072df67db566929a7d970659748a4f83de102..632403c5e25dced61f11c1ec381be6a094dfe312 100644 (file)
@@ -59,6 +59,7 @@
 #include "GPU_draw.h"
 #include "GPU_glew.h"
 #include "GPU_shader.h"
+#include "GPU_basic_shader.h"
 
 #include "WM_api.h"
 
@@ -66,8 +67,6 @@
 #include <limits.h>
 #include <math.h>
 
-extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
-
 typedef struct {
        DerivedMesh dm;
 
@@ -768,8 +767,8 @@ static void cdDM_drawMappedFaces(
                                        }
 
                                        if (draw_option == DM_DRAW_OPTION_STIPPLE) {
-                                               glEnable(GL_POLYGON_STIPPLE);
-                                               glPolygonStipple(stipple_quarttone);
+                                               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+                                               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
                                        }
 
                                        /* Goal is to draw as long of a contiguous triangle
@@ -798,7 +797,7 @@ static void cdDM_drawMappedFaces(
                                                start_element = tot_element;
 
                                                if (draw_option == DM_DRAW_OPTION_STIPPLE)
-                                                       glDisable(GL_POLYGON_STIPPLE);
+                                                       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                                        }
                                        else {
                                                tot_drawn += tot_tri_verts;
index dc50e39a8623c7c92aba64c6f789db76446168a0..642a89df8e0e571ca4b4b9ef5f766b29fb302b69 100644 (file)
@@ -57,8 +57,7 @@
 
 #include "GPU_glew.h"
 #include "GPU_shader.h"
-
-extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
+#include "GPU_basic_shader.h"
 
 static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4]);
 
@@ -804,8 +803,8 @@ static void emDM_drawMappedFaces(
                                        if (poly_prev != GL_ZERO) glEnd();
                                        poly_prev = GL_ZERO; /* force glBegin */
 
-                                       glEnable(GL_POLYGON_STIPPLE);
-                                       glPolygonStipple(stipple_quarttone);
+                                       GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
                                }
 
                                if      (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
@@ -867,7 +866,7 @@ static void emDM_drawMappedFaces(
                                        glEnd();
                                        poly_prev = GL_ZERO; /* force glBegin */
 
-                                       glDisable(GL_POLYGON_STIPPLE);
+                                       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                                }
                        }
                }
@@ -903,8 +902,8 @@ static void emDM_drawMappedFaces(
                                        if (poly_prev != GL_ZERO) glEnd();
                                        poly_prev = GL_ZERO; /* force glBegin */
 
-                                       glEnable(GL_POLYGON_STIPPLE);
-                                       glPolygonStipple(stipple_quarttone);
+                                       GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
                                }
 
                                if      (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
@@ -968,7 +967,7 @@ static void emDM_drawMappedFaces(
                                        glEnd();
                                        poly_prev = GL_ZERO; /* force glBegin */
 
-                                       glDisable(GL_POLYGON_STIPPLE);
+                                       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                                }
                        }
                }
index 53da38b2da8e9e64a27fe9a87d1ab9efeafeec6c..f16ef3df6bea90a89ee861b7035b59eb0e4e71fe 100644 (file)
@@ -77,6 +77,7 @@
 #include "GPU_glew.h"
 #include "GPU_buffers.h"
 #include "GPU_shader.h"
+#include "GPU_basic_shader.h"
 
 #include "CCGSubSurf.h"
 
@@ -87,8 +88,6 @@
 /* assumes MLoop's are layed out 4 for each poly, in order */
 #define USE_LOOP_LAYOUT_FAST
 
-extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
-
 static ThreadRWMutex loops_cache_rwlock = BLI_RWLOCK_INITIALIZER;
 static ThreadRWMutex origindex_cache_rwlock = BLI_RWLOCK_INITIALIZER;
 
@@ -3652,8 +3651,8 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm,
 
                        if (draw_option != DM_DRAW_OPTION_SKIP) {
                                if (draw_option == DM_DRAW_OPTION_STIPPLE) {
-                                       glEnable(GL_POLYGON_STIPPLE);
-                                       glPolygonStipple(stipple_quarttone);
+                                       GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
                                }
 
                                /* no need to set shading mode to flat because
@@ -3752,7 +3751,7 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm,
                                        }
                                }
                                if (draw_option == DM_DRAW_OPTION_STIPPLE)
-                                       glDisable(GL_POLYGON_STIPPLE);
+                                       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                        }
                }
        }
index ae2e674416067c3ee1d9b307cc3eccd649fda911..a3adf65cd84c874073b70b39dffeede286eca351 100644 (file)
@@ -1133,14 +1133,17 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
        sizey_solid = sizey / 4;
        y1 = rect->ymin;
 
+       /* Drawing the checkerboard.
+        * This could be optimized with a single checkerboard shader,
+        * instead of drawing twice and using stippling the second time. */
        /* layer: background, to show tranparency */
        glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
        glRectf(x1, y1, x1 + sizex, rect->ymax);
-       glEnable(GL_POLYGON_STIPPLE);
+       GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
        glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
-       glPolygonStipple(stipple_checker_8px);
+       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
        glRectf(x1, y1, x1 + sizex, rect->ymax);
-       glDisable(GL_POLYGON_STIPPLE);
+       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
        /* layer: color ramp */
        glShadeModel(GL_FLAT);
index da348c886503bea6a1e194a235f51ebfd84a4220..279572f82d167d7aba53638cab8d985374296ff2 100644 (file)
@@ -57,6 +57,8 @@
 
 #include "interface_intern.h"
 
+#include "GPU_basic_shader.h"
+
 #ifdef WITH_INPUT_IME
 #  include "WM_types.h"
 #endif
@@ -660,14 +662,14 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
                                glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 
                                /* light checkers */
-                               glEnable(GL_POLYGON_STIPPLE);
+                               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
                                glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
-                               glPolygonStipple(stipple_checker_8px);
+                               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
 
                                glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
                                glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 
-                               glDisable(GL_POLYGON_STIPPLE);
+                               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
                                /* alpha fill */
                                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
index 91eea6f8248b6514809c1bee516d989e69fb86a8..cbb6b7685af9240c5255813cb4bf2bcc4f1bb5e1 100644 (file)
 #define GL_CLAMP_TO_EDGE                        0x812F
 #endif
 
-
-/* ******************************************** */
-
-/* defined in BIF_gl.h */
-const GLubyte stipple_halftone[128] = {
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55};
-
-
-/*  repeat this pattern
- *
- *     X000X000
- *     00000000
- *     00X000X0
- *     00000000 */
-
-
-const GLubyte stipple_quarttone[128] = {
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
-       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0};
-
-
-const GLubyte stipple_diag_stripes_pos[128] = {
-       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
-       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
-       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
-       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
-       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
-       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
-       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
-       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
-       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
-       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
-       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
-       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
-       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
-       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
-       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
-       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f};
-
-
-const GLubyte stipple_diag_stripes_neg[128] = {
-       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
-       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
-       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
-       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
-       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
-       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
-       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
-       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
-       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
-       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
-       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
-       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
-       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
-       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
-       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
-       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80};
-
-const GLubyte stipple_checker_8px[128] = {
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255};
-
 /* UNUSED */
 #if 0
 void fdrawbezier(float vec[4][3])
@@ -206,10 +117,10 @@ void fdrawcheckerboard(float x1, float y1, float x2, float y2)
        glRectf(x1, y1, x2, y2);
        glColor3ubv(col2);
 
-       glEnable(GL_POLYGON_STIPPLE);
-       glPolygonStipple(stipple_checker_8px);
+       GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
        glRectf(x1, y1, x2, y2);
-       glDisable(GL_POLYGON_STIPPLE);
+       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 }
 
 void sdrawline(int x1, int y1, int x2, int y2)
index deb0a3f6d03a204da85b94292b96ad2eac16b391..393e7292d64d2acea134b47b27875413dd17de48 100644 (file)
@@ -281,14 +281,14 @@ static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequenc
 static void drawmeta_stipple(int value)
 {
        if (value) {
-               glEnable(GL_POLYGON_STIPPLE);
-               glPolygonStipple(stipple_halftone);
+               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
                
                glEnable(GL_LINE_STIPPLE);
                glLineStipple(1, 0x8888);
        }
        else {
-               glDisable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                glDisable(GL_LINE_STIPPLE);
        }
 }
@@ -586,8 +586,8 @@ void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, f
        float ymid1, ymid2;
        
        if (seq->flag & SEQ_MUTE) {
-               glEnable(GL_POLYGON_STIPPLE);
-               glPolygonStipple(stipple_halftone);
+               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
        }
        
        ymid1 = (y2 - y1) * 0.25f + y1;
@@ -634,7 +634,7 @@ void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, f
        glEnd();
        
        if (seq->flag & SEQ_MUTE) {
-               glDisable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
        }
 }
 
@@ -801,32 +801,32 @@ static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, AReg
 
        /* draw lock */
        if (seq->flag & SEQ_LOCK) {
-               glEnable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
                glEnable(GL_BLEND);
 
                /* light stripes */
                glColor4ub(255, 255, 255, 32);
-               glPolygonStipple(stipple_diag_stripes_pos);
+               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
                glRectf(x1, y1, x2, y2);
 
                /* dark stripes */
                glColor4ub(0, 0, 0, 32);
-               glPolygonStipple(stipple_diag_stripes_neg);
+               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP);
                glRectf(x1, y1, x2, y2);
 
-               glDisable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                glDisable(GL_BLEND);
        }
 
        if (!BKE_sequence_is_valid_check(seq)) {
-               glEnable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
 
                /* panic! */
                glColor4ub(255, 0, 0, 255);
-               glPolygonStipple(stipple_diag_stripes_pos);
+               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
                glRectf(x1, y1, x2, y2);
 
-               glDisable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
        }
 
        color3ubv_from_seq(scene, seq, col);
index f4eed3e1fda9bdf2e896c0ab7eae1eb90537fc0a..34f59b56fffe69fa408b3524e3af50189687803a 100644 (file)
@@ -65,6 +65,8 @@
 
 #include "uvedit_intern.h"
 
+#include "GPU_basic_shader.h"
+
 /* use editmesh tessface */
 #define USE_EDBM_LOOPTRIS
 
@@ -637,8 +639,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
 
                                        if (tf == activetf) {
                                                /* only once */
-                                               glEnable(GL_POLYGON_STIPPLE);
-                                               glPolygonStipple(stipple_quarttone);
+                                               GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+                                               GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
                                                UI_ThemeColor4(TH_EDITMESH_ACTIVE);
                                        }
                                        else {
@@ -650,7 +652,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
                                        glEnd();
 
                                        if (tf == activetf) {
-                                               glDisable(GL_POLYGON_STIPPLE);
+                                               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                                        }
                                }
                                else {
@@ -713,8 +715,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                        UI_ThemeColor4(TH_EDITMESH_ACTIVE);
 
-                       glEnable(GL_POLYGON_STIPPLE);
-                       glPolygonStipple(stipple_quarttone);
+                       GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
 
                        glBegin(GL_POLYGON);
                        BM_ITER_ELEM (l, &liter, activef, BM_LOOPS_OF_FACE) {
@@ -723,7 +725,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
                        }
                        glEnd();
 
-                       glDisable(GL_POLYGON_STIPPLE);
+                       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                        glDisable(GL_BLEND);
                }
        }
index 3298f0f35b4afc70a08770a89c639abcb6826fe9..f964e056d44d792634359e7769e03ee9edadb34f 100644 (file)
@@ -47,10 +47,27 @@ typedef enum GPUBasicShaderOption {
        GPU_SHADER_TEXTURE_2D =       (1<<3),   /* use 2D texture to replace diffuse color */
 
        GPU_SHADER_SOLID_LIGHTING =   (1<<4),   /* use faster lighting (set automatically) */
-       GPU_SHADER_OPTIONS_NUM = 5,
+       GPU_SHADER_STIPPLE =          (1<<5),   /* use stipple */
+       GPU_SHADER_OPTIONS_NUM = 6,
        GPU_SHADER_OPTION_COMBINATIONS = (1<<GPU_SHADER_OPTIONS_NUM)
 } GPUBasicShaderOption;
 
+/* Keep these in sync with gpu_shader_basic_frag.glsl */
+typedef enum GPUBasicShaderStipple {
+       GPU_SHADER_STIPPLE_HALFTONE                        = 0,
+       GPU_SHADER_STIPPLE_QUARTTONE                       = 1,
+       GPU_SHADER_STIPPLE_CHECKER_8PX                     = 2,
+       GPU_SHADER_STIPPLE_HEXAGON                         = 3,
+       GPU_SHADER_STIPPLE_DIAG_STRIPES                    = 4,
+       GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP               = 5,
+       GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW               = 6,
+       GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW_SWAP          = 7,
+       GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN            = 8,
+       GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN_SWAP       = 9,
+       GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER           = 10,
+       GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER_SWAP      = 11
+} GPUBasicShaderStipple;
+
 void GPU_basic_shaders_init(void);
 void GPU_basic_shaders_exit(void);
 
@@ -87,6 +104,7 @@ typedef struct GPULightData {
 
 void GPU_basic_shader_light_set(int light_num, GPULightData *light);
 void GPU_basic_shader_light_set_viewer(bool local);
+void GPU_basic_shader_stipple(GPUBasicShaderStipple stipple_id);
 
 #ifdef __cplusplus
 }
index c441a44c17b600722e93668c9c42bdce7311cd7c..c01d5321fe3ee511c71cec10c01ea2b466bc6218 100644 (file)
@@ -63,6 +63,210 @@ static struct {
        int lights_directional;
 } GPU_MATERIAL_STATE;
 
+
+/* Stipple patterns */
+/* ******************************************** */
+const GLubyte stipple_halftone[128] = {
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+       0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55};
+
+const GLubyte stipple_quarttone[128] = {
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0,
+       136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0};
+
+const GLubyte stipple_diag_stripes_pos[128] = {
+       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
+       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
+       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
+       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
+       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
+       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
+       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
+       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
+       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
+       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
+       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
+       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
+       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
+       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
+       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
+       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f};
+
+const GLubyte stipple_diag_stripes_neg[128] = {
+       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
+       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
+       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
+       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
+       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
+       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
+       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
+       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
+       0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
+       0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
+       0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
+       0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
+       0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
+       0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
+       0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
+       0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80};
+
+const GLubyte stipple_checker_8px[128] = {
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255};
+
+const GLubyte stipple_interlace_row[128] = {
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
+
+const GLubyte stipple_interlace_row_swap[128] = {
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
+
+const GLubyte stipple_interlace_column[128] = {
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
+
+const GLubyte stipple_interlace_column_swap[128] = {
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+       0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa};
+
+const GLubyte stipple_interlace_checker[128] = {
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
+       0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa};
+
+const GLubyte stipple_interlace_checker_swap[128] = {
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
+       0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55};
+
+const GLubyte stipple_hexagon[128] = {
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+       0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};
+/* ********************************************* */
+
 /* Init / exit */
 
 void GPU_basic_shaders_init(void)
@@ -141,6 +345,8 @@ static GPUShader *gpu_basic_shader(int options)
                        strcat(defines, "#define USE_TWO_SIDED\n");
                if (options & GPU_SHADER_TEXTURE_2D)
                        strcat(defines, "#define USE_TEXTURE\n");
+               if (options & GPU_SHADER_STIPPLE)
+                       strcat(defines, "#define USE_STIPPLE\n");
 
                if (options & GPU_SHADER_SOLID_LIGHTING)
                        strcat(defines, "#define USE_SOLID_LIGHTING\n");
@@ -214,6 +420,11 @@ void GPU_basic_shader_bind(int options)
                        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                        glDisable(GL_TEXTURE_2D);
                }
+
+               if (options & GPU_SHADER_STIPPLE)
+                       glEnable(GL_POLYGON_STIPPLE);
+               else if (bound_options & GPU_SHADER_STIPPLE)
+                       glDisable(GL_POLYGON_STIPPLE);
        }
 
        GPU_MATERIAL_STATE.bound_options = options;
@@ -329,3 +540,52 @@ void GPU_basic_shader_light_set_viewer(bool local)
        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (local)? GL_TRUE: GL_FALSE);
 }
 
+void GPU_basic_shader_stipple(GPUBasicShaderStipple stipple_id)
+{
+       if (USE_GLSL) {
+               glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_id"), stipple_id);
+       }
+       else {
+               switch(stipple_id) {
+               case GPU_SHADER_STIPPLE_HALFTONE:
+                       glPolygonStipple(stipple_halftone);
+                       return;
+               case GPU_SHADER_STIPPLE_QUARTTONE:
+                       glPolygonStipple(stipple_quarttone);
+                       return;
+               case GPU_SHADER_STIPPLE_CHECKER_8PX:
+                       glPolygonStipple(stipple_checker_8px);
+                       return;
+               case GPU_SHADER_STIPPLE_HEXAGON:
+                       glPolygonStipple(stipple_hexagon);
+                       return;
+               case GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP:
+                       glPolygonStipple(stipple_diag_stripes_neg);
+                       return;
+               case GPU_SHADER_STIPPLE_DIAG_STRIPES:
+                       glPolygonStipple(stipple_diag_stripes_pos);
+                       return;
+               case GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW:
+                       glPolygonStipple(stipple_interlace_row);
+                       return;
+               case GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW_SWAP:
+                       glPolygonStipple(stipple_interlace_row_swap);
+                       return;
+               case GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN:
+                       glPolygonStipple(stipple_interlace_column);
+                       return;
+               case GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN_SWAP:
+                       glPolygonStipple(stipple_interlace_column_swap);
+                       return;
+               case GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER:
+                       glPolygonStipple(stipple_interlace_checker);
+                       return;
+               case GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER_SWAP:
+                       glPolygonStipple(stipple_interlace_checker_swap);
+                       return;
+               default:
+                       glPolygonStipple(stipple_hexagon);
+                       return;
+               }
+       }
+}
index 27e428d7f6928b229b144e84324395ec86b02d13..92195bdf77934e113a690ea538f4daeecae3c93f 100644 (file)
@@ -2085,9 +2085,6 @@ void GPU_state_init(void)
 {
        float mat_ambient[] = { 0.0, 0.0, 0.0, 0.0 };
        float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
-       int a, x, y;
-       GLubyte pat[32 * 32];
-       const GLubyte *patc = pat;
        
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
@@ -2134,16 +2131,6 @@ void GPU_state_init(void)
        glPixelTransferi(GL_DEPTH_BIAS, 0);
        glPixelTransferi(GL_DEPTH_SCALE, 1);
        glDepthRange(0.0, 1.0);
-       
-       a = 0;
-       for (x = 0; x < 32; x++) {
-               for (y = 0; y < 4; y++) {
-                       if (x & 1) pat[a++] = 0x88;
-                       else pat[a++] = 0x22;
-               }
-       }
-
-       glPolygonStipple(patc);
 
        glMatrixMode(GL_TEXTURE);
        glLoadIdentity();
index 94c73d9e24886f375ed15ec1e96e36993ba59d90..7b4df51c12daec5a7c3821ec47dd4b1afbc94285 100644 (file)
 #define NUM_SOLID_LIGHTS 3
 #define NUM_SCENE_LIGHTS 8
 
+/* Keep these in sync with GPU_basic_shader.h */
+#define STIPPLE_HALFTONE                               0
+#define STIPPLE_QUARTTONE                              1
+#define STIPPLE_CHECKER_8PX                            2
+#define STIPPLE_HEXAGON                                3
+#define STIPPLE_DIAG_STRIPES                           4
+#define STIPPLE_DIAG_STRIPES_SWAP                      5
+#define STIPPLE_S3D_INTERLACE_ROW                      6
+#define STIPPLE_S3D_INTERLACE_ROW_SWAP                 7
+#define STIPPLE_S3D_INTERLACE_COLUMN                   8
+#define STIPPLE_S3D_INTERLACE_COLUMN_SWAP              9
+#define STIPPLE_S3D_INTERLACE_CHECKERBOARD             10
+#define STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP        11
+
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
 varying vec3 varying_normal;
 
@@ -29,8 +43,90 @@ varying vec2 varying_texture_coord;
 uniform sampler2D texture_map;
 #endif
 
+#ifdef USE_STIPPLE
+uniform int stipple_id;
+#endif
+
 void main()
 {
+#if defined(USE_STIPPLE)
+        /* We have to use mod function and integer casting.
+         * This can be optimized further with the bitwise operations
+         * when GLSL 1.3 is supported. */
+        if (stipple_id == STIPPLE_HALFTONE ||
+            stipple_id == STIPPLE_S3D_INTERLACE_CHECKERBOARD ||
+            stipple_id == STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP)
+        {
+            int result = int(mod(gl_FragCoord.x + gl_FragCoord.y, 2));
+            bool dis = result == 0;
+            if (stipple_id == STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP)
+                dis = !dis;
+            if (dis)
+                discard;
+        }
+        else if (stipple_id == STIPPLE_QUARTTONE) {
+            int mody = int(mod(gl_FragCoord.y, 4));
+            int modx = int(mod(gl_FragCoord.x, 4));
+            if (mody == 0) {
+                if (modx != 2)
+                    discard;
+            }
+            else if (mody == 2){
+                if (modx != 0)
+                    discard;
+            }
+            else
+                discard;
+        }
+        else if (stipple_id == STIPPLE_CHECKER_8PX) {
+            int result = int(mod(int(gl_FragCoord.x)/8 + int(gl_FragCoord.y)/8, 2));
+            if (result != 0)
+                discard;
+        }
+        else if (stipple_id == STIPPLE_DIAG_STRIPES) {
+            int mody = int(mod(gl_FragCoord.y, 16));
+            int modx = int(mod(gl_FragCoord.x, 16));
+            if ((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx)
+                discard;
+        }
+        else if (stipple_id == STIPPLE_DIAG_STRIPES_SWAP) {
+            int mody = int(mod(gl_FragCoord.y, 16));
+            int modx = int(mod(gl_FragCoord.x, 16));
+            if (!((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx))
+                discard;
+        }
+        else if (stipple_id == STIPPLE_S3D_INTERLACE_ROW || stipple_id == STIPPLE_S3D_INTERLACE_ROW_SWAP) {
+            int result = int(mod(gl_FragCoord.y, 2));
+            bool dis = result == 0;
+            if (stipple_id == STIPPLE_S3D_INTERLACE_ROW_SWAP)
+                dis = !dis;
+            if (dis)
+                discard;
+        }
+        else if (stipple_id == STIPPLE_S3D_INTERLACE_COLUMN || stipple_id == STIPPLE_S3D_INTERLACE_COLUMN_SWAP) {
+            int result = int(mod(gl_FragCoord.x, 2));
+            bool dis = result != 0;
+            if (stipple_id == STIPPLE_S3D_INTERLACE_COLUMN_SWAP)
+                dis = !dis;
+            if (dis)
+                discard;
+        }
+        else if (stipple_id == STIPPLE_HEXAGON) {
+            int mody = int(mod(gl_FragCoord.y, 2));
+            int modx = int(mod(gl_FragCoord.x, 4));
+            if (mody != 0) {
+                if (modx != 1)
+                    discard;
+            }
+            else {
+                if (modx != 3)
+                    discard;
+            }
+        }
+
+
+#endif
+
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
        /* compute normal */
        vec3 N = normalize(varying_normal);
index 21fc7f2b5b23c6faa5727320251ef91b45ed2b36..5576a1041231b554c549441cdc1397e1ebf429fb 100644 (file)
@@ -53,6 +53,7 @@
 #include "ED_screen.h"
 
 #include "GPU_glew.h"
+#include "GPU_basic_shader.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -82,76 +83,48 @@ static void wm_method_draw_stereo3d_pageflip(wmWindow *win)
        glDrawBuffer(GL_BACK);
 }
 
-static GLuint left_interlace_mask[32];
-static GLuint right_interlace_mask[32];
 static enum eStereo3dInterlaceType interlace_prev_type = -1;
 static char interlace_prev_swap = -1;
 
-static void wm_interlace_masks_create(wmWindow *win)
-{
-       GLuint pattern;
-       char i;
-       bool swap = (win->stereo3d_format->flag & S3D_INTERLACE_SWAP) != 0;
-       enum eStereo3dInterlaceType interlace_type = win->stereo3d_format->interlace_type;
-
-       if (interlace_prev_type == interlace_type && interlace_prev_swap == swap)
-               return;
-
-       switch (interlace_type) {
-               case S3D_INTERLACE_ROW:
-                       pattern = 0x00000000;
-                       pattern = swap ? ~pattern : pattern;
-                       for (i = 0; i < 32; i += 2) {
-                               left_interlace_mask[i] = pattern;
-                               right_interlace_mask[i] = ~pattern;
-                       }
-                       for (i = 1; i < 32; i += 2) {
-                               left_interlace_mask[i] = ~pattern;
-                               right_interlace_mask[i] = pattern;
-                       }
-                       break;
-               case S3D_INTERLACE_COLUMN:
-                       pattern = 0x55555555;
-                       pattern = swap ? ~pattern : pattern;
-                       for (i = 0; i < 32; i++) {
-                               left_interlace_mask[i] = pattern;
-                               right_interlace_mask[i] = ~pattern;
-                       }
-                       break;
-               case S3D_INTERLACE_CHECKERBOARD:
-               default:
-                       pattern = 0x55555555;
-                       pattern = swap ? ~pattern : pattern;
-                       for (i = 0; i < 32; i += 2) {
-                               left_interlace_mask[i] = pattern;
-                               right_interlace_mask[i] = ~pattern;
-                       }
-                       for (i = 1; i < 32; i += 2) {
-                               left_interlace_mask[i] = ~pattern;
-                               right_interlace_mask[i] = pattern;
-                       }
-                       break;
-       }
-       interlace_prev_type = interlace_type;
-       interlace_prev_swap = swap;
-}
-
 static void wm_method_draw_stereo3d_interlace(wmWindow *win)
 {
        wmDrawData *drawdata;
        int view;
-
-       wm_interlace_masks_create(win);
+       bool flag;
+       bool swap = (win->stereo3d_format->flag & S3D_INTERLACE_SWAP) != 0;
+       enum eStereo3dInterlaceType interlace_type = win->stereo3d_format->interlace_type;
 
        for (view = 0; view < 2; view ++) {
+               flag = swap ? !view : view;
                drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1);
-
-               glEnable(GL_POLYGON_STIPPLE);
-               glPolygonStipple(view ? (GLubyte *) right_interlace_mask : (GLubyte *) left_interlace_mask);
+               GPU_basic_shader_bind(GPU_SHADER_STIPPLE);
+               switch (interlace_type) {
+                       case S3D_INTERLACE_ROW:
+                               if (flag)
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW_SWAP);
+                               else
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW);
+                               break;
+                       case S3D_INTERLACE_COLUMN:
+                               if (flag)
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN_SWAP);
+                               else
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN);
+                               break;
+                       case S3D_INTERLACE_CHECKERBOARD:
+                       default:
+                               if (flag)
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER_SWAP);
+                               else
+                                       GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER);
+                               break;
+               }
 
                wm_triple_draw_textures(win, drawdata->triple, 1.0f);
-               glDisable(GL_POLYGON_STIPPLE);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
        }
+       interlace_prev_type = interlace_type;
+       interlace_prev_swap = swap;
 }
 
 static void wm_method_draw_stereo3d_anaglyph(wmWindow *win)
index 84dbfff74b00c0cb1bb4c877d0fd9be0f00aa19f..400fa6af22e7870fe7db42b1dee6dd52786893eb 100644 (file)
@@ -553,6 +553,8 @@ void RAS_OpenGLRasterizer::SetEye(const StereoEye eye)
                        break;
                case RAS_STEREO_VINTERLACE:
                {
+                       // OpenGL stippling is deprecated, it is no longer possible to affect all shaders
+                       // this way, offscreen rendering and then compositing may be the better solution
                        glEnable(GL_POLYGON_STIPPLE);
                        glPolygonStipple((const GLubyte*) ((m_curreye == RAS_STEREO_LEFTEYE) ? left_eye_vinterlace_mask : right_eye_vinterlace_mask));
                        if (m_curreye == RAS_STEREO_RIGHTEYE)