Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_draw.c
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_modifier_types.h" | #include "DNA_modifier_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_smoke_types.h" | #include "DNA_smoke_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "DNA_particle_types.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "BKE_bmfont.h" | #include "BKE_bmfont.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| ▲ Show 20 Lines • Show All 1,324 Lines • ▼ Show 20 Lines | static struct GPUMaterialState { | ||||
| GPUMaterialFixed (*matbuf); | GPUMaterialFixed (*matbuf); | ||||
| GPUMaterialFixed matbuf_fixed[FIXEDMAT]; | GPUMaterialFixed matbuf_fixed[FIXEDMAT]; | ||||
| int totmat; | int totmat; | ||||
| Material **gmatbuf; | Material **gmatbuf; | ||||
| Material *gmatbuf_fixed[FIXEDMAT]; | Material *gmatbuf_fixed[FIXEDMAT]; | ||||
| Material *gboundmat; | Material *gboundmat; | ||||
| Object *gob; | Object *gob; | ||||
| DupliObject *dob; | |||||
| Scene *gscene; | Scene *gscene; | ||||
| int glay; | int glay; | ||||
| bool gscenelock; | bool gscenelock; | ||||
| float (*gviewmat)[4]; | float (*gviewmat)[4]; | ||||
| float (*gviewinv)[4]; | float (*gviewinv)[4]; | ||||
| float (*gviewcamtexcofac); | float (*gviewcamtexcofac); | ||||
| bool backface_culling; | bool backface_culling; | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if (node) | ||||
| return (Material *)node->id; | return (Material *)node->id; | ||||
| else | else | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return ma; | return ma; | ||||
| } | } | ||||
| void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, bool glsl, bool *do_alpha_after) | void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, bool glsl, bool *do_alpha_after, DupliObject *dob) | ||||
| { | { | ||||
| Material *ma; | Material *ma; | ||||
| GPUMaterial *gpumat; | GPUMaterial *gpumat; | ||||
| GPUBlendMode alphablend; | GPUBlendMode alphablend; | ||||
| int a; | int a; | ||||
| const bool gamma = BKE_scene_check_color_management_enabled(scene); | const bool gamma = BKE_scene_check_color_management_enabled(scene); | ||||
| const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene); | const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene); | ||||
| const bool use_matcap = (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) != 0; /* assumes v3d->defmaterial->preview is set */ | const bool use_matcap = (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) != 0; /* assumes v3d->defmaterial->preview is set */ | ||||
| Show All 9 Lines | #endif | ||||
| GMS.lastmatnr = -1; | GMS.lastmatnr = -1; | ||||
| GMS.lastretval = -1; | GMS.lastretval = -1; | ||||
| GMS.lastalphablend = GPU_BLEND_SOLID; | GMS.lastalphablend = GPU_BLEND_SOLID; | ||||
| GMS.use_matcaps = use_matcap; | GMS.use_matcaps = use_matcap; | ||||
| GMS.backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0; | GMS.backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0; | ||||
| GMS.gob = ob; | GMS.gob = ob; | ||||
| GMS.dob = dob; | |||||
| GMS.gscene = scene; | GMS.gscene = scene; | ||||
| GMS.totmat = use_matcap ? 1 : ob->totcol + 1; /* materials start from 1, default material is 0 */ | GMS.totmat = use_matcap ? 1 : ob->totcol + 1; /* materials start from 1, default material is 0 */ | ||||
| GMS.glay = (v3d->localvd)? v3d->localvd->lay: v3d->lay; /* keep lamps visible in local view */ | GMS.glay = (v3d->localvd)? v3d->localvd->lay: v3d->lay; /* keep lamps visible in local view */ | ||||
| GMS.gscenelock = (v3d->scenelock != 0); | GMS.gscenelock = (v3d->scenelock != 0); | ||||
| GMS.gviewmat = rv3d->viewmat; | GMS.gviewmat = rv3d->viewmat; | ||||
| GMS.gviewinv = rv3d->viewinv; | GMS.gviewinv = rv3d->viewinv; | ||||
| GMS.gviewcamtexcofac = rv3d->viewcamtexcofac; | GMS.gviewcamtexcofac = rv3d->viewcamtexcofac; | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | for (a = 1; a <= ob->totcol; a++) { | ||||
| GMS.alphablend[a] = alphablend; | GMS.alphablend[a] = alphablend; | ||||
| } | } | ||||
| } | } | ||||
| /* let's start with a clean state */ | /* let's start with a clean state */ | ||||
| GPU_disable_material(); | GPU_disable_material(); | ||||
| } | } | ||||
| int GPU_get_particle_info(GPUParticleInfo *pi) | |||||
| { | |||||
| ParticleData *p; | |||||
| DupliObject *dob = GMS.dob; | |||||
| int ind; | |||||
| if(dob->particle_system) { | |||||
| if(dob->persistent_id[0] < dob->particle_system->totpart) | |||||
| ind = dob->persistent_id[0]; | |||||
| else { | |||||
| ind = dob->particle_system->child[dob->persistent_id[0] - dob->particle_system->totpart].parent; | |||||
| } | |||||
| if (ind >= 0) { | |||||
| p = &dob->particle_system->particles[ind]; | |||||
| pi->scalprops[0] = ind; | |||||
| pi->scalprops[1] = GMS.gscene->r.cfra - p->time; | |||||
| pi->scalprops[2] = p->lifetime; | |||||
| pi->scalprops[3] = p->size; | |||||
| copy_v3_v3(pi->location, p->state.co); | |||||
| copy_v3_v3(pi->velocity, p->state.vel); | |||||
| copy_v3_v3(pi->angular_velocity, p->state.ave); | |||||
| return 1; | |||||
| } | |||||
| else return 0; | |||||
| } | |||||
| else | |||||
| return 0; | |||||
| } | |||||
| int GPU_enable_material(int nr, void *attribs) | int GPU_enable_material(int nr, void *attribs) | ||||
| { | { | ||||
| GPUVertexAttribs *gattribs = attribs; | GPUVertexAttribs *gattribs = attribs; | ||||
| GPUMaterial *gpumat; | GPUMaterial *gpumat; | ||||
| GPUBlendMode alphablend; | GPUBlendMode alphablend; | ||||
| /* no GPU_begin_object_materials, use default material */ | /* no GPU_begin_object_materials, use default material */ | ||||
| if (!GMS.matbuf) { | if (!GMS.matbuf) { | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | int GPU_enable_material(int nr, void *attribs) | ||||
| if (GMS.lastretval) { | if (GMS.lastretval) { | ||||
| /* for alpha pass, use alpha blend */ | /* for alpha pass, use alpha blend */ | ||||
| alphablend = GMS.alphablend[nr]; | alphablend = GMS.alphablend[nr]; | ||||
| if (gattribs && GMS.gmatbuf[nr]) { | if (gattribs && GMS.gmatbuf[nr]) { | ||||
| /* bind glsl material and get attributes */ | /* bind glsl material and get attributes */ | ||||
| Material *mat = GMS.gmatbuf[nr]; | Material *mat = GMS.gmatbuf[nr]; | ||||
| GPUParticleInfo partile_info; | |||||
| float auto_bump_scale; | float auto_bump_scale; | ||||
| gpumat = GPU_material_from_blender(GMS.gscene, mat); | gpumat = GPU_material_from_blender(GMS.gscene, mat); | ||||
| GPU_material_vertex_attributes(gpumat, gattribs); | GPU_material_vertex_attributes(gpumat, gattribs); | ||||
| if (GMS.dob) | |||||
| GPU_get_particle_info(&partile_info); | |||||
| GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, GMS.gviewcamtexcofac, GMS.gscenelock); | GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, GMS.gviewcamtexcofac, GMS.gscenelock); | ||||
| auto_bump_scale = GMS.gob->derivedFinal != NULL ? GMS.gob->derivedFinal->auto_bump_scale : 1.0f; | auto_bump_scale = GMS.gob->derivedFinal != NULL ? GMS.gob->derivedFinal->auto_bump_scale : 1.0f; | ||||
| GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gob->col, auto_bump_scale); | GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gob->col, auto_bump_scale, &partile_info); | ||||
| GMS.gboundmat = mat; | GMS.gboundmat = mat; | ||||
| /* for glsl use alpha blend mode, unless it's set to solid and | /* for glsl use alpha blend mode, unless it's set to solid and | ||||
| * we are already drawing in an alpha pass */ | * we are already drawing in an alpha pass */ | ||||
| if (mat->game.alpha_blend != GPU_BLEND_SOLID) | if (mat->game.alpha_blend != GPU_BLEND_SOLID) | ||||
| alphablend= mat->game.alpha_blend; | alphablend= mat->game.alpha_blend; | ||||
| if (GMS.is_alpha_pass) glDepthMask(1); | if (GMS.is_alpha_pass) glDepthMask(1); | ||||
| ▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines | |||||