Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Thu, 9 Jun 2016 19:15:06 +0000 (05:15 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 9 Jun 2016 19:15:06 +0000 (05:15 +1000)
1  2 
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/scene.c
source/blender/editors/interface/interface_icons.c
source/blender/gpu/GPU_basic_shader.h
source/blender/gpu/intern/gpu_basic_shader.c
source/blender/gpu/shaders/gpu_shader_basic_frag.glsl

index 249e4ccd89c2fe3d5788ba19c4e2855765722a6f,392a38773e7c956c95362db02c45d6485628498a..267f7a65e008bbe7dae966fc512f81327bcced43
@@@ -464,6 -464,7 +464,6 @@@ static void cdDM_drawFacesSolid
  
                        BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors,
                                      setMaterial, false, false);
 -                      glShadeModel(GL_FLAT);
                        return;
                }
        }
        GPU_vertex_setup(dm);
        GPU_normal_setup(dm);
        GPU_triangle_setup(dm);
 -      glShadeModel(GL_SMOOTH);
        for (a = 0; a < dm->drawObject->totmaterial; a++) {
                if (!setMaterial || setMaterial(dm->drawObject->materials[a].mat_nr + 1, NULL)) {
                        GPU_buffer_draw_elements(
                }
        }
        GPU_buffers_unbind();
 -
 -      glShadeModel(GL_FLAT);
  }
  
  static void cdDM_drawFacesTex_common(
        if (mloopcol) {
                GPU_color_setup(dm, colType);
        }
 -              
 -      glShadeModel(GL_SMOOTH);
 +
        /* lastFlag = 0; */ /* UNUSED */
        for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
                GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
        }
  
        GPU_buffers_unbind();
 -      glShadeModel(GL_FLAT);
        
  }
  
@@@ -736,6 -742,9 +736,6 @@@ static void cdDM_drawMappedFaces
                        }
                }
        }
 -              
 -
 -      glShadeModel(GL_SMOOTH);
  
        tot_tri_elem = dm->drawObject->tot_triangle_point;
  
        }
  
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 -      glShadeModel(GL_FLAT);
  
        GPU_buffers_unbind();
  
@@@ -919,6 -929,8 +919,6 @@@ static void cdDM_drawMappedFacesGLSL
        matnr = -1;
        do_draw = false;
  
 -      glShadeModel(GL_SMOOTH);
 -
        if (setDrawOptions != NULL) {
                DMVertexAttribs attribs;
                DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n");
                MEM_freeN(mat_orig_to_new);
                MEM_freeN(matconv);
        }
 -      
 -      glShadeModel(GL_FLAT);
  }
  
  static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
@@@ -1189,6 -1203,8 +1189,6 @@@ static void cdDM_drawMappedFacesMat
  
        matnr = -1;
  
 -      glShadeModel(GL_SMOOTH);
 -
        memset(&attribs, 0, sizeof(attribs));
  
        glBegin(GL_TRIANGLES);
                cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal);
        }
        glEnd();
 -
 -      glShadeModel(GL_FLAT);
  }
  
  static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData)
@@@ -2642,6 -2660,9 +2642,9 @@@ void CDDM_calc_loop_normals(DerivedMes
  }
  
  /* #define DEBUG_CLNORS */
+ #ifdef DEBUG_CLNORS
+ #  include "BLI_linklist.h"
+ #endif
  
  void CDDM_calc_loop_normals_spacearr(
          DerivedMesh *dm, const bool use_split_normals, const float split_angle, MLoopNorSpaceArray *r_lnors_spacearr)
index 9615971e94072448d1df7761ea92eae653d6b768,a3393b6b9c0692ae56742b6762128a9a5c4bc99d..79d5ac2ec519e39785a090183e8a45f2bd5639bb
@@@ -285,6 -285,7 +285,6 @@@ Scene *BKE_scene_copy(Scene *sce, int t
                BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint);
                ts->imapaint.paintcursor = NULL;
                id_us_plus((ID *)ts->imapaint.stencil);
 -              ts->particle.paintcursor = NULL;
        }
        
        /* make a private copy of the avicodecdata */
