[Bf-blender-cvs] [15ebe30bc5b] blender2.8: Workbench: remove runtime warnings

Jeroen Bakker noreply at git.blender.org
Fri Jun 29 10:00:21 CEST 2018


Commit: 15ebe30bc5bdb9d515c8a8a478db6c7770ff0fb1
Author: Jeroen Bakker
Date:   Fri Jun 29 09:59:37 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB15ebe30bc5bdb9d515c8a8a478db6c7770ff0fb1

Workbench: remove runtime warnings

Added feature check when uploading material uniforms

===================================================================

M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/draw/engines/workbench/workbench_private.h

===================================================================

diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index 5eb2344bffe..fcf0d451742 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -580,11 +580,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 		workbench_material_copy(material, &material_template);
 		DRW_shgroup_stencil_mask(material->shgrp, 0xFF);
 		DRW_shgroup_uniform_int(material->shgrp, "object_id", &material->object_id, 1);
-		workbench_material_shgroup_uniform(material->shgrp, material);
-		if (color_type == V3D_SHADING_TEXTURE_COLOR) {
-			GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, 0.0);
-			DRW_shgroup_uniform_texture(material->shgrp, "image", tex);
-		}
+		workbench_material_shgroup_uniform(wpd, material->shgrp, material);
 
 		BLI_ghash_insert(wpd->material_hash, SET_UINT_IN_POINTER(hash), material);
 	}
@@ -630,11 +626,7 @@ static void workbench_cache_populate_particles(WORKBENCH_Data *vedata, Object *o
 			        shader);
 			DRW_shgroup_stencil_mask(shgrp, 0xFF);
 			DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1);
-			workbench_material_shgroup_uniform(shgrp, material);
-			if (image) {
-				GPUTexture *tex = GPU_texture_from_blender(image, NULL, GL_TEXTURE_2D, false, 0.0f);
-				DRW_shgroup_uniform_texture(shgrp, "image", tex);
-			}
+			workbench_material_shgroup_uniform(wpd, shgrp, material);
 		}
 	}
 }
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index 9cc01149067..fb7f3d2bb84 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -177,10 +177,6 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 		DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
 		workbench_material_set_normal_world_matrix(grp, wpd, e_data.normal_world_matrix);
 		workbench_material_copy(material, &material_template);
-		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);
@@ -189,7 +185,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 			DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
 		}
 
-		workbench_material_shgroup_uniform(grp, material);
+		workbench_material_shgroup_uniform(wpd, grp, material);
 		material->shgrp = grp;
 
 		/* Depth */
@@ -423,16 +419,12 @@ static void workbench_forward_cache_populate_particles(WORKBENCH_Data *vedata, O
 			                                shader);
 			workbench_material_set_normal_world_matrix(shgrp, wpd, e_data.normal_world_matrix);
 			DRW_shgroup_uniform_block(shgrp, "world_block", wpd->world_ubo);
-			workbench_material_shgroup_uniform(shgrp, material);
+			workbench_material_shgroup_uniform(wpd, shgrp, material);
 			DRW_shgroup_uniform_vec4(shgrp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
 			/* Hairs have lots of layer and can rapidly become the most prominent surface.
 			 * So lower their alpha artificially. */
 			float hair_alpha = wpd->shading.xray_alpha * 0.33f;
 			DRW_shgroup_uniform_float_copy(shgrp, "alpha", hair_alpha);
-			if (image) {
-				GPUTexture *tex = GPU_texture_from_blender(image, NULL, GL_TEXTURE_2D, false, 0.0f);
-				DRW_shgroup_uniform_texture(shgrp, "image", tex);
-			}
 			if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) {
 				BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE);
 				DRW_shgroup_uniform_texture(shgrp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture);
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
index 69900ca09ac..56b177d1afc 100644
--- a/source/blender/draw/engines/workbench/workbench_materials.c
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -2,6 +2,8 @@
 
 #include "workbench_private.h"
 
+#include "BIF_gl.h"
+
 #include "BLI_dynstr.h"
 
 #define HSV_SATURATION 0.5
@@ -177,11 +179,21 @@ int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, Image *i
 	return color_type;
 }
 
-void workbench_material_shgroup_uniform(DRWShadingGroup *grp, WORKBENCH_MaterialData *material)
+void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp, WORKBENCH_MaterialData *material)
 {
-	DRW_shgroup_uniform_vec4(grp, "materialDiffuseColor", material->diffuse_color, 1);
-	DRW_shgroup_uniform_vec4(grp, "materialSpecularColor", material->specular_color, 1);
-	DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1);
+	if (workbench_material_determine_color_type(wpd, material->ima) == V3D_SHADING_TEXTURE_COLOR)
+	{
+		GPUTexture *tex = GPU_texture_from_blender(material->ima, NULL, GL_TEXTURE_2D, false, 0.0f);
+		DRW_shgroup_uniform_texture(grp, "image", tex);
+	}
+	else {
+		DRW_shgroup_uniform_vec4(grp, "materialDiffuseColor", material->diffuse_color, 1);
+	}
+
+	if (SPECULAR_HIGHLIGHT_ENABLED(wpd)) {
+		DRW_shgroup_uniform_vec4(grp, "materialSpecularColor", material->specular_color, 1);
+		DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1);
+	}
 }
 
 void workbench_material_copy(WORKBENCH_MaterialData *dest_material, const WORKBENCH_MaterialData *source_material)
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
index b240c0a5c3a..3bec6bb6d53 100644
--- a/source/blender/draw/engines/workbench/workbench_private.h
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -270,7 +270,7 @@ uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template);
 int workbench_material_get_shader_index(WORKBENCH_PrivateData *wpd, bool use_textures, bool is_hair);
 void workbench_material_set_normal_world_matrix(
         DRWShadingGroup *grp, WORKBENCH_PrivateData *wpd, float persistent_matrix[3][3]);
-void workbench_material_shgroup_uniform(DRWShadingGroup *grp, WORKBENCH_MaterialData *material);
+void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp, WORKBENCH_MaterialData *material);
 void workbench_material_copy(WORKBENCH_MaterialData *dest_material, const WORKBENCH_MaterialData *source_material);
 
 /* workbench_studiolight.c */



More information about the Bf-blender-cvs mailing list