Add check for GPU materials enable state
authorCampbell Barton <ideasman42@gmail.com>
Fri, 17 Jul 2015 19:29:34 +0000 (05:29 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 17 Jul 2015 19:30:13 +0000 (05:30 +1000)
source/blender/gpu/GPU_draw.h
source/blender/gpu/intern/gpu_draw.c

index a6bc5ff002f39112ada88768f4975b3a0af9ad18..26db4058d342787b2b0a774be64093129834157d 100644 (file)
@@ -69,6 +69,7 @@ void GPU_state_init(void);
 void GPU_begin_object_materials(struct View3D *v3d, struct RegionView3D *rv3d, 
                                 struct Scene *scene, struct Object *ob, bool glsl, bool *do_alpha_after);
 void GPU_end_object_materials(void);
+bool GPU_object_materials_check(void);
 
 int GPU_enable_material(int nr, void *attribs);
 void GPU_disable_material(void);
index 4e2af56e1e55b23c32b7c669bbf9ad4e634506b5..79f92b76fe2ed36f6505bc39078358ea2f31f6af 100644 (file)
@@ -1407,6 +1407,8 @@ static struct GPUMaterialState {
        GPUMaterialFixed (*matbuf);
        GPUMaterialFixed matbuf_fixed[FIXEDMAT];
        int totmat;
+       /* set when called inside GPU_begin_object_materials / GPU_end_object_materials */
+       bool is_enabled;
 
        Material **gmatbuf;
        Material *gmatbuf_fixed[FIXEDMAT];
@@ -1526,6 +1528,7 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
        /* DupliObject must be restored */
        dob = GMS.dob;
        memset(&GMS, 0, sizeof(GMS));
+       GMS.is_enabled = true;
        GMS.dob = dob;
        GMS.lastmatnr = -1;
        GMS.lastretval = -1;
@@ -1824,11 +1827,17 @@ bool GPU_material_use_matcaps_get(void)
        return GMS.use_matcaps;
 }
 
+bool GPU_object_materials_check(void)
+{
+       return GMS.is_enabled;
+}
 
 void GPU_end_object_materials(void)
 {
        GPU_disable_material();
 
+       GMS.is_enabled = false;
+
        if (GMS.matbuf && GMS.matbuf != GMS.matbuf_fixed) {
                MEM_freeN(GMS.matbuf);
                MEM_freeN(GMS.gmatbuf);