From 700c40e2f9b59b7e780429fdc10fb0d2d5d117a1 Mon Sep 17 00:00:00 2001 From: Alexander Romanov Date: Fri, 25 Dec 2015 22:57:50 +0100 Subject: OpenGL: stipple support added to basic GLSL shader 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 --- source/blender/blenkernel/intern/cdderivedmesh.c | 9 +- source/blender/blenkernel/intern/editderivedmesh.c | 15 +- source/blender/blenkernel/intern/subsurf_ccg.c | 9 +- source/blender/editors/interface/interface_draw.c | 9 +- .../blender/editors/interface/interface_widgets.c | 8 +- source/blender/editors/screen/glutil.c | 95 +------- .../editors/space_sequencer/sequencer_draw.c | 26 +-- source/blender/editors/uvedit/uvedit_draw.c | 14 +- source/blender/gpu/GPU_basic_shader.h | 20 +- source/blender/gpu/intern/gpu_basic_shader.c | 260 +++++++++++++++++++++ source/blender/gpu/intern/gpu_draw.c | 13 -- .../blender/gpu/shaders/gpu_shader_basic_frag.glsl | 96 ++++++++ source/blender/windowmanager/intern/wm_stereo.c | 87 +++---- .../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 #include -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< 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) -- cgit v1.2.3