diff options
author | Miika Hamalainen <blender@miikah.org> | 2011-11-09 19:46:53 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2011-11-09 19:46:53 +0400 |
commit | 1b4a54ad73c058baa59ffdc9e5f18b0b79030fb0 (patch) | |
tree | a5b84d392ea14b0d760a5e24f7a8e51f203d558c /source/blender/editors/space_view3d/drawmesh.c | |
parent | edec46b0a6aac18f406991b9e16228d4bd848c61 (diff) | |
parent | bc5ec4e69cf3308c2563239c0e8372b853800a78 (diff) |
Merge with trunk r41701soc-2011-carrot
Diffstat (limited to 'source/blender/editors/space_view3d/drawmesh.c')
-rw-r--r-- | source/blender/editors/space_view3d/drawmesh.c | 187 |
1 files changed, 183 insertions, 4 deletions
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 0a332875cae..ade3a65054f 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -40,11 +40,12 @@ #include "DNA_material_types.h" #include "DNA_meshdata_types.h" +#include "DNA_node_types.h" +#include "DNA_object_types.h" #include "DNA_property_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_view3d_types.h" -#include "DNA_object_types.h" #include "BKE_DerivedMesh.h" #include "BKE_effect.h" @@ -52,6 +53,7 @@ #include "BKE_material.h" #include "BKE_paint.h" #include "BKE_property.h" +#include "BKE_scene.h" #include "BIF_gl.h" #include "BIF_glutil.h" @@ -64,6 +66,7 @@ #include "GPU_material.h" #include "ED_mesh.h" +#include "ED_uvedit.h" #include "view3d_intern.h" // own include @@ -626,7 +629,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl) ddm->release(ddm); } -void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) { Mesh *me= ob->data; @@ -648,7 +651,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, &data); } - else if(draw_flags & DRAW_IS_PAINT_SEL) { + else if(draw_flags & DRAW_FACE_SELECT) { if(ob->mode & OB_MODE_WEIGHT_PAINT) dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me, 1, GPU_enable_material, NULL); else @@ -676,7 +679,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o draw_textured_end(); /* draw edges and selected faces over textured mesh */ - if(!(ob == scene->obedit) && (draw_flags & DRAW_IS_PAINT_SEL)) + if(!(ob == scene->obedit) && (draw_flags & DRAW_FACE_SELECT)) draw_mesh_face_select(rv3d, me, dm); /* reset from negative scale correction */ @@ -686,3 +689,179 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } +/************************** NEW SHADING NODES ********************************/ + +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; + bNode *node; + int texture_set= 0; + + /* draw image texture if we find one */ + if(ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) { + /* 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) { + NodeTexBase *texbase= node->storage; + + /* 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); + + glMatrixMode(GL_TEXTURE); + glLoadMatrixf(texbase->tex_mapping.mat); + glMatrixMode(GL_MODELVIEW); + + /* 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) { + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + + /* 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 draw_flags) +{ + if((!scene_use_new_shading_nodes(scene)) || (draw_flags & DRAW_DYNAMIC_PAINT_PREVIEW)) { + draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, draw_flags); + 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(draw_flags & DRAW_FACE_SELECT) + set_face_cb= tex_mat_set_face_mesh_cb; + else + set_face_cb= NULL; + + /* test if we can use glsl */ + glsl= (v3d->drawtype == OB_MATERIAL) && GPU_glsl_support(); + + 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); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + + /* faceselect mode drawing over textured mesh */ + if(!(ob == scene->obedit) && (draw_flags & DRAW_FACE_SELECT)) + draw_mesh_face_select(rv3d, ob->data, dm); +} + |