Cycles: svn merge -r39669:39870 https://svn.blender.org/svnroot/bf-blender/trunk...
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 2 Sep 2011 12:33:29 +0000 (12:33 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 2 Sep 2011 12:33:29 +0000 (12:33 +0000)
53 files changed:
1  2 
CMakeLists.txt
release/scripts/startup/bl_ui/properties_texture.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/anim_sys.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/interface/interface_icons.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/object/object_add.c
source/blender/editors/render/render_preview.c
source/blender/editors/render/render_shading.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/space_buttons/buttons_context.c
source/blender/editors/space_buttons/space_buttons.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/gpu/intern/gpu_draw.c
source/blender/gpu/intern/gpu_material.c
source/blender/imbuf/CMakeLists.txt
source/blender/imbuf/intern/util.c
source/blender/imbuf/intern/writeimage.c
source/blender/makesdna/DNA_ID.h
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_texture.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blenderplayer/bad_level_call_stubs/stubs.c
source/gameengine/Ketsji/BL_BlenderShader.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp

diff --cc CMakeLists.txt
Simple merge
@@@ -681,9 -650,8 +683,9 @@@ void buttons_context_compute(const bCon
  
  const char *buttons_context_dir[] = {
        "world", "object", "mesh", "armature", "lattice", "curve",
-       "meta_ball", "lamp", "camera", "material", "material_slot",
+       "meta_ball", "lamp", "speaker", "camera", "material", "material_slot",
 -      "texture", "texture_slot", "bone", "edit_bone", "pose_bone", "particle_system", "particle_system_editable",
 +      "texture", "texture_slot", "texture_user", "bone", "edit_bone",
 +      "pose_bone", "particle_system", "particle_system_editable",
        "cloth", "soft_body", "fluid", "smoke", "collision", "brush", NULL};
  
  int buttons_context(const bContext *C, const char *member, bContextDataResult *result)
@@@ -646,167 -640,3 +646,167 @@@ void draw_mesh_textured_old(Scene *scen
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  }
  
-                       ob->data, useColors, GPU_enable_material);
 +/************************** NEW SHADING SYSTEM ********************************/
 +
 +typedef struct TexMatCallback {
 +      Scene *scene;
 +      Object *ob;
 +      Mesh *me;
 +      DerivedMesh *dm;
 +} TexMatCallback;
 +
 +static void tex_mat_set_material_cb(void *UNUSED(userData), int mat_nr, void *attribs)
 +{
 +      /* all we have to do here is simply enable the GLSL material, but note
 +         that the GLSL code will give different result depending on the drawtype,
 +         in texture draw mode it will output the active texture node, in material
 +         draw mode it will show the full material. */
 +      GPU_enable_material(mat_nr, attribs);
 +}
 +
 +static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
 +{
 +      /* texture draw mode without GLSL */
 +      TexMatCallback *data= (TexMatCallback*)userData;
 +      GPUVertexAttribs *gattribs = attribs;
 +      Image *ima;
 +      ImageUser *iuser;
 +      int texture_set= 0;
 +
 +      /* draw image texture if we find one */
 +      if(ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser)) {
 +              /* get openl texture */
 +              int mipmap= 1;
 +              int bindcode= (ima)? GPU_verify_image(ima, iuser, 0, 0, mipmap): 0;
 +              float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 +
 +              if(bindcode) {
 +                      /* disable existing material */
 +                      GPU_disable_material();
 +                      glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, zero);
 +                      glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero);
 +                      glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
 +
 +                      /* bind texture */
 +                      glEnable(GL_COLOR_MATERIAL);
 +                      glEnable(GL_TEXTURE_2D);
 +
 +                      glBindTexture(GL_TEXTURE_2D, ima->bindcode);
 +                      glColor3f(1.0f, 1.0f, 1.0f);
 +
 +                      /* use active UV texture layer */
 +                      memset(gattribs, 0, sizeof(*gattribs));
 +
 +                      gattribs->layer[0].type= CD_MTFACE;
 +                      gattribs->layer[0].name[0]= '\0';
 +                      gattribs->layer[0].gltexco= 1;
 +                      gattribs->totlayer= 1;
 +
 +                      texture_set= 1;
 +              }
 +      }
 +
 +      if(!texture_set) {
 +              /* disable texture */
 +              glDisable(GL_TEXTURE_2D);
 +              glDisable(GL_COLOR_MATERIAL);
 +
 +              /* draw single color */
 +              GPU_enable_material(mat_nr, attribs);
 +      }
 +}
 +
 +static int tex_mat_set_face_mesh_cb(void *userData, int index)
 +{
 +      /* faceselect mode face hiding */
 +      TexMatCallback *data= (TexMatCallback*)userData;
 +      Mesh *me = (Mesh*)data->me;
 +      MFace *mface = &me->mface[index];
 +
 +      return !(mface->flag & ME_HIDE);
 +}
 +
 +static int tex_mat_set_face_editmesh_cb(void *UNUSED(userData), int index)
 +{
 +      /* editmode face hiding */
 +      EditFace *efa= EM_get_face_for_index(index);
 +
 +      return !(efa->h);
 +}
 +
 +void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int faceselect)
 +{
 +      if(!scene_use_new_shading_system(scene)) {
 +              draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, faceselect);
 +              return;
 +      }
 +
 +      /* set opengl state for negative scale & color */
 +      if(ob->transflag & OB_NEG_SCALE) glFrontFace(GL_CW);
 +      else glFrontFace(GL_CCW);
 +
 +      glEnable(GL_LIGHTING);
 +
 +      if(ob->mode & OB_MODE_WEIGHT_PAINT) {
 +              /* weight paint mode exception */
 +              int useColors= 1;
 +
 +              dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions,
++                      ob->data, useColors, GPU_enable_material, NULL);
 +      }
 +      else {
 +              Mesh *me= ob->data;
 +              TexMatCallback data = {scene, ob, me, dm};
 +              int (*set_face_cb)(void*, int);
 +              int glsl;
 +              
 +              /* face hiding callback depending on mode */
 +              if(ob == scene->obedit)
 +                      set_face_cb= tex_mat_set_face_editmesh_cb;
 +              else if(faceselect)
 +                      set_face_cb= tex_mat_set_face_mesh_cb;
 +              else
 +                      set_face_cb= NULL;
 +
 +              /* test if we can use glsl */
 +              glsl= GPU_glsl_support();
 +
 +              if(v3d->drawtype == OB_TEXTURE)
 +                      glsl= (scene->gm.matmode == GAME_MAT_GLSL);
 +
 +              GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
 +
 +              if(glsl) {
 +                      /* draw glsl */
 +                      dm->drawMappedFacesMat(dm,
 +                              tex_mat_set_material_cb,
 +                              set_face_cb, &data);
 +              }
 +              else {
 +                      float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 +
 +                      /* draw textured */
 +                      glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, zero);
 +                      glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero);
 +                      glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
 +
 +                      dm->drawMappedFacesMat(dm,
 +                              tex_mat_set_texture_cb,
 +                              set_face_cb, &data);
 +              }
 +
 +              GPU_end_object_materials();
 +      }
 +
 +      /* reset opengl state */
 +      glDisable(GL_COLOR_MATERIAL);
 +      glDisable(GL_TEXTURE_2D);
 +      glDisable(GL_LIGHTING);
 +      glBindTexture(GL_TEXTURE_2D, 0);
 +      glFrontFace(GL_CCW);
 +
 +      /* faceselect mode drawing over textured mesh */
 +      if(!(ob == scene->obedit) && faceselect)
 +              draw_mesh_face_select(rv3d, ob->data, dm);
 +}
 +
