diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_draw.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index f8d0957f70d..efb7d688a49 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -393,7 +393,7 @@ int GPU_verify_image(Image *ima, int tftile, int tfmode, int compare) /* initialize tile mode and number of repeats */ GTS.ima = ima; - GTS.tilemode= (tfmode & TF_TILES) || (ima && (ima->tpageflag & IMA_TWINANIM)); + GTS.tilemode= (ima && (ima->tpageflag & (IMA_TILES|IMA_TWINANIM))); GTS.tileXRep = 0; GTS.tileYRep = 0; @@ -423,7 +423,7 @@ int GPU_verify_image(Image *ima, int tftile, int tfmode, int compare) glMatrixMode(GL_TEXTURE); glLoadIdentity(); - if((tfmode & TF_TILES) && ima!=NULL) + if(ima && (ima->tpageflag & IMA_TILES)) glScalef(ima->xrep, ima->yrep, 1.0); glMatrixMode(GL_MODELVIEW); @@ -776,16 +776,17 @@ void GPU_free_images(void) /* OpenGL Materials */ -/* materials start counting at # one.... */ -#define MAXMATBUF (MAXMAT+1) +#define FIXEDMAT 8 /* OpenGL state caching for materials */ static struct GPUMaterialState { - float matbuf[MAXMATBUF][2][4]; + float (*matbuf)[2][4]; + float matbuf_fixed[FIXEDMAT][2][4]; int totmat; - Material *gmatbuf[MAXMATBUF]; + Material **gmatbuf; + Material *gmatbuf_fixed[FIXEDMAT]; Material *gboundmat; Object *gob; Scene *gscene; @@ -793,7 +794,8 @@ static struct GPUMaterialState { float (*gviewmat)[4]; float (*gviewinv)[4]; - GPUBlendMode blendmode[MAXMATBUF]; + GPUBlendMode *blendmode; + GPUBlendMode blendmode_fixed[FIXEDMAT]; int alphapass; int lastmatnr, lastretval; @@ -814,7 +816,7 @@ Material *gpu_active_node_material(Material *ma) return ma; } -void GPU_set_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, int glsl, int *do_alpha_pass) +void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, int glsl, int *do_alpha_pass) { extern Material defmaterial; /* from material.c */ Material *ma; @@ -830,7 +832,7 @@ void GPU_set_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Obj GMS.gob = ob; GMS.gscene = scene; - GMS.totmat= ob->totcol; + GMS.totmat= ob->totcol+1; /* materials start from 1, default material is 0 */ GMS.glay= v3d->lay; GMS.gviewmat= rv3d->viewmat; GMS.gviewinv= rv3d->viewinv; @@ -838,6 +840,17 @@ void GPU_set_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Obj GMS.alphapass = (v3d && v3d->transp); if(do_alpha_pass) *do_alpha_pass = 0; + + if(GMS.totmat > FIXEDMAT) { + GMS.matbuf= MEM_callocN(sizeof(*GMS.matbuf)*GMS.totmat, "GMS.matbuf"); + GMS.gmatbuf= MEM_callocN(sizeof(*GMS.gmatbuf)*GMS.totmat, "GMS.matbuf"); + GMS.blendmode= MEM_callocN(sizeof(*GMS.blendmode)*GMS.totmat, "GMS.matbuf"); + } + else { + GMS.matbuf= GMS.matbuf_fixed; + GMS.gmatbuf= GMS.gmatbuf_fixed; + GMS.blendmode= GMS.blendmode_fixed; + } /* no materials assigned? */ if(ob->totcol==0) { @@ -870,10 +883,6 @@ void GPU_set_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Obj if(!glsl) ma= gpu_active_node_material(ma); if(ma==NULL) ma= &defmaterial; - /* this shouldn't happen .. */ - if(a>=MAXMATBUF) - continue; - /* create glsl material if requested */ gpumat = (glsl)? GPU_material_from_blender(GMS.gscene, ma): NULL; @@ -926,14 +935,14 @@ int GPU_enable_material(int nr, void *attribs) GPUBlendMode blendmode; /* prevent index to use un-initialized array items */ - if(nr>GMS.totmat) - nr= GMS.totmat; + if(nr>=GMS.totmat) + nr= 0; if(gattribs) memset(gattribs, 0, sizeof(*gattribs)); /* keep current material */ - if(nr>=MAXMATBUF || nr==GMS.lastmatnr) + if(nr==GMS.lastmatnr) return GMS.lastretval; /* unbind glsl material */ @@ -1004,6 +1013,21 @@ void GPU_disable_material(void) GPU_set_material_blend_mode(GPU_BLEND_SOLID); } +void GPU_end_object_materials(void) +{ + GPU_disable_material(); + + if(GMS.matbuf && GMS.matbuf != GMS.matbuf_fixed) { + MEM_freeN(GMS.matbuf); + MEM_freeN(GMS.gmatbuf); + MEM_freeN(GMS.blendmode); + + GMS.matbuf= NULL; + GMS.gmatbuf= NULL; + GMS.blendmode= NULL; + } +} + /* Lights */ int GPU_default_lights(void) |