diff options
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 9 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 9 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 8 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 95 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_draw.c | 26 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_draw.c | 14 | ||||
-rw-r--r-- | source/blender/gpu/GPU_basic_shader.h | 20 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_basic_shader.c | 260 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 13 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_basic_frag.glsl | 96 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_stereo.c | 87 | ||||
-rw-r--r-- | source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 2 |
14 files changed, 457 insertions, 206 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 836072df67d..632403c5e25 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -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; diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index dc50e39a862..642a89df8e0 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -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); } } } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 53da38b2da8..f16ef3df6be 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -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); } } } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index ae2e6744160..a3adf65cd84 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -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); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index da348c88650..279572f82d1 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -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); diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 91eea6f8248..cbb6b7685af 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -56,95 +56,6 @@ #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) diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index deb0a3f6d03..393e7292d64 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -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); diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index f4eed3e1fda..34f59b56fff 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -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); } } diff --git a/source/blender/gpu/GPU_basic_shader.h b/source/blender/gpu/GPU_basic_shader.h index 3298f0f35b4..f964e056d44 100644 --- a/source/blender/gpu/GPU_basic_shader.h +++ b/source/blender/gpu/GPU_basic_shader.h @@ -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 } diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c index c441a44c17b..c01d5321fe3 100644 --- a/source/blender/gpu/intern/gpu_basic_shader.c +++ b/source/blender/gpu/intern/gpu_basic_shader.c @@ -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; + } + } +} diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 27e428d7f69..92195bdf779 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -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(); diff --git a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl index 94c73d9e248..7b4df51c12d 100644 --- a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl @@ -12,6 +12,20 @@ #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); diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index 21fc7f2b5b2..5576a104123 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -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) diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 84dbfff74b0..400fa6af22e 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -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) |