@@@ -463,6 -464,8 +463,6 @@@ void BKE_scene_free(Scene *sce
  
  void BKE_scene_init(Scene *sce)
  {
 -      ParticleEditSettings *pset;
 -      int a;
        const char *colorspace_name;
        SceneRenderView *srv;
        CurveMapping *mblur_shutter_curve;
  
        sce->unit.scale_length = 1.0f;
  
 -      pset = &sce->toolsettings->particle;
 -      pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY;
 -      pset->emitterdist = 0.25f;
 -      pset->totrekey = 5;
 -      pset->totaddkey = 5;
 -      pset->brushtype = PE_BRUSH_NONE;
 -      pset->draw_step = 2;
 -      pset->fade_frames = 2;
 -      pset->selectmode = SCE_SELECT_PATH;
 -      for (a = 0; a < PE_TOT_BRUSH; a++) {
 -              pset->brush[a].strength = 0.5f;
 -              pset->brush[a].size = 50;
 -              pset->brush[a].step = 10;
 -              pset->brush[a].count = 10;
 -      }
 -      pset->brush[PE_BRUSH_CUT].strength = 1.0f;
 -
        sce->r.ffcodecdata.audio_mixrate = 48000;
        sce->r.ffcodecdata.audio_volume = 1.0f;
        sce->r.ffcodecdata.audio_bitrate = 192;
@@@ -2176,7 -2196,8 +2176,8 @@@ bool BKE_scene_use_shading_nodes_custom
  bool BKE_scene_use_world_space_shading(Scene *scene)
  {
        const RenderEngineType *type = RE_engines_find(scene->r.engine);
-       return (type && (type->flag & RE_USE_SHADING_NODES) || (scene->r.mode & R_USE_WS_SHADING));
+       return ((scene->r.mode & R_USE_WS_SHADING) ||
+               (type && (type->flag & RE_USE_SHADING_NODES)));
  }
  
  bool BKE_scene_use_spherical_stereo(Scene *scene)
index 0874979e0805d70e84cffeff7de6d8c7a2af4aaf,222b0366791dae970c29c1b2d6d48c25ed1c5152..446ac6347670120ba38b09d6643b41a63e75e2fd
@@@ -368,6 -368,7 +368,6 @@@ static void vicon_disclosure_tri_right_
        viconutil_set_point(pts[1], cx - d2, cy - d);
        viconutil_set_point(pts[2], cx + d2, cy);
  
 -      glShadeModel(GL_SMOOTH);
        glBegin(GL_TRIANGLES);
        glColor4f(0.8f, 0.8f, 0.8f, alpha);
        glVertex2iv(pts[0]);
        glColor4f(0.3f, 0.3f, 0.3f, alpha);
        glVertex2iv(pts[2]);
        glEnd();
 -      glShadeModel(GL_FLAT);
  
        glColor4f(0.0f, 0.0f, 0.0f, 1);
        viconutil_draw_lineloop_smooth(pts, 3);
@@@ -393,11 -395,13 +393,11 @@@ static void vicon_small_tri_right_draw(
  
        glColor4f(0.2f, 0.2f, 0.2f, alpha);
  
 -      glShadeModel(GL_SMOOTH);
        glBegin(GL_TRIANGLES);
        glVertex2iv(pts[0]);
        glVertex2iv(pts[1]);
        glVertex2iv(pts[2]);
        glEnd();
 -      glShadeModel(GL_FLAT);
  }
  
  static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), float alpha)
        viconutil_set_point(pts[1], cx - d, cy + d2);
        viconutil_set_point(pts[2], cx, cy - d2);
  
 -      glShadeModel(GL_SMOOTH);
        glBegin(GL_TRIANGLES);
        glColor4f(0.8f, 0.8f, 0.8f, alpha);
        glVertex2iv(pts[0]);
        glColor4f(0.3f, 0.3f, 0.3f, alpha);
        glVertex2iv(pts[2]);
        glEnd();
 -      glShadeModel(GL_FLAT);
  
        glColor4f(0.0f, 0.0f, 0.0f, 1);
        viconutil_draw_lineloop_smooth(pts, 3);
