Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <j.bakker@atmind.nl>2018-06-21 15:56:00 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2018-06-21 15:58:00 +0300
commitd5552a6d4ba5bb4ac34fe149c2ac9d7ff3f723fe (patch)
treeb1eb026add3eba7fc74fdb225e2ff25e098fb957 /source/blender/draw/engines/workbench/workbench_forward.c
parent3584810fdd1e35831d5445cf9da24e58ed2fd6d7 (diff)
T55570: Moved Texture drawtype as to shading popover
the use of the texture drawtype is limited. so who should we have it this prominent on the screen. By adding it as a shading.color_type option we should save some screenspace.
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_forward.c')
-rw-r--r--source/blender/draw/engines/workbench/workbench_forward.c98
1 files changed, 45 insertions, 53 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index db07f9bb6f5..6a4737ab8b9 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -144,7 +144,7 @@ static void workbench_init_object_data(ObjectEngineData *engine_data)
}
static WORKBENCH_MaterialData *get_or_create_material_data(
- WORKBENCH_Data *vedata, Object *ob, Material *mat, Image *ima, int drawtype)
+ WORKBENCH_Data *vedata, Object *ob, Material *mat, Image *ima, int color_type)
{
WORKBENCH_StorageList *stl = vedata->stl;
WORKBENCH_PassList *psl = vedata->psl;
@@ -158,7 +158,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
/* Solid */
workbench_material_update_data(wpd, ob, mat, &material_template);
material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1;
- material_template.drawtype = drawtype;
+ material_template.color_type = color_type;
material_template.ima = ima;
uint hash = workbench_material_get_hash(&material_template);
@@ -168,7 +168,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
/* transparent accum */
grp = DRW_shgroup_create(
- drawtype == OB_SOLID ? wpd->transparent_accum_sh : wpd->transparent_accum_texture_sh,
+ color_type == V3D_SHADING_TEXTURE_COLOR ? wpd->transparent_accum_texture_sh: wpd->transparent_accum_sh,
psl->transparent_accum_pass);
DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
DRW_shgroup_uniform_float(grp, "alpha", &wpd->shading.xray_alpha, 1);
@@ -178,26 +178,20 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
copy_v4_v4(material->material_data.diffuse_color, material_template.material_data.diffuse_color);
copy_v4_v4(material->material_data.specular_color, material_template.material_data.specular_color);
material->material_data.roughness = material_template.material_data.roughness;
- switch (drawtype) {
- case OB_SOLID:
- {
- if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) {
- BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE);
- DRW_shgroup_uniform_texture(grp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture);
- }
- if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) {
- DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
- }
- break;
- }
- case OB_TEXTURE:
- {
- GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, 0.0f);
- DRW_shgroup_uniform_texture(grp, "image", tex);
- break;
- }
+ if (color_type == V3D_SHADING_TEXTURE_COLOR)
+ {
+ GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, 0.0f);
+ DRW_shgroup_uniform_texture(grp, "image", tex);
}
+ if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) {
+ BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE);
+ DRW_shgroup_uniform_texture(grp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture);
+ }
+ if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) {
+ DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
+ }
+
material->material_ubo = DRW_uniformbuffer_create(sizeof(WORKBENCH_UBO_Material), &material->material_data);
DRW_shgroup_uniform_block(grp, "material_block", material->material_ubo);
material->shgrp = grp;
@@ -211,10 +205,10 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
return material;
}
-static void ensure_forward_shaders(WORKBENCH_PrivateData *wpd, int index, int drawtype, bool is_hair)
+static void ensure_forward_shaders(WORKBENCH_PrivateData *wpd, int index, bool use_textures, bool is_hair)
{
- if (e_data.composite_sh_cache[index] == NULL && drawtype == OB_SOLID && !is_hair) {
- char *defines = workbench_material_build_defines(wpd, drawtype, is_hair);
+ if (e_data.composite_sh_cache[index] == NULL && !use_textures && !is_hair) {
+ char *defines = workbench_material_build_defines(wpd, use_textures, is_hair);
char *composite_frag = workbench_build_forward_composite_frag();
e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines);
MEM_freeN(composite_frag);
@@ -222,7 +216,7 @@ static void ensure_forward_shaders(WORKBENCH_PrivateData *wpd, int index, int dr
}
if (e_data.transparent_accum_sh_cache[index] == NULL) {
- char *defines = workbench_material_build_defines(wpd, drawtype, is_hair);
+ char *defines = workbench_material_build_defines(wpd, use_textures, is_hair);
char *transparent_accum_vert = workbench_build_forward_vert();
char *transparent_accum_frag = workbench_build_forward_transparent_accum_frag();
e_data.transparent_accum_sh_cache[index] = DRW_shader_create(
@@ -236,15 +230,15 @@ static void ensure_forward_shaders(WORKBENCH_PrivateData *wpd, int index, int dr
static void select_forward_shaders(WORKBENCH_PrivateData *wpd)
{
- int index_solid = workbench_material_get_shader_index(wpd, OB_SOLID, false);
- int index_solid_hair = workbench_material_get_shader_index(wpd, OB_SOLID, true);
- int index_texture = workbench_material_get_shader_index(wpd, OB_TEXTURE, false);
- int index_texture_hair = workbench_material_get_shader_index(wpd, OB_TEXTURE, true);
+ int index_solid = workbench_material_get_shader_index(wpd, false, false);
+ int index_solid_hair = workbench_material_get_shader_index(wpd, false, true);
+ int index_texture = workbench_material_get_shader_index(wpd, true, false);
+ int index_texture_hair = workbench_material_get_shader_index(wpd, true, true);
- ensure_forward_shaders(wpd, index_solid, OB_SOLID, false);
- ensure_forward_shaders(wpd, index_solid_hair, OB_SOLID, true);
- ensure_forward_shaders(wpd, index_texture, OB_TEXTURE, false);
- ensure_forward_shaders(wpd, index_texture_hair, OB_TEXTURE, true);
+ ensure_forward_shaders(wpd, index_solid, false, false);
+ ensure_forward_shaders(wpd, index_solid_hair, false, true);
+ ensure_forward_shaders(wpd, index_texture, true, false);
+ ensure_forward_shaders(wpd, index_texture_hair, true, true);
wpd->composite_sh = e_data.composite_sh_cache[index_solid];
wpd->transparent_accum_sh = e_data.transparent_accum_sh_cache[index_solid];
@@ -399,19 +393,11 @@ static void workbench_forward_cache_populate_particles(WORKBENCH_Data *vedata, O
if (draw_as == PART_DRAW_PATH) {
Image *image = NULL;
Material *mat = give_current_material(ob, part->omat);
- int mat_drawtype = OB_SOLID;
+ ED_object_get_active_image(ob, part->omat, &image, NULL, NULL, NULL);
+ int color_type = workbench_material_determine_color_type(wpd, image);
+ WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, color_type);
- if (wpd->drawtype == OB_TEXTURE) {
- ED_object_get_active_image(ob, part->omat, &image, NULL, NULL, NULL);
- /* use OB_SOLID when no texture could be determined */
- if (image) {
- mat_drawtype = OB_TEXTURE;
- }
- }
-
- WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, mat_drawtype);
-
- struct GPUShader *shader = (mat_drawtype == OB_SOLID)
+ struct GPUShader *shader = (color_type != V3D_SHADING_TEXTURE_COLOR)
? wpd->transparent_accum_hair_sh
: wpd->transparent_accum_texture_hair_sh;
DRWShadingGroup *shgrp = DRW_shgroup_hair_create(
@@ -461,14 +447,14 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
return;
}
+ WORKBENCH_MaterialData *material;
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
const DRWContextState *draw_ctx = DRW_context_state_get();
const bool is_active = (ob == draw_ctx->obact);
const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
bool is_drawn = false;
- WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, NULL, NULL, OB_SOLID);
- if (!is_sculpt_mode && wpd->drawtype == OB_TEXTURE && ELEM(ob->type, OB_MESH)) {
+ if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && ELEM(ob->type, OB_MESH)) {
const Mesh *me = ob->data;
if (me->mloopuv) {
const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
@@ -484,11 +470,16 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
Image *image;
ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
/* use OB_SOLID when no texture could be determined */
- int mat_drawtype = OB_SOLID;
- if (image) {
- mat_drawtype = OB_TEXTURE;
+
+ int color_type = wpd->shading.color_type;
+ if (color_type == V3D_SHADING_TEXTURE_COLOR) {
+ /* use OB_SOLID when no texture could be determined */
+ if (image == NULL) {
+ color_type = V3D_SHADING_MATERIAL_COLOR;
+ }
}
- material = get_or_create_material_data(vedata, ob, mat, image, mat_drawtype);
+
+ material = get_or_create_material_data(vedata, ob, mat, image, color_type);
DRW_shgroup_call_object_add(material->shgrp_object_outline, geom_array[i], ob);
DRW_shgroup_call_object_add(material->shgrp, geom_array[i], ob);
}
@@ -499,10 +490,11 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
/* Fallback from not drawn OB_TEXTURE mode or just OB_SOLID mode */
if (!is_drawn) {
- if ((wpd->shading.color_type != V3D_SHADING_MATERIAL_COLOR)) {
+ if (ELEM(wpd->shading.color_type, V3D_SHADING_SINGLE_COLOR, V3D_SHADING_RANDOM_COLOR)) {
/* No material split needed */
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
if (geom) {
+ material = get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type);
if (is_sculpt_mode) {
DRW_shgroup_call_sculpt_add(material->shgrp_object_outline, ob, ob->obmat);
DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);
@@ -529,7 +521,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
}
Material *mat = give_current_material(ob, i + 1);
- material = get_or_create_material_data(vedata, ob, mat, NULL, OB_SOLID);
+ material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR);
if (is_sculpt_mode) {
DRW_shgroup_call_sculpt_add(material->shgrp_object_outline, ob, ob->obmat);
DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);