2.5:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 21 Jul 2009 18:29:37 +0000 (18:29 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 21 Jul 2009 18:29:37 +0000 (18:29 +0000)
* Fix armature drawing crash with materials.
* Mixed texture/material preview was doing wrong gamma correction.
* Use *f math functions for AAO.

source/blender/editors/preview/previewrender.c
source/blender/gpu/intern/gpu_draw.c
source/blender/render/intern/source/occlusion.c

index 624952b48f5b865096044cf8457671aef440afd7..b542b362ae08224ce9c00d3c329444b518966688 100644 (file)
@@ -472,9 +472,12 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, rcti *rect)
                newrect.ymin= rect->ymin;
                newrect.ymax= rect->ymin;
 
-               ok= ed_preview_draw_rect(sa, sce, id, (parent != NULL), 1, rect, &newrect);
-               if(parent)
-                       ok &= ed_preview_draw_rect(sa, sce, parent, 1, 0, rect, &newrect);
+               if(parent) {
+                       ok = ed_preview_draw_rect(sa, sce, parent, 1, 1, rect, &newrect);
+                       ok &= ed_preview_draw_rect(sa, sce, id, 1, 0, rect, &newrect);
+               }
+               else
+                       ok = ed_preview_draw_rect(sa, sce, id, 0, 0, rect, &newrect);
 
                if(ok)
                        *rect= newrect;
index 1031a240470b162840f404805c25389d86ae4ecf..eb834abc6708e45056d14559f0a03b7462fb7c08 100644 (file)
@@ -800,7 +800,7 @@ static struct GPUMaterialState {
 
        int lastmatnr, lastretval;
        GPUBlendMode lastblendmode;
-} GMS;
+} GMS = {NULL};
 
 Material *gpu_active_node_material(Material *ma)
 {
@@ -930,10 +930,33 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
 
 int GPU_enable_material(int nr, void *attribs)
 {
+       extern Material defmaterial; /* from material.c */
        GPUVertexAttribs *gattribs = attribs;
        GPUMaterial *gpumat;
        GPUBlendMode blendmode;
 
+       /* no GPU_begin_object_materials, use default material */
+       if(!GMS.matbuf) {
+               float diff[4], spec[4];
+
+               memset(&GMS, 0, sizeof(GMS));
+
+               diff[0]= (defmaterial.ref+defmaterial.emit)*defmaterial.r;
+               diff[1]= (defmaterial.ref+defmaterial.emit)*defmaterial.g;
+               diff[2]= (defmaterial.ref+defmaterial.emit)*defmaterial.b;
+               diff[3]= 1.0;
+
+               spec[0]= defmaterial.spec*defmaterial.specr;
+               spec[1]= defmaterial.spec*defmaterial.specg;
+               spec[2]= defmaterial.spec*defmaterial.specb;
+               spec[3]= 1.0;
+
+               glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff);
+               glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
+
+               return 0;
+       }
+
        /* prevent index to use un-initialized array items */
        if(nr>=GMS.totmat)
                nr= 0;
@@ -1021,11 +1044,11 @@ void GPU_end_object_materials(void)
                MEM_freeN(GMS.matbuf);
                MEM_freeN(GMS.gmatbuf);
                MEM_freeN(GMS.blendmode);
-
-               GMS.matbuf= NULL;
-               GMS.gmatbuf= NULL;
-               GMS.blendmode= NULL;
        }
+
+       GMS.matbuf= NULL;
+       GMS.gmatbuf= NULL;
+       GMS.blendmode= NULL;
 }
 
 /* Lights */
index 1cbf25231569f5a985d410465e9044f6346f08ed..feef3dd424a81176a2a73bf2ab238f0661a73f18 100644 (file)
@@ -754,9 +754,9 @@ static int occ_visible_quad(float *p, float *n, float *v0, float *v1, float *v2,
        sd[1]= INPR(n, v1) - c;
        sd[2]= INPR(n, v2) - c;
 
-       if(fabs(sd[0]) < epsilon) sd[0] = 0.0f;
-       if(fabs(sd[1]) < epsilon) sd[1] = 0.0f;
-       if(fabs(sd[2]) < epsilon) sd[2] = 0.0f;
+       if(fabsf(sd[0]) < epsilon) sd[0] = 0.0f;
+       if(fabsf(sd[1]) < epsilon) sd[1] = 0.0f;
+       if(fabsf(sd[2]) < epsilon) sd[2] = 0.0f;
 
        if(sd[0] > 0) {
                if(sd[1] > 0) {
@@ -1086,13 +1086,6 @@ static float occ_quad_form_factor(float *p, float *n, float *q0, float *q1, floa
 
 #endif
 
-static float saacosf(float fac)
-{
-       if(fac<= -1.0f) return (float)M_PI;
-       else if(fac>=1.0f) return 0.0f;
-       else return acos(fac); /* acosf(fac) */
-}
-
 static void normalizef(float *n)
 {
        float d;
@@ -1100,7 +1093,7 @@ static void normalizef(float *n)
        d= INPR(n, n);
 
        if(d > 1.0e-35F) {
-               d= 1.0f/sqrt(d); /* sqrtf(d) */
+               d= 1.0f/sqrtf(d);
 
                n[0] *= d; 
                n[1] *= d; 
@@ -1222,7 +1215,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float
                                fac= 1.0f;
 
                        /* accumulate occlusion from spherical harmonics */
-                       invd2 = 1.0f/sqrt(d2);
+                       invd2 = 1.0f/sqrtf(d2);
                        weight= occ_solid_angle(node, v, d2, invd2, n);
                        weight *= node->occlusion;
 
@@ -1258,7 +1251,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float
                                                weight *= tree->occlusion[node->child[b].face];
 
                                                if(bentn) {
-                                                       invd2= 1.0f/sqrt(d2);
+                                                       invd2= 1.0f/sqrtf(d2);
                                                        bentn[0] -= weight*invd2*v[0];
                                                        bentn[1] -= weight*invd2*v[1];
                                                        bentn[2] -= weight*invd2*v[2];