@@@ -1214,8 -1220,13 +1214,13 @@@ static void icon_draw_rect(float x, flo
                glaDrawPixelsSafe(draw_x, draw_y, draw_w, draw_h, draw_w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
        }
        else {
+               int bound_options;
+               GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
                glRasterPos2f(draw_x, draw_y);
                glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+               GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
        }
  
        if (ima)
@@@ -1557,6 -1568,8 +1562,6 @@@ int UI_idcode_icon_get(const int idcode
                        return ICON_NODETREE;
                case ID_OB:
                        return ICON_OBJECT_DATA;
 -              case ID_PA:
 -                      return ICON_PARTICLE_DATA;
                case ID_PAL:
                        return ICON_COLOR;  /* TODO! this would need its own icon! */
                case ID_PC:
index b9335ca60b6a0885afe3450251ef9d6191bc5aa4,1e2db6acc525ecb8b352d3b7ceb667b8eaf09ccf..fa53a01ff5e069cf3f0c3286f5a1cd67b4f6b46d
@@@ -46,12 -46,12 +46,13 @@@ typedef enum GPUBasicShaderOption 
        GPU_SHADER_LIGHTING =         (1 << 1),   /* use lighting */
        GPU_SHADER_TWO_SIDED =        (1 << 2),   /* flip normals towards viewer */
        GPU_SHADER_TEXTURE_2D =       (1 << 3),   /* use 2D texture to replace diffuse color */
+       GPU_SHADER_TEXTURE_RECT =     (1 << 4),   /* same as GPU_SHADER_TEXTURE_2D, for GL_TEXTURE_RECTANGLE */
  
-       GPU_SHADER_SOLID_LIGHTING =   (1 << 4),   /* use faster lighting (set automatically) */
-       GPU_SHADER_STIPPLE =          (1 << 5),   /* use stipple */
-       GPU_SHADER_LINE =             (1 << 6),   /* draw lines */
-       GPU_SHADER_FLAT_NORMAL =      (1 << 7),   /* use flat normals */
-       GPU_SHADER_OPTIONS_NUM = 8,
+       GPU_SHADER_SOLID_LIGHTING =   (1 << 5),   /* use faster lighting (set automatically) */
+       GPU_SHADER_STIPPLE =          (1 << 6),   /* use stipple */
+       GPU_SHADER_LINE =             (1 << 7),   /* draw lines */
 -      GPU_SHADER_OPTIONS_NUM = 8,
++      GPU_SHADER_FLAT_NORMAL =      (1 << 8),   /* use flat normals */
++      GPU_SHADER_OPTIONS_NUM = 9,
        GPU_SHADER_OPTION_COMBINATIONS = (1 << GPU_SHADER_OPTIONS_NUM)
  } GPUBasicShaderOption;
  
@@@ -77,6 -77,22 +78,22 @@@ void GPU_basic_shaders_exit(void)
  void GPU_basic_shader_bind(int options);
  int GPU_basic_shader_bound_options(void);
  
+ /* Only use for small blocks of code that don't support glsl shader. */
+ #define GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options) \
+ if (GPU_basic_shader_use_glsl_get()) { \
+       if ((bound_options = GPU_basic_shader_bound_options())) { \
+               GPU_basic_shader_bind(0); \
+       } \
+ } \
+ else { bound_options = 0; } ((void)0)
+ #define GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options) \
+ if (GPU_basic_shader_use_glsl_get()) { \
+       if (bound_options) { \
+               GPU_basic_shader_bind(bound_options); \
+       } \
+ } ((void)0)
  void GPU_basic_shader_colors(const float diffuse[3], const float specular[3],
        int shininess, float alpha);
  
@@@ -111,6 -127,9 +128,9 @@@ void GPU_basic_shader_stipple(GPUBasicS
  void GPU_basic_shader_line_stipple(GLint stipple_factor, GLushort stipple_pattern);
  void GPU_basic_shader_line_width(float line_width);
  
+ bool GPU_basic_shader_use_glsl_get(void);
+ void GPU_basic_shader_use_glsl_set(bool enabled);
  #ifdef __cplusplus
  }
  #endif
index aada3800ede59c9a2bee29a347c8fd7a0330e448,b0669225a4d181beb92e4a90c66cc591755b381b..cc4eafc1f6276d2687e368b39e1ac2109ecc3db6
@@@ -51,8 -51,6 +51,6 @@@
  
  /* State */
  
- static const bool USE_GLSL = false;
  static struct {
        GPUShader *cached_shaders[GPU_SHADER_OPTION_COMBINATIONS];
        bool failed_shaders[GPU_SHADER_OPTION_COMBINATIONS];
@@@ -269,6 -267,24 +267,24 @@@ const GLubyte stipple_hexagon[128] = 
        0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};
  /* ********************************************* */
  
+ /* GLSL State */
+ static bool USE_GLSL = false;
+ /**
+  * \note this isn't part of the basic shader API,
+  * only set from the command line once on startup.
+  */
+ void GPU_basic_shader_use_glsl_set(bool enabled)
+ {
+       USE_GLSL = enabled;
+ }
+ bool GPU_basic_shader_use_glsl_get(void)
+ {
+       return USE_GLSL;
+ }
  /* Init / exit */
  
  void GPU_basic_shaders_init(void)
@@@ -308,6 -324,9 +324,9 @@@ static int detect_options(
  
        if (glIsEnabled(GL_TEXTURE_2D))
                options |= GPU_SHADER_TEXTURE_2D;
+       if (glIsEnabled(GL_TEXTURE_RECTANGLE))
+               options |= GPU_SHADER_TEXTURE_RECT;
+       GPU_SHADER_TEXTURE_RECT
        if (glIsEnabled(GL_COLOR_MATERIAL))
                options |= GPU_SHADER_USE_COLOR;
  
@@@ -347,16 -366,16 +366,18 @@@ static GPUShader *gpu_basic_shader(int 
                        strcat(defines, "#define USE_COLOR\n");
                if (options & GPU_SHADER_TWO_SIDED)
                        strcat(defines, "#define USE_TWO_SIDED\n");
-               if (options & GPU_SHADER_TEXTURE_2D)
+               if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT))
                        strcat(defines, "#define USE_TEXTURE\n");
+               if (options & GPU_SHADER_TEXTURE_RECT)
+                       strcat(defines, "#define USE_TEXTURE_RECTANGLE\n");
                if (options & GPU_SHADER_STIPPLE)
                        strcat(defines, "#define USE_STIPPLE\n");
                if (options & GPU_SHADER_LINE) {
                        strcat(defines, "#define DRAW_LINE\n");
                        geom_glsl = datatoc_gpu_shader_basic_geom_glsl;
                }
 +              if (options & GPU_SHADER_FLAT_NORMAL)
 +                      strcat(defines, "#define USE_FLAT_NORMAL\n");
                if (options & GPU_SHADER_SOLID_LIGHTING)
                        strcat(defines, "#define USE_SOLID_LIGHTING\n");
                else if (options & GPU_SHADER_LIGHTING)
                
                if (shader) {
                        /* set texture map to first texture unit */
-                       if (options & GPU_SHADER_TEXTURE_2D) {
+                       if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT)) {
                                GPU_shader_bind(shader);
                                glUniform1i(GPU_shader_get_uniform(shader, "texture_map"), 0);
                                GPU_shader_unbind();
@@@ -401,6 -420,23 +422,23 @@@ void GPU_basic_shader_bind(int options
  {
        if (USE_GLSL) {
                if (options) {
+                       const int bound_options = GPU_MATERIAL_STATE.bound_options;
+                       /* texture options need to be set for basic shader too */
+                       if (options & GPU_SHADER_TEXTURE_2D) {
+                               glEnable(GL_TEXTURE_2D);
+                       }
+                       else if (bound_options & GPU_SHADER_TEXTURE_2D) {
+                               glDisable(GL_TEXTURE_2D);
+                       }
+                       if (options & GPU_SHADER_TEXTURE_RECT) {
+                               glEnable(GL_TEXTURE_RECTANGLE);
+                       }
+                       else if (bound_options & GPU_SHADER_TEXTURE_RECT) {
+                               glDisable(GL_TEXTURE_RECTANGLE);
+                       }
                        GPUShader *shader = gpu_basic_shader(options);
  
                        if (shader) {
                }
        }
        else {
-               int bound_options = GPU_MATERIAL_STATE.bound_options;
+               const int bound_options = GPU_MATERIAL_STATE.bound_options;
  
                if (options & GPU_SHADER_LIGHTING) {
                        glEnable(GL_LIGHTING);
                        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode);
                }
                else if (bound_options & GPU_SHADER_TEXTURE_2D) {
-                       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+                       if ((options & GPU_SHADER_TEXTURE_RECT) == 0) {
+                               glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+                       }
                        glDisable(GL_TEXTURE_2D);
                }
  
+               if (options & GPU_SHADER_TEXTURE_RECT) {
+                       GLint env_mode = (options & (GPU_SHADER_USE_COLOR | GPU_SHADER_LIGHTING)) ? GL_MODULATE : GL_REPLACE;
+                       glEnable(GL_TEXTURE_RECTANGLE);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode);
+               }
+               else if (bound_options & GPU_SHADER_TEXTURE_RECT) {
+                       if ((options & GPU_SHADER_TEXTURE_2D) == 0) {
+                               glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+                       }
+                       glDisable(GL_TEXTURE_RECTANGLE);
+               }
                if ((options & GPU_SHADER_LINE) && (options & GPU_SHADER_STIPPLE)) {
                        glEnable(GL_LINE_STIPPLE);
                }
                                glDisable(GL_POLYGON_STIPPLE);
                }
  
 +              if (options & GPU_SHADER_FLAT_NORMAL)
 +                      glShadeModel(GL_FLAT);
 +              else
 +                      glShadeModel(GL_SMOOTH);
 +
        }
  
        GPU_MATERIAL_STATE.bound_options = options;
index ad4182340d63153d744880cc4269be7ad5148cdc,ea5f6aef005ca229aa4dfb82513b18b2c20e90d8..01a335af0486d8ceb01897055bad0e63dac3be54
@@@ -3,6 -3,7 +3,7 @@@
   *
   * USE_COLOR: use glColor for diffuse colors
   * USE_TEXTURE: use texture for diffuse colors
+  * USE_TEXTURE_RECTANGLE: use GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D
   * USE_SCENE_LIGHTING: use lights (up to 8)
   * USE_SOLID_LIGHTING: assume 3 directional lights for solid draw mode
   * USE_TWO_SIDED: flip normal towards viewer
  #define STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP        11
  
  #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
 +#if defined(USE_FLAT_NORMAL)
 +varying vec3 eyespace_vert_pos;
 +#else
  varying vec3 varying_normal;
 -
 +#endif
  #ifndef USE_SOLID_LIGHTING
  varying vec3 varying_position;
  #endif
@@@ -42,8 -40,16 +43,16 @@@ varying vec4 varying_vertex_color
  #endif
  
  #ifdef USE_TEXTURE
+ #ifdef USE_TEXTURE_RECTANGLE
+ #define sampler2D_default sampler2DRect
+ #define texture2D_default texture2DRect
+ #else
+ #define sampler2D_default sampler2D
+ #define texture2D_default texture2D
+ #endif
  varying vec2 varying_texture_coord;
- uniform sampler2D texture_map;
+ uniform sampler2D_default texture_map;
  #endif
  
  #ifdef USE_STIPPLE
@@@ -140,11 -146,7 +149,11 @@@ void main(
  
  #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
        /* compute normal */
 +#if defined(USE_FLAT_NORMAL)
 +      vec3 N = normalize(cross(dFdx(eyespace_vert_pos), dFdy(eyespace_vert_pos)));
 +#else
        vec3 N = normalize(varying_normal);
 +#endif
  
  #ifdef USE_TWO_SIDED
        if (!gl_FrontFacing)
        float alpha;
  
  #if defined(USE_TEXTURE) && defined(USE_COLOR)
-       vec4 texture_color = texture2D(texture_map, varying_texture_coord);
+       vec4 texture_color = texture2D_default(texture_map, varying_texture_coord);
  
        L_diffuse *= texture_color.rgb * varying_vertex_color.rgb;
        alpha = texture_color.a * varying_vertex_color.a;
  #elif defined(USE_TEXTURE)
-       vec4 texture_color = texture2D(texture_map, varying_texture_coord);
+       vec4 texture_color = texture2D_default(texture_map, varying_texture_coord);
  
        L_diffuse *= texture_color.rgb;
        alpha = texture_color.a;
  
        /* no lighting */
  #if defined(USE_TEXTURE) && defined(USE_COLOR)
-       gl_FragColor = texture2D(texture_map, varying_texture_coord) * varying_vertex_color;
+       gl_FragColor = texture2D_default(texture_map, varying_texture_coord) * varying_vertex_color;
  #elif defined(USE_TEXTURE)
-       gl_FragColor = texture2D(texture_map, varying_texture_coord);
+       gl_FragColor = texture2D_default(texture_map, varying_texture_coord);
  #elif defined(USE_COLOR)
        gl_FragColor = varying_vertex_color;
  #else