Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_material.c
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "GPU_extensions.h" | #include "GPU_extensions.h" | ||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "GPU_lamp.h" | #include "GPU_lamp.h" | ||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "GPU_uniformbuffer.h" | |||||
| #include "gpu_codegen.h" | #include "gpu_codegen.h" | ||||
| #include "gpu_lamp_private.h" | #include "gpu_lamp_private.h" | ||||
| #ifdef WITH_OPENSUBDIV | #ifdef WITH_OPENSUBDIV | ||||
| # include "BKE_DerivedMesh.h" | # include "BKE_DerivedMesh.h" | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | struct GPUMaterial { | ||||
| int partangvel; | int partangvel; | ||||
| int objectinfoloc; | int objectinfoloc; | ||||
| ListBase lamps; | ListBase lamps; | ||||
| bool bound; | bool bound; | ||||
| bool is_opensubdiv; | bool is_opensubdiv; | ||||
| GPUUniformBuffer *ubo; /* UBOs for shader uniforms. */ | |||||
| }; | }; | ||||
| /* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */ | /* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */ | ||||
| static void texture_rgb_blend( | static void texture_rgb_blend( | ||||
| GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, | GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, | ||||
| int blendtype, GPUNodeLink **in); | int blendtype, GPUNodeLink **in); | ||||
| /* Functions */ | /* Functions */ | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
| void GPU_material_free(ListBase *gpumaterial) | void GPU_material_free(ListBase *gpumaterial) | ||||
| { | { | ||||
| for (LinkData *link = gpumaterial->first; link; link = link->next) { | for (LinkData *link = gpumaterial->first; link; link = link->next) { | ||||
| GPUMaterial *material = link->data; | GPUMaterial *material = link->data; | ||||
| if (material->pass) | if (material->pass) | ||||
| GPU_pass_free(material->pass); | GPU_pass_free(material->pass); | ||||
| if (material->ubo != NULL) { | |||||
| GPU_uniformbuffer_free(material->ubo); | |||||
| } | |||||
| BLI_freelistN(&material->lamps); | BLI_freelistN(&material->lamps); | ||||
| MEM_freeN(material); | MEM_freeN(material); | ||||
| } | } | ||||
| BLI_freelistN(gpumaterial); | BLI_freelistN(gpumaterial); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | GPUMatType GPU_Material_get_type(GPUMaterial *material) | ||||
| return material->type; | return material->type; | ||||
| } | } | ||||
| GPUPass *GPU_material_get_pass(GPUMaterial *material) | GPUPass *GPU_material_get_pass(GPUMaterial *material) | ||||
| { | { | ||||
| return material->pass; | return material->pass; | ||||
| } | } | ||||
| GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material) | |||||
| { | |||||
| return material->ubo; | |||||
| } | |||||
| /** | |||||
| * Create dynamic UBO from parameters | |||||
| * \param ListBase of BLI_genericNodeN(GPUInput) | |||||
| */ | |||||
| void GPU_material_create_uniform_buffer(GPUMaterial *material, ListBase *inputs) | |||||
| { | |||||
| material->ubo = GPU_uniformbuffer_dynamic_create(inputs, NULL); | |||||
| } | |||||
| void GPU_material_uniform_buffer_tag_dirty(ListBase *gpumaterials) | |||||
| { | |||||
| for (LinkData *link = gpumaterials->first; link; link = link->next) { | |||||
| GPUMaterial *material = link->data; | |||||
| if (material->ubo != NULL) { | |||||
| GPU_uniformbuffer_tag_dirty(material->ubo); | |||||
| } | |||||
| } | |||||
| } | |||||
| void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs) | void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs) | ||||
| { | { | ||||
| *attribs = material->attribs; | *attribs = material->attribs; | ||||
| } | } | ||||
| void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link) | void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link) | ||||
| { | { | ||||
| if (!material->outlink) | if (!material->outlink) | ||||
| ▲ Show 20 Lines • Show All 1,679 Lines • ▼ Show 20 Lines | GPUMaterial *GPU_material_from_nodetree( | ||||
| BLI_assert(GPU_material_from_nodetree_find(gpumaterials, engine_type, options) == NULL); | BLI_assert(GPU_material_from_nodetree_find(gpumaterials, engine_type, options) == NULL); | ||||
| /* allocate material */ | /* allocate material */ | ||||
| mat = GPU_material_construct_begin(NULL); /* TODO remove GPU_material_construct_begin */ | mat = GPU_material_construct_begin(NULL); /* TODO remove GPU_material_construct_begin */ | ||||
| mat->scene = scene; | mat->scene = scene; | ||||
| mat->engine_type = engine_type; | mat->engine_type = engine_type; | ||||
| mat->options = options; | mat->options = options; | ||||
| ntreeGPUMaterialNodes(ntree, mat, NODE_NEWER_SHADING); | ntreeGPUMaterialNodes_gpu(ntree, mat); | ||||
| /* Let Draw manager finish the construction. */ | /* Let Draw manager finish the construction. */ | ||||
| if (mat->outlink) { | if (mat->outlink) { | ||||
| outlink = mat->outlink; | outlink = mat->outlink; | ||||
| mat->pass = GPU_generate_pass_new( | mat->pass = GPU_generate_pass_new( | ||||
| &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines); | mat, &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines); | ||||
| } | } | ||||
| /* note that even if building the shader fails in some way, we still keep | /* note that even if building the shader fails in some way, we still keep | ||||
| * it to avoid trying to compile again and again, and simple do not use | * it to avoid trying to compile again and again, and simple do not use | ||||
| * the actual shader on drawing */ | * the actual shader on drawing */ | ||||
| link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink"); | link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink"); | ||||
| link->data = mat; | link->data = mat; | ||||
| ▲ Show 20 Lines • Show All 386 Lines • Show Last 20 Lines | |||||