@@@ -2155,7 -2152,8 +2153,7 @@@ static void gpu_update_lamps_shadows(Sc
                
                v3d->drawtype = OB_SOLID;
                v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
-               v3d->flag2 |= V3D_RENDER_OVERRIDE;
 -              v3d->flag2 &= ~V3D_SOLID_TEX;
+               v3d->flag2 |= V3D_RENDER_OVERRIDE | V3D_RENDER_SHADOW;
                
                GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
  
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -246,9 -244,10 +246,10 @@@ typedef struct View3D 
  
  /* View3d->flag2 (short) */
  #define V3D_RENDER_OVERRIDE           4
 -#define V3D_SOLID_TEX                 8
 +#define V3D_SOLID_TEX                 8       /* deprecated */
  #define V3D_DISPGP                            16
  #define V3D_LOCK_CAMERA                       32
+ #define V3D_RENDER_SHADOW             64 /* This is a runtime only flag that's used to tell draw_mesh_object() that we're doing a shadow pass instead of a regular draw */
  
  /* View3D->around */
  #define V3D_CENTER             0
Simple merge
@@@ -63,7 -64,7 +64,8 @@@
  #include "BKE_particle.h"
  #include "BKE_font.h"
  #include "BKE_node.h"
 +#include "BKE_depsgraph.h"
+ #include "BKE_speaker.h"
  
  #include "DNA_armature_types.h"
  #include "DNA_camera_types.h"
@@@ -43,10 -44,14 +43,11 @@@ struct Main
  struct NodeBlurData;
  struct Object;
  struct RenderData;
 -struct RenderEngine;
 -struct RenderEngineType;
  struct RenderResult;
  struct ReportList;
 -struct ReportList;
  struct Scene;
  struct SceneRenderLayer;
+ struct EnvMap;
  
  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  /* this include is what is exposed of render to outside world */
@@@ -1015,10 -1018,18 +1029,18 @@@ static int read_render_result(Render *r
        render_unique_exr_name(re, str, sample);
        printf("read exr tmp file: %s\n", str);
  
-       if(!read_render_result_from_file(str, re->result, 0))
 -      if(read_render_result_from_file(str, re->result)) {
++      if(read_render_result_from_file(str, re->result, 0)) {
+               success= TRUE;
+       }
+       else {
                printf("cannot read: %s\n", str);
+               success= FALSE;
+       }
  
        BLI_rw_mutex_unlock(&re->resultmutex);
+       return success;
  }
  
  /* *************************************************** */
@@@ -3308,22 -3421,124 +3330,79 @@@ void RE_layer_load_from_file(RenderLaye
  
  void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename)
  {
 -      if(!read_render_result_from_file(filename, result)) {
 -              BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
 -              return;
 -      }
 -}
 -
 -static int external_render_3d(Render *re, int do_all)
 -{
 -      RenderEngineType *type= BLI_findstring(&R_engines, re->r.engine, offsetof(RenderEngineType, idname));
 -      RenderEngine engine;
 +      /* optionally also add layers/passes that were in the file but not setup
 +         for rendering, useful for external render engines or network render */
 +      void *exrhandle= IMB_exr_get_handle();
 +      int rectx, recty;
  
 -      if(!(type && type->render))
 -              return 0;
 -      if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
 -              return 0;
 -      if(do_all && !(type->flag & RE_DO_ALL))
 -              return 0;
 -      if(!do_all && (type->flag & RE_DO_ALL))
 -              return 0;
 +      if(IMB_exr_begin_read(exrhandle, filename, &rectx, &recty))
 +              IMB_exr_multilayer_convert(exrhandle, result, ml_addlayer_cb, ml_addpass_cb);
  
 -      BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 -      if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
 -              RE_FreeRenderResult(re->result);
 -      
 -              if(0) // XXX re->r.scemode & R_FULL_SAMPLE)
 -                      re->result= new_full_sample_buffers_exr(re);
 -              else
 -                      re->result= new_render_result(re, &re->disprect, 0, 0); // XXX re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE));
 -      }
 -      BLI_rw_mutex_unlock(&re->resultmutex);
 +      IMB_exr_close(exrhandle);
        
 -      if(re->result==NULL)
 -              return 1;
 -
 -      /* external */
 -      memset(&engine, 0, sizeof(engine));
 -      engine.type= type;
 -      engine.re= re;
 -
 -      type->render(&engine, re->scene);
 -
 -      free_render_result(&engine.fullresult, engine.fullresult.first);
 -
 -      BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 -      if(re->result->exrhandle) {
 -              RenderResult *rr;
 -
 -              save_empty_result_tiles(re);
 -              
 -              for(rr= re->result; rr; rr= rr->next) {
 -                      IMB_exr_close(rr->exrhandle);
 -                      rr->exrhandle= NULL;
 -              }
 -              
 -              free_render_result(&re->fullresult, re->result);
 -              re->result= NULL;
 -              
 -              read_render_result(re, 0);
 +#if 0
 +      if(!read_render_result_from_file(filename, result, 1)) {
 +              BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
 +              return;
        }
 -      BLI_rw_mutex_unlock(&re->resultmutex);
 -
 -      return 1;
 +#endif
  }
  
+ const float default_envmap_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 };
+ int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, const char *relpath, int imtype, float layout[12])
+ {
+       ImBuf *ibuf=NULL;
+       int ok;
+       int dx;
+       int maxX=0,maxY=0,i=0;
+       char filepath[FILE_MAX];
+       if(env->cube[1]==NULL) {
+               BKE_report(reports, RPT_ERROR, "There is no generated environment map available to save");
+               return 0;
+       }
+       dx= env->cube[1]->x;
+       if (env->type == ENV_CUBE) {
+               for (i=0; i < 12; i+=2) {
+                       maxX = MAX2(maxX,layout[i] + 1);
+                       maxY = MAX2(maxY,layout[i+1] + 1);
+               }
+               ibuf = IMB_allocImBuf(maxX*dx, maxY*dx, 24, IB_rectfloat);
+               for (i=0; i < 12; i+=2)
+                       if (layout[i] > -1 && layout[i+1] > -1)
+                               IMB_rectcpy(ibuf, env->cube[i/2], layout[i]*dx, layout[i+1]*dx, 0, 0, dx, dx);
+       }
+       else if (env->type == ENV_PLANE) {
+               ibuf = IMB_allocImBuf(dx, dx, 24, IB_rectfloat);
+               IMB_rectcpy(ibuf, env->cube[1], 0, 0, 0, 0, dx, dx);
+       }
+       else {
+               BKE_report(reports, RPT_ERROR, "Invalid environment map type");
+               return 0;
+       }
+       if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
+               ibuf->profile = IB_PROFILE_LINEAR_RGB;
+       /* to save, we first get absolute path */
+       BLI_strncpy(filepath, relpath, sizeof(filepath));
+       BLI_path_abs(filepath, G.main->name);
+       ok= BKE_write_ibuf(ibuf, filepath, imtype, scene->r.subimtype, scene->r.quality);
+       IMB_freeImBuf(ibuf);
+       if(ok) {
+               return TRUE;
+       }
+       else {
+               BKE_report(reports, RPT_ERROR, "Error writing environment map.");
+               return FALSE;
+       }
+ }
 +