Merge branch 'master' into blender2.8
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 16 Jul 2018 12:36:59 +0000 (14:36 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 16 Jul 2018 12:36:59 +0000 (14:36 +0200)
1  2 
build_files/buildbot/slave_compile.py
intern/cycles/render/image.cpp
source/blender/windowmanager/intern/wm_playanim.c

index 59b35a535aa864fd4f6bb311b0290993a41cf9cd,bf8f9f15751c82c83fad47e2cad5a2b3c68f5318..a77f237e978ddc5e799e604b33be885c8db5a882
@@@ -60,6 -60,7 +60,6 @@@ if 'cmake' in builder
  
      # Config file to be used (relative to blender's sources root)
      cmake_config_file = "build_files/cmake/config/blender_full.cmake"
 -    cmake_player_config_file = None
      cmake_cuda_config_file = None
  
      # Set build options.
@@@ -77,7 -78,7 +77,7 @@@
          # cmake_extra_options.append('-DCUDA_NVCC_EXECUTABLE=/usr/local/cuda-hack/nvcc')
  
      elif builder.startswith('win'):
-         if builder.endswith('_vc2017'):
+         if builder.endswith('_vs2017'):
              if builder.startswith('win64'):
                  cmake_options.extend(['-G', 'Visual Studio 15 2017 Win64'])
              elif builder.startswith('win32'):
          elif glibc == 'glibc211':
              deb_name = "squeeze"
          cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
 -        cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
          if builder.endswith('x86_64_cmake'):
              chroot_name = 'buildbot_' + deb_name + '_x86_64'
 -            targets = ['player', 'blender']
 +            targets = ['blender']
          elif builder.endswith('i686_cmake'):
              bits = 32
              chroot_name = 'buildbot_' + deb_name + '_i686'
 -            targets = ['player', 'blender']
 +            targets = ['blender']
          cmake_extra_options.extend(["-DCMAKE_C_COMPILER=/usr/bin/gcc-7",
                                      "-DCMAKE_CXX_COMPILER=/usr/bin/g++-7"])
  
          os.chdir(target_build_dir)
          # Tweaking CMake options to respect the target
          target_cmake_options = cmake_options[:]
 -        if target == 'player':
 -            target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
 -        elif target == 'cuda':
 +        if target == 'cuda':
              target_cmake_options += cuda_cmake_options
              target_chroot_prefix = cuda_chroot_prefix[:]
              target_name = 'cycles_kernel_cuda'
index fa280fec01ff038711d011135f8c650e144833c8,27d6ae7828925b81e1a8ead0a5e00aa8feced4da..28ef026135a4eaec53516dea8180b90c625ee0ed
@@@ -33,15 -33,15 +33,15 @@@ CCL_NAMESPACE_BEGI
  /* Some helpers to silence warning in templated function. */
  static bool isfinite(uchar /*value*/)
  {
-       return false;
+       return true;
  }
  static bool isfinite(half /*value*/)
  {
-       return false;
+       return true;
  }
  static bool isfinite(uint16_t  /*value*/)
  {
-       return false;
+       return true;
  }
  
  ImageManager::ImageManager(const DeviceInfo& info)
@@@ -508,7 -508,6 +508,6 @@@ bool ImageManager::file_load_image(Imag
                                     int texture_limit,
                                     device_vector<DeviceType>& tex_img)
  {
-       const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
        ImageInput *in = NULL;
        if(!file_load_image_generic(img, &in)) {
                return false;
                        type == IMAGE_DATA_TYPE_BYTE4 ||
                                        type == IMAGE_DATA_TYPE_USHORT4);
        if(is_rgba) {
+               const StorageType one = util_image_cast_from_float<StorageType>(1.0f);
                if(cmyk) {
                        /* CMYK */
                        for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
-                               pixels[i*4+2] = (pixels[i*4+2]*pixels[i*4+3])/255;
-                               pixels[i*4+1] = (pixels[i*4+1]*pixels[i*4+3])/255;
-                               pixels[i*4+0] = (pixels[i*4+0]*pixels[i*4+3])/255;
-                               pixels[i*4+3] = alpha_one;
+                               float c = util_image_cast_to_float(pixels[i*4+0]);
+                               float m = util_image_cast_to_float(pixels[i*4+1]);
+                               float y = util_image_cast_to_float(pixels[i*4+2]);
+                               float k = util_image_cast_to_float(pixels[i*4+3]);
+                               pixels[i*4+0] = util_image_cast_from_float<StorageType>((1.0f - c) * (1.0f - k));
+                               pixels[i*4+1] = util_image_cast_from_float<StorageType>((1.0f - m) * (1.0f - k));
+                               pixels[i*4+2] = util_image_cast_from_float<StorageType>((1.0f - y) * (1.0f - k));
+                               pixels[i*4+3] = one;
                        }
                }
                else if(components == 2) {
                else if(components == 3) {
                        /* RGB */
                        for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
-                               pixels[i*4+3] = alpha_one;
+                               pixels[i*4+3] = one;
                                pixels[i*4+2] = pixels[i*3+2];
                                pixels[i*4+1] = pixels[i*3+1];
                                pixels[i*4+0] = pixels[i*3+0];
                else if(components == 1) {
                        /* grayscale */
                        for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
-                               pixels[i*4+3] = alpha_one;
+                               pixels[i*4+3] = one;
                                pixels[i*4+2] = pixels[i];
                                pixels[i*4+1] = pixels[i];
                                pixels[i*4+0] = pixels[i];
                }
                if(img->use_alpha == false) {
                        for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
-                               pixels[i*4+3] = alpha_one;
+                               pixels[i*4+3] = one;
                        }
                }
        }
@@@ -871,7 -876,7 +876,7 @@@ void ImageManager::device_load_image(De
                        thread_scoped_lock device_lock(device_mutex);
                        uint16_t *pixels = (uint16_t*)tex_img->alloc(1, 1);
  
-                       pixels[0] = TEX_IMAGE_MISSING_R;
+                       pixels[0] = (TEX_IMAGE_MISSING_R * 65535);
                }
  
                img->mem = tex_img;
                        thread_scoped_lock device_lock(device_mutex);
                        uint16_t *pixels = (uint16_t*)tex_img->alloc(1, 1);
  
-                       pixels[0] = TEX_IMAGE_MISSING_R;
-                       pixels[1] = TEX_IMAGE_MISSING_G;
-                       pixels[2] = TEX_IMAGE_MISSING_B;
-                       pixels[3] = TEX_IMAGE_MISSING_A;
+                       pixels[0] = (TEX_IMAGE_MISSING_R * 65535);
+                       pixels[1] = (TEX_IMAGE_MISSING_G * 65535);
+                       pixels[2] = (TEX_IMAGE_MISSING_B * 65535);
+                       pixels[3] = (TEX_IMAGE_MISSING_A * 65535);
                }
  
                img->mem = tex_img;
@@@ -1013,39 -1018,6 +1018,39 @@@ void ImageManager::device_update_slot(D
        }
  }
  
 +void ImageManager::device_load_builtin(Device *device,
 +                                       Scene *scene,
 +                                       Progress& progress)
 +{
 +      /* Load only builtin images, Blender needs this to load evaluated
 +       * scene data from depsgraph before it is freed. */
 +      if(!need_update) {
 +              return;
 +      }
 +
 +      TaskPool pool;
 +      for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
 +              for(size_t slot = 0; slot < images[type].size(); slot++) {
 +                      if(!images[type][slot])
 +                              continue;
 +
 +                      if(images[type][slot]->need_load) {
 +                              if(images[type][slot]->builtin_data) {
 +                                      pool.push(function_bind(&ImageManager::device_load_image,
 +                                                              this,
 +                                                              device,
 +                                                              scene,
 +                                                              (ImageDataType)type,
 +                                                              slot,
 +                                                              &progress));
 +                              }
 +                      }
 +              }
 +      }
 +
 +      pool.wait_work();
 +}
 +
  void ImageManager::device_free_builtin(Device *device)
  {
        for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
index 7ddc87a2524b3db5d456da010d3a59140eac93a6,f2c24858e170951fa525ab7d9d92fb4a13a2f391..d1a7f4ffea1214fd50a8915bbdb97c1cf46c6f54
  /** \file blender/windowmanager/intern/wm_playanim.c
   *  \ingroup wm
   *
+  * Animation player for image sequences & video's with sound support.
+  * Launched in a separate process from Blender's #RENDER_OT_play_rendered_anim
+  *
   * \note This file uses ghost directly and none of the WM definitions.
-  *       this could be made into its own module, alongside creator/
+  * this could be made into its own module, alongside creator.
   */
  
  #include <sys/types.h>
  #include "IMB_imbuf_types.h"
  #include "IMB_imbuf.h"
  
 -#include "BKE_depsgraph.h"
  #include "BKE_image.h"
  
  #include "BIF_gl.h"
  #include "BIF_glutil.h"
  
 +#include "GPU_matrix.h"
 +#include "GPU_immediate.h"
 +#include "GPU_immediate_util.h"
 +#include "GPU_batch.h"
 +#include "GPU_init_exit.h"
 +
  #include "DNA_scene_types.h"
  #include "ED_datafiles.h" /* for fonts */
  #include "GHOST_C-api.h"
  #include "BLF_api.h"
  
 +#include "DEG_depsgraph.h"
 +
  #include "WM_api.h"  /* only for WM_main_playanim */
  
  #ifdef WITH_AUDASPACE
 -#  include AUD_DEVICE_H
 -#  include AUD_HANDLE_H
 -#  include AUD_SOUND_H
 -#  include AUD_SPECIAL_H
 +#  include <AUD_Device.h>
 +#  include <AUD_Handle.h>
 +#  include <AUD_Sound.h>
 +#  include <AUD_Special.h>
  
  static AUD_Sound *source = NULL;
  static AUD_Handle *playback_handle = NULL;
@@@ -184,7 -180,6 +187,7 @@@ typedef enum eWS_Qual 
  static struct WindowStateGlobal {
        GHOST_SystemHandle ghost_system;
        void *ghost_window;
 +      Gwn_Context *gwn_context;
  
        /* events */
        eWS_Qual qual;
@@@ -201,8 -196,10 +204,8 @@@ static void playanim_window_get_size(in
  static void playanim_gl_matrix(void)
  {
        /* unified matrix, note it affects offset for drawing */
 -      glMatrixMode(GL_PROJECTION);
 -      glLoadIdentity();
 -      glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
 -      glMatrixMode(GL_MODELVIEW);
 +      /* note! cannot use GPU_matrix_ortho_2d_set here because shader ignores. */
 +      GPU_matrix_ortho_set(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f);
  }
  
  /* implementation */
@@@ -317,6 -314,7 +320,6 @@@ static void playanim_toscreen(PlayStat
  
        CLAMP(offs_x, 0.0f, 1.0f);
        CLAMP(offs_y, 0.0f, 1.0f);
 -      glRasterPos2f(offs_x, offs_y);
  
        glClearColor(0.1, 0.1, 0.1, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        /* checkerboard for case alpha */
        if (ibuf->planes == 32) {
                glEnable(GL_BLEND);
 -              glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 +              glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  
 -              fdrawcheckerboard(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
 +              imm_draw_box_checker_2d(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
        }
  
 -      glRasterPos2f(offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
 -                    offs_y + (ps->draw_flip[1] ? span_y : 0.0f));
 +      IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
  
 -      glPixelZoom(ps->zoom * (ps->draw_flip[0] ? -1.0f : 1.0f),
 -                  ps->zoom * (ps->draw_flip[1] ? -1.0f : 1.0f));
 -
 -      glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
 +      immDrawPixelsTex(
 +              &state,
 +              offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
 +              offs_y + (ps->draw_flip[1] ? span_y : 0.0f),
 +              ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
 +              ibuf->rect,
 +              ((ps->draw_flip[0] ? -1.0f : 1.0f)) * (ps->zoom / (float)ps->win_x),
 +              ((ps->draw_flip[1] ? -1.0f : 1.0f)) * (ps->zoom / (float)ps->win_y),
 +              NULL);
  
        glDisable(GL_BLEND);
  
                int sizex, sizey;
                float fsizex_inv, fsizey_inv;
                char str[32 + FILE_MAX];
 -              cpack(-1);
                BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime);
  
                playanim_window_get_size(&sizex, &sizey);
                fsizex_inv = 1.0f / sizex;
                fsizey_inv = 1.0f / sizey;
  
 +              BLF_color4f(fontid, 1.0, 1.0, 1.0, 1.0);
                BLF_enable(fontid, BLF_ASPECT);
                BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f);
                BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f);
                float fac = ps->picture->frame / (double)(((PlayAnimPict *)picsbase.last)->frame - ((PlayAnimPict *)picsbase.first)->frame);
  
                fac = 2.0f * fac - 1.0f;
 -              glMatrixMode(GL_PROJECTION);
 -              glPushMatrix();
 -              glLoadIdentity();
 -              glMatrixMode(GL_MODELVIEW);
 -              glPushMatrix();
 -              glLoadIdentity();
 -
 -              glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
 -
 -              glBegin(GL_LINES);
 -              glVertex2f(fac, -1.0f);
 -              glVertex2f(fac, 1.0f);
 -              glEnd();
 -
 -              glPopMatrix();
 -              glMatrixMode(GL_PROJECTION);
 -              glPopMatrix();
 -              glMatrixMode(GL_MODELVIEW);
 +              GPU_matrix_push_projection();
 +              GPU_matrix_identity_projection_set();
 +              GPU_matrix_push();
 +              GPU_matrix_identity_set();
 +
 +              uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
 +
 +              immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 +              immUniformColor3ub(0, 255, 0);
 +
 +              immBegin(GWN_PRIM_LINES, 2);
 +              immVertex2f(pos, fac, -1.0f);
 +              immVertex2f(pos, fac,  1.0f);
 +              immEnd();
 +
 +              immUnbindProgram();
 +
 +              GPU_matrix_pop();
 +              GPU_matrix_pop_projection();
        }
  
        GHOST_SwapWindowBuffers(g_WS.ghost_window);
@@@ -1280,11 -1273,6 +1283,11 @@@ static char *wm_main_playanim_intern(in
  
        //GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
  
 +      /* initialize OpenGL immediate mode */
 +      g_WS.gwn_context =  GWN_context_create();
 +      GPU_init();
 +      immActivate();
 +
        /* initialize the font */
        BLF_init();
        ps.fontid = BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
        /* we still miss freeing a lot!,
         * but many areas could skip initialization too for anim play */
  
 +      GPU_shader_free_builtin_shaders();
 +
 +      if (g_WS.gwn_context) {
 +              GWN_context_active_set(g_WS.gwn_context);
 +              GWN_context_discard(g_WS.gwn_context);
 +              g_WS.gwn_context = NULL;
 +      }
 +
        BLF_exit();
  
 +      immDeactivate();
 +      GPU_exit();
 +
        GHOST_DisposeWindow(g_WS.ghost_system, g_WS.ghost_window);
  
        /* early exit, IMB and BKE should be exited only in end */
  
        IMB_exit();
        BKE_images_exit();
 -      DAG_exit();
 +      DEG_free_node_types();
  
        totblock = MEM_get_memory_blocks_in_use();
        if (totblock != 0) {