Merging r46062 through r46073 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 29 Apr 2012 14:10:13 +0000 (14:10 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 29 Apr 2012 14:10:13 +0000 (14:10 +0000)
1  2 
source/blender/editors/include/ED_clip.h
source/blender/editors/space_clip/clip_editor.c
source/blender/editors/space_clip/clip_graph_ops.c
source/blender/editors/space_clip/space_clip.c

index dd306d38765b8652aa6519060341b6533b3324f7,dfd0f258fc08300831bbbf77782c12b9269a8f67..24d9fd3a297b4eaedca930bf7841548dfa017321
@@@ -42,8 -41,11 +42,11 @@@ struct wmEvent
  
  /* clip_editor.c */
  int ED_space_clip_poll(struct bContext *C);
+ int ED_space_clip_tracking_poll(struct bContext *C);
+ int ED_space_clip_tracking_size_poll(struct bContext *C);
+ int ED_space_clip_tracking_frame_poll(struct bContext *C);
  
 -void ED_space_clip_set(struct bContext *C, struct SpaceClip *sc, struct MovieClip *clip);
 +void ED_space_clip_set(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip);
  struct MovieClip *ED_space_clip(struct SpaceClip *sc);
  void ED_space_clip_size(struct SpaceClip *sc, int *width, int *height);
  void ED_space_clip_zoom(struct SpaceClip *sc, ARegion *ar, float *zoomx, float *zoomy);
@@@ -59,11 -61,8 +62,13 @@@ void ED_clip_point_undistorted_pos(Spac
  void ED_clip_point_stable_pos(struct bContext *C, float x, float y, float *xr, float *yr);
  void ED_clip_mouse_pos(struct bContext *C, struct wmEvent *event, float co[2]);
  
 +int ED_space_clip_texture_buffer_supported(struct SpaceClip *sc);
 +int ED_space_clip_load_movieclip_buffer(struct SpaceClip *sc, struct ImBuf *ibuf);
 +void ED_space_clip_unload_movieclip_buffer(struct SpaceClip *sc);
 +void ED_space_clip_free_texture_buffer(struct SpaceClip *sc);
 +
+ int ED_space_clip_show_trackedit(struct SpaceClip *sc);
  /* clip_ops.c */
  void ED_operatormacros_clip(void);
  
index 099c3c7532c555f691b89552e27d2ceb91e54aa5,885357a100d9c5ac98435467c0318a88a8bbba1f..69a8b0f4c92423efee63f99ff2e9f3a7b1648340
@@@ -70,14 -68,53 +73,59 @@@ int ED_space_clip_poll(bContext *C
        return FALSE;
  }
  
 -void ED_space_clip_set(bContext *C, SpaceClip *sc, MovieClip *clip)
+ int ED_space_clip_tracking_poll(bContext *C)
+ {
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       if (sc && sc->clip)
+               return ED_space_clip_show_trackedit(sc);
+       return FALSE;
+ }
+ int ED_space_clip_tracking_size_poll(bContext *C)
+ {
+       if (ED_space_clip_tracking_poll(C)) {
+               MovieClip *clip = CTX_data_edit_movieclip(C);
+               if (clip) {
+                       SpaceClip *sc = CTX_wm_space_clip(C);
+                       int width, height;
+                       BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+                       return width > 0 && height > 0;
+               }
+       }
+       return FALSE;
+ }
+ int ED_space_clip_tracking_frame_poll(bContext *C)
+ {
+       if (ED_space_clip_tracking_poll(C)) {
+               MovieClip *clip = CTX_data_edit_movieclip(C);
+               if (clip) {
+                       SpaceClip *sc = CTX_wm_space_clip(C);
+                       return BKE_movieclip_has_frame(clip, &sc->user);
+               }
+       }
+       return FALSE;
+ }
+ /* ******** editing functions ******** */
 +void ED_space_clip_set(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
  {
 +      MovieClip *old_clip;
 +
 +      if (!screen && C)
 +              screen = CTX_wm_screen(C);
 +
 +      old_clip = sc->clip;
        sc->clip = clip;
  
        if (sc->clip && sc->clip->id.us==0)
@@@ -345,166 -363,11 +393,175 @@@ void ED_clip_mouse_pos(bContext *C, wmE
        ED_clip_point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]);
  }
  
 +/* OpenGL draw context */
 +
 +typedef struct SpaceClipDrawContext {
 +      int support_checked, buffers_supported;
 +
 +      GLuint texture;                 /* OGL texture ID */
 +      short texture_allocated;        /* flag if texture was allocated by glGenTextures */
 +      struct ImBuf *texture_ibuf;     /* image buffer for which texture was created */
 +      int image_width, image_height;  /* image width and height for which texture was created */
 +      unsigned last_texture;          /* ID of previously used texture, so it'll be restored after clip drawing */
 +      int framenr;
 +} SpaceClipDrawContext;
 +
 +int ED_space_clip_texture_buffer_supported(SpaceClip *sc)
 +{
 +      SpaceClipDrawContext *context = sc->draw_context;
 +
 +      if (!context) {
 +              context = MEM_callocN(sizeof(SpaceClipDrawContext), "SpaceClipDrawContext");
 +              sc->draw_context = context;
 +      }
 +
 +      if (!context->support_checked) {
 +              context->support_checked = TRUE;
 +              context->buffers_supported = GPU_non_power_of_two_support();
 +      }
 +
 +      return context->buffers_supported;
 +}
 +
 +int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf)
 +{
 +      SpaceClipDrawContext *context = sc->draw_context;
 +      MovieClip *clip = ED_space_clip(sc);
 +      int need_rebind = 0;
 +
 +      context->last_texture = glaGetOneInteger(GL_TEXTURE_2D);
 +
 +      /* image texture need to be rebinded if displaying another image buffer
 +       * assuming displaying happens of footage frames only on which painting doesn't heppen.
 +       * so not changed image buffer pointer means unchanged image content */
 +      need_rebind |= context->texture_ibuf != ibuf;
 +      need_rebind |= context->framenr != sc->user.framenr;
 +
 +      if (need_rebind) {
 +              int width = ibuf->x, height = ibuf->y;
 +              float *frect = NULL, *fscalerect = NULL;
 +              unsigned int *rect = NULL, *scalerect = NULL;
 +              int need_recreate = 0;
 +
 +              if (width > GL_MAX_TEXTURE_SIZE || height > GL_MAX_TEXTURE_SIZE)
 +                      return 0;
 +
 +              rect = ibuf->rect;
 +              frect = ibuf->rect_float;
 +
 +              /* if image resolution changed (e.g. switched to proxy display) texture need to be recreated */
 +              need_recreate = context->image_width != ibuf->x || context->image_height != ibuf->y;
 +
 +              if (context->texture_ibuf && need_recreate) {
 +                      glDeleteTextures(1, &context->texture);
 +                      context->texture_allocated = 0;
 +              }
 +
 +#if 0
 +              /* disabled for now because current tracking users have got NPOT textures
 +               * working smoothly on their computers and forcing re-scaling during playback
 +               * slows down playback a lot */
 +
 +              /* if videocard doesn't support NPOT textures, need to do rescaling */
 +              if (!GPU_non_power_of_two_support()) {
 +                      if (!is_power_of_2_i(width) || !is_power_of_2_i(height)) {
 +                              width = power_of_2_max_i(width);
 +                              height = power_of_2_max_i(height);
 +
 +                              if (ibuf->x != width || ibuf->y != height) {
 +                                      if (frect) {
 +                                              fscalerect= MEM_mallocN(width*width*sizeof(*fscalerect)*4, "fscalerect");
 +                                              gluScaleImage(GL_RGBA, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float, width, height, GL_FLOAT, fscalerect);
 +
 +                                              frect = fscalerect;
 +                                      }
 +                                      else {
 +                                              scalerect= MEM_mallocN(width*height*sizeof(*scalerect), "scalerect");
 +                                              gluScaleImage(GL_RGBA, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect, width, height, GL_UNSIGNED_BYTE, scalerect);
 +
 +                                              rect = scalerect;
 +                                      }
 +                              }
 +                      }
 +              }
 +#endif
 +
 +              if (need_recreate || !context->texture_allocated) {
 +                      /* texture doesn't exist yet or need to be re-allocated because of changed dimensions */
 +                      int filter = GL_LINEAR;
 +
 +                      /* non-scaled proxy shouldn;t use diltering */
 +                      if ((clip->flag & MCLIP_USE_PROXY) == 0 ||
 +                          ELEM(sc->user.render_size, MCLIP_PROXY_RENDER_SIZE_FULL, MCLIP_PROXY_RENDER_SIZE_100))
 +                      {
 +                              filter = GL_NEAREST;
 +                      }
 +
 +                      glGenTextures(1, &context->texture);
 +                      glBindTexture(GL_TEXTURE_2D, context->texture);
 +                      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
 +                      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
 +                      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 +                      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 +              }
 +              else {
 +                      /* if texture doesn't need to be reallocated itself, just bind it so
 +                       * loading of image will happen to a proper texture */
 +                      glBindTexture(GL_TEXTURE_2D, context->texture);
 +              }
 +
 +              if (frect)
 +                      glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA16,  width, height, 0, GL_RGBA, GL_FLOAT, frect);
 +              else
 +                      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 +
 +              /* store settings */
 +              context->texture_allocated = 1;
 +              context->texture_ibuf = ibuf;
 +              context->image_width = ibuf->x;
 +              context->image_height = ibuf->y;
 +              context->framenr = sc->user.framenr;
 +
 +              if (fscalerect)
 +                      MEM_freeN(fscalerect);
 +              if (scalerect)
 +                      MEM_freeN(scalerect);
 +      }
 +      else {
 +              /* displaying exactly the same image which was loaded t oa texture,
 +               * just bint texture in this case */
 +              glBindTexture(GL_TEXTURE_2D, context->texture);
 +      }
 +
 +      glEnable(GL_TEXTURE_2D);
 +
 +      return 1;
 +}
 +
 +void ED_space_clip_unload_movieclip_buffer(SpaceClip *sc)
 +{
 +      SpaceClipDrawContext *context = sc->draw_context;
 +
 +      glBindTexture(GL_TEXTURE_2D, context->last_texture);
 +      glDisable(GL_TEXTURE_2D);
 +}
 +
 +void ED_space_clip_free_texture_buffer(SpaceClip *sc)
 +{
 +      SpaceClipDrawContext *context = sc->draw_context;
 +
 +      if (context) {
 +              glDeleteTextures(1, &context->texture);
 +
 +              MEM_freeN(context);
 +      }
 +}
++
+ int ED_space_clip_show_trackedit(SpaceClip *sc)
+ {
+       if (sc) {
+               return ELEM3(sc->mode, SC_MODE_TRACKING, SC_MODE_RECONSTRUCTION, SC_MODE_DISTORTION);
+       }
+       return FALSE;
+ }
index 113c11995d1444a451f55addb2d3136cee0dcede,7916a96f98c709dfc2dfa47cc00028d94551c965..7ab41078e16d42500bf0d7ea9d41a5e2ab05830f
  
  static int ED_space_clip_graph_poll(bContext *C)
  {
-       SpaceClip *sc = CTX_wm_space_clip(C);
+       if (ED_space_clip_tracking_poll(C)) {
 -              ARegion *ar = CTX_wm_region(C);
++              SpaceClip *sc = CTX_wm_space_clip(C);
  
-       if (sc && sc->clip) {
 -              return ar->regiontype == RGN_TYPE_PREVIEW;
 +              if (sc->view == SC_VIEW_GRAPH) {
 +                      ARegion *ar = CTX_wm_region(C);
 +
 +                      return ar->regiontype == RGN_TYPE_PREVIEW;
 +              }
        }
  
        return FALSE;